MessageHandler.c 1008 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  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. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = FALSE;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t Connector0PreviousSystemStatus;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. struct timespec TcciQueryOccupancyDeduct;
  118. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  119. }clientTime;
  120. typedef union
  121. {
  122. //Operations Initiated by Central System
  123. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  124. struct
  125. {
  126. //CsMsgValue[0]
  127. unsigned char StatusNotificationReq:1; //bit 0,
  128. unsigned char StatusNotificationConf:1; //bit 1,
  129. unsigned char TriggerMeterValue:1; //bit 2,
  130. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  131. unsigned char isOnCharging:1; //bit 4,
  132. unsigned char :3; //bit5~7
  133. }bits[CONNECTOR_QUANTITY];
  134. }CpinitiateMsg;
  135. CpinitiateMsg cpinitateMsg;
  136. //GetConfiguration Array
  137. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  139. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  140. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  141. static char *ChargePointErrorCodeStr[] = {
  142. MACROSTR(ConnectorLockFailure),
  143. MACROSTR(EVCommunicationError),
  144. MACROSTR(GroundFailure),
  145. MACROSTR(HighTemperature),
  146. MACROSTR(InternalError),
  147. MACROSTR(LocalListConflict),
  148. MACROSTR(NoError),
  149. MACROSTR(OtherError),
  150. MACROSTR(OverCurrentFailure),
  151. MACROSTR(OverVoltage),
  152. MACROSTR(PowerMeterFailure),
  153. MACROSTR(PowerSwitchFailure),
  154. MACROSTR(ReaderFailure),
  155. MACROSTR(ResetFailure),
  156. MACROSTR(UnderVoltage),
  157. MACROSTR(WeakSignal)
  158. };
  159. static char * ChargePointStatusStr[] = {
  160. MACROSTR(Available),
  161. MACROSTR(Preparing),
  162. MACROSTR(Charging),
  163. MACROSTR(SuspendedEVSE),
  164. MACROSTR(SuspendedEV),
  165. MACROSTR(Finishing),
  166. MACROSTR(Reserved),
  167. MACROSTR(Unavailable),
  168. MACROSTR(Faulted)
  169. };
  170. static char *RegistrationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Pending),
  173. MACROSTR(Rejected)
  174. };
  175. static char *AvailabilityTypeStr[] = {
  176. MACROSTR(Inoperative),
  177. MACROSTR(Operative)
  178. };
  179. static char *AvailabilityStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(Scheduled)
  183. };
  184. static char *ConfigurationStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(RebootRequired),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearCacheStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Rejected)
  193. };
  194. static char *ChargingProfilePurposeTypeStr[] = {
  195. MACROSTR(ChargePointMaxProfile),
  196. MACROSTR(TxDefaultProfile),
  197. MACROSTR(TxProfile)
  198. };
  199. static char *ChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Rejected),
  202. MACROSTR(NotSupported)
  203. };
  204. static char *ClearChargingProfileStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Unknown)
  207. };
  208. static char *GetCompositeScheduleStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *UpdateTypeStr[] = {
  213. MACROSTR(Differential),
  214. MACROSTR(Full)
  215. };
  216. static char *UpdateStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Failed),
  219. MACROSTR(NotSupported),
  220. MACROSTR(VersionMismatch)
  221. };
  222. static char *RemoteStartStopStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char *ReservationStatusStr[] = {
  227. MACROSTR(Accepted),
  228. MACROSTR(Faulted),
  229. MACROSTR(Occupied),
  230. MACROSTR(Rejected),
  231. MACROSTR(Unavailable)
  232. };
  233. static char *ResetTypeStr[] = {
  234. MACROSTR(Hard),
  235. MACROSTR(Soft)
  236. };
  237. static char *ResetStatusStr[] = {
  238. MACROSTR(Accepted),
  239. MACROSTR(Rejected)
  240. };
  241. static char * DiagnosticsStatusStr[] = {
  242. MACROSTR(Idle),
  243. MACROSTR(Uploaded),
  244. MACROSTR(UploadFailed),
  245. MACROSTR(Uploading)
  246. };
  247. static char * FirmwareStatusStr[] = {
  248. MACROSTR(Downloaded),
  249. MACROSTR(DownloadFailed),
  250. MACROSTR(Downloading),
  251. MACROSTR(Idle),
  252. MACROSTR(InstallationFailed),
  253. MACROSTR(Installing),
  254. MACROSTR(Installed)
  255. };
  256. static char * MessageTriggerStr[] = {
  257. MACROSTR(BootNotification),
  258. MACROSTR(DiagnosticsStatusNotification),
  259. MACROSTR(FirmwareStatusNotification),
  260. MACROSTR(Heartbeat),
  261. MACROSTR(MeterValues),
  262. MACROSTR(StatusNotification)
  263. };
  264. static char * TriggerMessageStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Rejected),
  267. MACROSTR(NotImplemented)
  268. };
  269. static char * UnlockStatusStr[] = {
  270. MACROSTR(Unlocked),
  271. MACROSTR(UnlockFailed),
  272. MACROSTR(NotSupported)
  273. };
  274. #if 0
  275. static char * StopTransactionReasonStr[] = {
  276. MACROSTR(EmergencyStop),
  277. MACROSTR(EVDisconnected),
  278. MACROSTR(HardReset),
  279. MACROSTR(Local),
  280. MACROSTR(Other),
  281. MACROSTR(PowerLoss),
  282. MACROSTR(Reboot),
  283. MACROSTR(Remote),
  284. MACROSTR(SoftReset),
  285. MACROSTR(UnlockCommand),
  286. MACROSTR(DeAuthorized)
  287. };
  288. #endif
  289. static char * CancelReservationStatusStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected)
  292. };
  293. static char * ReadingContextStr[] = {
  294. MACROSTR(Interruption.Begin),
  295. MACROSTR(Interruption.End),
  296. MACROSTR(Other),
  297. MACROSTR(Sample.Clock),
  298. MACROSTR(Sample.Periodic),
  299. MACROSTR(Transaction.Begin),
  300. MACROSTR(Transaction.End),
  301. MACROSTR(Trigger)
  302. };
  303. static char * ValueFormatStr[] = {
  304. MACROSTR(Raw),
  305. MACROSTR(SignedData)
  306. };
  307. static char * MeasurandStr[] = {
  308. MACROSTR(Current.Export),
  309. MACROSTR(Current.Import),
  310. MACROSTR(Current.Offered),
  311. MACROSTR(Energy.Active.Export.Register),
  312. MACROSTR(Energy.Active.Import.Register),
  313. MACROSTR(Energy.Reactive.Export.Register),
  314. MACROSTR(Energy.Reactive.Import.Register),
  315. MACROSTR(Energy.Active.Export.Interval),
  316. MACROSTR(Energy.Active.Import.Interval),
  317. MACROSTR(Energy.Reactive.Export.Interval),
  318. MACROSTR(Energy.Reactive.Import.Interval),
  319. MACROSTR(Frequency),
  320. MACROSTR(Power.Active.Export),
  321. MACROSTR(Power.Active.Import),
  322. MACROSTR(Power.Factor),
  323. MACROSTR(Power.Offered),
  324. MACROSTR(Power.Reactive.ExportMACROSTR),
  325. MACROSTR(Power.Reactive.Import),
  326. MACROSTR(RPM),
  327. MACROSTR(SoC),
  328. MACROSTR(Temperature),
  329. MACROSTR(Voltage)
  330. };
  331. static char * LocationStr[] = {
  332. MACROSTR(Body),
  333. MACROSTR(Cable),
  334. MACROSTR(EV),
  335. MACROSTR(Inlet),
  336. MACROSTR(Outlet)
  337. };
  338. static char * PhaseStr[] = {
  339. MACROSTR(L1),
  340. MACROSTR(L2),
  341. MACROSTR(L3),
  342. MACROSTR(N),
  343. MACROSTR(L1-N),
  344. MACROSTR(L2-N),
  345. MACROSTR(L3-N),
  346. MACROSTR(L1-L2),
  347. MACROSTR(L2-L3),
  348. MACROSTR(L3-L1)
  349. };
  350. static char * UnitOfMeasureStr[] = {
  351. MACROSTR(Wh),
  352. MACROSTR(kWh),
  353. MACROSTR(varh),
  354. MACROSTR(kvarh),
  355. MACROSTR(W),
  356. MACROSTR(kW),
  357. MACROSTR(VA),
  358. MACROSTR(kVA),
  359. MACROSTR(var),
  360. MACROSTR(kvar),
  361. MACROSTR(A),
  362. MACROSTR(V),
  363. MACROSTR(Celsius),
  364. MACROSTR(Fahrenheit),
  365. MACROSTR(K),
  366. MACROSTR(Percent)
  367. };
  368. //=========================================
  369. // Meter buffer process
  370. //=========================================
  371. int meterValueBufferDataQuantity(uint8_t gun_index, ReadingContext dataType)
  372. {
  373. uint32_t result = 0;
  374. char sqlCmd[8192];
  375. char zErrMsg[200];
  376. int rows, cols;
  377. char **resultData;
  378. sprintf(sqlCmd, "select count(idx) as dataQuantity from meterValuesBuffer where gun_index='%d' and ReadingContext='%d' order by ReadingContext, idx", gun_index, (dataType==ReadingContext_Sample_Periodic?0:1));
  379. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  380. {
  381. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  382. }
  383. else
  384. {
  385. if(rows >= 1)
  386. {
  387. result = atoi(resultData[1]);
  388. }
  389. }
  390. return result;
  391. }
  392. int meterValueBufferClear(uint8_t gun_index)
  393. {
  394. int result = PASS;
  395. char sqlCmd[512];
  396. char *errMsg = 0;
  397. sprintf(sqlCmd, "delete from meterValuesBuffer where gun_index=%d", gun_index);
  398. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  399. {
  400. DEBUG_INFO("SQL error: %s\n",errMsg);
  401. result = FAIL;
  402. }
  403. return result;
  404. }
  405. int meterValueBufferInsert(uint8_t gun_index, ReadingContext dataType, uint32_t transactionId, char *meterValue)
  406. {
  407. int result = PASS;
  408. char sqlCmd[8192];
  409. char *errMsg = 0;
  410. sprintf(sqlCmd, "insert into meterValuesBuffer(occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values(CURRENT_TIMESTAMP, '%d', '%d','%d','%s')", gun_index
  411. , transactionId
  412. , (dataType==ReadingContext_Sample_Periodic?0:1)
  413. , meterValue);
  414. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  415. {
  416. result = FAIL;
  417. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  418. }
  419. return result;
  420. }
  421. int meterValueBufferReplace(int bufferIdx, uint8_t gun_index, ReadingContext dataType, uint32_t transactionId, char *meterValue)
  422. {
  423. int result = PASS;
  424. char sqlCmd[8192];
  425. char *errMsg = 0;
  426. sprintf(sqlCmd, "replace into meterValuesBuffer(idx, occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values('%d', CURRENT_TIMESTAMP, '%d', '%d','%d','%s')", bufferIdx
  427. , gun_index
  428. , transactionId
  429. , (dataType==ReadingContext_Sample_Periodic?0:1)
  430. , meterValue);
  431. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  432. {
  433. result = FAIL;
  434. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  435. }
  436. return result;
  437. }
  438. int meterValueBufferQuery(uint8_t gun_index, json_object *MeterValues)
  439. {
  440. int result = PASS;
  441. char sqlCmd[8192];
  442. char zErrMsg[200];
  443. int rows, cols;
  444. char **resultData;
  445. sprintf(sqlCmd, "select * from meterValuesBuffer where gun_index='%d' order by ReadingContext, idx", gun_index);
  446. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  447. {
  448. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  449. result = FAIL;
  450. }
  451. else
  452. {
  453. for(uint32_t idxRow=1;idxRow<=rows;idxRow++)
  454. {
  455. json_object *MeterValue = json_tokener_parse(resultData[(idxRow*cols)+5]);
  456. json_object_array_add(MeterValues, MeterValue);
  457. }
  458. }
  459. return result;
  460. }
  461. //=========================================
  462. // Certificate related routine
  463. //=========================================
  464. int certVerify(char *privateKey, char *cert)
  465. {
  466. int result = PASS;
  467. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  468. // Load certificate file
  469. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  470. {
  471. DEBUG_ERROR("Load certificate error!\n");
  472. result = FAIL;
  473. }
  474. // Load private key file
  475. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  476. {
  477. DEBUG_ERROR("Load private key error!\n");
  478. result = FAIL;
  479. }
  480. if(!SSL_CTX_check_private_key(ctx))
  481. {
  482. result = FAIL;
  483. }
  484. SSL_CTX_free(ctx);
  485. return result;
  486. }
  487. //=========================================
  488. // TTIA routine
  489. //=========================================
  490. int sendTTIAInfo(uint8_t gun_index)
  491. {
  492. static int sn = 0;
  493. int result = FAIL;
  494. struct hostent *server;
  495. int udp_socket_fd;
  496. struct sockaddr_in dest_addr = {0};
  497. uint8_t tx_buf[80] = {0};
  498. uint8_t logBuf[256]= {0};
  499. uint8_t tx_len, tempIndex, socStart, socEnd;
  500. uint16_t PresentChargedEnergy;
  501. struct tm tmStart, tmEnd;
  502. DEBUG_INFO("sendTTIAInfo...\n");
  503. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  504. {
  505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  506. {
  507. tempIndex = ((gun_index==2) ? 1: 0);
  508. }
  509. else
  510. {
  511. tempIndex = gun_index;
  512. }
  513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  514. {
  515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  516. {
  517. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  518. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  519. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  520. }
  521. }
  522. }
  523. else if(gunType[gun_index] == GUN_TYPE_CCS)
  524. {
  525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  526. {
  527. tempIndex = ((gun_index==2) ? 1: 0);
  528. }
  529. else
  530. {
  531. tempIndex = gun_index;
  532. }
  533. for (int index = 0; index < CCS_QUANTITY; index++)
  534. {
  535. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  536. {
  537. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  538. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  539. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  540. }
  541. }
  542. }
  543. else if(gunType[gun_index] == GUN_TYPE_GBT)
  544. {
  545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  546. {
  547. tempIndex = ((gun_index==2) ? 1: 0);
  548. }
  549. else
  550. {
  551. tempIndex = gun_index;
  552. }
  553. for (int index = 0; index < GB_QUANTITY; index++)
  554. {
  555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  556. {
  557. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  558. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  559. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  560. }
  561. }
  562. }
  563. else if(gunType[gun_index] == GUN_TYPE_DO)
  564. {
  565. tempIndex = gun_index;
  566. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  567. {
  568. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  569. {
  570. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  571. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  572. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  573. }
  574. }
  575. }
  576. else
  577. {
  578. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  579. {
  580. tempIndex = 2;
  581. }
  582. else
  583. {
  584. tempIndex = gun_index;
  585. }
  586. for (int index = 0; index < AC_QUANTITY; index++)
  587. {
  588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  589. {
  590. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  591. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  592. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  593. }
  594. }// END
  595. }
  596. // Message assembly
  597. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  598. tx_buf[4] = 0x02; // Protocol Version
  599. tx_buf[5] = 0xb0; // Message ID
  600. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  601. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  602. tx_buf[8] = 0x00; // CarID low byte
  603. tx_buf[9] = 0x00; // CarID high byte
  604. tx_buf[10] = 0x00; // ID Storage
  605. tx_buf[11] = 0x00; // Driver lowest byte
  606. tx_buf[12] = 0x00; // Driver 2nd byte
  607. tx_buf[13] = 0x00; // Driver 3rd byte
  608. tx_buf[14] = 0x00; // Driver highest byte
  609. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  610. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  611. tx_buf[17] = 0x00; // Reserve
  612. tx_buf[18] = 60 & 0xff; // Payload length low byte
  613. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  614. // EVSE provider
  615. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  616. // EVSE provider
  617. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  618. // EVSE id
  619. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  620. // Connector id
  621. tx_buf[37] = gun_index;
  622. // EVSE station
  623. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  624. // Vehicle SN
  625. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  626. // Mileage
  627. tx_buf[61] = 0x00; // lowest byte
  628. tx_buf[62] = 0x00; // 2nd byte
  629. tx_buf[63] = 0x00; // highest byte
  630. // Start date time 6 bytes
  631. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%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))
  632. {
  633. struct tm *tmTarget;
  634. struct timeb tbTarget;
  635. tmStart.tm_year -= 1900;
  636. tmStart.tm_mon -= 1;
  637. tmStart.tm_gmtoff = 0;
  638. tbTarget.time = mktime(&tmStart);
  639. tbTarget.timezone = 0;
  640. tbTarget.time += (8*3600);
  641. tmTarget = gmtime(&tbTarget.time);
  642. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  643. tx_buf[65] = (tmTarget->tm_mon+1);
  644. tx_buf[66] = tmTarget->tm_mday;
  645. tx_buf[67] = tmTarget->tm_hour;
  646. tx_buf[68] = tmTarget->tm_min;
  647. tx_buf[69] = tmTarget->tm_sec;
  648. }
  649. // Stop date time 6 bytes
  650. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  651. {
  652. struct tm *tmTarget;
  653. struct timeb tbTarget;
  654. tmEnd.tm_year -= 1900;
  655. tmEnd.tm_mon -= 1;
  656. tmEnd.tm_gmtoff = 0;
  657. tbTarget.time = mktime(&tmEnd);
  658. tbTarget.timezone = 0;
  659. tbTarget.time += (8*3600);
  660. tmTarget = gmtime(&tbTarget.time);
  661. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  662. tx_buf[71] = (tmTarget->tm_mon+1);
  663. tx_buf[72] = tmTarget->tm_mday;
  664. tx_buf[73] = tmTarget->tm_hour;
  665. tx_buf[74] = tmTarget->tm_min;
  666. tx_buf[75] = tmTarget->tm_sec;
  667. }
  668. // Session energy 2 bytes
  669. tx_buf[76] = PresentChargedEnergy & 0xff;
  670. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  671. // Start SOC 1 byte
  672. tx_buf[78] = socStart;
  673. // Stop SOC 1 byte
  674. tx_buf[79] = socEnd;
  675. // Open socket
  676. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  677. if(udp_socket_fd == -1)
  678. {
  679. DEBUG_ERROR("UDP socket create failed!\n");
  680. }
  681. else
  682. {
  683. // Get server DNS entry
  684. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  685. if (server == NULL)
  686. {
  687. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  688. }
  689. else
  690. {
  691. // Build the server's Internet address
  692. bzero((char *) &dest_addr, sizeof(dest_addr));
  693. dest_addr.sin_family = AF_INET;
  694. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  695. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  696. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  697. {
  698. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  699. {
  700. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  701. }
  702. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  703. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  704. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  705. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  706. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  707. DEBUG_TTIA_INFO("---------- Header ----------\n");
  708. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  709. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  710. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  711. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  712. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  713. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  714. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  715. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  716. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  717. DEBUG_TTIA_INFO("Len: 0x3C\n");
  718. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  719. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  720. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  721. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  722. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  723. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  724. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  725. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  726. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  727. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  728. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  729. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  730. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  731. DEBUG_TTIA_INFO("=========================================\n");
  732. sn++;
  733. result = PASS;
  734. }
  735. else
  736. {
  737. DEBUG_ERROR("UDP sent out fail.\n");
  738. }
  739. }
  740. }
  741. return result;
  742. }
  743. //=========================================
  744. // Save configuration
  745. //=========================================
  746. int runShellCmd(const char*cmd)
  747. {
  748. int result = FAIL;
  749. char buf[256];
  750. FILE *fp;
  751. fp = popen(cmd, "r");
  752. if(fp != NULL)
  753. {
  754. while(fgets(buf, sizeof(buf), fp) != NULL)
  755. {
  756. DEBUG_INFO("%s\n", buf);
  757. }
  758. result = PASS;
  759. }
  760. pclose(fp);
  761. return result;
  762. }
  763. int StoreUsrConfigData(struct SysConfigData *UsrData)
  764. {
  765. int result = PASS;
  766. int fd,wrd;
  767. unsigned int i,Chk;
  768. unsigned char *ptr, *BufTmp;
  769. int MtdBlockSize = 0x300000;
  770. Chk=0;
  771. ptr=(unsigned char *)UsrData;
  772. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  773. {
  774. memset(BufTmp,0,MtdBlockSize);
  775. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  776. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  777. Chk+=*(BufTmp+i);
  778. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  779. // Output configuration to file.
  780. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  781. if (fd < 0)
  782. {
  783. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  784. free(BufTmp);
  785. return 0;
  786. }
  787. wrd=write(fd, BufTmp, MtdBlockSize);
  788. close(fd);
  789. if(wrd<MtdBlockSize)
  790. {
  791. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  792. free(BufTmp);
  793. return 0;
  794. }
  795. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  796. DEBUG_INFO("Erase /dev/mtd10.\n");
  797. runShellCmd("flash_erase /dev/mtd10 0 0");
  798. DEBUG_INFO("Write /dev/mtd10.\n");
  799. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  800. DEBUG_INFO("Erase /dev/mtd11.\n");
  801. runShellCmd("flash_erase /dev/mtd11 0 0");
  802. DEBUG_INFO("Write /dev/mtd11.\n");
  803. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  804. system("rm -f /mnt/EvseConfig.bin");
  805. DEBUG_INFO("EvseConfig write to flash OK\n");
  806. }
  807. else
  808. {
  809. DEBUG_ERROR("alloc BlockSize NG\r\n");
  810. result = FAIL;
  811. }
  812. if(BufTmp!=NULL)
  813. free(BufTmp);
  814. return result;
  815. }
  816. //=========================================
  817. // Sqlite3 related function
  818. //=========================================
  819. static int selectSqlCount = 0;
  820. static int callback(void *data, int argc, char **argv, char **azColName){
  821. int i;
  822. //printf("%s: ", (const char*)data);
  823. selectSqlCount = argc;
  824. for(i = 0; i<argc; i++){
  825. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  826. }
  827. //printf("\n");
  828. return 0;
  829. }
  830. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  831. //int i;
  832. //printf("%s:\n", (const char*)data);
  833. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  834. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  835. return 0;
  836. }
  837. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  838. //printf("%s:\n", (const char*)data);
  839. //idTag
  840. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  841. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  842. //parentIdTag
  843. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  844. //expir_date
  845. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  846. //status
  847. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  848. //version
  849. if(columenCount > 5)
  850. idTagQuery.listVersionInt = atoi(columnValue[5]);
  851. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  852. return 0;
  853. }
  854. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  855. {
  856. // localversion = argv[5] ? atoi(argv[5]) : 0;
  857. // printf("localversion=%d\n", localversion);
  858. return 0;
  859. }
  860. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  861. {
  862. for (int i = 0; i < n_columns; i++)
  863. {
  864. DEBUG_INFO("%s\t", col_values[i]);
  865. }
  866. DEBUG_INFO("\n");
  867. return 0;
  868. }
  869. int OCPP_cleanLocalCache()
  870. {
  871. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  872. char *errMsg = 0;
  873. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  874. if (SQLITE_OK != rc)
  875. {
  876. DEBUG_INFO("SQL error: %s\n",errMsg);
  877. return FALSE;
  878. }
  879. return TRUE;
  880. }
  881. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  882. {
  883. int isSuccess = TRUE;
  884. int ret = 0;
  885. //const char* data = "Callback function called";
  886. char sql[300];
  887. char zErrMsg[200];
  888. memset(sql, 0, 300);
  889. memset(zErrMsg, 0, 200);
  890. 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);
  891. //* Execute SQL statement */
  892. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  893. if( ret != SQLITE_OK )
  894. {
  895. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  896. isSuccess = FALSE;
  897. }
  898. return isSuccess;
  899. }
  900. void OCPP_getIdTagFromLocalCache(char idTag[])
  901. {
  902. int rc = 0;
  903. char sql[100];
  904. char zErrMsg[100];
  905. memset(sql, 0, 100);
  906. memset(zErrMsg, 0, 100);
  907. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  908. memset(&idTagQuery, 0, sizeof(idTagQuery));
  909. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  910. /* Execute SQL statement */
  911. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  912. if( rc != SQLITE_OK )
  913. {
  914. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  915. }
  916. }
  917. void OCPP_getListVerion()
  918. {
  919. int rc = 0;
  920. // const char* data = "Callback function called";
  921. char sql[100];
  922. char zErrMsg[100];
  923. memset(sql, 0, 100);
  924. memset(zErrMsg, 0, 100);
  925. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  926. /* Execute SQL statement */
  927. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  928. if( rc != SQLITE_OK )
  929. {
  930. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  931. }
  932. }
  933. void OCPP_get_TableAuthlocalAllData(void)
  934. {
  935. int rc = 0;
  936. char sql[100];
  937. char zErrMsg[100];
  938. memset(sql, 0, 100);
  939. memset(zErrMsg, 0, 100);
  940. sprintf(sql,"select * from ocpp_auth_local ");
  941. /* Execute SQL statement */
  942. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  943. if( rc != SQLITE_OK )
  944. {
  945. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  946. }
  947. //return ver;
  948. }
  949. int OCPP_cleanLocalList()
  950. {
  951. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  952. char *errMsg = 0;
  953. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  954. if (SQLITE_OK != rc)
  955. {
  956. DEBUG_INFO("%s\n",errMsg);
  957. return FALSE;
  958. }
  959. return TRUE;
  960. }
  961. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  962. {
  963. int isSuccess = FALSE;
  964. int ret = 0;
  965. //const char* data = "Callback function called";
  966. char sql[300];
  967. char zErrMsg[200];
  968. memset(sql, 0, 300);
  969. memset(zErrMsg, 0, 200);
  970. 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);
  971. //* Execute SQL statement */
  972. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  973. if( ret != SQLITE_OK )
  974. {
  975. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  976. return isSuccess;
  977. }
  978. memset(sql, 0, 300);
  979. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  980. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  981. if( ret != SQLITE_OK )
  982. {
  983. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  984. return isSuccess;
  985. }
  986. isSuccess = TRUE;
  987. return isSuccess;
  988. }
  989. void OCPP_getIdTagFromLocalList(char idTag[])
  990. {
  991. int rc = 0;
  992. // const char* data = "Callback function called";
  993. char sql[100];
  994. char zErrMsg[100];
  995. memset(sql, 0, 100);
  996. memset(zErrMsg, 0, 100);
  997. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  998. memset(&idTagQuery, 0, sizeof(idTagQuery));
  999. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1000. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  1001. /* Execute SQL statement */
  1002. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  1003. if( rc != SQLITE_OK )
  1004. {
  1005. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1006. }
  1007. //return ver;
  1008. }
  1009. void OCPP_deleteIdTagFromLocalList(char idTag[])
  1010. {
  1011. //int ver = 0;
  1012. //int isSuccess = FALSE;
  1013. int rc = 0;
  1014. char sql[100];
  1015. char zErrMsg[100];
  1016. memset(sql, 0, 100);
  1017. memset(zErrMsg, 0, 100);
  1018. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  1019. //* Execute SQL statement */
  1020. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  1021. if( rc != SQLITE_OK )
  1022. {
  1023. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1024. }
  1025. }
  1026. int getCurrentYear()
  1027. {
  1028. int result = 0;
  1029. time_t CurrentTime;
  1030. struct tm *tm;
  1031. CurrentTime = time(NULL);
  1032. tm=localtime(&CurrentTime);
  1033. result = (tm->tm_year + 1900);
  1034. return result;
  1035. }
  1036. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  1037. {
  1038. int result = PASS;
  1039. char* errMsg = NULL;
  1040. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  1041. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  1042. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1043. {
  1044. result = FAIL;
  1045. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  1046. }
  1047. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-100) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1048. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1049. {
  1050. result = FAIL;
  1051. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  1052. }
  1053. return result;
  1054. }
  1055. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  1056. {
  1057. int isSuccess = TRUE;
  1058. int tempIndex;
  1059. json_object *EnergyDataTransfer = json_object_new_object();
  1060. json_object *periodEnergys = json_object_new_object();
  1061. char sql[1024];
  1062. char zErrMsg[200];
  1063. memset(sql, 0, ARRAY_SIZE(sql));
  1064. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  1065. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  1066. {
  1067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1068. {
  1069. tempIndex = ((gun_index==2) ? 1: 0);
  1070. }
  1071. else
  1072. {
  1073. tempIndex = gun_index;
  1074. }
  1075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1076. {
  1077. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1078. {
  1079. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1080. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1081. {
  1082. uint8_t period[3];
  1083. sprintf((char*)period, "%d", idxPeriod);
  1084. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1085. }
  1086. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1087. } //end of the same index
  1088. }//end of for CHAdeMO_QUANTITY
  1089. }
  1090. else if(gunType[gun_index] == GUN_TYPE_CCS)
  1091. {
  1092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1093. {
  1094. tempIndex = ((gun_index==2) ? 1: 0);
  1095. }
  1096. else
  1097. {
  1098. tempIndex = gun_index;
  1099. }
  1100. for (int index = 0; index < CCS_QUANTITY; index++)
  1101. {
  1102. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1103. {
  1104. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1105. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1106. {
  1107. uint8_t period[3];
  1108. sprintf((char*)period, "%d", idxPeriod);
  1109. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1110. }
  1111. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1112. } //end of the same index
  1113. } // end of for CCS_QUANTITY
  1114. }
  1115. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1116. {
  1117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1118. {
  1119. tempIndex = ((gun_index==2) ? 1: 0);
  1120. }
  1121. else
  1122. {
  1123. tempIndex = gun_index;
  1124. }
  1125. for (int index = 0; index < GB_QUANTITY; index++)
  1126. {
  1127. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1128. {
  1129. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1130. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1131. {
  1132. uint8_t period[3];
  1133. sprintf((char*)period, "%d", idxPeriod);
  1134. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1135. }
  1136. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1137. } //end of the same index
  1138. } // end of for GB_QUANTITY
  1139. }
  1140. else if(gunType[gun_index] == GUN_TYPE_DO)
  1141. {
  1142. tempIndex = gun_index;
  1143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1144. {
  1145. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1146. {
  1147. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1148. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1149. {
  1150. uint8_t period[3];
  1151. sprintf((char*)period, "%d", idxPeriod);
  1152. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1153. }
  1154. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1155. } //end of the same index
  1156. }
  1157. }
  1158. else
  1159. {
  1160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1161. {
  1162. tempIndex = 2;
  1163. }
  1164. else
  1165. {
  1166. tempIndex = gun_index;
  1167. }
  1168. for (int index = 0; index < AC_QUANTITY; index++)
  1169. {
  1170. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1171. {
  1172. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1173. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1174. {
  1175. uint8_t period[3];
  1176. sprintf((char*)period, "%d", idxPeriod);
  1177. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1178. }
  1179. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1180. }//end of the same index
  1181. }//end of for AC_QUANTITY
  1182. }
  1183. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1184. json_object_put(EnergyDataTransfer);
  1185. //* Execute SQL statement */
  1186. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1187. {
  1188. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1189. isSuccess = FALSE;
  1190. }
  1191. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1192. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1193. {
  1194. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1195. isSuccess = FALSE;
  1196. }
  1197. return isSuccess;
  1198. }
  1199. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1200. {
  1201. int isSuccess = TRUE;
  1202. char sql[512];
  1203. char zErrMsg[200];
  1204. int rows, cols;
  1205. char **resultData;
  1206. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1207. /* Execute SQL statement */
  1208. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1209. {
  1210. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1211. isSuccess = FALSE;
  1212. }
  1213. else
  1214. {
  1215. if((rows > 0) && (atoi(resultData[4]) > 0))
  1216. {
  1217. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1218. }
  1219. else
  1220. {
  1221. DEBUG_WARN("There is not match transaction data.\n");
  1222. isSuccess = FALSE;
  1223. }
  1224. }
  1225. return isSuccess;
  1226. }
  1227. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1228. {
  1229. int result = PASS;
  1230. char* errMsg = NULL;
  1231. char sqlStr[8192];
  1232. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1233. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1234. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1235. {
  1236. result = FAIL;
  1237. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1238. }
  1239. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1240. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1241. {
  1242. result = FAIL;
  1243. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1244. }
  1245. return result;
  1246. }
  1247. int OCPP_update_deduct_info(int txId, char *creditNo)
  1248. {
  1249. int result = PASS;
  1250. char* errMsg = NULL;
  1251. char sqlStr[8192];
  1252. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1253. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1254. {
  1255. result = FAIL;
  1256. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1257. }
  1258. return result;
  1259. }
  1260. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1261. {
  1262. json_object *dataBuf = json_object_new_object();
  1263. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1264. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1265. json_object_object_add(dataBuf, "txId", json_object_new_int(atoi(columnValue[1])));
  1266. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1267. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1268. json_object_object_add(dataBuf, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1269. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[5])));
  1270. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[9]));
  1271. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1272. json_object_put(dataBuf);
  1273. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1274. return 0;
  1275. }
  1276. void OCPP_query_deduct_info()
  1277. {
  1278. int rc = 0;
  1279. char sql[100];
  1280. char zErrMsg[100];
  1281. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1282. /* Execute SQL statement */
  1283. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1284. if( rc != SQLITE_OK )
  1285. {
  1286. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1287. }
  1288. }
  1289. // Occupancy fee deduct queue process
  1290. int OCPP_insert_occupancyDeduct_info(char *occupancySN, char *creditNo, uint8_t deductResult, double amount, char *approvalNo)
  1291. {
  1292. int result = PASS;
  1293. char* errMsg = NULL;
  1294. char sqlStr[8192];
  1295. sprintf(sqlStr, "insert or replace into report_occupancyDeduct_info(occupancySN, creditNo, deductResult, amount, approvalNo, isUploaded) values('%s', '%s', '%d', '%.2f', '%s', '0');",
  1296. occupancySN, creditNo, deductResult, amount, approvalNo);
  1297. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1298. {
  1299. result = FAIL;
  1300. DEBUG_WARN( "Insert local report_occupancyDeduct_info error message: %s\n", errMsg);
  1301. }
  1302. sprintf(sqlStr, "delete from report_occupancyDeduct_info where (idx < (select idx from report_occupancyDeduct_info order by idx desc limit 1)-5000);");
  1303. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1304. {
  1305. result = FAIL;
  1306. DEBUG_WARN( "delete local report_occupancyDeduct_info error message: %s\n", errMsg);
  1307. }
  1308. return result;
  1309. }
  1310. int OCPP_update_occupancyDeduct_info(char *occupancySN)
  1311. {
  1312. int result = PASS;
  1313. char* errMsg = NULL;
  1314. char sqlStr[8192];
  1315. sprintf(sqlStr, "update report_occupancyDeduct_info set isUploaded='1' where occupancySN='%s';", occupancySN);
  1316. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1317. {
  1318. result = FAIL;
  1319. DEBUG_WARN( "Update local report_occupancyDeduct_info error message: %s\n", errMsg);
  1320. }
  1321. return result;
  1322. }
  1323. int queryOccupancyDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1324. {
  1325. json_object *dataBuf = json_object_new_object();
  1326. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1327. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_OccupancyDeductResult");
  1328. json_object_object_add(dataBuf, "occupancySN", json_object_new_string(columnValue[1]));
  1329. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1330. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1331. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[4])));
  1332. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[5]));
  1333. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1334. json_object_put(dataBuf);
  1335. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1336. return 0;
  1337. }
  1338. void OCPP_query_occupancyDeduct_info()
  1339. {
  1340. int rc = 0;
  1341. char sql[100];
  1342. char zErrMsg[100];
  1343. sprintf(sql,"select * from report_occupancyDeduct_info where isUploaded='0' order by idx limit 1");
  1344. /* Execute SQL statement */
  1345. rc = sqlite3_exec(db, sql, queryOccupancyDeductCallBack, 0, (char **)&zErrMsg);
  1346. if( rc != SQLITE_OK )
  1347. {
  1348. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1349. }
  1350. }
  1351. void reportReaderStatus(int gun_index)
  1352. {
  1353. struct timeval tmnow;
  1354. struct tm *tm;
  1355. char buf[28];//, usec_buf[6];
  1356. gettimeofday(&tmnow, NULL);
  1357. time_t t;
  1358. t = time(NULL);
  1359. /*UTC time and date*/
  1360. tm = gmtime(&t);
  1361. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1362. #if 0 // remove temporally
  1363. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1364. strcat(buf,".");
  1365. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1366. strcat(buf,usec_buf);
  1367. #endif
  1368. json_object *dataBuf = json_object_new_object();
  1369. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1370. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1371. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1372. json_object_object_add(dataBuf, "readerStatus", json_object_new_int(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus));
  1373. json_object_object_add(dataBuf, "timestamp", json_object_new_string(buf));
  1374. json_object_object_add(dataBuf, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  1375. json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
  1376. json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  1377. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1378. json_object_put(dataBuf);
  1379. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1380. }
  1381. void occupancyFeeAct(int gun_index)
  1382. {
  1383. struct timeval tmnow;
  1384. struct tm *tm;
  1385. char buf[28];//, usec_buf[6];
  1386. gettimeofday(&tmnow, NULL);
  1387. time_t t;
  1388. t = time(NULL);
  1389. /*UTC time and date*/
  1390. tm = gmtime(&t);
  1391. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1392. #if 0 // remove temporally
  1393. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1394. strcat(buf,".");
  1395. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1396. strcat(buf,usec_buf);
  1397. #endif
  1398. json_object *dataBuf = json_object_new_object();
  1399. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1400. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_OccupancyFeeAct");
  1401. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1402. json_object_object_add(dataBuf, "occupancySN", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN));
  1403. json_object_object_add(dataBuf, "action", json_object_new_int(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].action));
  1404. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1405. json_object_put(dataBuf);
  1406. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1407. }
  1408. //==========================================
  1409. // Check time passed since today
  1410. //==========================================
  1411. long long DiffTimebWithNow(struct timeb ST)
  1412. {
  1413. //return milli-second
  1414. struct timeb ET;
  1415. long long StartTime,StopTime;
  1416. ftime(&ET);
  1417. StartTime=(long long)ST.time;
  1418. StopTime=(long long)ET.time;
  1419. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1420. }
  1421. int getTimePassSinceToday(uint8_t gun_index)
  1422. {
  1423. int result = -1;
  1424. static time_t lastTime[4];
  1425. time_t t;
  1426. struct tm *tmStartToday;
  1427. struct timeb tbStartToday;
  1428. t=time(NULL);
  1429. if(difftime(t, lastTime[gun_index])>0)
  1430. {
  1431. tmStartToday=localtime(&t);
  1432. tmStartToday->tm_hour = 0;
  1433. tmStartToday->tm_min = 0;
  1434. tmStartToday->tm_sec = 0;
  1435. tbStartToday.time = mktime(tmStartToday);
  1436. tbStartToday.millitm = 0;
  1437. result = DiffTimebWithNow(tbStartToday)/1000;
  1438. lastTime[gun_index] = t;
  1439. }
  1440. return result;
  1441. }
  1442. void getNowDatetime(uint8_t *data)
  1443. {
  1444. time_t t = time(NULL);
  1445. struct tm tm = *localtime(&t);
  1446. 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);
  1447. }
  1448. int syncDateTimeRTC(uint8_t *data)
  1449. {
  1450. struct ParsingResult
  1451. {
  1452. int result;
  1453. int scanedElement;
  1454. int year;
  1455. int month;
  1456. int mday;
  1457. int hour;
  1458. int min;
  1459. int sec;
  1460. int tz_hour;
  1461. int tz_min;
  1462. float minSec;
  1463. }result;
  1464. struct tm tmOrg;
  1465. struct tm *tmTarget;
  1466. struct timeb tbTarget;
  1467. char buf[128];
  1468. memset(&result, 0x00, sizeof(struct ParsingResult));
  1469. result.result = PASS;
  1470. if(strstr((char*)data, ".") != NULL)
  1471. {
  1472. // Original data with mini second
  1473. if(strstr((char*)data, "Z") != NULL)
  1474. {
  1475. // Original data with Z
  1476. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1477. &result.year,
  1478. &result.month,
  1479. &result.mday,
  1480. &result.hour,
  1481. &result.min,
  1482. &result.sec,
  1483. &result.minSec);
  1484. }
  1485. else
  1486. {
  1487. // Original data without Z
  1488. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1489. &result.year,
  1490. &result.month,
  1491. &result.mday,
  1492. &result.hour,
  1493. &result.min,
  1494. &result.sec,
  1495. &result.minSec,
  1496. &result.tz_hour,
  1497. &result.tz_min);
  1498. }
  1499. }
  1500. else
  1501. {
  1502. // Original data without mini second
  1503. if(strstr((char*)data, "Z") != NULL)
  1504. {
  1505. // Original data with Z
  1506. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1507. &result.year,
  1508. &result.month,
  1509. &result.mday,
  1510. &result.hour,
  1511. &result.min,
  1512. &result.sec);
  1513. }
  1514. else
  1515. {
  1516. // Original data without Z
  1517. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1518. &result.year,
  1519. &result.month,
  1520. &result.mday,
  1521. &result.hour,
  1522. &result.min,
  1523. &result.sec,
  1524. &result.tz_hour,
  1525. &result.tz_min);
  1526. }
  1527. }
  1528. tmOrg.tm_year = result.year - 1900;
  1529. tmOrg.tm_mon = result.month - 1;
  1530. tmOrg.tm_mday = result.mday;
  1531. tmOrg.tm_hour = result.hour;
  1532. tmOrg.tm_min = result.min;
  1533. tmOrg.tm_sec = result.sec;
  1534. tmOrg.tm_gmtoff = 0;
  1535. tbTarget.time = mktime(&tmOrg);
  1536. tbTarget.timezone = 0;
  1537. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1538. tmTarget = gmtime(&tbTarget.time);
  1539. 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);
  1540. //DEBUG_INFO(" org date time: %s\n", data);
  1541. //DEBUG_INFO("parse date time: %s\n", buf);
  1542. system(buf);
  1543. system("/sbin/hwclock -w --systohc");
  1544. if(result.scanedElement < 6)
  1545. result.result = FAIL;
  1546. return result.result;
  1547. }
  1548. //==========================================
  1549. // Parse certificate content
  1550. //==========================================
  1551. int parseCertInfo(char *certPath, int parseType, char *data)
  1552. {
  1553. int result = FAIL;
  1554. int count = 0;
  1555. int showupLine = 0;
  1556. memset(data, 0, ARRAY_SIZE(data));
  1557. if(access(certPath,F_OK) != -1)
  1558. {
  1559. char temp[512] = {0};
  1560. char capturedData[256] = {0};
  1561. char hashType[10] = "SHA256";
  1562. FILE *fp;
  1563. // Need to get hash type first
  1564. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1565. fp = popen(temp, "r");
  1566. if(fp)
  1567. {
  1568. while(fgets(temp, sizeof(temp), fp) != NULL)
  1569. {
  1570. if(strstr(temp, "Signature Algorithm:") != NULL)
  1571. {
  1572. result = PASS;
  1573. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1574. sprintf((char*)hashType, "SHA256");
  1575. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1576. sprintf((char*)hashType, "SHA384");
  1577. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1578. sprintf((char*)hashType, "SHA512");
  1579. else
  1580. {
  1581. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1582. result = FAIL;
  1583. }
  1584. break;
  1585. }
  1586. }
  1587. }
  1588. switch(parseType)
  1589. {
  1590. case CERT_PARSE_HashAlgorithm:
  1591. sprintf((char*)data, hashType);
  1592. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1593. break;
  1594. case CERT_PARSE_SerialNumber:
  1595. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1596. fp = popen(temp, "r");
  1597. if(fp)
  1598. {
  1599. while(fgets(temp, sizeof(temp), fp) != NULL)
  1600. {
  1601. if(strstr(temp, "serial=") != NULL)
  1602. {
  1603. sscanf(temp, "%*[^=]=%s", capturedData);
  1604. result = PASS;
  1605. break;
  1606. }
  1607. }
  1608. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1609. sprintf((char*)data, capturedData);
  1610. }
  1611. break;
  1612. case CERT_PARSE_IssuerNameHash:
  1613. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1614. fp = popen(temp, "r");
  1615. if(fp)
  1616. {
  1617. while(fgets(temp, sizeof(temp), fp) != NULL)
  1618. {
  1619. if(strstr(temp, "SEQUENCE") != NULL)
  1620. {
  1621. count++;
  1622. if(count==4)
  1623. {
  1624. sscanf(temp, "%[^:]", capturedData);
  1625. showupLine = atoi(capturedData);
  1626. break;
  1627. }
  1628. }
  1629. }
  1630. }
  1631. if(showupLine > 0)
  1632. {
  1633. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  1634. system(temp);
  1635. }
  1636. else
  1637. {
  1638. break;
  1639. }
  1640. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  1641. {
  1642. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  1643. fp = popen(temp, "r");
  1644. if(fp)
  1645. {
  1646. while(fgets(temp, sizeof(temp), fp) != NULL)
  1647. {
  1648. if(strstr(temp, "(stdin)=") != NULL)
  1649. {
  1650. sscanf(temp, "%*[^=]=%s", capturedData);
  1651. result = PASS;
  1652. break;
  1653. }
  1654. }
  1655. stringtrimspace(capturedData);
  1656. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1657. sprintf((char*)data, capturedData);
  1658. }
  1659. }
  1660. break;
  1661. case CERT_PARSE_IssuerKeyHash:
  1662. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1663. fp = popen(temp, "r");
  1664. if(fp)
  1665. {
  1666. while(fgets(temp, sizeof(temp), fp) != NULL)
  1667. {
  1668. if(strstr(temp, "BIT STRING") != NULL)
  1669. {
  1670. sscanf(temp, "%[^:]", capturedData);
  1671. showupLine = atoi(capturedData);
  1672. break;
  1673. }
  1674. }
  1675. }
  1676. if(showupLine > 0)
  1677. {
  1678. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1679. system(temp);
  1680. }
  1681. else
  1682. {
  1683. break;
  1684. }
  1685. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1686. {
  1687. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1688. fp = popen(temp, "r");
  1689. if(fp)
  1690. {
  1691. while(fgets(temp, sizeof(temp), fp) != NULL)
  1692. {
  1693. if(strstr(temp, "(stdin)=") != NULL)
  1694. {
  1695. sscanf(temp, "%*[^=]=%s", capturedData);
  1696. result = PASS;
  1697. break;
  1698. }
  1699. }
  1700. stringtrimspace(capturedData);
  1701. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1702. sprintf((char*)data, capturedData);
  1703. }
  1704. }
  1705. break;
  1706. case CERT_PARSE_OcspUrl:
  1707. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1708. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1709. fp = popen(temp, "r");
  1710. if(fp)
  1711. {
  1712. while(fgets(temp, sizeof(temp), fp) != NULL)
  1713. {
  1714. if(strstr(temp, "OCSP - URI:") != NULL)
  1715. {
  1716. //strcpy((char*)data, temp);
  1717. sscanf(temp, "%*[^:]:%s", capturedData);
  1718. sprintf((char*)data, capturedData);
  1719. DEBUG_INFO("OCSP_URI: %s\n", data);
  1720. result = PASS;
  1721. break;
  1722. }
  1723. }
  1724. }
  1725. break;
  1726. default:
  1727. DEBUG_INFO("Parse type is invalid.\n");
  1728. break;
  1729. }
  1730. pclose(fp);
  1731. }
  1732. return result;
  1733. }
  1734. //==========================================
  1735. // GetCompositeSchedule logic related function
  1736. //==========================================
  1737. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1738. {
  1739. //return milli-second
  1740. unsigned int StartTime,StopTime;
  1741. StartTime=(unsigned int)ST.time;
  1742. StopTime=(unsigned int)ET.time;
  1743. return (StopTime-StartTime);
  1744. }
  1745. int DiffTimebWithNowSec(struct timeb ST)
  1746. {
  1747. //return milli-second
  1748. struct timeb ET;
  1749. unsigned int StartTime,StopTime;
  1750. ftime(&ET);
  1751. StartTime=(unsigned int)ST.time;
  1752. StopTime=(unsigned int)ET.time;
  1753. return (StopTime-StartTime);
  1754. }
  1755. int getStartStop(uint8_t *start, uint8_t *stop)
  1756. {
  1757. struct ParsingResult
  1758. {
  1759. int result;
  1760. int scanedElement;
  1761. int year;
  1762. int month;
  1763. int mday;
  1764. int hour;
  1765. int min;
  1766. int sec;
  1767. int tz_hour;
  1768. int tz_min;
  1769. float minSec;
  1770. };
  1771. struct ParsingResult parseStart;
  1772. struct ParsingResult parseStop;
  1773. int result = -1;
  1774. struct tm tmStart;
  1775. struct timeb tbStart;
  1776. struct tm tmStop;
  1777. struct timeb tbStop;
  1778. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1779. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1780. // Scan start & stop date time
  1781. if(strstr((char*)start, ".") != NULL)
  1782. {
  1783. // Original data with mini second
  1784. if(strstr((char*)start, "Z") != NULL)
  1785. {
  1786. // Original data with Z
  1787. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1788. &parseStart.year,
  1789. &parseStart.month,
  1790. &parseStart.mday,
  1791. &parseStart.hour,
  1792. &parseStart.min,
  1793. &parseStart.sec,
  1794. &parseStart.minSec);
  1795. }
  1796. else
  1797. {
  1798. // Original data without Z
  1799. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1800. &parseStart.year,
  1801. &parseStart.month,
  1802. &parseStart.mday,
  1803. &parseStart.hour,
  1804. &parseStart.min,
  1805. &parseStart.sec,
  1806. &parseStart.minSec,
  1807. &parseStart.tz_hour,
  1808. &parseStart.tz_min);
  1809. }
  1810. }
  1811. else
  1812. {
  1813. // Original data without mini second
  1814. if(strstr((char*)start, "Z") != NULL)
  1815. {
  1816. // Original data with Z
  1817. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1818. &parseStart.year,
  1819. &parseStart.month,
  1820. &parseStart.mday,
  1821. &parseStart.hour,
  1822. &parseStart.min,
  1823. &parseStart.sec);
  1824. }
  1825. else
  1826. {
  1827. // Original data without Z
  1828. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1829. &parseStart.year,
  1830. &parseStart.month,
  1831. &parseStart.mday,
  1832. &parseStart.hour,
  1833. &parseStart.min,
  1834. &parseStart.sec,
  1835. &parseStart.tz_hour,
  1836. &parseStart.tz_min);
  1837. }
  1838. }
  1839. if(strstr((char*)stop, ".") != NULL)
  1840. {
  1841. // Original data with mini second
  1842. if(strstr((char*)stop, "Z") != NULL)
  1843. {
  1844. // Original data with Z
  1845. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1846. &parseStop.year,
  1847. &parseStop.month,
  1848. &parseStop.mday,
  1849. &parseStop.hour,
  1850. &parseStop.min,
  1851. &parseStop.sec,
  1852. &parseStop.minSec);
  1853. }
  1854. else
  1855. {
  1856. // Original data without Z
  1857. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1858. &parseStop.year,
  1859. &parseStop.month,
  1860. &parseStop.mday,
  1861. &parseStop.hour,
  1862. &parseStop.min,
  1863. &parseStop.sec,
  1864. &parseStop.minSec,
  1865. &parseStop.tz_hour,
  1866. &parseStop.tz_min);
  1867. }
  1868. }
  1869. else
  1870. {
  1871. // Original data without mini second
  1872. if(strstr((char*)stop, "Z") != NULL)
  1873. {
  1874. // Original data with Z
  1875. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1876. &parseStop.year,
  1877. &parseStop.month,
  1878. &parseStop.mday,
  1879. &parseStop.hour,
  1880. &parseStop.min,
  1881. &parseStop.sec);
  1882. }
  1883. else
  1884. {
  1885. // Original data without Z
  1886. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1887. &parseStop.year,
  1888. &parseStop.month,
  1889. &parseStop.mday,
  1890. &parseStop.hour,
  1891. &parseStop.min,
  1892. &parseStop.sec,
  1893. &parseStop.tz_hour,
  1894. &parseStop.tz_min);
  1895. }
  1896. }
  1897. // Calculate date time difference
  1898. if((parseStart.scanedElement >=6) &&
  1899. (parseStop.scanedElement >=6))
  1900. {
  1901. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1902. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1903. tmStart.tm_year = parseStart.year - 1900;
  1904. tmStart.tm_mon = parseStart.month - 1;
  1905. tmStart.tm_mday = parseStart.mday;
  1906. tmStart.tm_hour = parseStart.hour;
  1907. tmStart.tm_min = parseStart.min;
  1908. tmStart.tm_sec = parseStart.sec;
  1909. tmStart.tm_gmtoff = 0;
  1910. tbStart.time = mktime(&tmStart);
  1911. tbStart.timezone = 0;
  1912. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1913. tmStop.tm_year = parseStop.year - 1900;
  1914. tmStop.tm_mon = parseStop.month - 1;
  1915. tmStop.tm_mday = parseStop.mday;
  1916. tmStop.tm_hour = parseStop.hour;
  1917. tmStop.tm_min = parseStop.min;
  1918. tmStop.tm_sec = parseStop.sec;
  1919. tmStop.tm_gmtoff = 0;
  1920. tbStop.time = mktime(&tmStop);
  1921. tbStop.timezone = 0;
  1922. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1923. result = DiffTimebSec(tbStart, tbStop);
  1924. //DEBUG_INFO("getStartStop(): %d\n", result);
  1925. }
  1926. else
  1927. {
  1928. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1929. }
  1930. return result;
  1931. }
  1932. int isOvertNow(uint8_t *start)
  1933. {
  1934. int result = NO;
  1935. struct ParsingResult
  1936. {
  1937. int result;
  1938. int scanedElement;
  1939. int year;
  1940. int month;
  1941. int mday;
  1942. int hour;
  1943. int min;
  1944. int sec;
  1945. int tz_hour;
  1946. int tz_min;
  1947. float minSec;
  1948. }parsingResult;
  1949. struct tm tmStart;
  1950. struct timeb tbStart;
  1951. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1952. if(strstr((char*)start, ".") != NULL)
  1953. {
  1954. // Original data with mini second
  1955. if(strstr((char*)start, "Z") != NULL)
  1956. {
  1957. // Original data with Z
  1958. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1959. &parsingResult.year,
  1960. &parsingResult.month,
  1961. &parsingResult.mday,
  1962. &parsingResult.hour,
  1963. &parsingResult.min,
  1964. &parsingResult.sec,
  1965. &parsingResult.minSec);
  1966. }
  1967. else
  1968. {
  1969. // Original data without Z
  1970. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1971. &parsingResult.year,
  1972. &parsingResult.month,
  1973. &parsingResult.mday,
  1974. &parsingResult.hour,
  1975. &parsingResult.min,
  1976. &parsingResult.sec,
  1977. &parsingResult.minSec,
  1978. &parsingResult.tz_hour,
  1979. &parsingResult.tz_min);
  1980. }
  1981. }
  1982. else
  1983. {
  1984. // Original data without mini second
  1985. if(strstr((char*)start, "Z") != NULL)
  1986. {
  1987. // Original data with Z
  1988. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1989. &parsingResult.year,
  1990. &parsingResult.month,
  1991. &parsingResult.mday,
  1992. &parsingResult.hour,
  1993. &parsingResult.min,
  1994. &parsingResult.sec);
  1995. }
  1996. else
  1997. {
  1998. // Original data without Z
  1999. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2000. &parsingResult.year,
  2001. &parsingResult.month,
  2002. &parsingResult.mday,
  2003. &parsingResult.hour,
  2004. &parsingResult.min,
  2005. &parsingResult.sec,
  2006. &parsingResult.tz_hour,
  2007. &parsingResult.tz_min);
  2008. }
  2009. }
  2010. if(parsingResult.scanedElement >= 6)
  2011. {
  2012. tmStart.tm_year = parsingResult.year - 1900;
  2013. tmStart.tm_mon = parsingResult.month - 1;
  2014. tmStart.tm_mday = parsingResult.mday;
  2015. tmStart.tm_hour = parsingResult.hour;
  2016. tmStart.tm_min = parsingResult.min;
  2017. tmStart.tm_sec = parsingResult.sec;
  2018. tmStart.tm_gmtoff = 0;
  2019. tbStart.time = mktime(&tmStart);
  2020. tbStart.timezone = 0;
  2021. tbStart.millitm = 0;
  2022. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  2023. if(DiffTimebWithNowSec(tbStart) <= 0)
  2024. result = NO;
  2025. else
  2026. result = YES;
  2027. }
  2028. else
  2029. {
  2030. DEBUG_WARN("Start date parsing error.\n");
  2031. }
  2032. return result;
  2033. }
  2034. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2035. {
  2036. struct ParsingResult
  2037. {
  2038. int result;
  2039. int scanedElement;
  2040. int year;
  2041. int month;
  2042. int mday;
  2043. int hour;
  2044. int min;
  2045. int sec;
  2046. int tz_hour;
  2047. int tz_min;
  2048. float minSec;
  2049. };
  2050. struct ParsingResult parseStart;
  2051. struct ParsingResult parseStop;
  2052. int result = -1;
  2053. struct tm tmStart;
  2054. struct timeb tbStart;
  2055. struct tm tmStop;
  2056. struct timeb tbStop;
  2057. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  2058. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  2059. // Scan start & stop date time
  2060. if(strstr((char*)start, ".") != NULL)
  2061. {
  2062. // Original data with mini second
  2063. if(strstr((char*)start, "Z") != NULL)
  2064. {
  2065. // Original data with Z
  2066. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  2067. &parseStart.year,
  2068. &parseStart.month,
  2069. &parseStart.mday,
  2070. &parseStart.hour,
  2071. &parseStart.min,
  2072. &parseStart.sec,
  2073. &parseStart.minSec);
  2074. }
  2075. else
  2076. {
  2077. // Original data without Z
  2078. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2079. &parseStart.year,
  2080. &parseStart.month,
  2081. &parseStart.mday,
  2082. &parseStart.hour,
  2083. &parseStart.min,
  2084. &parseStart.sec,
  2085. &parseStart.minSec,
  2086. &parseStart.tz_hour,
  2087. &parseStart.tz_min);
  2088. }
  2089. }
  2090. else
  2091. {
  2092. // Original data without mini second
  2093. if(strstr((char*)start, "Z") != NULL)
  2094. {
  2095. // Original data with Z
  2096. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  2097. &parseStart.year,
  2098. &parseStart.month,
  2099. &parseStart.mday,
  2100. &parseStart.hour,
  2101. &parseStart.min,
  2102. &parseStart.sec);
  2103. }
  2104. else
  2105. {
  2106. // Original data without Z
  2107. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2108. &parseStart.year,
  2109. &parseStart.month,
  2110. &parseStart.mday,
  2111. &parseStart.hour,
  2112. &parseStart.min,
  2113. &parseStart.sec,
  2114. &parseStart.tz_hour,
  2115. &parseStart.tz_min);
  2116. }
  2117. }
  2118. if(strstr((char*)stop, ".") != NULL)
  2119. {
  2120. // Original data with mini second
  2121. if(strstr((char*)stop, "Z") != NULL)
  2122. {
  2123. // Original data with Z
  2124. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  2125. &parseStop.year,
  2126. &parseStop.month,
  2127. &parseStop.mday,
  2128. &parseStop.hour,
  2129. &parseStop.min,
  2130. &parseStop.sec,
  2131. &parseStop.minSec);
  2132. }
  2133. else
  2134. {
  2135. // Original data without Z
  2136. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2137. &parseStop.year,
  2138. &parseStop.month,
  2139. &parseStop.mday,
  2140. &parseStop.hour,
  2141. &parseStop.min,
  2142. &parseStop.sec,
  2143. &parseStop.minSec,
  2144. &parseStop.tz_hour,
  2145. &parseStop.tz_min);
  2146. }
  2147. }
  2148. else
  2149. {
  2150. // Original data without mini second
  2151. if(strstr((char*)stop, "Z") != NULL)
  2152. {
  2153. // Original data with Z
  2154. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  2155. &parseStop.year,
  2156. &parseStop.month,
  2157. &parseStop.mday,
  2158. &parseStop.hour,
  2159. &parseStop.min,
  2160. &parseStop.sec);
  2161. }
  2162. else
  2163. {
  2164. // Original data without Z
  2165. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  2166. &parseStop.year,
  2167. &parseStop.month,
  2168. &parseStop.mday,
  2169. &parseStop.hour,
  2170. &parseStop.min,
  2171. &parseStop.sec,
  2172. &parseStop.tz_hour,
  2173. &parseStop.tz_min);
  2174. }
  2175. }
  2176. // Calculate date time difference
  2177. if((parseStart.scanedElement >=6) &&
  2178. (parseStop.scanedElement >=6))
  2179. {
  2180. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  2181. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  2182. tmStart.tm_year = parseStart.year - 1900;
  2183. tmStart.tm_mon = parseStart.month - 1;
  2184. tmStart.tm_mday = parseStart.mday;
  2185. tmStart.tm_hour = parseStart.hour;
  2186. tmStart.tm_min = parseStart.min;
  2187. tmStart.tm_sec = parseStart.sec;
  2188. tmStart.tm_gmtoff = 0;
  2189. tbStart.time = mktime(&tmStart);
  2190. tbStart.timezone = 0;
  2191. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  2192. tmStop.tm_year = parseStop.year - 1900;
  2193. tmStop.tm_mon = parseStop.month - 1;
  2194. tmStop.tm_mday = parseStop.mday;
  2195. tmStop.tm_hour = parseStop.hour;
  2196. tmStop.tm_min = parseStop.min;
  2197. tmStop.tm_sec = parseStop.sec;
  2198. tmStop.tm_gmtoff = 0;
  2199. tbStop.time = mktime(&tmStop);
  2200. tbStop.timezone = 0;
  2201. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  2202. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2203. //DEBUG_INFO("getStartStop(): %d\n", result);
  2204. }
  2205. else
  2206. {
  2207. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2208. }
  2209. return result;
  2210. }
  2211. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2212. {
  2213. FILE *fp;
  2214. char profileFileName[128];
  2215. char *line = NULL;
  2216. size_t len = 0;
  2217. time_t CurrentTime;
  2218. struct tm *tmComposite;
  2219. struct StructChargingProfile maxProfile;
  2220. struct StructChargingProfile compositeProfile;
  2221. uint8_t limitMax=0;
  2222. int compositePeriodIdx = 0;
  2223. //uint8_t isDurationNull = FALSE;
  2224. CurrentTime = time(NULL);
  2225. tmComposite=localtime(&CurrentTime);
  2226. 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);
  2227. if(isUnitA)
  2228. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2229. else
  2230. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2231. compositeProfile.ChargingSchedule.Duration = durationReq;
  2232. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2233. {
  2234. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2235. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2236. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2237. }
  2238. compositeProfile.ChargingProfileId = 0;
  2239. compositeProfile.StackLevel = 99 ;
  2240. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2241. maxProfile.ChargingProfileId = -1;
  2242. maxProfile.ChargingSchedule.Duration = -1;
  2243. system("rm -f /tmp/*.json");
  2244. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2245. // Search max profile
  2246. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2247. if((access(profileFileName, F_OK))!=-1)
  2248. {
  2249. fp = fopen(profileFileName, "r");
  2250. while(getline(&line, &len, fp) != -1)
  2251. {
  2252. json_object *obj = NULL;
  2253. obj = json_tokener_parse(line);
  2254. if(is_error(obj))
  2255. {
  2256. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2257. }
  2258. else
  2259. {
  2260. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2261. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2262. )
  2263. {
  2264. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2265. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2266. )
  2267. {
  2268. struct tm tmFrom, tmTo;
  2269. struct timeb tbFrom, tbTo;
  2270. 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) &&
  2271. (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))
  2272. {
  2273. tmFrom.tm_year -= 1900;
  2274. tmFrom.tm_mon -= 1;
  2275. tbFrom.time = mktime(&tmFrom);
  2276. tmTo.tm_year -= 1900;
  2277. tmTo.tm_mon -= 1;
  2278. tbTo.time = mktime(&tmTo);
  2279. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2280. {
  2281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2282. {
  2283. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2285. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2286. }
  2287. if(maxProfile.ChargingProfileId == -1)
  2288. DEBUG_INFO("MaxProfile found.\n");
  2289. else
  2290. DEBUG_INFO("MaxProfile updated.\n");
  2291. // Required item
  2292. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2293. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2294. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2295. if(isUnitA)
  2296. {
  2297. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2298. 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++)
  2299. {
  2300. 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"));
  2301. 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?
  2302. 3:
  2303. 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")));
  2304. 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")));
  2305. }
  2306. }
  2307. else
  2308. {
  2309. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2310. 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++)
  2311. {
  2312. 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"));
  2313. 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?
  2314. 3:
  2315. 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")));
  2316. 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));
  2317. }
  2318. }
  2319. // Optional item
  2320. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2321. {
  2322. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2323. }
  2324. else
  2325. {
  2326. sprintf((char*)maxProfile.ValidFrom, " ");
  2327. }
  2328. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2329. {
  2330. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2331. }
  2332. else
  2333. {
  2334. sprintf((char*)maxProfile.ValidTo, " ");
  2335. }
  2336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2337. {
  2338. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2339. }
  2340. else
  2341. {
  2342. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2343. }
  2344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2345. {
  2346. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2347. }
  2348. else
  2349. {
  2350. maxProfile.TransactionId = -1;
  2351. }
  2352. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2353. {
  2354. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2355. }
  2356. else
  2357. {
  2358. maxProfile.ChargingSchedule.Duration = 86400;
  2359. //isDurationNull = TRUE;
  2360. }
  2361. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2362. {
  2363. 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")));
  2364. }
  2365. else
  2366. {
  2367. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2368. }
  2369. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2370. {
  2371. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2372. }
  2373. else
  2374. {
  2375. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2376. }
  2377. }
  2378. }
  2379. }
  2380. else
  2381. {
  2382. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2383. {
  2384. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2385. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2386. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2387. }
  2388. if(maxProfile.ChargingProfileId == -1)
  2389. DEBUG_INFO("MaxProfile found.\n");
  2390. else
  2391. DEBUG_INFO("MaxProfile updated.\n");
  2392. // Required item
  2393. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2394. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2395. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2396. if(isUnitA)
  2397. {
  2398. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2399. 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++)
  2400. {
  2401. 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"));
  2402. 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?
  2403. 3:
  2404. 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")));
  2405. 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")));
  2406. }
  2407. }
  2408. else
  2409. {
  2410. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2411. 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++)
  2412. {
  2413. 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"));
  2414. 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?
  2415. 3:
  2416. 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")));
  2417. 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));
  2418. }
  2419. }
  2420. // Optional item
  2421. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2422. {
  2423. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2424. }
  2425. else
  2426. {
  2427. sprintf((char*)maxProfile.ValidFrom, " ");
  2428. }
  2429. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2430. {
  2431. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2432. }
  2433. else
  2434. {
  2435. sprintf((char*)maxProfile.ValidTo, " ");
  2436. }
  2437. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2438. {
  2439. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2440. }
  2441. else
  2442. {
  2443. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2444. }
  2445. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2446. {
  2447. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2448. }
  2449. else
  2450. {
  2451. maxProfile.TransactionId = -1;
  2452. }
  2453. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2454. {
  2455. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2456. }
  2457. else
  2458. {
  2459. maxProfile.ChargingSchedule.Duration = 86400;
  2460. //isDurationNull = TRUE;
  2461. }
  2462. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2463. {
  2464. 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")));
  2465. }
  2466. else
  2467. {
  2468. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2469. }
  2470. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2471. {
  2472. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2473. }
  2474. else
  2475. {
  2476. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2477. }
  2478. }
  2479. }
  2480. }
  2481. json_object_put(obj);
  2482. }
  2483. fclose(fp);
  2484. /*
  2485. if(maxProfile.ChargingProfileId !=-1)
  2486. {
  2487. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2488. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2489. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2490. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2491. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2492. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2493. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2494. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2495. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2496. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2497. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2498. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2499. {
  2500. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2501. {
  2502. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2503. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2504. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2505. }
  2506. }
  2507. }
  2508. else
  2509. DEBUG_INFO("MaxProfile not found.\n");
  2510. DEBUG_INFO("------------------------------------\n");*/
  2511. }
  2512. if(maxProfile.ChargingProfileId != -1)
  2513. {
  2514. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2515. {
  2516. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2517. {
  2518. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2519. 0:
  2520. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2521. }
  2522. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2523. {
  2524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2525. {
  2526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2527. 0:
  2528. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2529. if(idxPeriod > 0)
  2530. {
  2531. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2532. {
  2533. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2534. }
  2535. }
  2536. }
  2537. }
  2538. }
  2539. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2540. {
  2541. if(maxProfile.ChargingSchedule.Duration != -1)
  2542. {
  2543. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2544. }
  2545. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2546. {
  2547. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2548. {
  2549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2550. if(idxPeriod > 0)
  2551. {
  2552. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2553. {
  2554. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2555. }
  2556. }
  2557. }
  2558. }
  2559. }
  2560. else
  2561. {
  2562. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2563. {
  2564. if(maxProfile.ChargingSchedule.Duration != -1)
  2565. {
  2566. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2567. 0:
  2568. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2569. }
  2570. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2571. {
  2572. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2573. {
  2574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2575. 0:
  2576. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2577. if(idxPeriod > 0)
  2578. {
  2579. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2580. {
  2581. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2582. }
  2583. }
  2584. }
  2585. }
  2586. }
  2587. else
  2588. {
  2589. if(maxProfile.ChargingSchedule.Duration != -1)
  2590. {
  2591. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2592. 0:
  2593. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2594. }
  2595. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2596. {
  2597. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2598. {
  2599. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2600. 0:
  2601. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2602. if(idxPeriod > 0)
  2603. {
  2604. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2605. {
  2606. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2607. }
  2608. }
  2609. }
  2610. }
  2611. }
  2612. }
  2613. /*
  2614. DEBUG_INFO("MaxProfile after align.\n");
  2615. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2616. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2617. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2618. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2619. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2620. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2621. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2622. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2623. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2624. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2625. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2626. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2627. {
  2628. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2629. {
  2630. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2631. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2632. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2633. }
  2634. }
  2635. DEBUG_INFO("------------------------------------\n");*/
  2636. }
  2637. // Find each profile period quantity
  2638. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2639. {
  2640. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2641. limitMax = idx+1;
  2642. }
  2643. if(maxProfile.ChargingProfileId != -1)
  2644. {
  2645. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2646. {
  2647. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2648. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2649. (maxProfile.ChargingSchedule.Duration > 0))
  2650. {
  2651. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2652. {
  2653. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2654. compositePeriodIdx++;
  2655. }
  2656. else
  2657. {
  2658. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2659. }
  2660. }
  2661. }
  2662. }
  2663. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2664. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2665. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2666. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2667. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2668. {
  2669. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2670. {
  2671. compositeProfile.ChargingProfileId = 1;
  2672. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2673. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2674. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2675. }
  2676. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2677. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2678. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2679. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2680. }
  2681. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2682. if(line)
  2683. free(line);
  2684. }
  2685. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2686. {
  2687. FILE *fp;
  2688. char profileFileName[128];
  2689. char *line = NULL;
  2690. size_t len = 0;
  2691. time_t CurrentTime;
  2692. struct tm *tmComposite;
  2693. struct StructChargingProfile maxProfile;
  2694. struct StructChargingProfile defaultTxProfile;
  2695. struct StructChargingProfile txProfile;
  2696. struct StructChargingProfile compositeProfile;
  2697. struct StructChargingSchedulePeriod tmpPeriod;
  2698. uint8_t limitMax=0;
  2699. uint8_t limitDef=0;
  2700. uint8_t limitTx=0;
  2701. int compositePeriodIdx = 0;
  2702. CurrentTime = time(NULL);
  2703. tmComposite=localtime(&CurrentTime);
  2704. 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);
  2705. if(isUnitA)
  2706. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2707. else
  2708. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2709. compositeProfile.ChargingSchedule.Duration = durationReq;
  2710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2711. {
  2712. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2713. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2714. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2715. }
  2716. compositeProfile.ChargingProfileId = 0;
  2717. compositeProfile.StackLevel = 99 ;
  2718. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2719. maxProfile.ChargingProfileId = -1;
  2720. defaultTxProfile.ChargingProfileId = -1;
  2721. txProfile.ChargingProfileId = -1;
  2722. maxProfile.ChargingSchedule.Duration = -1;
  2723. defaultTxProfile.ChargingSchedule.Duration = -1;
  2724. txProfile.ChargingSchedule.Duration = -1;
  2725. system("rm -f /tmp/*.json");
  2726. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2727. /*
  2728. * Search valid charging profile
  2729. */
  2730. //DEBUG_INFO("====================================\n");
  2731. // Search tx profile
  2732. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2733. if((access(profileFileName, F_OK))!=-1)
  2734. {
  2735. fp = fopen(profileFileName, "r");
  2736. while(getline(&line, &len, fp) != -1)
  2737. {
  2738. json_object *obj = NULL;
  2739. obj = json_tokener_parse(line);
  2740. if(is_error(obj))
  2741. {
  2742. DEBUG_ERROR("Parse txProfile from file error.\n");
  2743. }
  2744. else
  2745. {
  2746. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2747. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2748. )
  2749. {
  2750. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2751. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2752. )
  2753. {
  2754. struct tm tmFrom, tmTo;
  2755. struct timeb tbFrom, tbTo;
  2756. 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) &&
  2757. (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))
  2758. {
  2759. tmFrom.tm_year -= 1900;
  2760. tmFrom.tm_mon -= 1;
  2761. tbFrom.time = mktime(&tmFrom);
  2762. tmTo.tm_year -= 1900;
  2763. tmTo.tm_mon -= 1;
  2764. tbTo.time = mktime(&tmTo);
  2765. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2766. {
  2767. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2768. {
  2769. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2770. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2771. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2772. }
  2773. if(txProfile.ChargingProfileId == -1)
  2774. DEBUG_INFO("TxProfile found.\n");
  2775. else
  2776. DEBUG_INFO("TxProfile updated.\n");
  2777. // Required item
  2778. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2779. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2780. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2781. if(isUnitA)
  2782. {
  2783. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2784. 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++)
  2785. {
  2786. 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"));
  2787. 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?
  2788. 3:
  2789. 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")));
  2790. 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")));
  2791. }
  2792. }
  2793. else
  2794. {
  2795. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2796. 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++)
  2797. {
  2798. 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"));
  2799. 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?
  2800. 3:
  2801. 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")));
  2802. 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));
  2803. }
  2804. }
  2805. // Optional item
  2806. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2807. {
  2808. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2809. }
  2810. else
  2811. {
  2812. sprintf((char*)txProfile.ValidFrom, " ");
  2813. }
  2814. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2815. {
  2816. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2817. }
  2818. else
  2819. {
  2820. sprintf((char*)txProfile.ValidTo, " ");
  2821. }
  2822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2823. {
  2824. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2825. }
  2826. else
  2827. {
  2828. sprintf((char*)txProfile.RecurrencyKind, " ");
  2829. }
  2830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2831. {
  2832. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2833. }
  2834. else
  2835. {
  2836. txProfile.TransactionId = -1;
  2837. }
  2838. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2839. {
  2840. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2841. }
  2842. else
  2843. {
  2844. txProfile.ChargingSchedule.Duration = 86400;
  2845. }
  2846. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2847. {
  2848. 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")));
  2849. }
  2850. else
  2851. {
  2852. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2853. }
  2854. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2855. {
  2856. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2857. }
  2858. else
  2859. {
  2860. txProfile.ChargingSchedule.MinChargingRate = -1;
  2861. }
  2862. }
  2863. }
  2864. }
  2865. else
  2866. {
  2867. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2868. {
  2869. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2870. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2871. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2872. }
  2873. if(txProfile.ChargingProfileId == -1)
  2874. DEBUG_INFO("TxProfile found.\n");
  2875. else
  2876. DEBUG_INFO("TxProfile updated.\n");
  2877. // Required item
  2878. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2879. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2880. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2881. if(isUnitA)
  2882. {
  2883. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2884. 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++)
  2885. {
  2886. 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"));
  2887. 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?
  2888. 3:
  2889. 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")));
  2890. 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")));
  2891. }
  2892. }
  2893. else
  2894. {
  2895. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2896. 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++)
  2897. {
  2898. 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"));
  2899. 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?
  2900. 3:
  2901. 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")));
  2902. 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));
  2903. }
  2904. }
  2905. // Optional item
  2906. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2907. {
  2908. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2909. }
  2910. else
  2911. {
  2912. sprintf((char*)txProfile.ValidFrom, " ");
  2913. }
  2914. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2915. {
  2916. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2917. }
  2918. else
  2919. {
  2920. sprintf((char*)txProfile.ValidTo, " ");
  2921. }
  2922. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2923. {
  2924. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2925. }
  2926. else
  2927. {
  2928. sprintf((char*)txProfile.RecurrencyKind, " ");
  2929. }
  2930. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2931. {
  2932. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2933. }
  2934. else
  2935. {
  2936. txProfile.TransactionId = -1;
  2937. }
  2938. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2939. {
  2940. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2941. }
  2942. else
  2943. {
  2944. txProfile.ChargingSchedule.Duration = 86400;
  2945. }
  2946. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2947. {
  2948. 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")));
  2949. }
  2950. else
  2951. {
  2952. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2953. }
  2954. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2955. {
  2956. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2957. }
  2958. else
  2959. {
  2960. txProfile.ChargingSchedule.MinChargingRate = -1;
  2961. }
  2962. }
  2963. }
  2964. }
  2965. json_object_put(obj);
  2966. }
  2967. fclose(fp);
  2968. /*
  2969. if(txProfile.ChargingProfileId != -1)
  2970. {
  2971. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2972. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2973. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2974. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2975. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2976. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2977. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2978. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2979. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2980. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2981. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2982. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2983. {
  2984. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2985. {
  2986. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2987. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2988. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2989. }
  2990. }
  2991. }
  2992. else
  2993. DEBUG_INFO("TxProfile not found.\n");*/
  2994. }
  2995. // Search default tx profile
  2996. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2997. if((access(profileFileName, F_OK))==-1)
  2998. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2999. if((access(profileFileName, F_OK))!=-1)
  3000. {
  3001. fp = fopen(profileFileName, "r");
  3002. while(getline(&line, &len, fp) != -1)
  3003. {
  3004. json_object *obj = NULL;
  3005. obj = json_tokener_parse(line);
  3006. if(is_error(obj))
  3007. {
  3008. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  3009. }
  3010. else
  3011. {
  3012. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  3013. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  3014. )
  3015. {
  3016. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3017. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3018. )
  3019. {
  3020. struct tm tmFrom, tmTo;
  3021. struct timeb tbFrom, tbTo;
  3022. 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) &&
  3023. (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))
  3024. {
  3025. tmFrom.tm_year -= 1900;
  3026. tmFrom.tm_mon -= 1;
  3027. tbFrom.time = mktime(&tmFrom);
  3028. tmTo.tm_year -= 1900;
  3029. tmTo.tm_mon -= 1;
  3030. tbTo.time = mktime(&tmTo);
  3031. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3032. {
  3033. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3034. {
  3035. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3036. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3037. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3038. }
  3039. if(defaultTxProfile.ChargingProfileId == -1)
  3040. DEBUG_INFO("TxDefaultProfile found.\n");
  3041. else
  3042. DEBUG_INFO("TxDefaultProfile updated.\n");
  3043. // Required item
  3044. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3045. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3046. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3047. if(isUnitA)
  3048. {
  3049. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3050. 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++)
  3051. {
  3052. 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"));
  3053. 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?
  3054. 3:
  3055. 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")));
  3056. 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")));
  3057. }
  3058. }
  3059. else
  3060. {
  3061. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3062. 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++)
  3063. {
  3064. 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"));
  3065. 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?
  3066. 3:
  3067. 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")));
  3068. 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));
  3069. }
  3070. }
  3071. // Optional item
  3072. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3073. {
  3074. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3075. }
  3076. else
  3077. {
  3078. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3079. }
  3080. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3081. {
  3082. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3083. }
  3084. else
  3085. {
  3086. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3087. }
  3088. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3089. {
  3090. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3091. }
  3092. else
  3093. {
  3094. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3095. }
  3096. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3097. {
  3098. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3099. }
  3100. else
  3101. {
  3102. defaultTxProfile.TransactionId = -1;
  3103. }
  3104. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3105. {
  3106. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3107. }
  3108. else
  3109. {
  3110. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3111. }
  3112. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3113. {
  3114. 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")));
  3115. }
  3116. else
  3117. {
  3118. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3119. }
  3120. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3121. {
  3122. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3123. }
  3124. else
  3125. {
  3126. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3127. }
  3128. }
  3129. }
  3130. }
  3131. else
  3132. {
  3133. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3134. {
  3135. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3136. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3137. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3138. }
  3139. if(defaultTxProfile.ChargingProfileId == -1)
  3140. DEBUG_INFO("TxDefaultProfile found.\n");
  3141. else
  3142. DEBUG_INFO("TxDefaultProfile updated.\n");
  3143. // Required item
  3144. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3145. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3146. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3147. if(isUnitA)
  3148. {
  3149. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3150. 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++)
  3151. {
  3152. 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"));
  3153. 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?
  3154. 3:
  3155. 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")));
  3156. 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")));
  3157. }
  3158. }
  3159. else
  3160. {
  3161. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3162. 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++)
  3163. {
  3164. 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"));
  3165. 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?
  3166. 3:
  3167. 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")));
  3168. 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));
  3169. }
  3170. }
  3171. // Optional item
  3172. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3173. {
  3174. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3175. }
  3176. else
  3177. {
  3178. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3179. }
  3180. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3181. {
  3182. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3183. }
  3184. else
  3185. {
  3186. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3187. }
  3188. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3189. {
  3190. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3191. }
  3192. else
  3193. {
  3194. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3195. }
  3196. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3197. {
  3198. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3199. }
  3200. else
  3201. {
  3202. defaultTxProfile.TransactionId = -1;
  3203. }
  3204. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3205. {
  3206. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3207. }
  3208. else
  3209. {
  3210. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3211. }
  3212. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3213. {
  3214. 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")));
  3215. }
  3216. else
  3217. {
  3218. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3219. }
  3220. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3221. {
  3222. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3223. }
  3224. else
  3225. {
  3226. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3227. }
  3228. }
  3229. }
  3230. }
  3231. json_object_put(obj);
  3232. }
  3233. fclose(fp);
  3234. /*
  3235. if(defaultTxProfile.ChargingProfileId != -1)
  3236. {
  3237. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3238. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3239. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3240. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3241. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3242. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3243. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3244. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3245. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3246. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3247. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3248. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3249. {
  3250. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3251. {
  3252. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3253. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3254. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3255. }
  3256. }
  3257. }
  3258. else
  3259. DEBUG_INFO("TxDefaultProfile not found.\n");
  3260. DEBUG_INFO("------------------------------------\n");*/
  3261. }
  3262. // Search max profile
  3263. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3264. if((access(profileFileName, F_OK))!=-1)
  3265. {
  3266. fp = fopen(profileFileName, "r");
  3267. while(getline(&line, &len, fp) != -1)
  3268. {
  3269. json_object *obj = NULL;
  3270. obj = json_tokener_parse(line);
  3271. if(is_error(obj))
  3272. {
  3273. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3274. }
  3275. else
  3276. {
  3277. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3278. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3279. )
  3280. {
  3281. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3282. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3283. )
  3284. {
  3285. struct tm tmFrom, tmTo;
  3286. struct timeb tbFrom, tbTo;
  3287. 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) &&
  3288. (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))
  3289. {
  3290. tmFrom.tm_year -= 1900;
  3291. tmFrom.tm_mon -= 1;
  3292. tbFrom.time = mktime(&tmFrom);
  3293. tmTo.tm_year -= 1900;
  3294. tmTo.tm_mon -= 1;
  3295. tbTo.time = mktime(&tmTo);
  3296. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3297. {
  3298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3299. {
  3300. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3301. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3303. }
  3304. if(maxProfile.ChargingProfileId == -1)
  3305. DEBUG_INFO("MaxProfile found.\n");
  3306. else
  3307. DEBUG_INFO("MaxProfile updated.\n");
  3308. // Required item
  3309. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3310. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3311. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3312. if(isUnitA)
  3313. {
  3314. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3315. 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++)
  3316. {
  3317. 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"));
  3318. 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?
  3319. 3:
  3320. 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")));
  3321. 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")));
  3322. }
  3323. }
  3324. else
  3325. {
  3326. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3327. 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++)
  3328. {
  3329. 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"));
  3330. 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?
  3331. 3:
  3332. 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")));
  3333. 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));
  3334. }
  3335. }
  3336. // Optional item
  3337. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3338. {
  3339. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3340. }
  3341. else
  3342. {
  3343. sprintf((char*)maxProfile.ValidFrom, " ");
  3344. }
  3345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3346. {
  3347. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3348. }
  3349. else
  3350. {
  3351. sprintf((char*)maxProfile.ValidTo, " ");
  3352. }
  3353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3354. {
  3355. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3356. }
  3357. else
  3358. {
  3359. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3360. }
  3361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3362. {
  3363. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3364. }
  3365. else
  3366. {
  3367. maxProfile.TransactionId = -1;
  3368. }
  3369. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3370. {
  3371. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3372. }
  3373. else
  3374. {
  3375. maxProfile.ChargingSchedule.Duration = 86400;
  3376. }
  3377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3378. {
  3379. 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")));
  3380. }
  3381. else
  3382. {
  3383. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3384. }
  3385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3386. {
  3387. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3388. }
  3389. else
  3390. {
  3391. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3392. }
  3393. }
  3394. }
  3395. }
  3396. else
  3397. {
  3398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3399. {
  3400. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3401. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3403. }
  3404. if(maxProfile.ChargingProfileId == -1)
  3405. DEBUG_INFO("MaxProfile found.\n");
  3406. else
  3407. DEBUG_INFO("MaxProfile updated.\n");
  3408. // Required item
  3409. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3410. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3411. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3412. if(isUnitA)
  3413. {
  3414. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3415. 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++)
  3416. {
  3417. 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"));
  3418. 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?
  3419. 3:
  3420. 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")));
  3421. 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")));
  3422. }
  3423. }
  3424. else
  3425. {
  3426. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3427. 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++)
  3428. {
  3429. 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"));
  3430. 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?
  3431. 3:
  3432. 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")));
  3433. 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));
  3434. }
  3435. }
  3436. // Optional item
  3437. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3438. {
  3439. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3440. }
  3441. else
  3442. {
  3443. sprintf((char*)maxProfile.ValidFrom, " ");
  3444. }
  3445. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3446. {
  3447. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3448. }
  3449. else
  3450. {
  3451. sprintf((char*)maxProfile.ValidTo, " ");
  3452. }
  3453. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3454. {
  3455. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3456. }
  3457. else
  3458. {
  3459. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3460. }
  3461. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3462. {
  3463. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3464. }
  3465. else
  3466. {
  3467. maxProfile.TransactionId = -1;
  3468. }
  3469. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3470. {
  3471. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3472. }
  3473. else
  3474. {
  3475. maxProfile.ChargingSchedule.Duration = 86400;
  3476. }
  3477. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3478. {
  3479. 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")));
  3480. }
  3481. else
  3482. {
  3483. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3484. }
  3485. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3486. {
  3487. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3488. }
  3489. else
  3490. {
  3491. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3492. }
  3493. }
  3494. }
  3495. }
  3496. json_object_put(obj);
  3497. }
  3498. fclose(fp);
  3499. /*
  3500. if(maxProfile.ChargingProfileId !=-1)
  3501. {
  3502. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3503. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3504. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3505. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3506. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3507. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3508. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3509. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3510. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3511. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3512. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3513. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3514. {
  3515. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3516. {
  3517. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3518. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3519. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3520. }
  3521. }
  3522. }
  3523. else
  3524. DEBUG_INFO("MaxProfile not found.\n");
  3525. DEBUG_INFO("------------------------------------\n");*/
  3526. }
  3527. /*
  3528. * Align found profile start schedule & periods
  3529. */
  3530. //DEBUG_INFO("====================================\n");
  3531. /*
  3532. // For local test usage, force modify found profile start schedule info
  3533. 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);
  3534. 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);
  3535. 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);
  3536. */
  3537. if(txProfile.ChargingProfileId != -1)
  3538. {
  3539. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3540. {
  3541. if(txProfile.ChargingSchedule.Duration != -1)
  3542. {
  3543. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3544. 0:
  3545. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3546. }
  3547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3548. {
  3549. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3550. {
  3551. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3552. 0:
  3553. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3554. if(idxPeriod > 0)
  3555. {
  3556. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3557. {
  3558. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3559. }
  3560. }
  3561. }
  3562. }
  3563. }
  3564. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3565. {
  3566. if(txProfile.ChargingSchedule.Duration != -1)
  3567. {
  3568. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3569. 0:
  3570. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3571. }
  3572. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3573. {
  3574. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3575. {
  3576. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3577. 0:
  3578. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3579. if(idxPeriod > 0)
  3580. {
  3581. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3582. {
  3583. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3584. }
  3585. }
  3586. }
  3587. }
  3588. }
  3589. else
  3590. {
  3591. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3592. {
  3593. if(txProfile.ChargingSchedule.Duration != -1)
  3594. {
  3595. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3596. 0:
  3597. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3598. }
  3599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3600. {
  3601. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3602. {
  3603. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3604. 0:
  3605. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3606. if(idxPeriod > 0)
  3607. {
  3608. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3609. {
  3610. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3611. }
  3612. }
  3613. }
  3614. }
  3615. }
  3616. else
  3617. {
  3618. if(txProfile.ChargingSchedule.Duration != -1)
  3619. {
  3620. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3621. 0:
  3622. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3623. }
  3624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3625. {
  3626. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3627. {
  3628. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3629. 0:
  3630. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3631. if(idxPeriod > 0)
  3632. {
  3633. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3634. {
  3635. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3636. }
  3637. }
  3638. }
  3639. }
  3640. }
  3641. }
  3642. /*
  3643. DEBUG_INFO("txProfile after align.\n");
  3644. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3645. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3646. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3647. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3648. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3649. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3650. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3651. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3652. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3653. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3654. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3655. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3656. {
  3657. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3658. {
  3659. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3660. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3661. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3662. }
  3663. }*/
  3664. }
  3665. if(defaultTxProfile.ChargingProfileId != -1)
  3666. {
  3667. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3668. {
  3669. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3670. {
  3671. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3672. 0:
  3673. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3674. }
  3675. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3676. {
  3677. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3678. {
  3679. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3680. 0:
  3681. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3682. if(idxPeriod > 0)
  3683. {
  3684. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3685. {
  3686. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3687. }
  3688. }
  3689. }
  3690. }
  3691. }
  3692. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3693. {
  3694. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3695. {
  3696. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3697. 0:
  3698. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3699. }
  3700. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3701. {
  3702. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3703. {
  3704. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3705. 0:
  3706. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3707. if(idxPeriod > 0)
  3708. {
  3709. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3710. {
  3711. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3712. }
  3713. }
  3714. }
  3715. }
  3716. }
  3717. else
  3718. {
  3719. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3720. {
  3721. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3722. {
  3723. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3724. 0:
  3725. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3726. }
  3727. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3728. {
  3729. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3730. {
  3731. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3732. 0:
  3733. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3734. if(idxPeriod > 0)
  3735. {
  3736. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3737. {
  3738. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3739. }
  3740. }
  3741. }
  3742. }
  3743. }
  3744. else
  3745. {
  3746. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3747. {
  3748. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3749. 0:
  3750. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3751. }
  3752. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3753. {
  3754. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3755. {
  3756. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3757. 0:
  3758. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3759. if(idxPeriod > 0)
  3760. {
  3761. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3762. {
  3763. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3764. }
  3765. }
  3766. }
  3767. }
  3768. }
  3769. }
  3770. /*
  3771. DEBUG_INFO("defaultTxProfile after align.\n");
  3772. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3773. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3774. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3775. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3776. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3777. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3778. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3779. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3780. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3781. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3782. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3783. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3784. {
  3785. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3786. {
  3787. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3788. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3789. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3790. }
  3791. }
  3792. DEBUG_INFO("------------------------------------\n");*/
  3793. }
  3794. if(maxProfile.ChargingProfileId != -1)
  3795. {
  3796. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3797. {
  3798. if(maxProfile.ChargingSchedule.Duration != -1)
  3799. {
  3800. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3801. 0:
  3802. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3803. }
  3804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3805. {
  3806. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3807. {
  3808. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3809. 0:
  3810. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3811. if(idxPeriod > 0)
  3812. {
  3813. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3814. {
  3815. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3816. }
  3817. }
  3818. }
  3819. }
  3820. }
  3821. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3822. {
  3823. if(maxProfile.ChargingSchedule.Duration != -1)
  3824. {
  3825. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3826. 0:
  3827. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3828. }
  3829. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3830. {
  3831. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3832. {
  3833. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3834. 0:
  3835. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3836. if(idxPeriod > 0)
  3837. {
  3838. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3839. {
  3840. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3841. }
  3842. }
  3843. }
  3844. }
  3845. }
  3846. else
  3847. {
  3848. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3849. {
  3850. if(maxProfile.ChargingSchedule.Duration != -1)
  3851. {
  3852. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3853. 0:
  3854. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3855. }
  3856. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3857. {
  3858. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3859. {
  3860. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3861. 0:
  3862. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3863. if(idxPeriod > 0)
  3864. {
  3865. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3866. {
  3867. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3868. }
  3869. }
  3870. }
  3871. }
  3872. }
  3873. else
  3874. {
  3875. if(maxProfile.ChargingSchedule.Duration != -1)
  3876. {
  3877. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3878. 0:
  3879. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3880. }
  3881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3882. {
  3883. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3884. {
  3885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3886. 0:
  3887. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3888. if(idxPeriod > 0)
  3889. {
  3890. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3891. {
  3892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3893. }
  3894. }
  3895. }
  3896. }
  3897. }
  3898. }
  3899. /*
  3900. DEBUG_INFO("MaxProfile after align.\n");
  3901. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3902. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3903. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3904. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3905. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3906. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3907. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3908. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3909. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3910. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3911. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3912. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3913. {
  3914. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3915. {
  3916. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3917. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3918. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3919. }
  3920. }
  3921. DEBUG_INFO("------------------------------------\n");*/
  3922. }
  3923. /*
  3924. * Merge to composite schedule
  3925. */
  3926. //DEBUG_INFO("====================================\n");
  3927. // Find each profile period quantity
  3928. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3929. {
  3930. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3931. limitMax = idx+1;
  3932. }
  3933. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3934. {
  3935. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3936. limitDef = idx+1;
  3937. }
  3938. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3939. {
  3940. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3941. limitTx = idx+1;
  3942. }
  3943. // TxProfile found, composite schedule based on it
  3944. if(txProfile.ChargingProfileId != -1)
  3945. {
  3946. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3947. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3948. {
  3949. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3950. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3951. (txProfile.ChargingSchedule.Duration > 0))
  3952. {
  3953. if(maxProfile.ChargingProfileId != -1)
  3954. {
  3955. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3956. {
  3957. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3958. {
  3959. if((maxProfile.ChargingSchedule.Duration > 0))
  3960. {
  3961. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3962. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3963. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3964. }
  3965. else
  3966. {
  3967. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3968. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3969. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3970. }
  3971. }
  3972. if(idxMaxPeriod == (limitMax-1))
  3973. {
  3974. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3975. {
  3976. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3977. {
  3978. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3979. compositePeriodIdx++;
  3980. }
  3981. else
  3982. {
  3983. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3984. }
  3985. }
  3986. }
  3987. }
  3988. }
  3989. else
  3990. {
  3991. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3992. {
  3993. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3994. compositePeriodIdx++;
  3995. }
  3996. else
  3997. {
  3998. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3999. }
  4000. }
  4001. }
  4002. if(idxTxPeriod == (limitTx-1))
  4003. {
  4004. if(defaultTxProfile.ChargingProfileId != -1)
  4005. {
  4006. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  4007. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4008. {
  4009. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  4010. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  4011. (defaultTxProfile.ChargingSchedule.Duration>0))
  4012. {
  4013. if(maxProfile.ChargingProfileId != -1)
  4014. {
  4015. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4016. {
  4017. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4018. {
  4019. if((maxProfile.ChargingSchedule.Duration > 0))
  4020. {
  4021. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4022. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4023. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  4024. }
  4025. else
  4026. {
  4027. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4028. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4029. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4030. }
  4031. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4032. {
  4033. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4034. {
  4035. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4036. compositePeriodIdx++;
  4037. }
  4038. else
  4039. {
  4040. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4041. }
  4042. }
  4043. // Delete duplicate period
  4044. if(compositePeriodIdx > 1)
  4045. {
  4046. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4047. {
  4048. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4049. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4050. compositePeriodIdx -= 1;
  4051. }
  4052. }
  4053. }
  4054. else
  4055. {
  4056. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4057. {
  4058. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4059. compositePeriodIdx++;
  4060. }
  4061. else
  4062. {
  4063. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4064. }
  4065. break;
  4066. }
  4067. }
  4068. }
  4069. else
  4070. {
  4071. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4072. {
  4073. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4074. compositePeriodIdx++;
  4075. }
  4076. else
  4077. {
  4078. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4079. }
  4080. }
  4081. }
  4082. }
  4083. }
  4084. }
  4085. }
  4086. }
  4087. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4088. else if(defaultTxProfile.ChargingProfileId != -1)
  4089. {
  4090. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  4091. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4092. {
  4093. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  4094. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  4095. (defaultTxProfile.ChargingSchedule.Duration > 0))
  4096. {
  4097. if(maxProfile.ChargingProfileId != -1)
  4098. {
  4099. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4100. {
  4101. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4102. {
  4103. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4104. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4105. if((maxProfile.ChargingSchedule.Duration > 0))
  4106. {
  4107. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  4108. }
  4109. else
  4110. {
  4111. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4112. }
  4113. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4114. {
  4115. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4116. {
  4117. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4118. compositePeriodIdx++;
  4119. }
  4120. else
  4121. {
  4122. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4123. }
  4124. }
  4125. // Delete duplicate period
  4126. if(compositePeriodIdx > 1)
  4127. {
  4128. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4129. {
  4130. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4131. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4132. compositePeriodIdx -= 1;
  4133. }
  4134. }
  4135. }
  4136. else
  4137. {
  4138. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4139. {
  4140. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4141. compositePeriodIdx++;
  4142. }
  4143. else
  4144. {
  4145. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4146. }
  4147. break;
  4148. }
  4149. }
  4150. }
  4151. else
  4152. {
  4153. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4154. {
  4155. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4156. compositePeriodIdx++;
  4157. }
  4158. else
  4159. {
  4160. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4161. }
  4162. }
  4163. }
  4164. }
  4165. }
  4166. // Fill other period by MaxProfile
  4167. if(maxProfile.ChargingProfileId != -1)
  4168. {
  4169. if(compositePeriodIdx==0)
  4170. {
  4171. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4172. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  4173. {
  4174. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4175. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4176. (maxProfile.ChargingSchedule.Duration > 0))
  4177. {
  4178. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4179. {
  4180. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4181. compositePeriodIdx++;
  4182. }
  4183. else
  4184. {
  4185. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4186. }
  4187. }
  4188. }
  4189. }
  4190. else
  4191. {
  4192. int lastCompositePeriodIdx = compositePeriodIdx;
  4193. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4194. {
  4195. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4196. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4197. (maxProfile.ChargingSchedule.Duration > 0))
  4198. {
  4199. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  4200. {
  4201. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit) &&
  4202. (compositeProfile.ChargingSchedule.Duration >= durationReq))
  4203. {
  4204. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4205. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4206. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  4207. }
  4208. else
  4209. {
  4210. if(maxProfile.ChargingSchedule.Duration > compositeProfile.ChargingSchedule.Duration)
  4211. {
  4212. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod <= compositeProfile.ChargingSchedule.Duration)
  4213. tmpPeriod.StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4214. else
  4215. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4216. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4217. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  4218. }
  4219. }
  4220. }
  4221. if(tmpPeriod.Limit != -1)
  4222. {
  4223. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  4224. {
  4225. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  4226. {
  4227. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4228. compositePeriodIdx++;
  4229. }
  4230. else
  4231. {
  4232. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4233. }
  4234. }
  4235. // Delete duplicate period
  4236. if(compositePeriodIdx > 1)
  4237. {
  4238. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4239. {
  4240. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4241. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4242. compositePeriodIdx -= 1;
  4243. }
  4244. }
  4245. }
  4246. }
  4247. }
  4248. if((maxProfile.ChargingSchedule.Duration > durationReq) && (maxProfile.ChargingSchedule.Duration > compositeProfile.ChargingSchedule.Duration))
  4249. {
  4250. compositeProfile.ChargingSchedule.Duration = durationReq;
  4251. }
  4252. else if(maxProfile.ChargingSchedule.Duration > compositeProfile.ChargingSchedule.Duration)
  4253. {
  4254. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4255. }
  4256. }
  4257. }
  4258. if(compositeProfile.ChargingSchedule.Duration < durationReq)
  4259. {
  4260. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4261. {
  4262. if((idxPeriod >= 0) && (compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1))
  4263. {
  4264. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4265. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  4266. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].NumberPhases;
  4267. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  4268. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4269. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4270. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4271. DEBUG_INFO("------------------------------------------------\n");
  4272. break;
  4273. }
  4274. }
  4275. }
  4276. compositeProfile.ChargingSchedule.Duration = durationReq;
  4277. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4278. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4279. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4280. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4282. {
  4283. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4284. {
  4285. compositeProfile.ChargingProfileId = 1;
  4286. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4287. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4288. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4289. }
  4290. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4291. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4292. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4293. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4294. }
  4295. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4296. if(line)
  4297. free(line);
  4298. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4299. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4300. }
  4301. //==========================================
  4302. // Init all share memory
  4303. //==========================================
  4304. int InitShareMemory()
  4305. {
  4306. int result = PASS;
  4307. int MeterSMId;
  4308. //creat ShmSysConfigAndInfo
  4309. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4310. {
  4311. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4312. result = FAIL;
  4313. }
  4314. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4315. {
  4316. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4317. result = FAIL;
  4318. }
  4319. else
  4320. {}
  4321. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4322. {
  4323. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4324. result = FAIL;
  4325. }
  4326. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4327. {
  4328. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4329. result = FAIL;
  4330. }
  4331. else
  4332. {}
  4333. //creat ShmPsuData
  4334. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4335. {
  4336. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4337. result = FAIL;
  4338. }
  4339. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4340. {
  4341. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4342. result = FAIL;
  4343. }
  4344. else
  4345. {}
  4346. //creat ShmOCPP16Data
  4347. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4348. {
  4349. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4350. result = FAIL;
  4351. }
  4352. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4353. {
  4354. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4355. result = FAIL;
  4356. }
  4357. else
  4358. {}
  4359. /****************************** For Initial Settings************************************************/
  4360. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4361. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4362. // allocate Configuration memory address
  4363. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4364. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4365. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4366. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4367. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4368. //offline MeterValue Interval
  4369. TempMeterValueInterval = 0;
  4370. return result;
  4371. }
  4372. int ProcessShareMemory()
  4373. {
  4374. int result = PASS;
  4375. if(InitShareMemory() == FAIL)
  4376. {
  4377. DEBUG_ERROR("InitShareMemory NG\n");
  4378. if(ShmStatusCodeData!=NULL)
  4379. {
  4380. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4381. }
  4382. result = FAIL;
  4383. }
  4384. // Model name parsing
  4385. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4386. {
  4387. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4388. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4389. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4390. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4391. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  4392. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  4393. ) // 'D' means DC
  4394. {
  4395. // DO series
  4396. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4397. {
  4398. gunTotalNumber += 1;
  4399. gunType[gun_index] = GUN_TYPE_DO;
  4400. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4401. {
  4402. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4403. {
  4404. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4405. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4406. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4407. }
  4408. }
  4409. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4410. {
  4411. case Gun_Type_Chademo:
  4412. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4413. break;
  4414. case Gun_Type_CCS_2:
  4415. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4416. break;
  4417. case Gun_Type_GB:
  4418. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4419. break;
  4420. case Gun_Type_AC:
  4421. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4422. break;
  4423. default:
  4424. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4425. break;
  4426. }
  4427. }
  4428. }
  4429. else
  4430. {
  4431. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4432. {
  4433. gunTotalNumber += 1;
  4434. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4435. {
  4436. case Gun_Type_Chademo:
  4437. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4438. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4439. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4440. {
  4441. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4442. {
  4443. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4444. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4445. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4446. }
  4447. }
  4448. break;
  4449. case Gun_Type_CCS_2:
  4450. gunType[gun_index] = GUN_TYPE_CCS;
  4451. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4452. for (int index = 0; index < CCS_QUANTITY; index++)
  4453. {
  4454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4455. {
  4456. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4457. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4458. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4459. }
  4460. }
  4461. break;
  4462. case Gun_Type_GB:
  4463. gunType[gun_index] = GUN_TYPE_GBT;
  4464. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4465. for (int index = 0; index < GB_QUANTITY; index++)
  4466. {
  4467. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4468. {
  4469. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4470. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4471. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4472. }
  4473. }
  4474. break;
  4475. case Gun_Type_AC:
  4476. gunType[gun_index] = GUN_TYPE_AC;
  4477. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4478. for (int index = 0; index < AC_QUANTITY; index++)
  4479. {
  4480. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4481. {
  4482. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4483. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4484. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4485. }
  4486. }
  4487. break;
  4488. default:
  4489. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4490. break;
  4491. }
  4492. }
  4493. }
  4494. }
  4495. else
  4496. {
  4497. DEBUG_ERROR("Model name parsing fail.\n");
  4498. result = FAIL;
  4499. }
  4500. if(result != PASS)sleep(5);
  4501. return result;
  4502. }
  4503. void checkRemoteStart(uint8_t connectorIdInt)
  4504. {
  4505. uint8_t tempIndex;
  4506. int result = PASS;
  4507. char cmdBuf[512];
  4508. //check Transaction active
  4509. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4510. {
  4511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4512. {
  4513. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4514. }
  4515. else
  4516. {
  4517. tempIndex = connectorIdInt -1;
  4518. }
  4519. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4520. {
  4521. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4522. {
  4523. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4524. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4525. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4526. {
  4527. //Reserved
  4528. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4529. }
  4530. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4531. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4532. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4533. {
  4534. //Reserved
  4535. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4536. result = FAIL;
  4537. goto end;
  4538. }
  4539. else
  4540. {
  4541. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4542. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4543. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4544. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4545. {
  4546. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4547. result = FAIL;
  4548. goto end;
  4549. }
  4550. }//END FOR ELSE
  4551. }
  4552. }// END FOR CHAdeMO_QUANTITY
  4553. }
  4554. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4555. {
  4556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4557. {
  4558. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4559. }
  4560. else
  4561. {
  4562. tempIndex = connectorIdInt -1;
  4563. }
  4564. for (int index = 0; index < CCS_QUANTITY; index++)
  4565. {
  4566. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4567. {
  4568. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4569. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4570. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4571. {
  4572. //Reserved
  4573. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4574. }
  4575. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4576. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4577. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4578. {
  4579. //Reserved
  4580. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4581. result = FAIL;
  4582. goto end;
  4583. }
  4584. else
  4585. {
  4586. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4587. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4588. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4589. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4590. {
  4591. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4592. result = FAIL;
  4593. goto end;
  4594. }
  4595. }// END FOR ELSE
  4596. }
  4597. }// END FOR CCS_QUANTITY
  4598. }
  4599. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4600. {
  4601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4602. {
  4603. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4604. }
  4605. else
  4606. {
  4607. tempIndex = connectorIdInt -1;
  4608. }
  4609. for (int index = 0; index < GB_QUANTITY; index++)
  4610. {
  4611. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4612. {
  4613. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4614. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4615. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4616. {
  4617. //Reserved
  4618. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4619. }
  4620. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4621. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4622. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4623. {
  4624. //Reserved
  4625. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4626. result = FAIL;
  4627. goto end;
  4628. }
  4629. else
  4630. {
  4631. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4632. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4633. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4634. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4635. {
  4636. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4637. result = FAIL;
  4638. goto end;
  4639. }
  4640. }// END FOR ELSE
  4641. }
  4642. } // END FOR GB_QUANTITY
  4643. }
  4644. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4645. {
  4646. tempIndex = connectorIdInt -1;
  4647. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4648. {
  4649. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4650. {
  4651. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4652. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4653. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4654. {
  4655. //Reserved
  4656. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4657. }
  4658. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4659. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4660. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4661. {
  4662. //Reserved
  4663. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4664. result = FAIL;
  4665. goto end;
  4666. }
  4667. else
  4668. {
  4669. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4670. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4671. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4672. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4673. {
  4674. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4675. result = FAIL;
  4676. goto end;
  4677. }
  4678. }// END FOR ELSE
  4679. }
  4680. } // END FOR GB_QUANTITY
  4681. }
  4682. else
  4683. {
  4684. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4685. {
  4686. tempIndex = 2;
  4687. }
  4688. else
  4689. {
  4690. tempIndex = connectorIdInt -1;
  4691. }
  4692. for (int index = 0; index < AC_QUANTITY; index++)
  4693. {
  4694. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4695. {
  4696. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4697. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4698. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4699. {
  4700. //Reserved
  4701. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4702. }
  4703. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4704. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4705. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4706. {
  4707. //Reserved
  4708. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4709. result = FAIL;
  4710. goto end;
  4711. }
  4712. else
  4713. {
  4714. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4715. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4716. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4717. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4718. {
  4719. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4720. result = FAIL;
  4721. goto end;
  4722. }
  4723. }//END FOR ELSE
  4724. }
  4725. }// END FOR AC_QUANTITY
  4726. }
  4727. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4728. {
  4729. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4730. {
  4731. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4732. {
  4733. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4734. system(cmdBuf);
  4735. }
  4736. }
  4737. else
  4738. {
  4739. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4740. result = FAIL;
  4741. }
  4742. }
  4743. end:
  4744. if(result == PASS)
  4745. {
  4746. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4747. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4748. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4749. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4750. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4751. }
  4752. }
  4753. int isConnector0Unavailable()
  4754. {
  4755. uint8_t result = YES;
  4756. uint8_t tempIndex;
  4757. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4758. {
  4759. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4760. {
  4761. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4762. {
  4763. tempIndex = ((gun_index==2) ? 1: 0);
  4764. }
  4765. else
  4766. {
  4767. tempIndex = gun_index;
  4768. }
  4769. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4770. {
  4771. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4772. {
  4773. 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))
  4774. {
  4775. result = NO;
  4776. }
  4777. }
  4778. }
  4779. }
  4780. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4781. {
  4782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4783. {
  4784. tempIndex = ((gun_index==2) ? 1: 0);
  4785. }
  4786. else
  4787. {
  4788. tempIndex = gun_index;
  4789. }
  4790. for (int index = 0; index < CCS_QUANTITY; index++)
  4791. {
  4792. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4793. {
  4794. 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))
  4795. {
  4796. result = NO;
  4797. }
  4798. }
  4799. }
  4800. }
  4801. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4802. {
  4803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4804. {
  4805. tempIndex = ((gun_index==2) ? 1: 0);
  4806. }
  4807. else
  4808. {
  4809. tempIndex = gun_index;
  4810. }
  4811. for (int index = 0; index < GB_QUANTITY; index++)
  4812. {
  4813. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4814. {
  4815. 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))
  4816. {
  4817. result = NO;
  4818. }
  4819. }
  4820. }
  4821. }
  4822. else if(gunType[gun_index] == GUN_TYPE_DO)
  4823. {
  4824. tempIndex = gun_index;
  4825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4826. {
  4827. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4828. {
  4829. 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))
  4830. {
  4831. result = NO;
  4832. }
  4833. }
  4834. }
  4835. }
  4836. else
  4837. {
  4838. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4839. {
  4840. tempIndex = 2;
  4841. }
  4842. else
  4843. {
  4844. tempIndex = gun_index;
  4845. }
  4846. for (int index = 0; index < AC_QUANTITY; index++)
  4847. {
  4848. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4849. {
  4850. 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))
  4851. {
  4852. result = NO;
  4853. }
  4854. }
  4855. }// END
  4856. }
  4857. }
  4858. return result;
  4859. }
  4860. void CheckSystemValue(void)
  4861. {
  4862. char filenmae[100]={0};
  4863. char str[100]={0};
  4864. int tempIndex = 0;
  4865. //===============================
  4866. // send Heartbeat
  4867. //===============================
  4868. if((server_sign == TRUE) && (HeartBeatWaitTime > 0) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4869. {
  4870. //parameter for test
  4871. if(HeartBeatWithNOResponse < 1)
  4872. sendHeartbeatRequest(0);
  4873. //===========================
  4874. // Reset Waiting Time
  4875. //===========================
  4876. HeartBeatWithNOResponse += 1;
  4877. }
  4878. //===============================
  4879. // Tcci credit deduct report
  4880. //===============================
  4881. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4882. {
  4883. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4884. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4885. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4886. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4887. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4888. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4889. }
  4890. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4891. {
  4892. OCPP_query_deduct_info();
  4893. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4894. }
  4895. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4896. {
  4897. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4898. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4899. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4900. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4901. }
  4902. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4903. {
  4904. OCPP_query_occupancyDeduct_info();
  4905. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4906. }
  4907. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4908. {
  4909. // ClockAlign MeterValue
  4910. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4911. {
  4912. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4913. {
  4914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4915. {
  4916. tempIndex = ((gun_index==2) ? 1: 0);
  4917. }
  4918. else
  4919. {
  4920. tempIndex = gun_index;
  4921. }
  4922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4923. {
  4924. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4925. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4926. {
  4927. reqClockAlignMeter[gun_index] = 1;
  4928. }
  4929. }// End for CHAdeMO
  4930. }
  4931. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4932. {
  4933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4934. {
  4935. tempIndex = ((gun_index==2) ? 1: 0);
  4936. }
  4937. else
  4938. {
  4939. tempIndex = gun_index;
  4940. }
  4941. for (int index = 0; index < CCS_QUANTITY; index++)
  4942. {
  4943. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4944. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4945. {
  4946. reqClockAlignMeter[gun_index] = 1;
  4947. }
  4948. } // End for CCS
  4949. }
  4950. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4951. {
  4952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4953. {
  4954. tempIndex = ((gun_index==2) ? 1: 0);
  4955. }
  4956. else
  4957. {
  4958. tempIndex = gun_index;
  4959. }
  4960. for (int index = 0; index < GB_QUANTITY; index++)
  4961. {
  4962. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4963. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4964. {
  4965. reqClockAlignMeter[gun_index] = 1;
  4966. }
  4967. }// End for GB
  4968. }
  4969. else if(gunType[gun_index] == GUN_TYPE_DO)
  4970. {
  4971. tempIndex = gun_index;
  4972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4973. {
  4974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4975. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4976. {
  4977. reqClockAlignMeter[gun_index] = 1;
  4978. }
  4979. }
  4980. }
  4981. else
  4982. {
  4983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4984. {
  4985. tempIndex = 2;
  4986. }
  4987. else
  4988. {
  4989. tempIndex = gun_index;
  4990. }
  4991. for (int index = 0; index < AC_QUANTITY; index++)
  4992. {
  4993. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4994. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4995. {
  4996. reqClockAlignMeter[gun_index] = 1;
  4997. }
  4998. }//End for AC
  4999. }
  5000. }
  5001. }
  5002. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  5003. {
  5004. //==========================================
  5005. // Check remote start without connector id
  5006. //==========================================
  5007. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  5008. {
  5009. int connectorIdInt = -1;
  5010. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  5011. {
  5012. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  5013. {
  5014. connectorIdInt = (gun_index+1);
  5015. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  5016. checkRemoteStart(connectorIdInt);
  5017. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  5018. break;
  5019. }
  5020. }
  5021. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  5022. {
  5023. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5024. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  5025. }
  5026. }
  5027. //==========================================
  5028. // csu trigger DataTransferReq
  5029. //==========================================
  5030. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  5031. {
  5032. sendDataTransferRequest(gun_index);
  5033. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  5034. }
  5035. //==========================================
  5036. // CSU Trigger Authorize Request
  5037. //==========================================
  5038. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  5039. {
  5040. sendAuthorizeRequest(0);
  5041. authorizeRetryTimes = authorizeRetryTimes + 1;
  5042. if(authorizeRetryTimes < 3)
  5043. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5044. }
  5045. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  5046. {
  5047. authorizeRetryTimes = 0;
  5048. SetOcppConnStatus(FALSE);
  5049. server_sign = FALSE;
  5050. }
  5051. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  5052. {
  5053. sendAuthorizeRequest(0);
  5054. }
  5055. //==========================================
  5056. // Charger start transaction
  5057. //==========================================
  5058. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  5059. {
  5060. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5061. meterValueBufferClear(gun_index);
  5062. sendStartTransactionRequest(gun_index);
  5063. refreshStartTimer(&clientTime.StartTransaction);
  5064. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5065. storeTempStopTransaction(gun_index);
  5066. }
  5067. //==========================================
  5068. // Charger stop transaction
  5069. //==========================================
  5070. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  5071. {
  5072. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5073. sendStopTransactionRequest(gun_index);
  5074. OCPP_updatePeriodEnergy(gun_index);
  5075. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  5076. refreshStartTimer(&clientTime.StopTransaction);
  5077. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  5078. }
  5079. //==========================================
  5080. // Charger OCMF message
  5081. //==========================================
  5082. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  5083. {
  5084. sendOcmfByDataTransferRequest(gun_index);
  5085. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  5086. }
  5087. //==========================================
  5088. // Charger status report
  5089. //==========================================
  5090. //--- Check Mode Change ---//
  5091. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5092. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5093. {
  5094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5095. {
  5096. tempIndex = ((gun_index==2) ? 1: 0);
  5097. }
  5098. else
  5099. {
  5100. tempIndex = gun_index;
  5101. }
  5102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5103. {
  5104. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5105. {
  5106. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5107. {
  5108. // Sent unplug message for California pricing logic
  5109. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5110. {
  5111. uint8_t ts[36];
  5112. getNowDatetime(ts);
  5113. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5114. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5115. if(strcmp((char*)dmsVersion, "2.0")==0)
  5116. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5117. else
  5118. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5119. sendUnplugByDataTransferRequest(gun_index);
  5120. interLock.isSentUnplug[gun_index] = 1;
  5121. }
  5122. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5123. {
  5124. interLock.isSentUnplug[gun_index] = 0;
  5125. }
  5126. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5127. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5128. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5129. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5130. {
  5131. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5132. if((access(filenmae,F_OK))!=-1)
  5133. {
  5134. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5135. sprintf(str,"rm -f %s",filenmae);
  5136. system(str);
  5137. }
  5138. }
  5139. }
  5140. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5141. #if 1 // for TempStopTransaction
  5142. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5143. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5144. {
  5145. checkTempStopTransaction(gun_index);
  5146. }
  5147. #endif
  5148. }
  5149. }
  5150. }
  5151. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5152. {
  5153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5154. {
  5155. tempIndex = ((gun_index==2) ? 1: 0);
  5156. }
  5157. else
  5158. {
  5159. tempIndex = gun_index;
  5160. }
  5161. for (int index = 0; index < CCS_QUANTITY; index++)
  5162. {
  5163. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5164. {
  5165. if((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]*/ )
  5166. {
  5167. // Sent unplug message for California pricing logic
  5168. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5169. {
  5170. uint8_t ts[36];
  5171. getNowDatetime(ts);
  5172. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5173. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5174. if(strcmp((char*)dmsVersion, "2.0")==0)
  5175. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5176. else
  5177. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5178. sendUnplugByDataTransferRequest(gun_index);
  5179. interLock.isSentUnplug[gun_index] = 1;
  5180. }
  5181. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5182. {
  5183. interLock.isSentUnplug[gun_index] = 0;
  5184. }
  5185. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5186. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5187. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5188. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5189. {
  5190. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5191. if((access(filenmae,F_OK))!=-1)
  5192. {
  5193. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5194. sprintf(str,"rm -f %s",filenmae);
  5195. system(str);
  5196. }
  5197. }
  5198. }
  5199. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5200. #if 1 // for TempStopTransaction
  5201. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5202. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5203. {
  5204. checkTempStopTransaction(gun_index);
  5205. }
  5206. #endif
  5207. }
  5208. }
  5209. }
  5210. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5211. {
  5212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5213. {
  5214. tempIndex = ((gun_index==2) ? 1: 0);
  5215. }
  5216. else
  5217. {
  5218. tempIndex = gun_index;
  5219. }
  5220. for (int index = 0; index < GB_QUANTITY; index++)
  5221. {
  5222. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5223. {
  5224. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5225. {
  5226. // Sent unplug message for California pricing logic
  5227. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5228. {
  5229. uint8_t ts[36];
  5230. getNowDatetime(ts);
  5231. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5232. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5233. if(strcmp((char*)dmsVersion, "2.0")==0)
  5234. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5235. else
  5236. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5237. sendUnplugByDataTransferRequest(gun_index);
  5238. interLock.isSentUnplug[gun_index] = 1;
  5239. }
  5240. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5241. {
  5242. interLock.isSentUnplug[gun_index] = 0;
  5243. }
  5244. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5245. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5246. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5247. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5248. {
  5249. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5250. if((access(filenmae,F_OK))!=-1)
  5251. {
  5252. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5253. sprintf(str,"rm -f %s",filenmae);
  5254. system(str);
  5255. }
  5256. }
  5257. }
  5258. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5259. #if 1 // for TempStopTransaction
  5260. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5261. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5262. {
  5263. checkTempStopTransaction(gun_index);
  5264. }
  5265. #endif
  5266. }
  5267. }
  5268. }
  5269. else if(gunType[gun_index] == GUN_TYPE_DO)
  5270. {
  5271. tempIndex = gun_index;
  5272. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5273. {
  5274. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5275. {
  5276. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5277. {
  5278. // Sent unplug message for California pricing logic
  5279. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5280. {
  5281. uint8_t ts[36];
  5282. getNowDatetime(ts);
  5283. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5284. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5285. if(strcmp((char*)dmsVersion, "2.0")==0)
  5286. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5287. else
  5288. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5289. sendUnplugByDataTransferRequest(gun_index);
  5290. interLock.isSentUnplug[gun_index] = 1;
  5291. }
  5292. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5293. {
  5294. interLock.isSentUnplug[gun_index] = 0;
  5295. }
  5296. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5297. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5298. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5299. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  5300. {
  5301. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5302. if((access(filenmae,F_OK))!=-1)
  5303. {
  5304. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5305. sprintf(str,"rm -f %s",filenmae);
  5306. system(str);
  5307. }
  5308. }
  5309. }
  5310. 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);
  5311. #if 1 // for TempStopTransaction
  5312. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5313. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5314. {
  5315. checkTempStopTransaction(gun_index);
  5316. }
  5317. #endif
  5318. }
  5319. }
  5320. }
  5321. else
  5322. {
  5323. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5324. {
  5325. tempIndex = 2;
  5326. }
  5327. else
  5328. {
  5329. tempIndex = gun_index;
  5330. }
  5331. for (int index = 0; index < AC_QUANTITY; index++)
  5332. {
  5333. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5334. {
  5335. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5336. {
  5337. // Sent unplug message for California pricing logic
  5338. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  5339. {
  5340. uint8_t ts[36];
  5341. getNowDatetime(ts);
  5342. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5343. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5344. if(strcmp((char*)dmsVersion, "2.0")==0)
  5345. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5346. else
  5347. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5348. sendUnplugByDataTransferRequest(gun_index);
  5349. interLock.isSentUnplug[gun_index] = 1;
  5350. }
  5351. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5352. {
  5353. interLock.isSentUnplug[gun_index] = 0;
  5354. }
  5355. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5356. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5357. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5358. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5359. {
  5360. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5361. if((access(filenmae,F_OK))!=-1)
  5362. {
  5363. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5364. sprintf(str,"rm -f %s",filenmae);
  5365. system(str);
  5366. }
  5367. }
  5368. }
  5369. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5370. #if 1 // for TempStopTransaction
  5371. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5372. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5373. {
  5374. checkTempStopTransaction(gun_index);
  5375. }
  5376. #endif
  5377. }
  5378. }// END
  5379. }
  5380. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5381. {
  5382. sendConnector0StatusNotificationRequest();
  5383. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5384. }
  5385. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5386. (
  5387. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5388. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5389. )
  5390. )
  5391. {
  5392. sendStatusNotificationRequest(gun_index);
  5393. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5394. }
  5395. //==============================================
  5396. // TCCI related DataTransfer messages
  5397. //==============================================
  5398. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5399. {
  5400. reportReaderStatus(gun_index);
  5401. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5402. }
  5403. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq == 1))
  5404. {
  5405. occupancyFeeAct(gun_index);
  5406. }
  5407. //==============================================
  5408. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5409. //==============================================
  5410. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5411. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  5412. {
  5413. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5414. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5415. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5416. }
  5417. //==============================================
  5418. // Meter report
  5419. //==============================================
  5420. // Trigger MeterValue
  5421. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5422. {
  5423. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5424. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5425. }
  5426. // Clock-aligned Meter value
  5427. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5428. {
  5429. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5430. reqClockAlignMeter[gun_index] = 0;
  5431. }
  5432. // Sample period MeterValue
  5433. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  5434. {
  5435. //check Transaction active
  5436. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5437. {
  5438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5439. {
  5440. tempIndex = ((gun_index==2) ? 1: 0);
  5441. }
  5442. else
  5443. {
  5444. tempIndex = gun_index;
  5445. }
  5446. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5447. {
  5448. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5449. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5450. {
  5451. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5452. {
  5453. reqSampleMeter[gun_index] = 1;
  5454. }
  5455. }
  5456. }// End for CHAdeMO
  5457. }
  5458. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5459. {
  5460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5461. {
  5462. tempIndex = ((gun_index==2) ? 1: 0);
  5463. }
  5464. else
  5465. {
  5466. tempIndex = gun_index;
  5467. }
  5468. for (int index = 0; index < CCS_QUANTITY; index++)
  5469. {
  5470. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5471. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5472. {
  5473. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5474. {
  5475. reqSampleMeter[gun_index] = 1;
  5476. }
  5477. }
  5478. } // End for CCS
  5479. }
  5480. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5481. {
  5482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5483. {
  5484. tempIndex = ((gun_index==2) ? 1: 0);
  5485. }
  5486. else
  5487. {
  5488. tempIndex = gun_index;
  5489. }
  5490. for (int index = 0; index < GB_QUANTITY; index++)
  5491. {
  5492. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5493. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5494. {
  5495. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5496. {
  5497. reqSampleMeter[gun_index] = 1;
  5498. }
  5499. }
  5500. }// End for GB
  5501. }
  5502. else if(gunType[gun_index] == GUN_TYPE_DO)
  5503. {
  5504. tempIndex = gun_index;
  5505. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5506. {
  5507. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5508. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5509. {
  5510. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5511. {
  5512. reqSampleMeter[gun_index] = 1;
  5513. }
  5514. }
  5515. }
  5516. }
  5517. else
  5518. {
  5519. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5520. {
  5521. tempIndex = 2;
  5522. }
  5523. else
  5524. {
  5525. tempIndex = gun_index;
  5526. }
  5527. for (int index = 0; index < AC_QUANTITY; index++)
  5528. {
  5529. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5530. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5531. {
  5532. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5533. {
  5534. reqSampleMeter[gun_index] = 1;
  5535. }
  5536. }
  5537. }//End for AC
  5538. }
  5539. if(reqSampleMeter[gun_index] == 1)
  5540. {
  5541. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5542. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5543. storeTempStopTransaction(gun_index);
  5544. reqSampleMeter[gun_index] = 0;
  5545. }
  5546. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5547. }
  5548. //==============================================
  5549. // Check Connector reserved
  5550. //==============================================
  5551. //===============================
  5552. // Check if Reserve is expired
  5553. //===============================
  5554. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5555. {
  5556. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5557. {
  5558. DEBUG_INFO("reserve expired.\n");
  5559. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5560. }
  5561. }//END OF Check if Reserve is expired
  5562. //==========================================
  5563. // csu trigger FirmwareStatusNotificationReq
  5564. //==========================================
  5565. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5566. {
  5567. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5568. }
  5569. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5570. {
  5571. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5572. }
  5573. //==========================================
  5574. // csu trigger DiagnosticsStatusNotificationReq
  5575. //==========================================
  5576. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5577. {
  5578. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5579. }
  5580. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5581. {
  5582. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5583. }
  5584. //==========================================
  5585. // csu trigger CancelReservationConf
  5586. //==========================================
  5587. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5588. {
  5589. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5590. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5591. }
  5592. //==========================================
  5593. // csu trigger ChangeAvailabilityConf
  5594. //==========================================
  5595. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5596. {
  5597. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5598. }
  5599. //==========================================
  5600. // csu trigger UnlockConnectorConf
  5601. //==========================================
  5602. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5603. {
  5604. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5605. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5606. }
  5607. //==========================================
  5608. // csu trigger ReserveNowConf
  5609. //==========================================
  5610. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5611. {
  5612. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5613. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5614. }
  5615. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5616. {
  5617. sendSignCertificateRequest();
  5618. }
  5619. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5620. {
  5621. sendSecurityEventNotificationRequest();
  5622. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5623. }
  5624. // Support 15118
  5625. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5626. {
  5627. json_object *data = json_object_new_object();
  5628. // Read csr file content
  5629. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5630. FILE *fp=fopen(CSR_V2G,"r");
  5631. char *line = NULL;
  5632. size_t len = 0;
  5633. while(getline(&line, &len, fp) != -1)
  5634. {
  5635. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5636. {
  5637. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5638. }
  5639. }
  5640. fclose(fp);
  5641. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5642. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5643. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5644. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5645. json_object_put(data);
  5646. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5647. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5648. }
  5649. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5650. {
  5651. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5652. int parseCertResult = FAIL;
  5653. json_object *data = json_object_new_object();
  5654. json_object *idToken = json_object_new_object();
  5655. json_object *iso15118CertificateHashData = json_object_new_array();
  5656. // Read CERTIFICATE_PnCAuth file content
  5657. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5658. {
  5659. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5660. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5661. char *line = NULL;
  5662. size_t len = 0;
  5663. while(getline(&line, &len, fp) != -1)
  5664. {
  5665. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5666. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5667. }
  5668. fclose(fp);
  5669. }
  5670. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5671. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5672. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5673. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5674. json_object_object_add(data, "idToken", idToken);
  5675. char parseData[512] = {0};
  5676. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5677. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5678. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5679. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5680. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5681. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5682. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5683. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5684. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5685. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5686. for(int idx=0; idx < 4; idx++)
  5687. {
  5688. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5689. {
  5690. json_object *OCSPRequestDataType = json_object_new_object();
  5691. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5692. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5693. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5694. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5695. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5696. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5697. parseCertResult = PASS;
  5698. }
  5699. }
  5700. if(parseCertResult == PASS)
  5701. {
  5702. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5703. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5704. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5705. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5706. json_object_put(data);
  5707. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5708. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5709. }
  5710. else
  5711. {
  5712. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5713. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5714. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5715. }
  5716. }
  5717. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5718. {
  5719. json_object *data = json_object_new_object();
  5720. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5721. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5722. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5723. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5724. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5725. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5726. json_object_put(data);
  5727. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5728. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5729. }
  5730. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5731. {
  5732. json_object *data = json_object_new_object();
  5733. json_object *OCSPRequestDataType = json_object_new_object();
  5734. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5735. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5736. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5737. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5738. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5739. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5740. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5741. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5742. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5743. json_object_put(data);
  5744. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5745. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5746. }
  5747. }
  5748. }
  5749. //==========================================
  5750. // send request routine
  5751. //==========================================
  5752. int sendAuthorizeRequest(int gun_index)
  5753. {
  5754. mtrace();
  5755. int result = FAIL;
  5756. char message[100]={0};
  5757. char guid[37];
  5758. char tempdata[65]={0};
  5759. DEBUG_INFO("sendAuthorizeRequest...\n");
  5760. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5761. //Local Authorize
  5762. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5763. {
  5764. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5765. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5767. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5768. result = PASS;
  5769. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5770. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5771. authorizeRetryTimes = 0;
  5772. return result;
  5773. }
  5774. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  5775. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5776. {
  5777. // Query from cache
  5778. DEBUG_INFO("Authorize from cache.\n");
  5779. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5780. // Query from list
  5781. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5782. {
  5783. DEBUG_INFO("Authorize from list.\n");
  5784. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5785. }
  5786. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5787. {
  5788. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5789. {
  5790. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5791. }
  5792. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5793. {
  5794. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5795. }
  5796. if(!GetOcppConnStatus())
  5797. {
  5798. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5799. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5800. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5801. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5802. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5803. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5804. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5805. authorizeRetryTimes = 0;
  5806. return result;
  5807. }
  5808. }
  5809. else
  5810. {
  5811. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5812. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5813. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5814. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5815. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5816. else
  5817. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5818. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5819. result = PASS;
  5820. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5821. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5822. authorizeRetryTimes = 0;
  5823. return result;
  5824. }
  5825. }
  5826. //initialize struct Authorize
  5827. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5828. //get data from shared memory
  5829. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5830. random_uuid(guid);
  5831. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5832. LWS_Send(message);
  5833. sprintf(tempdata, "Authorize,%d", gun_index);
  5834. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5835. {
  5836. result = PASS;
  5837. DEBUG_INFO("Authorize mapItem pass\n");
  5838. }
  5839. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5840. return result;
  5841. }
  5842. int sendBootNotificationRequest(void)
  5843. {
  5844. mtrace();
  5845. int result = FAIL;
  5846. char message[500]={0}, payload[700]={0};
  5847. char guid[37]={0};
  5848. char tempdata[65]={0};
  5849. // Fill BootNotification fields
  5850. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5851. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5852. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5853. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5854. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5855. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5856. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5857. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5858. ShmOCPP16Data->ChargeBoxId
  5859. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5860. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5861. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5862. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5863. ,ShmOCPP16Data->BootNotification.CpIccid
  5864. ,ShmOCPP16Data->BootNotification.CpImsi);
  5865. random_uuid(guid);
  5866. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5867. LWS_Send(message);
  5868. sprintf(tempdata, "BootNotification,0");
  5869. 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*/)
  5870. {
  5871. result = PASS;
  5872. }
  5873. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5874. strcpy(queuedata,message);
  5875. return result;
  5876. }
  5877. int sendDataTransferRequest(int gun_index)
  5878. {
  5879. mtrace();
  5880. char message[10240]={0};
  5881. char guid[37]={0};
  5882. char tempdata[65]={0};
  5883. int result = FAIL;
  5884. json_object *DataTransfer = json_object_new_object();
  5885. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5886. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5887. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5888. random_uuid(guid);
  5889. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5890. guid,
  5891. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5892. json_object_put(DataTransfer);
  5893. LWS_Send(message);
  5894. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5895. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5896. {
  5897. result = PASS;
  5898. DEBUG_INFO("DataTransfer mapItem pass\n");
  5899. }
  5900. return result;
  5901. }
  5902. int sendUnplugByDataTransferRequest(int gun_index)
  5903. {
  5904. mtrace();
  5905. char message[10752]={0};
  5906. char guid[37]={0};
  5907. char tempdata[65]={0};
  5908. int result = FAIL;
  5909. random_uuid(guid);
  5910. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5911. (gun_index+1),
  5912. MESSAGE_TYPE_CALL,
  5913. guid,
  5914. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5915. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5916. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5917. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5918. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5919. {
  5920. result = PASS;
  5921. DEBUG_INFO("DataTransfer mapItem pass\n");
  5922. }
  5923. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5924. return result;
  5925. }
  5926. int sendOcmfByDataTransferRequest(int gun_index)
  5927. {
  5928. mtrace();
  5929. json_object *DataTransfer = json_object_new_object();
  5930. json_object *data = json_object_new_object();
  5931. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5932. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5933. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5934. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5935. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5936. json_object_object_add(DataTransfer, "data", data);
  5937. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5938. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5939. char message[3000]={0};
  5940. char guid[37]={0};
  5941. char tempdata[65]={0};
  5942. int result = FAIL;
  5943. random_uuid(guid);
  5944. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5945. (gun_index+1),
  5946. MESSAGE_TYPE_CALL,
  5947. guid,
  5948. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5949. json_object_put(DataTransfer);
  5950. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5951. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5952. {
  5953. result = PASS;
  5954. DEBUG_INFO("DataTransfer mapItem pass\n");
  5955. }
  5956. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5957. return result;
  5958. }
  5959. int sendDiagnosticsStatusNotificationRequest(char *status)
  5960. {
  5961. mtrace();
  5962. int result = FAIL;
  5963. char message[110]={0};
  5964. char guid[37]={0};
  5965. char tempdata[65]={0};
  5966. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5967. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5968. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5969. random_uuid(guid);
  5970. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5971. LWS_SendNow(message);
  5972. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5973. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5974. {
  5975. result = PASS;
  5976. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5977. }
  5978. //#ifdef SystemLogMessage
  5979. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5980. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5981. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5982. //#endif
  5983. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5984. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5985. //record status
  5986. if(strcmp(status,"Idle")==0)
  5987. {
  5988. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5989. }
  5990. else if(strcmp(status,"Uploaded")==0)
  5991. {
  5992. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5993. }
  5994. else if(strcmp(status,"UploadFailed")==0)
  5995. {
  5996. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5997. }
  5998. else if(strcmp(status,"Uploading")==0)
  5999. {
  6000. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  6001. }
  6002. return result;
  6003. }
  6004. int sendFirmwareStatusNotificationRequest(char *status)
  6005. {
  6006. mtrace();
  6007. int result = FAIL;
  6008. char message[110]={0};
  6009. char guid[37]={0};
  6010. char tempdata[65]={0};
  6011. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  6012. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  6013. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  6014. random_uuid(guid);
  6015. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  6016. LWS_SendNow(message);
  6017. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6018. 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*/)
  6019. {
  6020. result = PASS;
  6021. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  6022. }
  6023. //#ifdef SystemLogMessage
  6024. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  6025. //DEBUG_INFO("Message: %s\n", SendBuffer);
  6026. //#endif
  6027. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  6028. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  6029. //record status
  6030. if(strcmp(status,"Downloaded")==0)
  6031. {
  6032. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  6033. }
  6034. else if(strcmp(status,"DownloadFailed")==0)
  6035. {
  6036. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  6037. }
  6038. else if(strcmp(status,"Downloading")==0)
  6039. {
  6040. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  6041. }
  6042. else if(strcmp(status,"Idle")==0)
  6043. {
  6044. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  6045. }
  6046. else if(strcmp(status,"InstallationFailed")==0)
  6047. {
  6048. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  6049. }
  6050. else if(strcmp(status,"Installing")==0)
  6051. {
  6052. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  6053. }
  6054. else if(strcmp(status,"Installed")==0)
  6055. {
  6056. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  6057. }
  6058. return result;
  6059. }
  6060. int sendHeartbeatRequest(int gun_index)
  6061. {
  6062. mtrace();
  6063. int result = FAIL;
  6064. char message[80]={0};
  6065. char guid[37]={0};
  6066. char tempdata[65]={0};
  6067. random_uuid(guid);
  6068. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6069. , MESSAGE_TYPE_CALL
  6070. , guid );
  6071. LWS_Send(message);
  6072. sprintf(tempdata, "Heartbeat,%d", 0);
  6073. 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*/)
  6074. {
  6075. result = PASS;
  6076. }
  6077. return result;
  6078. }
  6079. int sendStartTransactionRequest(int gun_index)
  6080. {
  6081. mtrace();
  6082. int result = FAIL;
  6083. char message[250]={0};
  6084. char guid[37]={0};
  6085. struct timeval tmnow;
  6086. struct tm *tm;
  6087. char buf[28];//, usec_buf[6];
  6088. char tempdata[65]={0};
  6089. int tempIndex = 0;
  6090. DEBUG_INFO("sendStartTransactionRequest...\n");
  6091. gettimeofday(&tmnow, NULL);
  6092. time_t t;
  6093. t = time(NULL);
  6094. /*UTC time and date*/
  6095. tm = gmtime(&t);
  6096. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6097. #if 0 // remove temporally
  6098. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6099. strcat(buf,".");
  6100. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6101. strcat(buf,usec_buf);
  6102. #endif
  6103. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  6104. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  6105. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6106. // clear StartTransaction Response
  6107. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  6108. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  6109. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  6110. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  6111. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6112. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6113. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6114. {
  6115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6116. {
  6117. tempIndex = ((gun_index==2) ? 1: 0);
  6118. }
  6119. else
  6120. {
  6121. tempIndex = gun_index;
  6122. }
  6123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6124. {
  6125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6126. {
  6127. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6128. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  6129. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6130. }
  6131. }
  6132. }
  6133. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6134. {
  6135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6136. {
  6137. tempIndex = ((gun_index==2) ? 1: 0);
  6138. }
  6139. else
  6140. {
  6141. tempIndex = gun_index;
  6142. }
  6143. for (int index = 0; index < CCS_QUANTITY; index++)
  6144. {
  6145. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6146. {
  6147. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6148. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  6149. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6150. }
  6151. }
  6152. }
  6153. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6154. {
  6155. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6156. {
  6157. tempIndex = ((gun_index==2) ? 1: 0);
  6158. }
  6159. else
  6160. {
  6161. tempIndex = gun_index;
  6162. }
  6163. for (int index = 0; index < GB_QUANTITY; index++)
  6164. {
  6165. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6166. {
  6167. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6168. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  6169. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6170. }
  6171. }
  6172. }
  6173. else if(gunType[gun_index] == GUN_TYPE_DO)
  6174. {
  6175. tempIndex = gun_index;
  6176. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6177. {
  6178. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6179. {
  6180. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6181. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  6182. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6183. }
  6184. }
  6185. }
  6186. else
  6187. {
  6188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6189. {
  6190. tempIndex = 2;
  6191. }
  6192. else
  6193. {
  6194. tempIndex = gun_index;
  6195. }
  6196. for (int index = 0; index < AC_QUANTITY; index++)
  6197. {
  6198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6199. {
  6200. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6201. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6202. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6203. }
  6204. }
  6205. }
  6206. random_uuid(guid);
  6207. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6208. {
  6209. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6210. , gun_index +1
  6211. , MESSAGE_TYPE_CALL
  6212. , guid
  6213. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6214. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6215. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6216. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6217. }
  6218. else
  6219. {
  6220. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6221. , gun_index +1
  6222. , MESSAGE_TYPE_CALL
  6223. , guid
  6224. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6225. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6226. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6227. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6228. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6229. }
  6230. #if 1
  6231. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6232. 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*/)
  6233. {
  6234. result = PASS;
  6235. }
  6236. #endif
  6237. strcpy(queuedata, message);
  6238. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6239. OCPP_insert_transaction_msg(YES, queuedata);
  6240. return result;
  6241. }
  6242. int sendConnector0StatusNotificationRequest()
  6243. {
  6244. mtrace();
  6245. int result = FAIL;
  6246. char message[600]={0};
  6247. char guid[37];
  6248. struct timeval tmnow;
  6249. struct tm *tm;
  6250. char buf[28];//, usec_buf[6];
  6251. char tempdata[65]={0};
  6252. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6253. gettimeofday(&tmnow, NULL);
  6254. time_t t;
  6255. t = time(NULL);
  6256. /*UTC time and date*/
  6257. tm = gmtime(&t);
  6258. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6259. random_uuid(guid);
  6260. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6261. , MESSAGE_TYPE_CALL
  6262. , guid
  6263. , "NoError"
  6264. , ""
  6265. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6266. , buf
  6267. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6268. , "");
  6269. LWS_Send(message);
  6270. sprintf(tempdata, "StatusNotification,%d", 99);
  6271. 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*/)
  6272. {
  6273. //DEBUG_ERROR("statusNotification mapitem pass");
  6274. result = PASS;
  6275. }
  6276. return result;
  6277. }
  6278. int sendStatusNotificationRequest(int gun_index)
  6279. {
  6280. mtrace();
  6281. int result = FAIL;
  6282. char message[600]={0};
  6283. char guid[37];
  6284. int currentStatus = 0;
  6285. struct timeval tmnow;
  6286. struct tm *tm;
  6287. char buf[28];//, usec_buf[6];
  6288. char tempdata[65]={0};
  6289. int tempIndex = 0;
  6290. uint8_t isStateChanged = TRUE;
  6291. uint8_t isContentIllegal = TRUE;
  6292. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6293. gettimeofday(&tmnow, NULL);
  6294. time_t t;
  6295. t = time(NULL);
  6296. /*UTC time and date*/
  6297. tm = gmtime(&t);
  6298. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6299. #if 0 // remove temporally
  6300. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6301. strcat(buf,".");
  6302. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6303. strcat(buf,usec_buf);
  6304. #endif
  6305. //printf("%s",buf);
  6306. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6307. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6308. // it's option
  6309. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6310. /*
  6311. enum _SYSTEM_STATUS
  6312. {
  6313. S_BOOTING = 0,
  6314. S_IDLE, = 1
  6315. S_AUTHORIZING, =2
  6316. S_REASSIGN_CHECK, =3
  6317. S_REASSIGN, =4
  6318. S_PRECHARGE, =5
  6319. S_PREPARING_FOR_EV, =6
  6320. S_PREPARING_FOR_EVSE, =7
  6321. S_CHARGING, =8
  6322. S_TERMINATING, =9
  6323. S_COMPLETE, =10
  6324. S_ALARM, =11
  6325. S_FAULT =12
  6326. }
  6327. */
  6328. //check Transaction active
  6329. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6330. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6331. {
  6332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6333. {
  6334. tempIndex = ((gun_index==2) ? 1: 0);
  6335. }
  6336. else
  6337. {
  6338. tempIndex = gun_index;
  6339. }
  6340. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6341. {
  6342. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6343. {
  6344. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6345. {
  6346. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6347. {
  6348. currentStatus = Preparing; //OCPP Status: Preparing
  6349. }
  6350. else
  6351. {
  6352. currentStatus = Available; //OCPP Status: Available
  6353. }
  6354. }
  6355. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6356. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6357. ) //S_PRECHARGE
  6358. {
  6359. currentStatus = Preparing; //OCPP Status: Preparing
  6360. }
  6361. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6362. {
  6363. currentStatus = Charging; //OCPP Status: Charging
  6364. }
  6365. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6366. {
  6367. currentStatus = Finishing; //OCPP Status: Finishing
  6368. }
  6369. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6370. {
  6371. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6372. }
  6373. 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
  6374. {
  6375. currentStatus = Unavailable; //OCPP Status: Unavailable
  6376. }
  6377. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6378. {
  6379. currentStatus = Faulted; //OCPP Status: Faulted
  6380. }
  6381. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6382. {
  6383. currentStatus = Reserved; //OCPP Status: Reserved
  6384. }
  6385. } //end of the same index
  6386. }//end of for CHAdeMO_QUANTITY
  6387. }
  6388. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6389. {
  6390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6391. {
  6392. tempIndex = ((gun_index==2) ? 1: 0);
  6393. }
  6394. else
  6395. {
  6396. tempIndex = gun_index;
  6397. }
  6398. for (int index = 0; index < CCS_QUANTITY; index++)
  6399. {
  6400. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6401. {
  6402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6403. {
  6404. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6405. {
  6406. currentStatus = Preparing; //OCPP Status: Preparing
  6407. }
  6408. else
  6409. {
  6410. currentStatus = Available; //OCPP Status: Available
  6411. }
  6412. }
  6413. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6414. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6415. ) //S_PRECHARGE
  6416. {
  6417. currentStatus = Preparing; //OCPP Status: Preparing
  6418. }
  6419. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6420. {
  6421. currentStatus = Charging; //OCPP Status: Charging
  6422. }
  6423. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6424. {
  6425. currentStatus = Finishing; //OCPP Status: Finishing
  6426. }
  6427. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6428. {
  6429. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6430. }
  6431. 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
  6432. {
  6433. currentStatus = Unavailable; //OCPP Status : Unavailable
  6434. }
  6435. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6436. {
  6437. currentStatus = Faulted; //OCPP Status: Faulted
  6438. }
  6439. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6440. {
  6441. currentStatus = Reserved; //OCPP Status: Reserved
  6442. }
  6443. } //end of the same index
  6444. } // end of for CCS_QUANTITY
  6445. }
  6446. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6447. {
  6448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6449. {
  6450. tempIndex = ((gun_index==2) ? 1: 0);
  6451. }
  6452. else
  6453. {
  6454. tempIndex = gun_index;
  6455. }
  6456. for (int index = 0; index < GB_QUANTITY; index++)
  6457. {
  6458. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6459. {
  6460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6461. {
  6462. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6463. {
  6464. currentStatus = Preparing; //OCPP Status: Preparing
  6465. }
  6466. else
  6467. {
  6468. currentStatus = Available; //OCPP Status: Available
  6469. }
  6470. }
  6471. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6472. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6473. ) //S_PRECHARGE
  6474. {
  6475. currentStatus = Preparing; //OCPP Status: Preparing
  6476. }
  6477. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6478. {
  6479. currentStatus = Charging; //OCPP Status: Charging
  6480. }
  6481. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6482. {
  6483. currentStatus = Finishing; //OCPP Status: Finishing
  6484. }
  6485. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6486. {
  6487. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6488. }
  6489. 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
  6490. {
  6491. currentStatus = Unavailable; //OCPP Status: Unavailable
  6492. }
  6493. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6494. {
  6495. currentStatus = Faulted; //OCPP Status: Faulted
  6496. }
  6497. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6498. {
  6499. currentStatus = Reserved; //OCPP Status: Reserved
  6500. }
  6501. } //end of the same index
  6502. } // end of for GB_QUANTITY
  6503. }
  6504. else if(gunType[gun_index] == GUN_TYPE_DO)
  6505. {
  6506. tempIndex = gun_index;
  6507. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6508. {
  6509. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6510. {
  6511. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6512. {
  6513. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6514. {
  6515. currentStatus = Preparing; //OCPP Status: Preparing
  6516. }
  6517. else
  6518. {
  6519. currentStatus = Available; //OCPP Status: Available
  6520. }
  6521. }
  6522. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6523. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6524. ) //S_PRECHARGE
  6525. {
  6526. currentStatus = Preparing; //OCPP Status: Preparing
  6527. }
  6528. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6529. {
  6530. currentStatus = Charging; //OCPP Status: Charging
  6531. }
  6532. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6533. {
  6534. currentStatus = Finishing; //OCPP Status: Finishing
  6535. }
  6536. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6537. {
  6538. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6539. }
  6540. 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
  6541. {
  6542. currentStatus = Unavailable; //OCPP Status: Unavailable
  6543. }
  6544. 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
  6545. {
  6546. currentStatus = Faulted; //OCPP Status: Faulted
  6547. }
  6548. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6549. {
  6550. currentStatus = Reserved; //OCPP Status: Reserved
  6551. }
  6552. } //end of the same index
  6553. }
  6554. }
  6555. else
  6556. {
  6557. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6558. {
  6559. tempIndex = 2;
  6560. }
  6561. else
  6562. {
  6563. tempIndex = gun_index;
  6564. }
  6565. for (int index = 0; index < AC_QUANTITY; index++)
  6566. {
  6567. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6568. {
  6569. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6570. {
  6571. 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))
  6572. {
  6573. currentStatus = Preparing; //OCPP Status: Preparing
  6574. }
  6575. else
  6576. {
  6577. currentStatus = Available; //OCPP Status: Available
  6578. }
  6579. }
  6580. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6581. {
  6582. currentStatus = Preparing; //OCPP Status: Preparing
  6583. }
  6584. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6585. {
  6586. currentStatus = Charging; //OCPP Status: Charging
  6587. }
  6588. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6589. {
  6590. currentStatus = Finishing; //OCPP Status: Finishing
  6591. }
  6592. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6593. {
  6594. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6595. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6596. else
  6597. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6598. }
  6599. 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
  6600. {
  6601. currentStatus = Unavailable; //OCPP Status: Unavailable
  6602. }
  6603. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6604. {
  6605. currentStatus = Faulted; //OCPP Status: Faulted
  6606. }
  6607. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6608. {
  6609. currentStatus = Reserved; //OCPP Status: Reserved
  6610. }
  6611. }//end of the same index
  6612. }//end of for AC_QUANTITY
  6613. }
  6614. //it's option
  6615. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6616. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6617. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6618. {
  6619. isStateChanged = FALSE;
  6620. }
  6621. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6622. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6623. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6624. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6625. isContentIllegal = TRUE;
  6626. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6627. {
  6628. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6629. {
  6630. isContentIllegal = FALSE;
  6631. break;
  6632. }
  6633. }
  6634. if(isContentIllegal)
  6635. {
  6636. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6637. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6638. }
  6639. random_uuid(guid);
  6640. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6641. , MESSAGE_TYPE_CALL
  6642. , guid
  6643. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6644. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6645. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6646. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6647. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6648. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6649. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6650. if((server_sign == TRUE) && isStateChanged)
  6651. {
  6652. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6653. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6654. LWS_Send(message);
  6655. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6656. 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*/)
  6657. {
  6658. //DEBUG_ERROR("statusNotification mapitem pass");
  6659. result = PASS;
  6660. }
  6661. }
  6662. else
  6663. {
  6664. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6665. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6666. result = PASS;
  6667. }
  6668. return result;
  6669. }
  6670. int sendStopTransactionRequest(int gun_index)
  6671. {
  6672. mtrace();
  6673. int result = FAIL;
  6674. //char message[1500]={0};
  6675. char guid[37]={0};
  6676. char tempdata[65]={0};
  6677. int tempIndex = 0;
  6678. char TempStopTransaction[256];
  6679. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6680. DEBUG_INFO("sendStopTransactionRequest \n");
  6681. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6682. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6683. //=========================== Stop Transaction Time ===============================================
  6684. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  6685. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6686. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6687. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6688. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6689. {
  6690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6691. {
  6692. tempIndex = ((gun_index==2) ? 1: 0);
  6693. }
  6694. else
  6695. {
  6696. tempIndex = gun_index;
  6697. }
  6698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6699. {
  6700. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6701. {
  6702. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6703. }
  6704. }// END OF CHAdeMO_QUANTITY
  6705. }
  6706. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6707. {
  6708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6709. {
  6710. tempIndex = ((gun_index==2) ? 1: 0);
  6711. }
  6712. else
  6713. {
  6714. tempIndex = gun_index;
  6715. }
  6716. for (int index = 0; index < CCS_QUANTITY; index++)
  6717. {
  6718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6719. {
  6720. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6721. }
  6722. }// END OF CCS_QUANTITY
  6723. }
  6724. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6725. {
  6726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6727. {
  6728. tempIndex = ((gun_index==2) ? 1: 0);
  6729. }
  6730. else
  6731. {
  6732. tempIndex = gun_index;
  6733. }
  6734. for (int index = 0; index < GB_QUANTITY; index++)
  6735. {
  6736. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6737. {
  6738. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6739. }
  6740. }// END OF GB_QUANTITY
  6741. }
  6742. else if(gunType[gun_index] == GUN_TYPE_DO)
  6743. {
  6744. tempIndex = gun_index;
  6745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6746. {
  6747. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6748. {
  6749. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6750. }
  6751. }// END OF GB_QUANTITY
  6752. }
  6753. else
  6754. {
  6755. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6756. {
  6757. tempIndex = 2;
  6758. }
  6759. else
  6760. {
  6761. tempIndex = gun_index;
  6762. }
  6763. for (int index = 0; index < AC_QUANTITY; index++)
  6764. {
  6765. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6766. {
  6767. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6768. }
  6769. }// END OF AC_QUANTITY
  6770. }
  6771. //================================================ Message create ====================================================
  6772. json_object *StopTransaction = json_object_new_object();
  6773. json_object *transactionDatas = json_object_new_array();
  6774. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6775. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6776. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6777. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6778. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6779. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6780. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6781. meterValueBufferQuery(gun_index, transactionDatas);
  6782. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6783. random_uuid(guid);
  6784. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6785. ,MESSAGE_TYPE_CALL
  6786. ,guid
  6787. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6788. json_object_put(StopTransaction);
  6789. #if 1 // for TempStopTransaction
  6790. //Delete TempStopTransaction
  6791. if((access(TempStopTransaction,F_OK))!=-1)
  6792. {
  6793. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6794. }
  6795. #endif
  6796. #if 1
  6797. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6798. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6799. {
  6800. result = PASS;
  6801. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6802. }
  6803. #endif
  6804. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6805. OCPP_insert_transaction_msg(NO, queuedata);
  6806. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6807. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6808. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6809. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6810. {
  6811. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6812. }
  6813. //for test
  6814. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6815. return result;
  6816. }
  6817. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6818. {
  6819. mtrace();
  6820. int result = FAIL;
  6821. char guid[37]={0};
  6822. char tempdata[65]={0};
  6823. int tempIndex = 0;
  6824. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6825. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6826. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6827. //set value
  6828. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6829. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6830. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6831. -1);
  6832. random_uuid(guid);
  6833. //UTC Date time
  6834. struct timeval tmnow;
  6835. struct tm *tm;
  6836. char buf[28];//, usec_buf[6];
  6837. gettimeofday(&tmnow, NULL);
  6838. time_t t;
  6839. t = time(NULL);
  6840. /*UTC time and date*/
  6841. tm = gmtime(&t);
  6842. if(dataType == ReadingContext_Sample_Clock)
  6843. {
  6844. struct tm *tmTarget;
  6845. struct timeb tbTarget;
  6846. tbTarget.time = mktime(tm);
  6847. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6848. tmTarget = gmtime(&tbTarget.time);
  6849. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6850. }
  6851. else
  6852. {
  6853. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6854. }
  6855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6856. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6857. //********************************(1)Current.Import L1************************************************/
  6858. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6859. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6860. (dataType == ReadingContext_Trigger))
  6861. {
  6862. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6863. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6864. {
  6865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6866. {
  6867. tempIndex = ((gun_index==2) ? 1: 0);
  6868. }
  6869. else
  6870. {
  6871. tempIndex = gun_index;
  6872. }
  6873. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6874. {
  6875. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6876. {
  6877. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6878. }
  6879. }
  6880. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6881. }
  6882. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6883. {
  6884. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6885. {
  6886. tempIndex = ((gun_index==2) ? 1: 0);
  6887. }
  6888. else
  6889. {
  6890. tempIndex = gun_index;
  6891. }
  6892. for (int index = 0; index < CCS_QUANTITY; index++)
  6893. {
  6894. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6895. {
  6896. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6897. }
  6898. }
  6899. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6900. }
  6901. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6902. {
  6903. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6904. {
  6905. tempIndex = ((gun_index==2) ? 1: 0);
  6906. }
  6907. else
  6908. {
  6909. tempIndex = gun_index;
  6910. }
  6911. for (int index = 0; index < GB_QUANTITY; index++)
  6912. {
  6913. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6914. {
  6915. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6916. }
  6917. }
  6918. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6919. }
  6920. else if(gunType[gun_index] == GUN_TYPE_DO)
  6921. {
  6922. tempIndex = gun_index;
  6923. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6924. {
  6925. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6926. {
  6927. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6928. }
  6929. }
  6930. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6931. }
  6932. else
  6933. {
  6934. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6935. {
  6936. tempIndex = 2;
  6937. }
  6938. else
  6939. {
  6940. tempIndex = gun_index;
  6941. }
  6942. for (int index = 0; index < AC_QUANTITY; index++)
  6943. {
  6944. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6945. {
  6946. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6947. }
  6948. }
  6949. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6950. }
  6951. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6952. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6953. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6954. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6956. }
  6957. //********************************(2)Energy.Active.Import.Register ************************************************/
  6958. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6959. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6960. (dataType == ReadingContext_Trigger))
  6961. {
  6962. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6963. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6964. {
  6965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6966. {
  6967. tempIndex = ((gun_index==2) ? 1: 0);
  6968. }
  6969. else
  6970. {
  6971. tempIndex = gun_index;
  6972. }
  6973. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6974. {
  6975. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6976. {
  6977. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6978. }
  6979. }
  6980. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6981. }
  6982. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6983. {
  6984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6985. {
  6986. tempIndex = ((gun_index==2) ? 1: 0);
  6987. }
  6988. else
  6989. {
  6990. tempIndex = gun_index;
  6991. }
  6992. for (int index = 0; index < CCS_QUANTITY; index++)
  6993. {
  6994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6995. {
  6996. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6997. }
  6998. }
  6999. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7000. }
  7001. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7002. {
  7003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7004. {
  7005. tempIndex = ((gun_index==2) ? 1: 0);
  7006. }
  7007. else
  7008. {
  7009. tempIndex = gun_index;
  7010. }
  7011. for (int index = 0; index < GB_QUANTITY; index++)
  7012. {
  7013. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7014. {
  7015. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7016. }
  7017. }
  7018. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7019. }
  7020. else if(gunType[gun_index] == GUN_TYPE_DO)
  7021. {
  7022. tempIndex = gun_index;
  7023. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7024. {
  7025. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7026. {
  7027. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7028. }
  7029. }
  7030. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7031. }
  7032. else
  7033. {
  7034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7035. {
  7036. tempIndex = 2;
  7037. }
  7038. else
  7039. {
  7040. tempIndex = gun_index;
  7041. }
  7042. for (int index = 0; index < AC_QUANTITY; index++)
  7043. {
  7044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7045. {
  7046. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7047. }
  7048. }
  7049. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7050. }
  7051. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7052. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7053. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7054. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7056. }
  7057. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7058. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7059. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7060. (dataType == ReadingContext_Trigger))
  7061. {
  7062. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7063. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7064. {
  7065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7066. {
  7067. tempIndex = ((gun_index==2) ? 1: 0);
  7068. }
  7069. else
  7070. {
  7071. tempIndex = gun_index;
  7072. }
  7073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7074. {
  7075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7076. {
  7077. if(dataType == ReadingContext_Sample_Clock)
  7078. {
  7079. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7080. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7081. }
  7082. else if(dataType == ReadingContext_Sample_Periodic)
  7083. {
  7084. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7085. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7086. }
  7087. else
  7088. {
  7089. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7090. }
  7091. }
  7092. } // END OF FOR CHAdeMO_QUANTITY
  7093. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7094. }
  7095. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7096. {
  7097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7098. {
  7099. tempIndex = ((gun_index==2) ? 1: 0);
  7100. }
  7101. else
  7102. {
  7103. tempIndex = gun_index;
  7104. }
  7105. for (int index = 0; index < CCS_QUANTITY; index++)
  7106. {
  7107. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7108. {
  7109. if(dataType == ReadingContext_Sample_Clock)
  7110. {
  7111. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7112. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7113. }
  7114. else if(dataType == ReadingContext_Sample_Periodic)
  7115. {
  7116. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7117. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7118. }
  7119. else
  7120. {
  7121. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7122. }
  7123. }
  7124. } // END OF CCS_QUANTITY
  7125. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7126. }
  7127. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7128. {
  7129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7130. {
  7131. tempIndex = ((gun_index==2) ? 1: 0);
  7132. }
  7133. else
  7134. {
  7135. tempIndex = gun_index;
  7136. }
  7137. for (int index = 0; index < GB_QUANTITY; index++)
  7138. {
  7139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7140. {
  7141. if(dataType == ReadingContext_Sample_Clock)
  7142. {
  7143. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7144. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7145. }
  7146. else if(dataType == ReadingContext_Sample_Periodic)
  7147. {
  7148. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7149. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7150. }
  7151. else
  7152. {
  7153. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7154. }
  7155. }
  7156. } // END OF GB_QUANTITY
  7157. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7158. }
  7159. else if(gunType[gun_index] == GUN_TYPE_DO)
  7160. {
  7161. tempIndex = gun_index;
  7162. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7163. {
  7164. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7165. {
  7166. if(dataType == ReadingContext_Sample_Clock)
  7167. {
  7168. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7169. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7170. }
  7171. else if(dataType == ReadingContext_Sample_Periodic)
  7172. {
  7173. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7174. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7175. }
  7176. else
  7177. {
  7178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7179. }
  7180. }
  7181. }
  7182. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7183. }
  7184. else
  7185. {
  7186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7187. {
  7188. tempIndex = 2;
  7189. }
  7190. else
  7191. {
  7192. tempIndex = gun_index;
  7193. }
  7194. for (int index = 0; index < AC_QUANTITY; index++)
  7195. {
  7196. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7197. {
  7198. if(dataType == ReadingContext_Sample_Clock)
  7199. {
  7200. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7201. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7202. }
  7203. else if(dataType == ReadingContext_Sample_Periodic)
  7204. {
  7205. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7206. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7207. }
  7208. else
  7209. {
  7210. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7211. }
  7212. }
  7213. }
  7214. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7215. }
  7216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7217. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7218. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7221. }
  7222. //********************************(4)Power.Active.Import************************************************/
  7223. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7224. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7225. (dataType == ReadingContext_Trigger))
  7226. {
  7227. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7228. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7229. {
  7230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7231. {
  7232. tempIndex = ((gun_index==2) ? 1: 0);
  7233. }
  7234. else
  7235. {
  7236. tempIndex = gun_index;
  7237. }
  7238. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7239. {
  7240. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7241. {
  7242. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7243. }
  7244. } // END OF FOR
  7245. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7246. }
  7247. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7248. {
  7249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7250. {
  7251. tempIndex = ((gun_index==2) ? 1: 0);
  7252. }
  7253. else
  7254. {
  7255. tempIndex = gun_index;
  7256. }
  7257. for (int index = 0; index < CCS_QUANTITY; index++)
  7258. {
  7259. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7260. {
  7261. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7262. }
  7263. }
  7264. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7265. }
  7266. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7267. {
  7268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7269. {
  7270. tempIndex = ((gun_index==2) ? 1: 0);
  7271. }
  7272. else
  7273. {
  7274. tempIndex = gun_index;
  7275. }
  7276. for (int index = 0; index < GB_QUANTITY; index++)
  7277. {
  7278. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7279. {
  7280. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7281. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7282. }
  7283. }
  7284. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7285. }
  7286. else if(gunType[gun_index] == GUN_TYPE_DO)
  7287. {
  7288. tempIndex = gun_index;
  7289. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7290. {
  7291. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7292. {
  7293. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7294. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7295. }
  7296. }
  7297. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7298. }
  7299. else
  7300. {
  7301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7302. {
  7303. tempIndex = 2;
  7304. }
  7305. else
  7306. {
  7307. tempIndex = gun_index;
  7308. }
  7309. for (int index = 0; index < AC_QUANTITY; index++)
  7310. {
  7311. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7312. {
  7313. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7314. }
  7315. }
  7316. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7317. }
  7318. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7319. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7320. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7323. }
  7324. //***********************************************(5)VOLTAGE L1******************************************************/
  7325. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7326. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7327. (dataType == ReadingContext_Trigger))
  7328. {
  7329. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7330. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7331. {
  7332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7333. {
  7334. tempIndex = ((gun_index==2) ? 1: 0);
  7335. }
  7336. else
  7337. {
  7338. tempIndex = gun_index;
  7339. }
  7340. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7341. {
  7342. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7343. {
  7344. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7345. }
  7346. }
  7347. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7348. }
  7349. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7350. {
  7351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7352. {
  7353. tempIndex = ((gun_index==2) ? 1: 0);
  7354. }
  7355. else
  7356. {
  7357. tempIndex = gun_index;
  7358. }
  7359. for (int index = 0; index < CCS_QUANTITY; index++)
  7360. {
  7361. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7362. {
  7363. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7364. }
  7365. }
  7366. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7367. }
  7368. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7369. {
  7370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7371. {
  7372. tempIndex = ((gun_index==2) ? 1: 0);
  7373. }
  7374. else
  7375. {
  7376. tempIndex = gun_index;
  7377. }
  7378. for (int index = 0; index < GB_QUANTITY; index++)
  7379. {
  7380. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7381. {
  7382. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7383. }
  7384. }
  7385. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7386. }
  7387. else if(gunType[gun_index] == GUN_TYPE_DO)
  7388. {
  7389. tempIndex = gun_index;
  7390. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7391. {
  7392. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7393. {
  7394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7395. }
  7396. }
  7397. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7398. }
  7399. else
  7400. {
  7401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7402. {
  7403. tempIndex = 2;
  7404. }
  7405. else
  7406. {
  7407. tempIndex = gun_index;
  7408. }
  7409. for (int index = 0; index < AC_QUANTITY; index++)
  7410. {
  7411. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7412. {
  7413. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7414. }
  7415. }
  7416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7417. }
  7418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7422. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7423. }
  7424. //***********************************************(6)SOC******************************************************/
  7425. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7426. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7427. (dataType == ReadingContext_Trigger))
  7428. {
  7429. 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))
  7430. {
  7431. //idx_sample=5;
  7432. //sampledValue = NULL;
  7433. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7434. {
  7435. tempIndex = ((gun_index==2) ? 1: 0);
  7436. }
  7437. else
  7438. {
  7439. tempIndex = gun_index;
  7440. }
  7441. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7442. {
  7443. //tempIndex = ((gun_index==2) ? 1: 0);
  7444. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7445. {
  7446. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7447. {
  7448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7449. }
  7450. }
  7451. }
  7452. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7453. {
  7454. //tempIndex = ((gun_index==2) ? 1: 0);
  7455. for (int index = 0; index < CCS_QUANTITY; index++)
  7456. {
  7457. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7458. {
  7459. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7460. }
  7461. }
  7462. }
  7463. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7464. {
  7465. //tempIndex = ((gun_index==2) ? 1: 0);
  7466. for (int index = 0; index < GB_QUANTITY; index++)
  7467. {
  7468. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7469. {
  7470. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7471. }
  7472. }
  7473. }
  7474. else if(gunType[gun_index] == GUN_TYPE_DO)
  7475. {
  7476. //tempIndex = ((gun_index==2) ? 1: 0);
  7477. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7478. {
  7479. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7480. {
  7481. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7482. }
  7483. }
  7484. }
  7485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7488. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7491. }
  7492. }
  7493. //********************************(7)Current.Import L2************************************************/
  7494. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7495. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7496. (dataType == ReadingContext_Trigger))
  7497. {
  7498. // Only for AC 3 phase
  7499. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7500. {
  7501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7502. {
  7503. tempIndex = 2;
  7504. }
  7505. else
  7506. {
  7507. tempIndex = gun_index;
  7508. }
  7509. for (int index = 0; index < AC_QUANTITY; index++)
  7510. {
  7511. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7512. {
  7513. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7514. }
  7515. }
  7516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7517. }
  7518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7523. }
  7524. //********************************(8)Current.Import L3************************************************/
  7525. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7526. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7527. (dataType == ReadingContext_Trigger))
  7528. {
  7529. // Only for AC 3 phase
  7530. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7531. {
  7532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7533. {
  7534. tempIndex = 2;
  7535. }
  7536. else
  7537. {
  7538. tempIndex = gun_index;
  7539. }
  7540. for (int index = 0; index < AC_QUANTITY; index++)
  7541. {
  7542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7543. {
  7544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7545. }
  7546. }
  7547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7548. }
  7549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7554. }
  7555. //***********************************************(9)VOLTAGE L2******************************************************/
  7556. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7557. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7558. (dataType == ReadingContext_Trigger))
  7559. {
  7560. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7561. {
  7562. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7563. {
  7564. tempIndex = 2;
  7565. }
  7566. else
  7567. {
  7568. tempIndex = gun_index;
  7569. }
  7570. for (int index = 0; index < AC_QUANTITY; index++)
  7571. {
  7572. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7573. {
  7574. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7575. }
  7576. }
  7577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7578. }
  7579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7584. }
  7585. //***********************************************(10)VOLTAGE L3******************************************************/
  7586. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7587. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7588. (dataType == ReadingContext_Trigger))
  7589. {
  7590. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7591. {
  7592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7593. {
  7594. tempIndex = 2;
  7595. }
  7596. else
  7597. {
  7598. tempIndex = gun_index;
  7599. }
  7600. for (int index = 0; index < AC_QUANTITY; index++)
  7601. {
  7602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7603. {
  7604. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7605. }
  7606. }
  7607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7608. }
  7609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7614. }
  7615. //***********************************************(11)Current.Offered******************************************************/
  7616. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7617. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7618. (dataType == ReadingContext_Trigger))
  7619. {
  7620. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7621. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7622. {
  7623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7624. {
  7625. tempIndex = ((gun_index==2) ? 1: 0);
  7626. }
  7627. else
  7628. {
  7629. tempIndex = gun_index;
  7630. }
  7631. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7632. {
  7633. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7634. {
  7635. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7636. }
  7637. } // END OF FOR CHAdeMO_QUANTITY
  7638. }
  7639. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7640. {
  7641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7642. {
  7643. tempIndex = ((gun_index==2) ? 1: 0);
  7644. }
  7645. else
  7646. {
  7647. tempIndex = gun_index;
  7648. }
  7649. for (int index = 0; index < CCS_QUANTITY; index++)
  7650. {
  7651. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7652. {
  7653. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7654. }
  7655. } // END OF CCS_QUANTITY
  7656. }
  7657. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7658. {
  7659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7660. {
  7661. tempIndex = ((gun_index==2) ? 1: 0);
  7662. }
  7663. else
  7664. {
  7665. tempIndex = gun_index;
  7666. }
  7667. for (int index = 0; index < GB_QUANTITY; index++)
  7668. {
  7669. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7670. {
  7671. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7672. }
  7673. } // END OF GB_QUANTITY
  7674. }
  7675. else if(gunType[gun_index] == GUN_TYPE_DO)
  7676. {
  7677. tempIndex = gun_index;
  7678. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7679. {
  7680. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7681. {
  7682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7683. }
  7684. }
  7685. }
  7686. else
  7687. {
  7688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7689. {
  7690. tempIndex = 2;
  7691. }
  7692. else
  7693. {
  7694. tempIndex = gun_index;
  7695. }
  7696. for (int index = 0; index < AC_QUANTITY; index++)
  7697. {
  7698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7699. {
  7700. uint16_t currentOffer;
  7701. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7702. {
  7703. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7704. }
  7705. else
  7706. {
  7707. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7708. }
  7709. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7710. }
  7711. }
  7712. }
  7713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7715. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7718. }
  7719. //***********************************************(12)Power.Offered******************************************************/
  7720. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7721. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7722. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7723. {
  7724. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7725. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7726. {
  7727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7728. {
  7729. tempIndex = ((gun_index==2) ? 1: 0);
  7730. }
  7731. else
  7732. {
  7733. tempIndex = gun_index;
  7734. }
  7735. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7736. {
  7737. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7738. {
  7739. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7740. }
  7741. } // END OF FOR CHAdeMO_QUANTITY
  7742. }
  7743. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7744. {
  7745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7746. {
  7747. tempIndex = ((gun_index==2) ? 1: 0);
  7748. }
  7749. else
  7750. {
  7751. tempIndex = gun_index;
  7752. }
  7753. for (int index = 0; index < CCS_QUANTITY; index++)
  7754. {
  7755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7756. {
  7757. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7758. }
  7759. } // END OF CCS_QUANTITY
  7760. }
  7761. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7762. {
  7763. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7764. {
  7765. tempIndex = ((gun_index==2) ? 1: 0);
  7766. }
  7767. else
  7768. {
  7769. tempIndex = gun_index;
  7770. }
  7771. for (int index = 0; index < GB_QUANTITY; index++)
  7772. {
  7773. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7774. {
  7775. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7776. }
  7777. } // END OF GB_QUANTITY
  7778. }
  7779. else if(gunType[gun_index] == GUN_TYPE_DO)
  7780. {
  7781. tempIndex = gun_index;
  7782. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7783. {
  7784. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7785. {
  7786. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7787. }
  7788. }
  7789. }
  7790. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7795. }
  7796. // Message create ====================================================================================================
  7797. if(TRUE)
  7798. {
  7799. json_object *MeterValueReq = json_object_new_object();
  7800. json_object *MeterValues = json_object_new_array();
  7801. json_object *sampledValues = json_object_new_array();
  7802. json_object *sampledValuesBuffer = json_object_new_array();
  7803. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7804. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7805. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7806. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7807. {
  7808. json_object *MeterValue = json_object_new_object();
  7809. json_object *MeterValueBuffer = json_object_new_object();
  7810. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7811. {
  7812. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7813. {
  7814. json_object *sampledValue = json_object_new_object();
  7815. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7816. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7817. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7818. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7819. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7820. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7821. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7822. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7823. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7824. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7825. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7826. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7827. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7828. json_object_array_add(sampledValues, sampledValue);
  7829. // For StopTxn data
  7830. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, (char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand ) != NULL) && (strlen((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData) > 0)) ||
  7831. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, (char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) != NULL) && (strlen((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData) > 0)))
  7832. {
  7833. json_object *sampledValue = json_object_new_object();
  7834. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7835. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7836. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7837. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7838. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7839. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7840. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7841. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7842. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7843. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7844. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7845. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7846. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7847. json_object_array_add(sampledValuesBuffer, sampledValue);
  7848. }
  7849. }
  7850. }
  7851. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7852. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7853. json_object_array_add(MeterValues, MeterValue);
  7854. // For StopTxn data
  7855. if((dataType != ReadingContext_Trigger) &&
  7856. (json_object_array_length(sampledValuesBuffer) > 0))
  7857. {
  7858. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7859. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  7860. if(meterValueBufferDataQuantity(gun_index, dataType) < 200)
  7861. meterValueBufferInsert(gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7862. else
  7863. meterValueBufferReplace(200, gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7864. json_object_put(MeterValueBuffer);
  7865. }
  7866. else
  7867. {
  7868. json_object_put(sampledValuesBuffer);
  7869. json_object_put(MeterValueBuffer);
  7870. }
  7871. }
  7872. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7873. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7874. ,gun_index + 1
  7875. ,MESSAGE_TYPE_CALL
  7876. ,guid
  7877. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7878. json_object_put(MeterValueReq);
  7879. }
  7880. // Put request guid to hash map
  7881. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7882. 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*/)
  7883. {
  7884. result = PASS;
  7885. //DEBUG_INFO("MeterValues mapitem pass\n");
  7886. }
  7887. if((dataType != ReadingContext_Trigger) &&
  7888. (dataType != ReadingContext_Sample_Clock) &&
  7889. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7890. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7891. else
  7892. {
  7893. if(FirstHeartBeat)
  7894. LWS_Send(queuedata +2);
  7895. }
  7896. return result;
  7897. }
  7898. int sendLogStatusNotificationRequest(char *status)
  7899. {
  7900. mtrace();
  7901. int result = PASS;
  7902. char message[4096]={0};
  7903. char guid[37]={0};
  7904. char tempdata[128]={0};
  7905. json_object *LogStatusNotification = json_object_new_object();
  7906. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7907. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7908. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7909. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7910. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7911. random_uuid(guid);
  7912. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7913. json_object_put(LogStatusNotification);
  7914. LWS_Send(message);
  7915. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7916. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7917. {
  7918. result = PASS;
  7919. }
  7920. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7921. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7922. return result;
  7923. }
  7924. int sendSecurityEventNotificationRequest()
  7925. {
  7926. mtrace();
  7927. int result = PASS;
  7928. char message[4096]={0};
  7929. char guid[37]={0};
  7930. char tempdata[128]={0};
  7931. json_object *SecurityEventNotification = json_object_new_object();
  7932. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7933. //Stop Transaction Time
  7934. struct timeval tmnow;
  7935. struct tm *tm;
  7936. gettimeofday(&tmnow, NULL);
  7937. time_t t;
  7938. t = time(NULL);
  7939. /*UTC time and date*/
  7940. tm = gmtime(&t);
  7941. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7942. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7943. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7944. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7945. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7946. random_uuid(guid);
  7947. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7948. json_object_put(SecurityEventNotification);
  7949. LWS_Send(message);
  7950. sprintf(tempdata, "SecurityEventNotification,0");
  7951. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7952. {
  7953. result = PASS;
  7954. }
  7955. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7956. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7957. return result;
  7958. }
  7959. int sendSignCertificateRequest()
  7960. {
  7961. mtrace();
  7962. int result = PASS;
  7963. char message[4096]={0};
  7964. char guid[37]={0};
  7965. char tempdata[128]={0};
  7966. json_object *SignCertificate = json_object_new_object();
  7967. DEBUG_INFO("sendSignCertificateRequest...\n");
  7968. // Read csr file content
  7969. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7970. FILE *fp=fopen(CSR_CP,"r");
  7971. char *line = NULL;
  7972. size_t len = 0;
  7973. while(getline(&line, &len, fp) != -1)
  7974. {
  7975. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7976. {
  7977. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7978. }
  7979. }
  7980. fclose(fp);
  7981. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7982. random_uuid(guid);
  7983. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7984. json_object_put(SignCertificate);
  7985. LWS_Send(message);
  7986. sprintf(tempdata, "SignCertificate,0");
  7987. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7988. {
  7989. result = PASS;
  7990. }
  7991. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7992. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7993. return result;
  7994. }
  7995. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7996. {
  7997. mtrace();
  7998. int result = PASS;
  7999. char message[4096]={0};
  8000. char guid[37]={0};
  8001. char tempdata[128]={0};
  8002. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  8003. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  8004. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  8005. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  8006. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  8007. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  8008. random_uuid(guid);
  8009. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8010. json_object_put(SignedFirmwareStatusNotification);
  8011. LWS_Send(message);
  8012. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  8013. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8014. {
  8015. result = PASS;
  8016. }
  8017. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  8018. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  8019. return result;
  8020. }
  8021. //==========================================
  8022. // send confirm routine
  8023. //==========================================
  8024. int sendCancelReservationConfirmation(char *uuid,char *payload)
  8025. {
  8026. mtrace();
  8027. int result = FAIL;
  8028. char message[100]={0};
  8029. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8030. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8031. LWS_Send(message);
  8032. result = TRUE;
  8033. return result;
  8034. }
  8035. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8036. {
  8037. mtrace();
  8038. int result = FAIL;
  8039. char message[100]={0};
  8040. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8041. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8042. LWS_Send(message);
  8043. result = TRUE;
  8044. return result;
  8045. }
  8046. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8047. {
  8048. mtrace();
  8049. int result = FAIL;
  8050. char message[100]={0};
  8051. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8052. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8053. LWS_Send(message);
  8054. result = TRUE;
  8055. return result;
  8056. }
  8057. int sendClearCacheConfirmation(char *uuid,char *payload)
  8058. {
  8059. mtrace();
  8060. int result = FAIL;
  8061. char message[500]={0};
  8062. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8063. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8064. LWS_Send(message);
  8065. return result;
  8066. }
  8067. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8068. {
  8069. mtrace();
  8070. int result = FAIL;
  8071. char message[500]={0};
  8072. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8073. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8074. LWS_Send(message);
  8075. return result;
  8076. }
  8077. int sendDataTransferConfirmation(char *uuid,char *payload)
  8078. {
  8079. mtrace();
  8080. char statusStr[20]={0};
  8081. char dataStr[10]={0};
  8082. char sstr[20]={0};
  8083. int c = 0;
  8084. char *loc;
  8085. int result = FAIL;
  8086. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8087. /**********************status**************************/
  8088. loc = strstr(payload, "status");
  8089. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8090. c = 0;
  8091. while (loc[3+strlen("status")+c] != '\"')
  8092. {
  8093. sstr[c] = loc[3+strlen("status")+c];
  8094. c++;
  8095. }
  8096. sstr[c] = '\0';
  8097. strcpy(statusStr, sstr);
  8098. /**********************data**************************/
  8099. loc = strstr(payload, "data");
  8100. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8101. c = 0;
  8102. while (loc[3+strlen("data")+c] != '\"')
  8103. {
  8104. sstr[c] = loc[3+strlen("data")+c];
  8105. c++;
  8106. }
  8107. sstr[c] = '\0';
  8108. strcpy(dataStr, sstr);
  8109. return result;
  8110. }
  8111. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8112. {
  8113. mtrace();
  8114. int result = FAIL;
  8115. char message[1000]={0};
  8116. int CompositeScheduleIndex = 0;
  8117. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8118. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8119. if(nPeriod == 0)
  8120. {
  8121. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8122. {
  8123. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8124. ,MESSAGE_TYPE_CALLRESULT
  8125. ,uuid
  8126. ,payload
  8127. ,connectorIdInt);
  8128. }
  8129. else
  8130. {
  8131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8132. ,MESSAGE_TYPE_CALLRESULT
  8133. ,uuid
  8134. ,payload
  8135. ,connectorIdInt
  8136. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8137. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8138. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8139. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8140. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8141. }
  8142. }
  8143. else
  8144. {
  8145. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8146. ,MESSAGE_TYPE_CALLRESULT
  8147. ,uuid
  8148. ,payload
  8149. ,connectorIdInt
  8150. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8151. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8152. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8153. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8154. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8155. {
  8156. if (idx_sample == 0)
  8157. {
  8158. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8159. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8160. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8161. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8162. }
  8163. else
  8164. {
  8165. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8166. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8167. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8168. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8169. }
  8170. }
  8171. sprintf(message + strlen(message), "]}}]");
  8172. }
  8173. LWS_Send(message);
  8174. result = TRUE;
  8175. return result;
  8176. }
  8177. int sendGetConfigurationConfirmation(char *uuid)
  8178. {
  8179. mtrace();
  8180. int result = FAIL;
  8181. int MaxKeySupported = 0;
  8182. int sentConfigurationNumber= 0;
  8183. int sentunConfigurationNumber= 0;
  8184. char message[1024*10]={0};
  8185. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8186. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8187. //configuration key
  8188. json_object *GetConfiguration = json_object_new_object();
  8189. json_object *configurationKey = json_object_new_array();
  8190. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8191. {
  8192. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8193. {
  8194. json_object *keyValue = json_object_new_object();
  8195. json_object_object_add(keyValue, "key", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key));
  8196. json_object_object_add(keyValue, "readonly", atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1?json_object_new_boolean(1):json_object_new_boolean(0));
  8197. json_object_object_add(keyValue, "value", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value));
  8198. json_object_array_add(configurationKey, keyValue);
  8199. sentConfigurationNumber = sentConfigurationNumber + 1;
  8200. }
  8201. }
  8202. json_object *unknownKey = json_object_new_array();
  8203. if(UnknownKeynum != 0)
  8204. {
  8205. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8206. {
  8207. DEBUG_INFO("unknown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8208. json_object_array_add(unknownKey, json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
  8209. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8210. }
  8211. }
  8212. if((sentConfigurationNumber>0) && (sentunConfigurationNumber>0))
  8213. {
  8214. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8215. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8216. }
  8217. else if(sentConfigurationNumber>0)
  8218. {
  8219. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8220. json_object_put(unknownKey);
  8221. }
  8222. else
  8223. {
  8224. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8225. json_object_put(configurationKey);
  8226. }
  8227. sprintf(message,"[%d,\"%s\",%s]"
  8228. ,MESSAGE_TYPE_CALLRESULT
  8229. ,uuid
  8230. ,json_object_to_json_string_ext(GetConfiguration, JSON_C_TO_STRING_PLAIN));
  8231. json_object_put(GetConfiguration);
  8232. LWS_Send(message);
  8233. return result;
  8234. }
  8235. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8236. {
  8237. mtrace();
  8238. int result = FAIL;
  8239. char message[400]={0};
  8240. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8241. if(strcmp(payload,"")==0)
  8242. {
  8243. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8244. }
  8245. else
  8246. {
  8247. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8248. }
  8249. LWS_Send(message);
  8250. result = TRUE;
  8251. return result;
  8252. }
  8253. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8254. {
  8255. mtrace();
  8256. int result = FAIL;
  8257. char message[80]={0};
  8258. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8259. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8260. LWS_Send(message);
  8261. result = TRUE;
  8262. return result;
  8263. }
  8264. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8265. {
  8266. mtrace();
  8267. int result = FAIL;
  8268. char message[80]={0};
  8269. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8270. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8271. LWS_Send(message);
  8272. result = TRUE;
  8273. return result;
  8274. }
  8275. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8276. {
  8277. mtrace();
  8278. int result = FAIL;
  8279. char message[80]={0};
  8280. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8281. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8282. LWS_Send(message);
  8283. result = TRUE;
  8284. return result;
  8285. }
  8286. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8287. {
  8288. mtrace();
  8289. int result = FAIL;
  8290. char message[80]={0};
  8291. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8292. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8293. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8294. LWS_Send(message);
  8295. result = TRUE;
  8296. return result;
  8297. }
  8298. int sendResetConfirmation(char *uuid,char *payload)
  8299. {
  8300. mtrace();
  8301. int result = FAIL;
  8302. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8303. char message[80]={0};
  8304. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8305. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8306. LWS_Send(message);
  8307. result = TRUE;
  8308. return result;
  8309. }
  8310. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8311. {
  8312. mtrace();
  8313. int result = FAIL;
  8314. char message[500]={0};
  8315. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8316. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8317. LWS_Send(message);
  8318. result = TRUE;
  8319. return result;
  8320. }
  8321. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8322. {
  8323. mtrace();
  8324. int result = FAIL;
  8325. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8326. char message[80]={0};
  8327. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8328. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8329. LWS_Send(message);
  8330. result = TRUE;
  8331. return result;
  8332. }
  8333. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8334. {
  8335. mtrace();
  8336. int result = FAIL;
  8337. char message[80]={0};
  8338. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8339. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8340. LWS_Send(message);
  8341. result = TRUE;
  8342. return result;
  8343. }
  8344. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8345. {
  8346. mtrace();
  8347. int result = FAIL;
  8348. char message[80]={0};
  8349. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8350. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8351. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8352. LWS_Send(message);
  8353. result = TRUE;
  8354. return result;
  8355. }
  8356. int sendUpdateFirmwareConfirmation(char *uuid)
  8357. {
  8358. mtrace();
  8359. int result = FAIL;
  8360. char message[60]={0};
  8361. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8362. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8363. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8364. LWS_Send(message);
  8365. result = TRUE;
  8366. return result;
  8367. }
  8368. int sendCertificateSignedConfirmation(char *uuid)
  8369. {
  8370. mtrace();
  8371. int result = PASS;
  8372. char message[4096]={0};
  8373. json_object *CertificateSigned = json_object_new_object();
  8374. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8375. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8376. sprintf(message,"[%d,\"%s\",%s]"
  8377. ,MESSAGE_TYPE_CALLRESULT
  8378. ,uuid
  8379. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8380. json_object_put(CertificateSigned);
  8381. LWS_Send(message);
  8382. return result;
  8383. }
  8384. int sendDeleteCertificateConfirmation(char *uuid)
  8385. {
  8386. mtrace();
  8387. int result = PASS;
  8388. char message[4096]={0};
  8389. json_object *DeleteCertificate = json_object_new_object();
  8390. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8391. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8392. sprintf(message,"[%d,\"%s\",%s]"
  8393. ,MESSAGE_TYPE_CALLRESULT
  8394. ,uuid
  8395. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8396. json_object_put(DeleteCertificate);
  8397. LWS_Send(message);
  8398. return result;
  8399. }
  8400. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8401. {
  8402. mtrace();
  8403. int result = PASS;
  8404. char message[4096]={0};
  8405. json_object *ExtendedTriggerMessage = json_object_new_object();
  8406. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8407. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8408. sprintf(message,"[%d,\"%s\",%s]"
  8409. ,MESSAGE_TYPE_CALLRESULT
  8410. ,uuid
  8411. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8412. json_object_put(ExtendedTriggerMessage);
  8413. LWS_Send(message);
  8414. return result;
  8415. }
  8416. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8417. {
  8418. mtrace();
  8419. int result = PASS;
  8420. char message[4096]={0};
  8421. json_object *GetInstalledCertificateIds = json_object_new_object();
  8422. json_object *certificateHashDataDatas = json_object_new_array();
  8423. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8424. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8425. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8426. {
  8427. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8428. {
  8429. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8430. {
  8431. json_object *certificateHashData = json_object_new_object();
  8432. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8433. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8434. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8435. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8436. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8437. }
  8438. }
  8439. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8440. }
  8441. else
  8442. {
  8443. json_object_put(certificateHashDataDatas);
  8444. }
  8445. sprintf(message,"[%d,\"%s\",%s]"
  8446. ,MESSAGE_TYPE_CALLRESULT
  8447. ,uuid
  8448. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8449. json_object_put(GetInstalledCertificateIds);
  8450. LWS_Send(message);
  8451. return result;
  8452. }
  8453. int sendGetLogConfirmation(char *uuid)
  8454. {
  8455. mtrace();
  8456. int result = PASS;
  8457. char message[4096]={0};
  8458. json_object *GetLog = json_object_new_object();
  8459. DEBUG_INFO("sendGetLogConfirmation...\n");
  8460. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8461. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8462. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8463. sprintf(message,"[%d,\"%s\",%s]"
  8464. ,MESSAGE_TYPE_CALLRESULT
  8465. ,uuid
  8466. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8467. json_object_put(GetLog);
  8468. LWS_Send(message);
  8469. return result;
  8470. }
  8471. int sendInstallCertificateConfirmation(char *uuid)
  8472. {
  8473. mtrace();
  8474. int result = PASS;
  8475. char message[4096]={0};
  8476. json_object *InstallCertificate = json_object_new_object();
  8477. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8478. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8479. sprintf(message,"[%d,\"%s\",%s]"
  8480. ,MESSAGE_TYPE_CALLRESULT
  8481. ,uuid
  8482. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8483. json_object_put(InstallCertificate);
  8484. LWS_Send(message);
  8485. return result;
  8486. }
  8487. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8488. {
  8489. mtrace();
  8490. int result = PASS;
  8491. char message[4096]={0};
  8492. json_object *SignedUpdateFirmware = json_object_new_object();
  8493. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8494. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8495. sprintf(message,"[%d,\"%s\",%s]"
  8496. ,MESSAGE_TYPE_CALLRESULT
  8497. ,uuid
  8498. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8499. json_object_put(SignedUpdateFirmware);
  8500. LWS_Send(message);
  8501. return result;
  8502. }
  8503. int sendUnknownConfirmation(char *uuid)
  8504. {
  8505. mtrace();
  8506. int result = PASS;
  8507. char message[256]={0};
  8508. DEBUG_INFO("sendUnknownConfirmation...\n");
  8509. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8510. LWS_Send(message);
  8511. return result;
  8512. }
  8513. //==========================================
  8514. // Handle server request routine Start
  8515. //==========================================
  8516. int handleCancelReservationRequest(char *uuid, char *payload)
  8517. {
  8518. mtrace();
  8519. int result = FAIL;
  8520. int gunNO = 0;
  8521. int reservationIdInt = -1;
  8522. char comfirmstr[20];
  8523. DEBUG_INFO("handleCancelReservationRequest...\n");
  8524. json_object *CancelReservation;
  8525. CancelReservation = json_tokener_parse(payload);
  8526. if(!is_error(CancelReservation))
  8527. {
  8528. // Required data
  8529. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8530. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8531. }
  8532. json_object_put(CancelReservation);
  8533. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8534. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8535. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8536. if(reservationIdInt != -1)
  8537. {
  8538. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8539. //check Transaction active
  8540. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8542. {
  8543. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8544. {
  8545. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8546. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8547. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8548. {
  8549. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8550. }
  8551. else
  8552. {
  8553. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8554. }
  8555. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8556. goto end;
  8557. }
  8558. }
  8559. for (int index = 0; index < CCS_QUANTITY; index++)
  8560. {
  8561. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8562. {
  8563. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8564. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8565. if(gunType[2] == GUN_TYPE_CCS)
  8566. {
  8567. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8568. }
  8569. else
  8570. {
  8571. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8572. }
  8573. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8574. goto end;
  8575. }
  8576. }
  8577. for (int index = 0; index < GB_QUANTITY; index++)
  8578. {
  8579. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8580. {
  8581. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8582. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8583. if(gunType[2] == GUN_TYPE_GBT)
  8584. {
  8585. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8586. }
  8587. else
  8588. {
  8589. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8590. }
  8591. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8592. goto end;
  8593. }
  8594. }
  8595. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8596. {
  8597. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8598. {
  8599. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8600. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8601. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8602. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8603. goto end;
  8604. }
  8605. }
  8606. for (int index = 0; index < AC_QUANTITY; index++)
  8607. {
  8608. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8609. {
  8610. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8611. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8612. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8613. {
  8614. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8615. }
  8616. else
  8617. {
  8618. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8619. }
  8620. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8621. goto end;
  8622. }
  8623. }
  8624. }
  8625. //The reservationId does NOT match the reservationId
  8626. sendCancelReservationConfirmation(uuid, comfirmstr);
  8627. end:
  8628. // Fill in ocpp packet uuid
  8629. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8630. return result;
  8631. }
  8632. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8633. {
  8634. mtrace();
  8635. int result = FAIL;
  8636. int gunIndex = -1;
  8637. char typeStr[16]={0};
  8638. char comfirmstr[20];
  8639. int specificId = FALSE;
  8640. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8641. json_object *ChangeAvailability;
  8642. ChangeAvailability = json_tokener_parse(payload);
  8643. if(!is_error(ChangeAvailability))
  8644. {
  8645. // Required data
  8646. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8647. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8648. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8649. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8650. }
  8651. json_object_put(ChangeAvailability);
  8652. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8653. {
  8654. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8655. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8656. }
  8657. else if(gunIndex == 0)
  8658. {
  8659. for(int i=0; i < gunTotalNumber; i++)
  8660. {
  8661. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8662. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8663. }
  8664. }
  8665. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8666. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8667. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8668. {
  8669. specificId = TRUE;
  8670. }
  8671. if(specificId == FALSE)
  8672. goto end;
  8673. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8674. {
  8675. //----------------------gunIndex is 0 ------------------------------------------------//
  8676. if(gunIndex == 0)
  8677. {
  8678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8679. {
  8680. for(int i=0; i < gunTotalNumber; i++)
  8681. {
  8682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8683. {
  8684. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8685. {
  8686. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8687. {
  8688. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8689. goto end;
  8690. }
  8691. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8692. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8693. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8694. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8695. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8696. {
  8697. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8698. goto end;
  8699. }
  8700. }
  8701. }//END FOR CHAdeMO_QUANTITY
  8702. for (int index = 0; index < CCS_QUANTITY; index++)
  8703. {
  8704. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8705. {
  8706. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8707. {
  8708. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8709. goto end;
  8710. }
  8711. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8712. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8713. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8714. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8715. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8716. {
  8717. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8718. goto end;
  8719. }
  8720. }
  8721. }//END FOR CCS_QUANTITY
  8722. for (int index = 0; index < GB_QUANTITY; index++)
  8723. {
  8724. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8725. {
  8726. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8727. {
  8728. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8729. goto end;
  8730. }
  8731. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8732. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8733. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8734. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8735. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8736. {
  8737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8738. goto end;
  8739. }
  8740. }
  8741. }// END FOR GB_QUANTITY
  8742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8743. {
  8744. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8745. {
  8746. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8747. {
  8748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8749. goto end;
  8750. }
  8751. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8754. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8755. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8756. {
  8757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8758. goto end;
  8759. }
  8760. }
  8761. }// END FOR GENERAL_GUN_QUANTITY
  8762. for (int index = 0; index < AC_QUANTITY; index++)
  8763. {
  8764. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8765. {
  8766. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8767. {
  8768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8769. goto end;
  8770. }
  8771. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8772. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8773. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8774. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8775. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8776. {
  8777. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8778. goto end;
  8779. }
  8780. }
  8781. }//END FOR AC_QUANTITY
  8782. }// END FOR gunTotalNumber
  8783. }
  8784. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8785. {
  8786. for(int i=0; i < gunTotalNumber; i++)
  8787. {
  8788. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8789. {
  8790. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8791. goto end;
  8792. }
  8793. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8794. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8795. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8796. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8797. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8798. {
  8799. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8800. goto end;
  8801. }
  8802. }
  8803. }
  8804. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8805. goto end;
  8806. }
  8807. //----------------------gunIndex is not 0 ------------------------------------------------//
  8808. //check Transaction active
  8809. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8810. {
  8811. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8812. {
  8813. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8814. {
  8815. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8816. goto end;
  8817. }
  8818. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8819. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8820. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8821. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8822. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8823. {
  8824. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8825. goto end;
  8826. }
  8827. else
  8828. {
  8829. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8830. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8831. goto end;
  8832. }
  8833. }
  8834. }//END FOR CHAdeMO_QUANTITY
  8835. for (int index = 0; index < CCS_QUANTITY; index++)
  8836. {
  8837. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8838. {
  8839. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8840. {
  8841. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8842. goto end;
  8843. }
  8844. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8845. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8846. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8847. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8848. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8849. {
  8850. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8851. goto end;
  8852. }
  8853. else
  8854. {
  8855. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8856. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8857. goto end;
  8858. }
  8859. }
  8860. }//END FOR CCS_QUANTITY
  8861. for (int index = 0; index < GB_QUANTITY; index++)
  8862. {
  8863. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8864. {
  8865. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8866. {
  8867. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8868. goto end;
  8869. }
  8870. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8871. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8872. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8873. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8874. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8875. {
  8876. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8877. goto end;
  8878. }
  8879. else
  8880. {
  8881. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8882. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8883. goto end;
  8884. }
  8885. }
  8886. }// END FOR GB_QUANTITY
  8887. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8888. {
  8889. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8890. {
  8891. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8892. {
  8893. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8894. goto end;
  8895. }
  8896. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8897. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8898. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8899. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8900. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8901. {
  8902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8903. goto end;
  8904. }
  8905. else
  8906. {
  8907. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8908. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8909. goto end;
  8910. }
  8911. }
  8912. }// END FOR GENERAL_GUN_QUANTITY
  8913. for (int index = 0; index < AC_QUANTITY; index++)
  8914. {
  8915. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8916. {
  8917. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8918. {
  8919. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8920. goto end;
  8921. }
  8922. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8923. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8924. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8925. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8926. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8927. {
  8928. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8929. goto end;
  8930. }
  8931. else
  8932. {
  8933. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8934. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8935. goto end;
  8936. }
  8937. }
  8938. }//END FOR AC_QUANTITY
  8939. }//END FOR AvailabilityTypeStr[Inoperative]
  8940. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8941. {
  8942. //----------------------gunIndex is 0 ------------------------------------------------//
  8943. if(gunIndex == 0)
  8944. {
  8945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8946. {
  8947. for(int i=0; i < gunTotalNumber; i++)
  8948. {
  8949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8950. {
  8951. 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
  8952. {
  8953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8954. goto end;
  8955. }
  8956. }//END FOR CHAdeMO_QUANTITY
  8957. for (int index = 0; index < CCS_QUANTITY; index++)
  8958. {
  8959. 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
  8960. {
  8961. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8962. goto end;
  8963. }
  8964. }//END FOR CCS_QUANTITY
  8965. for (int index = 0; index < GB_QUANTITY; index++)
  8966. {
  8967. 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
  8968. {
  8969. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8970. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8971. goto end;
  8972. }
  8973. }// END FOR GB_QUANTITY
  8974. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8975. {
  8976. 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
  8977. {
  8978. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8979. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8980. goto end;
  8981. }
  8982. }// END FOR GENERAL_GUN_QUANTITY
  8983. for (int index = 0; index < AC_QUANTITY; index++)
  8984. {
  8985. 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
  8986. {
  8987. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8988. goto end;
  8989. }
  8990. }//END FOR CHAdeMO_QUANTITY
  8991. }// END FOR gunTotalNumber
  8992. }
  8993. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8994. {
  8995. for(int i=0; i < gunTotalNumber; i++)
  8996. {
  8997. for (int index = 0; index < AC_QUANTITY; index++)
  8998. {
  8999. 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
  9000. {
  9001. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9002. goto end;
  9003. }
  9004. }//END FOR CHAdeMO_QUANTITY
  9005. } // END FOR gunTotalNumber
  9006. }
  9007. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9008. goto end;
  9009. }
  9010. //----------------------gunIndex is not 0 ------------------------------------------------//
  9011. //check Transaction active
  9012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9013. {
  9014. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9015. {
  9016. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9017. goto end;
  9018. }
  9019. }//END FOR CHAdeMO_QUANTITY
  9020. for (int index = 0; index < CCS_QUANTITY; index++)
  9021. {
  9022. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9023. {
  9024. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9025. goto end;
  9026. }
  9027. }//END FOR CCS_QUANTITY
  9028. for (int index = 0; index < GB_QUANTITY; index++)
  9029. {
  9030. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9031. {
  9032. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9033. goto end;
  9034. }
  9035. }// END FOR GB_QUANTITY
  9036. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9037. {
  9038. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9039. {
  9040. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9041. goto end;
  9042. }
  9043. }// END FOR GENERAL_GUN_QUANTITY
  9044. for (int index = 0; index < AC_QUANTITY; index++)
  9045. {
  9046. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9047. {
  9048. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9049. goto end;
  9050. }
  9051. }//END FOR AC_QUANTITY
  9052. }//END FOR AvailabilityTypeStr[Operative]
  9053. end:
  9054. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9055. {
  9056. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9057. }
  9058. else
  9059. {
  9060. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9061. }
  9062. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9063. {
  9064. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9065. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9066. }
  9067. else if(gunIndex == 0)
  9068. {
  9069. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9070. {
  9071. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9072. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9073. }
  9074. }
  9075. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9076. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9077. return result;
  9078. }
  9079. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9080. {
  9081. mtrace();
  9082. int valueInvalid = NO;
  9083. int result = FAIL;
  9084. char keystr[40]={0};
  9085. char valuestr[501]={0}; //value should be limited in 500 bytes
  9086. char comfirmstr[20]={0};
  9087. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9088. json_object *ChangeConfiguration;
  9089. ChangeConfiguration = json_tokener_parse(payload);
  9090. if(!is_error(ChangeConfiguration))
  9091. {
  9092. // Required data
  9093. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9094. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9095. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9096. {
  9097. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9098. }
  9099. else
  9100. {
  9101. valueInvalid = YES;
  9102. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9103. }
  9104. }
  9105. json_object_put(ChangeConfiguration);
  9106. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9107. {
  9108. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9109. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9110. }
  9111. else
  9112. {
  9113. int status = setKeyValue(keystr, valuestr);
  9114. switch(status)
  9115. {
  9116. case ConfigurationStatus_Accepted:
  9117. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9118. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9119. StoreConfigurationTable();
  9120. break;
  9121. case RebootRequired:
  9122. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9123. StoreConfigurationTable();
  9124. break;
  9125. case NotSupported:
  9126. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9127. break;
  9128. case ConfigurationStatus_Rejected:
  9129. default:
  9130. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9131. break;
  9132. }
  9133. }
  9134. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9135. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9136. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9137. {
  9138. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9139. SetOcppConnStatus(FALSE);
  9140. }
  9141. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9142. {
  9143. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9144. }
  9145. return result;
  9146. }
  9147. int handleClearCacheRequest(char *uuid, char *payload)
  9148. {
  9149. mtrace();
  9150. int result = FAIL;
  9151. char comfirmstr[20];
  9152. char rmFileCmd[100]={0};
  9153. struct stat stats;
  9154. DEBUG_INFO("handleClearCacheRequest...\n");
  9155. stat("/Storage/OCPP", &stats);
  9156. // Check for directory existence
  9157. if (S_ISDIR(stats.st_mode) == 1)
  9158. {}
  9159. else
  9160. {
  9161. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9162. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9163. system(rmFileCmd);
  9164. }
  9165. if(OCPP_cleanLocalCache())
  9166. {
  9167. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9168. }
  9169. else
  9170. {
  9171. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9172. }
  9173. sendClearCacheConfirmation(uuid, comfirmstr);
  9174. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9175. return result;
  9176. }
  9177. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9178. {
  9179. mtrace();
  9180. int result = FAIL;
  9181. int resultRename;
  9182. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9183. char chargingProfilePurposeStr[26]={0};
  9184. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9185. char tempchargingProfilePurposeStr[26]={0};
  9186. char str[100]={0};
  9187. char fname[200]={0};
  9188. char comfirmstr[20]={0};
  9189. char word[1600]={0};
  9190. int clearflag = FALSE;
  9191. int chargingProfileIdIsNULL = FALSE;
  9192. int connectorIsNULL = FALSE;
  9193. int chargingProfilePurposeIsNULL = FALSE;
  9194. int stackLevelIsNULL = FALSE;
  9195. //int GotoEnd = FALSE;
  9196. FILE *fptr1, *fptr2;
  9197. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9198. int n_chargingProfile=0;
  9199. int isEmptyFile = FALSE;
  9200. char sLineWord[1600]={0};
  9201. char chargingProfiles[10][100]={0};
  9202. int ChargeProfileCount = 0;
  9203. int ch;
  9204. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9205. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9206. json_object *ClearChargingProfile;
  9207. ClearChargingProfile = json_tokener_parse(payload);
  9208. if(!is_error(ClearChargingProfile))
  9209. {
  9210. // Optional data
  9211. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9212. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9213. else
  9214. chargingProfileIdIsNULL = TRUE;
  9215. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9216. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9217. else
  9218. connectorIsNULL = TRUE;
  9219. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9220. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9221. else
  9222. chargingProfilePurposeIsNULL = TRUE;
  9223. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9224. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9225. else
  9226. stackLevelIsNULL = TRUE;
  9227. }
  9228. json_object_put(ClearChargingProfile);
  9229. if(connectorIdInt > 0)
  9230. {
  9231. if(chargingProfilePurposeIsNULL == TRUE)
  9232. {
  9233. int m = 0;
  9234. memset(fname, 0, ARRAY_SIZE(fname));
  9235. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9236. if((access(fname,F_OK))!=-1)
  9237. {
  9238. strcpy(chargingProfiles[m], fname);
  9239. m = m + 1;
  9240. }
  9241. memset(fname, 0, ARRAY_SIZE(fname));
  9242. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9243. if((access(fname,F_OK))!=-1)
  9244. {
  9245. strcpy(chargingProfiles[m], fname);
  9246. m = m + 1;
  9247. }
  9248. ChargeProfileCount = m;
  9249. }
  9250. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9251. {
  9252. //strcpy(fname, TxDefaultProfile_1_JSON);
  9253. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9254. if((access(fname,F_OK))!=-1)
  9255. {
  9256. strcpy(chargingProfiles[0], fname);
  9257. ChargeProfileCount = 1;
  9258. }
  9259. }
  9260. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9261. {
  9262. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9263. if((access(fname,F_OK))!=-1)
  9264. {
  9265. strcpy(chargingProfiles[0], fname);
  9266. ChargeProfileCount = 1;
  9267. }
  9268. //strcpy(fname, TxProfile_1_JSON);
  9269. }
  9270. }
  9271. else // Check all Charging Profiles
  9272. {
  9273. int i = 0;
  9274. char fnametemp[200]={0};
  9275. ChargeProfileCount = 0;
  9276. //Check ChargePointMaxProfile.json exit
  9277. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9278. {
  9279. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9280. i = i + 1;
  9281. }
  9282. //Check TxDefaultProfile_0.json exit
  9283. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9284. {
  9285. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9286. i = i + 1;
  9287. }
  9288. //Check TxDefaultProfile_%d.json
  9289. for(int j=1; j <= gunTotalNumber; j++)
  9290. {
  9291. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9292. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9293. if((access(fnametemp,F_OK))!=-1)
  9294. {
  9295. strcpy(chargingProfiles[i], fnametemp);
  9296. i = i + 1;
  9297. }
  9298. }
  9299. //Check TxProfile_%d.json
  9300. for(int j=1; j <= gunTotalNumber; j++)
  9301. {
  9302. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9303. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9304. if((access(fnametemp,F_OK))!=-1)
  9305. {
  9306. strcpy(chargingProfiles[i], fnametemp);
  9307. i = i + 1;
  9308. }
  9309. }
  9310. ChargeProfileCount = i;
  9311. }// End connectorIsNULL is TRUE
  9312. if(ChargeProfileCount == 0)
  9313. {
  9314. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9315. goto end;
  9316. }
  9317. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9318. {
  9319. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9320. goto end;
  9321. }
  9322. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9323. {
  9324. memset(str, 0, ARRAY_SIZE(str));
  9325. // clear temp file
  9326. sprintf(str,"rm -f %s",temp);
  9327. system(str);
  9328. for(int k=0; k < ChargeProfileCount; k++)
  9329. {
  9330. memset(str, 0, ARRAY_SIZE(str));
  9331. //clear file in C
  9332. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9333. system(str);
  9334. }
  9335. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9336. goto end;
  9337. }
  9338. else if(connectorIsNULL == TRUE)
  9339. {
  9340. for(int k=0; k < ChargeProfileCount; k++)
  9341. {
  9342. fptr1 = fopen(chargingProfiles[k], "r");
  9343. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9344. //Check Charging Profile Count
  9345. while(fscanf(fptr1, "%s", word) != EOF)
  9346. {
  9347. //DEBUG_INFO("word=%s\n",word);
  9348. if(strstr(word, "chargingProfileId")!= NULL)
  9349. {
  9350. //DEBUG_INFO("test chargingProfileId \n");
  9351. n_chargingProfile = n_chargingProfile + 1;
  9352. //DEBUG_INFO("chargingProfileId Found\n");
  9353. }
  9354. }
  9355. rewind(fptr1);
  9356. //search Charging Profile Element
  9357. //int i= 0;
  9358. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9359. {
  9360. json_object *tmpProfilee;
  9361. tmpProfilee = json_tokener_parse(sLineWord);
  9362. if(!is_error(tmpProfilee))
  9363. {
  9364. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9365. {
  9366. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9367. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9368. }
  9369. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9370. {
  9371. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9372. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9373. }
  9374. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9375. {
  9376. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9377. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9378. }
  9379. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9380. {
  9381. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9382. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9383. }
  9384. }
  9385. json_object_put(tmpProfilee);
  9386. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9387. {
  9388. //------- not write to fptr2-------//
  9389. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9390. //clearflag = TRUE;
  9391. }
  9392. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9393. {
  9394. //------- not write to fptr2-------//
  9395. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9396. }
  9397. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9398. {
  9399. //------- not write to fptr2-------//
  9400. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9401. }
  9402. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9403. {
  9404. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9405. }
  9406. else
  9407. {
  9408. fprintf(fptr2, sLineWord);//writing data into file
  9409. }
  9410. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9411. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9412. if(clearflag == TRUE)
  9413. {
  9414. fclose(fptr1);
  9415. fclose(fptr2);
  9416. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9417. system(str);
  9418. // clear temp file
  9419. sprintf(str,"rm -f %s",temp);
  9420. system(str);
  9421. }
  9422. else
  9423. {
  9424. fclose(fptr1);
  9425. fclose(fptr2);
  9426. memset(str, 0, ARRAY_SIZE(str));
  9427. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9428. system(str);
  9429. resultRename = rename(temp, chargingProfiles[k]);
  9430. if(resultRename == 0)
  9431. {
  9432. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9433. }
  9434. else
  9435. {
  9436. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9437. }
  9438. if(comfirmstr[0]== 0)
  9439. {
  9440. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9441. }
  9442. //Check chargingProfile is empty file
  9443. /*------ Read the file ----------------*/
  9444. fptr1=fopen(chargingProfiles[k],"r");
  9445. ch=fgetc(fptr1);
  9446. rewind(fptr1);
  9447. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9448. if(ch!=EOF)
  9449. {
  9450. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9451. {
  9452. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9453. if(sLineWord[0]=='\0')
  9454. {
  9455. isEmptyFile = TRUE;
  9456. break;
  9457. }
  9458. else
  9459. {
  9460. isEmptyFile = FALSE;
  9461. break;
  9462. }
  9463. }
  9464. }
  9465. else
  9466. isEmptyFile = TRUE;
  9467. fclose(fptr1);
  9468. if(isEmptyFile == TRUE)
  9469. {
  9470. memset(str, 0, ARRAY_SIZE(str));
  9471. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9472. system(str);
  9473. }
  9474. }
  9475. }// End of while(int k=0; k < ChargePointCount; k++)
  9476. }
  9477. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9478. {
  9479. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9480. for(int k=0; k < ChargeProfileCount; k++)
  9481. {
  9482. fptr1 = fopen(chargingProfiles[k], "r");
  9483. fptr2 = fopen(temp, "w+");
  9484. //Check Charging Profile Count
  9485. while(fscanf(fptr1, "%s", word) != EOF)
  9486. {
  9487. //DEBUG_INFO("word=%s\n",word);
  9488. if(strstr(word, "chargingProfileId")!= NULL)
  9489. {
  9490. n_chargingProfile = n_chargingProfile + 1;
  9491. }
  9492. }
  9493. rewind(fptr1);
  9494. //search Charging Profile Element
  9495. //int i= 0;
  9496. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9497. {
  9498. json_object *tmpProfilee;
  9499. tmpProfilee = json_tokener_parse(sLineWord);
  9500. if(!is_error(tmpProfilee))
  9501. {
  9502. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9503. {
  9504. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9505. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9506. }
  9507. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9508. {
  9509. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9510. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9511. }
  9512. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9513. {
  9514. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9515. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9516. }
  9517. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9518. {
  9519. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9520. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9521. }
  9522. }
  9523. json_object_put(tmpProfilee);
  9524. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9525. {
  9526. //------- not write to fptr2-------//
  9527. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9528. //clearflag = TRUE;
  9529. }
  9530. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9531. {
  9532. //------- not write to fptr2-------//
  9533. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9534. }
  9535. else if(stackLevelIsNULL == TRUE)
  9536. {
  9537. //Clear Whole File
  9538. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9539. clearflag = TRUE;
  9540. break;
  9541. }
  9542. else
  9543. {
  9544. fprintf(fptr2, sLineWord);//writing data into file
  9545. }
  9546. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9547. }
  9548. if(clearflag == TRUE)
  9549. {
  9550. fclose(fptr1);
  9551. fclose(fptr2);
  9552. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9553. system(str);
  9554. // clear temp file
  9555. sprintf(str,"rm -f %s",temp);
  9556. system(str);
  9557. }
  9558. else
  9559. {
  9560. fclose(fptr1);
  9561. fclose(fptr2);
  9562. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9563. system(str);
  9564. resultRename = rename(temp, chargingProfiles[k]);
  9565. if(resultRename == 0)
  9566. {
  9567. DEBUG_INFO("File ChargingProfile renamed successfully");
  9568. }
  9569. else
  9570. {
  9571. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9572. }
  9573. if(comfirmstr[0]== 0)
  9574. {
  9575. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9576. }
  9577. //Check chargingProfile is empty file
  9578. /*------ Read the file ----------------*/
  9579. fptr1=fopen(chargingProfiles[k],"r");
  9580. ch=fgetc(fptr1);
  9581. rewind(fptr1);
  9582. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9583. if(ch!=EOF)
  9584. {
  9585. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9586. {
  9587. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9588. if(sLineWord[0]=='\0')
  9589. {
  9590. isEmptyFile = TRUE;
  9591. break;
  9592. }
  9593. else
  9594. {
  9595. isEmptyFile = FALSE;
  9596. break;
  9597. }
  9598. }
  9599. }
  9600. else
  9601. isEmptyFile = TRUE;
  9602. fclose(fptr1);
  9603. if(isEmptyFile == TRUE)
  9604. {
  9605. memset(str, 0, ARRAY_SIZE(str));
  9606. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9607. system(str);
  9608. }
  9609. /*------- End of reading ---------------*/
  9610. }
  9611. } // while(int k=0; k < ChargeProfileCount; k++)
  9612. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9613. end:
  9614. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9615. {
  9616. if(connectorIdInt == 0)
  9617. {
  9618. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9619. {
  9620. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9621. }
  9622. }
  9623. else
  9624. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9625. }
  9626. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9627. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9628. return result;
  9629. }
  9630. void createFirmwareVersionByDataTransfer(void)
  9631. {
  9632. json_object *FirmwareDataTransfer = json_object_new_object();
  9633. // AC & DC model
  9634. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9635. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9636. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9637. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9638. // DC model
  9639. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9640. {
  9641. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9642. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9643. (gunType[3] != GUN_TYPE_UNKNOWN))
  9644. {
  9645. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9646. }
  9647. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9648. {
  9649. // DS DM DW
  9650. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9651. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9652. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9653. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9654. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9655. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9656. }
  9657. else
  9658. {
  9659. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9660. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9661. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9662. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9663. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9664. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9665. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9666. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9667. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9668. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9669. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9670. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9671. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9672. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9673. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9674. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9675. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9676. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9677. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9678. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9679. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9680. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9681. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9682. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9683. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9684. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9685. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9686. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9687. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9688. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9689. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9690. }
  9691. }
  9692. // 4G model
  9693. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9694. {
  9695. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9696. }
  9697. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9698. json_object_put(FirmwareDataTransfer);
  9699. }
  9700. int handleDataTransferRequest(char *uuid, char *payload)
  9701. {
  9702. mtrace();
  9703. json_object *response = json_object_new_object();
  9704. int result = FAIL;
  9705. char tempvendorId[255]={0};
  9706. char tempmessageId[50]={0};
  9707. char tempdata[10240]={0};
  9708. char message[20480]={0};
  9709. DEBUG_INFO("handleDataTransferRequest...\n");
  9710. if((uuid != NULL) && (payload != NULL))
  9711. {
  9712. json_object *DataTransfer;
  9713. DataTransfer = json_tokener_parse(payload);
  9714. if(!is_error(DataTransfer))
  9715. {
  9716. // Required data
  9717. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9718. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9719. // Optional data
  9720. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9721. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9722. if(json_object_object_get(DataTransfer, "data") != NULL)
  9723. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9724. result = PASS;
  9725. }
  9726. json_object_put(DataTransfer);
  9727. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9728. {
  9729. // Send all moudle firmware version on EVSE
  9730. createFirmwareVersionByDataTransfer();
  9731. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9732. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9733. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9734. json_object_put(response);
  9735. }
  9736. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9737. {
  9738. system("/usr/bin/run_tmate_restart.sh &");
  9739. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9740. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9741. json_object_put(response);
  9742. }
  9743. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9744. {
  9745. json_object *data;
  9746. data = json_tokener_parse(tempdata);
  9747. if(!is_error(data))
  9748. {
  9749. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9750. {
  9751. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9752. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9753. if(json_object_object_get(data, "SOC") != NULL)
  9754. {
  9755. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9756. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9757. }
  9758. if(json_object_object_get(data, "Energy") != NULL)
  9759. {
  9760. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9761. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9762. }
  9763. if(json_object_object_get(data, "Duration") != NULL)
  9764. {
  9765. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9766. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9767. }
  9768. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9769. }
  9770. else
  9771. {
  9772. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9773. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9774. }
  9775. }
  9776. else
  9777. {
  9778. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9779. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9780. }
  9781. json_object_put(data);
  9782. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9783. json_object_put(response);
  9784. }
  9785. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9786. {
  9787. json_object *data;
  9788. data = json_tokener_parse(tempdata);
  9789. if(!is_error(data))
  9790. {
  9791. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9792. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9793. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9794. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9795. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9796. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9797. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9798. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9799. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9800. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9801. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9802. }
  9803. else
  9804. {
  9805. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9806. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9807. }
  9808. json_object_put(data);
  9809. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9810. json_object_put(response);
  9811. }
  9812. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9813. {
  9814. json_object *data;
  9815. data = json_tokener_parse(tempdata);
  9816. if(!is_error(data))
  9817. {
  9818. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9819. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9820. if(json_object_object_get(data, "idToken") != NULL)
  9821. {
  9822. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9823. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9824. }
  9825. else
  9826. {
  9827. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9828. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9829. }
  9830. if(json_object_object_get(data, "price") != NULL) //v1.0
  9831. {
  9832. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9833. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9834. }
  9835. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9836. {
  9837. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9838. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9839. }
  9840. else
  9841. {
  9842. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9843. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9844. }
  9845. }
  9846. else
  9847. {
  9848. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9849. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9850. }
  9851. json_object_put(data);
  9852. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9853. json_object_put(response);
  9854. }
  9855. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9856. {
  9857. json_object *data;
  9858. data = json_tokener_parse(tempdata);
  9859. if(!is_error(data))
  9860. {
  9861. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9862. if(json_object_object_get(data, "txId") != NULL)
  9863. {
  9864. // California pricing V1.0
  9865. DEBUG_INFO("California pricing V1.0\n");
  9866. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9867. sprintf((char*)dmsVersion, "1.0");
  9868. for(int idx = 0;idx<gunTotalNumber;idx++)
  9869. {
  9870. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9871. {
  9872. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9873. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9874. if(json_object_object_get(data, "description") != NULL)
  9875. {
  9876. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9877. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9878. }
  9879. else
  9880. {
  9881. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9882. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9883. }
  9884. }
  9885. }
  9886. }
  9887. else if(json_object_object_get(data, "transactionId") != NULL)
  9888. {
  9889. // California pricing V2.0
  9890. DEBUG_INFO("California pricing V2.0\n");
  9891. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9892. sprintf((char*)dmsVersion, "2.0");
  9893. for(int idx=0;idx<gunTotalNumber;idx++)
  9894. {
  9895. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9896. {
  9897. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9898. if(json_object_object_get(data, "timestamp") != NULL)
  9899. {
  9900. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9901. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9902. }
  9903. else
  9904. {
  9905. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9906. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9907. }
  9908. if(json_object_object_get(data, "meterValue") != NULL)
  9909. {
  9910. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9911. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9912. }
  9913. else
  9914. {
  9915. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9916. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9917. }
  9918. if(json_object_object_get(data, "cost") != NULL)
  9919. {
  9920. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9921. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9922. }
  9923. else
  9924. {
  9925. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9926. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9927. }
  9928. if(json_object_object_get(data, "state") != NULL)
  9929. {
  9930. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9931. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9932. }
  9933. else
  9934. {
  9935. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9936. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9937. }
  9938. if(json_object_object_get(data, "chargingPrice") != NULL)
  9939. {
  9940. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9941. {
  9942. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9943. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9944. }
  9945. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9946. {
  9947. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9948. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9949. }
  9950. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9951. {
  9952. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9953. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9954. }
  9955. }
  9956. else
  9957. {
  9958. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9959. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9960. }
  9961. if(json_object_object_get(data, "idlePrice") != NULL)
  9962. {
  9963. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9964. {
  9965. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9966. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9967. }
  9968. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9969. {
  9970. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9971. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9972. }
  9973. }
  9974. if(json_object_object_get(data, "nextPeriod") != NULL)
  9975. {
  9976. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9977. {
  9978. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9979. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9980. }
  9981. else
  9982. {
  9983. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9984. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9985. }
  9986. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9987. {
  9988. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9989. {
  9990. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  9991. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  9992. }
  9993. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9994. {
  9995. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  9996. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  9997. }
  9998. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9999. {
  10000. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  10001. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  10002. }
  10003. }
  10004. else
  10005. {
  10006. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10007. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10008. }
  10009. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10010. {
  10011. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10012. {
  10013. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  10014. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  10015. }
  10016. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10017. {
  10018. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  10019. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  10020. }
  10021. }
  10022. }
  10023. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10024. {
  10025. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10026. {
  10027. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10028. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10029. }
  10030. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10031. {
  10032. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10033. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10034. }
  10035. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10036. {
  10037. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10038. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10039. }
  10040. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10041. {
  10042. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10043. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10044. }
  10045. }
  10046. }
  10047. }
  10048. }
  10049. else
  10050. {
  10051. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10052. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10053. }
  10054. }
  10055. else
  10056. {
  10057. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10058. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10059. }
  10060. json_object_put(data);
  10061. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10062. json_object_put(response);
  10063. }
  10064. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10065. {
  10066. json_object *data;
  10067. data = json_tokener_parse(tempdata);
  10068. if(!is_error(data))
  10069. {
  10070. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10071. if(json_object_object_get(data, "txId") != NULL)
  10072. {
  10073. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10074. for(int idx = 0;idx<gunTotalNumber;idx++)
  10075. {
  10076. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10077. {
  10078. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10079. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10080. if(json_object_object_get(data, "description") != NULL)
  10081. {
  10082. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10083. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10084. }
  10085. else
  10086. {
  10087. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10088. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10089. }
  10090. }
  10091. }
  10092. }
  10093. else if(json_object_object_get(data, "transactionId") != NULL)
  10094. {
  10095. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10096. for(int idx = 0;idx<gunTotalNumber;idx++)
  10097. {
  10098. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10099. {
  10100. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10101. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10102. if(json_object_object_get(data, "cost") != NULL)
  10103. {
  10104. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10105. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10106. }
  10107. else
  10108. {
  10109. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10110. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10111. }
  10112. if(json_object_object_get(data, "priceText") != NULL)
  10113. {
  10114. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10115. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10116. }
  10117. else
  10118. {
  10119. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10120. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10121. }
  10122. if(json_object_object_get(data, "qrCodeText") != NULL)
  10123. {
  10124. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10125. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10126. }
  10127. }
  10128. }
  10129. }
  10130. else
  10131. {
  10132. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10133. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10134. }
  10135. }
  10136. else
  10137. {
  10138. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10139. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10140. }
  10141. json_object_put(data);
  10142. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10143. json_object_put(response);
  10144. }
  10145. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10146. {
  10147. json_object *data;
  10148. data = json_tokener_parse(tempdata);
  10149. if(!is_error(data))
  10150. {
  10151. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10152. if(json_object_object_get(data, "Content_Type") != NULL)
  10153. {
  10154. 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))
  10155. {
  10156. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10157. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10158. {
  10159. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10160. }
  10161. }
  10162. else
  10163. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10164. }
  10165. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10166. }
  10167. else
  10168. {
  10169. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10170. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10171. }
  10172. json_object_put(data);
  10173. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10174. json_object_put(response);
  10175. }
  10176. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10177. {
  10178. json_object *data;
  10179. data = json_tokener_parse(tempdata);
  10180. if(!is_error(data))
  10181. {
  10182. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10183. if(json_object_object_get(data, "ConnectorId") != NULL)
  10184. {
  10185. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10186. }
  10187. if(json_object_object_get(data, "SerialNo") != NULL)
  10188. {
  10189. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10190. }
  10191. if(json_object_object_get(data, "Page_Index") != NULL)
  10192. {
  10193. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10194. }
  10195. if(json_object_object_get(data, "Duration") != NULL)
  10196. {
  10197. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10198. }
  10199. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10200. }
  10201. else
  10202. {
  10203. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10204. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10205. }
  10206. json_object_put(data);
  10207. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10208. json_object_put(response);
  10209. }
  10210. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10211. {
  10212. json_object *data;
  10213. data = json_tokener_parse(tempdata);
  10214. if(!is_error(data))
  10215. {
  10216. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10217. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10218. {
  10219. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10220. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10221. else
  10222. {
  10223. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10224. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10225. }
  10226. }
  10227. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10228. {
  10229. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10230. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10231. else
  10232. {
  10233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10234. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10235. }
  10236. }
  10237. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10238. {
  10239. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10240. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10241. else
  10242. {
  10243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10244. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10245. }
  10246. }
  10247. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10248. {
  10249. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10250. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10251. else
  10252. {
  10253. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10254. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10255. }
  10256. }
  10257. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10258. {
  10259. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10260. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10261. else
  10262. {
  10263. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10264. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10265. }
  10266. }
  10267. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10268. {
  10269. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10270. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10271. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10272. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10273. else
  10274. {
  10275. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10276. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10277. }
  10278. }
  10279. if(json_object_object_get(data, "isAuthentication") != NULL)
  10280. {
  10281. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10282. {
  10283. case 0:
  10284. case 1:
  10285. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10286. break;
  10287. default:
  10288. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10289. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10290. break;
  10291. }
  10292. }
  10293. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10294. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10295. }
  10296. else
  10297. {
  10298. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10299. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10300. }
  10301. json_object_put(data);
  10302. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10303. json_object_put(response);
  10304. }
  10305. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10306. {
  10307. json_object *data;
  10308. data = json_tokener_parse(tempdata);
  10309. if(!is_error(data))
  10310. {
  10311. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10312. {
  10313. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10314. {
  10315. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10316. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10317. }
  10318. else
  10319. {
  10320. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10321. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10322. }
  10323. }
  10324. else
  10325. {
  10326. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10327. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10328. }
  10329. }
  10330. else
  10331. {
  10332. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10333. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10334. }
  10335. json_object_put(data);
  10336. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10337. json_object_put(response);
  10338. }
  10339. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10340. {
  10341. json_object *data;
  10342. data = json_tokener_parse(tempdata);
  10343. if(!is_error(data))
  10344. {
  10345. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10346. if(json_object_object_get(data, "stationName") != NULL)
  10347. {
  10348. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10349. }
  10350. else
  10351. {
  10352. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10353. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10354. }
  10355. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10356. {
  10357. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10358. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10359. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10360. }
  10361. }
  10362. else
  10363. {
  10364. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10365. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10366. }
  10367. json_object_put(data);
  10368. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10369. json_object_put(response);
  10370. }
  10371. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10372. {
  10373. json_object *data;
  10374. data = json_tokener_parse(tempdata);
  10375. if(!is_error(data))
  10376. {
  10377. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10378. if(json_object_object_get(data, "weatherId") != NULL)
  10379. {
  10380. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10381. }
  10382. else
  10383. {
  10384. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10385. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10386. }
  10387. if(json_object_object_get(data, "Temperature") != NULL)
  10388. {
  10389. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10390. }
  10391. else
  10392. {
  10393. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10394. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10395. }
  10396. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10397. {
  10398. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10399. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10400. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10401. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10402. );
  10403. }
  10404. }
  10405. else
  10406. {
  10407. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10408. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10409. }
  10410. json_object_put(data);
  10411. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10412. json_object_put(response);
  10413. }
  10414. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10415. {
  10416. json_object *data;
  10417. data = json_tokener_parse(tempdata);
  10418. if(!is_error(data))
  10419. {
  10420. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10421. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10422. {
  10423. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10424. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10425. }
  10426. else
  10427. {
  10428. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10429. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10430. }
  10431. }
  10432. else
  10433. {
  10434. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10435. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10436. }
  10437. json_object_put(data);
  10438. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10439. json_object_put(response);
  10440. }
  10441. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10442. {
  10443. json_object *data;
  10444. data = json_tokener_parse(tempdata);
  10445. if(!is_error(data))
  10446. {
  10447. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10448. {
  10449. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10450. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10451. if(gun_index < gunTotalNumber)
  10452. {
  10453. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10454. {
  10455. json_object *responsedata = json_object_new_object();
  10456. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10457. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10458. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10459. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10460. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10461. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10462. }
  10463. else
  10464. {
  10465. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10466. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10467. }
  10468. }
  10469. else
  10470. {
  10471. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10472. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10473. }
  10474. }
  10475. else
  10476. {
  10477. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10478. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10479. }
  10480. }
  10481. else
  10482. {
  10483. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10484. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10485. }
  10486. json_object_put(data);
  10487. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10488. json_object_put(response);
  10489. }
  10490. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10491. {
  10492. json_object *data;
  10493. data = json_tokener_parse(tempdata);
  10494. if(!is_error(data))
  10495. {
  10496. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10497. int gun_index = 0;
  10498. if(json_object_object_get(data, "ConnectorId") != NULL)
  10499. {
  10500. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10501. if(json_object_object_get(data, "occupancySN") != NULL)
  10502. {
  10503. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10504. }
  10505. else
  10506. {
  10507. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10508. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10509. }
  10510. if(json_object_object_get(data, "actionId") != NULL)
  10511. {
  10512. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10513. }
  10514. else
  10515. {
  10516. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10517. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10518. }
  10519. }
  10520. else
  10521. {
  10522. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10523. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10524. }
  10525. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10526. {
  10527. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10528. }
  10529. }
  10530. else
  10531. {
  10532. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10533. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10534. }
  10535. json_object_put(data);
  10536. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10537. json_object_put(response);
  10538. }
  10539. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10540. {
  10541. json_object *data;
  10542. data = json_tokener_parse(tempdata);
  10543. if(!is_error(data))
  10544. {
  10545. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10546. if(json_object_object_get(data, "price") != NULL)
  10547. {
  10548. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10549. }
  10550. else
  10551. {
  10552. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10553. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10554. }
  10555. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10556. {
  10557. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10558. }
  10559. }
  10560. else
  10561. {
  10562. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10563. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  10564. }
  10565. json_object_put(data);
  10566. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10567. json_object_put(response);
  10568. }
  10569. // Support ISO-15118 related message
  10570. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10571. {
  10572. char cmdBuf[1024]={0};
  10573. sprintf(cmdBuf, "openssl req -newkey rsa:2048 -out %s -nodes -keyout %s -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=%s/OU=IT/CN=%s\" &", CSR_V2G, PRIVATE_KEY_V2G, ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10574. system(cmdBuf);
  10575. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10576. json_object *responsedata = json_object_new_object();
  10577. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10578. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10579. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10580. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10581. json_object_put(response);
  10582. }
  10583. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10584. {
  10585. json_object *data;
  10586. data = json_tokener_parse(tempdata);
  10587. if(!is_error(data))
  10588. {
  10589. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10590. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10591. fclose(fp);
  10592. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10593. json_object *responsedata = json_object_new_object();
  10594. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10595. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10596. else
  10597. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10598. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10599. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10600. }
  10601. else
  10602. {
  10603. json_object *responsedata = json_object_new_object();
  10604. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10605. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10606. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10607. }
  10608. json_object_put(data);
  10609. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10610. json_object_put(response);
  10611. }
  10612. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10613. {
  10614. json_object *data;
  10615. data = json_tokener_parse(tempdata);
  10616. DEBUG_INFO("DeleteCertificate processing...\n");
  10617. if(!is_error(data))
  10618. {
  10619. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10620. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10621. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10622. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10623. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10624. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10625. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10626. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10627. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10628. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10629. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10630. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10631. char temp[256] = {0};
  10632. char compareData[256] = {0};
  10633. int isMatch = TRUE;
  10634. // Check certV2G
  10635. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10636. {
  10637. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10638. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10639. isMatch = FALSE;
  10640. if(isMatch == TRUE)
  10641. {
  10642. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10643. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10644. isMatch = FALSE;
  10645. }
  10646. if(isMatch == TRUE)
  10647. {
  10648. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10649. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10650. isMatch = FALSE;
  10651. }
  10652. if(isMatch == TRUE)
  10653. {
  10654. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10655. system(temp);
  10656. json_object *responsedata = json_object_new_object();
  10657. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10658. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10659. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10660. }
  10661. else
  10662. {
  10663. json_object *responsedata = json_object_new_object();
  10664. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10665. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10666. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10667. }
  10668. }
  10669. else
  10670. {
  10671. json_object *responsedata = json_object_new_object();
  10672. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10673. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10674. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10675. }
  10676. }
  10677. else
  10678. {
  10679. json_object *responsedata = json_object_new_object();
  10680. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10681. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10682. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10683. }
  10684. json_object_put(data);
  10685. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10686. json_object_put(response);
  10687. }
  10688. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10689. {
  10690. json_object *data;
  10691. data = json_tokener_parse(tempdata);
  10692. if(!is_error(data))
  10693. {
  10694. /*
  10695. * TODO:
  10696. * 1. Query certificate to response
  10697. */
  10698. json_object *responsedata = json_object_new_object();
  10699. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10700. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10701. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10702. }
  10703. else
  10704. {
  10705. json_object *responsedata = json_object_new_object();
  10706. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10707. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10708. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10709. }
  10710. json_object_put(data);
  10711. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10712. json_object_put(response);
  10713. }
  10714. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10715. {
  10716. json_object *data;
  10717. data = json_tokener_parse(tempdata);
  10718. if(!is_error(data))
  10719. {
  10720. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10721. if(json_object_object_get(data, "certificateType") != NULL)
  10722. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10723. if(json_object_object_get(data, "certificate") != NULL)
  10724. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10725. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10726. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10727. char temp[1024];
  10728. FILE *fp = fopen(tempCert, "w");
  10729. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10730. fclose(fp);
  10731. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10732. char strExpDate[30];
  10733. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10734. fp = popen(temp, "r");
  10735. if(fp)
  10736. {
  10737. while(fgets(temp, sizeof(temp), fp) != NULL)
  10738. {
  10739. if(strstr(temp, "notAfter=") != NULL)
  10740. {
  10741. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10742. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10743. break;
  10744. }
  10745. }
  10746. }
  10747. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10748. struct tm tmExpDate;
  10749. struct timeb tbExpDate;
  10750. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10751. tbExpDate.time = mktime(&tmExpDate);
  10752. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10753. {
  10754. DEBUG_INFO("The enddate is already expired...\n");
  10755. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10756. }
  10757. else
  10758. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10759. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10760. {
  10761. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10762. {
  10763. if(access(ROOTCA_V2G,F_OK) != -1)
  10764. {
  10765. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10766. rename(ROOTCA_V2G, "/Storage/rootCaV2g_fallback.pem");
  10767. rename(tempCert, ROOTCA_V2G);
  10768. }
  10769. else
  10770. {
  10771. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10772. rename(tempCert, ROOTCA_V2G);
  10773. }
  10774. json_object *responsedata = json_object_new_object();
  10775. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10776. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10777. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10778. }
  10779. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10780. {
  10781. if(access(ROOTCA_MO,F_OK) != -1)
  10782. {
  10783. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10784. rename(ROOTCA_MO, "/Storage/rootCaMo_fallback.pem");
  10785. rename(tempCert, ROOTCA_MO);
  10786. }
  10787. else
  10788. {
  10789. DEBUG_INFO("No existed MORootCertificate. Creating...\n");
  10790. rename(tempCert, ROOTCA_MO);
  10791. }
  10792. json_object *responsedata = json_object_new_object();
  10793. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10794. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10795. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10796. }
  10797. else
  10798. {
  10799. json_object *responsedata = json_object_new_object();
  10800. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10801. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10802. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10803. }
  10804. }
  10805. else
  10806. {
  10807. json_object *responsedata = json_object_new_object();
  10808. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10809. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10810. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10811. }
  10812. }
  10813. else
  10814. {
  10815. json_object *responsedata = json_object_new_object();
  10816. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10817. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10818. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10819. }
  10820. json_object_put(data);
  10821. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10822. json_object_put(response);
  10823. }
  10824. else
  10825. {
  10826. // Can not find valid message id
  10827. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10828. }
  10829. }
  10830. else
  10831. {
  10832. // Payload is null
  10833. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10834. }
  10835. LWS_Send(message);
  10836. return result;
  10837. }
  10838. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10839. {
  10840. mtrace();
  10841. int result = FAIL;
  10842. int connectorIdInt, durationInt;
  10843. char chargingRateUnitStr[4]={0};
  10844. char comfirmstr[20];
  10845. int confirmPeriods = 0;
  10846. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10847. json_object *GetCompositeSchedule;
  10848. GetCompositeSchedule = json_tokener_parse(payload);
  10849. if(!is_error(GetCompositeSchedule))
  10850. {
  10851. // Required data
  10852. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10853. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10854. else
  10855. connectorIdInt = -1;
  10856. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10857. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10858. else
  10859. durationInt = 86400;
  10860. // Optional data
  10861. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10862. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10863. }
  10864. json_object_put(GetCompositeSchedule);
  10865. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10866. if((connectorIdInt == 0) ||
  10867. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10868. {
  10869. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10870. struct StructChargingProfile tmpProfile[1];
  10871. if(strstr(chargingRateUnitStr, "W") != NULL)
  10872. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10873. else
  10874. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10875. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10876. {
  10877. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10878. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10879. }
  10880. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10881. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10882. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10883. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10884. {
  10885. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10886. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10887. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10888. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10889. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10890. {
  10891. confirmPeriods = idx;
  10892. break;
  10893. }
  10894. }
  10895. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10896. {
  10897. confirmPeriods += 1;
  10898. }
  10899. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10900. }
  10901. else
  10902. {
  10903. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10904. }
  10905. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10906. return result;
  10907. }
  10908. int handleGetConfigurationRequest(char *uuid, char *payload)
  10909. {
  10910. mtrace();
  10911. int result = FAIL;
  10912. int MaxKeySupported = 0;
  10913. int n_keys = 0;
  10914. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10915. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10916. json_object *GetConfiguration;
  10917. GetConfiguration = json_tokener_parse(payload);
  10918. if(!is_error(GetConfiguration))
  10919. {
  10920. // Optional data
  10921. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10922. {
  10923. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10924. {
  10925. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10926. n_keys = idx + 1;
  10927. }
  10928. }
  10929. }
  10930. json_object_put(GetConfiguration);
  10931. UnknownKeynum = 0;
  10932. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10933. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10934. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10935. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10936. if(n_keys != 0)
  10937. {
  10938. for(int i=0;i<n_keys;i++)
  10939. {
  10940. getKeyValue(requestKey[i]);
  10941. }
  10942. }
  10943. else
  10944. {
  10945. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10946. getKeyValue("");
  10947. }
  10948. processUnkownKey();
  10949. sendGetConfigurationConfirmation(uuid);
  10950. return result;
  10951. }
  10952. static char fnamePlusPath[100]={0};
  10953. static char fnamePWithNoPath[60]={0};
  10954. void checkUploadLog(void)
  10955. {
  10956. FILE *fp;
  10957. /* Open the command for reading. */
  10958. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10959. if (fp == NULL) {
  10960. DEBUG_WARN("Failed to run command\n" );
  10961. exit(1);
  10962. }
  10963. int ftppathlen = 0;
  10964. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10965. int i = 0;
  10966. /* Read the output a line at a time - output it. */
  10967. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10968. if(i==0)
  10969. {
  10970. ftppathlen = strlen(fnamePlusPath);
  10971. DEBUG_INFO("%s\n", fnamePlusPath);
  10972. fnamePlusPath[ftppathlen]='\0';
  10973. break;
  10974. }
  10975. i= i+1;
  10976. }
  10977. /* close */
  10978. pclose(fp);
  10979. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10980. {
  10981. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10982. {
  10983. fnamePlusPath[k]='\0';
  10984. }
  10985. }
  10986. i=1;
  10987. //char fname[60]={0};
  10988. while(i < ftppathlen)
  10989. {
  10990. int len=ftppathlen-i;
  10991. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10992. {
  10993. DEBUG_INFO("compare '/' all right\n");
  10994. break;
  10995. }
  10996. i=i+1;
  10997. }
  10998. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10999. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11000. fnamePWithNoPath[i+1] = '\0';
  11001. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11002. {
  11003. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11004. {
  11005. fnamePWithNoPath[j]='\0';
  11006. }
  11007. }
  11008. FILE* fp1 = fopen(fnamePlusPath, "r");
  11009. if (fp1)
  11010. {
  11011. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11012. // file exists
  11013. fclose(fp1);
  11014. }
  11015. else
  11016. {
  11017. // file doesn't exist
  11018. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11019. }
  11020. }
  11021. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11022. {
  11023. mtrace();
  11024. int result = FAIL;
  11025. time_t CurrentTime;
  11026. struct tm *tm;
  11027. pthread_t th_Status;
  11028. CurrentTime = time(NULL);
  11029. tm = localtime(&CurrentTime);
  11030. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11031. sprintf((char*)ShmOCPP16Data->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);
  11032. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11033. if(!interLock.isGetDiagnosticGoing)
  11034. {
  11035. interLock.isGetDiagnosticGoing = 1;
  11036. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11037. sleep(1);
  11038. }
  11039. else
  11040. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11041. return result;
  11042. }
  11043. void* GetDiagnosticsProcess(void* data)
  11044. {
  11045. pthread_detach(pthread_self());
  11046. mtrace();
  11047. int retriesInt=0, retryIntervalInt=0;
  11048. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11049. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  11050. int port=0;
  11051. int isSuccess = FALSE;
  11052. char cmdBuf[2048];
  11053. struct tm *tmNow;
  11054. time_t CurrentTime;
  11055. struct tm tmStart;
  11056. struct tm tmStop;
  11057. CurrentTime = time(NULL);
  11058. tmNow=localtime(&CurrentTime);
  11059. uint16_t targetYear, targetMonth;
  11060. json_object *GetDiagnostics;
  11061. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11062. GetDiagnostics = json_tokener_parse(data);
  11063. if(!is_error(GetDiagnostics))
  11064. {
  11065. // Required data
  11066. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11067. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11068. // Optional data
  11069. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11070. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11071. else
  11072. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11073. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11074. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11075. else
  11076. retryIntervalInt = 30;
  11077. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11078. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11079. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11080. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11081. }
  11082. json_object_put(GetDiagnostics);
  11083. // Notify CSU to get log of dispensers.
  11084. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  11085. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  11086. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  11087. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  11088. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  11089. )
  11090. {
  11091. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StartTime,"%s",startTimestr);
  11092. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StopTime,"%s",stopTimestr);
  11093. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = TRUE;
  11094. struct timespec timerGetDiagnostics;
  11095. refreshStartTimer(&timerGetDiagnostics);
  11096. while(ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq != FALSE)
  11097. {
  11098. if(getDiffSecNow(timerGetDiagnostics)>=180)
  11099. {
  11100. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = FALSE;
  11101. DEBUG_INFO("Waiting log of dispenser timeout.");
  11102. }
  11103. }
  11104. }
  11105. // Pack log to compress file
  11106. 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) &&
  11107. (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))
  11108. {
  11109. // Pack system log
  11110. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11111. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11112. targetYear = tmStart.tm_year;
  11113. targetMonth = tmStart.tm_mon;
  11114. do
  11115. {
  11116. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11117. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11118. if(targetMonth+1>=13)
  11119. {
  11120. targetYear += 1;
  11121. targetMonth = 1;
  11122. }
  11123. else
  11124. {
  11125. targetMonth += 1;
  11126. }
  11127. }while((targetYear < (tmNow->tm_year+1900)) ||
  11128. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11129. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11130. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11131. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  11132. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  11133. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  11134. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  11135. system(cmdBuf);
  11136. // Pack charging & event log
  11137. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11138. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11139. targetYear = tmStart.tm_year;
  11140. targetMonth = tmStart.tm_mon;
  11141. do
  11142. {
  11143. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11144. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  11145. if(targetMonth+1>=13)
  11146. {
  11147. targetYear += 1;
  11148. targetMonth = 1;
  11149. }
  11150. else
  11151. {
  11152. targetMonth += 1;
  11153. }
  11154. }while((targetYear < (tmNow->tm_year+1900)) ||
  11155. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11156. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11157. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11158. system(cmdBuf);
  11159. // Combine log file
  11160. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11161. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11162. }
  11163. else
  11164. {
  11165. system("exec /root/logPackTools 'log' 6");
  11166. }
  11167. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11168. system(cmdBuf);
  11169. checkUploadLog();
  11170. //****************location*******************/
  11171. if(strcmp(locationstr,"")==0)
  11172. {
  11173. DEBUG_INFO("location is <Empty>!\n");
  11174. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11175. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11176. goto end;
  11177. }
  11178. memset(protocol, 0, ARRAY_SIZE(protocol));
  11179. memset(user, 0, ARRAY_SIZE(user) );
  11180. memset(password, 0, ARRAY_SIZE(password));
  11181. memset(host, 0, ARRAY_SIZE(host));
  11182. memset(path, 0, ARRAY_SIZE(path));
  11183. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11184. memset(host1, 0, ARRAY_SIZE(host1));
  11185. memset(path1, 0, ARRAY_SIZE(path1));
  11186. /*location: ftp://user:password@host:port/path*/
  11187. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11188. if((access(fnamePlusPath,F_OK))!=-1)
  11189. {
  11190. DEBUG_INFO("fnamePlusPath exist.\n");
  11191. }
  11192. else
  11193. {
  11194. DEBUG_INFO("fnamePlusPath not exist!\n");
  11195. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11196. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11197. goto end;
  11198. }
  11199. if(strchr(locationstr,'@')==NULL)
  11200. {
  11201. sscanf(locationstr,
  11202. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11203. protocol, host, &port, path);
  11204. strcpy(user,"anonymous");
  11205. strcpy(password,"");
  11206. }
  11207. else
  11208. {
  11209. //DEBUG_INFO("pch=%s\n", pch);
  11210. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11211. protocol, user, password, host, &port, path);
  11212. }
  11213. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11214. {
  11215. DEBUG_INFO("protocol is not ftp/http ! \n");
  11216. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11217. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11218. goto end;
  11219. }
  11220. if(strncmp(locationstr,"http", 4) == 0)
  11221. {
  11222. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11223. sprintf(ftppath,"/%s", path);
  11224. do
  11225. {
  11226. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11227. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11228. sleep(3);
  11229. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11230. if(!isSuccess)
  11231. {
  11232. DEBUG_INFO("Diagnostics fail.\n");
  11233. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11234. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11235. sleep(retryIntervalInt);
  11236. }
  11237. else
  11238. {
  11239. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11240. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11242. }
  11243. retriesInt--;
  11244. }while((isSuccess == 0)&&(retriesInt >= 0));
  11245. }
  11246. else
  11247. {
  11248. sscanf(host,"%[^/]%s",host1, path1);
  11249. if(strlen(path) > 0)
  11250. sprintf(ftppath,"/%s", path);
  11251. else
  11252. sprintf(ftppath,"/%s", path1);
  11253. int ftppathlen=strlen(ftppath);
  11254. int i=1;
  11255. char filenametemp[50];
  11256. while(i < ftppathlen)
  11257. {
  11258. int len=ftppathlen-i;
  11259. if(ftppath[len]== 47) // '/' ascll code: 47
  11260. {
  11261. DEBUG_INFO("find '/' all right\n");
  11262. break;
  11263. }
  11264. i=i+1;
  11265. }
  11266. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11267. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11268. filenametemp[i+1] = 0;
  11269. if(port == 0)
  11270. port = 21;
  11271. do
  11272. {
  11273. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11274. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11275. sleep(3);
  11276. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11277. if(!isSuccess)
  11278. {
  11279. DEBUG_INFO("Diagnostics fail.\n");
  11280. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11281. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11282. sleep(retryIntervalInt);
  11283. }
  11284. else
  11285. {
  11286. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11287. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11288. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11289. }
  11290. retriesInt--;
  11291. }while((!isSuccess)&&(retriesInt >= 0));
  11292. }
  11293. end:
  11294. system("rm -f /mnt/*");
  11295. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  11296. sleep(5);
  11297. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11298. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11299. interLock.isGetDiagnosticGoing = 0;
  11300. pthread_exit(NULL);
  11301. }
  11302. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11303. {
  11304. mtrace();
  11305. int result = FAIL;
  11306. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11307. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11308. {
  11309. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11310. locallistVersion = -1;
  11311. }
  11312. else
  11313. {
  11314. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11315. locallistVersion = 0;
  11316. OCPP_getListVerion();
  11317. }
  11318. //from db.OCPP_getListVerion
  11319. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11320. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11321. sendGetLocalListVersionConfirmation(uuid,"");
  11322. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11323. return result;
  11324. }
  11325. int handleRemoteStartRequest(char *uuid, char *payload)
  11326. {
  11327. mtrace();
  11328. int result = PASS;
  11329. int connectorIdInt=-1;
  11330. int tempIndex = 0;
  11331. char comfirmstr[20]={0};
  11332. char cmdBuf[512];
  11333. json_object *RemoteStartTransaction;
  11334. FILE *fp;
  11335. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11336. if(server_pending == TRUE)
  11337. {
  11338. result = FAIL;
  11339. }
  11340. RemoteStartTransaction = json_tokener_parse(payload);
  11341. if(!is_error(RemoteStartTransaction))
  11342. {
  11343. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11344. {
  11345. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11346. }
  11347. else
  11348. {
  11349. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11350. {
  11351. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11352. {
  11353. connectorIdInt = (gun_index+1);
  11354. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11355. break;
  11356. }
  11357. }
  11358. }
  11359. if(connectorIdInt == 0)
  11360. {
  11361. DEBUG_WARN("Connector id shall not equal 0.\n");
  11362. result = FAIL;
  11363. }
  11364. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11365. {
  11366. DEBUG_WARN("idTag should not be NULL.\n");
  11367. result = FAIL;
  11368. }
  11369. else if(connectorIdInt == -1)
  11370. {
  11371. DEBUG_INFO("Connector id does not specific.\n");
  11372. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11373. {
  11374. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11375. // Required data
  11376. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11377. // Optional data
  11378. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11379. {
  11380. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11381. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11382. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11383. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11384. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11385. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11386. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11387. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11388. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11389. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11390. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11391. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11392. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11393. {
  11394. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  11395. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11396. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  11397. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11398. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  11399. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11400. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  11401. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11402. {
  11403. 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++)
  11404. {
  11405. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  11406. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  11407. 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)
  11408. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  11409. }
  11410. }
  11411. }
  11412. }
  11413. else
  11414. {
  11415. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11416. }
  11417. }
  11418. }
  11419. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11420. {
  11421. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11422. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11423. // Required data
  11424. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11425. // Optional data
  11426. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11427. {
  11428. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11429. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11430. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11431. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11432. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11433. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11434. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11435. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11436. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11437. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11438. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11439. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11440. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11441. {
  11442. sprintf((char*)ShmOCPP16Data->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")));
  11443. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11444. ShmOCPP16Data->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"));
  11445. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11446. ShmOCPP16Data->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"));
  11447. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11448. sprintf((char*)ShmOCPP16Data->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")));
  11449. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11450. {
  11451. 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++)
  11452. {
  11453. ShmOCPP16Data->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"));
  11454. ShmOCPP16Data->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"));
  11455. 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)
  11456. ShmOCPP16Data->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"));
  11457. }
  11458. }
  11459. }
  11460. }
  11461. else
  11462. {
  11463. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11464. }
  11465. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') && (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W'))
  11466. {
  11467. DEBUG_INFO("Checking charging status for DW series...\n");
  11468. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11469. {
  11470. if(cpinitateMsg.bits[gun_index].isOnCharging ||
  11471. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL) ||
  11472. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing") != NULL))
  11473. {
  11474. DEBUG_INFO("Found gun-%d is in charging.\n", gun_index);
  11475. if(connectorIdInt != (gun_index+1))
  11476. {
  11477. DEBUG_WARN("DWseries--> Other connector is in charging.\n");
  11478. result = FAIL;
  11479. break;
  11480. }
  11481. }
  11482. }
  11483. }
  11484. }
  11485. else
  11486. {
  11487. DEBUG_WARN("Connector id is over maximun value.\n");
  11488. result = FAIL;
  11489. }
  11490. }
  11491. if(result == PASS)
  11492. {
  11493. if(connectorIdInt > 0)
  11494. {
  11495. DEBUG_INFO("Specified gun-%d type: %d\n", (connectorIdInt -1), gunType[connectorIdInt -1]);
  11496. //check Transaction active
  11497. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11498. {
  11499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11500. {
  11501. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11502. }
  11503. else
  11504. {
  11505. tempIndex = connectorIdInt -1;
  11506. }
  11507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11508. {
  11509. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11510. {
  11511. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11512. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11513. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11514. {
  11515. //Reserved
  11516. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11517. }
  11518. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11519. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11520. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11521. {
  11522. //Reserved
  11523. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11524. {
  11525. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11526. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11527. goto end;
  11528. }
  11529. }
  11530. else
  11531. {
  11532. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11533. {
  11534. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11535. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11536. goto end;
  11537. }
  11538. }//END FOR ELSE
  11539. }
  11540. }// END FOR CHAdeMO_QUANTITY
  11541. }
  11542. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11543. {
  11544. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11545. {
  11546. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11547. }
  11548. else
  11549. {
  11550. tempIndex = connectorIdInt -1;
  11551. }
  11552. for (int index = 0; index < CCS_QUANTITY; index++)
  11553. {
  11554. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11555. {
  11556. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11557. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11558. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11559. {
  11560. //Reserved
  11561. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11562. }
  11563. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11564. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11565. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11566. {
  11567. //Reserved
  11568. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11569. {
  11570. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11571. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11572. goto end;
  11573. }
  11574. }
  11575. else
  11576. {
  11577. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11578. {
  11579. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11580. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11581. goto end;
  11582. }
  11583. }// END FOR ELSE
  11584. }
  11585. }// END FOR CCS_QUANTITY
  11586. }
  11587. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11588. {
  11589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11590. {
  11591. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11592. }
  11593. else
  11594. {
  11595. tempIndex = connectorIdInt -1;
  11596. }
  11597. for (int index = 0; index < GB_QUANTITY; index++)
  11598. {
  11599. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11600. {
  11601. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11602. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11603. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11604. {
  11605. //Reserved
  11606. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11607. }
  11608. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11609. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11610. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11611. {
  11612. //Reserved
  11613. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11614. {
  11615. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11616. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11617. goto end;
  11618. }
  11619. }
  11620. else
  11621. {
  11622. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11623. {
  11624. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11625. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11626. goto end;
  11627. }
  11628. }// END FOR ELSE
  11629. }
  11630. } // END FOR GB_QUANTITY
  11631. }
  11632. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11633. {
  11634. tempIndex = connectorIdInt -1;
  11635. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11636. {
  11637. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11638. {
  11639. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11640. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11641. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11642. {
  11643. //Reserved
  11644. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11645. }
  11646. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11647. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11648. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11649. {
  11650. //Reserved
  11651. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11652. {
  11653. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11654. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11655. goto end;
  11656. }
  11657. }
  11658. else
  11659. {
  11660. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11661. {
  11662. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11663. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11664. goto end;
  11665. }
  11666. }// END FOR ELSE
  11667. }
  11668. } // END FOR GB_QUANTITY
  11669. }
  11670. else
  11671. {
  11672. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11673. {
  11674. tempIndex = 2;
  11675. }
  11676. else
  11677. {
  11678. tempIndex = connectorIdInt -1;
  11679. }
  11680. for (int index = 0; index < AC_QUANTITY; index++)
  11681. {
  11682. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11683. {
  11684. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11685. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11686. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11687. {
  11688. //Reserved
  11689. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11690. }
  11691. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11692. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11693. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11694. {
  11695. //Reserved
  11696. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11697. {
  11698. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11699. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11700. goto end;
  11701. }
  11702. }
  11703. else
  11704. {
  11705. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11706. {
  11707. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11708. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11709. goto end;
  11710. }
  11711. }//END FOR ELSE
  11712. }
  11713. }// END FOR AC_QUANTITY
  11714. }
  11715. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11716. {
  11717. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11718. {
  11719. // Save profile to file
  11720. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11721. system(cmdBuf);
  11722. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11723. fp = fopen(cmdBuf, "w");
  11724. 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));
  11725. fclose(fp);
  11726. }
  11727. else
  11728. {
  11729. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11730. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11731. goto end;
  11732. }
  11733. }
  11734. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11735. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11736. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11737. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11738. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11739. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11740. }
  11741. else
  11742. {
  11743. uint8_t isHasIdleConnector = FALSE;
  11744. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11745. {
  11746. DEBUG_INFO("Check not specified gun-%d type: %d\n", gun_index, gunType[gun_index]);
  11747. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11748. {
  11749. isHasIdleConnector = TRUE;
  11750. break;
  11751. }
  11752. }
  11753. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11754. {
  11755. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11756. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11757. {
  11758. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11759. {
  11760. // Save profile to file
  11761. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11762. system(cmdBuf);
  11763. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11764. fp = fopen(cmdBuf, "w");
  11765. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11766. fclose(fp);
  11767. refreshStartTimer(&clientTime.RemoteStartWait);
  11768. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11769. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11770. }
  11771. else
  11772. {
  11773. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11774. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11775. }
  11776. }
  11777. else
  11778. {
  11779. refreshStartTimer(&clientTime.RemoteStartWait);
  11780. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11781. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11782. }
  11783. }
  11784. else
  11785. {
  11786. DEBUG_INFO("There is not any connector is idle.\n");
  11787. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11788. }
  11789. }
  11790. }
  11791. else
  11792. {
  11793. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11794. }
  11795. end:
  11796. json_object_put(RemoteStartTransaction);
  11797. sendRemoteStartConfirmation(uuid, comfirmstr);
  11798. return result;
  11799. }
  11800. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11801. {
  11802. mtrace();
  11803. int result = FAIL;
  11804. int match = FALSE;
  11805. int GunNO = 0;
  11806. int tempIndex = 0;
  11807. int transactionIdInt=0;
  11808. int transactionIdIsNULL= TRUE;
  11809. char comfirmstr[20];
  11810. json_object *RemoteStopTransaction;
  11811. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11812. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11813. if(server_pending == TRUE)
  11814. {
  11815. return 0;
  11816. }
  11817. RemoteStopTransaction = json_tokener_parse(payload);
  11818. if(!is_error(RemoteStopTransaction))
  11819. {
  11820. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11821. {
  11822. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11823. transactionIdIsNULL = FALSE;
  11824. }
  11825. }
  11826. json_object_put(RemoteStopTransaction);
  11827. if(transactionIdIsNULL == FALSE)
  11828. {
  11829. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11830. {
  11831. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11832. {
  11833. //check Transaction active
  11834. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11835. {
  11836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11837. {
  11838. tempIndex = ((gun_index==2) ? 1: 0);
  11839. }
  11840. else
  11841. {
  11842. tempIndex = gun_index;
  11843. }
  11844. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11845. {
  11846. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11847. {
  11848. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11849. {
  11850. match = TRUE;
  11851. GunNO = gun_index;
  11852. }
  11853. }
  11854. }// END FOR CHAdeMO_QUANTITY
  11855. }
  11856. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11857. {
  11858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11859. {
  11860. tempIndex = ((gun_index==2) ? 1: 0);
  11861. }
  11862. else
  11863. {
  11864. tempIndex = gun_index;
  11865. }
  11866. for (int index = 0; index < CCS_QUANTITY; index++)
  11867. {
  11868. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11869. {
  11870. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11871. {
  11872. match = TRUE;
  11873. GunNO = gun_index;
  11874. }
  11875. }
  11876. }// END FOR CCS_QUANTITY
  11877. }
  11878. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11879. {
  11880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11881. {
  11882. tempIndex = ((gun_index==2) ? 1: 0);
  11883. }
  11884. else
  11885. {
  11886. tempIndex = gun_index;
  11887. }
  11888. for (int index = 0; index < GB_QUANTITY; index++)
  11889. {
  11890. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11891. {
  11892. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11893. {
  11894. match = TRUE;
  11895. GunNO = gun_index;
  11896. }
  11897. }
  11898. }// END FOR GB_QUANTITY
  11899. }
  11900. else if(gunType[gun_index] == GUN_TYPE_DO)
  11901. {
  11902. tempIndex = gun_index;
  11903. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11904. {
  11905. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11906. {
  11907. 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
  11908. {
  11909. match = TRUE;
  11910. GunNO = gun_index;
  11911. }
  11912. }
  11913. }// END FOR GB_QUANTITY
  11914. }
  11915. else
  11916. {
  11917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11918. {
  11919. tempIndex = 2;
  11920. }
  11921. else
  11922. {
  11923. tempIndex = gun_index;
  11924. }
  11925. for (int index = 0; index < AC_QUANTITY; index++)
  11926. {
  11927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11928. {
  11929. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11930. {
  11931. match = TRUE;
  11932. GunNO = gun_index;
  11933. }
  11934. }
  11935. }// END FOR CHAdeMO_QUANTITY
  11936. } // END FOR AC ELSE
  11937. }// CHECK IF ResponseTransactionId == transactionIdInt
  11938. }//END FOR
  11939. if( match == TRUE)
  11940. {
  11941. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11942. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11943. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11944. }
  11945. else
  11946. {
  11947. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11948. }
  11949. }
  11950. else
  11951. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11952. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11953. return result;
  11954. }
  11955. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11956. {
  11957. mtrace();
  11958. int result = FAIL;
  11959. int connectorIdInt=0, reservationIdInt=0;
  11960. int tempIndex = 0;
  11961. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11962. char comfirmstr[20]={0};
  11963. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11964. int c = 0;
  11965. char *loc;
  11966. //char *ptr;
  11967. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11968. strcpy(sstrtemp, stringtrimspace(payload));
  11969. //***(1)connectorId ****/
  11970. c=0;
  11971. loc = strstr(sstrtemp, "connectorId");
  11972. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11973. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11974. {
  11975. sstr[c] = loc[strlen("connectorId")+2+c];
  11976. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11977. c++;
  11978. }
  11979. sstr[c] = '\0';
  11980. connectorIdInt = atoi(sstr);
  11981. //***(2)expiryDate ****/
  11982. loc = strstr(sstrtemp, "expiryDate");
  11983. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11984. c = 0;
  11985. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11986. {
  11987. sstr[c] = loc[3+strlen("expiryDate")+c];
  11988. c++;
  11989. }
  11990. sstr[c] = '\0';
  11991. strcpy(expiryDatestr, sstr);
  11992. //***(3)idTag ****/
  11993. loc = strstr(sstrtemp, "idTag");
  11994. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11995. c = 0;
  11996. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11997. {
  11998. sstr[c] = loc[3+strlen("idTag")+c];
  11999. c++;
  12000. }
  12001. sstr[c] = '\0';
  12002. strcpy(idTagstr, sstr);
  12003. //***(4)parentIdTag ****/
  12004. loc = strstr(sstrtemp, "parentIdTag");
  12005. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12006. c = 0;
  12007. if(loc == NULL)
  12008. {
  12009. strcpy(parentIdTagstr, "");
  12010. }
  12011. else
  12012. {
  12013. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  12014. {
  12015. sstr[c] = loc[3+strlen("parentIdTag")+c];
  12016. c++;
  12017. }
  12018. sstr[c] = '\0';
  12019. strcpy(parentIdTagstr, sstr);
  12020. }
  12021. //***(5)reservationId ****/
  12022. c=0;
  12023. loc = strstr(sstrtemp, "reservationId");
  12024. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12025. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12026. {
  12027. sstr[c] = loc[strlen("reservationId")+2+c];
  12028. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12029. c++;
  12030. }
  12031. sstr[c] = '\0';
  12032. reservationIdInt = atoi(sstr);
  12033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12034. /*
  12035. enum SYSTEM_STATUS
  12036. {
  12037. SYS_MODE_BOOTING = 0,
  12038. SYS_MODE_IDLE = 1,
  12039. SYS_MODE_AUTHORIZING = 2,
  12040. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12041. SYS_MODE_REASSIGN = 4,
  12042. SYS_MODE_PREPARING = 5,
  12043. SYS_MODE_PREPARE_FOR_EV = 6,
  12044. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12045. SYS_MODE_CHARGING = 8,
  12046. SYS_MODE_TERMINATING = 9,
  12047. SYS_MODE_COMPLETE = 10,
  12048. SYS_MODE_ALARM = 11,
  12049. SYS_MODE_FAULT = 12,
  12050. SYS_MODE_RESERVATION = 13,
  12051. SYS_MODE_BOOKING = 14,
  12052. SYS_MODE_MAINTAIN = 15,
  12053. SYS_MODE_DEBUG = 16,
  12054. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12055. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12056. SYS_MODE_UPDATE = 19
  12057. };
  12058. */
  12059. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12060. {
  12061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12062. goto end;
  12063. }
  12064. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12065. {
  12066. //check Transaction active
  12067. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12068. {
  12069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12070. {
  12071. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12072. }
  12073. else
  12074. {
  12075. tempIndex = connectorIdInt -1;
  12076. }
  12077. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12078. {
  12079. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12080. {
  12081. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12082. {
  12083. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12084. {
  12085. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12086. {
  12087. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12088. {
  12089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12090. }
  12091. else
  12092. {
  12093. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12095. }
  12096. }
  12097. 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'))
  12098. {
  12099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12100. }
  12101. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12102. {
  12103. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12104. }
  12105. else
  12106. {
  12107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12108. }
  12109. }
  12110. 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
  12111. {
  12112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12113. }
  12114. }
  12115. else
  12116. {
  12117. //replace reservation
  12118. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12119. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12120. }
  12121. }
  12122. } // END FOR CHAdeMO_QUANTITY
  12123. }
  12124. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12125. {
  12126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12127. {
  12128. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12129. }
  12130. else
  12131. {
  12132. tempIndex = connectorIdInt -1;
  12133. }
  12134. for (int index = 0; index < CCS_QUANTITY; index++)
  12135. {
  12136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12137. {
  12138. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12139. {
  12140. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12141. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12142. {
  12143. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12144. {
  12145. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12146. {
  12147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12148. }
  12149. else
  12150. {
  12151. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12153. }
  12154. }
  12155. 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'))
  12156. {
  12157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12158. }
  12159. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12160. {
  12161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12162. }
  12163. else
  12164. {
  12165. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12166. }
  12167. }
  12168. 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
  12169. {
  12170. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12171. }
  12172. }
  12173. else
  12174. {
  12175. //replace reservation
  12176. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12178. }
  12179. }
  12180. } // END FOR CCS_QUANTITY
  12181. }
  12182. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12183. {
  12184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12185. {
  12186. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12187. }
  12188. else
  12189. {
  12190. tempIndex = connectorIdInt -1;
  12191. }
  12192. for (int index = 0; index < GB_QUANTITY; index++)
  12193. {
  12194. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12195. {
  12196. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12197. {
  12198. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12199. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12200. {
  12201. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12202. {
  12203. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12204. {
  12205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12206. }
  12207. else
  12208. {
  12209. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12211. }
  12212. }
  12213. 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'))
  12214. {
  12215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12216. }
  12217. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12218. {
  12219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12220. }
  12221. else
  12222. {
  12223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12224. }
  12225. }
  12226. 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
  12227. {
  12228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12229. }
  12230. }
  12231. else
  12232. {
  12233. //replace reservation
  12234. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12236. }
  12237. }
  12238. }// END FOR GB_QUANTITY
  12239. }
  12240. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12241. {
  12242. tempIndex = connectorIdInt -1;
  12243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12244. {
  12245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12246. {
  12247. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12248. {
  12249. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12250. 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
  12251. {
  12252. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12253. {
  12254. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12255. {
  12256. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12257. }
  12258. else
  12259. {
  12260. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12262. }
  12263. }
  12264. 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'))
  12265. {
  12266. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12267. }
  12268. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12269. {
  12270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12271. }
  12272. else
  12273. {
  12274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12275. }
  12276. }
  12277. 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
  12278. {
  12279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12280. }
  12281. }
  12282. else
  12283. {
  12284. //replace reservation
  12285. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12287. }
  12288. }
  12289. }// END FOR GB_QUANTITY
  12290. }
  12291. else
  12292. {
  12293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12294. {
  12295. tempIndex = 2;
  12296. }
  12297. else
  12298. {
  12299. tempIndex = (connectorIdInt -1);
  12300. }
  12301. for (int index = 0; index < AC_QUANTITY; index++)
  12302. {
  12303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12304. {
  12305. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12306. {
  12307. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12308. {
  12309. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12310. {
  12311. 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))
  12312. {
  12313. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12314. }
  12315. else
  12316. {
  12317. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12319. }
  12320. }
  12321. 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'))
  12322. {
  12323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12324. }
  12325. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12326. {
  12327. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12328. }
  12329. else
  12330. {
  12331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12332. }
  12333. }
  12334. 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
  12335. {
  12336. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12337. }
  12338. }
  12339. else
  12340. {
  12341. //replace reservation
  12342. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12343. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12344. }
  12345. }
  12346. } // END FOR AC_QUANTITY
  12347. }
  12348. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12349. }
  12350. else if(connectorIdInt == 0)
  12351. {
  12352. //check Transaction active
  12353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12354. {
  12355. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12356. {
  12357. 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'))
  12358. {
  12359. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12360. goto end;
  12361. }
  12362. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12363. {
  12364. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12365. goto end;
  12366. }
  12367. 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
  12368. {
  12369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12370. goto end;
  12371. }
  12372. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12373. {
  12374. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12375. goto end;
  12376. }
  12377. }
  12378. }// END FOR CHAdeMO_QUANTITY
  12379. for (int index = 0; index < CCS_QUANTITY; index++)
  12380. {
  12381. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12382. {
  12383. 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'))
  12384. {
  12385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12386. goto end;
  12387. }
  12388. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12389. {
  12390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12391. goto end;
  12392. }
  12393. 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
  12394. {
  12395. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12396. goto end;
  12397. }
  12398. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12399. {
  12400. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12401. goto end;
  12402. }
  12403. }
  12404. } // END FOR CCS_QUANTITY
  12405. for (int index = 0; index < GB_QUANTITY; index++)
  12406. {
  12407. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12408. {
  12409. 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'))
  12410. {
  12411. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12412. goto end;
  12413. }
  12414. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12415. {
  12416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12417. goto end;
  12418. }
  12419. 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
  12420. {
  12421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12422. goto end;
  12423. }
  12424. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12425. {
  12426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12427. goto end;
  12428. }
  12429. }
  12430. } // END FOR GB_QUANTITY
  12431. for (int index = 0; index < AC_QUANTITY; index++)
  12432. {
  12433. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12434. {
  12435. 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'))
  12436. {
  12437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12438. goto end;
  12439. }
  12440. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12441. {
  12442. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12443. goto end;
  12444. }
  12445. 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
  12446. {
  12447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12448. goto end;
  12449. }
  12450. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12451. {
  12452. 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))
  12453. {
  12454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12455. goto end;
  12456. }
  12457. }
  12458. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12459. {
  12460. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12461. goto end;
  12462. }
  12463. }
  12464. }// END FOR AC_QUANTITY
  12465. //The connectorId is 0
  12466. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12468. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12469. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12470. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12471. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12472. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12473. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12474. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12475. result = TRUE;
  12476. return result;
  12477. }
  12478. else
  12479. {
  12480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12481. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12482. }
  12483. if(strcmp(comfirmstr,"Accepted") == 0)
  12484. {
  12485. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12486. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12487. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12488. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12489. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12490. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12491. result = TRUE;
  12492. return result;
  12493. }
  12494. end:
  12495. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12496. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12497. return result;
  12498. }
  12499. int handleResetRequest(char *uuid, char *payload)
  12500. {
  12501. mtrace();
  12502. int result = FAIL;
  12503. char sstr[10]={0},sstrtemp[30]={ 0 };
  12504. char typestr[10]={0};
  12505. char comfirmstr[20]={0};
  12506. int c = 0;
  12507. char *loc;
  12508. DEBUG_INFO("handleResetRequest...\n");
  12509. strcpy(sstrtemp, stringtrimspace(payload));
  12510. loc = strstr(sstrtemp, "type");
  12511. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12512. c = 0;
  12513. while (loc[3+strlen("type")+c] != '\"')
  12514. {
  12515. sstr[c] = loc[3+strlen("type")+c];
  12516. c++;
  12517. }
  12518. sstr[c] = '\0';
  12519. strcpy(typestr,sstr);
  12520. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12521. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12522. {
  12523. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12524. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12525. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12526. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12527. }
  12528. else
  12529. {
  12530. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12531. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12532. result = PASS;
  12533. }
  12534. sendResetConfirmation(uuid, comfirmstr);
  12535. return result;
  12536. }
  12537. int handleSendLocalListRequest(char *uuid, char *payload)
  12538. {
  12539. mtrace();
  12540. int result = FAIL;
  12541. char comfirmstr[20];
  12542. int checkState_Faulted = FALSE;
  12543. json_object *SendLocalList;
  12544. DEBUG_INFO("handleSendLocalListRequest...\n");
  12545. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12546. {
  12547. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12548. goto end;
  12549. }
  12550. //check Charge Point state
  12551. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12552. {
  12553. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12554. {
  12555. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12556. }
  12557. }
  12558. for (int index = 0; index < CCS_QUANTITY; index++)
  12559. {
  12560. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12561. {
  12562. checkState_Faulted = TRUE; //OCPP Status
  12563. }
  12564. }
  12565. for (int index = 0; index < GB_QUANTITY; index++)
  12566. {
  12567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12568. {
  12569. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12570. }
  12571. }
  12572. //check Charge Point state
  12573. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12574. {
  12575. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12576. {
  12577. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12578. }
  12579. }
  12580. //check Charge Point state
  12581. for (int index = 0; index < AC_QUANTITY; index++)
  12582. {
  12583. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12584. {
  12585. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12586. }
  12587. }
  12588. if(checkState_Faulted == TRUE)
  12589. {
  12590. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12591. goto end;
  12592. }
  12593. // Parsing payload
  12594. SendLocalList = json_tokener_parse(payload);
  12595. if(!is_error(SendLocalList))
  12596. {
  12597. // Required data
  12598. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12599. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12600. // Optional data
  12601. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12602. {
  12603. //Check UpdateType
  12604. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12605. {
  12606. //Local list full update
  12607. DEBUG_INFO("Local list full update.\n");
  12608. locallistVersion = 0;
  12609. OCPP_getListVerion();
  12610. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12611. {
  12612. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12613. goto end;
  12614. }
  12615. OCPP_cleanLocalList();
  12616. }
  12617. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12618. {
  12619. //Local list different update
  12620. DEBUG_INFO("Local list different update.\n");
  12621. locallistVersion = 0;
  12622. OCPP_getListVerion();
  12623. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12624. {
  12625. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12626. goto end;
  12627. }
  12628. }
  12629. else
  12630. {
  12631. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12632. goto end;
  12633. }
  12634. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12635. {
  12636. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12637. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12638. goto end;
  12639. }
  12640. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12641. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12642. {
  12643. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag"))));
  12644. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12645. {
  12646. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", stringtrimspace((char *)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"))));
  12647. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12648. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", stringtrimspace((char *)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"))));
  12649. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12650. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", stringtrimspace((char *)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"))));
  12651. }
  12652. // Add to db
  12653. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12654. {
  12655. //Local list full update
  12656. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12657. idx,
  12658. ShmOCPP16Data->SendLocalList.ListVersion,
  12659. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12660. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12661. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12662. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12663. // update list
  12664. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12665. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12666. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12667. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12668. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12669. }
  12670. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12671. {
  12672. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12673. idx,
  12674. ShmOCPP16Data->SendLocalList.ListVersion,
  12675. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12676. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12677. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12678. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12679. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12680. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12681. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12682. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12683. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12684. }
  12685. }
  12686. }
  12687. else
  12688. {
  12689. //Check UpdateType
  12690. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12691. {
  12692. //Local list full update
  12693. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12694. OCPP_cleanLocalList();
  12695. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12696. goto end;
  12697. }
  12698. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12699. {
  12700. //Local list different update
  12701. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12702. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12703. goto end;
  12704. }
  12705. }
  12706. result = PASS;
  12707. }
  12708. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12709. end:
  12710. json_object_put(SendLocalList);
  12711. sendSendLocalListConfirmation(uuid, comfirmstr);
  12712. return result;
  12713. }
  12714. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12715. {
  12716. mtrace();
  12717. int result = FAIL;
  12718. struct StructSetChargingProfile SetProfileReq = {0};
  12719. int tempchargingProfileIdInt;
  12720. int tempstackLevelInt;
  12721. int chargingSchedulePeriodCount = 0;
  12722. char comfirmstr[20]={0};
  12723. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12724. char rmFileCmd[128]={0};
  12725. int profileQuantity = 0;
  12726. int replaceableProfileCnt = 0;
  12727. json_object *SetChargingProfile;
  12728. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12729. SetChargingProfile = json_tokener_parse(payload);
  12730. if(!is_error(SetChargingProfile))
  12731. {
  12732. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12733. {
  12734. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12735. }
  12736. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12737. {
  12738. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12739. {
  12740. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12741. }
  12742. else
  12743. {
  12744. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12745. DEBUG_WARN("Cannot find chargingProfileId field.");
  12746. goto end;
  12747. }
  12748. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12749. {
  12750. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12751. }
  12752. else
  12753. {
  12754. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12755. DEBUG_WARN("Cannot find stackLevel field.");
  12756. goto end;
  12757. }
  12758. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12759. {
  12760. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12761. }
  12762. else
  12763. {
  12764. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12765. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12766. goto end;
  12767. }
  12768. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12769. {
  12770. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12771. }
  12772. else
  12773. {
  12774. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12775. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12776. goto end;
  12777. }
  12778. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12779. {
  12780. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12781. }
  12782. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12783. {
  12784. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12785. }
  12786. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12787. {
  12788. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12789. }
  12790. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12791. {
  12792. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12793. }
  12794. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12795. {
  12796. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12797. {
  12798. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  12799. }
  12800. else
  12801. {
  12802. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12803. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12804. goto end;
  12805. }
  12806. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12807. {
  12808. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12809. }
  12810. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12811. {
  12812. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12813. }
  12814. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12815. {
  12816. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  12817. }
  12818. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12819. {
  12820. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12821. if(chargingSchedulePeriodCount <= 10)
  12822. {
  12823. 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++)
  12824. {
  12825. 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)
  12826. {
  12827. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  12828. }
  12829. else
  12830. {
  12831. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12832. DEBUG_WARN("Cannot find startPeriod field.");
  12833. goto end;
  12834. }
  12835. 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)
  12836. {
  12837. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  12838. }
  12839. else
  12840. {
  12841. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12842. DEBUG_WARN("Cannot find limit field.");
  12843. goto end;
  12844. }
  12845. 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)
  12846. {
  12847. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  12848. }
  12849. }
  12850. }
  12851. }
  12852. else
  12853. {
  12854. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12855. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12856. goto end;
  12857. }
  12858. }
  12859. else
  12860. {
  12861. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12862. DEBUG_WARN("Cannot find chargingSchedule field.");
  12863. goto end;
  12864. }
  12865. }
  12866. }
  12867. // Profile periods quantity check
  12868. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12869. {
  12870. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12871. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12872. goto end;
  12873. }
  12874. // Check invalid limit
  12875. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12876. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12877. {
  12878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12879. {
  12880. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12881. {
  12882. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  12883. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12884. {
  12885. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12886. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12887. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12888. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12889. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12890. goto end;
  12891. }
  12892. }
  12893. }
  12894. else
  12895. {
  12896. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12897. {
  12898. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  12899. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  12900. {
  12901. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12902. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12903. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12904. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12905. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12906. goto end;
  12907. }
  12908. }
  12909. }
  12910. }
  12911. // Profile purpose info check
  12912. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12913. {
  12914. FILE *fp;
  12915. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12916. if(SetProfileReq.ConnectorId != 0)
  12917. {
  12918. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12919. DEBUG_WARN("Profile connector id is not 0.\n");
  12920. goto end;
  12921. }
  12922. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12923. if (!fp)
  12924. {
  12925. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12926. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12927. }
  12928. else
  12929. {
  12930. char *line = NULL;
  12931. size_t len = 0;
  12932. while(getline(&line, &len, fp) != -1)
  12933. {
  12934. json_object *obj = NULL;
  12935. obj = json_tokener_parse(line);
  12936. if(is_error(obj))
  12937. {
  12938. DEBUG_ERROR("Parse txProfile from file error.\n");
  12939. }
  12940. else
  12941. {
  12942. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12943. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12944. {
  12945. profileQuantity += 1;
  12946. }
  12947. else
  12948. replaceableProfileCnt += 1;
  12949. }
  12950. }
  12951. }
  12952. fclose(fp);
  12953. }
  12954. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12955. {
  12956. FILE *fp;
  12957. char filename[128]={0};
  12958. int tmpProfileQuantity;
  12959. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12960. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12961. {
  12962. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12963. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12964. goto end;
  12965. }
  12966. if(SetProfileReq.ConnectorId == 0)
  12967. {
  12968. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12969. {
  12970. tmpProfileQuantity = 0;
  12971. memset(filename, 0, ARRAY_SIZE(filename));
  12972. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12973. fp = fopen(filename, "r");
  12974. if (!fp)
  12975. {
  12976. DEBUG_INFO("%s does not create.\n", filename);
  12977. fp = fopen(filename, "w+");
  12978. }
  12979. else
  12980. {
  12981. char *line = NULL;
  12982. size_t len = 0;
  12983. while(getline(&line, &len, fp) != -1)
  12984. {
  12985. json_object *obj = NULL;
  12986. obj = json_tokener_parse(line);
  12987. if(is_error(obj))
  12988. {
  12989. DEBUG_ERROR("Parse txProfile from file error.\n");
  12990. }
  12991. else
  12992. {
  12993. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12994. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12995. {
  12996. tmpProfileQuantity += 1;
  12997. }
  12998. else
  12999. replaceableProfileCnt += 1;
  13000. }
  13001. }
  13002. }
  13003. fclose(fp);
  13004. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  13005. }
  13006. }
  13007. else
  13008. {
  13009. memset(filename, 0, ARRAY_SIZE(filename));
  13010. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13011. fp = fopen(filename, "r");
  13012. if (!fp)
  13013. {
  13014. DEBUG_INFO("%s does not create.\n", filename);
  13015. fp = fopen(filename, "w+");
  13016. }
  13017. else
  13018. {
  13019. char *line = NULL;
  13020. size_t len = 0;
  13021. while(getline(&line, &len, fp) != -1)
  13022. {
  13023. json_object *obj = NULL;
  13024. obj = json_tokener_parse(line);
  13025. if(is_error(obj))
  13026. {
  13027. DEBUG_ERROR("Parse txProfile from file error.\n");
  13028. }
  13029. else
  13030. {
  13031. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13032. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13033. {
  13034. profileQuantity += 1;
  13035. }
  13036. else
  13037. replaceableProfileCnt += 1;
  13038. }
  13039. }
  13040. }
  13041. fclose(fp);
  13042. }
  13043. }
  13044. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13045. {
  13046. int isMatchTransactiodId= FALSE;
  13047. FILE *fp;
  13048. char filename[128]={0};
  13049. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13050. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13051. if(SetProfileReq.ConnectorId == 0)
  13052. {
  13053. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13054. DEBUG_WARN("Profile connector id is 0.\n");
  13055. goto end;
  13056. }
  13057. int tempIndex = 0;
  13058. //check Transaction active
  13059. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13060. {
  13061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13062. {
  13063. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13064. }
  13065. else
  13066. {
  13067. tempIndex = SetProfileReq.ConnectorId -1;
  13068. }
  13069. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13070. {
  13071. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13072. {
  13073. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13074. {
  13075. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13076. {
  13077. isMatchTransactiodId = TRUE;
  13078. break;
  13079. }
  13080. }
  13081. }
  13082. }
  13083. }
  13084. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13085. {
  13086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13087. {
  13088. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13089. }
  13090. else
  13091. {
  13092. tempIndex = SetProfileReq.ConnectorId -1;
  13093. }
  13094. for (int index = 0; index < CCS_QUANTITY; index++)
  13095. {
  13096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13097. {
  13098. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13099. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13100. {
  13101. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13102. {
  13103. isMatchTransactiodId = TRUE;
  13104. break;
  13105. }
  13106. }
  13107. }
  13108. }
  13109. }
  13110. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13111. {
  13112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13113. {
  13114. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13115. }
  13116. else
  13117. {
  13118. tempIndex = SetProfileReq.ConnectorId -1;
  13119. }
  13120. for (int index = 0; index < GB_QUANTITY; index++)
  13121. {
  13122. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13123. {
  13124. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13125. {
  13126. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13127. {
  13128. isMatchTransactiodId = TRUE;
  13129. break;
  13130. }
  13131. }
  13132. }
  13133. }
  13134. }
  13135. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13136. {
  13137. tempIndex = SetProfileReq.ConnectorId -1;
  13138. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13139. {
  13140. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13141. {
  13142. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13143. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13144. {
  13145. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13146. {
  13147. isMatchTransactiodId = TRUE;
  13148. break;
  13149. }
  13150. }
  13151. }
  13152. }
  13153. }
  13154. else
  13155. {
  13156. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13157. {
  13158. tempIndex = 2;
  13159. }
  13160. else
  13161. {
  13162. tempIndex = (SetProfileReq.ConnectorId -1);
  13163. }
  13164. for (int index = 0; index < AC_QUANTITY; index++)
  13165. {
  13166. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13167. {
  13168. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13169. {
  13170. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13171. {
  13172. isMatchTransactiodId = TRUE;
  13173. break;
  13174. }
  13175. }
  13176. }
  13177. }
  13178. }
  13179. //check Transaction active
  13180. if(isMatchTransactiodId == FALSE)
  13181. {
  13182. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13183. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13184. goto end;
  13185. }
  13186. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13187. {
  13188. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13189. DEBUG_WARN("Connector id is over max gun number.\n");
  13190. goto end;
  13191. }
  13192. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13193. fp = fopen(filename, "r");
  13194. if (!fp)
  13195. {
  13196. DEBUG_INFO("%s does not create.\n", filename);
  13197. fp = fopen(filename, "w+");
  13198. }
  13199. else
  13200. {
  13201. char *line = NULL;
  13202. size_t len = 0;
  13203. while(getline(&line, &len, fp) != -1)
  13204. {
  13205. json_object *obj = NULL;
  13206. obj = json_tokener_parse(line);
  13207. if(is_error(obj))
  13208. {
  13209. DEBUG_ERROR("Parse txProfile from file error.\n");
  13210. }
  13211. else
  13212. {
  13213. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13214. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13215. {
  13216. profileQuantity += 1;
  13217. }
  13218. else
  13219. replaceableProfileCnt += 1;
  13220. }
  13221. }
  13222. }
  13223. fclose(fp);
  13224. }
  13225. // Check ChargeProfileMaxStackLevel
  13226. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13227. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13228. {
  13229. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13230. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13231. goto end;
  13232. }
  13233. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13234. {
  13235. FILE *fp;
  13236. char dataLine[4096]={0};
  13237. char fnametemp[128]={0};
  13238. int tmpProfileQuantity;
  13239. //Check ChargePointMaxProfile.json exit
  13240. profileQuantity = 0;
  13241. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13242. {
  13243. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13244. //Check Charging Profile Count
  13245. tmpProfileQuantity = 0;
  13246. while(fscanf(fp, "%s", dataLine) != EOF)
  13247. {
  13248. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13249. {
  13250. profileQuantity += 1;
  13251. tmpProfileQuantity += 1;
  13252. }
  13253. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13254. }
  13255. fclose(fp);
  13256. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13257. }
  13258. //Check TxDefaultProfile_%d.json
  13259. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13260. {
  13261. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13262. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13263. if((access(fnametemp,F_OK))!=-1)
  13264. {
  13265. fp = fopen(fnametemp, "r");
  13266. //Check Charging Profile Count
  13267. tmpProfileQuantity = 0;
  13268. while(fscanf(fp, "%s", dataLine) != EOF)
  13269. {
  13270. //DEBUG_INFO("word=%s\n",word);
  13271. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13272. {
  13273. profileQuantity += 1;
  13274. tmpProfileQuantity += 1;
  13275. }
  13276. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13277. }
  13278. fclose(fp);
  13279. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13280. }
  13281. }
  13282. //Check TxProfile_%d.json
  13283. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13284. {
  13285. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13286. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13287. if((access(fnametemp,F_OK))!=-1)
  13288. {
  13289. fp = fopen(fnametemp, "r");
  13290. //Check Charging Profile Count
  13291. tmpProfileQuantity = 0;
  13292. while(fscanf(fp, "%s", dataLine) != EOF)
  13293. {
  13294. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13295. {
  13296. profileQuantity += 1;
  13297. tmpProfileQuantity += 1;
  13298. }
  13299. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13300. }
  13301. fclose(fp);
  13302. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13303. }
  13304. }
  13305. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13306. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13307. // To check total Profile quantity
  13308. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13309. {
  13310. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13311. {
  13312. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13313. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13314. goto end;
  13315. }
  13316. }
  13317. else
  13318. {
  13319. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13320. {
  13321. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13322. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13323. goto end;
  13324. }
  13325. }
  13326. }
  13327. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13328. //**********************************Write to File********************************************************/
  13329. {
  13330. FILE *infile;
  13331. FILE *outfile;
  13332. char dataLine[4096]={0};
  13333. char filename[128]={0};
  13334. int chkChar=0;
  13335. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13336. {
  13337. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13338. {
  13339. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13340. }
  13341. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13342. {
  13343. if(SetProfileReq.ConnectorId==0)
  13344. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13345. else
  13346. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13347. }
  13348. else
  13349. {
  13350. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13351. }
  13352. infile = fopen (filename, "r");
  13353. outfile = fopen (tempfile, "w");
  13354. chkChar = fgetc(infile);
  13355. rewind(infile);
  13356. if(chkChar == EOF)
  13357. {
  13358. // Profile is empty
  13359. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13360. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13361. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13362. fclose(infile);
  13363. fclose(outfile);
  13364. sprintf(rmFileCmd,"rm -f %s",filename);
  13365. system(rmFileCmd);
  13366. rename(tempfile, filename);
  13367. }
  13368. else
  13369. {
  13370. // Profile is not empty
  13371. int ChargingProfileAdded = FALSE;
  13372. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13373. {
  13374. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13375. json_object *tmpChargingProfile;
  13376. tmpChargingProfile = json_tokener_parse(dataLine);
  13377. if(!is_error(SetChargingProfile))
  13378. {
  13379. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13380. {
  13381. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13382. {
  13383. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13384. }
  13385. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13386. {
  13387. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13388. }
  13389. }
  13390. }
  13391. json_object_put(tmpChargingProfile);
  13392. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13393. {
  13394. if(ChargingProfileAdded == FALSE)
  13395. {
  13396. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13397. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13398. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13399. ChargingProfileAdded = TRUE;
  13400. }
  13401. }
  13402. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13403. {
  13404. if(ChargingProfileAdded == FALSE)
  13405. {
  13406. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13407. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13408. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13409. ChargingProfileAdded = TRUE;
  13410. }
  13411. }
  13412. else
  13413. {
  13414. fprintf(outfile,"%s\n",dataLine);
  13415. if(ChargingProfileAdded == FALSE)
  13416. {
  13417. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13418. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13419. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13420. ChargingProfileAdded = TRUE;
  13421. }
  13422. }
  13423. } // end of while loop
  13424. fclose(infile);
  13425. fclose(outfile);
  13426. sprintf(rmFileCmd,"rm -f %s",filename);
  13427. system(rmFileCmd);
  13428. rename(tempfile, filename);
  13429. }
  13430. }
  13431. sleep(1);
  13432. result = TRUE;
  13433. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13434. }
  13435. end:
  13436. json_object_put(SetChargingProfile);
  13437. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13438. {
  13439. if(SetProfileReq.ConnectorId == 0)
  13440. {
  13441. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13442. {
  13443. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13444. }
  13445. }
  13446. else
  13447. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13448. }
  13449. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13450. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13451. return result;
  13452. }
  13453. int handleTriggerMessageRequest(char *uuid, char *payload)
  13454. {
  13455. mtrace();
  13456. int result = FAIL;
  13457. int connectorIdIsNULL = FALSE;
  13458. int connectorIdInt =0;
  13459. char sstr[40]={0},sstrtemp[100]={ 0 };
  13460. char requestedMessagestr[40]={0};
  13461. char comfirmstr[20]={0};
  13462. int c = 0;
  13463. char *loc;
  13464. DEBUG_INFO("handleTriggerMessageRequest\n");
  13465. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13466. strcpy(sstrtemp, stringtrimspace(payload));
  13467. c = 0;
  13468. loc = strstr(sstrtemp, "requestedMessage");
  13469. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13470. {
  13471. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13472. c++;
  13473. }
  13474. sstr[c] = '\0';
  13475. strcpy(requestedMessagestr, sstr);
  13476. c = 0;
  13477. loc = strstr(sstrtemp, "connectorId");
  13478. if(loc == NULL)
  13479. {
  13480. connectorIdIsNULL = TRUE;
  13481. }
  13482. else
  13483. {
  13484. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13485. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13486. {
  13487. sstr[c] = loc[strlen("connectorId")+2+c];
  13488. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13489. c++;
  13490. }
  13491. sstr[c] = '\0';
  13492. connectorIdInt = atoi(sstr);
  13493. }
  13494. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13495. {
  13496. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13497. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13498. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13499. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13500. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13501. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13502. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13503. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13504. {
  13505. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13506. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13507. return TRUE;
  13508. }
  13509. else
  13510. {
  13511. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13512. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13513. }
  13514. }
  13515. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13516. {
  13517. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13518. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13519. return TRUE;
  13520. }
  13521. //==========================
  13522. // Trigger message
  13523. //==========================
  13524. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13525. {
  13526. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13527. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13528. {
  13529. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13530. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13531. }
  13532. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13533. }
  13534. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13535. {
  13536. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13537. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13538. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13539. }
  13540. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13541. {
  13542. //sendBootNotificationRequest();
  13543. server_sign = FALSE;
  13544. }
  13545. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13546. {
  13547. refreshStartTimer(&clientTime.Heartbeat);
  13548. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13549. }
  13550. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13551. {
  13552. if(connectorIdIsNULL == FALSE)
  13553. {
  13554. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13555. {
  13556. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13557. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13558. }
  13559. }
  13560. else
  13561. {
  13562. for(int idx=0;idx< gunTotalNumber;idx++)
  13563. {
  13564. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13565. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13566. }
  13567. }
  13568. }
  13569. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13570. {
  13571. if(connectorIdIsNULL == FALSE)
  13572. {
  13573. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13574. {
  13575. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13576. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13577. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13578. }
  13579. }
  13580. else
  13581. {
  13582. for(int idx=0;idx< gunTotalNumber;idx++)
  13583. {
  13584. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13585. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13586. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13587. }
  13588. }
  13589. }
  13590. return result;
  13591. }
  13592. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13593. {
  13594. mtrace();
  13595. int result = FAIL;
  13596. int connectorIdInt =0;
  13597. char comfirmstr[20]={0};
  13598. int tempIndex = 0;
  13599. json_object *UnlockConnector;
  13600. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13601. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13602. UnlockConnector = json_tokener_parse(payload);
  13603. if(!is_error(UnlockConnector))
  13604. {
  13605. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13606. {
  13607. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13608. }
  13609. }
  13610. json_object_put(UnlockConnector);
  13611. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13612. if(gunTotalNumber == 0)
  13613. {
  13614. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13615. goto end;
  13616. }
  13617. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13618. {
  13619. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13620. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13621. goto end;
  13622. }
  13623. else
  13624. {
  13625. //check Transaction active
  13626. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13627. {
  13628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13629. {
  13630. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13631. }
  13632. else
  13633. {
  13634. tempIndex = connectorIdInt -1;
  13635. }
  13636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13637. {
  13638. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13639. {
  13640. //stop Transaction
  13641. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13642. }
  13643. }
  13644. }
  13645. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13646. {
  13647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13648. {
  13649. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13650. }
  13651. else
  13652. {
  13653. tempIndex = connectorIdInt -1;
  13654. }
  13655. for (int index = 0; index < CCS_QUANTITY; index++)
  13656. {
  13657. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13658. {
  13659. //stop Transaction
  13660. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13661. }
  13662. }
  13663. }
  13664. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13665. {
  13666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13667. {
  13668. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13669. }
  13670. else
  13671. {
  13672. tempIndex = connectorIdInt -1;
  13673. }
  13674. for (int index = 0; index < GB_QUANTITY; index++)
  13675. {
  13676. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13677. {
  13678. //stop Transaction
  13679. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13680. }
  13681. }
  13682. }
  13683. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13684. {
  13685. tempIndex = connectorIdInt -1;
  13686. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13687. {
  13688. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13689. {
  13690. //stop Transaction
  13691. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13692. }
  13693. }
  13694. }
  13695. else
  13696. {
  13697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13698. {
  13699. tempIndex = 2;
  13700. }
  13701. else
  13702. {
  13703. tempIndex = connectorIdInt-1;
  13704. }
  13705. for (int index = 0; index < AC_QUANTITY; index++)
  13706. {
  13707. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13708. {
  13709. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13710. }
  13711. }
  13712. }
  13713. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13714. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13715. result = TRUE;
  13716. return result;
  13717. }
  13718. end:
  13719. //json_object_put(obj); --- remove temporally
  13720. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13721. return result;
  13722. }
  13723. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13724. {
  13725. mtrace();
  13726. int result = FAIL;
  13727. pthread_t t;
  13728. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13729. sendUpdateFirmwareConfirmation(uuid);
  13730. if(!interLock.isUpdateFirmwareGoing)
  13731. {
  13732. interLock.isUpdateFirmwareGoing = 1;
  13733. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13734. sleep(1);
  13735. }
  13736. else
  13737. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13738. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13739. return result;
  13740. }
  13741. void *UpdateFirmwareProcess(void *data)
  13742. {
  13743. pthread_detach(pthread_self());
  13744. mtrace();
  13745. int retriesInt =0, retryIntervalInt=0;
  13746. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  13747. int port=0;
  13748. char locationstr[2048]={0}, retrieveDatestr[36]={0};
  13749. int isSuccess = 0;
  13750. char ftpbuf[2048];
  13751. char temp[2048];
  13752. char * pch;
  13753. char filenametemp[256];
  13754. json_object *UpdateFirmware;
  13755. UpdateFirmware = json_tokener_parse(data);
  13756. if(!is_error(UpdateFirmware))
  13757. {
  13758. // Required data
  13759. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13760. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13761. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13762. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13763. // Optional data
  13764. if(json_object_object_get(UpdateFirmware, "retries"))
  13765. {
  13766. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13767. }
  13768. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13769. {
  13770. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13771. }
  13772. }
  13773. json_object_put(UpdateFirmware);
  13774. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13775. memset(path, 0, ARRAY_SIZE(path));
  13776. // Wait retrieveData
  13777. if(strlen(retrieveDatestr) > 10)
  13778. {
  13779. do
  13780. {
  13781. sleep(1);
  13782. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13783. }
  13784. // Ready to download
  13785. system("rm -f /mnt/*");
  13786. if(strncmp(locationstr,"http", 4) == 0)
  13787. {
  13788. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13789. sprintf(ftppath,"/%s", path);
  13790. DEBUG_INFO("locationstr: %s\n", locationstr);
  13791. DEBUG_INFO("protocol: %s\n",protocol);
  13792. DEBUG_INFO("host: %s\n",host);
  13793. DEBUG_INFO("path: %s\n",path);
  13794. DEBUG_INFO("ftppath: %s\n",ftppath);
  13795. int ftppathlen=strlen(ftppath);
  13796. int i=1;
  13797. while(i < ftppathlen)
  13798. {
  13799. int len=ftppathlen-i;
  13800. if(ftppath[len]== 47) // '/' ascll code: 47
  13801. {
  13802. DEBUG_INFO("compare '/' all right\n");
  13803. break;
  13804. }
  13805. i=i+1;
  13806. }
  13807. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13808. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13809. filenametemp[i+1] = 0;
  13810. do
  13811. {
  13812. sleep(1);
  13813. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13814. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13815. sleep(1);
  13816. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13817. if(!isSuccess)
  13818. {
  13819. sleep(1);
  13820. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13821. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13822. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13823. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13824. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13825. }
  13826. else
  13827. {
  13828. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13829. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13830. }
  13831. retriesInt--;
  13832. }while((isSuccess == 0)&&(retriesInt >= 0));
  13833. }
  13834. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13835. {
  13836. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13837. memset(temp, 0, ARRAY_SIZE(temp));
  13838. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13839. strcpy(ftpbuf, locationstr);
  13840. int ftppathlen=strlen(ftpbuf);
  13841. int i=1;
  13842. while(i < ftppathlen)
  13843. {
  13844. int len=ftppathlen-i;
  13845. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13846. {
  13847. DEBUG_INFO(" compare '/' all right\n");
  13848. break;
  13849. }
  13850. i=i+1;
  13851. }
  13852. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13853. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13854. filenametemp[i+1] = 0;
  13855. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13856. pch=strchr(temp,'@');
  13857. if(pch==NULL)
  13858. {
  13859. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13860. protocol, host, &port, path);
  13861. strcpy(user,"anonymous");
  13862. strcpy(password,"");
  13863. }
  13864. else
  13865. {
  13866. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13867. protocol, user, host, &port, path);
  13868. }
  13869. sscanf(host,"%[^/]%s",host1, path1);
  13870. sprintf(ftppath,"%s:/%s", host,path);
  13871. if(port == 0)
  13872. {
  13873. port = 21;
  13874. }
  13875. do
  13876. {
  13877. sleep(1);
  13878. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13879. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13880. sleep(1);
  13881. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13882. if(!isSuccess)
  13883. {
  13884. //BulldogUtil.sleepMs(interval*1000);
  13885. DEBUG_INFO("Update firmware request and download file fail.\n");
  13886. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13887. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13888. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13889. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13890. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13891. }
  13892. else
  13893. {
  13894. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13895. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13896. }
  13897. retriesInt--;
  13898. }while((!isSuccess)&&(retriesInt >= 0));
  13899. }
  13900. else if((strncmp(locationstr,"ftp", 3) == 0) || (strncmp(locationstr,"ftps", 4) == 0)) // ftp/ftps
  13901. {
  13902. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13903. memset(temp, 0, ARRAY_SIZE(temp));
  13904. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13905. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13906. int ftppathlen=strlen(ftpbuf);
  13907. int i=1;
  13908. while(i < ftppathlen)
  13909. {
  13910. int len=ftppathlen-i;
  13911. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13912. {
  13913. DEBUG_INFO(" compare '/' all right\n");
  13914. break;
  13915. }
  13916. i=i+1;
  13917. }
  13918. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13919. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13920. filenametemp[i+1] = 0;
  13921. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13922. pch=strchr(temp,'@');
  13923. if(pch==NULL)
  13924. {
  13925. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13926. protocol, host, &port, path);
  13927. strcpy(user,"anonymous");
  13928. strcpy(password,"");
  13929. }
  13930. else
  13931. {
  13932. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13933. protocol, user, password, host, &port, path);
  13934. }
  13935. sscanf(host,"%[^/]%s",host1, path1);
  13936. sprintf(ftppath,"%s", path1);
  13937. //DEBUG_INFO("protocol =%s\n",protocol);
  13938. //DEBUG_INFO("user =%s\n",user);
  13939. //DEBUG_INFO("password =%s\n",password);
  13940. //DEBUG_INFO("host1 =%s\n",host1);
  13941. //DEBUG_INFO("port =%d\n",port);
  13942. //DEBUG_INFO("path1 =%s\n",path1);
  13943. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13944. //ftpFile(host, user, password, port, ftppath, fname);
  13945. //download firmware pthred
  13946. if(port == 0)
  13947. {
  13948. port = 21;
  13949. }
  13950. do
  13951. {
  13952. sleep(1);
  13953. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13954. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13955. sleep(1);
  13956. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13957. if(!isSuccess)
  13958. {
  13959. //BulldogUtil.sleepMs(interval*1000);
  13960. DEBUG_INFO("Update firmware request and download file fail.\n");
  13961. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13962. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13963. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13964. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13965. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13966. }
  13967. else
  13968. {
  13969. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13970. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13971. }
  13972. retriesInt--;
  13973. }while((!isSuccess)&&(retriesInt >= 0));
  13974. }
  13975. else
  13976. {
  13977. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13978. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13979. sleep(1);
  13980. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13981. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13982. }
  13983. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13984. {
  13985. sleep(3);
  13986. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13987. }
  13988. interLock.isUpdateFirmwareGoing = 0;
  13989. pthread_exit(NULL);
  13990. }
  13991. int handleCertificateSignedRequest(char *uuid, char *payload)
  13992. {
  13993. mtrace();
  13994. int result = PASS;
  13995. json_object *CertificateSigned;
  13996. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13997. CertificateSigned = json_tokener_parse(payload);
  13998. if(!is_error(CertificateSigned))
  13999. {
  14000. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  14001. }
  14002. json_object_put(CertificateSigned);
  14003. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  14004. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  14005. fclose(fp);
  14006. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14007. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  14008. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  14009. {
  14010. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  14011. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  14012. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  14013. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  14014. }
  14015. else
  14016. {
  14017. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  14018. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  14019. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14020. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14021. }
  14022. sendCertificateSignedConfirmation(uuid);
  14023. return result;
  14024. }
  14025. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14026. {
  14027. mtrace();
  14028. int result = PASS;
  14029. json_object *DeleteCertificate;
  14030. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14031. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14032. DeleteCertificate = json_tokener_parse(payload);
  14033. if(!is_error(DeleteCertificate))
  14034. {
  14035. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14036. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14037. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14038. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14039. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14040. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14041. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14042. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14043. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  14044. {
  14045. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  14046. }
  14047. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  14048. {
  14049. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  14050. }
  14051. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  14052. {
  14053. ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  14054. }
  14055. char temp[256] = {0};
  14056. char compareData[256] = {0};
  14057. int isMatch = TRUE;
  14058. // Check CentralSystemRootCertificate
  14059. if(access(ROOTCA_CS,F_OK) != -1)
  14060. {
  14061. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14062. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14063. for(int i = 0; compareData[i]; i++)
  14064. {
  14065. compareData[i] = tolower(compareData[i]);
  14066. }
  14067. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14068. isMatch = FALSE;
  14069. if(isMatch == TRUE)
  14070. {
  14071. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14072. for(int i = 0; compareData[i]; i++)
  14073. {
  14074. compareData[i] = tolower(compareData[i]);
  14075. }
  14076. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14077. isMatch = FALSE;
  14078. }
  14079. if(isMatch == TRUE)
  14080. {
  14081. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14082. for(int i = 0; compareData[i]; i++)
  14083. {
  14084. compareData[i] = tolower(compareData[i]);
  14085. }
  14086. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14087. isMatch = FALSE;
  14088. }
  14089. if(isMatch == TRUE)
  14090. {
  14091. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  14092. sprintf(temp, "rm -f %s", ROOTCA_CS);
  14093. system(temp);
  14094. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14095. goto End;
  14096. }
  14097. }
  14098. // Check ManufacturerRootCertificate
  14099. if(access(ROOTCA_MF,F_OK) != -1)
  14100. {
  14101. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14102. isMatch = TRUE;
  14103. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  14104. for(int i = 0; compareData[i]; i++)
  14105. {
  14106. compareData[i] = tolower(compareData[i]);
  14107. }
  14108. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14109. isMatch = FALSE;
  14110. if(isMatch == TRUE)
  14111. {
  14112. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  14113. for(int i = 0; compareData[i]; i++)
  14114. {
  14115. compareData[i] = tolower(compareData[i]);
  14116. }
  14117. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14118. isMatch = FALSE;
  14119. }
  14120. if(isMatch == TRUE)
  14121. {
  14122. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  14123. for(int i = 0; compareData[i]; i++)
  14124. {
  14125. compareData[i] = tolower(compareData[i]);
  14126. }
  14127. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14128. isMatch = FALSE;
  14129. }
  14130. if(isMatch == TRUE)
  14131. {
  14132. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  14133. sprintf(temp, "rm -f %s", ROOTCA_MF);
  14134. system(temp);
  14135. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14136. goto End;
  14137. }
  14138. }
  14139. // Check certCP
  14140. if(access(CERTIFICATE_CP,F_OK) != -1)
  14141. {
  14142. DEBUG_INFO("Checking certCP...\n");
  14143. isMatch = TRUE;
  14144. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  14145. for(int i = 0; compareData[i]; i++)
  14146. {
  14147. compareData[i] = tolower(compareData[i]);
  14148. }
  14149. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14150. isMatch = FALSE;
  14151. if(isMatch == TRUE)
  14152. {
  14153. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  14154. for(int i = 0; compareData[i]; i++)
  14155. {
  14156. compareData[i] = tolower(compareData[i]);
  14157. }
  14158. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14159. isMatch = FALSE;
  14160. }
  14161. if(isMatch == TRUE)
  14162. {
  14163. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  14164. for(int i = 0; compareData[i]; i++)
  14165. {
  14166. compareData[i] = tolower(compareData[i]);
  14167. }
  14168. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14169. isMatch = FALSE;
  14170. }
  14171. if(isMatch == TRUE)
  14172. {
  14173. DEBUG_INFO("Deleting certCP...\n");
  14174. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14175. system(temp);
  14176. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14177. goto End;
  14178. }
  14179. }
  14180. }
  14181. End:
  14182. json_object_put(DeleteCertificate);
  14183. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14184. sendDeleteCertificateConfirmation(uuid);
  14185. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14186. return result;
  14187. }
  14188. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14189. {
  14190. mtrace();
  14191. int result = PASS;
  14192. json_object *ExtendedTriggerMessage;
  14193. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14194. ExtendedTriggerMessage = json_tokener_parse(payload);
  14195. if(!is_error(ExtendedTriggerMessage))
  14196. {
  14197. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14198. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14199. {
  14200. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14201. }
  14202. else
  14203. {
  14204. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14205. }
  14206. }
  14207. json_object_put(ExtendedTriggerMessage);
  14208. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14209. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14210. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14211. {
  14212. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14213. }
  14214. else
  14215. {
  14216. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14217. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14218. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14219. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14220. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14221. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14222. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14223. {
  14224. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14225. }
  14226. else
  14227. {
  14228. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14229. }
  14230. }
  14231. sendExtendedTriggerMessageConfirmation(uuid);
  14232. //==========================
  14233. // Trigger message
  14234. //==========================
  14235. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14236. {
  14237. //sendBootNotificationRequest();
  14238. server_sign = FALSE;
  14239. }
  14240. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14241. {
  14242. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14243. }
  14244. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14245. {
  14246. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14247. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14248. {
  14249. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14250. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14251. }
  14252. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14253. }
  14254. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14255. {
  14256. refreshStartTimer(&clientTime.Heartbeat);
  14257. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14258. }
  14259. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14260. {
  14261. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14262. {
  14263. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14264. }
  14265. else
  14266. {
  14267. for(int idx=0;idx< gunTotalNumber;idx++)
  14268. {
  14269. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14270. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14271. }
  14272. }
  14273. }
  14274. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14275. {
  14276. char cmdBuf[1024]={0};
  14277. sprintf(cmdBuf, "openssl req -newkey rsa:2048 -out %s -nodes -keyout %s -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=%s/OU=IT/CN=%s\" &", CSR_CP, PRIVATE_KEY_CP, ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14278. system(cmdBuf);
  14279. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14280. }
  14281. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14282. {
  14283. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14284. {
  14285. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14286. }
  14287. else
  14288. {
  14289. for(int idx=0;idx< gunTotalNumber;idx++)
  14290. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14291. }
  14292. }
  14293. return result;
  14294. }
  14295. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14296. {
  14297. mtrace();
  14298. int result = PASS;
  14299. json_object *GetInstalledCertificateIds;
  14300. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14301. GetInstalledCertificateIds = json_tokener_parse(payload);
  14302. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14303. if(!is_error(GetInstalledCertificateIds))
  14304. {
  14305. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14306. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14307. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14308. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14309. // Check CentralSystemRootCertificate
  14310. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14311. {
  14312. if(access(ROOTCA_CS,F_OK) != -1)
  14313. {
  14314. char parseData[512] = {0};
  14315. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14316. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14317. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14318. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14319. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14320. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14321. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14322. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14323. }
  14324. else
  14325. {
  14326. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14327. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14328. }
  14329. }
  14330. // Check ManufacturerRootCertificate
  14331. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14332. {
  14333. if(access(ROOTCA_MF,F_OK) != -1)
  14334. {
  14335. char parseData[512] = {0};
  14336. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14337. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14338. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  14339. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14340. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14341. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14342. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14343. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14344. }
  14345. else
  14346. {
  14347. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14348. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14349. }
  14350. }
  14351. else
  14352. {
  14353. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14354. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14355. }
  14356. }
  14357. json_object_put(GetInstalledCertificateIds);
  14358. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14359. sendGetInstalledCertificateIdsConfirmation(uuid);
  14360. return result;
  14361. }
  14362. void* GetLogProcess(void* data)
  14363. {
  14364. pthread_detach(pthread_self());
  14365. mtrace();
  14366. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  14367. int port=0;
  14368. int isSuccess = FALSE;
  14369. char cmdBuf[2048];
  14370. struct tm *tmNow;
  14371. time_t CurrentTime;
  14372. struct tm tmStart;
  14373. struct tm tmStop;
  14374. CurrentTime = time(NULL);
  14375. tmNow=localtime(&CurrentTime);
  14376. uint16_t targetYear, targetMonth;
  14377. json_object *GetLog;
  14378. DEBUG_INFO("GetLogProcess...\n");
  14379. GetLog = json_tokener_parse(data);
  14380. if(!is_error(GetLog))
  14381. {
  14382. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14383. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14384. if(json_object_object_get(GetLog, "retries") != NULL)
  14385. {
  14386. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14387. }
  14388. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14389. {
  14390. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14391. }
  14392. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14393. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14394. {
  14395. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14396. }
  14397. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14398. {
  14399. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14400. }
  14401. }
  14402. json_object_put(GetLog);
  14403. // Pack log to compress file
  14404. if((sscanf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%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) &&
  14405. (sscanf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%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))
  14406. {
  14407. // Pack system log
  14408. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14409. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14410. targetYear = tmStart.tm_year;
  14411. targetMonth = tmStart.tm_mon;
  14412. do
  14413. {
  14414. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14415. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14416. if(targetMonth+1>=13)
  14417. {
  14418. targetYear += 1;
  14419. targetMonth = 1;
  14420. }
  14421. else
  14422. {
  14423. targetMonth += 1;
  14424. }
  14425. }while((targetYear < (tmNow->tm_year+1900)) ||
  14426. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14427. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14428. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14429. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  14430. system(cmdBuf);
  14431. // Pack charging & event log
  14432. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14433. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14434. targetYear = tmStart.tm_year;
  14435. targetMonth = tmStart.tm_mon;
  14436. do
  14437. {
  14438. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14439. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14440. if(targetMonth+1>=13)
  14441. {
  14442. targetYear += 1;
  14443. targetMonth = 1;
  14444. }
  14445. else
  14446. {
  14447. targetMonth += 1;
  14448. }
  14449. }while((targetYear < (tmNow->tm_year+1900)) ||
  14450. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14451. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14452. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14453. system(cmdBuf);
  14454. // Combine log file
  14455. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14456. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14457. }
  14458. else
  14459. {
  14460. system("exec /root/logPackTools 'log' 6");
  14461. }
  14462. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14463. system(cmdBuf);
  14464. checkUploadLog();
  14465. //****************location*******************/
  14466. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14467. {
  14468. DEBUG_INFO("location is <Empty>!\n");
  14469. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14470. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14471. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14472. goto end;
  14473. }
  14474. memset(protocol, 0, ARRAY_SIZE(protocol));
  14475. memset(user, 0, ARRAY_SIZE(user) );
  14476. memset(password, 0, ARRAY_SIZE(password));
  14477. memset(host, 0, ARRAY_SIZE(host));
  14478. memset(path, 0, ARRAY_SIZE(path));
  14479. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14480. memset(host1, 0, ARRAY_SIZE(host1));
  14481. memset(path1, 0, ARRAY_SIZE(path1));
  14482. /*location: ftp://user:password@host:port/path*/
  14483. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14484. if((access(fnamePlusPath,F_OK))!=-1)
  14485. {
  14486. DEBUG_INFO("fnamePlusPath exist.\n");
  14487. }
  14488. else
  14489. {
  14490. DEBUG_INFO("fnamePlusPath not exist!\n");
  14491. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14492. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14493. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14494. goto end;
  14495. }
  14496. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14497. {
  14498. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14499. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14500. protocol, host, &port, path);
  14501. strcpy(user,"anonymous");
  14502. strcpy(password,"");
  14503. }
  14504. else
  14505. {
  14506. //DEBUG_INFO("pch=%s\n", pch);
  14507. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14508. protocol, user, password, host, &port, path);
  14509. }
  14510. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14511. {
  14512. DEBUG_INFO("protocol is not ftp/http ! \n");
  14513. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14514. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14515. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14516. goto end;
  14517. }
  14518. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14519. {
  14520. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14521. sprintf(ftppath,"/%s", path);
  14522. do
  14523. {
  14524. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14525. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14526. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14527. sleep(3);
  14528. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14529. if(!isSuccess)
  14530. {
  14531. DEBUG_INFO("Diagnostics fail.\n");
  14532. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14533. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14534. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14535. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14536. }
  14537. else
  14538. {
  14539. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14540. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14541. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14542. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14543. }
  14544. ShmOCPP16Data->GetLog.retries--;
  14545. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14546. }
  14547. else
  14548. {
  14549. sscanf(host,"%[^/]%s",host1, path1);
  14550. if(strlen(path) > 0)
  14551. sprintf(ftppath,"/%s", path);
  14552. else
  14553. sprintf(ftppath,"/%s", path1);
  14554. int ftppathlen=strlen(ftppath);
  14555. int i=1;
  14556. char filenametemp[50];
  14557. while(i < ftppathlen)
  14558. {
  14559. int len=ftppathlen-i;
  14560. if(ftppath[len]== 47) // '/' ascll code: 47
  14561. {
  14562. DEBUG_INFO("find '/' all right\n");
  14563. break;
  14564. }
  14565. i=i+1;
  14566. }
  14567. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14568. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14569. filenametemp[i+1] = 0;
  14570. if(port == 0)
  14571. port = 21;
  14572. do
  14573. {
  14574. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14575. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14576. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14577. sleep(3);
  14578. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14579. if(!isSuccess)
  14580. {
  14581. DEBUG_INFO("Diagnostics fail.\n");
  14582. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14583. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14584. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14585. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14586. }
  14587. else
  14588. {
  14589. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14590. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14591. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14592. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14593. }
  14594. ShmOCPP16Data->GetLog.retries--;
  14595. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14596. }
  14597. end:
  14598. system("rm -f /mnt/*");
  14599. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  14600. sleep(5);
  14601. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14602. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14603. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14604. interLock.isGetDiagnosticGoing = 0;
  14605. pthread_exit(NULL);
  14606. }
  14607. int handleGetLogRequest(char *uuid, char *payload)
  14608. {
  14609. mtrace();
  14610. int result = PASS;
  14611. time_t CurrentTime;
  14612. struct tm *tm;
  14613. DEBUG_INFO("handleGetLogRequest...\n");
  14614. pthread_t th_Status;
  14615. CurrentTime = time(NULL);
  14616. tm = localtime(&CurrentTime);
  14617. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14618. sprintf((char*)ShmOCPP16Data->GetLog.Response_filename, "%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);
  14619. if(!interLock.isGetDiagnosticGoing)
  14620. {
  14621. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14622. interLock.isGetDiagnosticGoing = 1;
  14623. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14624. sleep(1);
  14625. }
  14626. else
  14627. {
  14628. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14629. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14630. }
  14631. sendGetLogConfirmation(uuid);
  14632. return result;
  14633. }
  14634. int handleInstallCertificateRequest(char *uuid, char *payload)
  14635. {
  14636. mtrace();
  14637. int result = PASS;
  14638. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14639. json_object *InstallCertificate;
  14640. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14641. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14642. InstallCertificate = json_tokener_parse(payload);
  14643. if(!is_error(InstallCertificate))
  14644. {
  14645. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14646. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14647. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14648. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14649. char temp[1024];
  14650. FILE *fp = fopen(tempCert, "w");
  14651. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14652. fclose(fp);
  14653. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14654. char strExpDate[30];
  14655. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14656. fp = popen(temp, "r");
  14657. if(fp)
  14658. {
  14659. while(fgets(temp, sizeof(temp), fp) != NULL)
  14660. {
  14661. if(strstr(temp, "notAfter=") != NULL)
  14662. {
  14663. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14664. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14665. break;
  14666. }
  14667. }
  14668. }
  14669. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14670. struct tm tmExpDate;
  14671. struct timeb tbExpDate;
  14672. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14673. tbExpDate.time = mktime(&tmExpDate);
  14674. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14675. {
  14676. DEBUG_INFO("The enddate is already expired...\n");
  14677. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14678. goto End;
  14679. }
  14680. // Verify certificate with rootCA
  14681. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14682. fp = popen(temp, "r");
  14683. if(fp)
  14684. {
  14685. while(fgets(temp, sizeof(temp), fp) != NULL)
  14686. {
  14687. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14688. {
  14689. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14690. break;
  14691. }
  14692. else
  14693. {
  14694. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14695. }
  14696. }
  14697. }
  14698. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14699. {
  14700. //=====================================================
  14701. // Verify if the certificate is valid or not. (OCSP?)
  14702. //=====================================================
  14703. /*
  14704. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14705. // Get ocsp url
  14706. char ocspUrl[512];
  14707. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14708. fp = popen(temp, "r");
  14709. if(fp)
  14710. {
  14711. while(fgets(temp, sizeof(temp), fp) != NULL)
  14712. {
  14713. if(strstr(temp, "://") != NULL)
  14714. {
  14715. strcpy(ocspUrl, temp);
  14716. break;
  14717. }
  14718. }
  14719. }
  14720. // Get certificate chain for issuer
  14721. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14722. *
  14723. // Execute OCSP
  14724. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14725. fp = popen(temp, "r");
  14726. if(fp)
  14727. {
  14728. while(fgets(temp, sizeof(temp), fp) != NULL)
  14729. {
  14730. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14731. {
  14732. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14733. break;
  14734. }
  14735. }
  14736. }
  14737. system("rm -f /Storage/OCPP/tempChain.pem");
  14738. pclose(fp);
  14739. */
  14740. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14741. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14742. {
  14743. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14744. goto End;
  14745. }
  14746. else
  14747. DEBUG_INFO("OCSP verifying...PASS.\n");
  14748. }
  14749. else
  14750. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14751. }
  14752. End:
  14753. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14754. {
  14755. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14756. {
  14757. if(access(ROOTCA_CS,F_OK) != -1)
  14758. {
  14759. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14760. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14761. rename(tempCert, ROOTCA_CS);
  14762. }
  14763. else
  14764. {
  14765. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14766. rename(tempCert, ROOTCA_CS);
  14767. }
  14768. }
  14769. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14770. {
  14771. if(access(ROOTCA_MF,F_OK) != -1)
  14772. {
  14773. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14774. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14775. rename(tempCert, ROOTCA_MF);
  14776. }
  14777. else
  14778. {
  14779. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14780. rename(tempCert, ROOTCA_MF);
  14781. }
  14782. }
  14783. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14784. }
  14785. sendInstallCertificateConfirmation(uuid);
  14786. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14787. {
  14788. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14789. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14790. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14791. }
  14792. json_object_put(InstallCertificate);
  14793. return result;
  14794. }
  14795. void *SignedUpdateFirmwareProcess(void *data)
  14796. {
  14797. pthread_detach(pthread_self());
  14798. mtrace();
  14799. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  14800. int port=0;
  14801. int isSuccess = 0;
  14802. char ftpbuf[2048];
  14803. char temp[2048];
  14804. char * pch;
  14805. char firmwareFileName[256];
  14806. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14807. json_object *SignedUpdateFirmware;
  14808. SignedUpdateFirmware = json_tokener_parse(data);
  14809. if(!is_error(SignedUpdateFirmware))
  14810. {
  14811. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14812. {
  14813. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14814. }
  14815. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14816. {
  14817. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14818. }
  14819. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14820. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14821. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14822. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14823. {
  14824. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14825. }
  14826. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14827. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14828. }
  14829. json_object_put(SignedUpdateFirmware);
  14830. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14831. memset(path, 0, ARRAY_SIZE(path));
  14832. // Wait retrieveData
  14833. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14834. {
  14835. do
  14836. {
  14837. sleep(1);
  14838. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14839. }
  14840. // Ready to download
  14841. system("rm -f /mnt/*");
  14842. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14843. {
  14844. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14845. sprintf(ftppath,"/%s", path);
  14846. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14847. DEBUG_INFO("protocol: %s\n",protocol);
  14848. DEBUG_INFO("host: %s\n",host);
  14849. DEBUG_INFO("path: %s\n",path);
  14850. DEBUG_INFO("ftppath: %s\n",ftppath);
  14851. int ftppathlen=strlen(ftppath);
  14852. int i=1;
  14853. while(i < ftppathlen)
  14854. {
  14855. int len=ftppathlen-i;
  14856. if(ftppath[len]== 47) // '/' ascll code: 47
  14857. {
  14858. DEBUG_INFO("compare '/' all right\n");
  14859. break;
  14860. }
  14861. i=i+1;
  14862. }
  14863. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14864. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14865. firmwareFileName[i+1] = 0;
  14866. do
  14867. {
  14868. sleep(1);
  14869. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14870. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14871. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14872. sleep(1);
  14873. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14874. if(!isSuccess)
  14875. {
  14876. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14877. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14878. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14879. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14880. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14881. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14882. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14883. }
  14884. else
  14885. {
  14886. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14887. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14888. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14889. }
  14890. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14891. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14892. }
  14893. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14894. {
  14895. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14896. memset(temp, 0, ARRAY_SIZE(temp));
  14897. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14898. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14899. int ftppathlen=strlen(ftpbuf);
  14900. int i=1;
  14901. while(i < ftppathlen)
  14902. {
  14903. int len=ftppathlen-i;
  14904. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14905. {
  14906. DEBUG_INFO(" compare '/' all right\n");
  14907. break;
  14908. }
  14909. i=i+1;
  14910. }
  14911. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14912. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14913. firmwareFileName[i+1] = 0;
  14914. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14915. pch=strchr(temp,'@');
  14916. if(pch==NULL)
  14917. {
  14918. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14919. protocol, host, &port, path);
  14920. strcpy(user,"anonymous");
  14921. strcpy(password,"");
  14922. }
  14923. else
  14924. {
  14925. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14926. protocol, user, host, &port, path);
  14927. }
  14928. sscanf(host,"%[^/]%s",host1, path1);
  14929. sprintf(ftppath,"%s:/%s", host,path);
  14930. if(port == 0)
  14931. {
  14932. port = 21;
  14933. }
  14934. do
  14935. {
  14936. sleep(1);
  14937. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14938. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14939. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14940. sleep(1);
  14941. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14942. if(!isSuccess)
  14943. {
  14944. sleep(1);
  14945. DEBUG_INFO("Update firmware request and download file fail.\n");
  14946. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14947. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14948. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14949. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14950. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14951. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14952. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14953. }
  14954. else
  14955. {
  14956. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14957. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14958. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14959. }
  14960. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14961. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14962. }
  14963. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14964. {
  14965. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14966. memset(temp, 0, ARRAY_SIZE(temp));
  14967. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14968. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14969. int ftppathlen=strlen(ftpbuf);
  14970. int i=1;
  14971. while(i < ftppathlen)
  14972. {
  14973. int len=ftppathlen-i;
  14974. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14975. {
  14976. DEBUG_INFO(" compare '/' all right\n");
  14977. break;
  14978. }
  14979. i=i+1;
  14980. }
  14981. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14982. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14983. firmwareFileName[i+1] = 0;
  14984. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14985. pch=strchr(temp,'@');
  14986. if(pch==NULL)
  14987. {
  14988. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14989. protocol, host, &port, path);
  14990. strcpy(user,"anonymous");
  14991. strcpy(password,"");
  14992. }
  14993. else
  14994. {
  14995. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14996. protocol, user, password, host, &port, path);
  14997. }
  14998. sscanf(host,"%[^/]%s",host1, path1);
  14999. sprintf(ftppath,"%s", path1);
  15000. //DEBUG_INFO("protocol =%s\n",protocol);
  15001. //DEBUG_INFO("user =%s\n",user);
  15002. //DEBUG_INFO("password =%s\n",password);
  15003. //DEBUG_INFO("host1 =%s\n",host1);
  15004. //DEBUG_INFO("port =%d\n",port);
  15005. //DEBUG_INFO("path1 =%s\n",path1);
  15006. //DEBUG_INFO("ftppath=%s\n",ftppath);
  15007. //ftpFile(host, user, password, port, ftppath, fname);
  15008. //download firmware pthred
  15009. if(port == 0)
  15010. {
  15011. port = 21;
  15012. }
  15013. do
  15014. {
  15015. sleep(1);
  15016. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15017. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15018. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15019. sleep(1);
  15020. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15021. if(!isSuccess)
  15022. {
  15023. //BulldogUtil.sleepMs(interval*1000);
  15024. DEBUG_INFO("Update firmware request and download file fail.\n");
  15025. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15026. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15027. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15028. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15029. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15030. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15031. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15032. }
  15033. else
  15034. {
  15035. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15036. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15037. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15038. }
  15039. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15040. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15041. }
  15042. else
  15043. {
  15044. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15045. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15046. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15047. sleep(1);
  15048. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15049. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15050. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15051. }
  15052. // Verify firmware image signature
  15053. struct stat st;
  15054. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15055. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15056. fclose(fp);
  15057. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15058. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15059. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15060. fclose(fp);
  15061. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15062. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15063. if(st.st_size == 0)
  15064. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15065. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15066. {
  15067. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15068. fp = popen(temp, "r");
  15069. if(fp)
  15070. {
  15071. while(fgets(temp, sizeof(temp), fp) != NULL)
  15072. {
  15073. if(strstr(temp, "Verified OK") != NULL)
  15074. {
  15075. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15076. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15077. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15078. }
  15079. else
  15080. {
  15081. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15082. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15083. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15084. sleep(1);
  15085. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15086. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15087. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15088. sleep(1);
  15089. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15090. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15091. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15092. }
  15093. break;
  15094. }
  15095. }
  15096. pclose(fp);
  15097. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15098. }
  15099. interLock.isUpdateFirmwareGoing = 0;
  15100. pthread_exit(NULL);
  15101. }
  15102. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15103. {
  15104. mtrace();
  15105. int result = PASS;
  15106. pthread_t t;
  15107. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15108. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15109. sendSignedUpdateFirmwareConfirmation(uuid);
  15110. if(!interLock.isUpdateFirmwareGoing)
  15111. {
  15112. interLock.isUpdateFirmwareGoing = 1;
  15113. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15114. sleep(1);
  15115. }
  15116. else
  15117. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15118. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15119. return result;
  15120. }
  15121. int handleUnknownRequest(char *uuid, char *payload)
  15122. {
  15123. mtrace();
  15124. int result = PASS;
  15125. DEBUG_INFO("handleUnknownRequest...\n");
  15126. sendUnknownConfirmation(uuid);
  15127. return result;
  15128. }
  15129. //==========================================
  15130. // Handle server response routine
  15131. //==========================================
  15132. void handleAuthorizeResponse(char *payload, int gun_index)
  15133. {
  15134. mtrace();
  15135. char expiryDatestr[36]={0};
  15136. char parentIdTagstr[21]={0};
  15137. char statusstr[20]={0};
  15138. int expiryDateISNULL=FALSE;
  15139. int parentIdTagISNULL=FALSE;
  15140. DEBUG_INFO("handleAuthorizeResponse...\n");
  15141. json_object *Authorize;
  15142. Authorize = json_tokener_parse(payload);
  15143. if(!is_error(Authorize))
  15144. {
  15145. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15146. {
  15147. // Required data
  15148. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15149. // Optional data
  15150. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15151. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15152. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15153. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15154. }
  15155. }
  15156. json_object_put(Authorize);
  15157. if(expiryDateISNULL == FALSE)
  15158. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15159. if(parentIdTagISNULL == FALSE)
  15160. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15161. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15162. //Update idTag information to authorization cache if supproted
  15163. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15164. {
  15165. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15166. }
  15167. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15168. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15169. authorizeRetryTimes = 0;
  15170. }
  15171. void handleBootNotificationResponse(char *payload, int gun_index)
  15172. {
  15173. mtrace();
  15174. char statusStr[12]={0};
  15175. char currentTimeStr[30]={0};
  15176. int intervalInt = 0;
  15177. DEBUG_INFO("handleBootNotificationResponse...\n");
  15178. json_object *BootNotification;
  15179. BootNotification = json_tokener_parse(payload);
  15180. if(!is_error(BootNotification))
  15181. {
  15182. // Required data
  15183. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15184. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15185. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15186. }
  15187. json_object_put(BootNotification);
  15188. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15189. BootNotificationInterval = intervalInt;
  15190. //write back to ShmOCPP16Data->BootNotification
  15191. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15192. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15193. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15194. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15195. {
  15196. BootNotificationInterval = 0;
  15197. if((intervalInt == 0) || (intervalInt >= 10))
  15198. {
  15199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15200. HeartBeatWaitTime = intervalInt;
  15201. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15202. }
  15203. server_sign = TRUE;
  15204. server_pending =FALSE;
  15205. }
  15206. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15207. {
  15208. server_pending = TRUE;
  15209. }
  15210. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15211. srand(time(NULL));
  15212. refreshStartTimer(&clientTime.Heartbeat);
  15213. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15214. SetOcppConnStatus(TRUE);
  15215. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15216. }
  15217. void handleDataTransferResponse(char *payload, int gun_index)
  15218. {
  15219. json_object *DataTransfer = json_tokener_parse(payload);
  15220. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15221. if(!is_error(DataTransfer))
  15222. {
  15223. // Required data
  15224. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15225. // Optional data
  15226. if(json_object_object_get(DataTransfer, "data") != NULL)
  15227. {
  15228. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15229. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15230. if(!is_error(Data))
  15231. {
  15232. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15233. {
  15234. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15235. {
  15236. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15237. }
  15238. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15239. {
  15240. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15241. {
  15242. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status")));
  15243. }
  15244. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15245. {
  15246. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime")));
  15247. }
  15248. }
  15249. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15250. }
  15251. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15252. {
  15253. if(json_object_object_get(Data, "status") != NULL)
  15254. {
  15255. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15256. }
  15257. if(json_object_object_get(Data, "exiResponse") != NULL)
  15258. {
  15259. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15260. }
  15261. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15262. }
  15263. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15264. {
  15265. if(json_object_object_get(Data, "status") != NULL)
  15266. {
  15267. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15268. }
  15269. if(json_object_object_get(Data, "ocspResult") != NULL)
  15270. {
  15271. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15272. }
  15273. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15274. }
  15275. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15276. {
  15277. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15278. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15279. }
  15280. else
  15281. {
  15282. if(json_object_object_get(Data, "msgId") != NULL)
  15283. {
  15284. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15285. {
  15286. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  15287. }
  15288. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15289. {
  15290. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15291. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15292. }
  15293. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeAct") != NULL)
  15294. {
  15295. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15296. {
  15297. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15298. if(json_object_object_get(Data, "occupancySN") != NULL)
  15299. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancySN, "%s", json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15300. if(json_object_object_get(Data, "startTime") != NULL)
  15301. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_startTime, "%s", json_object_get_string(json_object_object_get(Data, "startTime")));
  15302. if(json_object_object_get(Data, "duration") != NULL)
  15303. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_duration = json_object_get_int(json_object_object_get(Data, "duration"));
  15304. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15305. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancyFee = json_object_get_double(json_object_object_get(Data, "occupancyFee"));
  15306. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].OccupancyFeeActReq = 0;
  15307. }
  15308. else
  15309. {
  15310. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15311. {
  15312. if(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq)
  15313. {
  15314. strcpy((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].response_status, "Rejected");
  15315. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq = 0;
  15316. }
  15317. }
  15318. }
  15319. }
  15320. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15321. {
  15322. if(json_object_object_get(Data, "occupancySN") != NULL)
  15323. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15324. }
  15325. }
  15326. }
  15327. }
  15328. json_object_put(Data);
  15329. }
  15330. }
  15331. json_object_put(DataTransfer);
  15332. }
  15333. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15334. {
  15335. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15336. //struct json_object *obj;
  15337. // obj = json_tokener_parse(payload);
  15338. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15339. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15340. //No fields are defined.
  15341. }
  15342. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15343. {
  15344. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15345. //struct json_object *obj;
  15346. // obj = json_tokener_parse(payload);
  15347. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15348. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15349. //No fields are defined.
  15350. }
  15351. void handleHeartbeatResponse(char *payload, int gun_index)
  15352. {
  15353. mtrace();
  15354. DEBUG_INFO("handleHeartbeatResponse...\n");
  15355. json_object *Heartbeat;
  15356. Heartbeat = json_tokener_parse(payload);
  15357. if(!is_error(Heartbeat))
  15358. {
  15359. // Required data
  15360. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15361. }
  15362. json_object_put(Heartbeat);
  15363. if(FirstHeartBeat == 0)
  15364. {
  15365. FirstHeartBeat = 1;
  15366. DEBUG_INFO("FirstHeartBeat \n");
  15367. }
  15368. HeartBeatWithNOResponse = 0;
  15369. refreshStartTimer(&clientTime.Heartbeat);
  15370. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15371. }
  15372. void handleMeterValuesResponse(char *payload, int gun_index)
  15373. {
  15374. mtrace();
  15375. DEBUG_INFO("handleMeterValuesResponse...\n");
  15376. isQueueSendable = 1;
  15377. }
  15378. void handleStartTransactionResponse(char *payload, int gun_index)
  15379. {
  15380. mtrace();
  15381. //int transactionIdInt = 0;
  15382. FILE *outfile;
  15383. char data[100]={0};
  15384. DEBUG_INFO("handleStartTransactionResponse...\n");
  15385. json_object *StartTransaction;
  15386. StartTransaction = json_tokener_parse(payload);
  15387. if(!is_error(StartTransaction))
  15388. {
  15389. // Required data
  15390. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15391. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15392. // Optional data
  15393. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15394. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15395. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15396. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15397. }
  15398. json_object_put(StartTransaction);
  15399. OCPP_updatePeriodEnergy(gun_index);
  15400. //-----------Start : write to the Queue TransactionId file -----------------//
  15401. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15402. {}
  15403. else
  15404. {
  15405. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15406. if(log == NULL)
  15407. {
  15408. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15409. return ;
  15410. }
  15411. else
  15412. {
  15413. fclose(log);
  15414. }
  15415. }
  15416. // open file for writing
  15417. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15418. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15419. {
  15420. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15421. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15422. fputs(data, outfile);
  15423. fclose (outfile);
  15424. DEBUG_INFO("Update QueueTransactionId done...\n");
  15425. }
  15426. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15427. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15428. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15429. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15430. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15431. isQueueSendable = 1;
  15432. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15433. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15434. }
  15435. void handleStatusNotificationResponse(char *payload, int gun_index)
  15436. {
  15437. mtrace();
  15438. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15439. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15440. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15441. if(gun_index != 99)
  15442. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15443. }
  15444. void handleStopTransactionnResponse(char *payload, int gun_index)
  15445. {
  15446. mtrace();
  15447. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15448. json_object *StopTransaction;
  15449. StopTransaction = json_tokener_parse(payload);
  15450. if(!is_error(StopTransaction))
  15451. {
  15452. // Optional data
  15453. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15454. {
  15455. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15456. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15458. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15460. }
  15461. }
  15462. json_object_put(StopTransaction);
  15463. isQueueSendable = 1;
  15464. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15465. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15466. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15467. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15468. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15469. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15470. }
  15471. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15472. {
  15473. mtrace();
  15474. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15475. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15476. }
  15477. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15478. {
  15479. mtrace();
  15480. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15481. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15482. }
  15483. void handleSignCertificateResponse(char *payload, int gun_index)
  15484. {
  15485. mtrace();
  15486. DEBUG_INFO("handleSignCertificateResponse...\n");
  15487. json_object *SignCertificate;
  15488. SignCertificate = json_tokener_parse(payload);
  15489. if(!is_error(SignCertificate))
  15490. {
  15491. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15492. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15493. }
  15494. json_object_put(SignCertificate);
  15495. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15496. }
  15497. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15498. {
  15499. mtrace();
  15500. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15501. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15502. }
  15503. //==========================================
  15504. // Handle Error routine
  15505. //==========================================
  15506. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15507. {
  15508. mtrace();
  15509. #ifdef SystemLogMessage
  15510. DEBUG_INFO("errorCode: %s\n", errorCode);
  15511. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15512. DEBUG_INFO("errorDetails: %s\n", payload);
  15513. #endif
  15514. }
  15515. //===============================================
  15516. // Common routine
  15517. //===============================================
  15518. int initialConfigurationTable(void)
  15519. {
  15520. //clock_t start_t, end_t, total_t;
  15521. FILE *fp;
  15522. FILE *outfile;
  15523. char str[512]={0};
  15524. int confVersion = 26;
  15525. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15526. //start_t = clock();
  15527. //printf("Starting of the program, start_t = %ld\n", start_t);
  15528. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15529. // Check configuration file size is correct
  15530. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15531. {
  15532. struct stat st;
  15533. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15534. if(st.st_size < 3100)
  15535. {
  15536. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15537. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15538. }
  15539. }
  15540. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15541. {
  15542. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15543. if(outfile == NULL)
  15544. {
  15545. DEBUG_INFO("Error opening file\n");
  15546. return FALSE;
  15547. }
  15548. /*Core Profile*/
  15549. //AllowOfflineTxForUnknownId
  15550. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15554. //AuthorizationCacheEnabled
  15555. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15559. //AuthorizeRemoteTxRequests
  15560. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15564. //BlinkRepeat
  15565. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15569. //ClockAlignedDataInterval
  15570. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15574. //ConnectionTimeOut
  15575. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15577. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15579. else
  15580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15582. //GetConfigurationMaxKeys
  15583. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15587. // HeartbeatInterval
  15588. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15592. // LightIntensity
  15593. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15597. // LocalAuthorizeOffline
  15598. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15602. // LocalPreAuthorize
  15603. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15607. // MaxEnergyOnInvalidId
  15608. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15612. // MeterValuesAlignedData
  15613. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  15617. else
  15618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15620. // MeterValuesAlignedDataMaxLength
  15621. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15623. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15625. else
  15626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15628. // MeterValuesSampledData
  15629. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  15633. else
  15634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15636. // MeterValuesSampledDataMaxLength
  15637. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15641. else
  15642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15644. // MeterValueSampleInterval
  15645. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15649. // MinimumStatusDuration
  15650. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15653. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15655. // NumberOfConnectors
  15656. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15659. {
  15660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15661. }
  15662. else
  15663. {
  15664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15665. }
  15666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15667. // ResetRetries
  15668. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15672. // ConnectorPhaseRotation
  15673. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15677. // ConnectorPhaseRotationMaxLength
  15678. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15682. // StopTransactionOnEVSideDisconnect
  15683. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15687. // StopTransactionOnInvalidId
  15688. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15692. // StopTxnAlignedData
  15693. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15697. // StopTxnAlignedDataMaxLength
  15698. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15700. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15701. {
  15702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15703. }
  15704. else
  15705. {
  15706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15707. }
  15708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15709. // StopTxnSampledData
  15710. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15714. // StopTxnSampledDataMaxLength
  15715. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15718. {
  15719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15720. }
  15721. else
  15722. {
  15723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15724. }
  15725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15726. // SupportedFeatureProfiles
  15727. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15731. // SupportedFeatureProfilesMaxLength
  15732. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15736. // TransactionMessageAttempts
  15737. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15740. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15742. // TransactionMessageRetryInterval
  15743. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15746. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15748. // UnlockConnectorOnEVSideDisconnect
  15749. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15753. // WebSocketPingInterval
  15754. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15758. // QueueOffLineMeterValues
  15759. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15763. // AuthorizationKey
  15764. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15768. // SecurityProfile
  15769. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15773. // DefaultPrice
  15774. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15778. // CustomDisplayCostAndPrice
  15779. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15783. // CustomIdleFeeAfterStop
  15784. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15788. // TimeOffset
  15789. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15793. // NextTimeOffsetTransitionDateTime
  15794. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15798. // TimeOffsetNextTransition
  15799. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15803. // SystemUptimeSec
  15804. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15808. // FreeVend
  15809. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15813. // FreeVendIdtag
  15814. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15818. // OcppServer
  15819. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15821. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15823. // MaintainServer
  15824. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15826. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15828. // StatusNotificationPeriodically
  15829. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15833. // StatusNotificationInterval
  15834. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15838. // PreAuthAmount
  15839. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15843. // isEnableLocalPowerSharing
  15844. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15848. // PowerSharingServerIP
  15849. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15851. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15853. // EVCCID_PREFIX
  15854. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15858. // OffLineMaxChargingPower
  15859. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15863. // Configuration Version
  15864. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15868. // Charging profile refresh interval
  15869. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15873. // CpoName
  15874. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15878. // Ocpp Software certificated version
  15879. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15883. // Check certificate of download link
  15884. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  15885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  15886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "FALSE");
  15887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  15888. // RFID endian type
  15889. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  15890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  15891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  15892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  15893. // Authorization timeout
  15894. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  15895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  15896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "15");
  15897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  15898. // Enable AC charger CCS function
  15899. ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemAccessibility = 1;
  15900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemName, "EnableAcCcs");
  15901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData, "FALSE");
  15902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EnableAcCcs", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData);
  15903. //* Local Auth List Management Profile*/
  15904. #if 0
  15905. //For OCTT Test Case
  15906. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15909. #endif
  15910. #if 1
  15911. //LocalAuthListEnabled
  15912. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15916. #endif
  15917. //LocalAuthListMaxLength
  15918. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15922. //SendLocalListMaxLength
  15923. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15927. //ReserveConnectorZeroSupported
  15928. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15932. //* Smart Charging Profile */
  15933. //ChargeProfileMaxStackLevel
  15934. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15938. // ChargingScheduleAllowedChargingRateUnit
  15939. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15943. // ChargingScheduleMaxPeriods
  15944. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15948. // ConnectorSwitch3to1PhaseSupported
  15949. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15953. // MaxChargingProfilesInstalled
  15954. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15958. fclose(outfile);
  15959. }
  15960. else
  15961. {
  15962. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15963. char keystr[60]={0};
  15964. char readonlystr[10]={0};
  15965. char valuestr[256]={0};
  15966. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15967. if(fp == NULL) {
  15968. DEBUG_INFO("Error opening file");
  15969. return FALSE;
  15970. }
  15971. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15972. {
  15973. //DEBUG_INFO("Get Configuration \n");
  15974. if(strlen(str) > 0)
  15975. {
  15976. json_object *OCPPConfiguration;
  15977. OCPPConfiguration = json_tokener_parse(str);
  15978. if(json_object_object_get(OCPPConfiguration, "key") != NULL)
  15979. strcpy(keystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"key")));
  15980. if(json_object_object_get(OCPPConfiguration, "readonly") != NULL)
  15981. strcpy(readonlystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"readonly")));
  15982. if(json_object_object_get(OCPPConfiguration, "value") != NULL)
  15983. strcpy(valuestr, json_object_get_string(json_object_object_get(OCPPConfiguration,"value")));
  15984. json_object_put(OCPPConfiguration);
  15985. // DEBUG_INFO("keystr=%s\n",keystr);
  15986. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15987. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15988. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15989. {
  15990. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15991. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15993. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15994. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15995. }
  15996. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15997. {
  15998. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15999. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  16001. }
  16002. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  16003. {
  16004. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  16006. }
  16007. if(strcmp(keystr, "BlinkRepeat") == 0)
  16008. {
  16009. //Charger.BlinkRepeat = Integer.parseInt(value);
  16010. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  16012. }
  16013. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  16014. {
  16015. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16017. }
  16018. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16019. {
  16020. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16022. }
  16023. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16024. {
  16025. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16027. }
  16028. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16029. {
  16030. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16032. HeartBeatWaitTime = atoi(valuestr);
  16033. }
  16034. if(strcmp(keystr, "LightIntensity") == 0)
  16035. {
  16036. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16038. }
  16039. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16040. {
  16041. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16043. }
  16044. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16045. {
  16046. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16048. }
  16049. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16050. {
  16051. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16053. }
  16054. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16055. {
  16056. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16058. }
  16059. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16060. {
  16061. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16063. }
  16064. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16065. {
  16066. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16068. }
  16069. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16070. {
  16071. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16073. }
  16074. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16075. {
  16076. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16078. }
  16079. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16080. {
  16081. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16083. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16084. }
  16085. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16086. {
  16087. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16089. }
  16090. if(strcmp(keystr, "ResetRetries") == 0)
  16091. {
  16092. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16094. }
  16095. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16096. {
  16097. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16099. }
  16100. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16101. {
  16102. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16104. }
  16105. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16106. {
  16107. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16109. }
  16110. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16111. {
  16112. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16114. }
  16115. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16116. {
  16117. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16119. }
  16120. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16121. {
  16122. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16124. }
  16125. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16126. {
  16127. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16129. }
  16130. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16131. {
  16132. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16134. }
  16135. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16136. {
  16137. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16139. }
  16140. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16141. {
  16142. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16144. }
  16145. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16146. {
  16147. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16149. TransactionMessageAttemptsValue = atoi(valuestr);
  16150. }
  16151. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16152. {
  16153. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16155. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16156. }
  16157. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16158. {
  16159. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16161. }
  16162. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16163. {
  16164. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16166. }
  16167. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16168. {
  16169. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16171. }
  16172. if(strcmp(keystr, "AuthorizationKey") == 0)
  16173. {
  16174. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16175. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16177. }
  16178. if(strcmp(keystr, "SecurityProfile") == 0)
  16179. {
  16180. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16182. }
  16183. if(strcmp(keystr, "DefaultPrice") == 0)
  16184. {
  16185. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16187. }
  16188. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16189. {
  16190. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16192. }
  16193. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16194. {
  16195. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16197. }
  16198. if(strcmp(keystr, "TimeOffset") == 0)
  16199. {
  16200. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16202. }
  16203. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16204. {
  16205. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16207. }
  16208. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16209. {
  16210. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16212. }
  16213. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16214. {
  16215. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16217. }
  16218. if(strcmp(keystr, "FreeVend") == 0)
  16219. {
  16220. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16222. }
  16223. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16224. {
  16225. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16227. }
  16228. if(strcmp(keystr, "OcppServer") == 0)
  16229. {
  16230. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16231. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16232. }
  16233. if(strcmp(keystr, "MaintainServer") == 0)
  16234. {
  16235. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16236. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16237. }
  16238. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16239. {
  16240. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16242. }
  16243. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16244. {
  16245. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16247. }
  16248. if(strcmp(keystr, "PreAuthAmount") == 0)
  16249. {
  16250. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16252. }
  16253. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16254. {
  16255. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16257. }
  16258. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16259. {
  16260. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16261. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16262. }
  16263. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16264. {
  16265. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16267. }
  16268. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16269. {
  16270. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16272. }
  16273. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16274. {
  16275. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16277. }
  16278. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16279. {
  16280. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16282. }
  16283. if(strcmp(keystr, "CpoName") == 0)
  16284. {
  16285. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16287. }
  16288. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16289. {
  16290. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16292. }
  16293. if(strcmp(keystr, "AuthDownloadlinkCertificate") == 0)
  16294. {
  16295. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", valuestr);
  16297. }
  16298. if(strcmp(keystr, "RfidEndianType") == 0)
  16299. {
  16300. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  16302. }
  16303. if(strcmp(keystr, "AuthorizeTimeout") == 0)
  16304. {
  16305. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%s", valuestr);
  16307. }
  16308. if(strcmp(keystr, "EnableAcCcs") == 0)
  16309. {
  16310. ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData, "%s", valuestr);
  16312. }
  16313. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16314. {
  16315. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16317. }
  16318. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16319. {
  16320. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16322. }
  16323. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16324. {
  16325. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16327. }
  16328. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16329. {
  16330. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16332. }
  16333. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16334. {
  16335. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16337. }
  16338. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16339. {
  16340. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16342. }
  16343. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16344. {
  16345. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16347. }
  16348. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16349. {
  16350. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16352. }
  16353. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16354. {
  16355. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16357. }
  16358. }
  16359. }
  16360. fclose(fp);
  16361. }
  16362. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16363. {
  16364. return PASS;
  16365. }
  16366. else
  16367. {
  16368. return FAIL;
  16369. }
  16370. }
  16371. void StoreConfigurationTable(void)
  16372. {
  16373. FILE *outfile;
  16374. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16375. if(outfile == NULL)
  16376. {
  16377. DEBUG_INFO("Error opening file");
  16378. return ;
  16379. }
  16380. /*Core Profile*/
  16381. //AllowOfflineTxForUnknownId
  16382. /*
  16383. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16384. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16387. */
  16388. //DEBUG_INFO("data=%s\n",data);
  16389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16390. //AuthorizationCacheEnabled
  16391. /*
  16392. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16395. */
  16396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16397. //AuthorizeRemoteTxRequests
  16398. /*
  16399. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16402. */
  16403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16404. //BlinkRepeat
  16405. /*
  16406. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16409. */
  16410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16411. //ClockAlignedDataInterval
  16412. /*
  16413. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16416. */
  16417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16418. //ConnectionTimeOut
  16419. /*
  16420. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16423. */
  16424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16425. //GetConfigurationMaxKeys
  16426. /*
  16427. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16430. */
  16431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16432. // HeartbeatInterval
  16433. /*
  16434. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16437. */
  16438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16439. // LightIntensity
  16440. /*
  16441. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16444. */
  16445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16446. // LocalAuthorizeOffline
  16447. /*
  16448. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16451. */
  16452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16453. // LocalPreAuthorize
  16454. /*
  16455. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16458. */
  16459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16460. // MaxEnergyOnInvalidId
  16461. /*
  16462. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16465. */
  16466. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16468. // MeterValuesAlignedData
  16469. /*
  16470. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16473. */
  16474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16475. // MeterValuesAlignedDataMaxLength
  16476. /*
  16477. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16480. */
  16481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16482. // MeterValuesSampledData
  16483. /*
  16484. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16487. */
  16488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16489. // MeterValuesSampledDataMaxLength
  16490. /*
  16491. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16494. */
  16495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16496. // MeterValueSampleInterval
  16497. /*
  16498. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16501. */
  16502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16503. // MinimumStatusDuration
  16504. /*
  16505. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16508. */
  16509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16510. // NumberOfConnectors
  16511. /*
  16512. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16514. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16515. {
  16516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16517. }
  16518. else
  16519. {
  16520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16521. }
  16522. */
  16523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16524. // ResetRetries
  16525. /*
  16526. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16529. */
  16530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16531. // ConnectorPhaseRotation
  16532. /*
  16533. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16536. */
  16537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16538. // ConnectorPhaseRotationMaxLength
  16539. /*
  16540. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16543. */
  16544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16545. // StopTransactionOnEVSideDisconnect
  16546. /*
  16547. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16550. */
  16551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16552. // StopTransactionOnInvalidId
  16553. /*
  16554. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16557. */
  16558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16559. // StopTxnAlignedData
  16560. /*
  16561. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16564. */
  16565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16566. // StopTxnAlignedDataMaxLength
  16567. /*
  16568. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16571. */
  16572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16573. // StopTxnSampledData
  16574. /*
  16575. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16578. */
  16579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16580. // StopTxnSampledDataMaxLength
  16581. /*
  16582. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16585. */
  16586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16587. // SupportedFeatureProfiles
  16588. /*
  16589. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16592. */
  16593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16594. // SupportedFeatureProfilesMaxLength
  16595. /*
  16596. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16599. */
  16600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16601. // TransactionMessageAttempts
  16602. /*
  16603. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16606. */
  16607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16608. // TransactionMessageRetryInterval
  16609. /*
  16610. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16613. */
  16614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16615. // UnlockConnectorOnEVSideDisconnect
  16616. /*
  16617. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16620. */
  16621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16622. // WebSocketPingInterval
  16623. /*
  16624. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16627. */
  16628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16629. // QueueOffLineMeterValues
  16630. /*
  16631. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16634. */
  16635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16636. // AuthorizationKey
  16637. /*
  16638. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16641. */
  16642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16643. // SecurityProfile
  16644. /*
  16645. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16648. */
  16649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16650. // DefaultPrice
  16651. /*
  16652. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16655. */
  16656. json_object *tmp;
  16657. tmp = json_tokener_parse((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16658. if(!is_error(tmp))
  16659. {
  16660. DEBUG_INFO("JSON string type\n");
  16661. json_object *target = json_object_new_object();
  16662. json_object_object_add(target, "key", json_object_new_string("DefaultPrice"));
  16663. json_object_object_add(target, "readonly", (ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility?json_object_new_boolean(0):json_object_new_boolean(1)));
  16664. json_object_object_add(target, "value", json_object_new_string((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData));
  16665. fprintf(outfile, "%s\n", json_object_to_json_string_ext(target, JSON_C_TO_STRING_PLAIN));
  16666. json_object_put(target);
  16667. }
  16668. else
  16669. {
  16670. DEBUG_INFO("Normal string type\n");
  16671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16672. }
  16673. json_object_put(tmp);
  16674. // CustomDisplayCostAndPrice
  16675. /*
  16676. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16679. */
  16680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16681. // CustomIdleFeeAfterStop
  16682. /*
  16683. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16686. */
  16687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16688. // TimeOffset
  16689. /*
  16690. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16693. */
  16694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16695. // NextTimeOffsetTransitionDateTime
  16696. /*
  16697. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16700. */
  16701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16702. // TimeOffsetNextTransition
  16703. /*
  16704. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16707. */
  16708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16709. // SystemUptimeSec
  16710. /*
  16711. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16714. */
  16715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16716. // FreeVend
  16717. /*
  16718. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16721. */
  16722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16723. // FreeVendIdtag
  16724. /*
  16725. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16728. */
  16729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16730. // OcppServer
  16731. /*
  16732. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16735. */
  16736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16737. // MaintainServer
  16738. /*
  16739. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16742. */
  16743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16744. // StatusNotificationPeriodically
  16745. /*
  16746. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16749. */
  16750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16751. // StatusNotificationInterval
  16752. /*
  16753. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16756. */
  16757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16758. // PreAuthAmount
  16759. /*
  16760. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16763. */
  16764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16765. // isEnableLocalPowerSharing
  16766. /*
  16767. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16770. */
  16771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16772. // PowerSharingServerIP
  16773. /*
  16774. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16777. */
  16778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16779. // EVCCID_PREFIX
  16780. /*
  16781. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16784. */
  16785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16786. // OffLineMaxChargingPower
  16787. /*
  16788. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16791. */
  16792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16793. // ConfigurationVersion
  16794. /*
  16795. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16798. */
  16799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16800. // CharingProfileRefreshInterval
  16801. /*
  16802. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16805. */
  16806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16807. // CpoName
  16808. /*
  16809. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16812. */
  16813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16814. // OcppSoftwareVersion
  16815. /*
  16816. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16819. */
  16820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16821. // AuthDownloadlinkCertificate
  16822. /*
  16823. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  16824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  16825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE" );
  16826. */
  16827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  16828. // RfidEndianType
  16829. /*
  16830. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  16831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  16832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "BIG" );
  16833. */
  16834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  16835. // AuthorizeTimeout
  16836. /*
  16837. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  16838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  16839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "60" );
  16840. */
  16841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  16842. // EnableAcCcs
  16843. /*
  16844. ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemAccessibility = 1;
  16845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemName, "EnableAcCcs");
  16846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData, "TRUE" );
  16847. */
  16848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EnableAcCcs", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData);
  16849. //* Local Auth List Management Profile*/
  16850. //LocalAuthListEnabled
  16851. /*
  16852. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16855. */
  16856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16857. //LocalAuthListMaxLength
  16858. /*
  16859. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16862. */
  16863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16864. //SendLocalListMaxLength
  16865. /*
  16866. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16869. */
  16870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16871. //ReserveConnectorZeroSupported
  16872. /*
  16873. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16876. */
  16877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16878. //* Smart Charging Profile */
  16879. //ChargeProfileMaxStackLevel
  16880. /*
  16881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16884. */
  16885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16886. // ChargingScheduleAllowedChargingRateUnit
  16887. /*
  16888. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16891. */
  16892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16893. // ChargingScheduleMaxPeriods
  16894. /*
  16895. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16898. */
  16899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16900. // ConnectorSwitch3to1PhaseSupported
  16901. /*
  16902. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16905. */
  16906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16907. // MaxChargingProfilesInstalled
  16908. /*
  16909. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16912. */
  16913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16914. fclose(outfile);
  16915. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16916. }
  16917. void getKeyValue(char *keyReq)
  16918. {
  16919. int isEmpty = FALSE;
  16920. int isKnowKey = FALSE;
  16921. DEBUG_INFO("keyReq = %s\n", keyReq);
  16922. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16923. isEmpty = TRUE;
  16924. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16925. {
  16926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16929. {
  16930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16931. }
  16932. else
  16933. {
  16934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16935. }
  16936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16937. isKnowKey = TRUE;
  16938. }
  16939. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16940. {
  16941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16944. {
  16945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16946. }
  16947. else
  16948. {
  16949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16950. }
  16951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16952. isKnowKey = TRUE;
  16953. }
  16954. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16955. {
  16956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16959. {
  16960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16961. }
  16962. else
  16963. {
  16964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16965. }
  16966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16967. isKnowKey = TRUE;
  16968. }
  16969. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16970. {
  16971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16974. {
  16975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16976. }
  16977. else
  16978. {
  16979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16980. }
  16981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16982. isKnowKey = TRUE;
  16983. }
  16984. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16985. {
  16986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16989. {
  16990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16991. }
  16992. else
  16993. {
  16994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16995. }
  16996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16997. isKnowKey = TRUE;
  16998. }
  16999. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  17000. {
  17001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  17003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17004. {
  17005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  17006. }
  17007. else
  17008. {
  17009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  17010. }
  17011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  17012. isKnowKey = TRUE;
  17013. }
  17014. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  17015. {
  17016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  17018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17019. {
  17020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  17021. }
  17022. else
  17023. {
  17024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  17025. }
  17026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  17027. isKnowKey = TRUE;
  17028. }
  17029. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  17030. {
  17031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  17033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17034. {
  17035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  17036. }
  17037. else
  17038. {
  17039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  17040. }
  17041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  17042. isKnowKey = TRUE;
  17043. }
  17044. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17045. {
  17046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17049. {
  17050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17051. }
  17052. else
  17053. {
  17054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17055. }
  17056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17057. isKnowKey = TRUE;
  17058. }
  17059. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17060. {
  17061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17064. {
  17065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17066. }
  17067. else
  17068. {
  17069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17070. }
  17071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17072. isKnowKey = TRUE;
  17073. }
  17074. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17075. {
  17076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17079. {
  17080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17081. }
  17082. else
  17083. {
  17084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17085. }
  17086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17087. isKnowKey = TRUE;
  17088. }
  17089. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17090. {
  17091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17094. {
  17095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17096. }
  17097. else
  17098. {
  17099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17100. }
  17101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17102. isKnowKey = TRUE;
  17103. }
  17104. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17105. {
  17106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17109. {
  17110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17111. }
  17112. else
  17113. {
  17114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17115. }
  17116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17117. isKnowKey = TRUE;
  17118. }
  17119. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17120. {
  17121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17124. {
  17125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17126. }
  17127. else
  17128. {
  17129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17130. }
  17131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17132. isKnowKey = TRUE;
  17133. }
  17134. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17135. {
  17136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17139. {
  17140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17141. }
  17142. else
  17143. {
  17144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17145. }
  17146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17147. isKnowKey = TRUE;
  17148. }
  17149. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17150. {
  17151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17154. {
  17155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17156. }
  17157. else
  17158. {
  17159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17160. }
  17161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17162. isKnowKey = TRUE;
  17163. }
  17164. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17165. {
  17166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17169. {
  17170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17171. }
  17172. else
  17173. {
  17174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17175. }
  17176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17177. isKnowKey = TRUE;
  17178. }
  17179. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17180. {
  17181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17184. {
  17185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17186. }
  17187. else
  17188. {
  17189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17190. }
  17191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17192. isKnowKey = TRUE;
  17193. }
  17194. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17195. {
  17196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17199. {
  17200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17201. }
  17202. else
  17203. {
  17204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17205. }
  17206. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17208. isKnowKey = TRUE;
  17209. }
  17210. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17211. {
  17212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17215. {
  17216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17217. }
  17218. else
  17219. {
  17220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17221. }
  17222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17223. isKnowKey = TRUE;
  17224. }
  17225. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17226. {
  17227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17230. {
  17231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17232. }
  17233. else
  17234. {
  17235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17236. }
  17237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17238. isKnowKey = TRUE;
  17239. }
  17240. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17241. {
  17242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17245. {
  17246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17247. }
  17248. else
  17249. {
  17250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17251. }
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17253. isKnowKey = TRUE;
  17254. }
  17255. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17256. {
  17257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17260. {
  17261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17262. }
  17263. else
  17264. {
  17265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17266. }
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17268. isKnowKey = TRUE;
  17269. }
  17270. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17271. {
  17272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17275. {
  17276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17277. }
  17278. else
  17279. {
  17280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17281. }
  17282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17283. isKnowKey = TRUE;
  17284. }
  17285. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17286. {
  17287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17290. {
  17291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17292. }
  17293. else
  17294. {
  17295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17296. }
  17297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17298. isKnowKey = TRUE;
  17299. }
  17300. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17301. {
  17302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17305. {
  17306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17307. }
  17308. else
  17309. {
  17310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17311. }
  17312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17313. isKnowKey = TRUE;
  17314. }
  17315. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17316. {
  17317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17320. {
  17321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17322. }
  17323. else
  17324. {
  17325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17326. }
  17327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17328. isKnowKey = TRUE;
  17329. }
  17330. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17331. {
  17332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17335. {
  17336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17337. }
  17338. else
  17339. {
  17340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17341. }
  17342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17343. isKnowKey = TRUE;
  17344. }
  17345. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17346. {
  17347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17350. {
  17351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17352. }
  17353. else
  17354. {
  17355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17356. }
  17357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17358. isKnowKey = TRUE;
  17359. }
  17360. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17361. {
  17362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17365. {
  17366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17367. }
  17368. else
  17369. {
  17370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17371. }
  17372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17373. isKnowKey = TRUE;
  17374. }
  17375. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17376. {
  17377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17380. {
  17381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17382. }
  17383. else
  17384. {
  17385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17386. }
  17387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17388. isKnowKey = TRUE;
  17389. }
  17390. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17391. {
  17392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17395. {
  17396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17397. }
  17398. else
  17399. {
  17400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17401. }
  17402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17403. isKnowKey = TRUE;
  17404. }
  17405. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17406. {
  17407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17410. {
  17411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17412. }
  17413. else
  17414. {
  17415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17416. }
  17417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17418. isKnowKey = TRUE;
  17419. }
  17420. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17421. {
  17422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17425. {
  17426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17427. }
  17428. else
  17429. {
  17430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17431. }
  17432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17433. isKnowKey = TRUE;
  17434. }
  17435. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17436. {
  17437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17440. {
  17441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17442. }
  17443. else
  17444. {
  17445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17446. }
  17447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17448. isKnowKey = TRUE;
  17449. }
  17450. /*
  17451. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17452. {
  17453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17456. {
  17457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17458. }
  17459. else
  17460. {
  17461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17462. }
  17463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17464. isKnowKey = TRUE;
  17465. }*/
  17466. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17467. {
  17468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17471. {
  17472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17473. }
  17474. else
  17475. {
  17476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17477. }
  17478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17479. isKnowKey = TRUE;
  17480. }
  17481. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17482. {
  17483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17486. {
  17487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17488. }
  17489. else
  17490. {
  17491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17492. }
  17493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17494. isKnowKey = TRUE;
  17495. }
  17496. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17497. {
  17498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17501. {
  17502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17503. }
  17504. else
  17505. {
  17506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17507. }
  17508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17509. isKnowKey = TRUE;
  17510. }
  17511. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17512. {
  17513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17516. {
  17517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17518. }
  17519. else
  17520. {
  17521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17522. }
  17523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17524. isKnowKey = TRUE;
  17525. }
  17526. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17527. {
  17528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17531. {
  17532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17533. }
  17534. else
  17535. {
  17536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17537. }
  17538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17539. isKnowKey = TRUE;
  17540. }
  17541. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17542. {
  17543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17546. {
  17547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17548. }
  17549. else
  17550. {
  17551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17552. }
  17553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17554. isKnowKey = TRUE;
  17555. }
  17556. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17557. {
  17558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17561. {
  17562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17563. }
  17564. else
  17565. {
  17566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17567. }
  17568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17569. isKnowKey = TRUE;
  17570. }
  17571. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17572. {
  17573. struct sysinfo s_info;
  17574. int error = sysinfo(&s_info);
  17575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17578. {
  17579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17580. }
  17581. else
  17582. {
  17583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17584. }
  17585. if(error != 0)
  17586. {
  17587. DEBUG_WARN("System uptime get error: %d\n", error);
  17588. }
  17589. else
  17590. {
  17591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17592. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17593. }
  17594. isKnowKey = TRUE;
  17595. }
  17596. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17597. {
  17598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17601. {
  17602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17603. }
  17604. else
  17605. {
  17606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17607. }
  17608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17609. isKnowKey = TRUE;
  17610. }
  17611. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17612. {
  17613. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17616. {
  17617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17618. }
  17619. else
  17620. {
  17621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17622. }
  17623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17624. isKnowKey = TRUE;
  17625. }
  17626. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17627. {
  17628. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17631. {
  17632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17633. }
  17634. else
  17635. {
  17636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17637. }
  17638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17639. isKnowKey = TRUE;
  17640. }
  17641. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17642. {
  17643. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17646. {
  17647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17648. }
  17649. else
  17650. {
  17651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17652. }
  17653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17654. isKnowKey = TRUE;
  17655. }
  17656. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17657. {
  17658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17661. {
  17662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17663. }
  17664. else
  17665. {
  17666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17667. }
  17668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17669. isKnowKey = TRUE;
  17670. }
  17671. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17672. {
  17673. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17676. {
  17677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17678. }
  17679. else
  17680. {
  17681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17682. }
  17683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17684. isKnowKey = TRUE;
  17685. }
  17686. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17687. {
  17688. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17691. {
  17692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17693. }
  17694. else
  17695. {
  17696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17697. }
  17698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17699. isKnowKey = TRUE;
  17700. }
  17701. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17702. {
  17703. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17706. {
  17707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17708. }
  17709. else
  17710. {
  17711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17712. }
  17713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17714. isKnowKey = TRUE;
  17715. }
  17716. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17717. {
  17718. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17721. {
  17722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17723. }
  17724. else
  17725. {
  17726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17727. }
  17728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17729. isKnowKey = TRUE;
  17730. }
  17731. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17732. {
  17733. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17736. {
  17737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17738. }
  17739. else
  17740. {
  17741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17742. }
  17743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17744. isKnowKey = TRUE;
  17745. }
  17746. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17747. {
  17748. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17750. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17751. {
  17752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17753. }
  17754. else
  17755. {
  17756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17757. }
  17758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17759. isKnowKey = TRUE;
  17760. }
  17761. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17762. {
  17763. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17766. {
  17767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17768. }
  17769. else
  17770. {
  17771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17772. }
  17773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17774. isKnowKey = TRUE;
  17775. }
  17776. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17777. {
  17778. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17781. {
  17782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17783. }
  17784. else
  17785. {
  17786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17787. }
  17788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17789. isKnowKey = TRUE;
  17790. }
  17791. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17792. {
  17793. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17796. {
  17797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17798. }
  17799. else
  17800. {
  17801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17802. }
  17803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17804. isKnowKey = TRUE;
  17805. }
  17806. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17807. {
  17808. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17811. {
  17812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17813. }
  17814. else
  17815. {
  17816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17817. }
  17818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17819. isKnowKey = TRUE;
  17820. }
  17821. if(isEmpty || strcmp(keyReq, "AuthDownloadlinkCertificate") == 0 )
  17822. {
  17823. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthDownloadlinkCertificate].Item, "AuthDownloadlinkCertificate");
  17824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Key, "AuthDownloadlinkCertificate");
  17825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  17826. {
  17827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "0"/*"FALSE"*/);
  17828. }
  17829. else
  17830. {
  17831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "1"/*"TRUE"*/);
  17832. }
  17833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData );
  17834. isKnowKey = TRUE;
  17835. }
  17836. if(isEmpty || strcmp(keyReq, "RfidEndianType") == 0 )
  17837. {
  17838. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_RfidEndianType].Item, "RfidEndianType");
  17839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Key, "RfidEndianType");
  17840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  17841. {
  17842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "0"/*"FALSE"*/);
  17843. }
  17844. else
  17845. {
  17846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "1"/*"TRUE"*/);
  17847. }
  17848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Value, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  17849. isKnowKey = TRUE;
  17850. }
  17851. if(isEmpty || strcmp(keyReq, "AuthorizeTimeout") == 0 )
  17852. {
  17853. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeTimeout].Item, "AuthorizeTimeout");
  17854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Key, "AuthorizeTimeout");
  17855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  17856. {
  17857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "0"/*"FALSE"*/);
  17858. }
  17859. else
  17860. {
  17861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "1"/*"TRUE"*/);
  17862. }
  17863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  17864. isKnowKey = TRUE;
  17865. }
  17866. if(isEmpty || strcmp(keyReq, "EnableAcCcs") == 0 )
  17867. {
  17868. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EnableAcCcs].Item, "EnableAcCcs");
  17869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EnableAcCcs].Key, "EnableAcCcs");
  17870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemAccessibility == 1)
  17871. {
  17872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EnableAcCcs].ReadOnly, "0"/*"FALSE"*/);
  17873. }
  17874. else
  17875. {
  17876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EnableAcCcs].ReadOnly, "1"/*"TRUE"*/);
  17877. }
  17878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EnableAcCcs].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData );
  17879. isKnowKey = TRUE;
  17880. }
  17881. #if 1
  17882. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17883. {
  17884. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17886. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17887. {
  17888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17889. }
  17890. else
  17891. {
  17892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17893. }
  17894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17895. isKnowKey = TRUE;
  17896. }
  17897. #endif
  17898. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17899. {
  17900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17902. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17903. {
  17904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17905. }
  17906. else
  17907. {
  17908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17909. }
  17910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17911. isKnowKey = TRUE;
  17912. }
  17913. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17914. {
  17915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17917. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17918. {
  17919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17920. }
  17921. else
  17922. {
  17923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17924. }
  17925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17926. isKnowKey = TRUE;
  17927. }
  17928. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17929. {
  17930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17932. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17933. {
  17934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17935. }
  17936. else
  17937. {
  17938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17939. }
  17940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17941. isKnowKey = TRUE;
  17942. }
  17943. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17944. {
  17945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17947. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17948. {
  17949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17950. }
  17951. else
  17952. {
  17953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17954. }
  17955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17956. isKnowKey = TRUE;
  17957. }
  17958. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17959. {
  17960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17962. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17963. {
  17964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17965. }
  17966. else
  17967. {
  17968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17969. }
  17970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17971. isKnowKey = TRUE;
  17972. }
  17973. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17974. {
  17975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17977. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17978. {
  17979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17980. }
  17981. else
  17982. {
  17983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17984. }
  17985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17986. isKnowKey = TRUE;
  17987. }
  17988. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17989. {
  17990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17992. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17993. {
  17994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17995. }
  17996. else
  17997. {
  17998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17999. }
  18000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  18001. isKnowKey = TRUE;
  18002. }
  18003. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  18004. {
  18005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  18006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  18007. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18008. {
  18009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  18010. }
  18011. else
  18012. {
  18013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  18014. }
  18015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  18016. isKnowKey = TRUE;
  18017. }
  18018. //=========================================================
  18019. if(!isEmpty && !isKnowKey)
  18020. {
  18021. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  18022. strcpy(unknownkey[UnknownKeynum], keyReq);
  18023. UnknownKeynum = UnknownKeynum + 1;
  18024. }
  18025. }
  18026. void processUnkownKey(void)
  18027. {
  18028. DEBUG_INFO("processUnkownKey...\n");
  18029. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  18030. for(int index=0; index < UnknownKeynum; index++)
  18031. {
  18032. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  18033. {
  18034. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  18035. }
  18036. }
  18037. }
  18038. int setKeyValue(char *key, char *value)
  18039. {
  18040. int isSuccess = NotSupported;
  18041. int check_ascii=0;
  18042. char str[501]={0};
  18043. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  18044. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  18045. {
  18046. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  18047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  18048. {
  18049. strcpy(str, (const char*)value);
  18050. for(int i = 0; str[i]; i++){
  18051. str[i] = tolower(str[i]);
  18052. }
  18053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18054. isSuccess = ConfigurationStatus_Accepted;
  18055. }
  18056. else
  18057. {
  18058. isSuccess = ConfigurationStatus_Rejected;
  18059. }
  18060. }
  18061. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  18062. {
  18063. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  18064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  18065. {
  18066. strcpy(str, (const char*)value);
  18067. for(int i = 0; str[i]; i++){
  18068. str[i] = tolower(str[i]);
  18069. }
  18070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18071. isSuccess = ConfigurationStatus_Accepted;
  18072. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  18073. }
  18074. else
  18075. {
  18076. isSuccess = ConfigurationStatus_Rejected;
  18077. }
  18078. }
  18079. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  18080. {
  18081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  18082. {
  18083. strcpy(str, (const char*)value);
  18084. for(int i = 0; str[i]; i++)
  18085. {
  18086. str[i] = tolower(str[i]);
  18087. }
  18088. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  18089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18090. isSuccess = ConfigurationStatus_Accepted;
  18091. }
  18092. else
  18093. {
  18094. isSuccess = ConfigurationStatus_Rejected;
  18095. }
  18096. }
  18097. if(strcmp(key, "BlinkRepeat") == 0)
  18098. {
  18099. //Charger.BlinkRepeat = Integer.parseInt(value);
  18100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  18101. {
  18102. check_ascii = value[0];
  18103. if( (check_ascii < 48) || (check_ascii > 57) )
  18104. {
  18105. isSuccess = ConfigurationStatus_Rejected;
  18106. }
  18107. else
  18108. {
  18109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  18110. isSuccess = ConfigurationStatus_Accepted;
  18111. }
  18112. }
  18113. else
  18114. {
  18115. isSuccess = ConfigurationStatus_Rejected;
  18116. }
  18117. }
  18118. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18119. {
  18120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18121. {
  18122. check_ascii = value[0];
  18123. if( (check_ascii < 48) || (check_ascii > 57) )
  18124. {
  18125. isSuccess = ConfigurationStatus_Rejected;
  18126. }
  18127. else
  18128. {
  18129. if((atoi(value) == 0) || (atoi(value) >= 5))
  18130. {
  18131. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18133. isSuccess = ConfigurationStatus_Accepted;
  18134. }
  18135. else
  18136. isSuccess = ConfigurationStatus_Rejected;
  18137. }
  18138. }
  18139. else
  18140. {
  18141. isSuccess = ConfigurationStatus_Rejected;
  18142. }
  18143. }
  18144. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18145. {
  18146. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18147. {
  18148. check_ascii = value[0];
  18149. if( (check_ascii < 48) || (check_ascii > 57) )
  18150. {
  18151. isSuccess = ConfigurationStatus_Rejected;
  18152. }
  18153. else
  18154. {
  18155. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18157. isSuccess = ConfigurationStatus_Accepted;
  18158. }
  18159. }
  18160. else
  18161. {
  18162. isSuccess = ConfigurationStatus_Rejected;
  18163. }
  18164. }
  18165. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18166. {
  18167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18168. {
  18169. check_ascii = value[0];
  18170. if( (check_ascii < 48) || (check_ascii > 57) )
  18171. {
  18172. isSuccess = ConfigurationStatus_Rejected;
  18173. }
  18174. else
  18175. {
  18176. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18178. isSuccess = ConfigurationStatus_Accepted;
  18179. }
  18180. }
  18181. else
  18182. {
  18183. isSuccess = ConfigurationStatus_Rejected;
  18184. }
  18185. }
  18186. if(strcmp(key, "HeartbeatInterval") == 0)
  18187. {
  18188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18189. {
  18190. check_ascii = value[0];
  18191. if( (check_ascii < 48) || (check_ascii > 57) )
  18192. {
  18193. isSuccess = ConfigurationStatus_Rejected;
  18194. }
  18195. else
  18196. {
  18197. if((atoi(value) == 0) || (atoi(value) >= 10))
  18198. {
  18199. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18201. HeartBeatWaitTime = atoi(value);
  18202. isSuccess = ConfigurationStatus_Accepted;
  18203. }
  18204. else
  18205. {
  18206. isSuccess = ConfigurationStatus_Rejected;
  18207. }
  18208. }
  18209. }
  18210. else
  18211. {
  18212. isSuccess = ConfigurationStatus_Rejected;
  18213. }
  18214. }
  18215. if(strcmp(key, "LightIntensity") == 0)
  18216. {
  18217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18218. {
  18219. check_ascii = value[0];
  18220. if( (check_ascii < 48) || (check_ascii > 57) )
  18221. {
  18222. isSuccess = ConfigurationStatus_Rejected;
  18223. }
  18224. else
  18225. {
  18226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18227. isSuccess = ConfigurationStatus_Accepted;
  18228. }
  18229. }
  18230. else
  18231. {
  18232. isSuccess = ConfigurationStatus_Rejected;
  18233. }
  18234. }
  18235. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18236. {
  18237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18238. {
  18239. strcpy(str, (const char*)value);
  18240. for(int i = 0; str[i]; i++)
  18241. {
  18242. str[i] = tolower(str[i]);
  18243. }
  18244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18245. isSuccess = ConfigurationStatus_Accepted;
  18246. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18247. }
  18248. else
  18249. {
  18250. isSuccess = ConfigurationStatus_Rejected;
  18251. }
  18252. }
  18253. if(strcmp(key, "LocalPreAuthorize") == 0)
  18254. {
  18255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18256. {
  18257. strcpy(str, (const char*)value);
  18258. for(int i = 0; str[i]; i++)
  18259. {
  18260. str[i] = tolower(str[i]);
  18261. }
  18262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18263. isSuccess = ConfigurationStatus_Accepted;
  18264. }
  18265. else
  18266. {
  18267. isSuccess = ConfigurationStatus_Rejected;
  18268. }
  18269. }
  18270. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18271. {
  18272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18273. {
  18274. check_ascii = value[0];
  18275. if( (check_ascii < 48) || (check_ascii > 57) )
  18276. {
  18277. isSuccess = ConfigurationStatus_Rejected;
  18278. }
  18279. else
  18280. {
  18281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18282. isSuccess = ConfigurationStatus_Accepted;
  18283. }
  18284. }
  18285. else
  18286. {
  18287. isSuccess = ConfigurationStatus_Rejected;
  18288. }
  18289. }
  18290. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18291. {
  18292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18293. {
  18294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18295. isSuccess = ConfigurationStatus_Accepted;
  18296. }
  18297. else
  18298. {
  18299. isSuccess = ConfigurationStatus_Rejected;
  18300. }
  18301. }
  18302. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18303. {
  18304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18305. {
  18306. check_ascii = value[0];
  18307. if( (check_ascii < 48) || (check_ascii > 57) )
  18308. {
  18309. isSuccess = ConfigurationStatus_Rejected;
  18310. }
  18311. else
  18312. {
  18313. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18315. isSuccess = ConfigurationStatus_Accepted;
  18316. }
  18317. }
  18318. else
  18319. {
  18320. isSuccess = ConfigurationStatus_Rejected;
  18321. }
  18322. }
  18323. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18324. {
  18325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18326. {
  18327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18328. isSuccess = ConfigurationStatus_Accepted;
  18329. }
  18330. else
  18331. {
  18332. isSuccess = ConfigurationStatus_Rejected;
  18333. }
  18334. }
  18335. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18336. {
  18337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18338. {
  18339. check_ascii = value[0];
  18340. if( (check_ascii < 48) || (check_ascii > 57) )
  18341. {
  18342. isSuccess = ConfigurationStatus_Rejected;
  18343. }
  18344. else
  18345. {
  18346. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18348. isSuccess = ConfigurationStatus_Accepted;
  18349. }
  18350. }
  18351. else
  18352. {
  18353. isSuccess = ConfigurationStatus_Rejected;
  18354. }
  18355. }
  18356. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18357. {
  18358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18359. {
  18360. check_ascii = value[0];
  18361. if( (check_ascii < 48) || (check_ascii > 57) )
  18362. {
  18363. isSuccess = ConfigurationStatus_Rejected;
  18364. }
  18365. else
  18366. {
  18367. if((atoi(value) == 0) || (atoi(value) >= 3))
  18368. {
  18369. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18371. isSuccess = ConfigurationStatus_Accepted;
  18372. }
  18373. else
  18374. {
  18375. isSuccess = ConfigurationStatus_Rejected;
  18376. }
  18377. }
  18378. }
  18379. else
  18380. {
  18381. isSuccess = ConfigurationStatus_Rejected;
  18382. }
  18383. }
  18384. if(strcmp(key, "MinimumStatusDuration") == 0)
  18385. {
  18386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18387. {
  18388. check_ascii = value[0];
  18389. if( (check_ascii < 48) || (check_ascii > 57) )
  18390. {
  18391. isSuccess = ConfigurationStatus_Rejected;
  18392. }
  18393. else
  18394. {
  18395. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18396. {
  18397. isSuccess = ConfigurationStatus_Rejected;
  18398. }
  18399. else
  18400. {
  18401. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18403. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18404. isSuccess = ConfigurationStatus_Accepted;
  18405. }
  18406. }
  18407. }
  18408. else
  18409. {
  18410. isSuccess = ConfigurationStatus_Rejected;
  18411. }
  18412. }
  18413. if(strcmp(key, "NumberOfConnectors") == 0)
  18414. {
  18415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18416. {
  18417. check_ascii = value[0];
  18418. if( (check_ascii < 48) || (check_ascii > 57) )
  18419. {
  18420. isSuccess = ConfigurationStatus_Rejected;
  18421. }
  18422. else
  18423. {
  18424. //Charger.ResetRetries = Integer.parseInt(value);
  18425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18426. isSuccess = ConfigurationStatus_Accepted;
  18427. }
  18428. }
  18429. else
  18430. {
  18431. isSuccess = ConfigurationStatus_Rejected;
  18432. }
  18433. }
  18434. if(strcmp(key, "ResetRetries") == 0)
  18435. {
  18436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18437. {
  18438. check_ascii = value[0];
  18439. if( (check_ascii < 48) || (check_ascii > 57) )
  18440. {
  18441. isSuccess = ConfigurationStatus_Rejected;
  18442. }
  18443. else
  18444. {
  18445. //Charger.ResetRetries = Integer.parseInt(value);
  18446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18447. isSuccess = ConfigurationStatus_Accepted;
  18448. }
  18449. }
  18450. else
  18451. {
  18452. isSuccess = ConfigurationStatus_Rejected;
  18453. }
  18454. }
  18455. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18456. {
  18457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18458. {
  18459. strcpy(str, (const char*)value);
  18460. for(int i = 0; str[i]; i++)
  18461. {
  18462. str[i] = tolower(str[i]);
  18463. }
  18464. if(strcmp(str, "notapplicable")== 0)
  18465. {
  18466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18467. isSuccess = ConfigurationStatus_Accepted;
  18468. }
  18469. else if(strcmp(str, "unknown")== 0)
  18470. {
  18471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18472. isSuccess = ConfigurationStatus_Accepted;
  18473. }
  18474. else if(strcmp(str, "rst")== 0)
  18475. {
  18476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18477. isSuccess = ConfigurationStatus_Accepted;
  18478. }
  18479. else if(strcmp(str, "rts")== 0)
  18480. {
  18481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18482. isSuccess = ConfigurationStatus_Accepted;
  18483. }
  18484. else if(strcmp(str, "srt")== 0)
  18485. {
  18486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18487. isSuccess = ConfigurationStatus_Accepted;
  18488. }
  18489. else if(strcmp(str, "str")== 0)
  18490. {
  18491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18492. isSuccess = ConfigurationStatus_Accepted;
  18493. }
  18494. else if(strcmp(str, "trs")== 0)
  18495. {
  18496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18497. isSuccess = ConfigurationStatus_Accepted;
  18498. }
  18499. else if(strcmp(str, "tsr")== 0)
  18500. {
  18501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18502. isSuccess = ConfigurationStatus_Accepted;
  18503. }
  18504. else
  18505. {
  18506. isSuccess = ConfigurationStatus_Rejected;
  18507. }
  18508. }
  18509. else
  18510. {
  18511. isSuccess = ConfigurationStatus_Rejected;
  18512. }
  18513. }
  18514. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18515. {
  18516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18517. {
  18518. check_ascii = value[0];
  18519. if( (check_ascii < 48) || (check_ascii > 57) )
  18520. {
  18521. isSuccess = ConfigurationStatus_Rejected;
  18522. }
  18523. else
  18524. {
  18525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18526. isSuccess = ConfigurationStatus_Accepted;
  18527. }
  18528. }
  18529. else
  18530. {
  18531. isSuccess = ConfigurationStatus_Rejected;
  18532. }
  18533. }
  18534. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18535. {
  18536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18537. {
  18538. strcpy(str, (const char*)value);
  18539. for(int i = 0; str[i]; i++)
  18540. {
  18541. str[i] = tolower(str[i]);
  18542. }
  18543. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18545. isSuccess = ConfigurationStatus_Accepted;
  18546. }
  18547. else
  18548. {
  18549. isSuccess = ConfigurationStatus_Rejected;
  18550. }
  18551. }
  18552. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18553. {
  18554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18555. {
  18556. strcpy(str, (const char*)value);
  18557. for(int i = 0; str[i]; i++)
  18558. {
  18559. str[i] = tolower(str[i]);
  18560. }
  18561. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18563. isSuccess = ConfigurationStatus_Accepted;
  18564. }
  18565. else
  18566. {
  18567. isSuccess = ConfigurationStatus_Rejected;
  18568. }
  18569. }
  18570. if(strcmp(key, "StopTxnAlignedData") == 0)
  18571. {
  18572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18573. {
  18574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18575. isSuccess = ConfigurationStatus_Accepted;
  18576. }
  18577. else
  18578. {
  18579. isSuccess = ConfigurationStatus_Rejected;
  18580. }
  18581. }
  18582. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18583. {
  18584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18585. {
  18586. check_ascii = value[0];
  18587. if( (check_ascii < 48) || (check_ascii > 57) )
  18588. {
  18589. isSuccess = ConfigurationStatus_Rejected;
  18590. }
  18591. else
  18592. {
  18593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18594. isSuccess = ConfigurationStatus_Accepted;
  18595. }
  18596. }
  18597. else
  18598. {
  18599. isSuccess = ConfigurationStatus_Rejected;
  18600. }
  18601. }
  18602. if(strcmp(key, "StopTxnSampledData") == 0)
  18603. {
  18604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18605. {
  18606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18607. isSuccess = ConfigurationStatus_Accepted;
  18608. }
  18609. else
  18610. {
  18611. isSuccess = ConfigurationStatus_Rejected;
  18612. }
  18613. }
  18614. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18615. {
  18616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18617. {
  18618. check_ascii = value[0];
  18619. if( (check_ascii < 48) || (check_ascii > 57) )
  18620. {
  18621. isSuccess = ConfigurationStatus_Rejected;
  18622. }
  18623. else
  18624. {
  18625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18626. isSuccess = ConfigurationStatus_Accepted;
  18627. }
  18628. }
  18629. else
  18630. {
  18631. isSuccess = ConfigurationStatus_Rejected;
  18632. }
  18633. }
  18634. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18635. {
  18636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18637. {
  18638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18639. isSuccess = ConfigurationStatus_Accepted;
  18640. }
  18641. else
  18642. {
  18643. isSuccess = ConfigurationStatus_Rejected;
  18644. }
  18645. }
  18646. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18647. {
  18648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18649. {
  18650. check_ascii = value[0];
  18651. if( (check_ascii < 48) || (check_ascii > 57) )
  18652. {
  18653. isSuccess = ConfigurationStatus_Rejected;
  18654. }
  18655. else
  18656. {
  18657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18658. isSuccess = ConfigurationStatus_Accepted;
  18659. }
  18660. }
  18661. else
  18662. {
  18663. isSuccess = ConfigurationStatus_Rejected;
  18664. }
  18665. }
  18666. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18667. {
  18668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18669. {
  18670. check_ascii = value[0];
  18671. if( (check_ascii < 48) || (check_ascii > 57) )
  18672. {
  18673. isSuccess = ConfigurationStatus_Rejected;
  18674. }
  18675. else
  18676. {
  18677. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18679. TransactionMessageAttemptsValue = atoi(value);
  18680. isSuccess = ConfigurationStatus_Accepted;
  18681. }
  18682. }
  18683. else
  18684. {
  18685. isSuccess = ConfigurationStatus_Rejected;
  18686. }
  18687. }
  18688. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18689. {
  18690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18691. {
  18692. check_ascii = value[0];
  18693. if( (check_ascii < 48) || (check_ascii > 57) )
  18694. {
  18695. isSuccess = ConfigurationStatus_Rejected;
  18696. }
  18697. else
  18698. {
  18699. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18701. TransactionMessageRetryIntervalValue = atoi(value);
  18702. isSuccess = ConfigurationStatus_Accepted;
  18703. }
  18704. }
  18705. else
  18706. {
  18707. isSuccess = ConfigurationStatus_Rejected;
  18708. }
  18709. }
  18710. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18711. {
  18712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18713. {
  18714. strcpy(str, (const char*)value);
  18715. for(int i = 0; str[i]; i++)
  18716. {
  18717. str[i] = tolower(str[i]);
  18718. }
  18719. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18721. isSuccess = ConfigurationStatus_Accepted;
  18722. }
  18723. else
  18724. {
  18725. isSuccess = ConfigurationStatus_Rejected;
  18726. }
  18727. }
  18728. if(strcmp(key, "WebSocketPingInterval") == 0)
  18729. {
  18730. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18731. {
  18732. check_ascii = value[0];
  18733. if( (check_ascii < 48) || (check_ascii > 57) )
  18734. {
  18735. isSuccess = ConfigurationStatus_Rejected;
  18736. }
  18737. else
  18738. {
  18739. if((atoi(value) == 0) || (atoi(value) >= 10))
  18740. {
  18741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18742. isSuccess = ConfigurationStatus_Accepted;
  18743. }
  18744. else
  18745. isSuccess = ConfigurationStatus_Rejected;
  18746. }
  18747. }
  18748. else
  18749. {
  18750. isSuccess = ConfigurationStatus_Rejected;
  18751. }
  18752. }
  18753. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18754. {
  18755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18756. {
  18757. strcpy(str, (const char*)value);
  18758. for(int i = 0; str[i]; i++)
  18759. {
  18760. str[i] = tolower(str[i]);
  18761. }
  18762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18763. isSuccess = ConfigurationStatus_Accepted;
  18764. }
  18765. else
  18766. {
  18767. isSuccess = ConfigurationStatus_Rejected;
  18768. }
  18769. }
  18770. if(strcmp(key, "AuthorizationKey") == 0)
  18771. {
  18772. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18773. {
  18774. strcpy(str, (const char*)value);
  18775. int strlength = strlen(str);
  18776. char capture[3];
  18777. char stackItem = 0;
  18778. char password[21] = {0};
  18779. printf("String length: %d\n", strlength);
  18780. for(int idx=0; idx<(strlength/2); idx++)
  18781. {
  18782. capture[0] = str[(idx*2)];
  18783. capture[1] = str[(idx*2)+1];
  18784. capture[2] = 0;
  18785. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18786. sprintf(password,"%s%c", password, stackItem);
  18787. }
  18788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18789. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18790. isSuccess = ConfigurationStatus_Accepted;
  18791. }
  18792. else
  18793. {
  18794. isSuccess = ConfigurationStatus_Rejected;
  18795. }
  18796. }
  18797. if(strcmp(key, "SecurityProfile") == 0)
  18798. {
  18799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18800. {
  18801. check_ascii = value[0];
  18802. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18803. {
  18804. isSuccess = ConfigurationStatus_Rejected;
  18805. }
  18806. else if(check_ascii == 0x33)
  18807. {
  18808. isSuccess = NotSupported;
  18809. }
  18810. else
  18811. {
  18812. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18813. {
  18814. if(((check_ascii - 0x30) == 1) ||
  18815. ((check_ascii - 0x30) == 2) ||
  18816. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18817. {
  18818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18819. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18820. isSuccess = ConfigurationStatus_Accepted;
  18821. }
  18822. else
  18823. isSuccess = ConfigurationStatus_Rejected;
  18824. }
  18825. else
  18826. isSuccess = ConfigurationStatus_Rejected;
  18827. }
  18828. }
  18829. else
  18830. {
  18831. isSuccess = ConfigurationStatus_Rejected;
  18832. }
  18833. }
  18834. if(strcmp(key, "DefaultPrice") == 0)
  18835. {
  18836. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18837. {
  18838. strcpy(str, (const char*)value);
  18839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18840. isSuccess = ConfigurationStatus_Accepted;
  18841. }
  18842. else
  18843. {
  18844. isSuccess = ConfigurationStatus_Rejected;
  18845. }
  18846. }
  18847. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18848. {
  18849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18850. {
  18851. strcpy(str, (const char*)value);
  18852. for(int i = 0; str[i]; i++)
  18853. {
  18854. str[i] = tolower(str[i]);
  18855. }
  18856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18857. isSuccess = ConfigurationStatus_Accepted;
  18858. }
  18859. else
  18860. {
  18861. isSuccess = ConfigurationStatus_Rejected;
  18862. }
  18863. }
  18864. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18865. {
  18866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18867. {
  18868. strcpy(str, (const char*)value);
  18869. for(int i = 0; str[i]; i++)
  18870. {
  18871. str[i] = tolower(str[i]);
  18872. }
  18873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18874. isSuccess = ConfigurationStatus_Accepted;
  18875. }
  18876. else
  18877. {
  18878. isSuccess = ConfigurationStatus_Rejected;
  18879. }
  18880. }
  18881. if(strcmp(key, "TimeOffset") == 0)
  18882. {
  18883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18884. {
  18885. strcpy(str, (const char*)value);
  18886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18887. isSuccess = ConfigurationStatus_Accepted;
  18888. }
  18889. else
  18890. {
  18891. isSuccess = ConfigurationStatus_Rejected;
  18892. }
  18893. }
  18894. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18895. {
  18896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18897. {
  18898. strcpy(str, (const char*)value);
  18899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18900. isSuccess = ConfigurationStatus_Accepted;
  18901. }
  18902. else
  18903. {
  18904. isSuccess = ConfigurationStatus_Rejected;
  18905. }
  18906. }
  18907. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18908. {
  18909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18910. {
  18911. strcpy(str, (const char*)value);
  18912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18913. isSuccess = ConfigurationStatus_Accepted;
  18914. }
  18915. else
  18916. {
  18917. isSuccess = ConfigurationStatus_Rejected;
  18918. }
  18919. }
  18920. if(strcmp(key, "SystemUptimeSec") == 0)
  18921. {
  18922. isSuccess = NotSupported;
  18923. }
  18924. if(strcmp(key, "FreeVend") == 0)
  18925. {
  18926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18927. {
  18928. strcpy(str, (const char*)value);
  18929. for(int i = 0; str[i]; i++)
  18930. {
  18931. str[i] = tolower(str[i]);
  18932. }
  18933. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18935. isSuccess = ConfigurationStatus_Accepted;
  18936. }
  18937. else
  18938. {
  18939. isSuccess = ConfigurationStatus_Rejected;
  18940. }
  18941. }
  18942. if(strcmp(key, "FreeVendIdtag") == 0)
  18943. {
  18944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18945. {
  18946. strcpy(str, (const char*)value);
  18947. if(strlen(str) <= 20)
  18948. {
  18949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18950. isSuccess = ConfigurationStatus_Accepted;
  18951. }
  18952. else
  18953. {
  18954. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18955. isSuccess = ConfigurationStatus_Rejected;
  18956. }
  18957. }
  18958. else
  18959. {
  18960. isSuccess = ConfigurationStatus_Rejected;
  18961. }
  18962. }
  18963. if(strcmp(key, "OcppServer") == 0)
  18964. {
  18965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18966. {
  18967. strcpy(str, (const char*)value);
  18968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18969. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18970. isSuccess = ConfigurationStatus_Accepted;
  18971. }
  18972. else
  18973. {
  18974. isSuccess = ConfigurationStatus_Rejected;
  18975. }
  18976. }
  18977. if(strcmp(key, "MaintainServer") == 0)
  18978. {
  18979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18980. {
  18981. strcpy(str, (const char*)value);
  18982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18983. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18984. isSuccess = ConfigurationStatus_Accepted;
  18985. }
  18986. else
  18987. {
  18988. isSuccess = ConfigurationStatus_Rejected;
  18989. }
  18990. }
  18991. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18992. {
  18993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18994. {
  18995. strcpy(str, (const char*)value);
  18996. for(int i = 0; str[i]; i++)
  18997. {
  18998. str[i] = tolower(str[i]);
  18999. }
  19000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  19001. isSuccess = ConfigurationStatus_Accepted;
  19002. }
  19003. else
  19004. {
  19005. isSuccess = ConfigurationStatus_Rejected;
  19006. }
  19007. }
  19008. if(strcmp(key, "StatusNotificationInterval") == 0)
  19009. {
  19010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  19011. {
  19012. check_ascii = value[0];
  19013. if( (check_ascii < 48) || (check_ascii > 57) )
  19014. {
  19015. isSuccess = ConfigurationStatus_Rejected;
  19016. }
  19017. else
  19018. {
  19019. if((atoi(value) == 0) || (atoi(value) >= 10))
  19020. {
  19021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  19022. isSuccess = ConfigurationStatus_Accepted;
  19023. }
  19024. else
  19025. isSuccess = ConfigurationStatus_Rejected;
  19026. }
  19027. }
  19028. else
  19029. {
  19030. isSuccess = ConfigurationStatus_Rejected;
  19031. }
  19032. }
  19033. if(strcmp(key, "PreAuthAmount") == 0)
  19034. {
  19035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  19036. {
  19037. check_ascii = value[0];
  19038. if( (check_ascii < 48) || (check_ascii > 57) )
  19039. {
  19040. isSuccess = ConfigurationStatus_Rejected;
  19041. }
  19042. else
  19043. {
  19044. if(atof(value) >= 0)
  19045. {
  19046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  19047. isSuccess = ConfigurationStatus_Accepted;
  19048. }
  19049. else
  19050. isSuccess = ConfigurationStatus_Rejected;
  19051. }
  19052. }
  19053. else
  19054. {
  19055. isSuccess = ConfigurationStatus_Rejected;
  19056. }
  19057. }
  19058. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  19059. {
  19060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  19061. {
  19062. check_ascii = value[0];
  19063. if( (check_ascii < 48) || (check_ascii > 57) )
  19064. {
  19065. isSuccess = ConfigurationStatus_Rejected;
  19066. }
  19067. else
  19068. {
  19069. if(atoi(value) >= 0)
  19070. {
  19071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  19072. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  19073. isSuccess = ConfigurationStatus_Accepted;
  19074. }
  19075. else
  19076. isSuccess = ConfigurationStatus_Rejected;
  19077. }
  19078. }
  19079. else
  19080. {
  19081. isSuccess = ConfigurationStatus_Rejected;
  19082. }
  19083. }
  19084. if(strcmp(key, "PowerSharingServerIP") == 0)
  19085. {
  19086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  19087. {
  19088. strcpy(str, (const char*)value);
  19089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  19090. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  19091. isSuccess = ConfigurationStatus_Accepted;
  19092. }
  19093. else
  19094. {
  19095. isSuccess = ConfigurationStatus_Rejected;
  19096. }
  19097. }
  19098. if(strcmp(key, "EVCCID_PREFIX") == 0)
  19099. {
  19100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  19101. {
  19102. strcpy(str, (const char*)value);
  19103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  19104. isSuccess = ConfigurationStatus_Accepted;
  19105. }
  19106. else
  19107. {
  19108. isSuccess = ConfigurationStatus_Rejected;
  19109. }
  19110. }
  19111. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19112. {
  19113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19114. {
  19115. if(atoi(value) > modelnameInfo.ratedPower)
  19116. {
  19117. isSuccess = ConfigurationStatus_Rejected;
  19118. }
  19119. else{
  19120. strcpy(str, (const char*)value);
  19121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  19122. isSuccess = ConfigurationStatus_Accepted;
  19123. }
  19124. }
  19125. else
  19126. {
  19127. isSuccess = ConfigurationStatus_Rejected;
  19128. }
  19129. }
  19130. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19131. {
  19132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19133. {
  19134. if((atoi(value) != 0) && (atoi(value) < 5))
  19135. {
  19136. isSuccess = ConfigurationStatus_Rejected;
  19137. }
  19138. else{
  19139. strcpy(str, (const char*)value);
  19140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19141. isSuccess = ConfigurationStatus_Accepted;
  19142. }
  19143. }
  19144. else
  19145. {
  19146. isSuccess = ConfigurationStatus_Rejected;
  19147. }
  19148. }
  19149. if(strcmp(key, "CpoName") == 0)
  19150. {
  19151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19152. {
  19153. strcpy(str, (const char*)value);
  19154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19155. isSuccess = ConfigurationStatus_Accepted;
  19156. }
  19157. else
  19158. {
  19159. isSuccess = ConfigurationStatus_Rejected;
  19160. }
  19161. }
  19162. if(strcmp(key, "OcppSoftwareVersion") == 0)
  19163. {
  19164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  19165. {
  19166. strcpy(str, (const char*)value);
  19167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", str );
  19168. isSuccess = ConfigurationStatus_Accepted;
  19169. }
  19170. else
  19171. {
  19172. isSuccess = ConfigurationStatus_Rejected;
  19173. }
  19174. }
  19175. if(strcmp(key, "AuthDownloadlinkCertificate") == 0)
  19176. {
  19177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  19178. {
  19179. strcpy(str, (const char*)value);
  19180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19181. isSuccess = ConfigurationStatus_Accepted;
  19182. }
  19183. else
  19184. {
  19185. isSuccess = ConfigurationStatus_Rejected;
  19186. }
  19187. }
  19188. if(strcmp(key, "RfidEndianType") == 0)
  19189. {
  19190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  19191. {
  19192. strcpy(str, (const char*)value);
  19193. if((strcmp(str, "BIG")==0) || (strcmp(str, "LITTLE")==0))
  19194. {
  19195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "%s", str );
  19196. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = (strcmp(str, "BIG")==0)?1:0;
  19197. isSuccess = ConfigurationStatus_Accepted;
  19198. }
  19199. else
  19200. isSuccess = ConfigurationStatus_Rejected;
  19201. }
  19202. else
  19203. {
  19204. isSuccess = ConfigurationStatus_Rejected;
  19205. }
  19206. }
  19207. if(strcmp(key, "AuthorizeTimeout") == 0)
  19208. {
  19209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  19210. {
  19211. strcpy(str, (const char*)value);
  19212. check_ascii = value[0];
  19213. if((check_ascii < 48) || (check_ascii > 57))
  19214. {
  19215. isSuccess = ConfigurationStatus_Rejected;
  19216. }
  19217. else
  19218. {
  19219. if((atoi(value) >= 10) && (atoi(value) <= 300))
  19220. {
  19221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%s", str );
  19222. isSuccess = ConfigurationStatus_Accepted;
  19223. }
  19224. else
  19225. {
  19226. isSuccess = ConfigurationStatus_Rejected;
  19227. }
  19228. }
  19229. }
  19230. else
  19231. {
  19232. isSuccess = ConfigurationStatus_Rejected;
  19233. }
  19234. }
  19235. if(strcmp(key, "EnableAcCcs") == 0)
  19236. {
  19237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemAccessibility == 1)
  19238. {
  19239. strcpy(str, (const char*)value);
  19240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19241. isSuccess = ConfigurationStatus_Accepted;
  19242. }
  19243. else
  19244. {
  19245. isSuccess = ConfigurationStatus_Rejected;
  19246. }
  19247. }
  19248. #if 0
  19249. //For OCPP Test Case
  19250. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19251. {
  19252. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19253. {
  19254. strcpy(str, (const char*)value);
  19255. for(int i = 0; str[i]; i++)
  19256. {
  19257. str[i] = tolower(str[i]);
  19258. }
  19259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19260. isSuccess = ConfigurationStatus_Accepted;
  19261. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19262. }
  19263. else
  19264. {
  19265. isSuccess = ConfigurationStatus_Rejected;
  19266. }
  19267. }
  19268. #endif
  19269. #if 1
  19270. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19271. {
  19272. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19273. {
  19274. strcpy(str, (const char*)value);
  19275. for(int i = 0; str[i]; i++)
  19276. {
  19277. str[i] = tolower(str[i]);
  19278. }
  19279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19280. isSuccess = ConfigurationStatus_Accepted;
  19281. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19282. }
  19283. else
  19284. {
  19285. isSuccess = ConfigurationStatus_Rejected;
  19286. }
  19287. }
  19288. #endif
  19289. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19290. {
  19291. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19292. {
  19293. check_ascii = value[0];
  19294. if( (check_ascii < 48) || (check_ascii > 57) )
  19295. {
  19296. isSuccess = ConfigurationStatus_Rejected;
  19297. }
  19298. else
  19299. {
  19300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19301. isSuccess = ConfigurationStatus_Accepted;
  19302. }
  19303. }
  19304. else
  19305. {
  19306. isSuccess = ConfigurationStatus_Rejected;
  19307. }
  19308. }
  19309. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19310. {
  19311. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19312. {
  19313. check_ascii = value[0];
  19314. if( (check_ascii < 48) || (check_ascii > 57) )
  19315. {
  19316. isSuccess = ConfigurationStatus_Rejected;
  19317. }
  19318. else
  19319. {
  19320. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19321. isSuccess = ConfigurationStatus_Accepted;
  19322. }
  19323. }
  19324. else
  19325. {
  19326. isSuccess = ConfigurationStatus_Rejected;
  19327. }
  19328. }
  19329. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19330. {
  19331. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19332. {
  19333. strcpy(str, (const char*)value);
  19334. for(int i = 0; str[i]; i++)
  19335. {
  19336. str[i] = tolower(str[i]);
  19337. }
  19338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19339. isSuccess = ConfigurationStatus_Accepted;
  19340. }
  19341. else
  19342. {
  19343. isSuccess = ConfigurationStatus_Rejected;
  19344. }
  19345. }
  19346. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19347. {
  19348. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19349. {
  19350. check_ascii = value[0];
  19351. if( (check_ascii < 48) || (check_ascii > 57) )
  19352. {
  19353. isSuccess = ConfigurationStatus_Rejected;
  19354. }
  19355. else
  19356. {
  19357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19358. isSuccess = ConfigurationStatus_Accepted;
  19359. }
  19360. }
  19361. else
  19362. {
  19363. isSuccess = ConfigurationStatus_Rejected;
  19364. }
  19365. }
  19366. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19367. {
  19368. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19369. {
  19370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19371. isSuccess = ConfigurationStatus_Accepted;
  19372. }
  19373. else
  19374. {
  19375. isSuccess = ConfigurationStatus_Rejected;
  19376. }
  19377. }
  19378. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19379. {
  19380. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19381. {
  19382. check_ascii = value[0];
  19383. if( (check_ascii < 48) || (check_ascii > 57) )
  19384. {
  19385. isSuccess = ConfigurationStatus_Rejected;
  19386. }
  19387. else
  19388. {
  19389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19390. isSuccess = ConfigurationStatus_Accepted;
  19391. }
  19392. }
  19393. else
  19394. {
  19395. isSuccess = ConfigurationStatus_Rejected;
  19396. }
  19397. }
  19398. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19399. {
  19400. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19401. {
  19402. strcpy(str, (const char*)value);
  19403. for(int i = 0; str[i]; i++)
  19404. {
  19405. str[i] = tolower(str[i]);
  19406. }
  19407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19408. isSuccess = ConfigurationStatus_Accepted;
  19409. }
  19410. else
  19411. {
  19412. isSuccess = ConfigurationStatus_Rejected;
  19413. }
  19414. }
  19415. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19416. {
  19417. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19418. {
  19419. check_ascii = value[0];
  19420. if( (check_ascii < 48) || (check_ascii > 57) )
  19421. {
  19422. isSuccess = ConfigurationStatus_Rejected;
  19423. }
  19424. else
  19425. {
  19426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19427. isSuccess = ConfigurationStatus_Accepted;
  19428. }
  19429. }
  19430. else
  19431. {
  19432. isSuccess = ConfigurationStatus_Rejected;
  19433. }
  19434. }
  19435. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19436. return isSuccess;
  19437. }
  19438. int TransactionMessageAttemptsGet(void)
  19439. {
  19440. return TransactionMessageAttemptsValue;
  19441. }
  19442. int FirstHeartBeatResponse(void)
  19443. {
  19444. return FirstHeartBeat;
  19445. }
  19446. int TransactionMessageRetryIntervalGet(void)
  19447. {
  19448. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19449. }
  19450. int ReadHttpStatus(int sock)
  19451. {
  19452. //char c;
  19453. char buff[1024]="",*ptr=buff+1;
  19454. int bytes_received, status;
  19455. DEBUG_INFO("Begin Response ..\n");
  19456. while((bytes_received = recv(sock, ptr, 1, 0))){
  19457. if(bytes_received==-1){
  19458. perror("ReadHttpStatus");
  19459. exit(1);
  19460. }
  19461. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19462. ptr++;
  19463. }
  19464. *ptr=0;
  19465. ptr=buff+1;
  19466. sscanf(ptr,"%*s %d ", &status);
  19467. DEBUG_INFO("%s\n",ptr);
  19468. DEBUG_INFO("status=%d\n",status);
  19469. DEBUG_INFO("End Response ..\n");
  19470. return (bytes_received>0)?status:0;
  19471. }
  19472. //the only filed that it parsed is 'Content-Length'
  19473. int ParseHeader(int sock)
  19474. {
  19475. //char c;
  19476. char buff[1024]="",*ptr=buff+4;
  19477. int bytes_received;
  19478. DEBUG_INFO("Begin HEADER ..\n");
  19479. while((bytes_received = recv(sock, ptr, 1, 0))){
  19480. if(bytes_received==-1){
  19481. perror("Parse Header");
  19482. exit(1);
  19483. }
  19484. if(
  19485. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19486. (ptr[-1]=='\r') && (*ptr=='\n' )
  19487. ) break;
  19488. ptr++;
  19489. }
  19490. *ptr=0;
  19491. ptr=buff+4;
  19492. //printf("%s",ptr);
  19493. if(bytes_received){
  19494. ptr=strstr(ptr,"Content-Length:");
  19495. if(ptr){
  19496. sscanf(ptr,"%*s %d",&bytes_received);
  19497. }else
  19498. bytes_received=-1; //unknown size
  19499. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19500. }
  19501. DEBUG_INFO("End HEADER ..\n");
  19502. return bytes_received ;
  19503. }
  19504. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19505. {
  19506. int result = TRUE;
  19507. char rmFileCmd[300]={0};
  19508. char FilePath[256]={0};
  19509. char ftpbuf[2048];
  19510. int systemresult;
  19511. sprintf(FilePath,"/mnt/%s",filename);
  19512. system("ping 8.8.8.8 &");
  19513. if((access(FilePath,F_OK))!=-1)
  19514. {
  19515. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19516. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19517. system(rmFileCmd);
  19518. }
  19519. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19520. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19521. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19522. else
  19523. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19524. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19525. systemresult = system(ftpbuf);
  19526. if(systemresult != 0)
  19527. {
  19528. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19529. result = FALSE;
  19530. }
  19531. system("pkill ping");
  19532. return result;
  19533. }
  19534. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19535. {
  19536. int result = TRUE;
  19537. char rmFileCmd[300]={0};
  19538. char FilePath[256]={0};
  19539. char ftpbuf[2048];
  19540. int systemresult;
  19541. sprintf(FilePath,"/mnt/%s",filename);
  19542. system("ping 8.8.8.8 &");
  19543. if((access(FilePath,F_OK))!=-1)
  19544. {
  19545. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19546. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19547. system(rmFileCmd);
  19548. }
  19549. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19550. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19551. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19552. systemresult = system(ftpbuf);
  19553. if(systemresult != 0)
  19554. {
  19555. DEBUG_WARN("scp error!\n");
  19556. result = FALSE;
  19557. }
  19558. system("pkill ping");
  19559. return result;
  19560. }
  19561. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19562. {
  19563. int result = TRUE;
  19564. char rmFileCmd[300]={0};
  19565. char FilePath[256]={0};
  19566. char ftpbuf[2048];
  19567. int systemresult;
  19568. sprintf(FilePath,"/mnt/%s",filename);
  19569. system("ping 8.8.8.8 &");
  19570. if((access(FilePath,F_OK))!=-1)
  19571. {
  19572. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19573. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19574. system(rmFileCmd);
  19575. }
  19576. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19577. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19578. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19579. else
  19580. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19581. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19582. systemresult = system(ftpbuf);
  19583. if(systemresult != 0)
  19584. {
  19585. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19586. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --ca-certificate=/root/cacert.pem",filename, url);
  19587. else
  19588. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --no-check-certificate",filename, url);
  19589. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19590. systemresult = system(ftpbuf);
  19591. if(systemresult != 0)
  19592. {
  19593. DEBUG_WARN("FTP download fail!\n");
  19594. result = FALSE;
  19595. }
  19596. }
  19597. system("pkill ping");
  19598. return result;
  19599. }
  19600. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19601. {
  19602. char rmFileCmd[100]={0};
  19603. char FilePath[100]={0};
  19604. char buf[512];
  19605. int systemresult = 0;
  19606. //DEBUG_INFO("filename=%s\n",filename);
  19607. //DEBUG_INFO("url=%s\n",url);
  19608. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19609. if((access(FilePath,F_OK))!=-1)
  19610. {
  19611. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19612. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19613. system(rmFileCmd);
  19614. }
  19615. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19616. if(fp == NULL)
  19617. {
  19618. DEBUG_INFO("log is NULL\n");
  19619. return FALSE;
  19620. }
  19621. else
  19622. {
  19623. fprintf(fp, "%s\n", url);
  19624. fprintf(fp, "%s\n", filename);
  19625. fclose(fp);
  19626. }
  19627. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19628. if(phpFP == NULL)
  19629. {
  19630. DEBUG_INFO("PHP upload fail.\n");
  19631. return FALSE;
  19632. }
  19633. else
  19634. {
  19635. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19636. {
  19637. if(strstr(buf, "result") != NULL)
  19638. {
  19639. sscanf(buf, "result: %d", &systemresult);
  19640. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19641. }
  19642. }
  19643. pclose(phpFP);
  19644. }
  19645. if(systemresult != 1)
  19646. {
  19647. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19648. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19649. if(phpFP == NULL)
  19650. {
  19651. DEBUG_WARN("PHP PUT upload fail.\n");
  19652. return FALSE;
  19653. }
  19654. else
  19655. {
  19656. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19657. {
  19658. if(strstr(buf, "result") != NULL)
  19659. {
  19660. sscanf(buf, "result: %d", &systemresult);
  19661. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19662. }
  19663. }
  19664. pclose(phpFP);
  19665. }
  19666. }
  19667. if(systemresult != 1)
  19668. {
  19669. DEBUG_WARN("PHP PUT upload fail.\n");
  19670. return FALSE;
  19671. }
  19672. return TRUE;
  19673. }
  19674. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19675. {
  19676. int result = FALSE;
  19677. char ftpbuf[200];
  19678. int systemresult;
  19679. /*
  19680. // Domaind name transfer to IP address
  19681. struct hostent* server;
  19682. char *IPbuffer;
  19683. server = gethostbyname(location);
  19684. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19685. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19686. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19687. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19688. systemresult = system(ftpbuf);
  19689. if(systemresult != 0)
  19690. {
  19691. DEBUG_INFO("ftpput error!\n");
  19692. }
  19693. else
  19694. {
  19695. result = TRUE;
  19696. DEBUG_INFO("ftpput OK!\n");
  19697. }
  19698. return result;
  19699. }
  19700. int GetOcppServerURL()
  19701. {
  19702. int result = FALSE;
  19703. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19704. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19705. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19706. struct yuarel url;
  19707. char urlStr[512];
  19708. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19709. {
  19710. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19711. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19712. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19713. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19714. if(yuarel_parse(&url, urlStr) != -1)
  19715. {
  19716. sprintf(OcppProtocol, "%s", url.scheme);
  19717. sprintf(OcppHost, "%s", url.host);
  19718. if(url.path == NULL)
  19719. OcppTempPath[0] = '\0';
  19720. else
  19721. {
  19722. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19723. {
  19724. sprintf(OcppTempPath, "%s/", url.path);
  19725. }
  19726. else
  19727. {
  19728. sprintf(OcppTempPath, "%s", url.path);
  19729. }
  19730. }
  19731. if(url.port == 0)
  19732. {
  19733. if(strcmp(OcppProtocol, "wss") == 0)
  19734. OcppPort = 443;
  19735. else
  19736. OcppPort = 80;
  19737. }
  19738. else
  19739. OcppPort = url.port;
  19740. result = TRUE;
  19741. }
  19742. }
  19743. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19744. {
  19745. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19746. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19747. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19748. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19749. if(yuarel_parse(&url, urlStr) != -1)
  19750. {
  19751. sprintf(OcppProtocol, "%s", url.scheme);
  19752. sprintf(OcppHost, "%s", url.host);
  19753. if(url.path == NULL)
  19754. OcppTempPath[0] = '\0';
  19755. else
  19756. sprintf(OcppTempPath, "%s", url.path);
  19757. if(url.port == 0)
  19758. {
  19759. if(strcmp(OcppProtocol, "wss") == 0)
  19760. OcppPort = 443;
  19761. else
  19762. OcppPort = 80;
  19763. }
  19764. else
  19765. OcppPort = url.port;
  19766. result = TRUE;
  19767. }
  19768. }
  19769. else
  19770. {
  19771. strcpy(OcppHost,"");
  19772. }
  19773. return result;
  19774. }
  19775. int GetOcppPath()
  19776. {
  19777. int result = FALSE;
  19778. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19779. {
  19780. if(OcppTempPath == NULL)
  19781. {
  19782. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19783. }
  19784. else
  19785. {
  19786. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19787. }
  19788. result = TRUE;
  19789. goto End;
  19790. }
  19791. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19792. {
  19793. if(OcppTempPath == NULL)
  19794. {
  19795. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19796. }
  19797. else
  19798. {
  19799. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19800. }
  19801. result = TRUE;
  19802. goto End;
  19803. }
  19804. else
  19805. {
  19806. strcpy(OcppPath,"");
  19807. }
  19808. End:
  19809. return result;
  19810. }
  19811. int GetOcppPort()
  19812. {
  19813. return OcppPort;
  19814. }
  19815. int GetOcppConnStatus(void)
  19816. {
  19817. return ShmOCPP16Data->OcppConnStatus;
  19818. }
  19819. void SetOcppConnStatus(uint8_t status)
  19820. {
  19821. ShmOCPP16Data->OcppConnStatus = status;
  19822. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19823. }
  19824. int GetHeartBeatWithNOResponse(void)
  19825. {
  19826. return HeartBeatWithNOResponse;
  19827. }
  19828. void SetHeartBeatWithNOResponse(void)
  19829. {
  19830. HeartBeatWithNOResponse = 0;
  19831. }
  19832. void GetStartTransactionIdTag(int gun_index)
  19833. {
  19834. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19835. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19836. }
  19837. int GetStartTransactionId(int gun_index)
  19838. {
  19839. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19840. }
  19841. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19842. {
  19843. char ch;
  19844. FILE *fptr1;
  19845. int temptransactionId;
  19846. char str[100]={0};
  19847. temptransactionId = 0;
  19848. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19849. {
  19850. DEBUG_INFO("IdTag is empty.\n");
  19851. return temptransactionId;
  19852. }
  19853. /*------ Read the file ----------------*/
  19854. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19855. if (!fptr1)
  19856. {
  19857. DEBUG_INFO("QueueTransactionId file open error.\n");
  19858. //printf(" File not found or unable to open the input file!!\n");
  19859. return temptransactionId;
  19860. }
  19861. ch=fgetc(fptr1);
  19862. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19863. rewind(fptr1);
  19864. if(ch!=EOF)
  19865. {
  19866. // printf("%c",ch);
  19867. while (fgets(str, 100, fptr1) != NULL)
  19868. {
  19869. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19870. if(str[0]=='\0')
  19871. {
  19872. break;
  19873. }
  19874. char *revbuf[8] = {0}; // Variable store string split
  19875. int num = 0;// Quantity after string split
  19876. DEBUG_INFO("Transaction queue data= %s\n", str);
  19877. splitstring(str,",",revbuf,&num); // String split
  19878. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19879. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19880. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19881. DEBUG_INFO("------------------------------\n");
  19882. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19883. {
  19884. if(isStopTransaction)
  19885. {
  19886. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19887. {
  19888. temptransactionId = atoi(revbuf[2]);
  19889. //break;
  19890. }
  19891. }
  19892. else
  19893. {
  19894. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19895. {
  19896. temptransactionId = atoi(revbuf[2]);
  19897. //break;
  19898. }
  19899. }
  19900. }
  19901. }
  19902. }
  19903. else
  19904. DEBUG_INFO("EOF\n");
  19905. fclose(fptr1);
  19906. /*------- End of reading ---------------*/
  19907. return temptransactionId;
  19908. }
  19909. void SetTransactionIdZero(int transactionId)
  19910. {
  19911. char ch;
  19912. FILE *fptr1, *fptr2;
  19913. int temptransactionId = 0;
  19914. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19915. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19916. if (!fptr1)
  19917. {
  19918. //printf(" File not found or unable to open the input file!!\n");
  19919. return ;
  19920. }
  19921. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19922. if (!fptr2)
  19923. {
  19924. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19925. fclose(fptr1);
  19926. return ;
  19927. }
  19928. ch=fgetc(fptr1);
  19929. rewind(fptr1);
  19930. if(ch!=EOF)
  19931. {
  19932. // copy all contents to the temporary file except the specific line
  19933. while (fgets(str, 100, fptr1) != NULL)
  19934. {
  19935. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19936. if(str[0]=='\0')
  19937. {
  19938. break;
  19939. }
  19940. char *revbuf[8] = {0};
  19941. int num = 0;
  19942. strcpy(strtemp, str);
  19943. splitstring(str,",",revbuf,&num);
  19944. if(revbuf[2][0] != '\0')
  19945. {
  19946. temptransactionId = atoi(revbuf[2]);
  19947. if(transactionId != temptransactionId)
  19948. {
  19949. fprintf(fptr2, "%s\n", strtemp);
  19950. }
  19951. }
  19952. }
  19953. }
  19954. fclose(fptr1);
  19955. fclose(fptr2);
  19956. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19957. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19958. /*------ Read the file ----------------*/
  19959. }
  19960. int InternetDisconnect(void)
  19961. {
  19962. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19963. }
  19964. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19965. void storeTempStopTransaction(int gun_index)
  19966. {
  19967. char guid[37]={0};
  19968. int tempIndex = 0;
  19969. char TempStopTransaction[256];
  19970. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19971. DEBUG_INFO("storeTempStopTransaction...\n");
  19972. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19973. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19974. //=========================== Stop Transaction Time ===============================================
  19975. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19976. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19977. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19978. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19979. {
  19980. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19981. {
  19982. tempIndex = ((gun_index==2) ? 1: 0);
  19983. }
  19984. else
  19985. {
  19986. tempIndex = gun_index;
  19987. }
  19988. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19989. {
  19990. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19991. {
  19992. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19993. }
  19994. }// END OF CHAdeMO_QUANTITY
  19995. }
  19996. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19997. {
  19998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19999. {
  20000. tempIndex = ((gun_index==2) ? 1: 0);
  20001. }
  20002. else
  20003. {
  20004. tempIndex = gun_index;
  20005. }
  20006. for (int index = 0; index < CCS_QUANTITY; index++)
  20007. {
  20008. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20009. {
  20010. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  20011. }
  20012. }// END OF CCS_QUANTITY
  20013. }
  20014. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20015. {
  20016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20017. {
  20018. tempIndex = ((gun_index==2) ? 1: 0);
  20019. }
  20020. else
  20021. {
  20022. tempIndex = gun_index;
  20023. }
  20024. for (int index = 0; index < GB_QUANTITY; index++)
  20025. {
  20026. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20027. {
  20028. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  20029. }
  20030. }// END OF GB_QUANTITY
  20031. }
  20032. else if(gunType[gun_index] == GUN_TYPE_DO)
  20033. {
  20034. tempIndex = gun_index;
  20035. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20036. {
  20037. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20038. {
  20039. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  20040. }
  20041. }
  20042. }
  20043. else
  20044. {
  20045. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20046. {
  20047. tempIndex = 2;
  20048. }
  20049. else
  20050. {
  20051. tempIndex = gun_index;
  20052. }
  20053. for (int index = 0; index < AC_QUANTITY; index++)
  20054. {
  20055. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20056. {
  20057. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  20058. }
  20059. }// END OF AC_QUANTITY
  20060. }
  20061. //======================================== Message create ==============================================
  20062. json_object *StopTransaction = json_object_new_object();
  20063. json_object *transactionDatas = json_object_new_array();
  20064. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20065. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20066. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20067. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20068. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20069. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20070. meterValueBufferQuery(gun_index, transactionDatas);
  20071. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20072. random_uuid(guid);
  20073. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20074. ,MESSAGE_TYPE_CALL
  20075. ,guid
  20076. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20077. json_object_put(StopTransaction);
  20078. // Check File "TempStopTransaction" Exist
  20079. if((access(TempStopTransaction,F_OK))!=-1)
  20080. {
  20081. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20082. fclose(fopen(TempStopTransaction, "w"));
  20083. }
  20084. else
  20085. {
  20086. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20087. FILE *log = fopen(TempStopTransaction, "w+");
  20088. if(log == NULL)
  20089. {
  20090. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20091. return ;
  20092. }
  20093. else
  20094. {
  20095. fclose(log);
  20096. }
  20097. }
  20098. //Add TempStopTransaction | Update TempStopTransaction
  20099. // open file for writing
  20100. FILE *outfile;
  20101. outfile = fopen (TempStopTransaction, "a");
  20102. //DEBUG_INFO("data = %s\n", queuedata);
  20103. fputs(queuedata, outfile);
  20104. fputs("\n", outfile);
  20105. fclose (outfile);
  20106. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20107. OCPP_updatePeriodEnergy(gun_index);
  20108. }
  20109. void checkTempStopTransaction(int gun_index)
  20110. {
  20111. FILE *fptr1;
  20112. char ch;
  20113. char str[QUEUE_MESSAGE_LENGTH]={0};
  20114. char guid[37]={0};
  20115. char tempdata[65]={0};
  20116. char connectorStr[2]={0};
  20117. char TempStopTransaction[256];
  20118. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20119. fptr1 = fopen(TempStopTransaction, "r");
  20120. //TempStopTransaction格式: 槍號,StopTransaction封包
  20121. if (!fptr1)
  20122. {
  20123. //printf(" File not found or unable to open the input file!!\n");
  20124. return ;
  20125. }
  20126. ch=fgetc(fptr1);
  20127. //printf(" Now the content of the file %s is : \n",fname);
  20128. rewind(fptr1);
  20129. if(ch!=EOF)
  20130. {
  20131. // copy all contents to the temporary file except the specific line
  20132. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  20133. {
  20134. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20135. if(str[0]=='\0')
  20136. {
  20137. break;
  20138. }
  20139. //TempStopTransaction格式: 槍號,StopTransaction封包
  20140. strncpy(connectorStr, str, 1);
  20141. if(atoi(connectorStr) != (gun_index+1))
  20142. {
  20143. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  20144. fclose(fptr1);
  20145. return ;
  20146. }
  20147. //random_uuid(guid);
  20148. strncpy(guid, str+6, 36); //copy guid
  20149. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  20150. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  20151. {
  20152. //DEBUG_INFO("StopTransaction mapitem pass\n");
  20153. }
  20154. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  20155. OCPP_insert_transaction_msg(NO, str);
  20156. memset(str,0,ARRAY_SIZE(str));
  20157. }
  20158. }
  20159. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  20160. fclose(fptr1);
  20161. remove(TempStopTransaction); // remove the original file
  20162. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20163. }
  20164. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  20165. {
  20166. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20167. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  20168. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  20169. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  20170. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  20171. }
  20172. void FillTransactionId(int ConnectorId, int TransactionId)
  20173. {
  20174. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20175. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  20176. }
  20177. int GetWebSocketPingInterval(void)
  20178. {
  20179. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  20180. }
  20181. int GetServerSign(void)
  20182. {
  20183. return server_sign;
  20184. }
  20185. uint8_t GetOcppSecurityProfile()
  20186. {
  20187. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  20188. }
  20189. void MergeCertificates()
  20190. {
  20191. char cmdBuf[2048]={0};
  20192. if(access(ROOTCA_CS,F_OK) != -1)
  20193. {
  20194. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  20195. }
  20196. else
  20197. {
  20198. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20199. }
  20200. system(cmdBuf);
  20201. }
  20202. void GetOcppChargerBoxId(uint8_t *data)
  20203. {
  20204. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20205. }
  20206. void GetOcppSecurityPassword(uint8_t *data)
  20207. {
  20208. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20209. }
  20210. void SetOcppVersion(uint8_t *version)
  20211. {
  20212. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20213. DEBUG_INFO("ocpp version: %s\n", version);
  20214. if(strstr((char*)version, "ocpp1.6") != NULL)
  20215. {
  20216. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20217. }
  20218. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20219. {
  20220. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20221. system("pkill OcppBackend");
  20222. }
  20223. }
  20224. void SetServerSign(int value)
  20225. {
  20226. server_sign = value;
  20227. }
  20228. int GetBootNotificationInterval(void)
  20229. {
  20230. return BootNotificationInterval;
  20231. }
  20232. int GetInternetConn(void)
  20233. {
  20234. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20235. }
  20236. int GetBackendConnectionTimeout(void)
  20237. {
  20238. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20239. }
  20240. int isConnectorInitMode(int gun_index)
  20241. {
  20242. int tempIndex = 0;
  20243. int result = TRUE;
  20244. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20245. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20246. {
  20247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20248. {
  20249. tempIndex = ((gun_index==2) ? 1: 0);
  20250. }
  20251. else
  20252. {
  20253. tempIndex = gun_index;
  20254. }
  20255. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20256. {
  20257. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20258. {
  20259. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20260. } //end of the same index
  20261. }//end of for CHAdeMO_QUANTITY
  20262. }
  20263. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20264. {
  20265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20266. {
  20267. tempIndex = ((gun_index==2) ? 1: 0);
  20268. }
  20269. else
  20270. {
  20271. tempIndex = gun_index;
  20272. }
  20273. for (int index = 0; index < CCS_QUANTITY; index++)
  20274. {
  20275. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20276. {
  20277. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20278. } //end of the same index
  20279. } // end of for CCS_QUANTITY
  20280. }
  20281. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20282. {
  20283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20284. {
  20285. tempIndex = ((gun_index==2) ? 1: 0);
  20286. }
  20287. else
  20288. {
  20289. tempIndex = gun_index;
  20290. }
  20291. for (int index = 0; index < GB_QUANTITY; index++)
  20292. {
  20293. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20294. {
  20295. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20296. } //end of the same index
  20297. } // end of for GB_QUANTITY
  20298. }
  20299. else if(gunType[gun_index] == GUN_TYPE_DO)
  20300. {
  20301. tempIndex = gun_index;
  20302. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20303. {
  20304. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20305. {
  20306. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20307. } //end of the same index
  20308. }
  20309. }
  20310. else
  20311. {
  20312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20313. {
  20314. tempIndex = 2;
  20315. }
  20316. else
  20317. {
  20318. tempIndex = gun_index;
  20319. }
  20320. for (int index = 0; index < AC_QUANTITY; index++)
  20321. {
  20322. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20323. {
  20324. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20325. }//end of the same index
  20326. }//end of for AC_QUANTITY
  20327. }
  20328. return result;
  20329. }
  20330. void refreshProcDogTimer()
  20331. {
  20332. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20333. }
  20334. void InitialSystemValue(void)
  20335. {
  20336. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20337. locallistVersion=0;
  20338. BootNotificationInterval = 0;
  20339. authorizeRetryTimes = 0;
  20340. GunStatusInterval = 10;
  20341. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20342. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20343. //Heart Beat
  20344. HeartBeatWithNOResponse = 0;
  20345. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20346. if(HeartBeatWaitTime == 0)
  20347. FirstHeartBeat = TRUE;
  20348. else
  20349. FirstHeartBeat = FALSE;
  20350. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20351. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20352. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20353. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20354. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20355. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20356. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20357. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20358. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20359. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20360. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20361. //Status && ConnectorPlugIn Setting
  20362. Connector0PreviousSystemStatus = 99;
  20363. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20364. {
  20365. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20366. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20367. }
  20368. for (int index = 0; index < CCS_QUANTITY; index++)
  20369. {
  20370. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20371. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20372. }
  20373. for (int index = 0; index < GB_QUANTITY; index++)
  20374. {
  20375. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20376. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20377. }
  20378. for (int index = 0; index < AC_QUANTITY; index++)
  20379. {
  20380. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20381. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20382. }
  20383. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20384. {
  20385. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20386. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20387. }
  20388. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20389. {
  20390. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20391. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20392. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20393. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20394. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20395. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20396. }
  20397. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20398. refreshStartTimer(&clientTime.Heartbeat);
  20399. sleep(1);
  20400. }
  20401. void LWS_Send(char *str)
  20402. {
  20403. //=====================================================
  20404. // Check InternetConn 0: disconnected, 1: connected
  20405. //====================================================
  20406. if(GetOcppConnStatus() == 0)
  20407. {
  20408. DEBUG_INFO("offline now !!!\n");
  20409. return;
  20410. }
  20411. // Only disable isWebsocketSendable operation initiated by charger
  20412. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20413. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20414. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20415. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20416. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20417. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20418. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20419. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20420. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20421. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20422. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20423. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20424. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20425. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20426. {
  20427. isWebsocketSendable = 0;
  20428. }
  20429. pthread_mutex_lock(&lock_send);
  20430. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20431. sprintf((char *)SendBuffer, "%s", str);
  20432. SendBufLen = strlen(str);
  20433. pthread_mutex_unlock(&lock_send);
  20434. lws_callback_on_writable(wsi_client);
  20435. //lws_service(context, 0);
  20436. //sleep(1);
  20437. }
  20438. void LWS_SendNow(char *str)
  20439. {
  20440. //=====================================================
  20441. // Check InternetConn 0: disconnected, 1: connected
  20442. //====================================================
  20443. if(GetOcppConnStatus() == 0)
  20444. {
  20445. DEBUG_INFO("offline now !!!\n");
  20446. return;
  20447. }
  20448. // Only disable isWebsocketSendable operation initiated by charger
  20449. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20450. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20451. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20452. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20453. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20454. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20455. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20456. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20457. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20458. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20459. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20460. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20461. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20462. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20463. {
  20464. isWebsocketSendable = 0;
  20465. }
  20466. pthread_mutex_lock(&lock_send);
  20467. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20468. sprintf((char *)SendBuffer, "%s", str);
  20469. SendBufLen = strlen(str);
  20470. pthread_mutex_unlock(&lock_send);
  20471. lws_callback_on_writable(wsi_client);
  20472. lws_service(context, 0);
  20473. //sleep(1);
  20474. }