MessageHandler.c 782 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char isOnCharging:1; //bit 4.
  117. unsigned char :3; //bit 5~7
  118. }bits[CONNECTOR_QUANTITY];
  119. }CpinitiateMsg;
  120. CpinitiateMsg cpinitateMsg;
  121. //GetConfiguration Array
  122. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  125. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  126. #if 0
  127. static char *ChargePointErrorCodeStr[] = {
  128. MACROSTR(ConnectorLockFailure),
  129. MACROSTR(EVCommunicationError),
  130. MACROSTR(GroundFailure),
  131. MACROSTR(HighTemperature),
  132. MACROSTR(InternalError),
  133. MACROSTR(LocalListConflict),
  134. MACROSTR(NoError),
  135. MACROSTR(OtherError),
  136. MACROSTR(OverCurrentFailure),
  137. MACROSTR(OverVoltage),
  138. MACROSTR(PowerMeterFailure),
  139. MACROSTR(PowerSwitchFailure),
  140. MACROSTR(ReaderFailure),
  141. MACROSTR(ResetFailure),
  142. MACROSTR(UnderVoltage),
  143. MACROSTR(WeakSignal)
  144. };
  145. #endif
  146. static char * ChargePointStatusStr[] = {
  147. MACROSTR(Available),
  148. MACROSTR(Preparing),
  149. MACROSTR(Charging),
  150. MACROSTR(SuspendedEVSE),
  151. MACROSTR(SuspendedEV),
  152. MACROSTR(Finishing),
  153. MACROSTR(Reserved),
  154. MACROSTR(Unavailable),
  155. MACROSTR(Faulted)
  156. };
  157. static char *RegistrationStatusStr[] = {
  158. MACROSTR(Accepted),
  159. MACROSTR(Pending),
  160. MACROSTR(Rejected)
  161. };
  162. static char *AvailabilityTypeStr[] = {
  163. MACROSTR(Inoperative),
  164. MACROSTR(Operative)
  165. };
  166. static char *AvailabilityStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Rejected),
  169. MACROSTR(Scheduled)
  170. };
  171. static char *ConfigurationStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(RebootRequired),
  175. MACROSTR(NotSupported)
  176. };
  177. static char *ClearCacheStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected)
  180. };
  181. static char *ChargingProfilePurposeTypeStr[] = {
  182. MACROSTR(ChargePointMaxProfile),
  183. MACROSTR(TxDefaultProfile),
  184. MACROSTR(TxProfile)
  185. };
  186. static char *ChargingProfileStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupported)
  190. };
  191. static char *ClearChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Unknown)
  194. };
  195. static char *GetCompositeScheduleStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected)
  198. };
  199. static char *UpdateTypeStr[] = {
  200. MACROSTR(Differential),
  201. MACROSTR(Full)
  202. };
  203. static char *UpdateStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Failed),
  206. MACROSTR(NotSupported),
  207. MACROSTR(VersionMismatch)
  208. };
  209. static char *RemoteStartStopStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Rejected)
  212. };
  213. static char *ReservationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Faulted),
  216. MACROSTR(Occupied),
  217. MACROSTR(Rejected),
  218. MACROSTR(Unavailable)
  219. };
  220. static char *ResetTypeStr[] = {
  221. MACROSTR(Hard),
  222. MACROSTR(Soft)
  223. };
  224. static char *ResetStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Rejected)
  227. };
  228. static char * DiagnosticsStatusStr[] = {
  229. MACROSTR(Idle),
  230. MACROSTR(Uploaded),
  231. MACROSTR(UploadFailed),
  232. MACROSTR(Uploading)
  233. };
  234. static char * FirmwareStatusStr[] = {
  235. MACROSTR(Downloaded),
  236. MACROSTR(DownloadFailed),
  237. MACROSTR(Downloading),
  238. MACROSTR(Idle),
  239. MACROSTR(InstallationFailed),
  240. MACROSTR(Installing),
  241. MACROSTR(Installed)
  242. };
  243. static char * MessageTriggerStr[] = {
  244. MACROSTR(BootNotification),
  245. MACROSTR(DiagnosticsStatusNotification),
  246. MACROSTR(FirmwareStatusNotification),
  247. MACROSTR(Heartbeat),
  248. MACROSTR(MeterValues),
  249. MACROSTR(StatusNotification)
  250. };
  251. static char * TriggerMessageStatusStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Rejected),
  254. MACROSTR(NotImplemented)
  255. };
  256. static char * UnlockStatusStr[] = {
  257. MACROSTR(Unlocked),
  258. MACROSTR(UnlockFailed),
  259. MACROSTR(NotSupported)
  260. };
  261. #if 0
  262. static char * StopTransactionReasonStr[] = {
  263. MACROSTR(EmergencyStop),
  264. MACROSTR(EVDisconnected),
  265. MACROSTR(HardReset),
  266. MACROSTR(Local),
  267. MACROSTR(Other),
  268. MACROSTR(PowerLoss),
  269. MACROSTR(Reboot),
  270. MACROSTR(Remote),
  271. MACROSTR(SoftReset),
  272. MACROSTR(UnlockCommand),
  273. MACROSTR(DeAuthorized)
  274. };
  275. #endif
  276. static char * CancelReservationStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Rejected)
  279. };
  280. static char * ReadingContextStr[] = {
  281. MACROSTR(Interruption.Begin),
  282. MACROSTR(Interruption.End),
  283. MACROSTR(Other),
  284. MACROSTR(Sample.Clock),
  285. MACROSTR(Sample.Periodic),
  286. MACROSTR(Transaction.Begin),
  287. MACROSTR(Transaction.End),
  288. MACROSTR(Trigger)
  289. };
  290. static char * ValueFormatStr[] = {
  291. MACROSTR(Raw),
  292. MACROSTR(SignedData)
  293. };
  294. static char * MeasurandStr[] = {
  295. MACROSTR(Current.Export),
  296. MACROSTR(Current.Import),
  297. MACROSTR(Current.Offered),
  298. MACROSTR(Energy.Active.Export.Register),
  299. MACROSTR(Energy.Active.Import.Register),
  300. MACROSTR(Energy.Reactive.Export.Register),
  301. MACROSTR(Energy.Reactive.Import.Register),
  302. MACROSTR(Energy.Active.Export.Interval),
  303. MACROSTR(Energy.Active.Import.Interval),
  304. MACROSTR(Energy.Reactive.Export.Interval),
  305. MACROSTR(Energy.Reactive.Import.Interval),
  306. MACROSTR(Frequency),
  307. MACROSTR(Power.Active.Export),
  308. MACROSTR(Power.Active.Import),
  309. MACROSTR(Power.Factor),
  310. MACROSTR(Power.Offered),
  311. MACROSTR(Power.Reactive.ExportMACROSTR),
  312. MACROSTR(Power.Reactive.Import),
  313. MACROSTR(RPM),
  314. MACROSTR(SoC),
  315. MACROSTR(Temperature),
  316. MACROSTR(Voltage)
  317. };
  318. static char * LocationStr[] = {
  319. MACROSTR(Body),
  320. MACROSTR(Cable),
  321. MACROSTR(EV),
  322. MACROSTR(Inlet),
  323. MACROSTR(Outlet)
  324. };
  325. static char * PhaseStr[] = {
  326. MACROSTR(L1),
  327. MACROSTR(L2),
  328. MACROSTR(L3),
  329. MACROSTR(N),
  330. MACROSTR(L1-N),
  331. MACROSTR(L2-N),
  332. MACROSTR(L3-N),
  333. MACROSTR(L1-L2),
  334. MACROSTR(L2-L3),
  335. MACROSTR(L3-L1)
  336. };
  337. static char * UnitOfMeasureStr[] = {
  338. MACROSTR(Wh),
  339. MACROSTR(kWh),
  340. MACROSTR(varh),
  341. MACROSTR(kvarh),
  342. MACROSTR(W),
  343. MACROSTR(kW),
  344. MACROSTR(VA),
  345. MACROSTR(kVA),
  346. MACROSTR(var),
  347. MACROSTR(kvar),
  348. MACROSTR(A),
  349. MACROSTR(V),
  350. MACROSTR(Celsius),
  351. MACROSTR(Fahrenheit),
  352. MACROSTR(K),
  353. MACROSTR(Percent)
  354. };
  355. //=========================================
  356. // Save configuration
  357. //=========================================
  358. int runShellCmd(const char*cmd)
  359. {
  360. int result = FAIL;
  361. char buf[256];
  362. FILE *fp;
  363. fp = popen(cmd, "r");
  364. if(fp != NULL)
  365. {
  366. while(fgets(buf, sizeof(buf), fp) != NULL)
  367. {
  368. DEBUG_INFO("%s\n", buf);
  369. }
  370. result = PASS;
  371. }
  372. pclose(fp);
  373. return result;
  374. }
  375. int StoreUsrConfigData(struct SysConfigData *UsrData)
  376. {
  377. int result = PASS;
  378. int fd,wrd;
  379. unsigned int i,Chk;
  380. unsigned char *ptr, *BufTmp;
  381. int MtdBlockSize = 0x300000;
  382. Chk=0;
  383. ptr=(unsigned char *)UsrData;
  384. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  385. {
  386. memset(BufTmp,0,MtdBlockSize);
  387. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  388. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  389. Chk+=*(BufTmp+i);
  390. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  391. // Output configuration to file.
  392. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  393. if (fd < 0)
  394. {
  395. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  396. free(BufTmp);
  397. return 0;
  398. }
  399. wrd=write(fd, BufTmp, MtdBlockSize);
  400. close(fd);
  401. if(wrd<MtdBlockSize)
  402. {
  403. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  404. free(BufTmp);
  405. return 0;
  406. }
  407. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  408. DEBUG_INFO("Erase /dev/mtd10.\n");
  409. runShellCmd("flash_erase /dev/mtd10 0 0");
  410. DEBUG_INFO("Write /dev/mtd10.\n");
  411. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  412. DEBUG_INFO("Erase /dev/mtd11.\n");
  413. runShellCmd("flash_erase /dev/mtd11 0 0");
  414. DEBUG_INFO("Write /dev/mtd11.\n");
  415. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  416. system("rm -f /mnt/EvseConfig.bin");
  417. DEBUG_INFO("EvseConfig write to flash OK\n");
  418. }
  419. else
  420. {
  421. DEBUG_ERROR("alloc BlockSize NG\r\n");
  422. result = FAIL;
  423. }
  424. if(BufTmp!=NULL)
  425. free(BufTmp);
  426. return result;
  427. }
  428. //=========================================
  429. // Sqlite3 related function
  430. //=========================================
  431. static int selectSqlCount = 0;
  432. static int callback(void *data, int argc, char **argv, char **azColName){
  433. int i;
  434. //printf("%s: ", (const char*)data);
  435. selectSqlCount = argc;
  436. for(i = 0; i<argc; i++){
  437. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  438. }
  439. //printf("\n");
  440. return 0;
  441. }
  442. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  443. //int i;
  444. //printf("%s:\n", (const char*)data);
  445. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  446. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  447. return 0;
  448. }
  449. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  450. //printf("%s:\n", (const char*)data);
  451. //idTag
  452. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. //parentIdTag
  455. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  456. //expir_date
  457. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  458. //status
  459. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  460. //version
  461. if(columenCount > 5)
  462. idTagQuery.listVersionInt = atoi(columnValue[5]);
  463. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  464. return 0;
  465. }
  466. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  467. {
  468. // localversion = argv[5] ? atoi(argv[5]) : 0;
  469. // printf("localversion=%d\n", localversion);
  470. return 0;
  471. }
  472. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  473. {
  474. for (int i = 0; i < n_columns; i++)
  475. {
  476. DEBUG_INFO("%s\t", col_values[i]);
  477. }
  478. DEBUG_INFO("\n");
  479. return 0;
  480. }
  481. int OCPP_cleanLocalCache()
  482. {
  483. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  484. char *errMsg = 0;
  485. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  486. if (SQLITE_OK != rc)
  487. {
  488. DEBUG_INFO("SQL error: %s\n",errMsg);
  489. return FALSE;
  490. }
  491. return TRUE;
  492. }
  493. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  494. {
  495. int isSuccess = TRUE;
  496. int ret = 0;
  497. //const char* data = "Callback function called";
  498. char sql[300];
  499. char zErrMsg[200];
  500. memset(sql, 0, 300);
  501. memset(zErrMsg, 0, 200);
  502. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  503. //* Execute SQL statement */
  504. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  505. if( ret != SQLITE_OK )
  506. {
  507. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  508. isSuccess = FALSE;
  509. }
  510. return isSuccess;
  511. }
  512. void OCPP_getIdTagFromLocalCache(char idTag[])
  513. {
  514. int rc = 0;
  515. char sql[100];
  516. char zErrMsg[100];
  517. memset(sql, 0, 100);
  518. memset(zErrMsg, 0, 100);
  519. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  520. memset(&idTagQuery, 0, sizeof(idTagQuery));
  521. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  522. /* Execute SQL statement */
  523. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  524. if( rc != SQLITE_OK )
  525. {
  526. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  527. }
  528. }
  529. void OCPP_getListVerion()
  530. {
  531. int rc = 0;
  532. // const char* data = "Callback function called";
  533. char sql[100];
  534. char zErrMsg[100];
  535. memset(sql, 0, 100);
  536. memset(zErrMsg, 0, 100);
  537. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. }
  545. void OCPP_get_TableAuthlocalAllData(void)
  546. {
  547. int rc = 0;
  548. char sql[100];
  549. char zErrMsg[100];
  550. memset(sql, 0, 100);
  551. memset(zErrMsg, 0, 100);
  552. sprintf(sql,"select * from ocpp_auth_local ");
  553. /* Execute SQL statement */
  554. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  555. if( rc != SQLITE_OK )
  556. {
  557. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  558. }
  559. //return ver;
  560. }
  561. int OCPP_cleanLocalList()
  562. {
  563. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  564. char *errMsg = 0;
  565. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  566. if (SQLITE_OK != rc)
  567. {
  568. DEBUG_INFO("%s\n",errMsg);
  569. return FALSE;
  570. }
  571. return TRUE;
  572. }
  573. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  574. {
  575. int isSuccess = FALSE;
  576. int ret = 0;
  577. //const char* data = "Callback function called";
  578. char sql[300];
  579. char zErrMsg[200];
  580. memset(sql, 0, 300);
  581. memset(zErrMsg, 0, 200);
  582. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  583. //* Execute SQL statement */
  584. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  585. if( ret != SQLITE_OK )
  586. {
  587. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  588. return isSuccess;
  589. }
  590. memset(sql, 0, 300);
  591. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  592. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  593. if( ret != SQLITE_OK )
  594. {
  595. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  596. return isSuccess;
  597. }
  598. isSuccess = TRUE;
  599. return isSuccess;
  600. }
  601. void OCPP_getIdTagFromLocalList(char idTag[])
  602. {
  603. int rc = 0;
  604. // const char* data = "Callback function called";
  605. char sql[100];
  606. char zErrMsg[100];
  607. memset(sql, 0, 100);
  608. memset(zErrMsg, 0, 100);
  609. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  610. memset(&idTagQuery, 0, sizeof(idTagQuery));
  611. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  612. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  613. /* Execute SQL statement */
  614. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  615. if( rc != SQLITE_OK )
  616. {
  617. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  618. }
  619. //return ver;
  620. }
  621. void OCPP_deleteIdTagFromLocalList(char idTag[])
  622. {
  623. //int ver = 0;
  624. //int isSuccess = FALSE;
  625. int rc = 0;
  626. char sql[100];
  627. char zErrMsg[100];
  628. memset(sql, 0, 100);
  629. memset(zErrMsg, 0, 100);
  630. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  631. //* Execute SQL statement */
  632. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  633. if( rc != SQLITE_OK )
  634. {
  635. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  636. }
  637. }
  638. int getCurrentYear()
  639. {
  640. int result = 0;
  641. time_t CurrentTime;
  642. struct tm *tm;
  643. CurrentTime = time(NULL);
  644. tm=localtime(&CurrentTime);
  645. result = (tm->tm_year + 1900);
  646. return result;
  647. }
  648. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  649. {
  650. int result = PASS;
  651. char* errMsg = NULL;
  652. char sqlStr[8192];
  653. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  654. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  655. {
  656. result = FAIL;
  657. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  658. }
  659. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  660. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  661. {
  662. result = FAIL;
  663. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  664. }
  665. return result;
  666. }
  667. //==========================================
  668. // Check time passed since today
  669. //==========================================
  670. long long DiffTimebWithNow(struct timeb ST)
  671. {
  672. //return milli-second
  673. struct timeb ET;
  674. long long StartTime,StopTime;
  675. ftime(&ET);
  676. StartTime=(long long)ST.time;
  677. StopTime=(long long)ET.time;
  678. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  679. }
  680. int getTimePassSinceToday(uint8_t gun_index)
  681. {
  682. int result = -1;
  683. static time_t lastTime[4];
  684. time_t t;
  685. struct tm *tmStartToday;
  686. struct timeb tbStartToday;
  687. t=time(NULL);
  688. if(difftime(t, lastTime[gun_index])>0)
  689. {
  690. tmStartToday=localtime(&t);
  691. tmStartToday->tm_hour = 0;
  692. tmStartToday->tm_min = 0;
  693. tmStartToday->tm_sec = 0;
  694. tbStartToday.time = mktime(tmStartToday);
  695. tbStartToday.millitm = 0;
  696. result = DiffTimebWithNow(tbStartToday)/1000;
  697. lastTime[gun_index] = t;
  698. }
  699. return result;
  700. }
  701. void getNowDatetime(uint8_t *data)
  702. {
  703. time_t t = time(NULL);
  704. struct tm tm = *localtime(&t);
  705. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  706. }
  707. int syncDateTimeRTC(uint8_t *data)
  708. {
  709. struct ParsingResult
  710. {
  711. int result;
  712. int scanedElement;
  713. int year;
  714. int month;
  715. int mday;
  716. int hour;
  717. int min;
  718. int sec;
  719. int tz_hour;
  720. int tz_min;
  721. float minSec;
  722. }result;
  723. struct tm tmOrg;
  724. struct tm *tmTarget;
  725. struct timeb tbTarget;
  726. char buf[128];
  727. memset(&result, 0x00, sizeof(struct ParsingResult));
  728. result.result = PASS;
  729. if(strstr((char*)data, ".") != NULL)
  730. {
  731. // Original data with mini second
  732. if(strstr((char*)data, "Z") != NULL)
  733. {
  734. // Original data with Z
  735. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  736. &result.year,
  737. &result.month,
  738. &result.mday,
  739. &result.hour,
  740. &result.min,
  741. &result.sec,
  742. &result.minSec);
  743. }
  744. else
  745. {
  746. // Original data without Z
  747. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  748. &result.year,
  749. &result.month,
  750. &result.mday,
  751. &result.hour,
  752. &result.min,
  753. &result.sec,
  754. &result.minSec,
  755. &result.tz_hour,
  756. &result.tz_min);
  757. }
  758. }
  759. else
  760. {
  761. // Original data without mini second
  762. if(strstr((char*)data, "Z") != NULL)
  763. {
  764. // Original data with Z
  765. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  766. &result.year,
  767. &result.month,
  768. &result.mday,
  769. &result.hour,
  770. &result.min,
  771. &result.sec);
  772. }
  773. else
  774. {
  775. // Original data without Z
  776. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  777. &result.year,
  778. &result.month,
  779. &result.mday,
  780. &result.hour,
  781. &result.min,
  782. &result.sec,
  783. &result.tz_hour,
  784. &result.tz_min);
  785. }
  786. }
  787. tmOrg.tm_year = result.year - 1900;
  788. tmOrg.tm_mon = result.month - 1;
  789. tmOrg.tm_mday = result.mday;
  790. tmOrg.tm_hour = result.hour;
  791. tmOrg.tm_min = result.min;
  792. tmOrg.tm_sec = result.sec;
  793. tmOrg.tm_gmtoff = 0;
  794. tbTarget.time = mktime(&tmOrg);
  795. tbTarget.timezone = 0;
  796. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  797. tmTarget = gmtime(&tbTarget.time);
  798. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  799. //DEBUG_INFO(" org date time: %s\n", data);
  800. //DEBUG_INFO("parse date time: %s\n", buf);
  801. system(buf);
  802. system("/sbin/hwclock -w --systohc");
  803. if(result.scanedElement < 6)
  804. result.result = FAIL;
  805. return result.result;
  806. }
  807. //==========================================
  808. // GetCompositeSchedule logic related function
  809. //==========================================
  810. int DiffTimebSec(struct timeb ST, struct timeb ET)
  811. {
  812. //return milli-second
  813. unsigned int StartTime,StopTime;
  814. StartTime=(unsigned int)ST.time;
  815. StopTime=(unsigned int)ET.time;
  816. return (StopTime-StartTime);
  817. }
  818. int DiffTimebWithNowSec(struct timeb ST)
  819. {
  820. //return milli-second
  821. struct timeb ET;
  822. unsigned int StartTime,StopTime;
  823. ftime(&ET);
  824. StartTime=(unsigned int)ST.time;
  825. StopTime=(unsigned int)ET.time;
  826. return (StopTime-StartTime);
  827. }
  828. int getStartStop(uint8_t *start, uint8_t *stop)
  829. {
  830. int result = -1;
  831. struct tm tmStart;
  832. struct timeb tbStart;
  833. struct tm tmStop;
  834. struct timeb tbStop;
  835. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  836. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  837. {
  838. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  839. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  840. tmStart.tm_year -= 1900;
  841. tmStart.tm_mon -= 1;
  842. tbStart.time = mktime(&tmStart);
  843. tbStart.millitm = 0;
  844. tmStop.tm_year -= 1900;
  845. tmStop.tm_mon -= 1;
  846. tbStop.time = mktime(&tmStop);
  847. tbStop.millitm = 0;
  848. result = DiffTimebSec(tbStart, tbStop);
  849. //DEBUG_INFO("getStartStop(): %d\n", result);
  850. }
  851. else
  852. {
  853. DEBUG_WARN("Start or stop date parsing error.\r\n");
  854. }
  855. return result;
  856. }
  857. int isOvertNow(uint8_t *start)
  858. {
  859. int result = NO;
  860. struct tm tmStart;
  861. struct timeb tbStart;
  862. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  863. {
  864. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  865. tmStart.tm_year -= 1900;
  866. tmStart.tm_mon -= 1;
  867. tbStart.time = mktime(&tmStart);
  868. tbStart.millitm = 0;
  869. if(DiffTimebWithNowSec(tbStart) <= 0)
  870. result = NO;
  871. else
  872. result = YES;
  873. }
  874. else
  875. {
  876. DEBUG_WARN("Start date parsing error.\n");
  877. }
  878. return result;
  879. }
  880. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  881. {
  882. int result = -1;
  883. struct tm tmStart;
  884. struct timeb tbStart;
  885. struct tm tmStop;
  886. struct timeb tbStop;
  887. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  888. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  889. {
  890. tmStart.tm_year -= 1900;
  891. tmStart.tm_mon -= 1;
  892. tbStart.time = mktime(&tmStart);
  893. tbStart.millitm = 0;
  894. tmStop.tm_year -= 1900;
  895. tmStop.tm_mon -= 1;
  896. tbStop.time = mktime(&tmStop);
  897. tbStop.millitm = 0;
  898. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  899. }
  900. return result;
  901. }
  902. void 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. // Charger start transaction
  2596. //==============================================
  2597. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2598. {
  2599. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2600. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  2601. sendStartTransactionRequest(gun_index);
  2602. clientTime.StartTransaction = time((time_t*)NULL);
  2603. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2604. storeTempStopTransaction(gun_index);
  2605. }
  2606. //==============================================
  2607. // Charger stop transaction
  2608. //==============================================
  2609. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2610. {
  2611. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2612. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  2613. sendStopTransactionRequest(gun_index);
  2614. clientTime.StopTransaction = time((time_t*)NULL);
  2615. }
  2616. //==============================================
  2617. // Charger status report
  2618. //==============================================
  2619. //--- Check Mode Change ---//
  2620. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2621. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2622. {
  2623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2624. {
  2625. tempIndex = ((gun_index==2) ? 1: 0);
  2626. }
  2627. else
  2628. {
  2629. tempIndex = gun_index;
  2630. }
  2631. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2632. {
  2633. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2634. {
  2635. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2636. {
  2637. // Sent unplug message for California pricing logic
  2638. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2639. {
  2640. uint8_t ts[20];
  2641. getNowDatetime(ts);
  2642. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2643. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2644. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2645. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2646. }
  2647. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2648. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2649. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2650. }
  2651. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2652. {
  2653. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2654. if((access(filenmae,F_OK))!=-1)
  2655. {
  2656. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2657. sprintf(str,"rm -f %s",filenmae);
  2658. system(str);
  2659. }
  2660. }
  2661. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2662. #if 1 // for TempStopTransaction
  2663. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2664. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2665. {
  2666. checkTempStopTransaction(gun_index);
  2667. }
  2668. #endif
  2669. }
  2670. }
  2671. }
  2672. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2673. {
  2674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2675. {
  2676. tempIndex = ((gun_index==2) ? 1: 0);
  2677. }
  2678. else
  2679. {
  2680. tempIndex = gun_index;
  2681. }
  2682. for (int index = 0; index < CCS_QUANTITY; index++)
  2683. {
  2684. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2685. {
  2686. 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]*/ )
  2687. {
  2688. // Sent unplug message for California pricing logic
  2689. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2690. {
  2691. uint8_t ts[20];
  2692. getNowDatetime(ts);
  2693. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2694. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2695. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2696. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2697. }
  2698. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2699. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2700. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2701. }
  2702. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2703. {
  2704. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2705. if((access(filenmae,F_OK))!=-1)
  2706. {
  2707. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2708. sprintf(str,"rm -f %s",filenmae);
  2709. system(str);
  2710. }
  2711. }
  2712. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2713. #if 1 // for TempStopTransaction
  2714. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2715. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2716. {
  2717. checkTempStopTransaction(gun_index);
  2718. }
  2719. #endif
  2720. }
  2721. }
  2722. }
  2723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2724. {
  2725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2726. {
  2727. tempIndex = ((gun_index==2) ? 1: 0);
  2728. }
  2729. else
  2730. {
  2731. tempIndex = gun_index;
  2732. }
  2733. for (int index = 0; index < GB_QUANTITY; index++)
  2734. {
  2735. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2736. {
  2737. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2738. {
  2739. // Sent unplug message for California pricing logic
  2740. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2741. {
  2742. uint8_t ts[20];
  2743. getNowDatetime(ts);
  2744. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2745. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2746. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2747. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2748. }
  2749. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2750. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2751. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2752. }
  2753. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2754. {
  2755. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2756. if((access(filenmae,F_OK))!=-1)
  2757. {
  2758. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2759. sprintf(str,"rm -f %s",filenmae);
  2760. system(str);
  2761. }
  2762. }
  2763. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2764. #if 1 // for TempStopTransaction
  2765. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2766. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2767. {
  2768. checkTempStopTransaction(gun_index);
  2769. }
  2770. #endif
  2771. }
  2772. }
  2773. }
  2774. else if(gunType[gun_index] == GUN_TYPE_DO)
  2775. {
  2776. tempIndex = gun_index;
  2777. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2778. {
  2779. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2780. {
  2781. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2782. {
  2783. // Sent unplug message for California pricing logic
  2784. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2785. {
  2786. uint8_t ts[20];
  2787. getNowDatetime(ts);
  2788. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2789. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2790. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2791. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2792. }
  2793. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2794. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2795. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2796. }
  2797. 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
  2798. {
  2799. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2800. if((access(filenmae,F_OK))!=-1)
  2801. {
  2802. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2803. sprintf(str,"rm -f %s",filenmae);
  2804. system(str);
  2805. }
  2806. }
  2807. 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);
  2808. #if 1 // for TempStopTransaction
  2809. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2810. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2811. {
  2812. checkTempStopTransaction(gun_index);
  2813. }
  2814. #endif
  2815. }
  2816. }
  2817. }
  2818. else
  2819. {
  2820. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2821. {
  2822. tempIndex = 2;
  2823. }
  2824. else
  2825. {
  2826. tempIndex = gun_index;
  2827. }
  2828. for (int index = 0; index < AC_QUANTITY; index++)
  2829. {
  2830. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2831. {
  2832. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2833. {
  2834. // Sent unplug message for California pricing logic
  2835. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2836. {
  2837. uint8_t ts[20];
  2838. getNowDatetime(ts);
  2839. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2840. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2841. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2842. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2843. }
  2844. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2845. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2846. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2847. }
  2848. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2849. {
  2850. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2851. if((access(filenmae,F_OK))!=-1)
  2852. {
  2853. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2854. sprintf(str,"rm -f %s",filenmae);
  2855. system(str);
  2856. }
  2857. }
  2858. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2859. #if 1 // for TempStopTransaction
  2860. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2861. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2862. {
  2863. checkTempStopTransaction(gun_index);
  2864. }
  2865. #endif
  2866. }
  2867. }// END
  2868. }
  2869. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  2870. (
  2871. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  2872. )
  2873. )
  2874. {
  2875. if(SystemInitial > 0)
  2876. SystemInitial -= 1;
  2877. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  2878. sendStatusNotificationRequest(gun_index);
  2879. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2880. }
  2881. //==============================================
  2882. // CSU Trigger Smart Charging Profilw
  2883. //==============================================
  2884. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2885. {
  2886. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  2887. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  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[0]=='D'))
  7384. {
  7385. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  7386. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  7387. (gunType[3] != GUN_TYPE_UNKNOWN))
  7388. {
  7389. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7390. }
  7391. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  7392. {
  7393. // DS DM DW
  7394. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7395. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7396. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7397. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7398. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7399. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7400. }
  7401. else
  7402. {
  7403. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7404. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7405. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7406. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7407. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7408. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7409. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7410. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7411. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7412. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7413. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7414. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7415. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7416. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7417. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7418. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7419. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7420. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7421. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7422. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7423. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7424. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7425. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7426. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7427. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7428. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7429. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7430. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7431. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7432. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7433. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7434. }
  7435. }
  7436. // 4G model
  7437. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7438. {
  7439. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7440. }
  7441. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7442. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7443. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7444. json_object_put(FirmwareDataTransfer);
  7445. }
  7446. int handleDataTransferRequest(char *uuid, char *payload)
  7447. {
  7448. mtrace();
  7449. json_object *response = json_object_new_object();
  7450. int result = FAIL;
  7451. char tempvendorId[255]={0};
  7452. char tempmessageId[50]={0};
  7453. char tempdata[512]={0};
  7454. char message[2048]={0};
  7455. DEBUG_INFO("handleDataTransferRequest...\n");
  7456. if((uuid != NULL) && (payload != NULL))
  7457. {
  7458. json_object *DataTransfer;
  7459. DataTransfer = json_tokener_parse(payload);
  7460. if(!is_error(DataTransfer))
  7461. {
  7462. // Required data
  7463. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7464. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7465. // Optional data
  7466. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7467. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7468. if(json_object_object_get(DataTransfer, "data") != NULL)
  7469. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7470. result = PASS;
  7471. }
  7472. json_object_put(DataTransfer);
  7473. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7474. {
  7475. // Send all moudle firmware version on EVSE
  7476. createFirmwareVersionByDataTransfer();
  7477. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7478. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  7479. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7480. json_object_put(response);
  7481. }
  7482. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7483. {
  7484. system("/usr/bin/run_tmate_restart.sh &");
  7485. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7486. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7487. json_object_put(response);
  7488. }
  7489. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7490. {
  7491. json_object *data;
  7492. data = json_tokener_parse(tempdata);
  7493. if(!is_error(data))
  7494. {
  7495. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7496. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7497. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7498. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7499. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7500. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7501. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7502. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7503. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7504. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7505. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7506. }
  7507. else
  7508. {
  7509. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7510. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7511. }
  7512. json_object_put(data);
  7513. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7514. json_object_put(response);
  7515. }
  7516. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7517. {
  7518. json_object *data;
  7519. data = json_tokener_parse(tempdata);
  7520. if(!is_error(data))
  7521. {
  7522. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7523. if(json_object_object_get(data, "idToken") != NULL)
  7524. {
  7525. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7526. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7527. }
  7528. if(json_object_object_get(data, "price") != NULL)
  7529. {
  7530. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7531. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7532. }
  7533. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7534. }
  7535. else
  7536. {
  7537. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7538. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7539. }
  7540. json_object_put(data);
  7541. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7542. json_object_put(response);
  7543. }
  7544. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7545. {
  7546. json_object *data;
  7547. data = json_tokener_parse(tempdata);
  7548. if(!is_error(data))
  7549. {
  7550. if(json_object_object_get(data, "txId") != NULL)
  7551. {
  7552. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7553. for(int idx = 0;idx<gunTotalNumber;idx++)
  7554. {
  7555. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7556. {
  7557. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7558. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7559. if(json_object_object_get(data, "description") != NULL)
  7560. {
  7561. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7562. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7563. }
  7564. }
  7565. }
  7566. }
  7567. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7568. }
  7569. else
  7570. {
  7571. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7572. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7573. }
  7574. json_object_put(data);
  7575. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7576. json_object_put(response);
  7577. }
  7578. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7579. {
  7580. json_object *data;
  7581. data = json_tokener_parse(tempdata);
  7582. if(!is_error(data))
  7583. {
  7584. if(json_object_object_get(data, "txId") != NULL)
  7585. {
  7586. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7587. for(int idx = 0;idx<gunTotalNumber;idx++)
  7588. {
  7589. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7590. {
  7591. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7592. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7593. if(json_object_object_get(data, "description") != NULL)
  7594. {
  7595. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7596. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7597. }
  7598. }
  7599. }
  7600. }
  7601. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7602. }
  7603. else
  7604. {
  7605. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7606. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7607. }
  7608. json_object_put(data);
  7609. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7610. json_object_put(response);
  7611. }
  7612. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7613. {
  7614. json_object *data;
  7615. data = json_tokener_parse(tempdata);
  7616. if(!is_error(data))
  7617. {
  7618. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7619. if(json_object_object_get(data, "Content_Type") != NULL)
  7620. {
  7621. 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))
  7622. {
  7623. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7624. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7625. {
  7626. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7627. }
  7628. }
  7629. else
  7630. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7631. }
  7632. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7633. }
  7634. else
  7635. {
  7636. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7637. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7638. }
  7639. json_object_put(data);
  7640. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7641. json_object_put(response);
  7642. }
  7643. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7644. {
  7645. json_object *data;
  7646. data = json_tokener_parse(tempdata);
  7647. if(!is_error(data))
  7648. {
  7649. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7650. if(json_object_object_get(data, "Page_Index") != NULL)
  7651. {
  7652. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7653. }
  7654. if(json_object_object_get(data, "Duration") != NULL)
  7655. {
  7656. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7657. }
  7658. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7659. }
  7660. else
  7661. {
  7662. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7663. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7664. }
  7665. json_object_put(data);
  7666. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7667. json_object_put(response);
  7668. }
  7669. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  7670. {
  7671. json_object *data;
  7672. data = json_tokener_parse(tempdata);
  7673. if(!is_error(data))
  7674. {
  7675. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7676. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  7677. {
  7678. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  7679. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  7680. else
  7681. {
  7682. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7683. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7684. }
  7685. }
  7686. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  7687. {
  7688. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  7689. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  7690. else
  7691. {
  7692. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7693. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7694. }
  7695. }
  7696. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  7697. {
  7698. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  7699. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  7700. else
  7701. {
  7702. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7703. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7704. }
  7705. }
  7706. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  7707. {
  7708. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  7709. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  7710. else
  7711. {
  7712. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7713. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7714. }
  7715. }
  7716. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  7717. {
  7718. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  7719. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  7720. else
  7721. {
  7722. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7723. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7724. }
  7725. }
  7726. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  7727. {
  7728. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  7729. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  7730. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  7731. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  7732. else
  7733. {
  7734. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7735. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7736. }
  7737. }
  7738. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  7739. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7740. }
  7741. else
  7742. {
  7743. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7744. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7745. }
  7746. json_object_put(data);
  7747. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7748. json_object_put(response);
  7749. }
  7750. else
  7751. {
  7752. // Can not find valid message id
  7753. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7754. }
  7755. }
  7756. else
  7757. {
  7758. // Payload is null
  7759. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7760. }
  7761. LWS_Send(message);
  7762. return result;
  7763. }
  7764. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7765. {
  7766. mtrace();
  7767. int result = FAIL;
  7768. int connectorIdInt, durationInt;
  7769. char chargingRateUnitStr[4]={0};
  7770. char comfirmstr[20];
  7771. int confirmPeriods = 0;
  7772. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7773. json_object *GetCompositeSchedule;
  7774. GetCompositeSchedule = json_tokener_parse(payload);
  7775. if(!is_error(GetCompositeSchedule))
  7776. {
  7777. // Required data
  7778. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7779. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7780. else
  7781. connectorIdInt = -1;
  7782. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7783. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7784. else
  7785. durationInt = 86400;
  7786. // Optional data
  7787. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7788. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7789. }
  7790. json_object_put(GetCompositeSchedule);
  7791. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7792. if((connectorIdInt == 0) ||
  7793. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7794. {
  7795. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7796. struct StructChargingProfile tmpProfile[1];
  7797. if(strstr(chargingRateUnitStr, "W") != NULL)
  7798. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7799. else
  7800. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7801. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7802. {
  7803. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7804. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7805. }
  7806. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7807. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7808. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7809. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7810. {
  7811. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7812. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7813. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7814. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7815. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7816. {
  7817. confirmPeriods = idx;
  7818. break;
  7819. }
  7820. }
  7821. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7822. {
  7823. confirmPeriods += 1;
  7824. }
  7825. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7826. }
  7827. else
  7828. {
  7829. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7830. }
  7831. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7832. return result;
  7833. }
  7834. int handleGetConfigurationRequest(char *uuid, char *payload)
  7835. {
  7836. mtrace();
  7837. int result = FAIL;
  7838. int MaxKeySupported = 0;
  7839. int n_keys = 0;
  7840. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7841. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7842. json_object *GetConfiguration;
  7843. GetConfiguration = json_tokener_parse(payload);
  7844. if(!is_error(GetConfiguration))
  7845. {
  7846. // Optional data
  7847. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7848. {
  7849. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7850. {
  7851. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7852. n_keys = idx + 1;
  7853. }
  7854. }
  7855. }
  7856. json_object_put(GetConfiguration);
  7857. UnknownKeynum = 0;
  7858. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7859. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7860. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7861. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7862. if(n_keys != 0)
  7863. {
  7864. for(int i=0;i<n_keys;i++)
  7865. {
  7866. getKeyValue(requestKey[i]);
  7867. }
  7868. }
  7869. else
  7870. {
  7871. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7872. getKeyValue("");
  7873. }
  7874. processUnkownKey();
  7875. sendGetConfigurationConfirmation(uuid);
  7876. return result;
  7877. }
  7878. static char fnamePlusPath[100]={0};
  7879. static char fnamePWithNoPath[60]={0};
  7880. void checkUploadLog(void)
  7881. {
  7882. FILE *fp;
  7883. /* Open the command for reading. */
  7884. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7885. if (fp == NULL) {
  7886. DEBUG_WARN("Failed to run command\n" );
  7887. exit(1);
  7888. }
  7889. int ftppathlen = 0;
  7890. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7891. int i = 0;
  7892. /* Read the output a line at a time - output it. */
  7893. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7894. if(i==0)
  7895. {
  7896. ftppathlen = strlen(fnamePlusPath);
  7897. DEBUG_INFO("%s\n", fnamePlusPath);
  7898. fnamePlusPath[ftppathlen]='\0';
  7899. break;
  7900. }
  7901. i= i+1;
  7902. }
  7903. /* close */
  7904. pclose(fp);
  7905. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7906. {
  7907. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7908. {
  7909. fnamePlusPath[k]='\0';
  7910. }
  7911. }
  7912. i=1;
  7913. //char fname[60]={0};
  7914. while(i < ftppathlen)
  7915. {
  7916. int len=ftppathlen-i;
  7917. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7918. {
  7919. DEBUG_INFO("compare '/' all right\n");
  7920. break;
  7921. }
  7922. i=i+1;
  7923. }
  7924. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7925. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7926. fnamePWithNoPath[i+1] = '\0';
  7927. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7928. {
  7929. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7930. {
  7931. fnamePWithNoPath[j]='\0';
  7932. }
  7933. }
  7934. FILE* fp1 = fopen(fnamePlusPath, "r");
  7935. if (fp1)
  7936. {
  7937. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7938. // file exists
  7939. fclose(fp1);
  7940. }
  7941. else
  7942. {
  7943. // file doesn't exist
  7944. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7945. }
  7946. }
  7947. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7948. {
  7949. mtrace();
  7950. int result = FAIL;
  7951. time_t CurrentTime;
  7952. struct tm *tm;
  7953. pthread_t th_Status;
  7954. CurrentTime = time(NULL);
  7955. tm = localtime(&CurrentTime);
  7956. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  7957. 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);
  7958. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  7959. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7960. return result;
  7961. }
  7962. void* GetDiagnosticsProcess(void* data)
  7963. {
  7964. pthread_detach(pthread_self());
  7965. mtrace();
  7966. int retriesInt=0, retryIntervalInt=0;
  7967. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7968. 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};
  7969. int port=0;
  7970. int isSuccess = FALSE;
  7971. char ftpbuf[200]={0};
  7972. char cmdBuf[2048];
  7973. struct tm *tmNow;
  7974. time_t CurrentTime;
  7975. struct tm tmStart;
  7976. struct tm tmStop;
  7977. CurrentTime = time(NULL);
  7978. tmNow=localtime(&CurrentTime);
  7979. uint16_t targetYear, targetMonth;
  7980. json_object *GetDiagnostics;
  7981. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7982. GetDiagnostics = json_tokener_parse(data);
  7983. if(!is_error(GetDiagnostics))
  7984. {
  7985. // Required data
  7986. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7987. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7988. // Optional data
  7989. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7990. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7991. else
  7992. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7993. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7994. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7995. else
  7996. retryIntervalInt = 30;
  7997. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7998. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7999. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8000. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8001. }
  8002. json_object_put(GetDiagnostics);
  8003. // Pack log to compress file
  8004. 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) &&
  8005. (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))
  8006. {
  8007. // Pack system log
  8008. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8009. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8010. targetYear = tmStart.tm_year;
  8011. targetMonth = tmStart.tm_mon;
  8012. do
  8013. {
  8014. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8015. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8016. if(targetMonth+1>=13)
  8017. {
  8018. targetYear += 1;
  8019. targetMonth = 1;
  8020. }
  8021. else
  8022. {
  8023. targetMonth += 1;
  8024. }
  8025. }while((targetYear < (tmNow->tm_year+1900)) ||
  8026. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8027. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8028. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8029. system(cmdBuf);
  8030. // Pack charging & event log
  8031. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8032. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8033. targetYear = tmStart.tm_year;
  8034. targetMonth = tmStart.tm_mon;
  8035. do
  8036. {
  8037. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8038. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8039. if(targetMonth+1>=13)
  8040. {
  8041. targetYear += 1;
  8042. targetMonth = 1;
  8043. }
  8044. else
  8045. {
  8046. targetMonth += 1;
  8047. }
  8048. }while((targetYear < (tmNow->tm_year+1900)) ||
  8049. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8050. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8051. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8052. system(cmdBuf);
  8053. // Combine log file
  8054. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8055. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8056. }
  8057. else
  8058. {
  8059. system("exec /root/logPackTools 'log' 6");
  8060. }
  8061. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8062. system(cmdBuf);
  8063. checkUploadLog();
  8064. //****************location*******************/
  8065. if(strcmp(locationstr,"")==0)
  8066. {
  8067. DEBUG_INFO("location is <Empty>!\n");
  8068. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8069. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8070. goto end;
  8071. }
  8072. memset(protocol, 0, ARRAY_SIZE(protocol));
  8073. memset(user, 0, ARRAY_SIZE(user) );
  8074. memset(password, 0, ARRAY_SIZE(password));
  8075. memset(host, 0, ARRAY_SIZE(host));
  8076. memset(path, 0, ARRAY_SIZE(path));
  8077. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8078. memset(host1, 0, ARRAY_SIZE(host1));
  8079. memset(path1, 0, ARRAY_SIZE(path1));
  8080. /*location: ftp://user:password@host:port/path*/
  8081. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8082. if((access(fnamePlusPath,F_OK))!=-1)
  8083. {
  8084. DEBUG_INFO("fnamePlusPath exist.\n");
  8085. }
  8086. else
  8087. {
  8088. DEBUG_INFO("fnamePlusPath not exist!\n");
  8089. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8090. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8091. goto end;
  8092. }
  8093. if(strchr(locationstr,'@')==NULL)
  8094. {
  8095. sscanf(locationstr,
  8096. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8097. protocol, host, &port, path);
  8098. strcpy(user,"anonymous");
  8099. strcpy(password,"");
  8100. }
  8101. else
  8102. {
  8103. //DEBUG_INFO("pch=%s\n", pch);
  8104. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8105. protocol, user, password, host, &port, path);
  8106. }
  8107. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8108. {
  8109. DEBUG_INFO("protocol is not ftp/http ! \n");
  8110. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8111. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8112. goto end;
  8113. }
  8114. if(strncmp(locationstr,"http", 4) == 0)
  8115. {
  8116. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8117. sprintf(ftppath,"/%s", path);
  8118. do
  8119. {
  8120. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8121. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8122. sleep(3);
  8123. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8124. if(!isSuccess)
  8125. {
  8126. DEBUG_INFO("Diagnostics fail.\n");
  8127. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8128. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8129. sleep(retryIntervalInt);
  8130. }
  8131. else
  8132. {
  8133. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8134. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8135. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8136. }
  8137. retriesInt--;
  8138. }while((isSuccess == 0)&&(retriesInt >= 0));
  8139. }
  8140. else
  8141. {
  8142. sscanf(host,"%[^/]%s",host1, path1);
  8143. if(strlen(path) > 0)
  8144. sprintf(ftppath,"/%s", path);
  8145. else
  8146. sprintf(ftppath,"/%s", path1);
  8147. int ftppathlen=strlen(ftppath);
  8148. int i=1;
  8149. char filenametemp[50];
  8150. while(i < ftppathlen)
  8151. {
  8152. int len=ftppathlen-i;
  8153. if(ftppath[len]== 47) // '/' ascll code: 47
  8154. {
  8155. DEBUG_INFO("find '/' all right\n");
  8156. break;
  8157. }
  8158. i=i+1;
  8159. }
  8160. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8161. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8162. filenametemp[i+1] = 0;
  8163. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  8164. if(port == 0)
  8165. port = 21;
  8166. do
  8167. {
  8168. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8169. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8170. sleep(3);
  8171. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8172. if(!isSuccess)
  8173. {
  8174. DEBUG_INFO("Diagnostics fail.\n");
  8175. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8176. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8177. sleep(retryIntervalInt);
  8178. }
  8179. else
  8180. {
  8181. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8182. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8183. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8184. }
  8185. retriesInt--;
  8186. }while((!isSuccess)&&(retriesInt >= 0));
  8187. }
  8188. end:
  8189. system("rm -f /mnt/*");
  8190. sleep(5);
  8191. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8192. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8193. pthread_exit(NULL);
  8194. }
  8195. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8196. {
  8197. mtrace();
  8198. int result = FAIL;
  8199. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8200. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8201. {
  8202. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8203. locallistVersion = -1;
  8204. }
  8205. else
  8206. {
  8207. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8208. OCPP_getListVerion();
  8209. }
  8210. //from db.OCPP_getListVerion
  8211. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  8212. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  8213. sendGetLocalListVersionConfirmation(uuid,"");
  8214. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  8215. return result;
  8216. }
  8217. int handleRemoteStartRequest(char *uuid, char *payload)
  8218. {
  8219. mtrace();
  8220. int result = FAIL;
  8221. int connectorIdInt=0;
  8222. int tempIndex = 0;
  8223. int connectorIdIsNULL, chargingProfileIsNULL;
  8224. char comfirmstr[20]={0};
  8225. char cmdBuf[512];
  8226. json_object *RemoteStartTransaction;
  8227. FILE *fp;
  8228. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8229. if(server_pending == TRUE)
  8230. {
  8231. return 0;
  8232. }
  8233. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8234. RemoteStartTransaction = json_tokener_parse(payload);
  8235. if(!is_error(RemoteStartTransaction))
  8236. {
  8237. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8238. {
  8239. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8240. if(connectorIdInt <= gunTotalNumber)
  8241. {
  8242. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8243. // Required data
  8244. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8245. // Optional data
  8246. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8247. {
  8248. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8249. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8250. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8251. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8252. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8253. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8254. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8255. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8256. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8257. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8258. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8259. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8260. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8261. {
  8262. 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")));
  8263. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8264. 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"));
  8265. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8266. 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"));
  8267. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8268. 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")));
  8269. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8270. {
  8271. 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++)
  8272. {
  8273. 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"));
  8274. 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"));
  8275. 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)
  8276. 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"));
  8277. }
  8278. }
  8279. }
  8280. }
  8281. else
  8282. chargingProfileIsNULL = TRUE;
  8283. }
  8284. }
  8285. else
  8286. connectorIdIsNULL = TRUE;
  8287. }
  8288. else
  8289. connectorIdIsNULL = TRUE;
  8290. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8291. {
  8292. DEBUG_WARN("Connector id is NULL\n.");
  8293. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8294. goto end;
  8295. }
  8296. /*
  8297. enum _SYSTEM_STATUS
  8298. {
  8299. S_BOOTING = 0,
  8300. S_IDLE, = 1
  8301. S_AUTHORIZING, = 2
  8302. S_REASSIGN_CHECK, = 3
  8303. S_REASSIGN, = 4
  8304. S_PRECHARGE, = 5
  8305. S_PREPARING_FOR_EV, = 6
  8306. S_PREPARING_FOR_EVSE, = 7
  8307. S_CHARGING, = 8
  8308. S_TERMINATING, = 9
  8309. S_COMPLETE, = 10
  8310. S_ALARM, = 11
  8311. S_FAULT = 12
  8312. }
  8313. */
  8314. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8315. {
  8316. //check Transaction active
  8317. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8318. {
  8319. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8320. {
  8321. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8322. }
  8323. else
  8324. {
  8325. tempIndex = connectorIdInt -1;
  8326. }
  8327. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8328. {
  8329. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8330. {
  8331. 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))
  8332. {
  8333. //Reserved
  8334. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8335. }
  8336. 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))
  8337. {
  8338. //Reserved
  8339. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8340. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8341. goto end;
  8342. }
  8343. else
  8344. {
  8345. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8346. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8347. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8348. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8349. {
  8350. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8351. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8352. goto end;
  8353. }
  8354. }//END FOR ELSE
  8355. }
  8356. }// END FOR CHAdeMO_QUANTITY
  8357. }
  8358. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8359. {
  8360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8361. {
  8362. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8363. }
  8364. else
  8365. {
  8366. tempIndex = connectorIdInt -1;
  8367. }
  8368. for (int index = 0; index < CCS_QUANTITY; index++)
  8369. {
  8370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8371. {
  8372. 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))
  8373. {
  8374. //Reserved
  8375. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8376. }
  8377. 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))
  8378. {
  8379. //Reserved
  8380. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8381. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8382. goto end;
  8383. }
  8384. else
  8385. {
  8386. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8387. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8388. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8389. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8390. {
  8391. DEBUG_WARN("CCS connector not allow start\n.");
  8392. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8393. goto end;
  8394. }
  8395. }// END FOR ELSE
  8396. }
  8397. }// END FOR CCS_QUANTITY
  8398. }
  8399. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8400. {
  8401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8402. {
  8403. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8404. }
  8405. else
  8406. {
  8407. tempIndex = connectorIdInt -1;
  8408. }
  8409. for (int index = 0; index < GB_QUANTITY; index++)
  8410. {
  8411. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8412. {
  8413. 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))
  8414. {
  8415. //Reserved
  8416. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8417. }
  8418. 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))
  8419. {
  8420. //Reserved
  8421. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8422. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8423. goto end;
  8424. }
  8425. else
  8426. {
  8427. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8428. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8429. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8430. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8431. {
  8432. DEBUG_WARN("GB connector not allow start\n.");
  8433. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8434. goto end;
  8435. }
  8436. }// END FOR ELSE
  8437. }
  8438. } // END FOR GB_QUANTITY
  8439. }
  8440. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8441. {
  8442. tempIndex = connectorIdInt -1;
  8443. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8444. {
  8445. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8446. {
  8447. 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))
  8448. {
  8449. //Reserved
  8450. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8451. }
  8452. 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))
  8453. {
  8454. //Reserved
  8455. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8456. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8457. goto end;
  8458. }
  8459. else
  8460. {
  8461. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8462. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8463. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8464. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8465. {
  8466. DEBUG_WARN("GB connector not allow start\n.");
  8467. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8468. goto end;
  8469. }
  8470. }// END FOR ELSE
  8471. }
  8472. } // END FOR GB_QUANTITY
  8473. }
  8474. else
  8475. {
  8476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8477. {
  8478. tempIndex = 2;
  8479. }
  8480. else
  8481. {
  8482. tempIndex = connectorIdInt -1;
  8483. }
  8484. for (int index = 0; index < AC_QUANTITY; index++)
  8485. {
  8486. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8487. {
  8488. 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))
  8489. {
  8490. //Reserved
  8491. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8492. }
  8493. 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))
  8494. {
  8495. //Reserved
  8496. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8498. goto end;
  8499. }
  8500. else
  8501. {
  8502. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8503. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8504. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8505. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8506. {
  8507. DEBUG_WARN("AC connector not allow start\n.");
  8508. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8509. goto end;
  8510. }
  8511. }//END FOR ELSE
  8512. }
  8513. }// END FOR AC_QUANTITY
  8514. }
  8515. if(chargingProfileIsNULL == FALSE)
  8516. {
  8517. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8518. {
  8519. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8520. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8521. //memset idTag
  8522. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8523. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8524. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8525. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8526. // Save profile to file
  8527. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8528. system(cmdBuf);
  8529. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8530. fp = fopen(cmdBuf, "w");
  8531. 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));
  8532. fclose(fp);
  8533. }
  8534. else
  8535. {
  8536. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8537. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8538. }
  8539. }
  8540. else
  8541. {
  8542. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8543. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8544. //memset idTag
  8545. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8546. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8547. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8548. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8549. }
  8550. }
  8551. else
  8552. {
  8553. DEBUG_WARN("Connector id over\n.");
  8554. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8555. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8556. }
  8557. end:
  8558. json_object_put(RemoteStartTransaction);
  8559. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8560. {
  8561. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8562. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8563. }
  8564. //OCPP send RemoteStartConfirmation by first.
  8565. sendRemoteStartConfirmation(uuid, comfirmstr);
  8566. return result;
  8567. }
  8568. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8569. {
  8570. mtrace();
  8571. int result = FAIL;
  8572. int match = FALSE;
  8573. int GunNO = 0;
  8574. int tempIndex = 0;
  8575. int transactionIdInt=0;
  8576. int transactionIdIsNULL= TRUE;
  8577. char comfirmstr[20];
  8578. json_object *RemoteStopTransaction;
  8579. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8580. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8581. if(server_pending == TRUE)
  8582. {
  8583. return 0;
  8584. }
  8585. RemoteStopTransaction = json_tokener_parse(payload);
  8586. if(!is_error(RemoteStopTransaction))
  8587. {
  8588. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8589. {
  8590. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8591. transactionIdIsNULL = FALSE;
  8592. }
  8593. }
  8594. json_object_put(RemoteStopTransaction);
  8595. if(transactionIdIsNULL == FALSE)
  8596. {
  8597. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8598. {
  8599. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8600. {
  8601. //check Transaction active
  8602. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8603. {
  8604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8605. {
  8606. tempIndex = ((gun_index==2) ? 1: 0);
  8607. }
  8608. else
  8609. {
  8610. tempIndex = gun_index;
  8611. }
  8612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8613. {
  8614. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8615. {
  8616. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8617. {
  8618. match = TRUE;
  8619. GunNO = gun_index;
  8620. }
  8621. }
  8622. }// END FOR CHAdeMO_QUANTITY
  8623. }
  8624. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8625. {
  8626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8627. {
  8628. tempIndex = ((gun_index==2) ? 1: 0);
  8629. }
  8630. else
  8631. {
  8632. tempIndex = gun_index;
  8633. }
  8634. for (int index = 0; index < CCS_QUANTITY; index++)
  8635. {
  8636. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8637. {
  8638. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8639. {
  8640. match = TRUE;
  8641. GunNO = gun_index;
  8642. }
  8643. }
  8644. }// END FOR CCS_QUANTITY
  8645. }
  8646. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8647. {
  8648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8649. {
  8650. tempIndex = ((gun_index==2) ? 1: 0);
  8651. }
  8652. else
  8653. {
  8654. tempIndex = gun_index;
  8655. }
  8656. for (int index = 0; index < GB_QUANTITY; index++)
  8657. {
  8658. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8659. {
  8660. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8661. {
  8662. match = TRUE;
  8663. GunNO = gun_index;
  8664. }
  8665. }
  8666. }// END FOR GB_QUANTITY
  8667. }
  8668. else if(gunType[gun_index] == GUN_TYPE_DO)
  8669. {
  8670. tempIndex = gun_index;
  8671. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8672. {
  8673. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8674. {
  8675. 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
  8676. {
  8677. match = TRUE;
  8678. GunNO = gun_index;
  8679. }
  8680. }
  8681. }// END FOR GB_QUANTITY
  8682. }
  8683. else
  8684. {
  8685. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8686. {
  8687. tempIndex = 2;
  8688. }
  8689. else
  8690. {
  8691. tempIndex = gun_index;
  8692. }
  8693. for (int index = 0; index < AC_QUANTITY; index++)
  8694. {
  8695. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8696. {
  8697. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8698. {
  8699. match = TRUE;
  8700. GunNO = gun_index;
  8701. }
  8702. }
  8703. }// END FOR CHAdeMO_QUANTITY
  8704. } // END FOR AC ELSE
  8705. }// CHECK IF ResponseTransactionId == transactionIdInt
  8706. }//END FOR
  8707. if( match == TRUE)
  8708. {
  8709. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8710. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8711. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8712. }
  8713. else
  8714. {
  8715. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8716. }
  8717. }
  8718. else
  8719. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8720. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8721. return result;
  8722. }
  8723. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8724. {
  8725. mtrace();
  8726. int result = FAIL;
  8727. int connectorIdInt=0, reservationIdInt=0;
  8728. int tempIndex = 0;
  8729. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8730. char comfirmstr[20]={0};
  8731. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8732. int c = 0;
  8733. char *loc;
  8734. //char *ptr;
  8735. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8736. strcpy(sstrtemp, stringtrimspace(payload));
  8737. //***(1)connectorId ****/
  8738. c=0;
  8739. loc = strstr(sstrtemp, "connectorId");
  8740. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8741. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8742. {
  8743. sstr[c] = loc[strlen("connectorId")+2+c];
  8744. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8745. c++;
  8746. }
  8747. sstr[c] = '\0';
  8748. connectorIdInt = atoi(sstr);
  8749. //***(2)expiryDate ****/
  8750. loc = strstr(sstrtemp, "expiryDate");
  8751. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8752. c = 0;
  8753. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8754. {
  8755. sstr[c] = loc[3+strlen("expiryDate")+c];
  8756. c++;
  8757. }
  8758. sstr[c] = '\0';
  8759. strcpy(expiryDatestr, sstr);
  8760. //***(3)idTag ****/
  8761. loc = strstr(sstrtemp, "idTag");
  8762. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8763. c = 0;
  8764. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8765. {
  8766. sstr[c] = loc[3+strlen("idTag")+c];
  8767. c++;
  8768. }
  8769. sstr[c] = '\0';
  8770. strcpy(idTagstr, sstr);
  8771. //***(4)parentIdTag ****/
  8772. loc = strstr(sstrtemp, "parentIdTag");
  8773. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8774. c = 0;
  8775. if(loc == NULL)
  8776. {
  8777. strcpy(parentIdTagstr, "");
  8778. }
  8779. else
  8780. {
  8781. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8782. {
  8783. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8784. c++;
  8785. }
  8786. sstr[c] = '\0';
  8787. strcpy(parentIdTagstr, sstr);
  8788. }
  8789. //***(5)reservationId ****/
  8790. c=0;
  8791. loc = strstr(sstrtemp, "reservationId");
  8792. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8793. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8794. {
  8795. sstr[c] = loc[strlen("reservationId")+2+c];
  8796. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8797. c++;
  8798. }
  8799. sstr[c] = '\0';
  8800. reservationIdInt = atoi(sstr);
  8801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8802. /*
  8803. enum SYSTEM_STATUS
  8804. {
  8805. SYS_MODE_BOOTING = 0,
  8806. SYS_MODE_IDLE = 1,
  8807. SYS_MODE_AUTHORIZING = 2,
  8808. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8809. SYS_MODE_REASSIGN = 4,
  8810. SYS_MODE_PREPARING = 5,
  8811. SYS_MODE_PREPARE_FOR_EV = 6,
  8812. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8813. SYS_MODE_CHARGING = 8,
  8814. SYS_MODE_TERMINATING = 9,
  8815. SYS_MODE_COMPLETE = 10,
  8816. SYS_MODE_ALARM = 11,
  8817. SYS_MODE_FAULT = 12,
  8818. SYS_MODE_RESERVATION = 13,
  8819. SYS_MODE_BOOKING = 14,
  8820. SYS_MODE_MAINTAIN = 15,
  8821. SYS_MODE_DEBUG = 16,
  8822. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8823. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8824. SYS_MODE_UPDATE = 19
  8825. };
  8826. */
  8827. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8828. {
  8829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8830. goto end;
  8831. }
  8832. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8833. {
  8834. //check Transaction active
  8835. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8836. {
  8837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8838. {
  8839. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8840. }
  8841. else
  8842. {
  8843. tempIndex = connectorIdInt -1;
  8844. }
  8845. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8846. {
  8847. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8848. {
  8849. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8850. {
  8851. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8852. {
  8853. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8854. {
  8855. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8856. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8857. }
  8858. 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'))
  8859. {
  8860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8861. }
  8862. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8863. {
  8864. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8865. }
  8866. else
  8867. {
  8868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8869. }
  8870. }
  8871. 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
  8872. {
  8873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8874. }
  8875. }
  8876. else
  8877. {
  8878. //replace reservation
  8879. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8881. }
  8882. }
  8883. } // END FOR CHAdeMO_QUANTITY
  8884. }
  8885. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8886. {
  8887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8888. {
  8889. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8890. }
  8891. else
  8892. {
  8893. tempIndex = connectorIdInt -1;
  8894. }
  8895. for (int index = 0; index < CCS_QUANTITY; index++)
  8896. {
  8897. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8898. {
  8899. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8900. {
  8901. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8902. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8903. {
  8904. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8905. {
  8906. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8908. }
  8909. 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'))
  8910. {
  8911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8912. }
  8913. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8914. {
  8915. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8916. }
  8917. else
  8918. {
  8919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8920. }
  8921. }
  8922. 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
  8923. {
  8924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8925. }
  8926. }
  8927. else
  8928. {
  8929. //replace reservation
  8930. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8932. }
  8933. }
  8934. } // END FOR CCS_QUANTITY
  8935. }
  8936. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8937. {
  8938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8939. {
  8940. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8941. }
  8942. else
  8943. {
  8944. tempIndex = connectorIdInt -1;
  8945. }
  8946. for (int index = 0; index < GB_QUANTITY; index++)
  8947. {
  8948. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8949. {
  8950. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8951. {
  8952. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8953. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8954. {
  8955. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8956. {
  8957. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8959. }
  8960. 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'))
  8961. {
  8962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8963. }
  8964. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8965. {
  8966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8967. }
  8968. else
  8969. {
  8970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8971. }
  8972. }
  8973. 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
  8974. {
  8975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8976. }
  8977. }
  8978. else
  8979. {
  8980. //replace reservation
  8981. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8983. }
  8984. }
  8985. }// END FOR GB_QUANTITY
  8986. }
  8987. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8988. {
  8989. tempIndex = connectorIdInt -1;
  8990. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8991. {
  8992. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8993. {
  8994. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8995. {
  8996. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8997. 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
  8998. {
  8999. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9000. {
  9001. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9002. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9003. }
  9004. 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'))
  9005. {
  9006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9007. }
  9008. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9009. {
  9010. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9011. }
  9012. else
  9013. {
  9014. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9015. }
  9016. }
  9017. 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
  9018. {
  9019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9020. }
  9021. }
  9022. else
  9023. {
  9024. //replace reservation
  9025. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9026. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9027. }
  9028. }
  9029. }// END FOR GB_QUANTITY
  9030. }
  9031. else
  9032. {
  9033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9034. {
  9035. tempIndex = 2;
  9036. }
  9037. else
  9038. {
  9039. tempIndex = (connectorIdInt -1);
  9040. }
  9041. for (int index = 0; index < AC_QUANTITY; index++)
  9042. {
  9043. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9044. {
  9045. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9046. {
  9047. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9048. {
  9049. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9050. {
  9051. 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))
  9052. {
  9053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9054. }
  9055. else
  9056. {
  9057. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9059. }
  9060. }
  9061. 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'))
  9062. {
  9063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9064. }
  9065. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9066. {
  9067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9068. }
  9069. else
  9070. {
  9071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9072. }
  9073. }
  9074. 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
  9075. {
  9076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9077. }
  9078. }
  9079. else
  9080. {
  9081. //replace reservation
  9082. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9084. }
  9085. }
  9086. } // END FOR AC_QUANTITY
  9087. }
  9088. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9089. }
  9090. else if(connectorIdInt == 0)
  9091. {
  9092. //check Transaction active
  9093. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9094. {
  9095. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9096. {
  9097. 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'))
  9098. {
  9099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9100. goto end;
  9101. }
  9102. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9103. {
  9104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9105. goto end;
  9106. }
  9107. 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
  9108. {
  9109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9110. goto end;
  9111. }
  9112. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9113. {
  9114. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9115. goto end;
  9116. }
  9117. }
  9118. }// END FOR CHAdeMO_QUANTITY
  9119. for (int index = 0; index < CCS_QUANTITY; index++)
  9120. {
  9121. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9122. {
  9123. 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'))
  9124. {
  9125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9126. goto end;
  9127. }
  9128. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9129. {
  9130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9131. goto end;
  9132. }
  9133. 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
  9134. {
  9135. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9136. goto end;
  9137. }
  9138. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9139. {
  9140. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9141. goto end;
  9142. }
  9143. }
  9144. } // END FOR CCS_QUANTITY
  9145. for (int index = 0; index < GB_QUANTITY; index++)
  9146. {
  9147. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9148. {
  9149. 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'))
  9150. {
  9151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9152. goto end;
  9153. }
  9154. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9155. {
  9156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9157. goto end;
  9158. }
  9159. 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
  9160. {
  9161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9162. goto end;
  9163. }
  9164. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9165. {
  9166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9167. goto end;
  9168. }
  9169. }
  9170. } // END FOR GB_QUANTITY
  9171. for (int index = 0; index < AC_QUANTITY; index++)
  9172. {
  9173. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9174. {
  9175. 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'))
  9176. {
  9177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9178. goto end;
  9179. }
  9180. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9181. {
  9182. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9183. goto end;
  9184. }
  9185. 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
  9186. {
  9187. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9188. goto end;
  9189. }
  9190. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9191. {
  9192. 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))
  9193. {
  9194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9195. goto end;
  9196. }
  9197. }
  9198. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9199. {
  9200. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9201. goto end;
  9202. }
  9203. }
  9204. }// END FOR AC_QUANTITY
  9205. //The connectorId is 0
  9206. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  9207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9208. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9209. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  9210. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9211. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  9212. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9213. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  9214. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  9215. result = TRUE;
  9216. return result;
  9217. }
  9218. else
  9219. {
  9220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9221. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9222. }
  9223. if(strcmp(comfirmstr,"Accepted") == 0)
  9224. {
  9225. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9226. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9227. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9228. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9229. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9230. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  9231. result = TRUE;
  9232. return result;
  9233. }
  9234. end:
  9235. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9236. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9237. return result;
  9238. }
  9239. int handleResetRequest(char *uuid, char *payload)
  9240. {
  9241. mtrace();
  9242. int result = FAIL;
  9243. char sstr[10]={0},sstrtemp[30]={ 0 };
  9244. char typestr[10]={0};
  9245. char comfirmstr[20]={0};
  9246. int c = 0;
  9247. char *loc;
  9248. DEBUG_INFO("handleResetRequest...\n");
  9249. strcpy(sstrtemp, stringtrimspace(payload));
  9250. loc = strstr(sstrtemp, "type");
  9251. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9252. c = 0;
  9253. while (loc[3+strlen("type")+c] != '\"')
  9254. {
  9255. sstr[c] = loc[3+strlen("type")+c];
  9256. c++;
  9257. }
  9258. sstr[c] = '\0';
  9259. strcpy(typestr,sstr);
  9260. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  9261. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9262. {
  9263. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  9264. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  9265. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9266. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9267. }
  9268. else
  9269. {
  9270. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9271. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9272. result = PASS;
  9273. }
  9274. sendResetConfirmation(uuid, comfirmstr);
  9275. return result;
  9276. }
  9277. int handleSendLocalListRequest(char *uuid, char *payload)
  9278. {
  9279. mtrace();
  9280. int result = FAIL;
  9281. char comfirmstr[20];
  9282. int checkState_Faulted = FALSE;
  9283. json_object *SendLocalList;
  9284. DEBUG_INFO("handleSendLocalListRequest...\n");
  9285. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9286. {
  9287. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9288. goto end;
  9289. }
  9290. //check Charge Point state
  9291. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9292. {
  9293. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9294. {
  9295. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9296. }
  9297. }
  9298. for (int index = 0; index < CCS_QUANTITY; index++)
  9299. {
  9300. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9301. {
  9302. checkState_Faulted = TRUE; //OCPP Status
  9303. }
  9304. }
  9305. for (int index = 0; index < GB_QUANTITY; index++)
  9306. {
  9307. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9308. {
  9309. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9310. }
  9311. }
  9312. //check Charge Point state
  9313. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9314. {
  9315. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9316. {
  9317. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9318. }
  9319. }
  9320. //check Charge Point state
  9321. for (int index = 0; index < AC_QUANTITY; index++)
  9322. {
  9323. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9324. {
  9325. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9326. }
  9327. }
  9328. if(checkState_Faulted == TRUE)
  9329. {
  9330. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9331. goto end;
  9332. }
  9333. // Parsing payload
  9334. SendLocalList = json_tokener_parse(payload);
  9335. if(!is_error(SendLocalList))
  9336. {
  9337. // Required data
  9338. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  9339. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  9340. // Optional data
  9341. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  9342. {
  9343. //Check UpdateType
  9344. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9345. {
  9346. //Local list full update
  9347. DEBUG_INFO("Local list full update.\n");
  9348. OCPP_getListVerion();
  9349. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  9350. {
  9351. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9352. goto end;
  9353. }
  9354. OCPP_cleanLocalList();
  9355. }
  9356. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9357. {
  9358. //Local list different update
  9359. DEBUG_INFO("Local list different update.\n");
  9360. OCPP_getListVerion();
  9361. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  9362. {
  9363. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9364. goto end;
  9365. }
  9366. }
  9367. else
  9368. {
  9369. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9370. goto end;
  9371. }
  9372. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9373. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  9374. {
  9375. 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")));
  9376. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  9377. {
  9378. 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")));
  9379. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  9380. 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")));
  9381. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  9382. 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")));
  9383. }
  9384. // Add to db
  9385. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9386. {
  9387. //Local list full update
  9388. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  9389. idx,
  9390. ShmOCPP16DataPH->SendLocalList.ListVersion,
  9391. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9392. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9393. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9394. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9395. // update list
  9396. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  9397. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9398. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9399. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9400. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9401. }
  9402. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9403. {
  9404. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  9405. idx,
  9406. ShmOCPP16DataPH->SendLocalList.ListVersion,
  9407. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9408. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9409. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9410. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9411. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  9412. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9413. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9414. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9415. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9416. }
  9417. }
  9418. }
  9419. else
  9420. {
  9421. //Check UpdateType
  9422. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9423. {
  9424. //Local list full update
  9425. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9426. OCPP_cleanLocalList();
  9427. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9428. goto end;
  9429. }
  9430. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9431. {
  9432. //Local list different update
  9433. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9434. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9435. goto end;
  9436. }
  9437. }
  9438. result = PASS;
  9439. }
  9440. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9441. end:
  9442. json_object_put(SendLocalList);
  9443. sendSendLocalListConfirmation(uuid, comfirmstr);
  9444. return result;
  9445. }
  9446. #define MAX 200
  9447. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9448. {
  9449. mtrace();
  9450. int result = FAIL;
  9451. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9452. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9453. char chargingProfilePurposeStr[30]={0};
  9454. char chargingProfileKindStr[16]={0};
  9455. char recurrencyKindStr[10]={0};
  9456. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9457. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9458. int chargingSchedulePeriodCount = 0;
  9459. char comfirmstr[20]={0};
  9460. int meet= FALSE;
  9461. FILE *fptr1;
  9462. char filename[MAX]={0};
  9463. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  9464. char rmFileCmd[50]={0};
  9465. char tempchargingProfilePurposeStr[30]={0};
  9466. char word[1600]={0};
  9467. int n_chargingProfile = 0;
  9468. json_object *SetChargingProfile;
  9469. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9470. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9471. SetChargingProfile = json_tokener_parse(payload);
  9472. if(!is_error(SetChargingProfile))
  9473. {
  9474. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9475. {
  9476. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9477. if(connectorIdInt == 0)
  9478. {
  9479. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9480. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9481. }
  9482. else
  9483. {
  9484. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9485. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9486. }
  9487. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9488. }
  9489. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9490. {
  9491. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9492. {
  9493. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9495. {
  9496. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9497. }
  9498. else
  9499. {
  9500. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9501. }
  9502. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9503. }
  9504. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9505. {
  9506. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9507. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9508. {
  9509. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9510. }
  9511. else
  9512. {
  9513. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9514. }
  9515. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9516. }
  9517. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9518. {
  9519. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9520. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9521. {
  9522. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9523. }
  9524. else
  9525. {
  9526. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9527. }
  9528. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9529. }
  9530. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9531. {
  9532. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9533. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9534. {
  9535. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9536. }
  9537. else
  9538. {
  9539. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9540. }
  9541. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9542. }
  9543. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9544. {
  9545. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9546. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9547. {
  9548. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9549. }
  9550. else
  9551. {
  9552. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9553. }
  9554. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9555. }
  9556. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9557. {
  9558. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9559. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9560. {
  9561. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9562. }
  9563. else
  9564. {
  9565. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9566. }
  9567. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9568. }
  9569. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9570. {
  9571. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9572. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9573. {
  9574. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9575. }
  9576. else
  9577. {
  9578. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9579. }
  9580. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9581. }
  9582. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9583. {
  9584. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9585. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9586. {
  9587. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9588. }
  9589. else
  9590. {
  9591. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9592. }
  9593. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9594. }
  9595. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9596. {
  9597. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9598. {
  9599. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9600. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9601. {
  9602. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9603. }
  9604. else
  9605. {
  9606. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9607. }
  9608. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9609. }
  9610. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9611. {
  9612. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9613. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9614. {
  9615. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9616. }
  9617. else
  9618. {
  9619. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9620. }
  9621. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9622. }
  9623. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9624. {
  9625. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9626. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9627. {
  9628. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9629. }
  9630. else
  9631. {
  9632. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9633. }
  9634. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9635. }
  9636. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9637. {
  9638. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9639. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9640. {
  9641. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9642. }
  9643. else
  9644. {
  9645. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9646. }
  9647. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9648. }
  9649. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9650. {
  9651. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9652. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9653. if(chargingSchedulePeriodCount <= 10)
  9654. {
  9655. 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++)
  9656. {
  9657. 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)
  9658. {
  9659. 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"));
  9660. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9661. {
  9662. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9663. }
  9664. else
  9665. {
  9666. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9667. }
  9668. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9669. }
  9670. 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)
  9671. {
  9672. 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"));
  9673. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9674. {
  9675. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9676. }
  9677. else
  9678. {
  9679. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9680. }
  9681. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9682. }
  9683. 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)
  9684. {
  9685. 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"));
  9686. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9687. {
  9688. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9689. }
  9690. else
  9691. {
  9692. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9693. }
  9694. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9695. }
  9696. }
  9697. }
  9698. }
  9699. }
  9700. }
  9701. }
  9702. json_object_put(SetChargingProfile);
  9703. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9704. {
  9705. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9706. goto end;
  9707. }
  9708. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9709. {
  9710. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9711. if(connectorIdInt != 0)
  9712. {
  9713. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9714. goto end;
  9715. }
  9716. strcpy(filename, ChargePointMaxProfile_JSON );
  9717. fptr1 = fopen(filename, "r");
  9718. if (!fptr1)
  9719. {
  9720. //file not exist
  9721. DEBUG_INFO("Unable to open the input file!!\n");
  9722. fptr1 = fopen(filename, "w+");
  9723. }
  9724. else
  9725. {
  9726. //Check Charging Profile Count
  9727. while(fscanf(fptr1, "%s", word) != EOF)
  9728. {
  9729. //DEBUG_INFO("word=%s\n",word);
  9730. if(strstr(word, "chargingProfileId")!= NULL)
  9731. {
  9732. //DEBUG_INFO("test chargingProfileId \n");
  9733. n_chargingProfile = n_chargingProfile + 1;
  9734. //DEBUG_INFO("chargingProfileId Found\n");
  9735. }
  9736. }
  9737. }
  9738. fclose(fptr1);
  9739. }
  9740. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9741. {
  9742. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9743. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9744. {
  9745. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9746. goto end;
  9747. }
  9748. memset(filename, 0, ARRAY_SIZE(filename));
  9749. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  9750. fptr1 = fopen(filename, "r");
  9751. if (!fptr1)
  9752. {
  9753. //file not exist
  9754. //DEBUG_INFO("Unable to open the input file!!\n");
  9755. fptr1 = fopen(filename, "w+");
  9756. }
  9757. else
  9758. {
  9759. //Check Charging Profile Count
  9760. while(fscanf(fptr1, "%s", word) != EOF)
  9761. {
  9762. //DEBUG_INFO("word=%s\n",word);
  9763. if(strstr(word, "chargingProfileId")!= NULL)
  9764. {
  9765. //DEBUG_INFO("test chargingProfileId \n");
  9766. n_chargingProfile = n_chargingProfile + 1;
  9767. //DEBUG_INFO("chargingProfileId Found\n");
  9768. }
  9769. }
  9770. }
  9771. fclose(fptr1);
  9772. }
  9773. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9774. {
  9775. //printf("set chargingProfile 1-4\n");
  9776. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9777. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9778. if(connectorIdInt == 0)
  9779. {
  9780. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9781. goto end;
  9782. }
  9783. int tempIndex = 0;
  9784. //check Transaction active
  9785. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9786. {
  9787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9788. {
  9789. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9790. }
  9791. else
  9792. {
  9793. tempIndex = connectorIdInt -1;
  9794. }
  9795. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9796. {
  9797. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9798. {
  9799. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9800. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9801. {
  9802. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9803. {
  9804. meet = TRUE;
  9805. break;
  9806. }
  9807. }
  9808. }
  9809. }
  9810. }
  9811. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9812. {
  9813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9814. {
  9815. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9816. }
  9817. else
  9818. {
  9819. tempIndex = connectorIdInt -1;
  9820. }
  9821. for (int index = 0; index < CCS_QUANTITY; index++)
  9822. {
  9823. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9824. {
  9825. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9826. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9827. {
  9828. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9829. {
  9830. meet = TRUE;
  9831. break;
  9832. }
  9833. }
  9834. }
  9835. }
  9836. }
  9837. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9838. {
  9839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9840. {
  9841. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9842. }
  9843. else
  9844. {
  9845. tempIndex = connectorIdInt -1;
  9846. }
  9847. for (int index = 0; index < GB_QUANTITY; index++)
  9848. {
  9849. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9850. {
  9851. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9852. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9853. {
  9854. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9855. {
  9856. meet = TRUE;
  9857. break;
  9858. }
  9859. }
  9860. }
  9861. }
  9862. }
  9863. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9864. {
  9865. tempIndex = connectorIdInt -1;
  9866. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9867. {
  9868. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9869. {
  9870. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9871. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9872. {
  9873. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9874. {
  9875. meet = TRUE;
  9876. break;
  9877. }
  9878. }
  9879. }
  9880. }
  9881. }
  9882. else
  9883. {
  9884. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9885. {
  9886. tempIndex = 2;
  9887. }
  9888. else
  9889. {
  9890. tempIndex = (connectorIdInt -1);
  9891. }
  9892. for (int index = 0; index < AC_QUANTITY; index++)
  9893. {
  9894. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9895. {
  9896. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9897. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9898. {
  9899. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9900. {
  9901. meet = TRUE;
  9902. break;
  9903. }
  9904. }
  9905. }
  9906. }
  9907. }
  9908. //check Transaction active
  9909. if(meet == FALSE)
  9910. {
  9911. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9912. goto end;
  9913. }
  9914. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9915. {
  9916. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9917. goto end;
  9918. }
  9919. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9920. fptr1 = fopen(filename, "r");
  9921. if (!fptr1)
  9922. {
  9923. //file not exist
  9924. DEBUG_INFO("Unable to open the input file!!\n");
  9925. fptr1 = fopen(filename, "w+");
  9926. }
  9927. else
  9928. {
  9929. //Check Charging Profile Count
  9930. while(fscanf(fptr1, "%s", word) != EOF)
  9931. {
  9932. //DEBUG_INFO("word=%s\n",word);
  9933. if(strstr(word, "chargingProfileId")!= NULL)
  9934. {
  9935. //DEBUG_INFO("test chargingProfileId \n");
  9936. n_chargingProfile = n_chargingProfile + 1;
  9937. //DEBUG_INFO("chargingProfileId Found\n");
  9938. }
  9939. }
  9940. }
  9941. fclose(fptr1);
  9942. }
  9943. // Check ChargeProfileMaxStackLevel
  9944. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9945. {
  9946. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9947. goto end;
  9948. }
  9949. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9950. {
  9951. int i = 0;
  9952. char fnametemp[200]={0};
  9953. n_chargingProfile = 0;
  9954. //Check ChargePointMaxProfile.json exit
  9955. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  9956. {
  9957. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  9958. //Check Charging Profile Count
  9959. while(fscanf(fptr1, "%s", word) != EOF)
  9960. {
  9961. //DEBUG_INFO("word=%s\n",word);
  9962. if(strstr(word, "chargingProfileId")!= NULL)
  9963. {
  9964. //DEBUG_INFO("test chargingProfileId \n");
  9965. n_chargingProfile = n_chargingProfile + 1;
  9966. i = i + 1;
  9967. //DEBUG_INFO("chargingProfileId Found\n");
  9968. }
  9969. memset(word, 0, ARRAY_SIZE(word));
  9970. }
  9971. fclose(fptr1);
  9972. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9973. }
  9974. //Check TxDefaultProfile_0.json exit
  9975. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  9976. {
  9977. i = 0;
  9978. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  9979. //Check Charging Profile Count
  9980. while(fscanf(fptr1, "%s", word) != EOF)
  9981. {
  9982. //DEBUG_INFO("word=%s\n",word);
  9983. if(strstr(word, "chargingProfileId")!= NULL)
  9984. {
  9985. //DEBUG_INFO("test chargingProfileId \n");
  9986. n_chargingProfile = n_chargingProfile + 1;
  9987. i = i + 1;
  9988. //DEBUG_INFO("chargingProfileId Found\n");
  9989. }
  9990. memset(word, 0, ARRAY_SIZE(word));
  9991. }
  9992. fclose(fptr1);
  9993. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9994. }
  9995. //Check TxDefaultProfile_%d.json
  9996. for(int j=1; j <= gunTotalNumber; j++)
  9997. {
  9998. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9999. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  10000. if((access(fnametemp,F_OK))!=-1)
  10001. {
  10002. i = 0;
  10003. fptr1 = fopen(fnametemp, "r");
  10004. //Check Charging Profile Count
  10005. while(fscanf(fptr1, "%s", word) != EOF)
  10006. {
  10007. //DEBUG_INFO("word=%s\n",word);
  10008. if(strstr(word, "chargingProfileId")!= NULL)
  10009. {
  10010. //DEBUG_INFO("test chargingProfileId \n");
  10011. n_chargingProfile = n_chargingProfile + 1;
  10012. i = i + 1;
  10013. //DEBUG_INFO("chargingProfileId Found\n");
  10014. }
  10015. memset(word, 0, ARRAY_SIZE(word));
  10016. }
  10017. fclose(fptr1);
  10018. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10019. }
  10020. }
  10021. //Check TxProfile_%d.json
  10022. for(int j=1; j <= gunTotalNumber; j++)
  10023. {
  10024. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10025. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10026. if((access(fnametemp,F_OK))!=-1)
  10027. {
  10028. i = 0;
  10029. fptr1 = fopen(fnametemp, "r");
  10030. //Check Charging Profile Count
  10031. while(fscanf(fptr1, "%s", word) != EOF)
  10032. {
  10033. //DEBUG_INFO("word=%s\n",word);
  10034. if(strstr(word, "chargingProfileId")!= NULL)
  10035. {
  10036. //DEBUG_INFO("test chargingProfileId \n");
  10037. n_chargingProfile = n_chargingProfile + 1;
  10038. i = i + 1;
  10039. //DEBUG_INFO("chargingProfileId Found\n");
  10040. }
  10041. memset(word, 0, ARRAY_SIZE(word));
  10042. }
  10043. fclose(fptr1);
  10044. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10045. }
  10046. }
  10047. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10048. {
  10049. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10050. goto end;
  10051. }
  10052. }
  10053. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10054. //**********************************Write to File********************************************************/
  10055. FILE *infile;
  10056. FILE *outfile;
  10057. infile = fopen (filename, "r");
  10058. outfile = fopen (tempfile, "w");
  10059. int d =0;
  10060. d = fgetc(infile);
  10061. rewind(infile);
  10062. if(d == EOF)
  10063. {
  10064. // Profile is empty
  10065. fprintf(outfile,"%s\n",payload);
  10066. fclose(infile);
  10067. fclose(outfile);
  10068. sprintf(rmFileCmd,"rm -f %s",filename);
  10069. system(rmFileCmd);
  10070. rename(tempfile, filename);
  10071. }
  10072. else
  10073. {
  10074. // Profile is not empty
  10075. char buf[2048]={0};
  10076. int ChargingProfileAdded = FALSE;
  10077. while (fgets(buf, sizeof(buf), infile) != NULL)
  10078. {
  10079. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10080. json_object *tmpChargingProfile;
  10081. tmpChargingProfile = json_tokener_parse(buf);
  10082. if(!is_error(SetChargingProfile))
  10083. {
  10084. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10085. {
  10086. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10087. }
  10088. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10089. {
  10090. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10091. {
  10092. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10093. }
  10094. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10095. {
  10096. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10097. }
  10098. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10099. {
  10100. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10101. }
  10102. }
  10103. }
  10104. json_object_put(tmpChargingProfile);
  10105. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10106. {
  10107. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10108. {
  10109. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10110. if(ChargingProfileAdded == FALSE)
  10111. {
  10112. fprintf(outfile,"%s\n",payload);
  10113. ChargingProfileAdded = TRUE;
  10114. }
  10115. }
  10116. else
  10117. {
  10118. if(tempstackLevelInt < stackLevelInt)
  10119. {
  10120. if(ChargingProfileAdded == FALSE)
  10121. {
  10122. fprintf(outfile,"%s\n",buf);
  10123. fprintf(outfile,"%s\n",payload);
  10124. ChargingProfileAdded = TRUE;
  10125. }
  10126. else
  10127. {
  10128. fprintf(outfile,"%s\n",buf);
  10129. }
  10130. }
  10131. else
  10132. {
  10133. if(ChargingProfileAdded == FALSE)
  10134. {
  10135. fprintf(outfile,"%s\n",buf);
  10136. fprintf(outfile,"%s\n",payload);
  10137. ChargingProfileAdded = TRUE;
  10138. }
  10139. else
  10140. {
  10141. fprintf(outfile,"%s\n",buf);
  10142. }
  10143. }
  10144. }
  10145. }
  10146. else
  10147. {
  10148. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10149. {
  10150. if(ChargingProfileAdded == FALSE)
  10151. {
  10152. fprintf(outfile,"%s\n",buf);
  10153. fprintf(outfile,"%s\n",payload);
  10154. ChargingProfileAdded = TRUE;
  10155. }
  10156. else
  10157. {
  10158. fprintf(outfile,"%s\n",buf);
  10159. }
  10160. }
  10161. else if(tempstackLevelInt < stackLevelInt)
  10162. {
  10163. if(ChargingProfileAdded == FALSE)
  10164. {
  10165. fprintf(outfile,"%s\n",buf);
  10166. fprintf(outfile,"%s\n",payload);
  10167. ChargingProfileAdded = TRUE;
  10168. }
  10169. else
  10170. {
  10171. fprintf(outfile,"%s\n",buf);
  10172. }
  10173. }
  10174. else
  10175. {
  10176. if(ChargingProfileAdded == FALSE)
  10177. {
  10178. fprintf(outfile,"%s\n",buf);
  10179. fprintf(outfile,"%s\n",payload);
  10180. ChargingProfileAdded = TRUE;
  10181. }
  10182. else
  10183. {
  10184. fprintf(outfile,"%s\n",buf);
  10185. }
  10186. }
  10187. }
  10188. } // end of while loop
  10189. fclose(infile);
  10190. fclose(outfile);
  10191. sprintf(rmFileCmd,"rm -f %s",filename);
  10192. system(rmFileCmd);
  10193. rename(tempfile, filename);
  10194. }
  10195. sleep(1);
  10196. result = TRUE;
  10197. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10198. end:
  10199. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10200. {
  10201. if(connectorIdInt == 0)
  10202. {
  10203. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10204. {
  10205. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  10206. }
  10207. }
  10208. else
  10209. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  10210. }
  10211. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10212. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10213. return result;
  10214. }
  10215. int handleTriggerMessageRequest(char *uuid, char *payload)
  10216. {
  10217. mtrace();
  10218. int result = FAIL;
  10219. int connectorIdIsNULL = FALSE;
  10220. int connectorIdInt =0;
  10221. char sstr[40]={0},sstrtemp[100]={ 0 };
  10222. char requestedMessagestr[40]={0};
  10223. char comfirmstr[20]={0};
  10224. int c = 0;
  10225. char *loc;
  10226. DEBUG_INFO("handleTriggerMessageRequest\n");
  10227. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10228. strcpy(sstrtemp, stringtrimspace(payload));
  10229. c = 0;
  10230. loc = strstr(sstrtemp, "requestedMessage");
  10231. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10232. {
  10233. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10234. c++;
  10235. }
  10236. sstr[c] = '\0';
  10237. strcpy(requestedMessagestr, sstr);
  10238. c = 0;
  10239. loc = strstr(sstrtemp, "connectorId");
  10240. if(loc == NULL)
  10241. {
  10242. connectorIdIsNULL = TRUE;
  10243. }
  10244. else
  10245. {
  10246. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10247. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10248. {
  10249. sstr[c] = loc[strlen("connectorId")+2+c];
  10250. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10251. c++;
  10252. }
  10253. sstr[c] = '\0';
  10254. connectorIdInt = atoi(sstr);
  10255. }
  10256. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10257. {
  10258. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10259. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10260. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10261. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10262. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10263. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10264. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10265. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10266. {
  10267. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10268. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10269. return TRUE;
  10270. }
  10271. else
  10272. {
  10273. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10274. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10275. }
  10276. }
  10277. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10278. {
  10279. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10280. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10281. return TRUE;
  10282. }
  10283. //==========================
  10284. // Trigger message
  10285. //==========================
  10286. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10287. {
  10288. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10289. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10290. {
  10291. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10292. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10293. }
  10294. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10295. }
  10296. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10297. {
  10298. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  10299. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10300. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10301. }
  10302. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10303. {
  10304. //sendBootNotificationRequest();
  10305. server_sign = FALSE;
  10306. }
  10307. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10308. {
  10309. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10310. }
  10311. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10312. {
  10313. if(connectorIdIsNULL == FALSE)
  10314. {
  10315. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10316. {
  10317. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10318. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10319. }
  10320. }
  10321. else
  10322. {
  10323. for(int idx=0;idx< gunTotalNumber;idx++)
  10324. {
  10325. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10326. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10327. }
  10328. }
  10329. }
  10330. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10331. {
  10332. if(connectorIdIsNULL == FALSE)
  10333. {
  10334. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10335. {
  10336. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10337. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  10338. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10339. }
  10340. }
  10341. else
  10342. {
  10343. for(int idx=0;idx< gunTotalNumber;idx++)
  10344. {
  10345. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  10346. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10347. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10348. }
  10349. }
  10350. }
  10351. return result;
  10352. }
  10353. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10354. {
  10355. mtrace();
  10356. int result = FAIL;
  10357. int connectorIdInt =0;
  10358. char comfirmstr[20]={0};
  10359. int tempIndex = 0;
  10360. json_object *UnlockConnector;
  10361. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10362. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10363. UnlockConnector = json_tokener_parse(payload);
  10364. if(!is_error(UnlockConnector))
  10365. {
  10366. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10367. {
  10368. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10369. }
  10370. }
  10371. json_object_put(UnlockConnector);
  10372. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10373. if(gunTotalNumber == 0)
  10374. {
  10375. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10376. goto end;
  10377. }
  10378. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10379. {
  10380. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10381. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10382. goto end;
  10383. }
  10384. else
  10385. {
  10386. //check Transaction active
  10387. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10388. {
  10389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10390. {
  10391. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10392. }
  10393. else
  10394. {
  10395. tempIndex = connectorIdInt -1;
  10396. }
  10397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10398. {
  10399. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10400. {
  10401. //stop Transaction
  10402. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10403. }
  10404. }
  10405. }
  10406. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10407. {
  10408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10409. {
  10410. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10411. }
  10412. else
  10413. {
  10414. tempIndex = connectorIdInt -1;
  10415. }
  10416. for (int index = 0; index < CCS_QUANTITY; index++)
  10417. {
  10418. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10419. {
  10420. //stop Transaction
  10421. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10422. }
  10423. }
  10424. }
  10425. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10426. {
  10427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10428. {
  10429. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10430. }
  10431. else
  10432. {
  10433. tempIndex = connectorIdInt -1;
  10434. }
  10435. for (int index = 0; index < GB_QUANTITY; index++)
  10436. {
  10437. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10438. {
  10439. //stop Transaction
  10440. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10441. }
  10442. }
  10443. }
  10444. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10445. {
  10446. tempIndex = connectorIdInt -1;
  10447. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10448. {
  10449. 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)))
  10450. {
  10451. //stop Transaction
  10452. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10453. }
  10454. }
  10455. }
  10456. else
  10457. {
  10458. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10459. {
  10460. tempIndex = 2;
  10461. }
  10462. else
  10463. {
  10464. tempIndex = connectorIdInt-1;
  10465. }
  10466. for (int index = 0; index < AC_QUANTITY; index++)
  10467. {
  10468. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10469. {
  10470. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10471. }
  10472. }
  10473. }
  10474. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10475. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  10476. result = TRUE;
  10477. return result;
  10478. }
  10479. end:
  10480. //json_object_put(obj); --- remove temporally
  10481. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10482. return result;
  10483. }
  10484. static char UpdateFirmwarepayloadData[300]={0};
  10485. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10486. {
  10487. mtrace();
  10488. int result = FAIL;
  10489. pthread_t t;
  10490. sendUpdateFirmwareConfirmation(uuid);
  10491. memset(UpdateFirmwarepayloadData, 0, 300);
  10492. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10493. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10494. ////pthread_join(t, NULL); //
  10495. //pthread_detach(t);
  10496. //sendUpdateFirmwareConfirmation(uuid);
  10497. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  10498. return result;
  10499. }
  10500. void *UpdateFirmwareProcess(void *data)
  10501. {
  10502. pthread_detach(pthread_self());
  10503. mtrace();
  10504. int retriesInt =0, retryIntervalInt=0;
  10505. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10506. int port=0;
  10507. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10508. int isSuccess = 0;
  10509. char ftpbuf[512];
  10510. char temp[100];
  10511. char * pch;
  10512. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10513. json_object *UpdateFirmware;
  10514. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10515. if(!is_error(UpdateFirmware))
  10516. {
  10517. // Required data
  10518. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10519. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10520. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10521. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10522. // Optional data
  10523. if(json_object_object_get(UpdateFirmware, "retries"))
  10524. {
  10525. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10526. }
  10527. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10528. {
  10529. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10530. }
  10531. }
  10532. json_object_put(UpdateFirmware);
  10533. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10534. memset(path, 0, ARRAY_SIZE(path));
  10535. // Wait retrieveData
  10536. if(strlen(retrieveDatestr) > 10)
  10537. {
  10538. do
  10539. {
  10540. sleep(1);
  10541. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10542. }
  10543. // Ready to download
  10544. system("rm -f /mnt/*");
  10545. if(strncmp(locationstr,"http", 4) == 0)
  10546. {
  10547. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10548. sprintf(ftppath,"/%s", path);
  10549. DEBUG_INFO("locationstr: %s\n", locationstr);
  10550. DEBUG_INFO("protocol: %s\n",protocol);
  10551. DEBUG_INFO("host: %s\n",host);
  10552. DEBUG_INFO("path: %s\n",path);
  10553. DEBUG_INFO("ftppath: %s\n",ftppath);
  10554. int ftppathlen=strlen(ftppath);
  10555. int i=1;
  10556. char filenametemp[50];
  10557. while(i < ftppathlen)
  10558. {
  10559. int len=ftppathlen-i;
  10560. if(ftppath[len]== 47) // '/' ascll code: 47
  10561. {
  10562. DEBUG_INFO("compare '/' all right\n");
  10563. break;
  10564. }
  10565. i=i+1;
  10566. }
  10567. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10568. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10569. filenametemp[i+1] = 0;
  10570. do
  10571. {
  10572. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10573. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10574. sleep(1);
  10575. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10576. if(!isSuccess)
  10577. {
  10578. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10579. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10580. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10581. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10582. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10583. }
  10584. else
  10585. {
  10586. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10587. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10588. }
  10589. retriesInt--;
  10590. }while((isSuccess == 0)&&(retriesInt >= 0));
  10591. }
  10592. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10593. {
  10594. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10595. memset(temp, 0, ARRAY_SIZE(temp));
  10596. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10597. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10598. int ftppathlen=strlen(ftpbuf);
  10599. int i=1;
  10600. char filenametemp[50];
  10601. while(i < ftppathlen)
  10602. {
  10603. int len=ftppathlen-i;
  10604. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10605. {
  10606. DEBUG_INFO(" compare '/' all right\n");
  10607. break;
  10608. }
  10609. i=i+1;
  10610. }
  10611. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10612. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10613. filenametemp[i+1] = 0;
  10614. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10615. pch=strchr(temp,'@');
  10616. if(pch==NULL)
  10617. {
  10618. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10619. protocol, host, &port, path);
  10620. strcpy(user,"anonymous");
  10621. strcpy(password,"");
  10622. }
  10623. else
  10624. {
  10625. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10626. protocol, user, password, host, &port, path);
  10627. }
  10628. sscanf(host,"%[^/]%s",host1, path1);
  10629. sprintf(ftppath,"%s", path1);
  10630. //DEBUG_INFO("protocol =%s\n",protocol);
  10631. //DEBUG_INFO("user =%s\n",user);
  10632. //DEBUG_INFO("password =%s\n",password);
  10633. //DEBUG_INFO("host1 =%s\n",host1);
  10634. //DEBUG_INFO("port =%d\n",port);
  10635. //DEBUG_INFO("path1 =%s\n",path1);
  10636. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10637. //ftpFile(host, user, password, port, ftppath, fname);
  10638. //download firmware pthred
  10639. if(port == 0)
  10640. {
  10641. port = 21;
  10642. }
  10643. do
  10644. {
  10645. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10646. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10647. sleep(1);
  10648. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10649. if(!isSuccess)
  10650. {
  10651. //BulldogUtil.sleepMs(interval*1000);
  10652. DEBUG_INFO("Update firmware request and download file fail.\n");
  10653. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10654. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10655. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10656. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10657. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10658. }
  10659. else
  10660. {
  10661. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10662. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10663. }
  10664. retriesInt--;
  10665. }while((!isSuccess)&&(retriesInt >= 0));
  10666. }
  10667. else
  10668. {
  10669. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10670. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10671. sleep(1);
  10672. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10673. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10674. }
  10675. // OCPPPH only, must announce CSU upgrade firmware
  10676. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  10677. pthread_exit(NULL);
  10678. }
  10679. int handleCertificateSignedRequest(char *uuid, char *payload)
  10680. {
  10681. mtrace();
  10682. int result = PASS;
  10683. json_object *CertificateSigned;
  10684. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10685. CertificateSigned = json_tokener_parse(payload);
  10686. if(!is_error(CertificateSigned))
  10687. {
  10688. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10689. }
  10690. json_object_put(CertificateSigned);
  10691. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  10692. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  10693. fclose(fp);
  10694. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10695. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  10696. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  10697. sendCertificateSignedConfirmation(uuid);
  10698. return result;
  10699. }
  10700. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10701. {
  10702. mtrace();
  10703. int result = PASS;
  10704. json_object *DeleteCertificate;
  10705. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10706. DeleteCertificate = json_tokener_parse(payload);
  10707. if(!is_error(DeleteCertificate))
  10708. {
  10709. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10710. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10711. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10712. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10713. }
  10714. json_object_put(DeleteCertificate);
  10715. /*
  10716. * TODO: Delete certificateSigned process
  10717. */
  10718. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  10719. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  10720. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  10721. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  10722. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  10723. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  10724. sendDeleteCertificateConfirmation(uuid);
  10725. return result;
  10726. }
  10727. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10728. {
  10729. mtrace();
  10730. int result = PASS;
  10731. json_object *ExtendedTriggerMessage;
  10732. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10733. ExtendedTriggerMessage = json_tokener_parse(payload);
  10734. if(!is_error(ExtendedTriggerMessage))
  10735. {
  10736. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10737. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10738. {
  10739. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10740. }
  10741. else
  10742. {
  10743. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  10744. }
  10745. }
  10746. json_object_put(ExtendedTriggerMessage);
  10747. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  10748. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  10749. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10750. {
  10751. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10752. }
  10753. else
  10754. {
  10755. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10756. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10757. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10758. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10759. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10760. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10761. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10762. {
  10763. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10764. }
  10765. else
  10766. {
  10767. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10768. }
  10769. }
  10770. sendExtendedTriggerMessageConfirmation(uuid);
  10771. //==========================
  10772. // Trigger message
  10773. //==========================
  10774. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10775. {
  10776. //sendBootNotificationRequest();
  10777. server_sign = FALSE;
  10778. }
  10779. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10780. {
  10781. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  10782. }
  10783. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10784. {
  10785. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10786. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10787. {
  10788. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10789. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10790. }
  10791. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10792. }
  10793. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10794. {
  10795. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10796. }
  10797. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10798. {
  10799. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10800. {
  10801. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10802. }
  10803. else
  10804. {
  10805. for(int idx=0;idx< gunTotalNumber;idx++)
  10806. {
  10807. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10808. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10809. }
  10810. }
  10811. }
  10812. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10813. {
  10814. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  10815. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  10816. {
  10817. 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\" &");
  10818. }
  10819. }
  10820. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10821. {
  10822. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10823. {
  10824. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10825. }
  10826. else
  10827. {
  10828. for(int idx=0;idx< gunTotalNumber;idx++)
  10829. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10830. }
  10831. }
  10832. return result;
  10833. }
  10834. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10835. {
  10836. mtrace();
  10837. int result = PASS;
  10838. json_object *GetInstalledCertificateIds;
  10839. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10840. GetInstalledCertificateIds = json_tokener_parse(payload);
  10841. if(!is_error(GetInstalledCertificateIds))
  10842. {
  10843. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10844. }
  10845. json_object_put(GetInstalledCertificateIds);
  10846. /*
  10847. * TODO: Return installed certificate process
  10848. */
  10849. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10850. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  10851. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10852. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  10853. sendGetInstalledCertificateIdsConfirmation(uuid);
  10854. return result;
  10855. }
  10856. int handleGetLogRequest(char *uuid, char *payload)
  10857. {
  10858. mtrace();
  10859. int result = PASS;
  10860. json_object *GetLog;
  10861. DEBUG_INFO("handleGetLogRequest...\n");
  10862. GetLog = json_tokener_parse(payload);
  10863. if(!is_error(GetLog))
  10864. {
  10865. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10866. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10867. if(json_object_object_get(GetLog, "retries") != NULL)
  10868. {
  10869. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10870. }
  10871. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10872. {
  10873. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10874. }
  10875. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10876. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10877. {
  10878. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10879. }
  10880. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10881. {
  10882. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10883. }
  10884. }
  10885. json_object_put(GetLog);
  10886. /*
  10887. * TODO: Upload log process
  10888. */
  10889. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  10890. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  10891. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  10892. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  10893. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  10894. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  10895. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  10896. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  10897. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  10898. sendGetLogConfirmation(uuid);
  10899. return result;
  10900. }
  10901. int handleInstallCertificateRequest(char *uuid, char *payload)
  10902. {
  10903. mtrace();
  10904. int result = PASS;
  10905. json_object *InstallCertificate;
  10906. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10907. InstallCertificate = json_tokener_parse(payload);
  10908. if(!is_error(InstallCertificate))
  10909. {
  10910. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10911. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10912. /*
  10913. * TODO: Install certificate process
  10914. */
  10915. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  10916. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  10917. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  10918. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  10919. sendInstallCertificateConfirmation(uuid);
  10920. }
  10921. json_object_put(InstallCertificate);
  10922. return result;
  10923. }
  10924. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10925. {
  10926. mtrace();
  10927. int result = PASS;
  10928. json_object *SignedUpdateFirmware;
  10929. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10930. SignedUpdateFirmware = json_tokener_parse(payload);
  10931. if(!is_error(SignedUpdateFirmware))
  10932. {
  10933. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10934. {
  10935. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10936. }
  10937. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10938. {
  10939. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10940. }
  10941. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10942. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10943. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10944. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10945. {
  10946. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10947. }
  10948. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10949. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10950. }
  10951. json_object_put(SignedUpdateFirmware);
  10952. /*
  10953. * TODO: Upgrade firmware process
  10954. */
  10955. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10956. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  10957. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  10958. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  10959. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  10960. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  10961. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  10962. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  10963. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  10964. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  10965. sendInstallCertificateConfirmation(uuid);
  10966. return result;
  10967. }
  10968. int handleUnknownRequest(char *uuid, char *payload)
  10969. {
  10970. mtrace();
  10971. int result = PASS;
  10972. DEBUG_INFO("handleUnknownRequest...\n");
  10973. sendUnknownConfirmation(uuid);
  10974. result = PASS;
  10975. return result;
  10976. }
  10977. //==========================================
  10978. // Handle server response routine
  10979. //==========================================
  10980. void handleAuthorizeResponse(char *payload, int gun_index)
  10981. {
  10982. mtrace();
  10983. char expiryDatestr[30]={0};
  10984. char parentIdTagstr[20]={0};
  10985. char statusstr[20]={0};
  10986. int expiryDateISNULL=FALSE;
  10987. int parentIdTagISNULL=FALSE;
  10988. DEBUG_INFO("handleAuthorizeResponse...\n");
  10989. json_object *Authorize;
  10990. Authorize = json_tokener_parse(payload);
  10991. if(!is_error(Authorize))
  10992. {
  10993. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10994. {
  10995. // Required data
  10996. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10997. // Optional data
  10998. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10999. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11000. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11001. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11002. }
  11003. }
  11004. json_object_put(Authorize);
  11005. if(expiryDateISNULL == FALSE)
  11006. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11007. if(parentIdTagISNULL == FALSE)
  11008. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11009. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11010. //Update idTag information to authorization cache if supproted
  11011. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11012. {
  11013. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11014. }
  11015. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11016. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11017. authorizeRetryTimes = 0;
  11018. }
  11019. void handleBootNotificationResponse(char *payload, int gun_index)
  11020. {
  11021. mtrace();
  11022. char statusStr[12]={0};
  11023. char currentTimeStr[30]={0};
  11024. int intervalInt = 0;
  11025. DEBUG_INFO("handleBootNotificationResponse...\n");
  11026. json_object *BootNotification;
  11027. BootNotification = json_tokener_parse(payload);
  11028. if(!is_error(BootNotification))
  11029. {
  11030. // Required data
  11031. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11032. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11033. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11034. }
  11035. json_object_put(BootNotification);
  11036. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11037. BootNotificationInterval = intervalInt;
  11038. HeartBeatWaitTime = intervalInt;
  11039. //write back to ShmOCPP16DataPH->BootNotification
  11040. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11041. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11042. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11043. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11044. {
  11045. server_sign = TRUE;
  11046. server_pending =FALSE;
  11047. }
  11048. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11049. {
  11050. server_pending = TRUE;
  11051. }
  11052. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11053. srand(time(NULL));
  11054. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11055. SetOcppConnStatus(TRUE);
  11056. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11057. }
  11058. void handleDataTransferResponse(char *payload, int gun_index)
  11059. {
  11060. char sstr[160]={0};//sstr[200]={ 0 };
  11061. int c = 0;
  11062. char *loc;
  11063. DEBUG_INFO("handleDataTransferResponse ...\n");
  11064. loc = strstr(payload, "status");
  11065. c = 0;
  11066. while (loc[3+strlen("status")+c] != '\"')
  11067. {
  11068. sstr[c] = loc[3+strlen("status")+c];
  11069. c++;
  11070. }
  11071. sstr[c] = '\0';
  11072. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11073. }
  11074. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11075. {
  11076. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11077. //struct json_object *obj;
  11078. // obj = json_tokener_parse(payload);
  11079. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11080. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11081. //No fields are defined.
  11082. }
  11083. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11084. {
  11085. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11086. //struct json_object *obj;
  11087. // obj = json_tokener_parse(payload);
  11088. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11089. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11090. //No fields are defined.
  11091. }
  11092. void handleHeartbeatResponse(char *payload, int gun_index)
  11093. {
  11094. mtrace();
  11095. DEBUG_INFO("handleHeartbeatResponse...\n");
  11096. json_object *Heartbeat;
  11097. Heartbeat = json_tokener_parse(payload);
  11098. if(!is_error(Heartbeat))
  11099. {
  11100. // Required data
  11101. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11102. }
  11103. json_object_put(Heartbeat);
  11104. if(FirstHeartBeat == 0)
  11105. {
  11106. FirstHeartBeat = 1;
  11107. DEBUG_INFO("FirstHeartBeat \n");
  11108. }
  11109. HeartBeatWithNOResponse = 0;
  11110. clientTime.Heartbeat=time((time_t*)NULL);
  11111. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11112. }
  11113. void handleMeterValuesResponse(char *payload, int gun_index)
  11114. {
  11115. mtrace();
  11116. DEBUG_INFO("handleMeterValuesResponse...\n");
  11117. }
  11118. void handleStartTransactionResponse(char *payload, int gun_index)
  11119. {
  11120. mtrace();
  11121. //int transactionIdInt = 0;
  11122. FILE *outfile;
  11123. char data[100]={0};
  11124. DEBUG_INFO("handleStartTransactionResponse...\n");
  11125. json_object *StartTransaction;
  11126. StartTransaction = json_tokener_parse(payload);
  11127. if(!is_error(StartTransaction))
  11128. {
  11129. // Required data
  11130. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11131. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11132. // Optional data
  11133. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11134. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11135. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11136. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11137. }
  11138. json_object_put(StartTransaction);
  11139. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11140. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11141. //-----------Start : write to the Queue TransactionId file -----------------//
  11142. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11143. {}
  11144. else
  11145. {
  11146. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11147. if(log == NULL)
  11148. {
  11149. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11150. return ;
  11151. }
  11152. else
  11153. {
  11154. fclose(log);
  11155. }
  11156. }
  11157. // open file for writing
  11158. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11159. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11160. {
  11161. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11162. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11163. fputs(data, outfile);
  11164. fclose (outfile);
  11165. }
  11166. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11167. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11168. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11169. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11170. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11171. }
  11172. void handleStatusNotificationResponse(char *payload, int gun_index)
  11173. {
  11174. mtrace();
  11175. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11176. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11177. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11178. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11179. }
  11180. void handleStopTransactionnResponse(char *payload, int gun_index)
  11181. {
  11182. mtrace();
  11183. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11184. json_object *StopTransaction;
  11185. StopTransaction = json_tokener_parse(payload);
  11186. if(!is_error(StopTransaction))
  11187. {
  11188. // Optional data
  11189. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11190. {
  11191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11192. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11193. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11194. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11195. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11196. }
  11197. }
  11198. json_object_put(StopTransaction);
  11199. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11200. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11201. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11202. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11203. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11204. }
  11205. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11206. {
  11207. mtrace();
  11208. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11209. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  11210. }
  11211. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11212. {
  11213. mtrace();
  11214. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11215. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  11216. }
  11217. void handleSignCertificateResponse(char *payload, int gun_index)
  11218. {
  11219. mtrace();
  11220. DEBUG_INFO("handleSignCertificateResponse...\n");
  11221. json_object *SignCertificate;
  11222. SignCertificate = json_tokener_parse(payload);
  11223. if(!is_error(SignCertificate))
  11224. {
  11225. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11226. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  11227. }
  11228. json_object_put(SignCertificate);
  11229. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  11230. }
  11231. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11232. {
  11233. mtrace();
  11234. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11235. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11236. }
  11237. //==========================================
  11238. // Handle Error routine
  11239. //==========================================
  11240. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11241. {
  11242. mtrace();
  11243. #ifdef SystemLogMessage
  11244. DEBUG_INFO("errorCode: %s\n", errorCode);
  11245. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11246. DEBUG_INFO("errorDetails: %s\n", payload);
  11247. #endif
  11248. }
  11249. //===============================================
  11250. // Common routine
  11251. //===============================================
  11252. int initialConfigurationTable(void)
  11253. {
  11254. //clock_t start_t, end_t, total_t;
  11255. FILE *fp;
  11256. FILE *outfile;
  11257. char str[512]={0};
  11258. char sstr[256]={0};
  11259. int c = 0;
  11260. char *loc;
  11261. int confVersion = 3;
  11262. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11263. //start_t = clock();
  11264. //printf("Starting of the program, start_t = %ld\n", start_t);
  11265. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11266. // Check configuration file size is correct
  11267. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  11268. {
  11269. struct stat st;
  11270. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  11271. if(st.st_size < 3100)
  11272. {
  11273. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  11274. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11275. }
  11276. }
  11277. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  11278. {
  11279. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11280. if(outfile == NULL)
  11281. {
  11282. DEBUG_INFO("Error opening file\n");
  11283. return FALSE;
  11284. }
  11285. /*Core Profile*/
  11286. //AllowOfflineTxForUnknownId
  11287. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11288. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11291. //AuthorizationCacheEnabled
  11292. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11293. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11296. //AuthorizeRemoteTxRequests
  11297. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11301. //BlinkRepeat
  11302. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11306. //ClockAlignedDataInterval
  11307. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11308. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11309. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11311. //ConnectionTimeOut
  11312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11316. //GetConfigurationMaxKeys
  11317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11319. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11321. // HeartbeatInterval
  11322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11326. // LightIntensity
  11327. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11329. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11331. // LocalAuthorizeOffline
  11332. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11336. // LocalPreAuthorize
  11337. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11341. // MaxEnergyOnInvalidId
  11342. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11344. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11346. // MeterValuesAlignedData
  11347. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11351. else
  11352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11354. // MeterValuesAlignedDataMaxLength
  11355. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11359. else
  11360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11362. // MeterValuesSampledData
  11363. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11365. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11367. else
  11368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11370. // MeterValuesSampledDataMaxLength
  11371. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11375. else
  11376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11378. // MeterValueSampleInterval
  11379. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11381. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11383. // MinimumStatusDuration
  11384. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11386. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11387. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11389. // NumberOfConnectors
  11390. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11391. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11393. {
  11394. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11395. }
  11396. else
  11397. {
  11398. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11399. }
  11400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11401. // ResetRetries
  11402. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11406. // ConnectorPhaseRotation
  11407. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11408. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11409. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11411. // ConnectorPhaseRotationMaxLength
  11412. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11413. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11414. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11416. // StopTransactionOnEVSideDisconnect
  11417. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11419. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11421. // StopTransactionOnInvalidId
  11422. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11424. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11426. // StopTxnAlignedData
  11427. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11429. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11431. // StopTxnAlignedDataMaxLength
  11432. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11434. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11436. // StopTxnSampledData
  11437. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11440. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11441. else
  11442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11444. // StopTxnSampledDataMaxLength
  11445. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11446. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11448. {
  11449. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11450. }
  11451. else
  11452. {
  11453. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11454. }
  11455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11456. // SupportedFeatureProfiles
  11457. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11458. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11459. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11461. // SupportedFeatureProfilesMaxLength
  11462. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11463. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11464. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11466. // TransactionMessageAttempts
  11467. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11468. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11469. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11470. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11472. // TransactionMessageRetryInterval
  11473. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11474. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11475. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11476. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11478. // UnlockConnectorOnEVSideDisconnect
  11479. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11480. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11481. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11483. // WebSocketPingInterval
  11484. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11485. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11486. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11488. // QueueOffLineStartTransactionMessage
  11489. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11490. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11491. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11493. // AuthorizationKey
  11494. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11495. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11496. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  11497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11498. // SecurityProfile
  11499. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11500. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11501. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11503. // DefaultPrice
  11504. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11505. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11506. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11508. // CustomDisplayCostAndPrice
  11509. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11510. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11511. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11513. // CustomIdleFeeAfterStop
  11514. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11515. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11516. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11518. // Configuration Version
  11519. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11520. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11521. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11523. //* Local Auth List Management Profile*/
  11524. #if 0
  11525. //For OCTT Test Case
  11526. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11528. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11529. #endif
  11530. #if 1
  11531. //LocalAuthListEnabled
  11532. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11533. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11534. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11536. #endif
  11537. //LocalAuthListMaxLength
  11538. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11539. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11540. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11542. //SendLocalListMaxLength
  11543. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11544. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11545. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11547. //ReserveConnectorZeroSupported
  11548. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11549. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11550. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11552. //* Smart Charging Profile */
  11553. //ChargeProfileMaxStackLevel
  11554. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11555. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11556. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11558. // ChargingScheduleAllowedChargingRateUnit
  11559. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11560. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11561. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11563. // ChargingScheduleMaxPeriods
  11564. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11565. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11566. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11568. // ConnectorSwitch3to1PhaseSupported
  11569. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11573. // MaxChargingProfilesInstalled
  11574. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11575. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11576. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11578. fclose(outfile);
  11579. }
  11580. else
  11581. {
  11582. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  11583. char keystr[60]={0};
  11584. char readonlystr[10]={0};
  11585. char valuestr[256]={0};
  11586. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  11587. if(fp == NULL) {
  11588. DEBUG_INFO("Error opening file");
  11589. return FALSE;
  11590. }
  11591. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11592. {
  11593. //DEBUG_INFO("Get Configuration \n");
  11594. if(strlen(str) > 0)
  11595. {
  11596. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11597. //*************************key*********************************/
  11598. if(strstr(str, "key") != NULL)
  11599. {
  11600. loc = strstr(str, "key");
  11601. c = 0;
  11602. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11603. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11604. {
  11605. sstr[c] = loc[strlen("key")+3+c];
  11606. c++;
  11607. }
  11608. sstr[c] = '\0';
  11609. strcpy(keystr,sstr);
  11610. }
  11611. //*************************readonly*********************************/
  11612. if(strstr(str, "readonly") != NULL)
  11613. {
  11614. loc = strstr(str, "readonly");
  11615. c = 0;
  11616. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11617. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11618. {
  11619. sstr[c] = loc[strlen("readonly")+2+c];
  11620. c++;
  11621. }
  11622. sstr[c] = '\0';
  11623. strcpy(readonlystr,sstr);
  11624. }
  11625. //*************************value*********************************/
  11626. if(strstr(str, "value") != NULL)
  11627. {
  11628. loc = strstr(str, "value");
  11629. c = 0;
  11630. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11631. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11632. {
  11633. sstr[c] = loc[strlen("value")+3+c];
  11634. c++;
  11635. }
  11636. sstr[c] = '\0';
  11637. strcpy(valuestr,sstr);
  11638. }
  11639. // DEBUG_INFO("keystr=%s\n",keystr);
  11640. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11641. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11642. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11643. {
  11644. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11645. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11646. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11647. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11648. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11649. }
  11650. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11651. {
  11652. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11653. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11654. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11655. }
  11656. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11657. {
  11658. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11660. }
  11661. if(strcmp(keystr, "BlinkRepeat") == 0)
  11662. {
  11663. //Charger.BlinkRepeat = Integer.parseInt(value);
  11664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11665. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11666. }
  11667. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11668. {
  11669. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11671. }
  11672. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11673. {
  11674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11676. }
  11677. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11678. {
  11679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11681. }
  11682. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11683. {
  11684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11686. HeartBeatWaitTime = atoi(valuestr);
  11687. }
  11688. if(strcmp(keystr, "LightIntensity") == 0)
  11689. {
  11690. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11691. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11692. }
  11693. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11694. {
  11695. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11696. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11697. }
  11698. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11699. {
  11700. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11701. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11702. }
  11703. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11704. {
  11705. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11706. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11707. }
  11708. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11709. {
  11710. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11711. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11712. }
  11713. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11714. {
  11715. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11716. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11717. }
  11718. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11719. {
  11720. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11721. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11722. }
  11723. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11724. {
  11725. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11726. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11727. }
  11728. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11729. {
  11730. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11731. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11732. }
  11733. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11734. {
  11735. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11736. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11737. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11738. }
  11739. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11740. {
  11741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11742. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11743. }
  11744. if(strcmp(keystr, "ResetRetries") == 0)
  11745. {
  11746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11748. }
  11749. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11750. {
  11751. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11753. }
  11754. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11755. {
  11756. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11757. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11758. }
  11759. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11760. {
  11761. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11762. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11763. }
  11764. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11765. {
  11766. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11767. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11768. }
  11769. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11770. {
  11771. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11772. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11773. }
  11774. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11775. {
  11776. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11777. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11778. }
  11779. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11780. {
  11781. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11782. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11783. }
  11784. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11785. {
  11786. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11787. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11788. }
  11789. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11790. {
  11791. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11792. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11793. }
  11794. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11795. {
  11796. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11797. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11798. }
  11799. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11800. {
  11801. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11802. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11803. TransactionMessageAttemptsValue = atoi(valuestr);
  11804. }
  11805. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11806. {
  11807. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11808. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11809. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11810. }
  11811. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11812. {
  11813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11814. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11815. }
  11816. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11817. {
  11818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11820. }
  11821. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11822. {
  11823. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11824. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11825. }
  11826. if(strcmp(keystr, "AuthorizationKey") == 0)
  11827. {
  11828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11829. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11830. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11831. }
  11832. if(strcmp(keystr, "SecurityProfile") == 0)
  11833. {
  11834. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11835. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11836. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11837. }
  11838. if(strcmp(keystr, "DefaultPrice") == 0)
  11839. {
  11840. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11841. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11842. }
  11843. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11844. {
  11845. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11846. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11847. }
  11848. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11849. {
  11850. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11851. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11852. }
  11853. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11854. {
  11855. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11856. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11857. }
  11858. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11859. {
  11860. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11861. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11862. }
  11863. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11864. {
  11865. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11866. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11867. }
  11868. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11869. {
  11870. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11871. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11872. }
  11873. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11874. {
  11875. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11876. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11877. }
  11878. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11879. {
  11880. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11881. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11882. }
  11883. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11884. {
  11885. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11886. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11887. }
  11888. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11889. {
  11890. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11891. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11892. }
  11893. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11894. {
  11895. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11896. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11897. }
  11898. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11899. {
  11900. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11901. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11902. }
  11903. }
  11904. }
  11905. fclose(fp);
  11906. }
  11907. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11908. {
  11909. return PASS;
  11910. }
  11911. else
  11912. {
  11913. return FAIL;
  11914. }
  11915. }
  11916. void StoreConfigurationTable(void)
  11917. {
  11918. FILE *outfile;
  11919. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11920. if(outfile == NULL)
  11921. {
  11922. DEBUG_INFO("Error opening file");
  11923. return ;
  11924. }
  11925. /*Core Profile*/
  11926. //AllowOfflineTxForUnknownId
  11927. /*
  11928. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11929. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11930. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11932. */
  11933. //DEBUG_INFO("data=%s\n",data);
  11934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11935. //AuthorizationCacheEnabled
  11936. /*
  11937. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11940. */
  11941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11942. //AuthorizeRemoteTxRequests
  11943. /*
  11944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11947. */
  11948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11949. //BlinkRepeat
  11950. /*
  11951. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11954. */
  11955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11956. //ClockAlignedDataInterval
  11957. /*
  11958. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11961. */
  11962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11963. //ConnectionTimeOut
  11964. /*
  11965. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11968. */
  11969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11970. //GetConfigurationMaxKeys
  11971. /*
  11972. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11975. */
  11976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11977. // HeartbeatInterval
  11978. /*
  11979. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11982. */
  11983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11984. // LightIntensity
  11985. /*
  11986. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11989. */
  11990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11991. // LocalAuthorizeOffline
  11992. /*
  11993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11996. */
  11997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11998. // LocalPreAuthorize
  11999. /*
  12000. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12003. */
  12004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12005. // MaxEnergyOnInvalidId
  12006. /*
  12007. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12010. */
  12011. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12013. // MeterValuesAlignedData
  12014. /*
  12015. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12017. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12018. */
  12019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12020. // MeterValuesAlignedDataMaxLength
  12021. /*
  12022. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12024. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12025. */
  12026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12027. // MeterValuesSampledData
  12028. /*
  12029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12032. */
  12033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12034. // MeterValuesSampledDataMaxLength
  12035. /*
  12036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12039. */
  12040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12041. // MeterValueSampleInterval
  12042. /*
  12043. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12046. */
  12047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12048. // MinimumStatusDuration
  12049. /*
  12050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12053. */
  12054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12055. // NumberOfConnectors
  12056. /*
  12057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12059. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12060. {
  12061. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12062. }
  12063. else
  12064. {
  12065. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12066. }
  12067. */
  12068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12069. // ResetRetries
  12070. /*
  12071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12074. */
  12075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12076. // ConnectorPhaseRotation
  12077. /*
  12078. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12080. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12081. */
  12082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12083. // ConnectorPhaseRotationMaxLength
  12084. /*
  12085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12088. */
  12089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12090. // StopTransactionOnEVSideDisconnect
  12091. /*
  12092. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12095. */
  12096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12097. // StopTransactionOnInvalidId
  12098. /*
  12099. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12102. */
  12103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12104. // StopTxnAlignedData
  12105. /*
  12106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12109. */
  12110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12111. // StopTxnAlignedDataMaxLength
  12112. /*
  12113. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12116. */
  12117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12118. // StopTxnSampledData
  12119. /*
  12120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12123. */
  12124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12125. // StopTxnSampledDataMaxLength
  12126. /*
  12127. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12130. */
  12131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12132. // SupportedFeatureProfiles
  12133. /*
  12134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12137. */
  12138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12139. // SupportedFeatureProfilesMaxLength
  12140. /*
  12141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12144. */
  12145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12146. // TransactionMessageAttempts
  12147. /*
  12148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12151. */
  12152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12153. // TransactionMessageRetryInterval
  12154. /*
  12155. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12158. */
  12159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12160. // UnlockConnectorOnEVSideDisconnect
  12161. /*
  12162. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12165. */
  12166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12167. // WebSocketPingInterval
  12168. /*
  12169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12172. */
  12173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12174. // QueueOffLineStartTransactionMessage
  12175. /*
  12176. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12179. */
  12180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12181. // AuthorizationKey
  12182. /*
  12183. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12186. */
  12187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12188. // SecurityProfile
  12189. /*
  12190. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12193. */
  12194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12195. // DefaultPrice
  12196. /*
  12197. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12200. */
  12201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12202. // CustomDisplayCostAndPrice
  12203. /*
  12204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12207. */
  12208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12209. // CustomIdleFeeAfterStop
  12210. /*
  12211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12214. */
  12215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12216. // ConfigurationVersion
  12217. /*
  12218. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12221. */
  12222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12223. //* Local Auth List Management Profile*/
  12224. //LocalAuthListEnabled
  12225. /*
  12226. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12228. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12229. */
  12230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12231. //LocalAuthListMaxLength
  12232. /*
  12233. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12236. */
  12237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12238. //SendLocalListMaxLength
  12239. /*
  12240. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12242. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12243. */
  12244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12245. //ReserveConnectorZeroSupported
  12246. /*
  12247. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12250. */
  12251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12252. //* Smart Charging Profile */
  12253. //ChargeProfileMaxStackLevel
  12254. /*
  12255. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12257. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12258. */
  12259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12260. // ChargingScheduleAllowedChargingRateUnit
  12261. /*
  12262. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12263. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12265. */
  12266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12267. // ChargingScheduleMaxPeriods
  12268. /*
  12269. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12272. */
  12273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12274. // ConnectorSwitch3to1PhaseSupported
  12275. /*
  12276. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12278. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12279. */
  12280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12281. // MaxChargingProfilesInstalled
  12282. /*
  12283. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12286. */
  12287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12288. fclose(outfile);
  12289. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12290. }
  12291. void getKeyValue(char *keyReq)
  12292. {
  12293. int isEmpty = FALSE;
  12294. int isKnowKey = FALSE;
  12295. DEBUG_INFO("keyReq = %s\n", keyReq);
  12296. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12297. isEmpty = TRUE;
  12298. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12299. {
  12300. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12302. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12303. {
  12304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12305. }
  12306. else
  12307. {
  12308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12309. }
  12310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12311. isKnowKey = TRUE;
  12312. }
  12313. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12314. {
  12315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12317. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12318. {
  12319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12320. }
  12321. else
  12322. {
  12323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12324. }
  12325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12326. isKnowKey = TRUE;
  12327. }
  12328. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12329. {
  12330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12332. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12333. {
  12334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12335. }
  12336. else
  12337. {
  12338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12339. }
  12340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12341. isKnowKey = TRUE;
  12342. }
  12343. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12344. {
  12345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12347. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12348. {
  12349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12350. }
  12351. else
  12352. {
  12353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12354. }
  12355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12356. isKnowKey = TRUE;
  12357. }
  12358. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12359. {
  12360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12362. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12363. {
  12364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12365. }
  12366. else
  12367. {
  12368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12369. }
  12370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12371. isKnowKey = TRUE;
  12372. }
  12373. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12374. {
  12375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12377. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12378. {
  12379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12380. }
  12381. else
  12382. {
  12383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12384. }
  12385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12386. isKnowKey = TRUE;
  12387. }
  12388. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12389. {
  12390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12392. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12393. {
  12394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12395. }
  12396. else
  12397. {
  12398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12399. }
  12400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12401. isKnowKey = TRUE;
  12402. }
  12403. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12404. {
  12405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12407. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12408. {
  12409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12410. }
  12411. else
  12412. {
  12413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12414. }
  12415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12416. isKnowKey = TRUE;
  12417. }
  12418. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12419. {
  12420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12422. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12423. {
  12424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12425. }
  12426. else
  12427. {
  12428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12429. }
  12430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12431. isKnowKey = TRUE;
  12432. }
  12433. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12434. {
  12435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12437. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12438. {
  12439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12440. }
  12441. else
  12442. {
  12443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12444. }
  12445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12446. isKnowKey = TRUE;
  12447. }
  12448. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12449. {
  12450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12452. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12453. {
  12454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12455. }
  12456. else
  12457. {
  12458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12459. }
  12460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12461. isKnowKey = TRUE;
  12462. }
  12463. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12464. {
  12465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12467. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12468. {
  12469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12470. }
  12471. else
  12472. {
  12473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12474. }
  12475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12476. isKnowKey = TRUE;
  12477. }
  12478. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12479. {
  12480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12482. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12483. {
  12484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12485. }
  12486. else
  12487. {
  12488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12489. }
  12490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12491. isKnowKey = TRUE;
  12492. }
  12493. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12494. {
  12495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12497. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12498. {
  12499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12500. }
  12501. else
  12502. {
  12503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12504. }
  12505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12506. isKnowKey = TRUE;
  12507. }
  12508. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12509. {
  12510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12512. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12513. {
  12514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12515. }
  12516. else
  12517. {
  12518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12519. }
  12520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12521. isKnowKey = TRUE;
  12522. }
  12523. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12524. {
  12525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12527. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12528. {
  12529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12530. }
  12531. else
  12532. {
  12533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12534. }
  12535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12536. isKnowKey = TRUE;
  12537. }
  12538. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12539. {
  12540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12542. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12543. {
  12544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12545. }
  12546. else
  12547. {
  12548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12549. }
  12550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12551. isKnowKey = TRUE;
  12552. }
  12553. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12554. {
  12555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12557. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12558. {
  12559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12560. }
  12561. else
  12562. {
  12563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12564. }
  12565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  12566. isKnowKey = TRUE;
  12567. }
  12568. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12569. {
  12570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12572. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12573. {
  12574. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12575. }
  12576. else
  12577. {
  12578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12579. }
  12580. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12582. isKnowKey = TRUE;
  12583. }
  12584. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12585. {
  12586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12588. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12589. {
  12590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12591. }
  12592. else
  12593. {
  12594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12595. }
  12596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12597. isKnowKey = TRUE;
  12598. }
  12599. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12600. {
  12601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12603. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12604. {
  12605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12606. }
  12607. else
  12608. {
  12609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12610. }
  12611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12612. isKnowKey = TRUE;
  12613. }
  12614. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12615. {
  12616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12618. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12619. {
  12620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12621. }
  12622. else
  12623. {
  12624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12625. }
  12626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12627. isKnowKey = TRUE;
  12628. }
  12629. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12630. {
  12631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12633. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12634. {
  12635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12636. }
  12637. else
  12638. {
  12639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12640. }
  12641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12642. isKnowKey = TRUE;
  12643. }
  12644. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12645. {
  12646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12648. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12649. {
  12650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12651. }
  12652. else
  12653. {
  12654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12655. }
  12656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12657. isKnowKey = TRUE;
  12658. }
  12659. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12660. {
  12661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12663. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12664. {
  12665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12666. }
  12667. else
  12668. {
  12669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12670. }
  12671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12672. isKnowKey = TRUE;
  12673. }
  12674. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12675. {
  12676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12678. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12679. {
  12680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12681. }
  12682. else
  12683. {
  12684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12685. }
  12686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12687. isKnowKey = TRUE;
  12688. }
  12689. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12690. {
  12691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12693. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12694. {
  12695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12696. }
  12697. else
  12698. {
  12699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12700. }
  12701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12702. isKnowKey = TRUE;
  12703. }
  12704. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12705. {
  12706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12708. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12709. {
  12710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12711. }
  12712. else
  12713. {
  12714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12715. }
  12716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12717. isKnowKey = TRUE;
  12718. }
  12719. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12720. {
  12721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12723. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12724. {
  12725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12726. }
  12727. else
  12728. {
  12729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12730. }
  12731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12732. isKnowKey = TRUE;
  12733. }
  12734. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12735. {
  12736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12738. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12739. {
  12740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12741. }
  12742. else
  12743. {
  12744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12745. }
  12746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12747. isKnowKey = TRUE;
  12748. }
  12749. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12750. {
  12751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12753. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12754. {
  12755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12756. }
  12757. else
  12758. {
  12759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12760. }
  12761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12762. isKnowKey = TRUE;
  12763. }
  12764. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12765. {
  12766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12768. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12769. {
  12770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12771. }
  12772. else
  12773. {
  12774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12775. }
  12776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12777. isKnowKey = TRUE;
  12778. }
  12779. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12780. {
  12781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12783. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12784. {
  12785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12786. }
  12787. else
  12788. {
  12789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12790. }
  12791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12792. isKnowKey = TRUE;
  12793. }
  12794. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12795. {
  12796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12798. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12799. {
  12800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12801. }
  12802. else
  12803. {
  12804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12805. }
  12806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12807. isKnowKey = TRUE;
  12808. }
  12809. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12810. {
  12811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12813. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12814. {
  12815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12816. }
  12817. else
  12818. {
  12819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12820. }
  12821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12822. isKnowKey = TRUE;
  12823. }
  12824. /*
  12825. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12826. {
  12827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12829. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12830. {
  12831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12832. }
  12833. else
  12834. {
  12835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12836. }
  12837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12838. isKnowKey = TRUE;
  12839. }*/
  12840. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12841. {
  12842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12843. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12844. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12845. {
  12846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12847. }
  12848. else
  12849. {
  12850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12851. }
  12852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12853. isKnowKey = TRUE;
  12854. }
  12855. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12856. {
  12857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12859. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12860. {
  12861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12862. }
  12863. else
  12864. {
  12865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12866. }
  12867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12868. isKnowKey = TRUE;
  12869. }
  12870. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12871. {
  12872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12874. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12875. {
  12876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12877. }
  12878. else
  12879. {
  12880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12881. }
  12882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12883. isKnowKey = TRUE;
  12884. }
  12885. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12886. {
  12887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12889. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12890. {
  12891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12892. }
  12893. else
  12894. {
  12895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12896. }
  12897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12898. isKnowKey = TRUE;
  12899. }
  12900. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12901. {
  12902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12904. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12905. {
  12906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12907. }
  12908. else
  12909. {
  12910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12911. }
  12912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12913. isKnowKey = TRUE;
  12914. }
  12915. #if 1
  12916. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12917. {
  12918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12920. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12921. {
  12922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12923. }
  12924. else
  12925. {
  12926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12927. }
  12928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12929. isKnowKey = TRUE;
  12930. }
  12931. #endif
  12932. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12933. {
  12934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12935. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12936. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12937. {
  12938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12939. }
  12940. else
  12941. {
  12942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12943. }
  12944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12945. isKnowKey = TRUE;
  12946. }
  12947. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12948. {
  12949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12951. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12952. {
  12953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12954. }
  12955. else
  12956. {
  12957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12958. }
  12959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12960. isKnowKey = TRUE;
  12961. }
  12962. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12963. {
  12964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12966. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12967. {
  12968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12969. }
  12970. else
  12971. {
  12972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12973. }
  12974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12975. isKnowKey = TRUE;
  12976. }
  12977. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12978. {
  12979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12980. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12981. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12982. {
  12983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12984. }
  12985. else
  12986. {
  12987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12988. }
  12989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12990. isKnowKey = TRUE;
  12991. }
  12992. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12993. {
  12994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12996. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12997. {
  12998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12999. }
  13000. else
  13001. {
  13002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13003. }
  13004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13005. isKnowKey = TRUE;
  13006. }
  13007. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13008. {
  13009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13011. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13012. {
  13013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13014. }
  13015. else
  13016. {
  13017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13018. }
  13019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13020. isKnowKey = TRUE;
  13021. }
  13022. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13023. {
  13024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13026. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13027. {
  13028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13029. }
  13030. else
  13031. {
  13032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13033. }
  13034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13035. isKnowKey = TRUE;
  13036. }
  13037. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13038. {
  13039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13041. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13042. {
  13043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13044. }
  13045. else
  13046. {
  13047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13048. }
  13049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13050. isKnowKey = TRUE;
  13051. }
  13052. //=========================================================
  13053. if(!isEmpty && !isKnowKey)
  13054. {
  13055. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13056. strcpy(unknownkey[UnknownKeynum], keyReq);
  13057. UnknownKeynum = UnknownKeynum + 1;
  13058. }
  13059. }
  13060. void processUnkownKey(void)
  13061. {
  13062. DEBUG_INFO("processUnkownKey...\n");
  13063. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13064. for(int index=0; index < UnknownKeynum; index++)
  13065. {
  13066. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13067. {
  13068. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13069. }
  13070. }
  13071. }
  13072. int setKeyValue(char *key, char *value)
  13073. {
  13074. int isSuccess = NotSupported;
  13075. int check_ascii=0;
  13076. char str[256]={0};
  13077. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13078. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13079. {
  13080. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13081. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13082. {
  13083. strcpy(str, (const char*)value);
  13084. for(int i = 0; str[i]; i++){
  13085. str[i] = tolower(str[i]);
  13086. }
  13087. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13088. isSuccess = ConfigurationStatus_Accepted;
  13089. }
  13090. else
  13091. {
  13092. isSuccess = ConfigurationStatus_Rejected;
  13093. }
  13094. }
  13095. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13096. {
  13097. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13098. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13099. {
  13100. strcpy(str, (const char*)value);
  13101. for(int i = 0; str[i]; i++){
  13102. str[i] = tolower(str[i]);
  13103. }
  13104. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13105. isSuccess = ConfigurationStatus_Accepted;
  13106. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13107. }
  13108. else
  13109. {
  13110. isSuccess = ConfigurationStatus_Rejected;
  13111. }
  13112. }
  13113. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13114. {
  13115. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13116. {
  13117. strcpy(str, (const char*)value);
  13118. for(int i = 0; str[i]; i++)
  13119. {
  13120. str[i] = tolower(str[i]);
  13121. }
  13122. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13123. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13124. isSuccess = ConfigurationStatus_Accepted;
  13125. }
  13126. else
  13127. {
  13128. isSuccess = ConfigurationStatus_Rejected;
  13129. }
  13130. }
  13131. if(strcmp(key, "BlinkRepeat") == 0)
  13132. {
  13133. //Charger.BlinkRepeat = Integer.parseInt(value);
  13134. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13135. {
  13136. check_ascii = value[0];
  13137. if( (check_ascii < 48) || (check_ascii > 57) )
  13138. {
  13139. isSuccess = ConfigurationStatus_Rejected;
  13140. }
  13141. else
  13142. {
  13143. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13144. isSuccess = ConfigurationStatus_Accepted;
  13145. }
  13146. }
  13147. else
  13148. {
  13149. isSuccess = ConfigurationStatus_Rejected;
  13150. }
  13151. }
  13152. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13153. {
  13154. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13155. {
  13156. check_ascii = value[0];
  13157. if( (check_ascii < 48) || (check_ascii > 57) )
  13158. {
  13159. isSuccess = ConfigurationStatus_Rejected;
  13160. }
  13161. else
  13162. {
  13163. if((atoi(value) == 0) || (atoi(value) >= 10))
  13164. {
  13165. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13166. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13167. isSuccess = ConfigurationStatus_Accepted;
  13168. }
  13169. else
  13170. isSuccess = ConfigurationStatus_Rejected;
  13171. }
  13172. }
  13173. else
  13174. {
  13175. isSuccess = ConfigurationStatus_Rejected;
  13176. }
  13177. }
  13178. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13179. {
  13180. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13181. {
  13182. check_ascii = value[0];
  13183. if( (check_ascii < 48) || (check_ascii > 57) )
  13184. {
  13185. isSuccess = ConfigurationStatus_Rejected;
  13186. }
  13187. else
  13188. {
  13189. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13190. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13191. isSuccess = ConfigurationStatus_Accepted;
  13192. }
  13193. }
  13194. else
  13195. {
  13196. isSuccess = ConfigurationStatus_Rejected;
  13197. }
  13198. }
  13199. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13200. {
  13201. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13202. {
  13203. check_ascii = value[0];
  13204. if( (check_ascii < 48) || (check_ascii > 57) )
  13205. {
  13206. isSuccess = ConfigurationStatus_Rejected;
  13207. }
  13208. else
  13209. {
  13210. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13211. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13212. isSuccess = ConfigurationStatus_Accepted;
  13213. }
  13214. }
  13215. else
  13216. {
  13217. isSuccess = ConfigurationStatus_Rejected;
  13218. }
  13219. }
  13220. if(strcmp(key, "HeartbeatInterval") == 0)
  13221. {
  13222. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13223. {
  13224. check_ascii = value[0];
  13225. if( (check_ascii < 48) || (check_ascii > 57) )
  13226. {
  13227. isSuccess = ConfigurationStatus_Rejected;
  13228. }
  13229. else
  13230. {
  13231. if((atoi(value) == 0) || (atoi(value) >= 10))
  13232. {
  13233. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13234. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13235. HeartBeatWaitTime = atoi(value);
  13236. isSuccess = ConfigurationStatus_Accepted;
  13237. }
  13238. else
  13239. {
  13240. isSuccess = ConfigurationStatus_Rejected;
  13241. }
  13242. }
  13243. }
  13244. else
  13245. {
  13246. isSuccess = ConfigurationStatus_Rejected;
  13247. }
  13248. }
  13249. if(strcmp(key, "LightIntensity") == 0)
  13250. {
  13251. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13252. {
  13253. check_ascii = value[0];
  13254. if( (check_ascii < 48) || (check_ascii > 57) )
  13255. {
  13256. isSuccess = ConfigurationStatus_Rejected;
  13257. }
  13258. else
  13259. {
  13260. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13261. isSuccess = ConfigurationStatus_Accepted;
  13262. }
  13263. }
  13264. else
  13265. {
  13266. isSuccess = ConfigurationStatus_Rejected;
  13267. }
  13268. }
  13269. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13270. {
  13271. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13272. {
  13273. strcpy(str, (const char*)value);
  13274. for(int i = 0; str[i]; i++)
  13275. {
  13276. str[i] = tolower(str[i]);
  13277. }
  13278. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13279. isSuccess = ConfigurationStatus_Accepted;
  13280. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13281. }
  13282. else
  13283. {
  13284. isSuccess = ConfigurationStatus_Rejected;
  13285. }
  13286. }
  13287. if(strcmp(key, "LocalPreAuthorize") == 0)
  13288. {
  13289. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13290. {
  13291. strcpy(str, (const char*)value);
  13292. for(int i = 0; str[i]; i++)
  13293. {
  13294. str[i] = tolower(str[i]);
  13295. }
  13296. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13297. isSuccess = ConfigurationStatus_Accepted;
  13298. }
  13299. else
  13300. {
  13301. isSuccess = ConfigurationStatus_Rejected;
  13302. }
  13303. }
  13304. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13305. {
  13306. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13307. {
  13308. check_ascii = value[0];
  13309. if( (check_ascii < 48) || (check_ascii > 57) )
  13310. {
  13311. isSuccess = ConfigurationStatus_Rejected;
  13312. }
  13313. else
  13314. {
  13315. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13316. isSuccess = ConfigurationStatus_Accepted;
  13317. }
  13318. }
  13319. else
  13320. {
  13321. isSuccess = ConfigurationStatus_Rejected;
  13322. }
  13323. }
  13324. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13325. {
  13326. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13327. {
  13328. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13329. isSuccess = ConfigurationStatus_Accepted;
  13330. }
  13331. else
  13332. {
  13333. isSuccess = ConfigurationStatus_Rejected;
  13334. }
  13335. }
  13336. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13337. {
  13338. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13339. {
  13340. check_ascii = value[0];
  13341. if( (check_ascii < 48) || (check_ascii > 57) )
  13342. {
  13343. isSuccess = ConfigurationStatus_Rejected;
  13344. }
  13345. else
  13346. {
  13347. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13348. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13349. isSuccess = ConfigurationStatus_Accepted;
  13350. }
  13351. }
  13352. else
  13353. {
  13354. isSuccess = ConfigurationStatus_Rejected;
  13355. }
  13356. }
  13357. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13358. {
  13359. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13360. {
  13361. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13362. isSuccess = ConfigurationStatus_Accepted;
  13363. }
  13364. else
  13365. {
  13366. isSuccess = ConfigurationStatus_Rejected;
  13367. }
  13368. }
  13369. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13370. {
  13371. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13372. {
  13373. check_ascii = value[0];
  13374. if( (check_ascii < 48) || (check_ascii > 57) )
  13375. {
  13376. isSuccess = ConfigurationStatus_Rejected;
  13377. }
  13378. else
  13379. {
  13380. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13381. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13382. isSuccess = ConfigurationStatus_Accepted;
  13383. }
  13384. }
  13385. else
  13386. {
  13387. isSuccess = ConfigurationStatus_Rejected;
  13388. }
  13389. }
  13390. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13391. {
  13392. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13393. {
  13394. check_ascii = value[0];
  13395. if( (check_ascii < 48) || (check_ascii > 57) )
  13396. {
  13397. isSuccess = ConfigurationStatus_Rejected;
  13398. }
  13399. else
  13400. {
  13401. if((atoi(value) == 0) || (atoi(value) >= 10))
  13402. {
  13403. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13404. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13405. isSuccess = ConfigurationStatus_Accepted;
  13406. }
  13407. else
  13408. {
  13409. isSuccess = ConfigurationStatus_Rejected;
  13410. }
  13411. }
  13412. }
  13413. else
  13414. {
  13415. isSuccess = ConfigurationStatus_Rejected;
  13416. }
  13417. }
  13418. if(strcmp(key, "MinimumStatusDuration") == 0)
  13419. {
  13420. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13421. {
  13422. check_ascii = value[0];
  13423. if( (check_ascii < 48) || (check_ascii > 57) )
  13424. {
  13425. isSuccess = ConfigurationStatus_Rejected;
  13426. }
  13427. else
  13428. {
  13429. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13430. {
  13431. isSuccess = ConfigurationStatus_Rejected;
  13432. }
  13433. else
  13434. {
  13435. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13436. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13437. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13438. isSuccess = ConfigurationStatus_Accepted;
  13439. }
  13440. }
  13441. }
  13442. else
  13443. {
  13444. isSuccess = ConfigurationStatus_Rejected;
  13445. }
  13446. }
  13447. if(strcmp(key, "NumberOfConnectors") == 0)
  13448. {
  13449. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13450. {
  13451. check_ascii = value[0];
  13452. if( (check_ascii < 48) || (check_ascii > 57) )
  13453. {
  13454. isSuccess = ConfigurationStatus_Rejected;
  13455. }
  13456. else
  13457. {
  13458. //Charger.ResetRetries = Integer.parseInt(value);
  13459. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13460. isSuccess = ConfigurationStatus_Accepted;
  13461. }
  13462. }
  13463. else
  13464. {
  13465. isSuccess = ConfigurationStatus_Rejected;
  13466. }
  13467. }
  13468. if(strcmp(key, "ResetRetries") == 0)
  13469. {
  13470. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13471. {
  13472. check_ascii = value[0];
  13473. if( (check_ascii < 48) || (check_ascii > 57) )
  13474. {
  13475. isSuccess = ConfigurationStatus_Rejected;
  13476. }
  13477. else
  13478. {
  13479. //Charger.ResetRetries = Integer.parseInt(value);
  13480. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13481. isSuccess = ConfigurationStatus_Accepted;
  13482. }
  13483. }
  13484. else
  13485. {
  13486. isSuccess = ConfigurationStatus_Rejected;
  13487. }
  13488. }
  13489. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13490. {
  13491. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13492. {
  13493. strcpy(str, (const char*)value);
  13494. for(int i = 0; str[i]; i++)
  13495. {
  13496. str[i] = tolower(str[i]);
  13497. }
  13498. if(strcmp(str, "notapplicable")== 0)
  13499. {
  13500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13501. isSuccess = ConfigurationStatus_Accepted;
  13502. }
  13503. else if(strcmp(str, "unknown")== 0)
  13504. {
  13505. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13506. isSuccess = ConfigurationStatus_Accepted;
  13507. }
  13508. else if(strcmp(str, "rst")== 0)
  13509. {
  13510. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13511. isSuccess = ConfigurationStatus_Accepted;
  13512. }
  13513. else if(strcmp(str, "rts")== 0)
  13514. {
  13515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13516. isSuccess = ConfigurationStatus_Accepted;
  13517. }
  13518. else if(strcmp(str, "srt")== 0)
  13519. {
  13520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13521. isSuccess = ConfigurationStatus_Accepted;
  13522. }
  13523. else if(strcmp(str, "str")== 0)
  13524. {
  13525. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13526. isSuccess = ConfigurationStatus_Accepted;
  13527. }
  13528. else if(strcmp(str, "trs")== 0)
  13529. {
  13530. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13531. isSuccess = ConfigurationStatus_Accepted;
  13532. }
  13533. else if(strcmp(str, "tsr")== 0)
  13534. {
  13535. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13536. isSuccess = ConfigurationStatus_Accepted;
  13537. }
  13538. else
  13539. {
  13540. isSuccess = ConfigurationStatus_Rejected;
  13541. }
  13542. }
  13543. else
  13544. {
  13545. isSuccess = ConfigurationStatus_Rejected;
  13546. }
  13547. }
  13548. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13549. {
  13550. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13551. {
  13552. check_ascii = value[0];
  13553. if( (check_ascii < 48) || (check_ascii > 57) )
  13554. {
  13555. isSuccess = ConfigurationStatus_Rejected;
  13556. }
  13557. else
  13558. {
  13559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13560. isSuccess = ConfigurationStatus_Accepted;
  13561. }
  13562. }
  13563. else
  13564. {
  13565. isSuccess = ConfigurationStatus_Rejected;
  13566. }
  13567. }
  13568. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13569. {
  13570. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13571. {
  13572. strcpy(str, (const char*)value);
  13573. for(int i = 0; str[i]; i++)
  13574. {
  13575. str[i] = tolower(str[i]);
  13576. }
  13577. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13579. isSuccess = ConfigurationStatus_Accepted;
  13580. }
  13581. else
  13582. {
  13583. isSuccess = ConfigurationStatus_Rejected;
  13584. }
  13585. }
  13586. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13587. {
  13588. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13589. {
  13590. strcpy(str, (const char*)value);
  13591. for(int i = 0; str[i]; i++)
  13592. {
  13593. str[i] = tolower(str[i]);
  13594. }
  13595. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13596. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13597. isSuccess = ConfigurationStatus_Accepted;
  13598. }
  13599. else
  13600. {
  13601. isSuccess = ConfigurationStatus_Rejected;
  13602. }
  13603. }
  13604. if(strcmp(key, "StopTxnAlignedData") == 0)
  13605. {
  13606. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13607. {
  13608. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13609. isSuccess = ConfigurationStatus_Accepted;
  13610. }
  13611. else
  13612. {
  13613. isSuccess = ConfigurationStatus_Rejected;
  13614. }
  13615. }
  13616. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13617. {
  13618. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13619. {
  13620. check_ascii = value[0];
  13621. if( (check_ascii < 48) || (check_ascii > 57) )
  13622. {
  13623. isSuccess = ConfigurationStatus_Rejected;
  13624. }
  13625. else
  13626. {
  13627. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13628. isSuccess = ConfigurationStatus_Accepted;
  13629. }
  13630. }
  13631. else
  13632. {
  13633. isSuccess = ConfigurationStatus_Rejected;
  13634. }
  13635. }
  13636. if(strcmp(key, "StopTxnSampledData") == 0)
  13637. {
  13638. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13639. {
  13640. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13641. isSuccess = ConfigurationStatus_Accepted;
  13642. }
  13643. else
  13644. {
  13645. isSuccess = ConfigurationStatus_Rejected;
  13646. }
  13647. }
  13648. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13649. {
  13650. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13651. {
  13652. check_ascii = value[0];
  13653. if( (check_ascii < 48) || (check_ascii > 57) )
  13654. {
  13655. isSuccess = ConfigurationStatus_Rejected;
  13656. }
  13657. else
  13658. {
  13659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13660. isSuccess = ConfigurationStatus_Accepted;
  13661. }
  13662. }
  13663. else
  13664. {
  13665. isSuccess = ConfigurationStatus_Rejected;
  13666. }
  13667. }
  13668. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13669. {
  13670. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13671. {
  13672. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13673. isSuccess = ConfigurationStatus_Accepted;
  13674. }
  13675. else
  13676. {
  13677. isSuccess = ConfigurationStatus_Rejected;
  13678. }
  13679. }
  13680. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13681. {
  13682. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13683. {
  13684. check_ascii = value[0];
  13685. if( (check_ascii < 48) || (check_ascii > 57) )
  13686. {
  13687. isSuccess = ConfigurationStatus_Rejected;
  13688. }
  13689. else
  13690. {
  13691. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13692. isSuccess = ConfigurationStatus_Accepted;
  13693. }
  13694. }
  13695. else
  13696. {
  13697. isSuccess = ConfigurationStatus_Rejected;
  13698. }
  13699. }
  13700. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13701. {
  13702. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13703. {
  13704. check_ascii = value[0];
  13705. if( (check_ascii < 48) || (check_ascii > 57) )
  13706. {
  13707. isSuccess = ConfigurationStatus_Rejected;
  13708. }
  13709. else
  13710. {
  13711. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13712. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13713. TransactionMessageAttemptsValue = atoi(value);
  13714. isSuccess = ConfigurationStatus_Accepted;
  13715. }
  13716. }
  13717. else
  13718. {
  13719. isSuccess = ConfigurationStatus_Rejected;
  13720. }
  13721. }
  13722. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13723. {
  13724. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13725. {
  13726. check_ascii = value[0];
  13727. if( (check_ascii < 48) || (check_ascii > 57) )
  13728. {
  13729. isSuccess = ConfigurationStatus_Rejected;
  13730. }
  13731. else
  13732. {
  13733. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13735. TransactionMessageRetryIntervalValue = atoi(value);
  13736. isSuccess = ConfigurationStatus_Accepted;
  13737. }
  13738. }
  13739. else
  13740. {
  13741. isSuccess = ConfigurationStatus_Rejected;
  13742. }
  13743. }
  13744. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13745. {
  13746. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13747. {
  13748. strcpy(str, (const char*)value);
  13749. for(int i = 0; str[i]; i++)
  13750. {
  13751. str[i] = tolower(str[i]);
  13752. }
  13753. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13754. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13755. isSuccess = ConfigurationStatus_Accepted;
  13756. }
  13757. else
  13758. {
  13759. isSuccess = ConfigurationStatus_Rejected;
  13760. }
  13761. }
  13762. if(strcmp(key, "WebSocketPingInterval") == 0)
  13763. {
  13764. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13765. {
  13766. check_ascii = value[0];
  13767. if( (check_ascii < 48) || (check_ascii > 57) )
  13768. {
  13769. isSuccess = ConfigurationStatus_Rejected;
  13770. }
  13771. else
  13772. {
  13773. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13774. isSuccess = ConfigurationStatus_Accepted;
  13775. }
  13776. }
  13777. else
  13778. {
  13779. isSuccess = ConfigurationStatus_Rejected;
  13780. }
  13781. }
  13782. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13783. {
  13784. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13785. {
  13786. strcpy(str, (const char*)value);
  13787. for(int i = 0; str[i]; i++)
  13788. {
  13789. str[i] = tolower(str[i]);
  13790. }
  13791. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13792. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13793. isSuccess = ConfigurationStatus_Accepted;
  13794. }
  13795. else
  13796. {
  13797. isSuccess = ConfigurationStatus_Rejected;
  13798. }
  13799. }
  13800. if(strcmp(key, "AuthorizationKey") == 0)
  13801. {
  13802. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13803. {
  13804. strcpy(str, (const char*)value);
  13805. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13806. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13807. isSuccess = ConfigurationStatus_Accepted;
  13808. }
  13809. else
  13810. {
  13811. isSuccess = ConfigurationStatus_Rejected;
  13812. }
  13813. }
  13814. if(strcmp(key, "SecurityProfile") == 0)
  13815. {
  13816. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13817. {
  13818. check_ascii = value[0];
  13819. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13820. {
  13821. isSuccess = ConfigurationStatus_Rejected;
  13822. }
  13823. else if(check_ascii == 0x33)
  13824. {
  13825. isSuccess = NotSupported;
  13826. }
  13827. else
  13828. {
  13829. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13830. {
  13831. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13832. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13833. isSuccess = ConfigurationStatus_Accepted;
  13834. }
  13835. else
  13836. isSuccess = ConfigurationStatus_Rejected;
  13837. }
  13838. }
  13839. else
  13840. {
  13841. isSuccess = ConfigurationStatus_Rejected;
  13842. }
  13843. }
  13844. if(strcmp(key, "DefaultPrice") == 0)
  13845. {
  13846. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13847. {
  13848. strcpy(str, (const char*)value);
  13849. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13850. isSuccess = ConfigurationStatus_Accepted;
  13851. }
  13852. else
  13853. {
  13854. isSuccess = ConfigurationStatus_Rejected;
  13855. }
  13856. }
  13857. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13858. {
  13859. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13860. {
  13861. strcpy(str, (const char*)value);
  13862. for(int i = 0; str[i]; i++)
  13863. {
  13864. str[i] = tolower(str[i]);
  13865. }
  13866. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13867. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13868. isSuccess = ConfigurationStatus_Accepted;
  13869. }
  13870. else
  13871. {
  13872. isSuccess = ConfigurationStatus_Rejected;
  13873. }
  13874. }
  13875. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13876. {
  13877. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13878. {
  13879. strcpy(str, (const char*)value);
  13880. for(int i = 0; str[i]; i++)
  13881. {
  13882. str[i] = tolower(str[i]);
  13883. }
  13884. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13885. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13886. isSuccess = ConfigurationStatus_Accepted;
  13887. }
  13888. else
  13889. {
  13890. isSuccess = ConfigurationStatus_Rejected;
  13891. }
  13892. }
  13893. #if 0
  13894. //For OCPP Test Case
  13895. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13896. {
  13897. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13898. {
  13899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13900. isSuccess = ConfigurationStatus_Accepted;
  13901. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13902. }
  13903. else
  13904. {
  13905. isSuccess = ConfigurationStatus_Rejected;
  13906. }
  13907. }
  13908. #endif
  13909. #if 1
  13910. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13911. {
  13912. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13913. {
  13914. strcpy(str, (const char*)value);
  13915. for(int i = 0; str[i]; i++)
  13916. {
  13917. str[i] = tolower(str[i]);
  13918. }
  13919. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13920. isSuccess = ConfigurationStatus_Accepted;
  13921. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13922. }
  13923. else
  13924. {
  13925. isSuccess = ConfigurationStatus_Rejected;
  13926. }
  13927. }
  13928. #endif
  13929. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13930. {
  13931. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13932. {
  13933. check_ascii = value[0];
  13934. if( (check_ascii < 48) || (check_ascii > 57) )
  13935. {
  13936. isSuccess = ConfigurationStatus_Rejected;
  13937. }
  13938. else
  13939. {
  13940. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13941. isSuccess = ConfigurationStatus_Accepted;
  13942. }
  13943. }
  13944. else
  13945. {
  13946. isSuccess = ConfigurationStatus_Rejected;
  13947. }
  13948. }
  13949. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13950. {
  13951. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13952. {
  13953. check_ascii = value[0];
  13954. if( (check_ascii < 48) || (check_ascii > 57) )
  13955. {
  13956. isSuccess = ConfigurationStatus_Rejected;
  13957. }
  13958. else
  13959. {
  13960. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13961. isSuccess = ConfigurationStatus_Accepted;
  13962. }
  13963. }
  13964. else
  13965. {
  13966. isSuccess = ConfigurationStatus_Rejected;
  13967. }
  13968. }
  13969. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13970. {
  13971. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13972. {
  13973. strcpy(str, (const char*)value);
  13974. for(int i = 0; str[i]; i++)
  13975. {
  13976. str[i] = tolower(str[i]);
  13977. }
  13978. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13979. isSuccess = ConfigurationStatus_Accepted;
  13980. }
  13981. else
  13982. {
  13983. isSuccess = ConfigurationStatus_Rejected;
  13984. }
  13985. }
  13986. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13987. {
  13988. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13989. {
  13990. check_ascii = value[0];
  13991. if( (check_ascii < 48) || (check_ascii > 57) )
  13992. {
  13993. isSuccess = ConfigurationStatus_Rejected;
  13994. }
  13995. else
  13996. {
  13997. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13998. isSuccess = ConfigurationStatus_Accepted;
  13999. }
  14000. }
  14001. else
  14002. {
  14003. isSuccess = ConfigurationStatus_Rejected;
  14004. }
  14005. }
  14006. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14007. {
  14008. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14009. {
  14010. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14011. isSuccess = ConfigurationStatus_Accepted;
  14012. }
  14013. else
  14014. {
  14015. isSuccess = ConfigurationStatus_Rejected;
  14016. }
  14017. }
  14018. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14019. {
  14020. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14021. {
  14022. check_ascii = value[0];
  14023. if( (check_ascii < 48) || (check_ascii > 57) )
  14024. {
  14025. isSuccess = ConfigurationStatus_Rejected;
  14026. }
  14027. else
  14028. {
  14029. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14030. isSuccess = ConfigurationStatus_Accepted;
  14031. }
  14032. }
  14033. else
  14034. {
  14035. isSuccess = ConfigurationStatus_Rejected;
  14036. }
  14037. }
  14038. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14039. {
  14040. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14041. {
  14042. strcpy(str, (const char*)value);
  14043. for(int i = 0; str[i]; i++)
  14044. {
  14045. str[i] = tolower(str[i]);
  14046. }
  14047. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14048. isSuccess = ConfigurationStatus_Accepted;
  14049. }
  14050. else
  14051. {
  14052. isSuccess = ConfigurationStatus_Rejected;
  14053. }
  14054. }
  14055. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14056. {
  14057. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14058. {
  14059. check_ascii = value[0];
  14060. if( (check_ascii < 48) || (check_ascii > 57) )
  14061. {
  14062. isSuccess = ConfigurationStatus_Rejected;
  14063. }
  14064. else
  14065. {
  14066. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14067. isSuccess = ConfigurationStatus_Accepted;
  14068. }
  14069. }
  14070. else
  14071. {
  14072. isSuccess = ConfigurationStatus_Rejected;
  14073. }
  14074. }
  14075. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14076. return isSuccess;
  14077. }
  14078. int TransactionMessageAttemptsGet(void)
  14079. {
  14080. return TransactionMessageAttemptsValue;
  14081. }
  14082. int FirstHeartBeatResponse(void)
  14083. {
  14084. return FirstHeartBeat;
  14085. }
  14086. int TransactionMessageRetryIntervalGet(void)
  14087. {
  14088. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14089. }
  14090. int ReadHttpStatus(int sock)
  14091. {
  14092. //char c;
  14093. char buff[1024]="",*ptr=buff+1;
  14094. int bytes_received, status;
  14095. DEBUG_INFO("Begin Response ..\n");
  14096. while((bytes_received = recv(sock, ptr, 1, 0))){
  14097. if(bytes_received==-1){
  14098. perror("ReadHttpStatus");
  14099. exit(1);
  14100. }
  14101. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14102. ptr++;
  14103. }
  14104. *ptr=0;
  14105. ptr=buff+1;
  14106. sscanf(ptr,"%*s %d ", &status);
  14107. DEBUG_INFO("%s\n",ptr);
  14108. DEBUG_INFO("status=%d\n",status);
  14109. DEBUG_INFO("End Response ..\n");
  14110. return (bytes_received>0)?status:0;
  14111. }
  14112. //the only filed that it parsed is 'Content-Length'
  14113. int ParseHeader(int sock)
  14114. {
  14115. //char c;
  14116. char buff[1024]="",*ptr=buff+4;
  14117. int bytes_received;
  14118. DEBUG_INFO("Begin HEADER ..\n");
  14119. while((bytes_received = recv(sock, ptr, 1, 0))){
  14120. if(bytes_received==-1){
  14121. perror("Parse Header");
  14122. exit(1);
  14123. }
  14124. if(
  14125. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14126. (ptr[-1]=='\r') && (*ptr=='\n' )
  14127. ) break;
  14128. ptr++;
  14129. }
  14130. *ptr=0;
  14131. ptr=buff+4;
  14132. //printf("%s",ptr);
  14133. if(bytes_received){
  14134. ptr=strstr(ptr,"Content-Length:");
  14135. if(ptr){
  14136. sscanf(ptr,"%*s %d",&bytes_received);
  14137. }else
  14138. bytes_received=-1; //unknown size
  14139. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14140. }
  14141. DEBUG_INFO("End HEADER ..\n");
  14142. return bytes_received ;
  14143. }
  14144. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14145. {
  14146. int result = TRUE;
  14147. char rmFileCmd[100]={0};
  14148. char FilePath[100]={0};
  14149. char ftpbuf[200];
  14150. int systemresult;
  14151. //DEBUG_INFO("filename=%s\n",filename);
  14152. //DEBUG_INFO("url=%s\n",url);
  14153. sprintf(FilePath,"/mnt/%s",filename);
  14154. system("ping 8.8.8.8 &");
  14155. if((access(FilePath,F_OK))!=-1)
  14156. {
  14157. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14158. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14159. system(rmFileCmd);
  14160. }
  14161. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14162. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14163. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14164. systemresult = system(ftpbuf);
  14165. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14166. if(systemresult != 0)
  14167. {
  14168. DEBUG_INFO("http DownLoad error!\n");
  14169. result = FALSE;
  14170. }
  14171. system("pkill ping");
  14172. return result;
  14173. }
  14174. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14175. {
  14176. int result = TRUE;
  14177. char rmFileCmd[100]={0};
  14178. char FilePath[100]={0};
  14179. char ftpbuf[200];
  14180. int systemresult;
  14181. //char temp[100];
  14182. sprintf(FilePath,"/mnt/%s",filename);
  14183. system("ping 8.8.8.8 &");
  14184. if((access(FilePath,F_OK))!=-1)
  14185. {
  14186. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14187. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14188. system(rmFileCmd);
  14189. }
  14190. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14191. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14192. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14193. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14194. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14195. systemresult = system(ftpbuf);
  14196. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14197. if(systemresult != 0)
  14198. {
  14199. DEBUG_WARN("wget error!\n");
  14200. result = FALSE;
  14201. }
  14202. system("pkill ping");
  14203. return result;
  14204. }
  14205. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14206. {
  14207. char rmFileCmd[100]={0};
  14208. char FilePath[100]={0};
  14209. char buf[512];
  14210. int systemresult = 0;
  14211. //DEBUG_INFO("filename=%s\n",filename);
  14212. //DEBUG_INFO("url=%s\n",url);
  14213. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14214. if((access(FilePath,F_OK))!=-1)
  14215. {
  14216. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14217. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14218. system(rmFileCmd);
  14219. }
  14220. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14221. if(fp == NULL)
  14222. {
  14223. DEBUG_INFO("log is NULL\n");
  14224. return FALSE;
  14225. }
  14226. else
  14227. {
  14228. fprintf(fp, "%s\n", url);
  14229. fprintf(fp, "%s\n", filename);
  14230. fclose(fp);
  14231. }
  14232. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14233. if(phpFP == NULL)
  14234. {
  14235. DEBUG_INFO("PHP upload fail.\n");
  14236. return FALSE;
  14237. }
  14238. else
  14239. {
  14240. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14241. {
  14242. if(strstr(buf, "result") != NULL)
  14243. {
  14244. sscanf(buf, "result: %d", &systemresult);
  14245. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14246. }
  14247. }
  14248. pclose(phpFP);
  14249. }
  14250. if(systemresult != 1)
  14251. {
  14252. DEBUG_INFO("HTTP upload error!\n");
  14253. return FALSE;
  14254. }
  14255. return TRUE;
  14256. }
  14257. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14258. {
  14259. struct hostent* server;
  14260. char *IPbuffer;
  14261. char ftpbuf[200];
  14262. int systemresult;
  14263. // To retrieve host information
  14264. server = gethostbyname(location);
  14265. // To convert an Internet network
  14266. // address into ASCII string
  14267. IPbuffer = inet_ntoa(*((struct in_addr*)
  14268. server->h_addr_list[0]));
  14269. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14270. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14271. /* format : ftpput -u username -p passwd IP target source*/
  14272. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14273. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14274. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14275. systemresult = system(ftpbuf);
  14276. DEBUG_INFO("systemresult=%d\n",systemresult);
  14277. if(systemresult != 0)
  14278. {
  14279. DEBUG_INFO("ftpput error!\n");
  14280. return FALSE;
  14281. }
  14282. return TRUE;
  14283. }
  14284. int GetOcppServerURL()
  14285. {
  14286. int result = FALSE;
  14287. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14288. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14289. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14290. struct yuarel url;
  14291. char urlStr[512];
  14292. // OCPPPH only
  14293. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  14294. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14295. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  14296. {
  14297. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  14298. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14299. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14300. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  14301. if(yuarel_parse(&url, urlStr) != -1)
  14302. {
  14303. sprintf(OcppProtocol, "%s", url.scheme);
  14304. sprintf(OcppHost, "%s", url.host);
  14305. if(url.path == NULL)
  14306. OcppTempPath[0] = '\0';
  14307. else
  14308. sprintf(OcppTempPath, "%s", url.path);
  14309. if(url.port == 0)
  14310. {
  14311. if(strcmp(OcppProtocol, "wss") == 0)
  14312. OcppPort = 443;
  14313. else
  14314. OcppPort = 80;
  14315. }
  14316. else
  14317. OcppPort = url.port;
  14318. result = TRUE;
  14319. }
  14320. }
  14321. else
  14322. {
  14323. strcpy(OcppHost,"");
  14324. }
  14325. return result;
  14326. }
  14327. int GetOcppPath()
  14328. {
  14329. int result = FALSE;
  14330. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  14331. {
  14332. if(OcppTempPath == NULL)
  14333. {
  14334. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  14335. }
  14336. else
  14337. {
  14338. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  14339. }
  14340. result = TRUE;
  14341. goto End;
  14342. }
  14343. else
  14344. {
  14345. strcpy(OcppPath,"");
  14346. }
  14347. End:
  14348. return result;
  14349. }
  14350. int GetOcppPort()
  14351. {
  14352. return OcppPort;
  14353. }
  14354. int GetOcppConnStatus(void)
  14355. {
  14356. return ShmOCPP16DataPH->OcppConnStatus;
  14357. }
  14358. void SetOcppConnStatus(uint8_t status)
  14359. {
  14360. ShmOCPP16DataPH->OcppConnStatus = status;
  14361. }
  14362. int GetHeartBeatWithNOResponse(void)
  14363. {
  14364. return HeartBeatWithNOResponse;
  14365. }
  14366. void SetHeartBeatWithNOResponse(void)
  14367. {
  14368. HeartBeatWithNOResponse = 0;
  14369. }
  14370. void GetStartTransactionIdTag(int gun_index)
  14371. {
  14372. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14373. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14374. }
  14375. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14376. {
  14377. char ch;
  14378. FILE *fptr1;
  14379. int temptransactionId;
  14380. char str[100]={0};
  14381. temptransactionId = 0;
  14382. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14383. {
  14384. DEBUG_INFO("IdTag is empty.\n");
  14385. return temptransactionId;
  14386. }
  14387. /*------ Read the file ----------------*/
  14388. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  14389. if (!fptr1)
  14390. {
  14391. DEBUG_INFO("QueueTransactionId file open error.\n");
  14392. //printf(" File not found or unable to open the input file!!\n");
  14393. return temptransactionId;
  14394. }
  14395. ch=fgetc(fptr1);
  14396. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  14397. rewind(fptr1);
  14398. if(ch!=EOF)
  14399. {
  14400. // printf("%c",ch);
  14401. while (fgets(str, 100, fptr1) != NULL)
  14402. {
  14403. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14404. if(str[0]=='\0')
  14405. {
  14406. break;
  14407. }
  14408. char *revbuf[8] = {0}; // Variable store string split
  14409. int num = 0;// Quantity after string split
  14410. DEBUG_INFO("Transaction queue data= %s\n", str);
  14411. splitstring(str,",",revbuf,&num); // String split
  14412. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14413. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14414. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14415. DEBUG_INFO("------------------------------\n");
  14416. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14417. {
  14418. if(isStopTransaction)
  14419. {
  14420. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14421. {
  14422. temptransactionId = atoi(revbuf[2]);
  14423. //break;
  14424. }
  14425. }
  14426. else
  14427. {
  14428. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14429. {
  14430. temptransactionId = atoi(revbuf[2]);
  14431. //break;
  14432. }
  14433. }
  14434. }
  14435. }
  14436. }
  14437. else
  14438. DEBUG_INFO("EOF\n");
  14439. fclose(fptr1);
  14440. /*------- End of reading ---------------*/
  14441. return temptransactionId;
  14442. }
  14443. void SetTransactionIdZero(int transactionId)
  14444. {
  14445. char ch;
  14446. FILE *fptr1, *fptr2;
  14447. int temptransactionId = 0;
  14448. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  14449. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  14450. if (!fptr1)
  14451. {
  14452. //printf(" File not found or unable to open the input file!!\n");
  14453. return ;
  14454. }
  14455. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14456. if (!fptr2)
  14457. {
  14458. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14459. fclose(fptr1);
  14460. return ;
  14461. }
  14462. ch=fgetc(fptr1);
  14463. rewind(fptr1);
  14464. if(ch!=EOF)
  14465. {
  14466. // copy all contents to the temporary file except the specific line
  14467. while (fgets(str, 100, fptr1) != NULL)
  14468. {
  14469. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14470. if(str[0]=='\0')
  14471. {
  14472. break;
  14473. }
  14474. char *revbuf[8] = {0};
  14475. int num = 0;
  14476. strcpy(strtemp, str);
  14477. splitstring(str,",",revbuf,&num);
  14478. if(revbuf[2][0] != '\0')
  14479. {
  14480. temptransactionId = atoi(revbuf[2]);
  14481. if(transactionId != temptransactionId)
  14482. {
  14483. fprintf(fptr2, "%s\n", strtemp);
  14484. }
  14485. }
  14486. }
  14487. }
  14488. fclose(fptr1);
  14489. fclose(fptr2);
  14490. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  14491. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  14492. /*------ Read the file ----------------*/
  14493. }
  14494. int InternetDisconnect(void)
  14495. {
  14496. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14497. }
  14498. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14499. void storeTempStopTransaction(int gun_index)
  14500. {
  14501. char guid[37]={0};
  14502. int tempIndex = 0;
  14503. char TempStopTransaction[256];
  14504. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  14505. DEBUG_INFO("storeTempStopTransaction...\n");
  14506. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14507. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  14508. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14509. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14510. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14511. {
  14512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14513. {
  14514. tempIndex = ((gun_index==2) ? 1: 0);
  14515. }
  14516. else
  14517. {
  14518. tempIndex = gun_index;
  14519. }
  14520. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14521. {
  14522. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14523. {
  14524. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14525. }
  14526. }// END OF CHAdeMO_QUANTITY
  14527. }
  14528. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14529. {
  14530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14531. {
  14532. tempIndex = ((gun_index==2) ? 1: 0);
  14533. }
  14534. else
  14535. {
  14536. tempIndex = gun_index;
  14537. }
  14538. for (int index = 0; index < CCS_QUANTITY; index++)
  14539. {
  14540. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14541. {
  14542. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14543. }
  14544. }// END OF CCS_QUANTITY
  14545. }
  14546. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14547. {
  14548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14549. {
  14550. tempIndex = ((gun_index==2) ? 1: 0);
  14551. }
  14552. else
  14553. {
  14554. tempIndex = gun_index;
  14555. }
  14556. for (int index = 0; index < GB_QUANTITY; index++)
  14557. {
  14558. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14559. {
  14560. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14561. }
  14562. }// END OF GB_QUANTITY
  14563. }
  14564. else if(gunType[gun_index] == GUN_TYPE_DO)
  14565. {
  14566. tempIndex = gun_index;
  14567. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14568. {
  14569. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14570. {
  14571. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14572. }
  14573. }
  14574. }
  14575. else
  14576. {
  14577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14578. {
  14579. tempIndex = 2;
  14580. }
  14581. else
  14582. {
  14583. tempIndex = gun_index;
  14584. }
  14585. for (int index = 0; index < AC_QUANTITY; index++)
  14586. {
  14587. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14588. {
  14589. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14590. }
  14591. }// END OF AC_QUANTITY
  14592. }
  14593. //Stop Transaction Time
  14594. struct timeval tmnow;
  14595. struct tm *tm;
  14596. char buf[28];//, usec_buf[6];
  14597. gettimeofday(&tmnow, NULL);
  14598. time_t t;
  14599. t = time(NULL);
  14600. /*UTC time and date*/
  14601. tm = gmtime(&t);
  14602. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  14604. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  14605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14606. random_uuid(guid);
  14607. /***********************************transactionData******************************************************/
  14608. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14609. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14610. //=================================
  14611. //1. Transaction_Begin
  14612. //=================================
  14613. //============================== Energy.Active.Import.Interval ===========================================
  14614. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14615. {
  14616. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14617. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14618. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14619. 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*/]);
  14620. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14621. 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))
  14622. {
  14623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14624. }
  14625. else
  14626. {
  14627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14628. }
  14629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14631. }
  14632. //=================================
  14633. //2. Transaction_End
  14634. //=================================
  14635. //2.1====================================== Current.Import L1 ==============================================
  14636. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14637. {
  14638. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14639. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14640. {
  14641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14642. {
  14643. tempIndex = ((gun_index==2) ? 1: 0);
  14644. }
  14645. else
  14646. {
  14647. tempIndex = gun_index;
  14648. }
  14649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14650. {
  14651. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14652. {
  14653. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14654. }
  14655. }// End of for CHAdeMO_QUANTITY
  14656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14657. }
  14658. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14659. {
  14660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14661. {
  14662. tempIndex = ((gun_index==2) ? 1: 0);
  14663. }
  14664. else
  14665. {
  14666. tempIndex = gun_index;
  14667. }
  14668. for (int index = 0; index < CCS_QUANTITY; index++)
  14669. {
  14670. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14671. {
  14672. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14673. }
  14674. }// End of for CCS_QUANTITY
  14675. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14676. }
  14677. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14678. {
  14679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14680. {
  14681. tempIndex = ((gun_index==2) ? 1: 0);
  14682. }
  14683. else
  14684. {
  14685. tempIndex = gun_index;
  14686. }
  14687. for (int index = 0; index < GB_QUANTITY; index++)
  14688. {
  14689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14690. {
  14691. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14692. }
  14693. }// End of for GB_QUANTITY
  14694. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14695. }
  14696. else if(gunType[gun_index] == GUN_TYPE_DO)
  14697. {
  14698. tempIndex = gun_index;
  14699. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14700. {
  14701. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14702. {
  14703. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14704. }
  14705. }
  14706. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14707. }
  14708. else
  14709. {
  14710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14711. {
  14712. tempIndex = 2;
  14713. }
  14714. else
  14715. {
  14716. tempIndex = gun_index;
  14717. }
  14718. for (int index = 0; index < AC_QUANTITY; index++)
  14719. {
  14720. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14721. {
  14722. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14723. }
  14724. }// End of for AC_QUANTITY
  14725. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14726. }
  14727. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14730. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14731. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14732. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14733. }
  14734. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14735. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14736. {
  14737. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14738. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14739. {
  14740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14741. {
  14742. tempIndex = ((gun_index==2) ? 1: 0);
  14743. }
  14744. else
  14745. {
  14746. tempIndex = gun_index;
  14747. }
  14748. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14749. {
  14750. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14751. {
  14752. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14753. }
  14754. }// END OF CHAdeMO_QUANTITY
  14755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14756. }
  14757. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14758. {
  14759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14760. {
  14761. tempIndex = ((gun_index==2) ? 1: 0);
  14762. }
  14763. else
  14764. {
  14765. tempIndex = gun_index;
  14766. }
  14767. for (int index = 0; index < CCS_QUANTITY; index++)
  14768. {
  14769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14770. {
  14771. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14772. }
  14773. }// END OF CCS_QUANTITY
  14774. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14775. }
  14776. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14777. {
  14778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14779. {
  14780. tempIndex = ((gun_index==2) ? 1: 0);
  14781. }
  14782. else
  14783. {
  14784. tempIndex = gun_index;
  14785. }
  14786. for (int index = 0; index < GB_QUANTITY; index++)
  14787. {
  14788. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14789. {
  14790. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14791. }
  14792. }// END OF GB_QUANTITY
  14793. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14794. }
  14795. else if(gunType[gun_index] == GUN_TYPE_DO)
  14796. {
  14797. tempIndex = gun_index;
  14798. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14799. {
  14800. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14801. {
  14802. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14803. }
  14804. }
  14805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14806. }
  14807. else
  14808. {
  14809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14810. {
  14811. tempIndex = 2;
  14812. }
  14813. else
  14814. {
  14815. tempIndex = gun_index;
  14816. }
  14817. for (int index = 0; index < AC_QUANTITY; index++)
  14818. {
  14819. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14820. {
  14821. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14822. }
  14823. }// END OF AC_QUANTITY
  14824. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14825. }
  14826. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14828. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14829. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14830. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14831. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14832. }
  14833. //2.3====================================== Power.Active.Import =========================================
  14834. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14835. {
  14836. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14837. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14838. {
  14839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14840. {
  14841. tempIndex = ((gun_index==2) ? 1: 0);
  14842. }
  14843. else
  14844. {
  14845. tempIndex = gun_index;
  14846. }
  14847. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14848. {
  14849. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14850. {
  14851. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14852. }
  14853. } // End for CHAdeMO_QUANTITY
  14854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14855. }
  14856. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14857. {
  14858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14859. {
  14860. tempIndex = ((gun_index==2) ? 1: 0);
  14861. }
  14862. else
  14863. {
  14864. tempIndex = gun_index;
  14865. }
  14866. for (int index = 0; index < CCS_QUANTITY; index++)
  14867. {
  14868. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14869. {
  14870. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14871. }
  14872. } // END for CCS_QUANTITY
  14873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14874. }
  14875. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14876. {
  14877. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14878. {
  14879. tempIndex = ((gun_index==2) ? 1: 0);
  14880. }
  14881. else
  14882. {
  14883. tempIndex = gun_index;
  14884. }
  14885. for (int index = 0; index < GB_QUANTITY; index++)
  14886. {
  14887. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14888. {
  14889. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14890. }
  14891. }// END for GB_QUANTITY
  14892. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14893. }
  14894. else if(gunType[gun_index] == GUN_TYPE_DO)
  14895. {
  14896. tempIndex = gun_index;
  14897. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14898. {
  14899. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14900. {
  14901. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14902. }
  14903. }
  14904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14905. }
  14906. else
  14907. {
  14908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14909. {
  14910. tempIndex = 2;
  14911. }
  14912. else
  14913. {
  14914. tempIndex = gun_index;
  14915. }
  14916. for (int index = 0; index < AC_QUANTITY; index++)
  14917. {
  14918. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14919. {
  14920. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14921. }
  14922. } // END for AC_QUANTITY
  14923. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14924. }
  14925. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14927. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14928. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14929. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14930. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14931. }
  14932. //2.4====================================== Voltage L1 ====================================================
  14933. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14934. {
  14935. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14936. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14937. {
  14938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14939. {
  14940. tempIndex = ((gun_index==2) ? 1: 0);
  14941. }
  14942. else
  14943. {
  14944. tempIndex = gun_index;
  14945. }
  14946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14947. {
  14948. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14949. {
  14950. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14951. }
  14952. } // END OF FOR CHAdeMO_QUANTITY
  14953. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14954. }
  14955. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14956. {
  14957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14958. {
  14959. tempIndex = ((gun_index==2) ? 1: 0);
  14960. }
  14961. else
  14962. {
  14963. tempIndex = gun_index;
  14964. }
  14965. for (int index = 0; index < CCS_QUANTITY; index++)
  14966. {
  14967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14968. {
  14969. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14970. }
  14971. } // END OF FOR CCS_QUANTITY
  14972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14973. }
  14974. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14975. {
  14976. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14977. {
  14978. tempIndex = ((gun_index==2) ? 1: 0);
  14979. }
  14980. else
  14981. {
  14982. tempIndex = gun_index;
  14983. }
  14984. for (int index = 0; index < GB_QUANTITY; index++)
  14985. {
  14986. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14987. {
  14988. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14989. }
  14990. } // END OF FOR GB_QUANTITY
  14991. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14992. }
  14993. else if(gunType[gun_index] == GUN_TYPE_DO)
  14994. {
  14995. tempIndex = gun_index;
  14996. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14997. {
  14998. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14999. {
  15000. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15001. }
  15002. }
  15003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15004. }
  15005. else
  15006. {
  15007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15008. {
  15009. tempIndex = 2;
  15010. }
  15011. else
  15012. {
  15013. tempIndex = gun_index;
  15014. }
  15015. for (int index = 0; index < AC_QUANTITY; index++)
  15016. {
  15017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15018. {
  15019. 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
  15020. }
  15021. } // END OF FOR AC_QUANTITY
  15022. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15023. }
  15024. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15027. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15030. }
  15031. //2.5============================================== End SoC =========================================================
  15032. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15033. {
  15034. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15035. 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))
  15036. {
  15037. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15038. {
  15039. tempIndex = ((gun_index==2) ? 1: 0);
  15040. }
  15041. else
  15042. {
  15043. tempIndex = gun_index;
  15044. }
  15045. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15046. {
  15047. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15048. {
  15049. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15050. {
  15051. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15052. }
  15053. }
  15054. }
  15055. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15056. {
  15057. for (int index = 0; index < CCS_QUANTITY; index++)
  15058. {
  15059. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15060. {
  15061. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15062. }
  15063. }
  15064. }
  15065. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15066. {
  15067. for (int index = 0; index < GB_QUANTITY; index++)
  15068. {
  15069. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15070. {
  15071. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15072. }
  15073. }
  15074. }
  15075. else if(gunType[gun_index] == GUN_TYPE_DO)
  15076. {
  15077. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15078. {
  15079. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15080. {
  15081. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15082. }
  15083. }
  15084. }
  15085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15087. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15089. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15090. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15091. } // END FOR DC CASE
  15092. }
  15093. //2.6====================================== Current.Import L2 ==============================================
  15094. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15095. {
  15096. // AC 3 phase L2 current
  15097. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15098. {
  15099. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15100. {
  15101. tempIndex = 2;
  15102. }
  15103. else
  15104. {
  15105. tempIndex = gun_index;
  15106. }
  15107. for (int index = 0; index < AC_QUANTITY; index++)
  15108. {
  15109. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15110. {
  15111. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15112. }
  15113. }// End of for AC_QUANTITY
  15114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15115. }
  15116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15121. }
  15122. //2.7====================================== Current.Import L3 ==============================================
  15123. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15124. {
  15125. // AC 3 phase L3 current
  15126. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15127. {
  15128. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15129. {
  15130. tempIndex = 2;
  15131. }
  15132. else
  15133. {
  15134. tempIndex = gun_index;
  15135. }
  15136. for (int index = 0; index < AC_QUANTITY; index++)
  15137. {
  15138. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15139. {
  15140. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15141. }
  15142. }// End of for AC_QUANTITY
  15143. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15144. }
  15145. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15148. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15149. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15150. }
  15151. //2.9====================================== Voltage L2 ====================================================
  15152. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15153. {
  15154. // AC 3 phase L2 volatge
  15155. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15156. {
  15157. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15158. {
  15159. tempIndex = 2;
  15160. }
  15161. else
  15162. {
  15163. tempIndex = gun_index;
  15164. }
  15165. for (int index = 0; index < AC_QUANTITY; index++)
  15166. {
  15167. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15168. {
  15169. 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
  15170. }
  15171. } // END OF FOR AC_QUANTITY
  15172. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15173. }
  15174. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15175. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15177. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15179. }
  15180. //2.10====================================== Voltage L3 ====================================================
  15181. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15182. {
  15183. // AC 3 phase L3 volatge
  15184. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15185. {
  15186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15187. {
  15188. tempIndex = 2;
  15189. }
  15190. else
  15191. {
  15192. tempIndex = gun_index;
  15193. }
  15194. for (int index = 0; index < AC_QUANTITY; index++)
  15195. {
  15196. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15197. {
  15198. 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
  15199. }
  15200. } // END OF FOR AC_QUANTITY
  15201. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15202. }
  15203. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15204. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15205. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15206. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15207. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15208. }
  15209. //====================== Start SoC ================================
  15210. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15211. {
  15212. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15213. 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))
  15214. {
  15215. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15216. {
  15217. tempIndex = ((gun_index==2) ? 1: 0);
  15218. }
  15219. else
  15220. {
  15221. tempIndex = gun_index;
  15222. }
  15223. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15224. {
  15225. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15226. {
  15227. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15228. {
  15229. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15230. }
  15231. }
  15232. }
  15233. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15234. {
  15235. for (int index = 0; index < CCS_QUANTITY; index++)
  15236. {
  15237. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15238. {
  15239. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15240. }
  15241. }
  15242. }
  15243. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15244. {
  15245. for (int index = 0; index < GB_QUANTITY; index++)
  15246. {
  15247. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15248. {
  15249. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15250. }
  15251. }
  15252. }
  15253. else if(gunType[gun_index] == GUN_TYPE_DO)
  15254. {
  15255. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15256. {
  15257. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15258. {
  15259. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15260. }
  15261. }
  15262. }
  15263. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15264. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15265. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15269. } // END FOR DC CASE
  15270. }
  15271. //======================================== Message create ==============================================
  15272. json_object *StopTransaction = json_object_new_object();
  15273. json_object *transactionDatas = json_object_new_array();
  15274. json_object *sampledValues = json_object_new_array();
  15275. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  15276. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  15277. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  15278. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  15279. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  15280. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15281. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  15282. {
  15283. json_object *transactionData = json_object_new_object();
  15284. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15285. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15286. {
  15287. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15288. {
  15289. json_object *sampledValue = json_object_new_object();
  15290. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15291. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15292. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15293. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15294. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15295. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15296. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15297. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15298. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15299. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15300. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15301. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15302. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15303. json_object_array_add(sampledValues, sampledValue);
  15304. }
  15305. }
  15306. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15307. json_object_array_add(transactionDatas, transactionData);
  15308. }
  15309. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15310. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15311. ,MESSAGE_TYPE_CALL
  15312. ,guid
  15313. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15314. json_object_put(StopTransaction);
  15315. // Check File "TempStopTransaction" Exist
  15316. if((access(TempStopTransaction,F_OK))!=-1)
  15317. {
  15318. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15319. fclose(fopen(TempStopTransaction, "w"));
  15320. }
  15321. else
  15322. {
  15323. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15324. FILE *log = fopen(TempStopTransaction, "w+");
  15325. if(log == NULL)
  15326. {
  15327. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15328. return ;
  15329. }
  15330. else
  15331. {
  15332. fclose(log);
  15333. }
  15334. }
  15335. //Add TempStopTransaction | Update TempStopTransaction
  15336. // open file for writing
  15337. FILE *outfile;
  15338. outfile = fopen (TempStopTransaction, "a");
  15339. //DEBUG_INFO("data = %s\n", queuedata);
  15340. fputs(queuedata, outfile);
  15341. fputs("\n", outfile);
  15342. fclose (outfile);
  15343. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15344. }
  15345. void checkTempStopTransaction(int gun_index)
  15346. {
  15347. FILE *fptr1;
  15348. char ch;
  15349. char str[QUEUE_MESSAGE_LENGTH]={0};
  15350. char guid[37]={0};
  15351. char tempdata[65]={0};
  15352. char connectorStr[2]={0};
  15353. char TempStopTransaction[256];
  15354. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15355. fptr1 = fopen(TempStopTransaction, "r");
  15356. //TempStopTransaction格式: 槍號,StopTransaction封包
  15357. if (!fptr1)
  15358. {
  15359. //printf(" File not found or unable to open the input file!!\n");
  15360. return ;
  15361. }
  15362. ch=fgetc(fptr1);
  15363. //printf(" Now the content of the file %s is : \n",fname);
  15364. rewind(fptr1);
  15365. if(ch!=EOF)
  15366. {
  15367. // copy all contents to the temporary file except the specific line
  15368. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15369. {
  15370. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15371. if(str[0]=='\0')
  15372. {
  15373. break;
  15374. }
  15375. //TempStopTransaction格式: 槍號,StopTransaction封包
  15376. strncpy(connectorStr, str, 1);
  15377. if(atoi(connectorStr) != (gun_index+1))
  15378. {
  15379. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15380. fclose(fptr1);
  15381. return ;
  15382. }
  15383. //random_uuid(guid);
  15384. strncpy(guid, str+6, 36); //copy guid
  15385. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15386. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15387. {
  15388. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15389. }
  15390. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15391. OCPP_insert_transaction_msg(NO, str);
  15392. memset(str,0,ARRAY_SIZE(str));
  15393. }
  15394. }
  15395. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15396. fclose(fptr1);
  15397. remove(TempStopTransaction); // remove the original file
  15398. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15399. }
  15400. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15401. {
  15402. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15403. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15404. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15405. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15406. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15407. }
  15408. int GetWebSocketPingInterval(void)
  15409. {
  15410. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15411. }
  15412. int GetServerSign(void)
  15413. {
  15414. return server_sign;
  15415. }
  15416. uint8_t GetOcppSecurityProfile()
  15417. {
  15418. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15419. }
  15420. void GetOcppChargerBoxId(uint8_t *data)
  15421. {
  15422. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  15423. }
  15424. void GetOcppSecurityPassword(uint8_t *data)
  15425. {
  15426. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15427. }
  15428. void SetOcppVersion(uint8_t *version)
  15429. {
  15430. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15431. DEBUG_INFO("ocpp version: %s\n", version);
  15432. if(strstr((char*)version, "ocpp1.6") != NULL)
  15433. {
  15434. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15435. }
  15436. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15437. {
  15438. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15439. system("pkill OcppBackend");
  15440. }
  15441. }
  15442. void SetServerSign(int value)
  15443. {
  15444. server_sign = value;
  15445. }
  15446. int GetBootNotificationInterval(void)
  15447. {
  15448. return BootNotificationInterval;
  15449. }
  15450. int GetInternetConn(void)
  15451. {
  15452. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15453. }
  15454. int GetBackendConnectionTimeout(void)
  15455. {
  15456. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15457. }
  15458. int isConnectorInitMode(int gun_index)
  15459. {
  15460. int tempIndex = 0;
  15461. int result = TRUE;
  15462. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15463. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15464. {
  15465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15466. {
  15467. tempIndex = ((gun_index==2) ? 1: 0);
  15468. }
  15469. else
  15470. {
  15471. tempIndex = gun_index;
  15472. }
  15473. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15474. {
  15475. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15476. {
  15477. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15478. } //end of the same index
  15479. }//end of for CHAdeMO_QUANTITY
  15480. }
  15481. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15482. {
  15483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15484. {
  15485. tempIndex = ((gun_index==2) ? 1: 0);
  15486. }
  15487. else
  15488. {
  15489. tempIndex = gun_index;
  15490. }
  15491. for (int index = 0; index < CCS_QUANTITY; index++)
  15492. {
  15493. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15494. {
  15495. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15496. } //end of the same index
  15497. } // end of for CCS_QUANTITY
  15498. }
  15499. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15500. {
  15501. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15502. {
  15503. tempIndex = ((gun_index==2) ? 1: 0);
  15504. }
  15505. else
  15506. {
  15507. tempIndex = gun_index;
  15508. }
  15509. for (int index = 0; index < GB_QUANTITY; index++)
  15510. {
  15511. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15512. {
  15513. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15514. } //end of the same index
  15515. } // end of for GB_QUANTITY
  15516. }
  15517. else if(gunType[gun_index] == GUN_TYPE_DO)
  15518. {
  15519. tempIndex = gun_index;
  15520. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15521. {
  15522. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15523. {
  15524. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15525. } //end of the same index
  15526. }
  15527. }
  15528. else
  15529. {
  15530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15531. {
  15532. tempIndex = 2;
  15533. }
  15534. else
  15535. {
  15536. tempIndex = gun_index;
  15537. }
  15538. for (int index = 0; index < AC_QUANTITY; index++)
  15539. {
  15540. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15541. {
  15542. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15543. }//end of the same index
  15544. }//end of for AC_QUANTITY
  15545. }
  15546. return result;
  15547. }
  15548. void refreshProcDogTimer()
  15549. {
  15550. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  15551. }
  15552. void InitialSystemValue(void)
  15553. {
  15554. int connectorIndex = 0;
  15555. //int valueASCII = 0;
  15556. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15557. gunTotalNumber=0;
  15558. SystemInitial = 0;
  15559. locallistVersion=0;
  15560. BootNotificationInterval = 0;
  15561. authorizeRetryTimes = 0;
  15562. GunStatusInterval = 10;
  15563. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15564. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15565. //Hear Beat
  15566. HeartBeatWithNOResponse = 0;
  15567. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15568. FirstHeartBeat = 0;
  15569. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15570. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15571. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15572. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15573. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15574. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15575. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15576. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15577. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15578. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15579. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15580. memset(gunType, 0, ARRAY_SIZE(gunType));
  15581. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15582. {
  15583. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  15584. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  15585. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  15586. {
  15587. // DO series
  15588. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15589. {
  15590. SystemInitial = SystemInitial + 1;
  15591. gunTotalNumber = gunTotalNumber + 1;
  15592. gunType[connectorIndex] = GUN_TYPE_DO;
  15593. connectorIndex = connectorIndex + 1;
  15594. }
  15595. }
  15596. else
  15597. {
  15598. // DM, DW, DS series
  15599. //check connector / socket type (index: 8, 9, 10)
  15600. for(int index=7; index <10 ; index++)
  15601. {
  15602. if(index != 8)
  15603. {
  15604. // DC Connector
  15605. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15606. {
  15607. SystemInitial = SystemInitial + 1;
  15608. gunTotalNumber = gunTotalNumber + 1;
  15609. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15610. connectorIndex = connectorIndex + 1;
  15611. }
  15612. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15613. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15614. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15615. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15616. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15617. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15618. {
  15619. SystemInitial = SystemInitial + 1;
  15620. gunTotalNumber = gunTotalNumber + 1;
  15621. gunType[connectorIndex] = GUN_TYPE_CCS;
  15622. connectorIndex = connectorIndex + 1;
  15623. }
  15624. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15625. {
  15626. SystemInitial = SystemInitial + 1;
  15627. gunTotalNumber = gunTotalNumber + 1;
  15628. gunType[connectorIndex] = GUN_TYPE_GBT;
  15629. connectorIndex = connectorIndex + 1;
  15630. }
  15631. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15632. {
  15633. SystemInitial = SystemInitial + 1;
  15634. gunTotalNumber = gunTotalNumber + 1;
  15635. gunType[connectorIndex] = GUN_TYPE_DO;
  15636. connectorIndex = connectorIndex + 1;
  15637. }
  15638. }
  15639. else
  15640. {
  15641. // AC Connector
  15642. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15643. {
  15644. SystemInitial = SystemInitial + 1;
  15645. gunTotalNumber = gunTotalNumber + 1;
  15646. gunType[connectorIndex] = GUN_TYPE_AC;
  15647. connectorIndex = connectorIndex + 1;
  15648. }
  15649. }
  15650. }
  15651. }
  15652. //DEBUG_INFO("DC ...\n");
  15653. }
  15654. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15655. {
  15656. //check connector / socket type (index: 8, 9, 10)
  15657. for(int index=7; index <10 ; index++)
  15658. {
  15659. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15660. {
  15661. SystemInitial = SystemInitial + 1;
  15662. gunTotalNumber = gunTotalNumber + 1;
  15663. gunType[connectorIndex] = GUN_TYPE_AC;
  15664. connectorIndex = connectorIndex + 1;
  15665. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15666. }
  15667. }
  15668. }
  15669. //Status && ConnectorPlugIn Setting
  15670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15671. {
  15672. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15673. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15674. }
  15675. for (int index = 0; index < CCS_QUANTITY; index++)
  15676. {
  15677. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15678. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15679. }
  15680. for (int index = 0; index < GB_QUANTITY; index++)
  15681. {
  15682. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15683. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15684. }
  15685. for (int index = 0; index < AC_QUANTITY; index++)
  15686. {
  15687. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15688. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15689. }
  15690. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15691. {
  15692. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15693. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15694. }
  15695. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15696. {
  15697. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15698. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15699. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15700. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15701. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15702. }
  15703. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15704. clientTime.Heartbeat=time((time_t*)NULL);
  15705. sleep(1);
  15706. }
  15707. void LWS_Send(char *str)
  15708. {
  15709. //=====================================================
  15710. // Check InternetConn 0: disconnected, 1: connected
  15711. //====================================================
  15712. if(GetOcppConnStatus() == 0)
  15713. {
  15714. DEBUG_INFO("offline now !!!\n");
  15715. return;
  15716. }
  15717. // Only disable isWebsocketSendable operation initiated by charger
  15718. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15719. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15720. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15721. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15722. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15723. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15724. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15725. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15726. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15727. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15728. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15729. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15730. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15731. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15732. {
  15733. isWebsocketSendable = 0;
  15734. }
  15735. pthread_mutex_lock(&lock_send);
  15736. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15737. sprintf((char *)SendBuffer, "%s", str);
  15738. SendBufLen = strlen(str);
  15739. pthread_mutex_unlock(&lock_send);
  15740. lws_callback_on_writable(wsi_client);
  15741. //lws_service(context, 0);
  15742. //sleep(1);
  15743. }
  15744. void LWS_SendNow(char *str)
  15745. {
  15746. //=====================================================
  15747. // Check InternetConn 0: disconnected, 1: connected
  15748. //====================================================
  15749. if(GetOcppConnStatus() == 0)
  15750. {
  15751. DEBUG_INFO("offline now !!!\n");
  15752. return;
  15753. }
  15754. // Only disable isWebsocketSendable operation initiated by charger
  15755. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15756. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15757. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15758. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15759. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15760. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15761. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15762. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15763. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15764. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15765. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15766. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15767. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15768. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15769. {
  15770. isWebsocketSendable = 0;
  15771. }
  15772. pthread_mutex_lock(&lock_send);
  15773. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15774. sprintf((char *)SendBuffer, "%s", str);
  15775. SendBufLen = strlen(str);
  15776. pthread_mutex_unlock(&lock_send);
  15777. lws_callback_on_writable(wsi_client);
  15778. lws_service(context, 0);
  15779. //sleep(1);
  15780. }