MessageHandler.c 1022 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809
  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. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='Z'))
  4394. ) // 'D' means DC
  4395. {
  4396. // DO series
  4397. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4398. {
  4399. gunTotalNumber += 1;
  4400. gunType[gun_index] = GUN_TYPE_DO;
  4401. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4402. {
  4403. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4404. {
  4405. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4406. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4407. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4408. }
  4409. }
  4410. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4411. {
  4412. case Gun_Type_Chademo:
  4413. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4414. break;
  4415. case Gun_Type_CCS_2:
  4416. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4417. break;
  4418. case Gun_Type_GB:
  4419. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4420. break;
  4421. case Gun_Type_AC:
  4422. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4423. break;
  4424. default:
  4425. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4426. break;
  4427. }
  4428. }
  4429. }
  4430. else
  4431. {
  4432. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4433. {
  4434. gunTotalNumber += 1;
  4435. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4436. {
  4437. case Gun_Type_Chademo:
  4438. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4439. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4440. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4441. {
  4442. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4443. {
  4444. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4445. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4446. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4447. }
  4448. }
  4449. break;
  4450. case Gun_Type_CCS_2:
  4451. gunType[gun_index] = GUN_TYPE_CCS;
  4452. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4453. for (int index = 0; index < CCS_QUANTITY; index++)
  4454. {
  4455. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4456. {
  4457. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4458. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4459. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4460. }
  4461. }
  4462. break;
  4463. case Gun_Type_GB:
  4464. gunType[gun_index] = GUN_TYPE_GBT;
  4465. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4466. for (int index = 0; index < GB_QUANTITY; index++)
  4467. {
  4468. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4469. {
  4470. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4471. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4472. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4473. }
  4474. }
  4475. break;
  4476. case Gun_Type_AC:
  4477. gunType[gun_index] = GUN_TYPE_AC;
  4478. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4479. for (int index = 0; index < AC_QUANTITY; index++)
  4480. {
  4481. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4482. {
  4483. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4484. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4485. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4486. }
  4487. }
  4488. break;
  4489. default:
  4490. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4491. break;
  4492. }
  4493. }
  4494. }
  4495. }
  4496. else
  4497. {
  4498. DEBUG_ERROR("Model name parsing fail.\n");
  4499. result = FAIL;
  4500. }
  4501. if(result != PASS)sleep(5);
  4502. return result;
  4503. }
  4504. void checkRemoteStart(uint8_t connectorIdInt)
  4505. {
  4506. uint8_t tempIndex;
  4507. int result = PASS;
  4508. char cmdBuf[512];
  4509. //check Transaction active
  4510. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4511. {
  4512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4513. {
  4514. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4515. }
  4516. else
  4517. {
  4518. tempIndex = connectorIdInt -1;
  4519. }
  4520. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4521. {
  4522. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4523. {
  4524. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4525. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4526. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4527. {
  4528. //Reserved
  4529. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4530. }
  4531. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4532. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4533. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4534. {
  4535. //Reserved
  4536. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4537. result = FAIL;
  4538. goto end;
  4539. }
  4540. else
  4541. {
  4542. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4543. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4544. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4545. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4546. {
  4547. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4548. result = FAIL;
  4549. goto end;
  4550. }
  4551. }//END FOR ELSE
  4552. }
  4553. }// END FOR CHAdeMO_QUANTITY
  4554. }
  4555. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4556. {
  4557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4558. {
  4559. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4560. }
  4561. else
  4562. {
  4563. tempIndex = connectorIdInt -1;
  4564. }
  4565. for (int index = 0; index < CCS_QUANTITY; index++)
  4566. {
  4567. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4568. {
  4569. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4570. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4571. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4572. {
  4573. //Reserved
  4574. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4575. }
  4576. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4577. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4578. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4579. {
  4580. //Reserved
  4581. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4582. result = FAIL;
  4583. goto end;
  4584. }
  4585. else
  4586. {
  4587. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4588. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4589. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4590. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4591. {
  4592. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4593. result = FAIL;
  4594. goto end;
  4595. }
  4596. }// END FOR ELSE
  4597. }
  4598. }// END FOR CCS_QUANTITY
  4599. }
  4600. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4601. {
  4602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4603. {
  4604. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4605. }
  4606. else
  4607. {
  4608. tempIndex = connectorIdInt -1;
  4609. }
  4610. for (int index = 0; index < GB_QUANTITY; index++)
  4611. {
  4612. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4613. {
  4614. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4615. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4616. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4617. {
  4618. //Reserved
  4619. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4620. }
  4621. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4622. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4623. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4624. {
  4625. //Reserved
  4626. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4627. result = FAIL;
  4628. goto end;
  4629. }
  4630. else
  4631. {
  4632. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4633. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4634. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4635. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4636. {
  4637. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4638. result = FAIL;
  4639. goto end;
  4640. }
  4641. }// END FOR ELSE
  4642. }
  4643. } // END FOR GB_QUANTITY
  4644. }
  4645. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4646. {
  4647. tempIndex = connectorIdInt -1;
  4648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4649. {
  4650. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4651. {
  4652. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4653. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4654. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4655. {
  4656. //Reserved
  4657. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4658. }
  4659. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4660. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4661. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4662. {
  4663. //Reserved
  4664. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4665. result = FAIL;
  4666. goto end;
  4667. }
  4668. else
  4669. {
  4670. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4671. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4672. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4673. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4674. {
  4675. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4676. result = FAIL;
  4677. goto end;
  4678. }
  4679. }// END FOR ELSE
  4680. }
  4681. } // END FOR GB_QUANTITY
  4682. }
  4683. else
  4684. {
  4685. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4686. {
  4687. tempIndex = 2;
  4688. }
  4689. else
  4690. {
  4691. tempIndex = connectorIdInt -1;
  4692. }
  4693. for (int index = 0; index < AC_QUANTITY; index++)
  4694. {
  4695. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4696. {
  4697. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4698. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4699. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4700. {
  4701. //Reserved
  4702. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4703. }
  4704. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4705. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4706. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4707. {
  4708. //Reserved
  4709. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4710. result = FAIL;
  4711. goto end;
  4712. }
  4713. else
  4714. {
  4715. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4716. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4717. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4718. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4719. {
  4720. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4721. result = FAIL;
  4722. goto end;
  4723. }
  4724. }//END FOR ELSE
  4725. }
  4726. }// END FOR AC_QUANTITY
  4727. }
  4728. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4729. {
  4730. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4731. {
  4732. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4733. {
  4734. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4735. system(cmdBuf);
  4736. }
  4737. }
  4738. else
  4739. {
  4740. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4741. result = FAIL;
  4742. }
  4743. }
  4744. end:
  4745. if(result == PASS)
  4746. {
  4747. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4748. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4749. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4750. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4751. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4752. }
  4753. }
  4754. int isConnector0Unavailable()
  4755. {
  4756. uint8_t result = YES;
  4757. uint8_t tempIndex;
  4758. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4759. {
  4760. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4761. {
  4762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4763. {
  4764. tempIndex = ((gun_index==2) ? 1: 0);
  4765. }
  4766. else
  4767. {
  4768. tempIndex = gun_index;
  4769. }
  4770. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4771. {
  4772. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4773. {
  4774. 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))
  4775. {
  4776. result = NO;
  4777. }
  4778. }
  4779. }
  4780. }
  4781. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4782. {
  4783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4784. {
  4785. tempIndex = ((gun_index==2) ? 1: 0);
  4786. }
  4787. else
  4788. {
  4789. tempIndex = gun_index;
  4790. }
  4791. for (int index = 0; index < CCS_QUANTITY; index++)
  4792. {
  4793. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4794. {
  4795. 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))
  4796. {
  4797. result = NO;
  4798. }
  4799. }
  4800. }
  4801. }
  4802. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4803. {
  4804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4805. {
  4806. tempIndex = ((gun_index==2) ? 1: 0);
  4807. }
  4808. else
  4809. {
  4810. tempIndex = gun_index;
  4811. }
  4812. for (int index = 0; index < GB_QUANTITY; index++)
  4813. {
  4814. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4815. {
  4816. 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))
  4817. {
  4818. result = NO;
  4819. }
  4820. }
  4821. }
  4822. }
  4823. else if(gunType[gun_index] == GUN_TYPE_DO)
  4824. {
  4825. tempIndex = gun_index;
  4826. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4827. {
  4828. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4829. {
  4830. 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))
  4831. {
  4832. result = NO;
  4833. }
  4834. }
  4835. }
  4836. }
  4837. else
  4838. {
  4839. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4840. {
  4841. tempIndex = 2;
  4842. }
  4843. else
  4844. {
  4845. tempIndex = gun_index;
  4846. }
  4847. for (int index = 0; index < AC_QUANTITY; index++)
  4848. {
  4849. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4850. {
  4851. 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))
  4852. {
  4853. result = NO;
  4854. }
  4855. }
  4856. }// END
  4857. }
  4858. }
  4859. return result;
  4860. }
  4861. void CheckSystemValue(void)
  4862. {
  4863. char filenmae[100]={0};
  4864. char str[100]={0};
  4865. int tempIndex = 0;
  4866. //===============================
  4867. // send Heartbeat
  4868. //===============================
  4869. if((server_sign == TRUE) && (HeartBeatWaitTime > 0) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4870. {
  4871. //parameter for test
  4872. if(HeartBeatWithNOResponse < 1)
  4873. sendHeartbeatRequest(0);
  4874. //===========================
  4875. // Reset Waiting Time
  4876. //===========================
  4877. HeartBeatWithNOResponse += 1;
  4878. }
  4879. //===============================
  4880. // Tcci credit deduct report
  4881. //===============================
  4882. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4883. {
  4884. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4885. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4886. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4887. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4888. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4889. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4890. }
  4891. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4892. {
  4893. OCPP_query_deduct_info();
  4894. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4895. }
  4896. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4897. {
  4898. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4899. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4900. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4901. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4902. }
  4903. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4904. {
  4905. OCPP_query_occupancyDeduct_info();
  4906. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4907. }
  4908. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4909. {
  4910. // ClockAlign MeterValue
  4911. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4912. {
  4913. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4914. {
  4915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4916. {
  4917. tempIndex = ((gun_index==2) ? 1: 0);
  4918. }
  4919. else
  4920. {
  4921. tempIndex = gun_index;
  4922. }
  4923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4924. {
  4925. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4926. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4927. {
  4928. reqClockAlignMeter[gun_index] = 1;
  4929. }
  4930. }// End for CHAdeMO
  4931. }
  4932. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4933. {
  4934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4935. {
  4936. tempIndex = ((gun_index==2) ? 1: 0);
  4937. }
  4938. else
  4939. {
  4940. tempIndex = gun_index;
  4941. }
  4942. for (int index = 0; index < CCS_QUANTITY; index++)
  4943. {
  4944. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4945. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4946. {
  4947. reqClockAlignMeter[gun_index] = 1;
  4948. }
  4949. } // End for CCS
  4950. }
  4951. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4952. {
  4953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4954. {
  4955. tempIndex = ((gun_index==2) ? 1: 0);
  4956. }
  4957. else
  4958. {
  4959. tempIndex = gun_index;
  4960. }
  4961. for (int index = 0; index < GB_QUANTITY; index++)
  4962. {
  4963. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4964. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4965. {
  4966. reqClockAlignMeter[gun_index] = 1;
  4967. }
  4968. }// End for GB
  4969. }
  4970. else if(gunType[gun_index] == GUN_TYPE_DO)
  4971. {
  4972. tempIndex = gun_index;
  4973. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4974. {
  4975. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4976. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4977. {
  4978. reqClockAlignMeter[gun_index] = 1;
  4979. }
  4980. }
  4981. }
  4982. else
  4983. {
  4984. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4985. {
  4986. tempIndex = 2;
  4987. }
  4988. else
  4989. {
  4990. tempIndex = gun_index;
  4991. }
  4992. for (int index = 0; index < AC_QUANTITY; index++)
  4993. {
  4994. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4995. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4996. {
  4997. reqClockAlignMeter[gun_index] = 1;
  4998. }
  4999. }//End for AC
  5000. }
  5001. }
  5002. }
  5003. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  5004. {
  5005. //==========================================
  5006. // Check remote start without connector id
  5007. //==========================================
  5008. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  5009. {
  5010. int connectorIdInt = -1;
  5011. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  5012. {
  5013. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  5014. {
  5015. connectorIdInt = (gun_index+1);
  5016. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  5017. checkRemoteStart(connectorIdInt);
  5018. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  5019. break;
  5020. }
  5021. }
  5022. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  5023. {
  5024. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5025. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  5026. }
  5027. }
  5028. //==========================================
  5029. // csu trigger DataTransferReq
  5030. //==========================================
  5031. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  5032. {
  5033. sendDataTransferRequest(gun_index);
  5034. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  5035. }
  5036. //==========================================
  5037. // CSU Trigger Authorize Request
  5038. //==========================================
  5039. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  5040. {
  5041. sendAuthorizeRequest(0);
  5042. authorizeRetryTimes = authorizeRetryTimes + 1;
  5043. if(authorizeRetryTimes < 3)
  5044. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5045. }
  5046. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  5047. {
  5048. authorizeRetryTimes = 0;
  5049. SetOcppConnStatus(FALSE);
  5050. server_sign = FALSE;
  5051. }
  5052. 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))
  5053. {
  5054. sendAuthorizeRequest(0);
  5055. }
  5056. //==========================================
  5057. // Charger start transaction
  5058. //==========================================
  5059. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  5060. {
  5061. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5062. meterValueBufferClear(gun_index);
  5063. sendStartTransactionRequest(gun_index);
  5064. refreshStartTimer(&clientTime.StartTransaction);
  5065. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5066. storeTempStopTransaction(gun_index);
  5067. }
  5068. //==========================================
  5069. // Charger stop transaction
  5070. //==========================================
  5071. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  5072. {
  5073. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5074. sendStopTransactionRequest(gun_index);
  5075. OCPP_updatePeriodEnergy(gun_index);
  5076. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  5077. refreshStartTimer(&clientTime.StopTransaction);
  5078. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  5079. }
  5080. //==========================================
  5081. // Charger OCMF message
  5082. //==========================================
  5083. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  5084. {
  5085. sendOcmfByDataTransferRequest(gun_index);
  5086. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  5087. }
  5088. //==========================================
  5089. // Charger status report
  5090. //==========================================
  5091. //--- Check Mode Change ---//
  5092. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5093. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5094. {
  5095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5096. {
  5097. tempIndex = ((gun_index==2) ? 1: 0);
  5098. }
  5099. else
  5100. {
  5101. tempIndex = gun_index;
  5102. }
  5103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5104. {
  5105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5106. {
  5107. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5108. {
  5109. // Sent unplug message for California pricing logic
  5110. 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])
  5111. {
  5112. uint8_t ts[36];
  5113. getNowDatetime(ts);
  5114. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5115. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5116. if(strcmp((char*)dmsVersion, "2.0")==0)
  5117. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5118. else
  5119. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5120. sendUnplugByDataTransferRequest(gun_index);
  5121. interLock.isSentUnplug[gun_index] = 1;
  5122. }
  5123. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5124. {
  5125. interLock.isSentUnplug[gun_index] = 0;
  5126. }
  5127. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5128. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5129. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5130. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5131. {
  5132. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5133. if((access(filenmae,F_OK))!=-1)
  5134. {
  5135. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5136. sprintf(str,"rm -f %s",filenmae);
  5137. system(str);
  5138. }
  5139. }
  5140. }
  5141. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5142. #if 1 // for TempStopTransaction
  5143. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5144. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5145. {
  5146. checkTempStopTransaction(gun_index);
  5147. }
  5148. #endif
  5149. }
  5150. }
  5151. }
  5152. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5153. {
  5154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5155. {
  5156. tempIndex = ((gun_index==2) ? 1: 0);
  5157. }
  5158. else
  5159. {
  5160. tempIndex = gun_index;
  5161. }
  5162. for (int index = 0; index < CCS_QUANTITY; index++)
  5163. {
  5164. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5165. {
  5166. 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]*/ )
  5167. {
  5168. // Sent unplug message for California pricing logic
  5169. 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])
  5170. {
  5171. uint8_t ts[36];
  5172. getNowDatetime(ts);
  5173. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5174. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5175. if(strcmp((char*)dmsVersion, "2.0")==0)
  5176. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5177. else
  5178. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5179. sendUnplugByDataTransferRequest(gun_index);
  5180. interLock.isSentUnplug[gun_index] = 1;
  5181. }
  5182. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5183. {
  5184. interLock.isSentUnplug[gun_index] = 0;
  5185. }
  5186. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5187. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5188. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5189. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5190. {
  5191. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5192. if((access(filenmae,F_OK))!=-1)
  5193. {
  5194. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5195. sprintf(str,"rm -f %s",filenmae);
  5196. system(str);
  5197. }
  5198. }
  5199. }
  5200. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5201. #if 1 // for TempStopTransaction
  5202. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5203. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5204. {
  5205. checkTempStopTransaction(gun_index);
  5206. }
  5207. #endif
  5208. }
  5209. }
  5210. }
  5211. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5212. {
  5213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5214. {
  5215. tempIndex = ((gun_index==2) ? 1: 0);
  5216. }
  5217. else
  5218. {
  5219. tempIndex = gun_index;
  5220. }
  5221. for (int index = 0; index < GB_QUANTITY; index++)
  5222. {
  5223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5224. {
  5225. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5226. {
  5227. // Sent unplug message for California pricing logic
  5228. 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])
  5229. {
  5230. uint8_t ts[36];
  5231. getNowDatetime(ts);
  5232. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5233. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5234. if(strcmp((char*)dmsVersion, "2.0")==0)
  5235. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5236. else
  5237. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5238. sendUnplugByDataTransferRequest(gun_index);
  5239. interLock.isSentUnplug[gun_index] = 1;
  5240. }
  5241. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5242. {
  5243. interLock.isSentUnplug[gun_index] = 0;
  5244. }
  5245. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5246. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5247. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5248. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5249. {
  5250. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5251. if((access(filenmae,F_OK))!=-1)
  5252. {
  5253. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5254. sprintf(str,"rm -f %s",filenmae);
  5255. system(str);
  5256. }
  5257. }
  5258. }
  5259. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5260. #if 1 // for TempStopTransaction
  5261. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5262. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5263. {
  5264. checkTempStopTransaction(gun_index);
  5265. }
  5266. #endif
  5267. }
  5268. }
  5269. }
  5270. else if(gunType[gun_index] == GUN_TYPE_DO)
  5271. {
  5272. tempIndex = gun_index;
  5273. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5274. {
  5275. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5276. {
  5277. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5278. {
  5279. // Sent unplug message for California pricing logic
  5280. 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])
  5281. {
  5282. uint8_t ts[36];
  5283. getNowDatetime(ts);
  5284. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5285. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5286. if(strcmp((char*)dmsVersion, "2.0")==0)
  5287. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5288. else
  5289. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5290. sendUnplugByDataTransferRequest(gun_index);
  5291. interLock.isSentUnplug[gun_index] = 1;
  5292. }
  5293. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5294. {
  5295. interLock.isSentUnplug[gun_index] = 0;
  5296. }
  5297. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5298. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5299. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5300. 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
  5301. {
  5302. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5303. if((access(filenmae,F_OK))!=-1)
  5304. {
  5305. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5306. sprintf(str,"rm -f %s",filenmae);
  5307. system(str);
  5308. }
  5309. }
  5310. }
  5311. 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);
  5312. #if 1 // for TempStopTransaction
  5313. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5314. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5315. {
  5316. checkTempStopTransaction(gun_index);
  5317. }
  5318. #endif
  5319. }
  5320. }
  5321. }
  5322. else
  5323. {
  5324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5325. {
  5326. tempIndex = 2;
  5327. }
  5328. else
  5329. {
  5330. tempIndex = gun_index;
  5331. }
  5332. for (int index = 0; index < AC_QUANTITY; index++)
  5333. {
  5334. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5335. {
  5336. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5337. {
  5338. // Sent unplug message for California pricing logic
  5339. 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])
  5340. {
  5341. uint8_t ts[36];
  5342. getNowDatetime(ts);
  5343. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5344. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5345. if(strcmp((char*)dmsVersion, "2.0")==0)
  5346. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5347. else
  5348. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5349. sendUnplugByDataTransferRequest(gun_index);
  5350. interLock.isSentUnplug[gun_index] = 1;
  5351. }
  5352. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5353. {
  5354. interLock.isSentUnplug[gun_index] = 0;
  5355. }
  5356. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5357. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5358. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5359. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5360. {
  5361. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5362. if((access(filenmae,F_OK))!=-1)
  5363. {
  5364. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5365. sprintf(str,"rm -f %s",filenmae);
  5366. system(str);
  5367. }
  5368. }
  5369. }
  5370. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5371. #if 1 // for TempStopTransaction
  5372. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5373. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5374. {
  5375. checkTempStopTransaction(gun_index);
  5376. }
  5377. #endif
  5378. }
  5379. }// END
  5380. }
  5381. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5382. {
  5383. sendConnector0StatusNotificationRequest();
  5384. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5385. }
  5386. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5387. (
  5388. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5389. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5390. )
  5391. )
  5392. {
  5393. sendStatusNotificationRequest(gun_index);
  5394. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5395. }
  5396. //==============================================
  5397. // TCCI related DataTransfer messages
  5398. //==============================================
  5399. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5400. {
  5401. reportReaderStatus(gun_index);
  5402. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5403. }
  5404. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq == 1))
  5405. {
  5406. occupancyFeeAct(gun_index);
  5407. }
  5408. //==============================================
  5409. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5410. //==============================================
  5411. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5412. ((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))))
  5413. {
  5414. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5415. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5416. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5417. }
  5418. //==============================================
  5419. // Meter report
  5420. //==============================================
  5421. // Trigger MeterValue
  5422. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5423. {
  5424. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5425. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5426. }
  5427. // Clock-aligned Meter value
  5428. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5429. {
  5430. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5431. reqClockAlignMeter[gun_index] = 0;
  5432. }
  5433. // Sample period MeterValue
  5434. 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))))
  5435. {
  5436. //check Transaction active
  5437. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5438. {
  5439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5440. {
  5441. tempIndex = ((gun_index==2) ? 1: 0);
  5442. }
  5443. else
  5444. {
  5445. tempIndex = gun_index;
  5446. }
  5447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5448. {
  5449. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5450. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5451. {
  5452. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5453. {
  5454. reqSampleMeter[gun_index] = 1;
  5455. }
  5456. }
  5457. }// End for CHAdeMO
  5458. }
  5459. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5460. {
  5461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5462. {
  5463. tempIndex = ((gun_index==2) ? 1: 0);
  5464. }
  5465. else
  5466. {
  5467. tempIndex = gun_index;
  5468. }
  5469. for (int index = 0; index < CCS_QUANTITY; index++)
  5470. {
  5471. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5472. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5473. {
  5474. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5475. {
  5476. reqSampleMeter[gun_index] = 1;
  5477. }
  5478. }
  5479. } // End for CCS
  5480. }
  5481. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5482. {
  5483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5484. {
  5485. tempIndex = ((gun_index==2) ? 1: 0);
  5486. }
  5487. else
  5488. {
  5489. tempIndex = gun_index;
  5490. }
  5491. for (int index = 0; index < GB_QUANTITY; index++)
  5492. {
  5493. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5494. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5495. {
  5496. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5497. {
  5498. reqSampleMeter[gun_index] = 1;
  5499. }
  5500. }
  5501. }// End for GB
  5502. }
  5503. else if(gunType[gun_index] == GUN_TYPE_DO)
  5504. {
  5505. tempIndex = gun_index;
  5506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5507. {
  5508. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5509. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5510. {
  5511. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5512. {
  5513. reqSampleMeter[gun_index] = 1;
  5514. }
  5515. }
  5516. }
  5517. }
  5518. else
  5519. {
  5520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5521. {
  5522. tempIndex = 2;
  5523. }
  5524. else
  5525. {
  5526. tempIndex = gun_index;
  5527. }
  5528. for (int index = 0; index < AC_QUANTITY; index++)
  5529. {
  5530. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5531. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5532. {
  5533. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5534. {
  5535. reqSampleMeter[gun_index] = 1;
  5536. }
  5537. }
  5538. }//End for AC
  5539. }
  5540. if(reqSampleMeter[gun_index] == 1)
  5541. {
  5542. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5543. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5544. storeTempStopTransaction(gun_index);
  5545. reqSampleMeter[gun_index] = 0;
  5546. }
  5547. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5548. }
  5549. //==============================================
  5550. // Check Connector reserved
  5551. //==============================================
  5552. //===============================
  5553. // Check if Reserve is expired
  5554. //===============================
  5555. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5556. {
  5557. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5558. {
  5559. DEBUG_INFO("reserve expired.\n");
  5560. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5561. }
  5562. }//END OF Check if Reserve is expired
  5563. //==========================================
  5564. // csu trigger FirmwareStatusNotificationReq
  5565. //==========================================
  5566. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5567. {
  5568. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5569. }
  5570. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5571. {
  5572. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5573. }
  5574. //==========================================
  5575. // csu trigger DiagnosticsStatusNotificationReq
  5576. //==========================================
  5577. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5578. {
  5579. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5580. }
  5581. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5582. {
  5583. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5584. }
  5585. //==========================================
  5586. // csu trigger CancelReservationConf
  5587. //==========================================
  5588. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5589. {
  5590. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5591. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5592. }
  5593. //==========================================
  5594. // csu trigger ChangeAvailabilityConf
  5595. //==========================================
  5596. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5597. {
  5598. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5599. }
  5600. //==========================================
  5601. // csu trigger UnlockConnectorConf
  5602. //==========================================
  5603. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5604. {
  5605. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5606. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5607. }
  5608. //==========================================
  5609. // csu trigger ReserveNowConf
  5610. //==========================================
  5611. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5612. {
  5613. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5614. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5615. }
  5616. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5617. {
  5618. sendSignCertificateRequest();
  5619. }
  5620. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5621. {
  5622. sendSecurityEventNotificationRequest();
  5623. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5624. }
  5625. // Support 15118
  5626. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5627. {
  5628. json_object *data = json_object_new_object();
  5629. // Read csr file content
  5630. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5631. FILE *fp=fopen(CSR_V2G,"r");
  5632. char *line = NULL;
  5633. size_t len = 0;
  5634. while(getline(&line, &len, fp) != -1)
  5635. {
  5636. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5637. {
  5638. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5639. }
  5640. }
  5641. fclose(fp);
  5642. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5643. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5644. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5645. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5646. json_object_put(data);
  5647. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5648. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5649. }
  5650. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5651. {
  5652. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5653. int parseCertResult = FAIL;
  5654. json_object *data = json_object_new_object();
  5655. json_object *idToken = json_object_new_object();
  5656. json_object *iso15118CertificateHashData = json_object_new_array();
  5657. // Read CERTIFICATE_PnCAuth file content
  5658. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5659. {
  5660. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5661. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5662. char *line = NULL;
  5663. size_t len = 0;
  5664. while(getline(&line, &len, fp) != -1)
  5665. {
  5666. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5667. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5668. }
  5669. fclose(fp);
  5670. }
  5671. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5672. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5673. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5674. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5675. json_object_object_add(data, "idToken", idToken);
  5676. char parseData[512] = {0};
  5677. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5678. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5679. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5680. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5681. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5682. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5683. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5684. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5685. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5686. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5687. for(int idx=0; idx < 4; idx++)
  5688. {
  5689. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5690. {
  5691. json_object *OCSPRequestDataType = json_object_new_object();
  5692. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5693. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5694. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5695. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5696. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5697. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5698. parseCertResult = PASS;
  5699. }
  5700. }
  5701. if(parseCertResult == PASS)
  5702. {
  5703. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5704. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5705. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5706. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5707. json_object_put(data);
  5708. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5709. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5710. }
  5711. else
  5712. {
  5713. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5714. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5715. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5716. }
  5717. }
  5718. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5719. {
  5720. json_object *data = json_object_new_object();
  5721. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5722. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5723. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5724. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5725. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5726. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5727. json_object_put(data);
  5728. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5729. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5730. }
  5731. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5732. {
  5733. json_object *data = json_object_new_object();
  5734. json_object *OCSPRequestDataType = json_object_new_object();
  5735. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5736. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5737. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5738. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5739. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5740. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5741. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5742. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5743. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5744. json_object_put(data);
  5745. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5746. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5747. }
  5748. }
  5749. }
  5750. //==========================================
  5751. // send request routine
  5752. //==========================================
  5753. int sendAuthorizeRequest(int gun_index)
  5754. {
  5755. mtrace();
  5756. int result = FAIL;
  5757. char message[100]={0};
  5758. char guid[37];
  5759. char tempdata[65]={0};
  5760. DEBUG_INFO("sendAuthorizeRequest...\n");
  5761. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5762. //Local Authorize
  5763. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5764. {
  5765. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5767. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5768. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5769. result = PASS;
  5770. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5771. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5772. authorizeRetryTimes = 0;
  5773. return result;
  5774. }
  5775. 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))||
  5776. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5777. {
  5778. // Query from cache
  5779. DEBUG_INFO("Authorize from cache.\n");
  5780. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5781. // Query from list
  5782. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5783. {
  5784. DEBUG_INFO("Authorize from list.\n");
  5785. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5786. }
  5787. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5788. {
  5789. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5790. {
  5791. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5792. }
  5793. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5794. {
  5795. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5796. }
  5797. if(!GetOcppConnStatus())
  5798. {
  5799. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5800. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5801. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5802. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5803. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5804. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5805. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5806. authorizeRetryTimes = 0;
  5807. return result;
  5808. }
  5809. }
  5810. else
  5811. {
  5812. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5813. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5814. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5815. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5816. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5817. else
  5818. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5819. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5820. result = PASS;
  5821. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5822. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5823. authorizeRetryTimes = 0;
  5824. return result;
  5825. }
  5826. }
  5827. //initialize struct Authorize
  5828. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5829. //get data from shared memory
  5830. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5831. random_uuid(guid);
  5832. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5833. LWS_Send(message);
  5834. sprintf(tempdata, "Authorize,%d", gun_index);
  5835. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5836. {
  5837. result = PASS;
  5838. DEBUG_INFO("Authorize mapItem pass\n");
  5839. }
  5840. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5841. return result;
  5842. }
  5843. int sendBootNotificationRequest(void)
  5844. {
  5845. mtrace();
  5846. int result = FAIL;
  5847. char message[500]={0}, payload[700]={0};
  5848. char guid[37]={0};
  5849. char tempdata[65]={0};
  5850. // Fill BootNotification fields
  5851. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5852. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5853. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5854. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5855. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5856. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5857. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5858. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5859. ShmOCPP16Data->ChargeBoxId
  5860. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5861. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5862. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5863. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5864. ,ShmOCPP16Data->BootNotification.CpIccid
  5865. ,ShmOCPP16Data->BootNotification.CpImsi);
  5866. random_uuid(guid);
  5867. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5868. LWS_Send(message);
  5869. sprintf(tempdata, "BootNotification,0");
  5870. 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*/)
  5871. {
  5872. result = PASS;
  5873. }
  5874. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5875. strcpy(queuedata,message);
  5876. return result;
  5877. }
  5878. int sendDataTransferRequest(int gun_index)
  5879. {
  5880. mtrace();
  5881. char message[10240]={0};
  5882. char guid[37]={0};
  5883. char tempdata[65]={0};
  5884. int result = FAIL;
  5885. json_object *DataTransfer = json_object_new_object();
  5886. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5887. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5888. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5889. random_uuid(guid);
  5890. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5891. guid,
  5892. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5893. json_object_put(DataTransfer);
  5894. LWS_Send(message);
  5895. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5896. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5897. {
  5898. result = PASS;
  5899. DEBUG_INFO("DataTransfer mapItem pass\n");
  5900. }
  5901. return result;
  5902. }
  5903. int sendUnplugByDataTransferRequest(int gun_index)
  5904. {
  5905. mtrace();
  5906. char message[10752]={0};
  5907. char guid[37]={0};
  5908. char tempdata[65]={0};
  5909. int result = FAIL;
  5910. random_uuid(guid);
  5911. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5912. (gun_index+1),
  5913. MESSAGE_TYPE_CALL,
  5914. guid,
  5915. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5916. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5917. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5918. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5919. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5920. {
  5921. result = PASS;
  5922. DEBUG_INFO("DataTransfer mapItem pass\n");
  5923. }
  5924. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5925. return result;
  5926. }
  5927. int sendOcmfByDataTransferRequest(int gun_index)
  5928. {
  5929. mtrace();
  5930. json_object *DataTransfer = json_object_new_object();
  5931. json_object *data = json_object_new_object();
  5932. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5933. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5934. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5935. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5936. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5937. json_object_object_add(DataTransfer, "data", data);
  5938. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5939. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5940. char message[3000]={0};
  5941. char guid[37]={0};
  5942. char tempdata[65]={0};
  5943. int result = FAIL;
  5944. random_uuid(guid);
  5945. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5946. (gun_index+1),
  5947. MESSAGE_TYPE_CALL,
  5948. guid,
  5949. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5950. json_object_put(DataTransfer);
  5951. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5952. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5953. {
  5954. result = PASS;
  5955. DEBUG_INFO("DataTransfer mapItem pass\n");
  5956. }
  5957. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5958. return result;
  5959. }
  5960. int sendDiagnosticsStatusNotificationRequest(char *status)
  5961. {
  5962. mtrace();
  5963. int result = FAIL;
  5964. char message[110]={0};
  5965. char guid[37]={0};
  5966. char tempdata[65]={0};
  5967. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5968. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5969. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5970. random_uuid(guid);
  5971. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5972. LWS_SendNow(message);
  5973. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5974. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5975. {
  5976. result = PASS;
  5977. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5978. }
  5979. //#ifdef SystemLogMessage
  5980. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5981. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5982. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5983. //#endif
  5984. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5985. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5986. //record status
  5987. if(strcmp(status,"Idle")==0)
  5988. {
  5989. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5990. }
  5991. else if(strcmp(status,"Uploaded")==0)
  5992. {
  5993. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5994. }
  5995. else if(strcmp(status,"UploadFailed")==0)
  5996. {
  5997. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5998. }
  5999. else if(strcmp(status,"Uploading")==0)
  6000. {
  6001. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  6002. }
  6003. return result;
  6004. }
  6005. int sendFirmwareStatusNotificationRequest(char *status)
  6006. {
  6007. mtrace();
  6008. int result = FAIL;
  6009. char message[110]={0};
  6010. char guid[37]={0};
  6011. char tempdata[65]={0};
  6012. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  6013. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  6014. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  6015. random_uuid(guid);
  6016. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  6017. LWS_SendNow(message);
  6018. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6019. 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*/)
  6020. {
  6021. result = PASS;
  6022. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  6023. }
  6024. //#ifdef SystemLogMessage
  6025. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  6026. //DEBUG_INFO("Message: %s\n", SendBuffer);
  6027. //#endif
  6028. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  6029. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  6030. //record status
  6031. if(strcmp(status,"Downloaded")==0)
  6032. {
  6033. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  6034. }
  6035. else if(strcmp(status,"DownloadFailed")==0)
  6036. {
  6037. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  6038. }
  6039. else if(strcmp(status,"Downloading")==0)
  6040. {
  6041. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  6042. }
  6043. else if(strcmp(status,"Idle")==0)
  6044. {
  6045. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  6046. }
  6047. else if(strcmp(status,"InstallationFailed")==0)
  6048. {
  6049. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  6050. }
  6051. else if(strcmp(status,"Installing")==0)
  6052. {
  6053. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  6054. }
  6055. else if(strcmp(status,"Installed")==0)
  6056. {
  6057. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  6058. }
  6059. return result;
  6060. }
  6061. int sendHeartbeatRequest(int gun_index)
  6062. {
  6063. mtrace();
  6064. int result = FAIL;
  6065. char message[80]={0};
  6066. char guid[37]={0};
  6067. char tempdata[65]={0};
  6068. random_uuid(guid);
  6069. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6070. , MESSAGE_TYPE_CALL
  6071. , guid );
  6072. LWS_Send(message);
  6073. sprintf(tempdata, "Heartbeat,%d", 0);
  6074. 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*/)
  6075. {
  6076. result = PASS;
  6077. }
  6078. return result;
  6079. }
  6080. int sendStartTransactionRequest(int gun_index)
  6081. {
  6082. mtrace();
  6083. int result = FAIL;
  6084. char message[250]={0};
  6085. char guid[37]={0};
  6086. struct timeval tmnow;
  6087. struct tm *tm;
  6088. char buf[28];//, usec_buf[6];
  6089. char tempdata[65]={0};
  6090. int tempIndex = 0;
  6091. DEBUG_INFO("sendStartTransactionRequest...\n");
  6092. gettimeofday(&tmnow, NULL);
  6093. time_t t;
  6094. t = time(NULL);
  6095. /*UTC time and date*/
  6096. tm = gmtime(&t);
  6097. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6098. #if 0 // remove temporally
  6099. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6100. strcat(buf,".");
  6101. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6102. strcat(buf,usec_buf);
  6103. #endif
  6104. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  6105. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  6106. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6107. // clear StartTransaction Response
  6108. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  6109. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  6110. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  6111. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  6112. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6113. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6114. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6115. {
  6116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6117. {
  6118. tempIndex = ((gun_index==2) ? 1: 0);
  6119. }
  6120. else
  6121. {
  6122. tempIndex = gun_index;
  6123. }
  6124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6125. {
  6126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6127. {
  6128. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6129. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  6130. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6131. }
  6132. }
  6133. }
  6134. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6135. {
  6136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6137. {
  6138. tempIndex = ((gun_index==2) ? 1: 0);
  6139. }
  6140. else
  6141. {
  6142. tempIndex = gun_index;
  6143. }
  6144. for (int index = 0; index < CCS_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6147. {
  6148. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6149. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  6150. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6151. }
  6152. }
  6153. }
  6154. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6155. {
  6156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6157. {
  6158. tempIndex = ((gun_index==2) ? 1: 0);
  6159. }
  6160. else
  6161. {
  6162. tempIndex = gun_index;
  6163. }
  6164. for (int index = 0; index < GB_QUANTITY; index++)
  6165. {
  6166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6167. {
  6168. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6169. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  6170. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6171. }
  6172. }
  6173. }
  6174. else if(gunType[gun_index] == GUN_TYPE_DO)
  6175. {
  6176. tempIndex = gun_index;
  6177. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6178. {
  6179. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6180. {
  6181. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6182. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  6183. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6184. }
  6185. }
  6186. }
  6187. else
  6188. {
  6189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6190. {
  6191. tempIndex = 2;
  6192. }
  6193. else
  6194. {
  6195. tempIndex = gun_index;
  6196. }
  6197. for (int index = 0; index < AC_QUANTITY; index++)
  6198. {
  6199. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6200. {
  6201. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6202. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6203. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6204. }
  6205. }
  6206. }
  6207. random_uuid(guid);
  6208. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6209. {
  6210. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6211. , gun_index +1
  6212. , MESSAGE_TYPE_CALL
  6213. , guid
  6214. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6215. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6216. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6217. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6218. }
  6219. else
  6220. {
  6221. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6222. , gun_index +1
  6223. , MESSAGE_TYPE_CALL
  6224. , guid
  6225. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6226. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6227. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6228. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6229. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6230. }
  6231. #if 1
  6232. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6233. 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*/)
  6234. {
  6235. result = PASS;
  6236. }
  6237. #endif
  6238. strcpy(queuedata, message);
  6239. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6240. OCPP_insert_transaction_msg(YES, queuedata);
  6241. return result;
  6242. }
  6243. int sendConnector0StatusNotificationRequest()
  6244. {
  6245. mtrace();
  6246. int result = FAIL;
  6247. char message[600]={0};
  6248. char guid[37];
  6249. struct timeval tmnow;
  6250. struct tm *tm;
  6251. char buf[28];//, usec_buf[6];
  6252. char tempdata[65]={0};
  6253. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6254. gettimeofday(&tmnow, NULL);
  6255. time_t t;
  6256. t = time(NULL);
  6257. /*UTC time and date*/
  6258. tm = gmtime(&t);
  6259. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6260. random_uuid(guid);
  6261. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6262. , MESSAGE_TYPE_CALL
  6263. , guid
  6264. , "NoError"
  6265. , ""
  6266. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6267. , buf
  6268. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6269. , "");
  6270. LWS_Send(message);
  6271. sprintf(tempdata, "StatusNotification,%d", 99);
  6272. 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*/)
  6273. {
  6274. //DEBUG_ERROR("statusNotification mapitem pass");
  6275. result = PASS;
  6276. }
  6277. return result;
  6278. }
  6279. int sendStatusNotificationRequest(int gun_index)
  6280. {
  6281. mtrace();
  6282. int result = FAIL;
  6283. char message[600]={0};
  6284. char guid[37];
  6285. int currentStatus = 0;
  6286. struct timeval tmnow;
  6287. struct tm *tm;
  6288. char buf[28];//, usec_buf[6];
  6289. char tempdata[65]={0};
  6290. int tempIndex = 0;
  6291. uint8_t isStateChanged = TRUE;
  6292. uint8_t isContentIllegal = TRUE;
  6293. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6294. gettimeofday(&tmnow, NULL);
  6295. time_t t;
  6296. t = time(NULL);
  6297. /*UTC time and date*/
  6298. tm = gmtime(&t);
  6299. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6300. #if 0 // remove temporally
  6301. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6302. strcat(buf,".");
  6303. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6304. strcat(buf,usec_buf);
  6305. #endif
  6306. //printf("%s",buf);
  6307. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6308. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6309. // it's option
  6310. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6311. /*
  6312. enum _SYSTEM_STATUS
  6313. {
  6314. S_BOOTING = 0,
  6315. S_IDLE, = 1
  6316. S_AUTHORIZING, =2
  6317. S_REASSIGN_CHECK, =3
  6318. S_REASSIGN, =4
  6319. S_PRECHARGE, =5
  6320. S_PREPARING_FOR_EV, =6
  6321. S_PREPARING_FOR_EVSE, =7
  6322. S_CHARGING, =8
  6323. S_TERMINATING, =9
  6324. S_COMPLETE, =10
  6325. S_ALARM, =11
  6326. S_FAULT =12
  6327. }
  6328. */
  6329. //check Transaction active
  6330. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6331. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6332. {
  6333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6334. {
  6335. tempIndex = ((gun_index==2) ? 1: 0);
  6336. }
  6337. else
  6338. {
  6339. tempIndex = gun_index;
  6340. }
  6341. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6342. {
  6343. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6344. {
  6345. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6346. {
  6347. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6348. {
  6349. currentStatus = Preparing; //OCPP Status: Preparing
  6350. }
  6351. else
  6352. {
  6353. currentStatus = Available; //OCPP Status: Available
  6354. }
  6355. }
  6356. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6357. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6358. ) //S_PRECHARGE
  6359. {
  6360. currentStatus = Preparing; //OCPP Status: Preparing
  6361. }
  6362. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6363. {
  6364. currentStatus = Charging; //OCPP Status: Charging
  6365. }
  6366. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6367. {
  6368. currentStatus = Finishing; //OCPP Status: Finishing
  6369. }
  6370. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6371. {
  6372. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6373. }
  6374. 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
  6375. {
  6376. currentStatus = Unavailable; //OCPP Status: Unavailable
  6377. }
  6378. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6379. {
  6380. currentStatus = Faulted; //OCPP Status: Faulted
  6381. }
  6382. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6383. {
  6384. currentStatus = Reserved; //OCPP Status: Reserved
  6385. }
  6386. } //end of the same index
  6387. }//end of for CHAdeMO_QUANTITY
  6388. }
  6389. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6390. {
  6391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6392. {
  6393. tempIndex = ((gun_index==2) ? 1: 0);
  6394. }
  6395. else
  6396. {
  6397. tempIndex = gun_index;
  6398. }
  6399. for (int index = 0; index < CCS_QUANTITY; index++)
  6400. {
  6401. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6402. {
  6403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6404. {
  6405. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6406. {
  6407. currentStatus = Preparing; //OCPP Status: Preparing
  6408. }
  6409. else
  6410. {
  6411. currentStatus = Available; //OCPP Status: Available
  6412. }
  6413. }
  6414. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6415. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6416. ) //S_PRECHARGE
  6417. {
  6418. currentStatus = Preparing; //OCPP Status: Preparing
  6419. }
  6420. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6421. {
  6422. currentStatus = Charging; //OCPP Status: Charging
  6423. }
  6424. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6425. {
  6426. currentStatus = Finishing; //OCPP Status: Finishing
  6427. }
  6428. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6429. {
  6430. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6431. }
  6432. 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
  6433. {
  6434. currentStatus = Unavailable; //OCPP Status : Unavailable
  6435. }
  6436. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6437. {
  6438. currentStatus = Faulted; //OCPP Status: Faulted
  6439. }
  6440. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6441. {
  6442. currentStatus = Reserved; //OCPP Status: Reserved
  6443. }
  6444. } //end of the same index
  6445. } // end of for CCS_QUANTITY
  6446. }
  6447. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6448. {
  6449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6450. {
  6451. tempIndex = ((gun_index==2) ? 1: 0);
  6452. }
  6453. else
  6454. {
  6455. tempIndex = gun_index;
  6456. }
  6457. for (int index = 0; index < GB_QUANTITY; index++)
  6458. {
  6459. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6460. {
  6461. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6462. {
  6463. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6464. {
  6465. currentStatus = Preparing; //OCPP Status: Preparing
  6466. }
  6467. else
  6468. {
  6469. currentStatus = Available; //OCPP Status: Available
  6470. }
  6471. }
  6472. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6473. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6474. ) //S_PRECHARGE
  6475. {
  6476. currentStatus = Preparing; //OCPP Status: Preparing
  6477. }
  6478. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6479. {
  6480. currentStatus = Charging; //OCPP Status: Charging
  6481. }
  6482. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6483. {
  6484. currentStatus = Finishing; //OCPP Status: Finishing
  6485. }
  6486. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6487. {
  6488. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6489. }
  6490. 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
  6491. {
  6492. currentStatus = Unavailable; //OCPP Status: Unavailable
  6493. }
  6494. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6495. {
  6496. currentStatus = Faulted; //OCPP Status: Faulted
  6497. }
  6498. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6499. {
  6500. currentStatus = Reserved; //OCPP Status: Reserved
  6501. }
  6502. } //end of the same index
  6503. } // end of for GB_QUANTITY
  6504. }
  6505. else if(gunType[gun_index] == GUN_TYPE_DO)
  6506. {
  6507. tempIndex = gun_index;
  6508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6509. {
  6510. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6511. {
  6512. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6513. {
  6514. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6515. {
  6516. currentStatus = Preparing; //OCPP Status: Preparing
  6517. }
  6518. else
  6519. {
  6520. currentStatus = Available; //OCPP Status: Available
  6521. }
  6522. }
  6523. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6524. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6525. ) //S_PRECHARGE
  6526. {
  6527. currentStatus = Preparing; //OCPP Status: Preparing
  6528. }
  6529. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6530. {
  6531. currentStatus = Charging; //OCPP Status: Charging
  6532. }
  6533. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6534. {
  6535. currentStatus = Finishing; //OCPP Status: Finishing
  6536. }
  6537. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6538. {
  6539. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6540. }
  6541. 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
  6542. {
  6543. currentStatus = Unavailable; //OCPP Status: Unavailable
  6544. }
  6545. 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
  6546. {
  6547. currentStatus = Faulted; //OCPP Status: Faulted
  6548. }
  6549. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6550. {
  6551. currentStatus = Reserved; //OCPP Status: Reserved
  6552. }
  6553. } //end of the same index
  6554. }
  6555. }
  6556. else
  6557. {
  6558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6559. {
  6560. tempIndex = 2;
  6561. }
  6562. else
  6563. {
  6564. tempIndex = gun_index;
  6565. }
  6566. for (int index = 0; index < AC_QUANTITY; index++)
  6567. {
  6568. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6569. {
  6570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6571. {
  6572. 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))
  6573. {
  6574. currentStatus = Preparing; //OCPP Status: Preparing
  6575. }
  6576. else
  6577. {
  6578. currentStatus = Available; //OCPP Status: Available
  6579. }
  6580. }
  6581. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6582. {
  6583. currentStatus = Preparing; //OCPP Status: Preparing
  6584. }
  6585. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6586. {
  6587. currentStatus = Charging; //OCPP Status: Charging
  6588. }
  6589. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6590. {
  6591. currentStatus = Finishing; //OCPP Status: Finishing
  6592. }
  6593. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6594. {
  6595. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6596. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6597. else
  6598. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6599. }
  6600. 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
  6601. {
  6602. currentStatus = Unavailable; //OCPP Status: Unavailable
  6603. }
  6604. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6605. {
  6606. currentStatus = Faulted; //OCPP Status: Faulted
  6607. }
  6608. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6609. {
  6610. currentStatus = Reserved; //OCPP Status: Reserved
  6611. }
  6612. }//end of the same index
  6613. }//end of for AC_QUANTITY
  6614. }
  6615. //it's option
  6616. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6617. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6618. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6619. {
  6620. isStateChanged = FALSE;
  6621. }
  6622. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6623. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6624. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6625. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6626. isContentIllegal = TRUE;
  6627. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6628. {
  6629. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6630. {
  6631. isContentIllegal = FALSE;
  6632. break;
  6633. }
  6634. }
  6635. if(isContentIllegal)
  6636. {
  6637. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6638. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6639. }
  6640. random_uuid(guid);
  6641. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6642. , MESSAGE_TYPE_CALL
  6643. , guid
  6644. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6645. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6646. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6647. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6648. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6649. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6650. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6651. if((server_sign == TRUE) && isStateChanged)
  6652. {
  6653. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6654. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6655. LWS_Send(message);
  6656. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6657. 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*/)
  6658. {
  6659. //DEBUG_ERROR("statusNotification mapitem pass");
  6660. result = PASS;
  6661. }
  6662. }
  6663. else
  6664. {
  6665. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6666. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6667. result = PASS;
  6668. }
  6669. return result;
  6670. }
  6671. int sendStopTransactionRequest(int gun_index)
  6672. {
  6673. mtrace();
  6674. int result = FAIL;
  6675. //char message[1500]={0};
  6676. char guid[37]={0};
  6677. char tempdata[65]={0};
  6678. int tempIndex = 0;
  6679. char TempStopTransaction[256];
  6680. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6681. DEBUG_INFO("sendStopTransactionRequest \n");
  6682. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6683. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6684. //=========================== Stop Transaction Time ===============================================
  6685. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  6686. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6687. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6688. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6689. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6690. {
  6691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6692. {
  6693. tempIndex = ((gun_index==2) ? 1: 0);
  6694. }
  6695. else
  6696. {
  6697. tempIndex = gun_index;
  6698. }
  6699. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6700. {
  6701. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6702. {
  6703. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6704. }
  6705. }// END OF CHAdeMO_QUANTITY
  6706. }
  6707. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6708. {
  6709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6710. {
  6711. tempIndex = ((gun_index==2) ? 1: 0);
  6712. }
  6713. else
  6714. {
  6715. tempIndex = gun_index;
  6716. }
  6717. for (int index = 0; index < CCS_QUANTITY; index++)
  6718. {
  6719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6720. {
  6721. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6722. }
  6723. }// END OF CCS_QUANTITY
  6724. }
  6725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6726. {
  6727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6728. {
  6729. tempIndex = ((gun_index==2) ? 1: 0);
  6730. }
  6731. else
  6732. {
  6733. tempIndex = gun_index;
  6734. }
  6735. for (int index = 0; index < GB_QUANTITY; index++)
  6736. {
  6737. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6738. {
  6739. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6740. }
  6741. }// END OF GB_QUANTITY
  6742. }
  6743. else if(gunType[gun_index] == GUN_TYPE_DO)
  6744. {
  6745. tempIndex = gun_index;
  6746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6747. {
  6748. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6749. {
  6750. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6751. }
  6752. }// END OF GB_QUANTITY
  6753. }
  6754. else
  6755. {
  6756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6757. {
  6758. tempIndex = 2;
  6759. }
  6760. else
  6761. {
  6762. tempIndex = gun_index;
  6763. }
  6764. for (int index = 0; index < AC_QUANTITY; index++)
  6765. {
  6766. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6767. {
  6768. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6769. }
  6770. }// END OF AC_QUANTITY
  6771. }
  6772. //================================================ Message create ====================================================
  6773. json_object *StopTransaction = json_object_new_object();
  6774. json_object *transactionDatas = json_object_new_array();
  6775. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6776. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6777. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6778. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6779. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6780. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6781. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6782. meterValueBufferQuery(gun_index, transactionDatas);
  6783. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6784. random_uuid(guid);
  6785. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6786. ,MESSAGE_TYPE_CALL
  6787. ,guid
  6788. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6789. json_object_put(StopTransaction);
  6790. #if 1 // for TempStopTransaction
  6791. //Delete TempStopTransaction
  6792. if((access(TempStopTransaction,F_OK))!=-1)
  6793. {
  6794. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6795. }
  6796. #endif
  6797. #if 1
  6798. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6799. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6800. {
  6801. result = PASS;
  6802. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6803. }
  6804. #endif
  6805. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6806. OCPP_insert_transaction_msg(NO, queuedata);
  6807. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6808. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6809. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6810. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6811. {
  6812. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6813. }
  6814. //for test
  6815. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6816. return result;
  6817. }
  6818. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6819. {
  6820. mtrace();
  6821. int result = FAIL;
  6822. char guid[37]={0};
  6823. char tempdata[65]={0};
  6824. int tempIndex = 0;
  6825. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6826. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6827. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6828. //set value
  6829. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6830. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6831. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6832. -1);
  6833. random_uuid(guid);
  6834. //UTC Date time
  6835. struct timeval tmnow;
  6836. struct tm *tm;
  6837. char buf[28];//, usec_buf[6];
  6838. gettimeofday(&tmnow, NULL);
  6839. time_t t;
  6840. t = time(NULL);
  6841. /*UTC time and date*/
  6842. tm = gmtime(&t);
  6843. if(dataType == ReadingContext_Sample_Clock)
  6844. {
  6845. struct tm *tmTarget;
  6846. struct timeb tbTarget;
  6847. tbTarget.time = mktime(tm);
  6848. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6849. tmTarget = gmtime(&tbTarget.time);
  6850. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6851. }
  6852. else
  6853. {
  6854. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6855. }
  6856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6857. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6858. //********************************(1)Current.Import L1************************************************/
  6859. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6860. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6861. (dataType == ReadingContext_Trigger))
  6862. {
  6863. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6865. {
  6866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6867. {
  6868. tempIndex = ((gun_index==2) ? 1: 0);
  6869. }
  6870. else
  6871. {
  6872. tempIndex = gun_index;
  6873. }
  6874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6875. {
  6876. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6877. {
  6878. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6879. }
  6880. }
  6881. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6882. }
  6883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6884. {
  6885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6886. {
  6887. tempIndex = ((gun_index==2) ? 1: 0);
  6888. }
  6889. else
  6890. {
  6891. tempIndex = gun_index;
  6892. }
  6893. for (int index = 0; index < CCS_QUANTITY; index++)
  6894. {
  6895. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6896. {
  6897. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6898. }
  6899. }
  6900. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6901. }
  6902. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6903. {
  6904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6905. {
  6906. tempIndex = ((gun_index==2) ? 1: 0);
  6907. }
  6908. else
  6909. {
  6910. tempIndex = gun_index;
  6911. }
  6912. for (int index = 0; index < GB_QUANTITY; index++)
  6913. {
  6914. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6915. {
  6916. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6917. }
  6918. }
  6919. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6920. }
  6921. else if(gunType[gun_index] == GUN_TYPE_DO)
  6922. {
  6923. tempIndex = gun_index;
  6924. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6925. {
  6926. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6927. {
  6928. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6929. }
  6930. }
  6931. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6932. }
  6933. else
  6934. {
  6935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6936. {
  6937. tempIndex = 2;
  6938. }
  6939. else
  6940. {
  6941. tempIndex = gun_index;
  6942. }
  6943. for (int index = 0; index < AC_QUANTITY; index++)
  6944. {
  6945. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6946. {
  6947. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6948. }
  6949. }
  6950. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6951. }
  6952. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6953. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6954. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6957. }
  6958. //********************************(2)Energy.Active.Import.Register ************************************************/
  6959. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6960. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6961. (dataType == ReadingContext_Trigger))
  6962. {
  6963. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6964. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6965. {
  6966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6967. {
  6968. tempIndex = ((gun_index==2) ? 1: 0);
  6969. }
  6970. else
  6971. {
  6972. tempIndex = gun_index;
  6973. }
  6974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6975. {
  6976. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6977. {
  6978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6979. }
  6980. }
  6981. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6982. }
  6983. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6984. {
  6985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6986. {
  6987. tempIndex = ((gun_index==2) ? 1: 0);
  6988. }
  6989. else
  6990. {
  6991. tempIndex = gun_index;
  6992. }
  6993. for (int index = 0; index < CCS_QUANTITY; index++)
  6994. {
  6995. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6996. {
  6997. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6998. }
  6999. }
  7000. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7001. }
  7002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7003. {
  7004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7005. {
  7006. tempIndex = ((gun_index==2) ? 1: 0);
  7007. }
  7008. else
  7009. {
  7010. tempIndex = gun_index;
  7011. }
  7012. for (int index = 0; index < GB_QUANTITY; index++)
  7013. {
  7014. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7015. {
  7016. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7017. }
  7018. }
  7019. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7020. }
  7021. else if(gunType[gun_index] == GUN_TYPE_DO)
  7022. {
  7023. tempIndex = gun_index;
  7024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7025. {
  7026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7027. {
  7028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7029. }
  7030. }
  7031. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7032. }
  7033. else
  7034. {
  7035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7036. {
  7037. tempIndex = 2;
  7038. }
  7039. else
  7040. {
  7041. tempIndex = gun_index;
  7042. }
  7043. for (int index = 0; index < AC_QUANTITY; index++)
  7044. {
  7045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7046. {
  7047. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7048. }
  7049. }
  7050. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7051. }
  7052. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7053. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7054. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7056. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7057. }
  7058. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7059. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7060. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7061. (dataType == ReadingContext_Trigger))
  7062. {
  7063. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7064. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7065. {
  7066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7067. {
  7068. tempIndex = ((gun_index==2) ? 1: 0);
  7069. }
  7070. else
  7071. {
  7072. tempIndex = gun_index;
  7073. }
  7074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7075. {
  7076. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7077. {
  7078. if(dataType == ReadingContext_Sample_Clock)
  7079. {
  7080. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7081. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7082. }
  7083. else if(dataType == ReadingContext_Sample_Periodic)
  7084. {
  7085. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7086. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7087. }
  7088. else
  7089. {
  7090. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7091. }
  7092. }
  7093. } // END OF FOR CHAdeMO_QUANTITY
  7094. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7095. }
  7096. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7097. {
  7098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7099. {
  7100. tempIndex = ((gun_index==2) ? 1: 0);
  7101. }
  7102. else
  7103. {
  7104. tempIndex = gun_index;
  7105. }
  7106. for (int index = 0; index < CCS_QUANTITY; index++)
  7107. {
  7108. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7109. {
  7110. if(dataType == ReadingContext_Sample_Clock)
  7111. {
  7112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7113. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7114. }
  7115. else if(dataType == ReadingContext_Sample_Periodic)
  7116. {
  7117. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7118. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7119. }
  7120. else
  7121. {
  7122. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7123. }
  7124. }
  7125. } // END OF CCS_QUANTITY
  7126. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7127. }
  7128. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7129. {
  7130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7131. {
  7132. tempIndex = ((gun_index==2) ? 1: 0);
  7133. }
  7134. else
  7135. {
  7136. tempIndex = gun_index;
  7137. }
  7138. for (int index = 0; index < GB_QUANTITY; index++)
  7139. {
  7140. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7141. {
  7142. if(dataType == ReadingContext_Sample_Clock)
  7143. {
  7144. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7145. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7146. }
  7147. else if(dataType == ReadingContext_Sample_Periodic)
  7148. {
  7149. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7150. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7151. }
  7152. else
  7153. {
  7154. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7155. }
  7156. }
  7157. } // END OF GB_QUANTITY
  7158. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7159. }
  7160. else if(gunType[gun_index] == GUN_TYPE_DO)
  7161. {
  7162. tempIndex = gun_index;
  7163. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7164. {
  7165. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7166. {
  7167. if(dataType == ReadingContext_Sample_Clock)
  7168. {
  7169. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7170. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7171. }
  7172. else if(dataType == ReadingContext_Sample_Periodic)
  7173. {
  7174. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7175. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7176. }
  7177. else
  7178. {
  7179. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7180. }
  7181. }
  7182. }
  7183. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7184. }
  7185. else
  7186. {
  7187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7188. {
  7189. tempIndex = 2;
  7190. }
  7191. else
  7192. {
  7193. tempIndex = gun_index;
  7194. }
  7195. for (int index = 0; index < AC_QUANTITY; index++)
  7196. {
  7197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7198. {
  7199. if(dataType == ReadingContext_Sample_Clock)
  7200. {
  7201. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7202. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7203. }
  7204. else if(dataType == ReadingContext_Sample_Periodic)
  7205. {
  7206. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7207. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7208. }
  7209. else
  7210. {
  7211. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7212. }
  7213. }
  7214. }
  7215. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7216. }
  7217. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7218. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7222. }
  7223. //********************************(4)Power.Active.Import************************************************/
  7224. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7225. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7226. (dataType == ReadingContext_Trigger))
  7227. {
  7228. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7229. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7230. {
  7231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7232. {
  7233. tempIndex = ((gun_index==2) ? 1: 0);
  7234. }
  7235. else
  7236. {
  7237. tempIndex = gun_index;
  7238. }
  7239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7240. {
  7241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7242. {
  7243. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7244. }
  7245. } // END OF FOR
  7246. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7247. }
  7248. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7249. {
  7250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7251. {
  7252. tempIndex = ((gun_index==2) ? 1: 0);
  7253. }
  7254. else
  7255. {
  7256. tempIndex = gun_index;
  7257. }
  7258. for (int index = 0; index < CCS_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7261. {
  7262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7263. }
  7264. }
  7265. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7266. }
  7267. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7268. {
  7269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7270. {
  7271. tempIndex = ((gun_index==2) ? 1: 0);
  7272. }
  7273. else
  7274. {
  7275. tempIndex = gun_index;
  7276. }
  7277. for (int index = 0; index < GB_QUANTITY; index++)
  7278. {
  7279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7280. {
  7281. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7282. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7283. }
  7284. }
  7285. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7286. }
  7287. else if(gunType[gun_index] == GUN_TYPE_DO)
  7288. {
  7289. tempIndex = gun_index;
  7290. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7291. {
  7292. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7293. {
  7294. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7295. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7296. }
  7297. }
  7298. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7299. }
  7300. else
  7301. {
  7302. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7303. {
  7304. tempIndex = 2;
  7305. }
  7306. else
  7307. {
  7308. tempIndex = gun_index;
  7309. }
  7310. for (int index = 0; index < AC_QUANTITY; index++)
  7311. {
  7312. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7313. {
  7314. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7315. }
  7316. }
  7317. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7318. }
  7319. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7320. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7324. }
  7325. //***********************************************(5)VOLTAGE L1******************************************************/
  7326. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7327. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7328. (dataType == ReadingContext_Trigger))
  7329. {
  7330. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7331. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7332. {
  7333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7334. {
  7335. tempIndex = ((gun_index==2) ? 1: 0);
  7336. }
  7337. else
  7338. {
  7339. tempIndex = gun_index;
  7340. }
  7341. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7342. {
  7343. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7344. {
  7345. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7346. }
  7347. }
  7348. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7349. }
  7350. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7351. {
  7352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7353. {
  7354. tempIndex = ((gun_index==2) ? 1: 0);
  7355. }
  7356. else
  7357. {
  7358. tempIndex = gun_index;
  7359. }
  7360. for (int index = 0; index < CCS_QUANTITY; index++)
  7361. {
  7362. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7363. {
  7364. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7365. }
  7366. }
  7367. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7368. }
  7369. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7370. {
  7371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7372. {
  7373. tempIndex = ((gun_index==2) ? 1: 0);
  7374. }
  7375. else
  7376. {
  7377. tempIndex = gun_index;
  7378. }
  7379. for (int index = 0; index < GB_QUANTITY; index++)
  7380. {
  7381. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7382. {
  7383. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7384. }
  7385. }
  7386. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7387. }
  7388. else if(gunType[gun_index] == GUN_TYPE_DO)
  7389. {
  7390. tempIndex = gun_index;
  7391. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7392. {
  7393. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7394. {
  7395. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7396. }
  7397. }
  7398. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7399. }
  7400. else
  7401. {
  7402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7403. {
  7404. tempIndex = 2;
  7405. }
  7406. else
  7407. {
  7408. tempIndex = gun_index;
  7409. }
  7410. for (int index = 0; index < AC_QUANTITY; index++)
  7411. {
  7412. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7413. {
  7414. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7415. }
  7416. }
  7417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7418. }
  7419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7422. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7424. }
  7425. //***********************************************(6)SOC******************************************************/
  7426. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7427. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7428. (dataType == ReadingContext_Trigger))
  7429. {
  7430. 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))
  7431. {
  7432. //idx_sample=5;
  7433. //sampledValue = NULL;
  7434. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7435. {
  7436. tempIndex = ((gun_index==2) ? 1: 0);
  7437. }
  7438. else
  7439. {
  7440. tempIndex = gun_index;
  7441. }
  7442. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7443. {
  7444. //tempIndex = ((gun_index==2) ? 1: 0);
  7445. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7446. {
  7447. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7448. {
  7449. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7450. }
  7451. }
  7452. }
  7453. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7454. {
  7455. //tempIndex = ((gun_index==2) ? 1: 0);
  7456. for (int index = 0; index < CCS_QUANTITY; index++)
  7457. {
  7458. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7459. {
  7460. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7461. }
  7462. }
  7463. }
  7464. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7465. {
  7466. //tempIndex = ((gun_index==2) ? 1: 0);
  7467. for (int index = 0; index < GB_QUANTITY; index++)
  7468. {
  7469. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7470. {
  7471. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7472. }
  7473. }
  7474. }
  7475. else if(gunType[gun_index] == GUN_TYPE_DO)
  7476. {
  7477. //tempIndex = ((gun_index==2) ? 1: 0);
  7478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7479. {
  7480. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7481. {
  7482. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7483. }
  7484. }
  7485. }
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7489. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7492. }
  7493. }
  7494. //********************************(7)Current.Import L2************************************************/
  7495. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7496. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7497. (dataType == ReadingContext_Trigger))
  7498. {
  7499. // Only for AC 3 phase
  7500. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7501. {
  7502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7503. {
  7504. tempIndex = 2;
  7505. }
  7506. else
  7507. {
  7508. tempIndex = gun_index;
  7509. }
  7510. for (int index = 0; index < AC_QUANTITY; index++)
  7511. {
  7512. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7513. {
  7514. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7515. }
  7516. }
  7517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7518. }
  7519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7524. }
  7525. //********************************(8)Current.Import L3************************************************/
  7526. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7527. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7528. (dataType == ReadingContext_Trigger))
  7529. {
  7530. // Only for AC 3 phase
  7531. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7532. {
  7533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7534. {
  7535. tempIndex = 2;
  7536. }
  7537. else
  7538. {
  7539. tempIndex = gun_index;
  7540. }
  7541. for (int index = 0; index < AC_QUANTITY; index++)
  7542. {
  7543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7544. {
  7545. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7546. }
  7547. }
  7548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7549. }
  7550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7554. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7555. }
  7556. //***********************************************(9)VOLTAGE L2******************************************************/
  7557. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7558. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7559. (dataType == ReadingContext_Trigger))
  7560. {
  7561. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7562. {
  7563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7564. {
  7565. tempIndex = 2;
  7566. }
  7567. else
  7568. {
  7569. tempIndex = gun_index;
  7570. }
  7571. for (int index = 0; index < AC_QUANTITY; index++)
  7572. {
  7573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7574. {
  7575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7576. }
  7577. }
  7578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7579. }
  7580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7585. }
  7586. //***********************************************(10)VOLTAGE L3******************************************************/
  7587. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7588. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7589. (dataType == ReadingContext_Trigger))
  7590. {
  7591. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7592. {
  7593. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7594. {
  7595. tempIndex = 2;
  7596. }
  7597. else
  7598. {
  7599. tempIndex = gun_index;
  7600. }
  7601. for (int index = 0; index < AC_QUANTITY; index++)
  7602. {
  7603. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7604. {
  7605. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7606. }
  7607. }
  7608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7609. }
  7610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7615. }
  7616. //***********************************************(11)Current.Offered******************************************************/
  7617. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7618. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7619. (dataType == ReadingContext_Trigger))
  7620. {
  7621. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7622. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7623. {
  7624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7625. {
  7626. tempIndex = ((gun_index==2) ? 1: 0);
  7627. }
  7628. else
  7629. {
  7630. tempIndex = gun_index;
  7631. }
  7632. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7633. {
  7634. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7635. {
  7636. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7637. }
  7638. } // END OF FOR CHAdeMO_QUANTITY
  7639. }
  7640. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7641. {
  7642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7643. {
  7644. tempIndex = ((gun_index==2) ? 1: 0);
  7645. }
  7646. else
  7647. {
  7648. tempIndex = gun_index;
  7649. }
  7650. for (int index = 0; index < CCS_QUANTITY; index++)
  7651. {
  7652. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7653. {
  7654. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7655. }
  7656. } // END OF CCS_QUANTITY
  7657. }
  7658. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7659. {
  7660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7661. {
  7662. tempIndex = ((gun_index==2) ? 1: 0);
  7663. }
  7664. else
  7665. {
  7666. tempIndex = gun_index;
  7667. }
  7668. for (int index = 0; index < GB_QUANTITY; index++)
  7669. {
  7670. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7671. {
  7672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7673. }
  7674. } // END OF GB_QUANTITY
  7675. }
  7676. else if(gunType[gun_index] == GUN_TYPE_DO)
  7677. {
  7678. tempIndex = gun_index;
  7679. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7680. {
  7681. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7682. {
  7683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7684. }
  7685. }
  7686. }
  7687. else
  7688. {
  7689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7690. {
  7691. tempIndex = 2;
  7692. }
  7693. else
  7694. {
  7695. tempIndex = gun_index;
  7696. }
  7697. for (int index = 0; index < AC_QUANTITY; index++)
  7698. {
  7699. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7700. {
  7701. uint16_t currentOffer;
  7702. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7703. {
  7704. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7705. }
  7706. else
  7707. {
  7708. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7709. }
  7710. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7711. }
  7712. }
  7713. }
  7714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7715. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7718. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7719. }
  7720. //***********************************************(12)Power.Offered******************************************************/
  7721. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7722. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7723. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7724. {
  7725. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7726. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7727. {
  7728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7729. {
  7730. tempIndex = ((gun_index==2) ? 1: 0);
  7731. }
  7732. else
  7733. {
  7734. tempIndex = gun_index;
  7735. }
  7736. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7737. {
  7738. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7739. {
  7740. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7741. }
  7742. } // END OF FOR CHAdeMO_QUANTITY
  7743. }
  7744. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7745. {
  7746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7747. {
  7748. tempIndex = ((gun_index==2) ? 1: 0);
  7749. }
  7750. else
  7751. {
  7752. tempIndex = gun_index;
  7753. }
  7754. for (int index = 0; index < CCS_QUANTITY; index++)
  7755. {
  7756. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7757. {
  7758. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7759. }
  7760. } // END OF CCS_QUANTITY
  7761. }
  7762. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7763. {
  7764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7765. {
  7766. tempIndex = ((gun_index==2) ? 1: 0);
  7767. }
  7768. else
  7769. {
  7770. tempIndex = gun_index;
  7771. }
  7772. for (int index = 0; index < GB_QUANTITY; index++)
  7773. {
  7774. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7775. {
  7776. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7777. }
  7778. } // END OF GB_QUANTITY
  7779. }
  7780. else if(gunType[gun_index] == GUN_TYPE_DO)
  7781. {
  7782. tempIndex = gun_index;
  7783. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7784. {
  7785. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7786. {
  7787. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7788. }
  7789. }
  7790. }
  7791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7796. }
  7797. // Message create ====================================================================================================
  7798. if(TRUE)
  7799. {
  7800. json_object *MeterValueReq = json_object_new_object();
  7801. json_object *MeterValues = json_object_new_array();
  7802. json_object *sampledValues = json_object_new_array();
  7803. json_object *sampledValuesBuffer = json_object_new_array();
  7804. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7805. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7806. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7807. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7808. {
  7809. json_object *MeterValue = json_object_new_object();
  7810. json_object *MeterValueBuffer = json_object_new_object();
  7811. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7812. {
  7813. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7814. {
  7815. json_object *sampledValue = json_object_new_object();
  7816. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7817. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7818. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7819. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7820. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7821. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7822. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7823. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7824. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7825. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7826. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7827. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7828. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7829. json_object_array_add(sampledValues, sampledValue);
  7830. // For StopTxn data
  7831. 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)) ||
  7832. ((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)))
  7833. {
  7834. json_object *sampledValue = json_object_new_object();
  7835. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7836. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7837. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7838. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7839. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7840. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7841. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7842. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7843. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7844. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7845. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7846. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7847. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7848. json_object_array_add(sampledValuesBuffer, sampledValue);
  7849. }
  7850. }
  7851. }
  7852. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7853. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7854. json_object_array_add(MeterValues, MeterValue);
  7855. // For StopTxn data
  7856. if((dataType != ReadingContext_Trigger) &&
  7857. (json_object_array_length(sampledValuesBuffer) > 0))
  7858. {
  7859. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7860. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  7861. if(meterValueBufferDataQuantity(gun_index, dataType) < 200)
  7862. meterValueBufferInsert(gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7863. else
  7864. meterValueBufferReplace(200, gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7865. json_object_put(MeterValueBuffer);
  7866. }
  7867. else
  7868. {
  7869. json_object_put(sampledValuesBuffer);
  7870. json_object_put(MeterValueBuffer);
  7871. }
  7872. }
  7873. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7874. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7875. ,gun_index + 1
  7876. ,MESSAGE_TYPE_CALL
  7877. ,guid
  7878. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7879. json_object_put(MeterValueReq);
  7880. }
  7881. // Put request guid to hash map
  7882. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7883. 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*/)
  7884. {
  7885. result = PASS;
  7886. //DEBUG_INFO("MeterValues mapitem pass\n");
  7887. }
  7888. if((dataType != ReadingContext_Trigger) &&
  7889. (dataType != ReadingContext_Sample_Clock) &&
  7890. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7891. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7892. else
  7893. {
  7894. if(FirstHeartBeat)
  7895. LWS_Send(queuedata +2);
  7896. }
  7897. return result;
  7898. }
  7899. int sendLogStatusNotificationRequest(char *status)
  7900. {
  7901. mtrace();
  7902. int result = PASS;
  7903. char message[4096]={0};
  7904. char guid[37]={0};
  7905. char tempdata[128]={0};
  7906. json_object *LogStatusNotification = json_object_new_object();
  7907. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7908. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7909. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7910. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7911. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7912. random_uuid(guid);
  7913. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7914. json_object_put(LogStatusNotification);
  7915. LWS_Send(message);
  7916. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7917. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7918. {
  7919. result = PASS;
  7920. }
  7921. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7922. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7923. return result;
  7924. }
  7925. int sendSecurityEventNotificationRequest()
  7926. {
  7927. mtrace();
  7928. int result = PASS;
  7929. char message[4096]={0};
  7930. char guid[37]={0};
  7931. char tempdata[128]={0};
  7932. json_object *SecurityEventNotification = json_object_new_object();
  7933. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7934. //Stop Transaction Time
  7935. struct timeval tmnow;
  7936. struct tm *tm;
  7937. gettimeofday(&tmnow, NULL);
  7938. time_t t;
  7939. t = time(NULL);
  7940. /*UTC time and date*/
  7941. tm = gmtime(&t);
  7942. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7943. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7944. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7945. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7946. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7947. random_uuid(guid);
  7948. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7949. json_object_put(SecurityEventNotification);
  7950. LWS_Send(message);
  7951. sprintf(tempdata, "SecurityEventNotification,0");
  7952. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7953. {
  7954. result = PASS;
  7955. }
  7956. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7957. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7958. return result;
  7959. }
  7960. int sendSignCertificateRequest()
  7961. {
  7962. mtrace();
  7963. int result = PASS;
  7964. char message[4096]={0};
  7965. char guid[37]={0};
  7966. char tempdata[128]={0};
  7967. json_object *SignCertificate = json_object_new_object();
  7968. DEBUG_INFO("sendSignCertificateRequest...\n");
  7969. // Read csr file content
  7970. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7971. FILE *fp=fopen(CSR_CP,"r");
  7972. char *line = NULL;
  7973. size_t len = 0;
  7974. while(getline(&line, &len, fp) != -1)
  7975. {
  7976. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7977. {
  7978. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7979. }
  7980. }
  7981. fclose(fp);
  7982. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7983. random_uuid(guid);
  7984. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7985. json_object_put(SignCertificate);
  7986. LWS_Send(message);
  7987. sprintf(tempdata, "SignCertificate,0");
  7988. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7989. {
  7990. result = PASS;
  7991. }
  7992. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7993. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7994. return result;
  7995. }
  7996. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7997. {
  7998. mtrace();
  7999. int result = PASS;
  8000. char message[4096]={0};
  8001. char guid[37]={0};
  8002. char tempdata[128]={0};
  8003. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  8004. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  8005. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  8006. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  8007. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  8008. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  8009. random_uuid(guid);
  8010. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8011. json_object_put(SignedFirmwareStatusNotification);
  8012. LWS_Send(message);
  8013. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  8014. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8015. {
  8016. result = PASS;
  8017. }
  8018. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  8019. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  8020. return result;
  8021. }
  8022. //==========================================
  8023. // send confirm routine
  8024. //==========================================
  8025. int sendCancelReservationConfirmation(char *uuid,char *payload)
  8026. {
  8027. mtrace();
  8028. int result = FAIL;
  8029. char message[100]={0};
  8030. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8031. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8032. LWS_Send(message);
  8033. result = TRUE;
  8034. return result;
  8035. }
  8036. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8037. {
  8038. mtrace();
  8039. int result = FAIL;
  8040. char message[100]={0};
  8041. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8042. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8043. LWS_Send(message);
  8044. result = TRUE;
  8045. return result;
  8046. }
  8047. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8048. {
  8049. mtrace();
  8050. int result = FAIL;
  8051. char message[100]={0};
  8052. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8053. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8054. LWS_Send(message);
  8055. result = TRUE;
  8056. return result;
  8057. }
  8058. int sendClearCacheConfirmation(char *uuid,char *payload)
  8059. {
  8060. mtrace();
  8061. int result = FAIL;
  8062. char message[500]={0};
  8063. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8064. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8065. LWS_Send(message);
  8066. return result;
  8067. }
  8068. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8069. {
  8070. mtrace();
  8071. int result = FAIL;
  8072. char message[500]={0};
  8073. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8074. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8075. LWS_Send(message);
  8076. return result;
  8077. }
  8078. int sendDataTransferConfirmation(char *uuid,char *payload)
  8079. {
  8080. mtrace();
  8081. char statusStr[20]={0};
  8082. char dataStr[10]={0};
  8083. char sstr[20]={0};
  8084. int c = 0;
  8085. char *loc;
  8086. int result = FAIL;
  8087. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8088. /**********************status**************************/
  8089. loc = strstr(payload, "status");
  8090. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8091. c = 0;
  8092. while (loc[3+strlen("status")+c] != '\"')
  8093. {
  8094. sstr[c] = loc[3+strlen("status")+c];
  8095. c++;
  8096. }
  8097. sstr[c] = '\0';
  8098. strcpy(statusStr, sstr);
  8099. /**********************data**************************/
  8100. loc = strstr(payload, "data");
  8101. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8102. c = 0;
  8103. while (loc[3+strlen("data")+c] != '\"')
  8104. {
  8105. sstr[c] = loc[3+strlen("data")+c];
  8106. c++;
  8107. }
  8108. sstr[c] = '\0';
  8109. strcpy(dataStr, sstr);
  8110. return result;
  8111. }
  8112. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8113. {
  8114. mtrace();
  8115. int result = FAIL;
  8116. char message[1000]={0};
  8117. int CompositeScheduleIndex = 0;
  8118. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8119. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8120. if(nPeriod == 0)
  8121. {
  8122. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8123. {
  8124. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8125. ,MESSAGE_TYPE_CALLRESULT
  8126. ,uuid
  8127. ,payload
  8128. ,connectorIdInt);
  8129. }
  8130. else
  8131. {
  8132. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8133. ,MESSAGE_TYPE_CALLRESULT
  8134. ,uuid
  8135. ,payload
  8136. ,connectorIdInt
  8137. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8138. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8139. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8140. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8141. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8142. }
  8143. }
  8144. else
  8145. {
  8146. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8147. ,MESSAGE_TYPE_CALLRESULT
  8148. ,uuid
  8149. ,payload
  8150. ,connectorIdInt
  8151. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8152. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8153. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8154. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8155. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8156. {
  8157. if (idx_sample == 0)
  8158. {
  8159. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8160. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8161. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8162. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8163. }
  8164. else
  8165. {
  8166. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8167. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8168. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8169. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8170. }
  8171. }
  8172. sprintf(message + strlen(message), "]}}]");
  8173. }
  8174. LWS_Send(message);
  8175. result = TRUE;
  8176. return result;
  8177. }
  8178. int sendGetConfigurationConfirmation(char *uuid)
  8179. {
  8180. mtrace();
  8181. int result = FAIL;
  8182. int MaxKeySupported = 0;
  8183. int sentConfigurationNumber= 0;
  8184. int sentunConfigurationNumber= 0;
  8185. char message[1024*10]={0};
  8186. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8187. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8188. //configuration key
  8189. json_object *GetConfiguration = json_object_new_object();
  8190. json_object *configurationKey = json_object_new_array();
  8191. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8192. {
  8193. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8194. {
  8195. json_object *keyValue = json_object_new_object();
  8196. json_object_object_add(keyValue, "key", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key));
  8197. 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));
  8198. json_object_object_add(keyValue, "value", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value));
  8199. json_object_array_add(configurationKey, keyValue);
  8200. sentConfigurationNumber = sentConfigurationNumber + 1;
  8201. }
  8202. }
  8203. json_object *unknownKey = json_object_new_array();
  8204. if(UnknownKeynum != 0)
  8205. {
  8206. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8207. {
  8208. DEBUG_INFO("unknown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8209. json_object_array_add(unknownKey, json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
  8210. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8211. }
  8212. }
  8213. if((sentConfigurationNumber>0) && (sentunConfigurationNumber>0))
  8214. {
  8215. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8216. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8217. }
  8218. else if(sentConfigurationNumber>0)
  8219. {
  8220. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8221. json_object_put(unknownKey);
  8222. }
  8223. else
  8224. {
  8225. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8226. json_object_put(configurationKey);
  8227. }
  8228. sprintf(message,"[%d,\"%s\",%s]"
  8229. ,MESSAGE_TYPE_CALLRESULT
  8230. ,uuid
  8231. ,json_object_to_json_string_ext(GetConfiguration, JSON_C_TO_STRING_PLAIN));
  8232. json_object_put(GetConfiguration);
  8233. LWS_Send(message);
  8234. return result;
  8235. }
  8236. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8237. {
  8238. mtrace();
  8239. int result = FAIL;
  8240. char message[400]={0};
  8241. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8242. if(strcmp(payload,"")==0)
  8243. {
  8244. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8245. }
  8246. else
  8247. {
  8248. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8249. }
  8250. LWS_Send(message);
  8251. result = TRUE;
  8252. return result;
  8253. }
  8254. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8255. {
  8256. mtrace();
  8257. int result = FAIL;
  8258. char message[80]={0};
  8259. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8260. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8261. LWS_Send(message);
  8262. result = TRUE;
  8263. return result;
  8264. }
  8265. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8266. {
  8267. mtrace();
  8268. int result = FAIL;
  8269. char message[80]={0};
  8270. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8271. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8272. LWS_Send(message);
  8273. result = TRUE;
  8274. return result;
  8275. }
  8276. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8277. {
  8278. mtrace();
  8279. int result = FAIL;
  8280. char message[80]={0};
  8281. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8282. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8283. LWS_Send(message);
  8284. result = TRUE;
  8285. return result;
  8286. }
  8287. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8288. {
  8289. mtrace();
  8290. int result = FAIL;
  8291. char message[80]={0};
  8292. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8293. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8294. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8295. LWS_Send(message);
  8296. result = TRUE;
  8297. return result;
  8298. }
  8299. int sendResetConfirmation(char *uuid,char *payload)
  8300. {
  8301. mtrace();
  8302. int result = FAIL;
  8303. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8304. char message[80]={0};
  8305. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8306. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8307. LWS_Send(message);
  8308. result = TRUE;
  8309. return result;
  8310. }
  8311. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8312. {
  8313. mtrace();
  8314. int result = FAIL;
  8315. char message[500]={0};
  8316. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8317. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8318. LWS_Send(message);
  8319. result = TRUE;
  8320. return result;
  8321. }
  8322. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8323. {
  8324. mtrace();
  8325. int result = FAIL;
  8326. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8327. char message[80]={0};
  8328. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8329. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8330. LWS_Send(message);
  8331. result = TRUE;
  8332. return result;
  8333. }
  8334. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8335. {
  8336. mtrace();
  8337. int result = FAIL;
  8338. char message[80]={0};
  8339. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8340. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8341. LWS_Send(message);
  8342. result = TRUE;
  8343. return result;
  8344. }
  8345. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8346. {
  8347. mtrace();
  8348. int result = FAIL;
  8349. char message[80]={0};
  8350. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8351. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8352. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8353. LWS_Send(message);
  8354. result = TRUE;
  8355. return result;
  8356. }
  8357. int sendUpdateFirmwareConfirmation(char *uuid)
  8358. {
  8359. mtrace();
  8360. int result = FAIL;
  8361. char message[60]={0};
  8362. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8363. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8364. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8365. LWS_Send(message);
  8366. result = TRUE;
  8367. return result;
  8368. }
  8369. int sendCertificateSignedConfirmation(char *uuid)
  8370. {
  8371. mtrace();
  8372. int result = PASS;
  8373. char message[4096]={0};
  8374. json_object *CertificateSigned = json_object_new_object();
  8375. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8376. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8377. sprintf(message,"[%d,\"%s\",%s]"
  8378. ,MESSAGE_TYPE_CALLRESULT
  8379. ,uuid
  8380. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8381. json_object_put(CertificateSigned);
  8382. LWS_Send(message);
  8383. return result;
  8384. }
  8385. int sendDeleteCertificateConfirmation(char *uuid)
  8386. {
  8387. mtrace();
  8388. int result = PASS;
  8389. char message[4096]={0};
  8390. json_object *DeleteCertificate = json_object_new_object();
  8391. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8392. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8393. sprintf(message,"[%d,\"%s\",%s]"
  8394. ,MESSAGE_TYPE_CALLRESULT
  8395. ,uuid
  8396. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8397. json_object_put(DeleteCertificate);
  8398. LWS_Send(message);
  8399. return result;
  8400. }
  8401. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8402. {
  8403. mtrace();
  8404. int result = PASS;
  8405. char message[4096]={0};
  8406. json_object *ExtendedTriggerMessage = json_object_new_object();
  8407. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8408. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8409. sprintf(message,"[%d,\"%s\",%s]"
  8410. ,MESSAGE_TYPE_CALLRESULT
  8411. ,uuid
  8412. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8413. json_object_put(ExtendedTriggerMessage);
  8414. LWS_Send(message);
  8415. return result;
  8416. }
  8417. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8418. {
  8419. mtrace();
  8420. int result = PASS;
  8421. char message[4096]={0};
  8422. json_object *GetInstalledCertificateIds = json_object_new_object();
  8423. json_object *certificateHashDataDatas = json_object_new_array();
  8424. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8425. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8426. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8427. {
  8428. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8429. {
  8430. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8431. {
  8432. json_object *certificateHashData = json_object_new_object();
  8433. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8434. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8435. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8436. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8437. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8438. }
  8439. }
  8440. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8441. }
  8442. else
  8443. {
  8444. json_object_put(certificateHashDataDatas);
  8445. }
  8446. sprintf(message,"[%d,\"%s\",%s]"
  8447. ,MESSAGE_TYPE_CALLRESULT
  8448. ,uuid
  8449. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8450. json_object_put(GetInstalledCertificateIds);
  8451. LWS_Send(message);
  8452. return result;
  8453. }
  8454. int sendGetLogConfirmation(char *uuid)
  8455. {
  8456. mtrace();
  8457. int result = PASS;
  8458. char message[4096]={0};
  8459. json_object *GetLog = json_object_new_object();
  8460. DEBUG_INFO("sendGetLogConfirmation...\n");
  8461. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8462. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8463. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8464. sprintf(message,"[%d,\"%s\",%s]"
  8465. ,MESSAGE_TYPE_CALLRESULT
  8466. ,uuid
  8467. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8468. json_object_put(GetLog);
  8469. LWS_Send(message);
  8470. return result;
  8471. }
  8472. int sendInstallCertificateConfirmation(char *uuid)
  8473. {
  8474. mtrace();
  8475. int result = PASS;
  8476. char message[4096]={0};
  8477. json_object *InstallCertificate = json_object_new_object();
  8478. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8479. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8480. sprintf(message,"[%d,\"%s\",%s]"
  8481. ,MESSAGE_TYPE_CALLRESULT
  8482. ,uuid
  8483. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8484. json_object_put(InstallCertificate);
  8485. LWS_Send(message);
  8486. return result;
  8487. }
  8488. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8489. {
  8490. mtrace();
  8491. int result = PASS;
  8492. char message[4096]={0};
  8493. json_object *SignedUpdateFirmware = json_object_new_object();
  8494. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8495. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8496. sprintf(message,"[%d,\"%s\",%s]"
  8497. ,MESSAGE_TYPE_CALLRESULT
  8498. ,uuid
  8499. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8500. json_object_put(SignedUpdateFirmware);
  8501. LWS_Send(message);
  8502. return result;
  8503. }
  8504. int sendUnknownConfirmation(char *uuid)
  8505. {
  8506. mtrace();
  8507. int result = PASS;
  8508. char message[256]={0};
  8509. DEBUG_INFO("sendUnknownConfirmation...\n");
  8510. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8511. LWS_Send(message);
  8512. return result;
  8513. }
  8514. //==========================================
  8515. // Handle server request routine Start
  8516. //==========================================
  8517. int handleCancelReservationRequest(char *uuid, char *payload)
  8518. {
  8519. mtrace();
  8520. int result = FAIL;
  8521. int gunNO = 0;
  8522. int reservationIdInt = -1;
  8523. char comfirmstr[20];
  8524. DEBUG_INFO("handleCancelReservationRequest...\n");
  8525. json_object *CancelReservation;
  8526. CancelReservation = json_tokener_parse(payload);
  8527. if(!is_error(CancelReservation))
  8528. {
  8529. // Required data
  8530. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8531. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8532. }
  8533. json_object_put(CancelReservation);
  8534. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8535. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8536. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8537. if(reservationIdInt != -1)
  8538. {
  8539. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8540. //check Transaction active
  8541. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8542. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8543. {
  8544. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8545. {
  8546. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8547. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8548. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8549. {
  8550. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8551. }
  8552. else
  8553. {
  8554. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8555. }
  8556. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8557. goto end;
  8558. }
  8559. }
  8560. for (int index = 0; index < CCS_QUANTITY; index++)
  8561. {
  8562. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8563. {
  8564. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8565. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8566. if(gunType[2] == GUN_TYPE_CCS)
  8567. {
  8568. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8569. }
  8570. else
  8571. {
  8572. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8573. }
  8574. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8575. goto end;
  8576. }
  8577. }
  8578. for (int index = 0; index < GB_QUANTITY; index++)
  8579. {
  8580. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8581. {
  8582. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8583. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8584. if(gunType[2] == GUN_TYPE_GBT)
  8585. {
  8586. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8587. }
  8588. else
  8589. {
  8590. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8591. }
  8592. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8593. goto end;
  8594. }
  8595. }
  8596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8597. {
  8598. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8599. {
  8600. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8601. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8602. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8603. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8604. goto end;
  8605. }
  8606. }
  8607. for (int index = 0; index < AC_QUANTITY; index++)
  8608. {
  8609. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8610. {
  8611. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8612. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8613. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8614. {
  8615. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8616. }
  8617. else
  8618. {
  8619. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8620. }
  8621. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8622. goto end;
  8623. }
  8624. }
  8625. }
  8626. //The reservationId does NOT match the reservationId
  8627. sendCancelReservationConfirmation(uuid, comfirmstr);
  8628. end:
  8629. // Fill in ocpp packet uuid
  8630. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8631. return result;
  8632. }
  8633. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8634. {
  8635. mtrace();
  8636. int result = FAIL;
  8637. int gunIndex = -1;
  8638. char typeStr[16]={0};
  8639. char comfirmstr[20];
  8640. int specificId = FALSE;
  8641. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8642. json_object *ChangeAvailability;
  8643. ChangeAvailability = json_tokener_parse(payload);
  8644. if(!is_error(ChangeAvailability))
  8645. {
  8646. // Required data
  8647. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8648. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8649. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8650. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8651. }
  8652. json_object_put(ChangeAvailability);
  8653. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8654. {
  8655. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8656. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8657. }
  8658. else if(gunIndex == 0)
  8659. {
  8660. for(int i=0; i < gunTotalNumber; i++)
  8661. {
  8662. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8663. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8664. }
  8665. }
  8666. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8667. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8668. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8669. {
  8670. specificId = TRUE;
  8671. }
  8672. if(specificId == FALSE)
  8673. goto end;
  8674. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8675. {
  8676. //----------------------gunIndex is 0 ------------------------------------------------//
  8677. if(gunIndex == 0)
  8678. {
  8679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8680. {
  8681. for(int i=0; i < gunTotalNumber; i++)
  8682. {
  8683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8684. {
  8685. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8686. {
  8687. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8688. {
  8689. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8690. goto end;
  8691. }
  8692. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8693. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8694. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8695. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8696. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8697. {
  8698. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8699. goto end;
  8700. }
  8701. }
  8702. }//END FOR CHAdeMO_QUANTITY
  8703. for (int index = 0; index < CCS_QUANTITY; index++)
  8704. {
  8705. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8706. {
  8707. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8708. {
  8709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8710. goto end;
  8711. }
  8712. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8713. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8714. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8715. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8716. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8717. {
  8718. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8719. goto end;
  8720. }
  8721. }
  8722. }//END FOR CCS_QUANTITY
  8723. for (int index = 0; index < GB_QUANTITY; index++)
  8724. {
  8725. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8726. {
  8727. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8728. {
  8729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8730. goto end;
  8731. }
  8732. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8733. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8734. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8735. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8736. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8737. {
  8738. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8739. goto end;
  8740. }
  8741. }
  8742. }// END FOR GB_QUANTITY
  8743. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8744. {
  8745. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8746. {
  8747. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8748. {
  8749. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8750. goto end;
  8751. }
  8752. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8754. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8755. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8756. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8757. {
  8758. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8759. goto end;
  8760. }
  8761. }
  8762. }// END FOR GENERAL_GUN_QUANTITY
  8763. for (int index = 0; index < AC_QUANTITY; index++)
  8764. {
  8765. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8766. {
  8767. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8768. {
  8769. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8770. goto end;
  8771. }
  8772. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8773. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8774. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8775. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8776. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8777. {
  8778. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8779. goto end;
  8780. }
  8781. }
  8782. }//END FOR AC_QUANTITY
  8783. }// END FOR gunTotalNumber
  8784. }
  8785. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8786. {
  8787. for(int i=0; i < gunTotalNumber; i++)
  8788. {
  8789. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8790. {
  8791. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8792. goto end;
  8793. }
  8794. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8795. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8796. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8797. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8798. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8799. {
  8800. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8801. goto end;
  8802. }
  8803. }
  8804. }
  8805. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8806. goto end;
  8807. }
  8808. //----------------------gunIndex is not 0 ------------------------------------------------//
  8809. //check Transaction active
  8810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8811. {
  8812. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8813. {
  8814. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8815. {
  8816. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8817. goto end;
  8818. }
  8819. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8820. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8821. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8822. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8823. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8824. {
  8825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8826. goto end;
  8827. }
  8828. else
  8829. {
  8830. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8831. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8832. goto end;
  8833. }
  8834. }
  8835. }//END FOR CHAdeMO_QUANTITY
  8836. for (int index = 0; index < CCS_QUANTITY; index++)
  8837. {
  8838. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8839. {
  8840. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8841. {
  8842. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8843. goto end;
  8844. }
  8845. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8846. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8847. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8848. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8849. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8850. {
  8851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8852. goto end;
  8853. }
  8854. else
  8855. {
  8856. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8857. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8858. goto end;
  8859. }
  8860. }
  8861. }//END FOR CCS_QUANTITY
  8862. for (int index = 0; index < GB_QUANTITY; index++)
  8863. {
  8864. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8865. {
  8866. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8867. {
  8868. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8869. goto end;
  8870. }
  8871. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8872. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8873. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8874. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8875. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8876. {
  8877. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8878. goto end;
  8879. }
  8880. else
  8881. {
  8882. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8883. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8884. goto end;
  8885. }
  8886. }
  8887. }// END FOR GB_QUANTITY
  8888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8889. {
  8890. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8891. {
  8892. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8893. {
  8894. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8895. goto end;
  8896. }
  8897. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8898. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8899. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8900. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8901. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8902. {
  8903. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8904. goto end;
  8905. }
  8906. else
  8907. {
  8908. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8909. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8910. goto end;
  8911. }
  8912. }
  8913. }// END FOR GENERAL_GUN_QUANTITY
  8914. for (int index = 0; index < AC_QUANTITY; index++)
  8915. {
  8916. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8917. {
  8918. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8919. {
  8920. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8921. goto end;
  8922. }
  8923. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8924. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8925. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8926. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8927. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8928. {
  8929. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8930. goto end;
  8931. }
  8932. else
  8933. {
  8934. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8935. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8936. goto end;
  8937. }
  8938. }
  8939. }//END FOR AC_QUANTITY
  8940. }//END FOR AvailabilityTypeStr[Inoperative]
  8941. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8942. {
  8943. //----------------------gunIndex is 0 ------------------------------------------------//
  8944. if(gunIndex == 0)
  8945. {
  8946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8947. {
  8948. for(int i=0; i < gunTotalNumber; i++)
  8949. {
  8950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8951. {
  8952. 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
  8953. {
  8954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8955. goto end;
  8956. }
  8957. }//END FOR CHAdeMO_QUANTITY
  8958. for (int index = 0; index < CCS_QUANTITY; index++)
  8959. {
  8960. 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
  8961. {
  8962. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8963. goto end;
  8964. }
  8965. }//END FOR CCS_QUANTITY
  8966. for (int index = 0; index < GB_QUANTITY; index++)
  8967. {
  8968. 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
  8969. {
  8970. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8971. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8972. goto end;
  8973. }
  8974. }// END FOR GB_QUANTITY
  8975. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8976. {
  8977. 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
  8978. {
  8979. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8980. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8981. goto end;
  8982. }
  8983. }// END FOR GENERAL_GUN_QUANTITY
  8984. for (int index = 0; index < AC_QUANTITY; index++)
  8985. {
  8986. 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
  8987. {
  8988. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8989. goto end;
  8990. }
  8991. }//END FOR CHAdeMO_QUANTITY
  8992. }// END FOR gunTotalNumber
  8993. }
  8994. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8995. {
  8996. for(int i=0; i < gunTotalNumber; i++)
  8997. {
  8998. for (int index = 0; index < AC_QUANTITY; index++)
  8999. {
  9000. 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
  9001. {
  9002. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9003. goto end;
  9004. }
  9005. }//END FOR CHAdeMO_QUANTITY
  9006. } // END FOR gunTotalNumber
  9007. }
  9008. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9009. goto end;
  9010. }
  9011. //----------------------gunIndex is not 0 ------------------------------------------------//
  9012. //check Transaction active
  9013. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9014. {
  9015. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9016. {
  9017. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9018. goto end;
  9019. }
  9020. }//END FOR CHAdeMO_QUANTITY
  9021. for (int index = 0; index < CCS_QUANTITY; index++)
  9022. {
  9023. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9024. {
  9025. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9026. goto end;
  9027. }
  9028. }//END FOR CCS_QUANTITY
  9029. for (int index = 0; index < GB_QUANTITY; index++)
  9030. {
  9031. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9032. {
  9033. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9034. goto end;
  9035. }
  9036. }// END FOR GB_QUANTITY
  9037. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9038. {
  9039. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9040. {
  9041. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9042. goto end;
  9043. }
  9044. }// END FOR GENERAL_GUN_QUANTITY
  9045. for (int index = 0; index < AC_QUANTITY; index++)
  9046. {
  9047. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9048. {
  9049. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9050. goto end;
  9051. }
  9052. }//END FOR AC_QUANTITY
  9053. }//END FOR AvailabilityTypeStr[Operative]
  9054. end:
  9055. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9056. {
  9057. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9058. }
  9059. else
  9060. {
  9061. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9062. }
  9063. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9064. {
  9065. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9066. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9067. }
  9068. else if(gunIndex == 0)
  9069. {
  9070. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9071. {
  9072. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9073. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9074. }
  9075. }
  9076. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9077. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9078. return result;
  9079. }
  9080. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9081. {
  9082. mtrace();
  9083. int valueInvalid = NO;
  9084. int result = FAIL;
  9085. char keystr[40]={0};
  9086. char valuestr[501]={0}; //value should be limited in 500 bytes
  9087. char comfirmstr[20]={0};
  9088. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9089. json_object *ChangeConfiguration;
  9090. ChangeConfiguration = json_tokener_parse(payload);
  9091. if(!is_error(ChangeConfiguration))
  9092. {
  9093. // Required data
  9094. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9095. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9096. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9097. {
  9098. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9099. }
  9100. else
  9101. {
  9102. valueInvalid = YES;
  9103. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9104. }
  9105. }
  9106. json_object_put(ChangeConfiguration);
  9107. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9108. {
  9109. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9110. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9111. }
  9112. else
  9113. {
  9114. int status = setKeyValue(keystr, valuestr);
  9115. switch(status)
  9116. {
  9117. case ConfigurationStatus_Accepted:
  9118. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9119. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9120. StoreConfigurationTable();
  9121. break;
  9122. case RebootRequired:
  9123. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9124. StoreConfigurationTable();
  9125. break;
  9126. case NotSupported:
  9127. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9128. break;
  9129. case ConfigurationStatus_Rejected:
  9130. default:
  9131. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9132. break;
  9133. }
  9134. }
  9135. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9136. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9137. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9138. {
  9139. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9140. SetOcppConnStatus(FALSE);
  9141. }
  9142. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0) || (strcmp(keystr,"RfidEndianType")==0) ||
  9143. (strcmp(keystr,"Enable15118")==0) || (strcmp(keystr,"WifiSsid")==0) || (strcmp(keystr,"WifiPassword")==0) || (strcmp(keystr,"StopChargingByButton")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9144. {
  9145. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9146. }
  9147. return result;
  9148. }
  9149. int handleClearCacheRequest(char *uuid, char *payload)
  9150. {
  9151. mtrace();
  9152. int result = FAIL;
  9153. char comfirmstr[20];
  9154. char rmFileCmd[100]={0};
  9155. struct stat stats;
  9156. DEBUG_INFO("handleClearCacheRequest...\n");
  9157. stat("/Storage/OCPP", &stats);
  9158. // Check for directory existence
  9159. if (S_ISDIR(stats.st_mode) == 1)
  9160. {}
  9161. else
  9162. {
  9163. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9164. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9165. system(rmFileCmd);
  9166. }
  9167. if(OCPP_cleanLocalCache())
  9168. {
  9169. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9170. }
  9171. else
  9172. {
  9173. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9174. }
  9175. sendClearCacheConfirmation(uuid, comfirmstr);
  9176. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9177. return result;
  9178. }
  9179. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9180. {
  9181. mtrace();
  9182. int result = FAIL;
  9183. int resultRename;
  9184. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9185. char chargingProfilePurposeStr[26]={0};
  9186. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9187. char tempchargingProfilePurposeStr[26]={0};
  9188. char str[100]={0};
  9189. char fname[200]={0};
  9190. char comfirmstr[20]={0};
  9191. char word[1600]={0};
  9192. int clearflag = FALSE;
  9193. int chargingProfileIdIsNULL = FALSE;
  9194. int connectorIsNULL = FALSE;
  9195. int chargingProfilePurposeIsNULL = FALSE;
  9196. int stackLevelIsNULL = FALSE;
  9197. //int GotoEnd = FALSE;
  9198. FILE *fptr1, *fptr2;
  9199. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9200. int n_chargingProfile=0;
  9201. int isEmptyFile = FALSE;
  9202. char sLineWord[1600]={0};
  9203. char chargingProfiles[10][100]={0};
  9204. int ChargeProfileCount = 0;
  9205. int ch;
  9206. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9207. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9208. json_object *ClearChargingProfile;
  9209. ClearChargingProfile = json_tokener_parse(payload);
  9210. if(!is_error(ClearChargingProfile))
  9211. {
  9212. // Optional data
  9213. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9214. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9215. else
  9216. chargingProfileIdIsNULL = TRUE;
  9217. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9218. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9219. else
  9220. connectorIsNULL = TRUE;
  9221. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9222. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9223. else
  9224. chargingProfilePurposeIsNULL = TRUE;
  9225. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9226. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9227. else
  9228. stackLevelIsNULL = TRUE;
  9229. }
  9230. json_object_put(ClearChargingProfile);
  9231. if(connectorIdInt > 0)
  9232. {
  9233. if(chargingProfilePurposeIsNULL == TRUE)
  9234. {
  9235. int m = 0;
  9236. memset(fname, 0, ARRAY_SIZE(fname));
  9237. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9238. if((access(fname,F_OK))!=-1)
  9239. {
  9240. strcpy(chargingProfiles[m], fname);
  9241. m = m + 1;
  9242. }
  9243. memset(fname, 0, ARRAY_SIZE(fname));
  9244. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9245. if((access(fname,F_OK))!=-1)
  9246. {
  9247. strcpy(chargingProfiles[m], fname);
  9248. m = m + 1;
  9249. }
  9250. ChargeProfileCount = m;
  9251. }
  9252. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9253. {
  9254. //strcpy(fname, TxDefaultProfile_1_JSON);
  9255. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9256. if((access(fname,F_OK))!=-1)
  9257. {
  9258. strcpy(chargingProfiles[0], fname);
  9259. ChargeProfileCount = 1;
  9260. }
  9261. }
  9262. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9263. {
  9264. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9265. if((access(fname,F_OK))!=-1)
  9266. {
  9267. strcpy(chargingProfiles[0], fname);
  9268. ChargeProfileCount = 1;
  9269. }
  9270. //strcpy(fname, TxProfile_1_JSON);
  9271. }
  9272. }
  9273. else // Check all Charging Profiles
  9274. {
  9275. int i = 0;
  9276. char fnametemp[200]={0};
  9277. ChargeProfileCount = 0;
  9278. //Check ChargePointMaxProfile.json exit
  9279. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9280. {
  9281. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9282. i = i + 1;
  9283. }
  9284. //Check TxDefaultProfile_0.json exit
  9285. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9286. {
  9287. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9288. i = i + 1;
  9289. }
  9290. //Check TxDefaultProfile_%d.json
  9291. for(int j=1; j <= gunTotalNumber; j++)
  9292. {
  9293. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9294. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9295. if((access(fnametemp,F_OK))!=-1)
  9296. {
  9297. strcpy(chargingProfiles[i], fnametemp);
  9298. i = i + 1;
  9299. }
  9300. }
  9301. //Check TxProfile_%d.json
  9302. for(int j=1; j <= gunTotalNumber; j++)
  9303. {
  9304. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9305. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9306. if((access(fnametemp,F_OK))!=-1)
  9307. {
  9308. strcpy(chargingProfiles[i], fnametemp);
  9309. i = i + 1;
  9310. }
  9311. }
  9312. ChargeProfileCount = i;
  9313. }// End connectorIsNULL is TRUE
  9314. if(ChargeProfileCount == 0)
  9315. {
  9316. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9317. goto end;
  9318. }
  9319. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9320. {
  9321. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9322. goto end;
  9323. }
  9324. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9325. {
  9326. memset(str, 0, ARRAY_SIZE(str));
  9327. // clear temp file
  9328. sprintf(str,"rm -f %s",temp);
  9329. system(str);
  9330. for(int k=0; k < ChargeProfileCount; k++)
  9331. {
  9332. memset(str, 0, ARRAY_SIZE(str));
  9333. //clear file in C
  9334. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9335. system(str);
  9336. }
  9337. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9338. goto end;
  9339. }
  9340. else if(connectorIsNULL == TRUE)
  9341. {
  9342. for(int k=0; k < ChargeProfileCount; k++)
  9343. {
  9344. fptr1 = fopen(chargingProfiles[k], "r");
  9345. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9346. //Check Charging Profile Count
  9347. while(fscanf(fptr1, "%s", word) != EOF)
  9348. {
  9349. //DEBUG_INFO("word=%s\n",word);
  9350. if(strstr(word, "chargingProfileId")!= NULL)
  9351. {
  9352. //DEBUG_INFO("test chargingProfileId \n");
  9353. n_chargingProfile = n_chargingProfile + 1;
  9354. //DEBUG_INFO("chargingProfileId Found\n");
  9355. }
  9356. }
  9357. rewind(fptr1);
  9358. //search Charging Profile Element
  9359. //int i= 0;
  9360. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9361. {
  9362. json_object *tmpProfilee;
  9363. tmpProfilee = json_tokener_parse(sLineWord);
  9364. if(!is_error(tmpProfilee))
  9365. {
  9366. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9367. {
  9368. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9369. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9370. }
  9371. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9372. {
  9373. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9374. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9375. }
  9376. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9377. {
  9378. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9379. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9380. }
  9381. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9382. {
  9383. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9384. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9385. }
  9386. }
  9387. json_object_put(tmpProfilee);
  9388. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9389. {
  9390. //------- not write to fptr2-------//
  9391. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9392. //clearflag = TRUE;
  9393. }
  9394. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9395. {
  9396. //------- not write to fptr2-------//
  9397. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9398. }
  9399. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9400. {
  9401. //------- not write to fptr2-------//
  9402. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9403. }
  9404. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9405. {
  9406. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9407. }
  9408. else
  9409. {
  9410. fprintf(fptr2, sLineWord);//writing data into file
  9411. }
  9412. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9413. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9414. if(clearflag == TRUE)
  9415. {
  9416. fclose(fptr1);
  9417. fclose(fptr2);
  9418. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9419. system(str);
  9420. // clear temp file
  9421. sprintf(str,"rm -f %s",temp);
  9422. system(str);
  9423. }
  9424. else
  9425. {
  9426. fclose(fptr1);
  9427. fclose(fptr2);
  9428. memset(str, 0, ARRAY_SIZE(str));
  9429. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9430. system(str);
  9431. resultRename = rename(temp, chargingProfiles[k]);
  9432. if(resultRename == 0)
  9433. {
  9434. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9435. }
  9436. else
  9437. {
  9438. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9439. }
  9440. if(comfirmstr[0]== 0)
  9441. {
  9442. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9443. }
  9444. //Check chargingProfile is empty file
  9445. /*------ Read the file ----------------*/
  9446. fptr1=fopen(chargingProfiles[k],"r");
  9447. ch=fgetc(fptr1);
  9448. rewind(fptr1);
  9449. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9450. if(ch!=EOF)
  9451. {
  9452. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9453. {
  9454. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9455. if(sLineWord[0]=='\0')
  9456. {
  9457. isEmptyFile = TRUE;
  9458. break;
  9459. }
  9460. else
  9461. {
  9462. isEmptyFile = FALSE;
  9463. break;
  9464. }
  9465. }
  9466. }
  9467. else
  9468. isEmptyFile = TRUE;
  9469. fclose(fptr1);
  9470. if(isEmptyFile == TRUE)
  9471. {
  9472. memset(str, 0, ARRAY_SIZE(str));
  9473. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9474. system(str);
  9475. }
  9476. }
  9477. }// End of while(int k=0; k < ChargePointCount; k++)
  9478. }
  9479. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9480. {
  9481. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9482. for(int k=0; k < ChargeProfileCount; k++)
  9483. {
  9484. fptr1 = fopen(chargingProfiles[k], "r");
  9485. fptr2 = fopen(temp, "w+");
  9486. //Check Charging Profile Count
  9487. while(fscanf(fptr1, "%s", word) != EOF)
  9488. {
  9489. //DEBUG_INFO("word=%s\n",word);
  9490. if(strstr(word, "chargingProfileId")!= NULL)
  9491. {
  9492. n_chargingProfile = n_chargingProfile + 1;
  9493. }
  9494. }
  9495. rewind(fptr1);
  9496. //search Charging Profile Element
  9497. //int i= 0;
  9498. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9499. {
  9500. json_object *tmpProfilee;
  9501. tmpProfilee = json_tokener_parse(sLineWord);
  9502. if(!is_error(tmpProfilee))
  9503. {
  9504. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9505. {
  9506. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9507. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9508. }
  9509. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9510. {
  9511. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9512. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9513. }
  9514. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9515. {
  9516. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9517. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9518. }
  9519. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9520. {
  9521. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9522. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9523. }
  9524. }
  9525. json_object_put(tmpProfilee);
  9526. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9527. {
  9528. //------- not write to fptr2-------//
  9529. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9530. //clearflag = TRUE;
  9531. }
  9532. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9533. {
  9534. //------- not write to fptr2-------//
  9535. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9536. }
  9537. else if(stackLevelIsNULL == TRUE)
  9538. {
  9539. //Clear Whole File
  9540. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9541. clearflag = TRUE;
  9542. break;
  9543. }
  9544. else
  9545. {
  9546. fprintf(fptr2, sLineWord);//writing data into file
  9547. }
  9548. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9549. }
  9550. if(clearflag == TRUE)
  9551. {
  9552. fclose(fptr1);
  9553. fclose(fptr2);
  9554. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9555. system(str);
  9556. // clear temp file
  9557. sprintf(str,"rm -f %s",temp);
  9558. system(str);
  9559. }
  9560. else
  9561. {
  9562. fclose(fptr1);
  9563. fclose(fptr2);
  9564. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9565. system(str);
  9566. resultRename = rename(temp, chargingProfiles[k]);
  9567. if(resultRename == 0)
  9568. {
  9569. DEBUG_INFO("File ChargingProfile renamed successfully");
  9570. }
  9571. else
  9572. {
  9573. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9574. }
  9575. if(comfirmstr[0]== 0)
  9576. {
  9577. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9578. }
  9579. //Check chargingProfile is empty file
  9580. /*------ Read the file ----------------*/
  9581. fptr1=fopen(chargingProfiles[k],"r");
  9582. ch=fgetc(fptr1);
  9583. rewind(fptr1);
  9584. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9585. if(ch!=EOF)
  9586. {
  9587. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9588. {
  9589. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9590. if(sLineWord[0]=='\0')
  9591. {
  9592. isEmptyFile = TRUE;
  9593. break;
  9594. }
  9595. else
  9596. {
  9597. isEmptyFile = FALSE;
  9598. break;
  9599. }
  9600. }
  9601. }
  9602. else
  9603. isEmptyFile = TRUE;
  9604. fclose(fptr1);
  9605. if(isEmptyFile == TRUE)
  9606. {
  9607. memset(str, 0, ARRAY_SIZE(str));
  9608. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9609. system(str);
  9610. }
  9611. /*------- End of reading ---------------*/
  9612. }
  9613. } // while(int k=0; k < ChargeProfileCount; k++)
  9614. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9615. end:
  9616. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9617. {
  9618. if(connectorIdInt == 0)
  9619. {
  9620. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9621. {
  9622. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9623. }
  9624. }
  9625. else
  9626. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9627. }
  9628. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9629. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9630. return result;
  9631. }
  9632. void createFirmwareVersionByDataTransfer(void)
  9633. {
  9634. json_object *FirmwareDataTransfer = json_object_new_object();
  9635. // AC & DC model
  9636. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9637. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9638. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9639. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9640. // DC model
  9641. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9642. {
  9643. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9644. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9645. (gunType[3] != GUN_TYPE_UNKNOWN))
  9646. {
  9647. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9648. }
  9649. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='L') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='Z'))
  9650. {
  9651. // DS DM DW
  9652. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9653. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9654. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9655. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9656. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9657. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9658. }
  9659. else
  9660. {
  9661. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9662. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9663. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9664. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9665. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9666. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9667. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9668. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9669. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9670. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9671. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9672. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9673. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9674. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9675. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9676. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9677. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9678. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9679. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9680. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9681. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9682. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9683. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9684. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9685. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9686. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9687. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9688. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9689. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9690. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9691. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9692. }
  9693. }
  9694. // 4G model
  9695. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9696. {
  9697. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9698. }
  9699. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9700. json_object_put(FirmwareDataTransfer);
  9701. }
  9702. int handleDataTransferRequest(char *uuid, char *payload)
  9703. {
  9704. mtrace();
  9705. json_object *response = json_object_new_object();
  9706. int result = FAIL;
  9707. char tempvendorId[255]={0};
  9708. char tempmessageId[50]={0};
  9709. char tempdata[10240]={0};
  9710. char message[20480]={0};
  9711. DEBUG_INFO("handleDataTransferRequest...\n");
  9712. if((uuid != NULL) && (payload != NULL))
  9713. {
  9714. json_object *DataTransfer;
  9715. DataTransfer = json_tokener_parse(payload);
  9716. if(!is_error(DataTransfer))
  9717. {
  9718. // Required data
  9719. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9720. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9721. // Optional data
  9722. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9723. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9724. if(json_object_object_get(DataTransfer, "data") != NULL)
  9725. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9726. result = PASS;
  9727. }
  9728. json_object_put(DataTransfer);
  9729. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9730. {
  9731. // Send all moudle firmware version on EVSE
  9732. createFirmwareVersionByDataTransfer();
  9733. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9734. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9735. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9736. json_object_put(response);
  9737. }
  9738. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9739. {
  9740. system("/usr/bin/run_tmate_restart.sh &");
  9741. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9742. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9743. json_object_put(response);
  9744. }
  9745. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9746. {
  9747. json_object *data;
  9748. data = json_tokener_parse(tempdata);
  9749. if(!is_error(data))
  9750. {
  9751. 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))
  9752. {
  9753. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9754. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9755. if(json_object_object_get(data, "SOC") != NULL)
  9756. {
  9757. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9758. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9759. }
  9760. if(json_object_object_get(data, "Energy") != NULL)
  9761. {
  9762. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9763. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9764. }
  9765. if(json_object_object_get(data, "Duration") != NULL)
  9766. {
  9767. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9768. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9769. }
  9770. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9771. }
  9772. else
  9773. {
  9774. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9775. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9776. }
  9777. }
  9778. else
  9779. {
  9780. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9781. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9782. }
  9783. json_object_put(data);
  9784. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9785. json_object_put(response);
  9786. }
  9787. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9788. {
  9789. json_object *data;
  9790. data = json_tokener_parse(tempdata);
  9791. if(!is_error(data))
  9792. {
  9793. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9794. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9795. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9796. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9797. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9798. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9799. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9800. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9801. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9802. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9803. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9804. }
  9805. else
  9806. {
  9807. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9808. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9809. }
  9810. json_object_put(data);
  9811. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9812. json_object_put(response);
  9813. }
  9814. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9815. {
  9816. json_object *data;
  9817. data = json_tokener_parse(tempdata);
  9818. if(!is_error(data))
  9819. {
  9820. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9821. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9822. if(json_object_object_get(data, "idToken") != NULL)
  9823. {
  9824. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9825. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9826. }
  9827. else
  9828. {
  9829. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9830. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9831. }
  9832. if(json_object_object_get(data, "price") != NULL) //v1.0
  9833. {
  9834. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9835. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9836. }
  9837. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9838. {
  9839. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9840. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9841. }
  9842. else
  9843. {
  9844. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9845. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9846. }
  9847. }
  9848. else
  9849. {
  9850. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9851. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9852. }
  9853. json_object_put(data);
  9854. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9855. json_object_put(response);
  9856. }
  9857. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9858. {
  9859. json_object *data;
  9860. data = json_tokener_parse(tempdata);
  9861. if(!is_error(data))
  9862. {
  9863. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9864. if(json_object_object_get(data, "txId") != NULL)
  9865. {
  9866. // California pricing V1.0
  9867. DEBUG_INFO("California pricing V1.0\n");
  9868. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9869. sprintf((char*)dmsVersion, "1.0");
  9870. for(int idx = 0;idx<gunTotalNumber;idx++)
  9871. {
  9872. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9873. {
  9874. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9875. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9876. if(json_object_object_get(data, "description") != NULL)
  9877. {
  9878. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9879. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9880. }
  9881. else
  9882. {
  9883. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9884. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9885. }
  9886. }
  9887. }
  9888. }
  9889. else if(json_object_object_get(data, "transactionId") != NULL)
  9890. {
  9891. // California pricing V2.0
  9892. DEBUG_INFO("California pricing V2.0\n");
  9893. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9894. sprintf((char*)dmsVersion, "2.0");
  9895. for(int idx=0;idx<gunTotalNumber;idx++)
  9896. {
  9897. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9898. {
  9899. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9900. if(json_object_object_get(data, "timestamp") != NULL)
  9901. {
  9902. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9903. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9904. }
  9905. else
  9906. {
  9907. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9908. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9909. }
  9910. if(json_object_object_get(data, "meterValue") != NULL)
  9911. {
  9912. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9913. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9914. }
  9915. else
  9916. {
  9917. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9918. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9919. }
  9920. if(json_object_object_get(data, "cost") != NULL)
  9921. {
  9922. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9923. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9924. }
  9925. else
  9926. {
  9927. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9928. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9929. }
  9930. if(json_object_object_get(data, "state") != NULL)
  9931. {
  9932. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9933. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9934. }
  9935. else
  9936. {
  9937. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9938. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9939. }
  9940. if(json_object_object_get(data, "chargingPrice") != NULL)
  9941. {
  9942. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9943. {
  9944. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9945. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9946. }
  9947. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9948. {
  9949. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9950. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9951. }
  9952. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9953. {
  9954. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9955. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9956. }
  9957. }
  9958. else
  9959. {
  9960. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9961. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9962. }
  9963. if(json_object_object_get(data, "idlePrice") != NULL)
  9964. {
  9965. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9966. {
  9967. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9968. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9969. }
  9970. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9971. {
  9972. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9973. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9974. }
  9975. }
  9976. if(json_object_object_get(data, "nextPeriod") != NULL)
  9977. {
  9978. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9979. {
  9980. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9981. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9982. }
  9983. else
  9984. {
  9985. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9986. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9987. }
  9988. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9989. {
  9990. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9991. {
  9992. 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")));
  9993. 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"));
  9994. }
  9995. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9996. {
  9997. 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")));
  9998. 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"));
  9999. }
  10000. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  10001. {
  10002. 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")));
  10003. 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"));
  10004. }
  10005. }
  10006. else
  10007. {
  10008. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10009. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10010. }
  10011. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10012. {
  10013. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10014. {
  10015. 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")));
  10016. 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"));
  10017. }
  10018. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10019. {
  10020. 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")));
  10021. 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"));
  10022. }
  10023. }
  10024. }
  10025. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10026. {
  10027. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10028. {
  10029. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10030. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10031. }
  10032. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10033. {
  10034. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10035. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10036. }
  10037. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10038. {
  10039. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10040. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10041. }
  10042. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10043. {
  10044. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10045. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10046. }
  10047. }
  10048. }
  10049. }
  10050. }
  10051. else
  10052. {
  10053. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10054. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10055. }
  10056. }
  10057. else
  10058. {
  10059. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10060. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10061. }
  10062. json_object_put(data);
  10063. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10064. json_object_put(response);
  10065. }
  10066. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10067. {
  10068. json_object *data;
  10069. data = json_tokener_parse(tempdata);
  10070. if(!is_error(data))
  10071. {
  10072. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10073. if(json_object_object_get(data, "txId") != NULL)
  10074. {
  10075. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10076. for(int idx = 0;idx<gunTotalNumber;idx++)
  10077. {
  10078. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10079. {
  10080. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10081. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10082. if(json_object_object_get(data, "description") != NULL)
  10083. {
  10084. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10085. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10086. }
  10087. else
  10088. {
  10089. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10090. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10091. }
  10092. }
  10093. }
  10094. }
  10095. else if(json_object_object_get(data, "transactionId") != NULL)
  10096. {
  10097. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10098. for(int idx = 0;idx<gunTotalNumber;idx++)
  10099. {
  10100. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10101. {
  10102. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10103. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10104. if(json_object_object_get(data, "cost") != NULL)
  10105. {
  10106. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10107. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10108. }
  10109. else
  10110. {
  10111. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10112. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10113. }
  10114. if(json_object_object_get(data, "priceText") != NULL)
  10115. {
  10116. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10117. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10118. }
  10119. else
  10120. {
  10121. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10122. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10123. }
  10124. if(json_object_object_get(data, "qrCodeText") != NULL)
  10125. {
  10126. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10127. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10128. }
  10129. }
  10130. }
  10131. }
  10132. else
  10133. {
  10134. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10135. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10136. }
  10137. }
  10138. else
  10139. {
  10140. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10141. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10142. }
  10143. json_object_put(data);
  10144. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10145. json_object_put(response);
  10146. }
  10147. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10148. {
  10149. json_object *data;
  10150. data = json_tokener_parse(tempdata);
  10151. if(!is_error(data))
  10152. {
  10153. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10154. if(json_object_object_get(data, "Content_Type") != NULL)
  10155. {
  10156. 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))
  10157. {
  10158. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10159. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10160. {
  10161. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10162. }
  10163. }
  10164. else
  10165. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10166. }
  10167. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10168. }
  10169. else
  10170. {
  10171. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10172. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10173. }
  10174. json_object_put(data);
  10175. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10176. json_object_put(response);
  10177. }
  10178. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10179. {
  10180. json_object *data;
  10181. data = json_tokener_parse(tempdata);
  10182. if(!is_error(data))
  10183. {
  10184. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10185. if(json_object_object_get(data, "ConnectorId") != NULL)
  10186. {
  10187. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10188. }
  10189. if(json_object_object_get(data, "SerialNo") != NULL)
  10190. {
  10191. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10192. }
  10193. if(json_object_object_get(data, "Page_Index") != NULL)
  10194. {
  10195. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10196. }
  10197. if(json_object_object_get(data, "Duration") != NULL)
  10198. {
  10199. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10200. }
  10201. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10202. }
  10203. else
  10204. {
  10205. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10206. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10207. }
  10208. json_object_put(data);
  10209. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10210. json_object_put(response);
  10211. }
  10212. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10213. {
  10214. json_object *data;
  10215. data = json_tokener_parse(tempdata);
  10216. if(!is_error(data))
  10217. {
  10218. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10219. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10220. {
  10221. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10222. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10223. else
  10224. {
  10225. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10226. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10227. }
  10228. }
  10229. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10230. {
  10231. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10232. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10233. else
  10234. {
  10235. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10236. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10237. }
  10238. }
  10239. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10240. {
  10241. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10242. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10243. else
  10244. {
  10245. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10246. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10247. }
  10248. }
  10249. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10250. {
  10251. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10252. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10253. else
  10254. {
  10255. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10256. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10257. }
  10258. }
  10259. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10260. {
  10261. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10262. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10263. else
  10264. {
  10265. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10266. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10267. }
  10268. }
  10269. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10270. {
  10271. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10272. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10273. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10274. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10275. else
  10276. {
  10277. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10278. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10279. }
  10280. }
  10281. if(json_object_object_get(data, "isAuthentication") != NULL)
  10282. {
  10283. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10284. {
  10285. case 0:
  10286. case 1:
  10287. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10288. break;
  10289. default:
  10290. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10291. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10292. break;
  10293. }
  10294. }
  10295. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10296. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10297. }
  10298. else
  10299. {
  10300. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10301. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10302. }
  10303. json_object_put(data);
  10304. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10305. json_object_put(response);
  10306. }
  10307. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10308. {
  10309. json_object *data;
  10310. data = json_tokener_parse(tempdata);
  10311. if(!is_error(data))
  10312. {
  10313. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10314. {
  10315. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10316. {
  10317. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10318. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10319. }
  10320. else
  10321. {
  10322. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10323. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10324. }
  10325. }
  10326. else
  10327. {
  10328. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10329. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10330. }
  10331. }
  10332. else
  10333. {
  10334. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10335. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10336. }
  10337. json_object_put(data);
  10338. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10339. json_object_put(response);
  10340. }
  10341. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10342. {
  10343. json_object *data;
  10344. data = json_tokener_parse(tempdata);
  10345. if(!is_error(data))
  10346. {
  10347. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10348. if(json_object_object_get(data, "stationName") != NULL)
  10349. {
  10350. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10351. }
  10352. else
  10353. {
  10354. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10355. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10356. }
  10357. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10358. {
  10359. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10360. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10361. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10362. }
  10363. }
  10364. else
  10365. {
  10366. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10367. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10368. }
  10369. json_object_put(data);
  10370. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10371. json_object_put(response);
  10372. }
  10373. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10374. {
  10375. json_object *data;
  10376. data = json_tokener_parse(tempdata);
  10377. if(!is_error(data))
  10378. {
  10379. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10380. if(json_object_object_get(data, "weatherId") != NULL)
  10381. {
  10382. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10383. }
  10384. else
  10385. {
  10386. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10387. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10388. }
  10389. if(json_object_object_get(data, "Temperature") != NULL)
  10390. {
  10391. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10392. }
  10393. else
  10394. {
  10395. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10396. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10397. }
  10398. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10399. {
  10400. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10401. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10402. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10403. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10404. );
  10405. }
  10406. }
  10407. else
  10408. {
  10409. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10410. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10411. }
  10412. json_object_put(data);
  10413. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10414. json_object_put(response);
  10415. }
  10416. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10417. {
  10418. json_object *data;
  10419. data = json_tokener_parse(tempdata);
  10420. if(!is_error(data))
  10421. {
  10422. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10423. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10424. {
  10425. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10426. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10427. }
  10428. else
  10429. {
  10430. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10431. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10432. }
  10433. }
  10434. else
  10435. {
  10436. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10437. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10438. }
  10439. json_object_put(data);
  10440. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10441. json_object_put(response);
  10442. }
  10443. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10444. {
  10445. json_object *data;
  10446. data = json_tokener_parse(tempdata);
  10447. if(!is_error(data))
  10448. {
  10449. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10450. {
  10451. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10452. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10453. if(gun_index < gunTotalNumber)
  10454. {
  10455. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10456. {
  10457. json_object *responsedata = json_object_new_object();
  10458. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10459. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10460. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10461. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10462. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10463. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10464. }
  10465. else
  10466. {
  10467. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10468. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10469. }
  10470. }
  10471. else
  10472. {
  10473. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10474. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10475. }
  10476. }
  10477. else
  10478. {
  10479. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10480. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10481. }
  10482. }
  10483. else
  10484. {
  10485. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10486. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10487. }
  10488. json_object_put(data);
  10489. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10490. json_object_put(response);
  10491. }
  10492. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10493. {
  10494. json_object *data;
  10495. data = json_tokener_parse(tempdata);
  10496. if(!is_error(data))
  10497. {
  10498. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10499. int gun_index = 0;
  10500. if(json_object_object_get(data, "ConnectorId") != NULL)
  10501. {
  10502. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10503. if(json_object_object_get(data, "occupancySN") != NULL)
  10504. {
  10505. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10506. }
  10507. else
  10508. {
  10509. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10510. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10511. }
  10512. if(json_object_object_get(data, "actionId") != NULL)
  10513. {
  10514. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10515. }
  10516. else
  10517. {
  10518. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10519. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10520. }
  10521. }
  10522. else
  10523. {
  10524. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10525. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10526. }
  10527. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10528. {
  10529. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10530. }
  10531. }
  10532. else
  10533. {
  10534. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10535. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10536. }
  10537. json_object_put(data);
  10538. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10539. json_object_put(response);
  10540. }
  10541. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10542. {
  10543. json_object *data;
  10544. data = json_tokener_parse(tempdata);
  10545. if(!is_error(data))
  10546. {
  10547. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10548. if(json_object_object_get(data, "price") != NULL)
  10549. {
  10550. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10551. }
  10552. else
  10553. {
  10554. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10555. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10556. }
  10557. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10558. {
  10559. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10560. }
  10561. }
  10562. else
  10563. {
  10564. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10565. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  10566. }
  10567. json_object_put(data);
  10568. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10569. json_object_put(response);
  10570. }
  10571. // Support ISO-15118 related message
  10572. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10573. {
  10574. char cmdBuf[1024]={0};
  10575. 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);
  10576. system(cmdBuf);
  10577. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10578. json_object *responsedata = json_object_new_object();
  10579. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10580. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10581. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10582. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10583. json_object_put(response);
  10584. }
  10585. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10586. {
  10587. json_object *data;
  10588. data = json_tokener_parse(tempdata);
  10589. if(!is_error(data))
  10590. {
  10591. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10592. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10593. fclose(fp);
  10594. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10595. json_object *responsedata = json_object_new_object();
  10596. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10597. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10598. else
  10599. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10600. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10601. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10602. }
  10603. else
  10604. {
  10605. json_object *responsedata = json_object_new_object();
  10606. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10607. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10608. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10609. }
  10610. json_object_put(data);
  10611. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10612. json_object_put(response);
  10613. }
  10614. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10615. {
  10616. json_object *data;
  10617. data = json_tokener_parse(tempdata);
  10618. DEBUG_INFO("DeleteCertificate processing...\n");
  10619. if(!is_error(data))
  10620. {
  10621. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10622. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10623. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10624. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10625. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10626. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10627. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10628. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10629. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10630. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10631. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10632. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10633. char temp[256] = {0};
  10634. char compareData[256] = {0};
  10635. int isMatch = TRUE;
  10636. // Check certV2G
  10637. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10638. {
  10639. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10640. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10641. isMatch = FALSE;
  10642. if(isMatch == TRUE)
  10643. {
  10644. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10645. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10646. isMatch = FALSE;
  10647. }
  10648. if(isMatch == TRUE)
  10649. {
  10650. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10651. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10652. isMatch = FALSE;
  10653. }
  10654. if(isMatch == TRUE)
  10655. {
  10656. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10657. system(temp);
  10658. json_object *responsedata = json_object_new_object();
  10659. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10660. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10661. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10662. }
  10663. else
  10664. {
  10665. json_object *responsedata = json_object_new_object();
  10666. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10667. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10668. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10669. }
  10670. }
  10671. else
  10672. {
  10673. json_object *responsedata = json_object_new_object();
  10674. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10675. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10676. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10677. }
  10678. }
  10679. else
  10680. {
  10681. json_object *responsedata = json_object_new_object();
  10682. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10683. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10684. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10685. }
  10686. json_object_put(data);
  10687. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10688. json_object_put(response);
  10689. }
  10690. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10691. {
  10692. json_object *data;
  10693. data = json_tokener_parse(tempdata);
  10694. if(!is_error(data))
  10695. {
  10696. /*
  10697. * TODO:
  10698. * 1. Query certificate to response
  10699. */
  10700. json_object *responsedata = json_object_new_object();
  10701. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10702. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10703. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10704. }
  10705. else
  10706. {
  10707. json_object *responsedata = json_object_new_object();
  10708. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10709. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10710. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10711. }
  10712. json_object_put(data);
  10713. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10714. json_object_put(response);
  10715. }
  10716. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10717. {
  10718. json_object *data;
  10719. data = json_tokener_parse(tempdata);
  10720. if(!is_error(data))
  10721. {
  10722. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10723. if(json_object_object_get(data, "certificateType") != NULL)
  10724. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10725. if(json_object_object_get(data, "certificate") != NULL)
  10726. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10727. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10728. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10729. char temp[1024];
  10730. FILE *fp = fopen(tempCert, "w");
  10731. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10732. fclose(fp);
  10733. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10734. char strExpDate[30];
  10735. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10736. fp = popen(temp, "r");
  10737. if(fp)
  10738. {
  10739. while(fgets(temp, sizeof(temp), fp) != NULL)
  10740. {
  10741. if(strstr(temp, "notAfter=") != NULL)
  10742. {
  10743. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10744. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10745. break;
  10746. }
  10747. }
  10748. }
  10749. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10750. struct tm tmExpDate;
  10751. struct timeb tbExpDate;
  10752. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10753. tbExpDate.time = mktime(&tmExpDate);
  10754. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10755. {
  10756. DEBUG_INFO("The enddate is already expired...\n");
  10757. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10758. }
  10759. else
  10760. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10761. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10762. {
  10763. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10764. {
  10765. if(access(ROOTCA_V2G,F_OK) != -1)
  10766. {
  10767. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10768. rename(ROOTCA_V2G, "/Storage/rootCaV2g_fallback.pem");
  10769. rename(tempCert, ROOTCA_V2G);
  10770. }
  10771. else
  10772. {
  10773. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10774. rename(tempCert, ROOTCA_V2G);
  10775. }
  10776. json_object *responsedata = json_object_new_object();
  10777. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10778. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10779. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10780. }
  10781. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10782. {
  10783. if(access(ROOTCA_MO,F_OK) != -1)
  10784. {
  10785. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10786. rename(ROOTCA_MO, "/Storage/rootCaMo_fallback.pem");
  10787. rename(tempCert, ROOTCA_MO);
  10788. }
  10789. else
  10790. {
  10791. DEBUG_INFO("No existed MORootCertificate. Creating...\n");
  10792. rename(tempCert, ROOTCA_MO);
  10793. }
  10794. json_object *responsedata = json_object_new_object();
  10795. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10796. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10797. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10798. }
  10799. else
  10800. {
  10801. json_object *responsedata = json_object_new_object();
  10802. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10803. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10804. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10805. }
  10806. }
  10807. else
  10808. {
  10809. json_object *responsedata = json_object_new_object();
  10810. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10811. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10812. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10813. }
  10814. }
  10815. else
  10816. {
  10817. json_object *responsedata = json_object_new_object();
  10818. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10819. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10820. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10821. }
  10822. json_object_put(data);
  10823. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10824. json_object_put(response);
  10825. }
  10826. else
  10827. {
  10828. // Can not find valid message id
  10829. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10830. }
  10831. }
  10832. else
  10833. {
  10834. // Payload is null
  10835. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10836. }
  10837. LWS_Send(message);
  10838. return result;
  10839. }
  10840. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10841. {
  10842. mtrace();
  10843. int result = FAIL;
  10844. int connectorIdInt, durationInt;
  10845. char chargingRateUnitStr[4]={0};
  10846. char comfirmstr[20];
  10847. int confirmPeriods = 0;
  10848. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10849. json_object *GetCompositeSchedule;
  10850. GetCompositeSchedule = json_tokener_parse(payload);
  10851. if(!is_error(GetCompositeSchedule))
  10852. {
  10853. // Required data
  10854. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10855. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10856. else
  10857. connectorIdInt = -1;
  10858. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10859. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10860. else
  10861. durationInt = 86400;
  10862. // Optional data
  10863. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10864. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10865. }
  10866. json_object_put(GetCompositeSchedule);
  10867. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10868. if((connectorIdInt == 0) ||
  10869. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10870. {
  10871. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10872. struct StructChargingProfile tmpProfile[1];
  10873. if(strstr(chargingRateUnitStr, "W") != NULL)
  10874. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10875. else
  10876. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10877. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10878. {
  10879. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10880. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10881. }
  10882. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10883. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10884. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10885. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10886. {
  10887. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10888. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10889. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10890. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10891. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10892. {
  10893. confirmPeriods = idx;
  10894. break;
  10895. }
  10896. }
  10897. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10898. {
  10899. confirmPeriods += 1;
  10900. }
  10901. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10902. }
  10903. else
  10904. {
  10905. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10906. }
  10907. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10908. return result;
  10909. }
  10910. int handleGetConfigurationRequest(char *uuid, char *payload)
  10911. {
  10912. mtrace();
  10913. int result = FAIL;
  10914. int MaxKeySupported = 0;
  10915. int n_keys = 0;
  10916. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10917. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10918. json_object *GetConfiguration;
  10919. GetConfiguration = json_tokener_parse(payload);
  10920. if(!is_error(GetConfiguration))
  10921. {
  10922. // Optional data
  10923. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10924. {
  10925. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10926. {
  10927. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10928. n_keys = idx + 1;
  10929. }
  10930. }
  10931. }
  10932. json_object_put(GetConfiguration);
  10933. UnknownKeynum = 0;
  10934. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10935. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10936. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10937. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10938. if(n_keys != 0)
  10939. {
  10940. for(int i=0;i<n_keys;i++)
  10941. {
  10942. getKeyValue(requestKey[i]);
  10943. }
  10944. }
  10945. else
  10946. {
  10947. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10948. getKeyValue("");
  10949. }
  10950. processUnkownKey();
  10951. sendGetConfigurationConfirmation(uuid);
  10952. return result;
  10953. }
  10954. static char fnamePlusPath[100]={0};
  10955. static char fnamePWithNoPath[60]={0};
  10956. void checkUploadLog(void)
  10957. {
  10958. FILE *fp;
  10959. /* Open the command for reading. */
  10960. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10961. if (fp == NULL) {
  10962. DEBUG_WARN("Failed to run command\n" );
  10963. exit(1);
  10964. }
  10965. int ftppathlen = 0;
  10966. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10967. int i = 0;
  10968. /* Read the output a line at a time - output it. */
  10969. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10970. if(i==0)
  10971. {
  10972. ftppathlen = strlen(fnamePlusPath);
  10973. DEBUG_INFO("%s\n", fnamePlusPath);
  10974. fnamePlusPath[ftppathlen]='\0';
  10975. break;
  10976. }
  10977. i= i+1;
  10978. }
  10979. /* close */
  10980. pclose(fp);
  10981. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10982. {
  10983. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10984. {
  10985. fnamePlusPath[k]='\0';
  10986. }
  10987. }
  10988. i=1;
  10989. //char fname[60]={0};
  10990. while(i < ftppathlen)
  10991. {
  10992. int len=ftppathlen-i;
  10993. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10994. {
  10995. DEBUG_INFO("compare '/' all right\n");
  10996. break;
  10997. }
  10998. i=i+1;
  10999. }
  11000. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11001. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11002. fnamePWithNoPath[i+1] = '\0';
  11003. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11004. {
  11005. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11006. {
  11007. fnamePWithNoPath[j]='\0';
  11008. }
  11009. }
  11010. FILE* fp1 = fopen(fnamePlusPath, "r");
  11011. if (fp1)
  11012. {
  11013. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11014. // file exists
  11015. fclose(fp1);
  11016. }
  11017. else
  11018. {
  11019. // file doesn't exist
  11020. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11021. }
  11022. }
  11023. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11024. {
  11025. mtrace();
  11026. int result = FAIL;
  11027. time_t CurrentTime;
  11028. struct tm *tm;
  11029. pthread_t th_Status;
  11030. CurrentTime = time(NULL);
  11031. tm = localtime(&CurrentTime);
  11032. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11033. 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);
  11034. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11035. if(!interLock.isGetDiagnosticGoing)
  11036. {
  11037. interLock.isGetDiagnosticGoing = 1;
  11038. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11039. sleep(1);
  11040. }
  11041. else
  11042. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11043. return result;
  11044. }
  11045. void* GetDiagnosticsProcess(void* data)
  11046. {
  11047. pthread_detach(pthread_self());
  11048. mtrace();
  11049. int retriesInt=0, retryIntervalInt=0;
  11050. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11051. 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};
  11052. int port=0;
  11053. int isSuccess = FALSE;
  11054. char cmdBuf[2048];
  11055. struct tm *tmNow;
  11056. time_t CurrentTime;
  11057. struct tm tmStart;
  11058. struct tm tmStop;
  11059. CurrentTime = time(NULL);
  11060. tmNow=localtime(&CurrentTime);
  11061. uint16_t targetYear, targetMonth;
  11062. json_object *GetDiagnostics;
  11063. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11064. GetDiagnostics = json_tokener_parse(data);
  11065. if(!is_error(GetDiagnostics))
  11066. {
  11067. // Required data
  11068. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11069. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11070. // Optional data
  11071. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11072. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11073. else
  11074. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11075. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11076. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11077. else
  11078. retryIntervalInt = 30;
  11079. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11080. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11081. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11082. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11083. }
  11084. json_object_put(GetDiagnostics);
  11085. // Notify CSU to get log of dispensers.
  11086. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  11087. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  11088. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  11089. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  11090. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  11091. )
  11092. {
  11093. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StartTime,"%s",startTimestr);
  11094. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StopTime,"%s",stopTimestr);
  11095. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = TRUE;
  11096. struct timespec timerGetDiagnostics;
  11097. refreshStartTimer(&timerGetDiagnostics);
  11098. while(ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq != FALSE)
  11099. {
  11100. if(getDiffSecNow(timerGetDiagnostics)>=180)
  11101. {
  11102. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = FALSE;
  11103. DEBUG_INFO("Waiting log of dispenser timeout.");
  11104. }
  11105. }
  11106. }
  11107. // Pack log to compress file
  11108. 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) &&
  11109. (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))
  11110. {
  11111. // Pack system log
  11112. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11113. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11114. targetYear = tmStart.tm_year;
  11115. targetMonth = tmStart.tm_mon;
  11116. do
  11117. {
  11118. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11119. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11120. if(targetMonth+1>=13)
  11121. {
  11122. targetYear += 1;
  11123. targetMonth = 1;
  11124. }
  11125. else
  11126. {
  11127. targetMonth += 1;
  11128. }
  11129. }while((targetYear < (tmNow->tm_year+1900)) ||
  11130. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11131. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11132. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11133. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  11134. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  11135. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  11136. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  11137. system(cmdBuf);
  11138. // Pack charging & event log
  11139. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11140. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11141. targetYear = tmStart.tm_year;
  11142. targetMonth = tmStart.tm_mon;
  11143. do
  11144. {
  11145. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11146. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  11147. if(targetMonth+1>=13)
  11148. {
  11149. targetYear += 1;
  11150. targetMonth = 1;
  11151. }
  11152. else
  11153. {
  11154. targetMonth += 1;
  11155. }
  11156. }while((targetYear < (tmNow->tm_year+1900)) ||
  11157. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11158. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11159. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11160. system(cmdBuf);
  11161. // Combine log file
  11162. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11163. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11164. }
  11165. else
  11166. {
  11167. system("exec /root/logPackTools 'log' 6");
  11168. }
  11169. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11170. system(cmdBuf);
  11171. checkUploadLog();
  11172. //****************location*******************/
  11173. if(strcmp(locationstr,"")==0)
  11174. {
  11175. DEBUG_INFO("location is <Empty>!\n");
  11176. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11177. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11178. goto end;
  11179. }
  11180. memset(protocol, 0, ARRAY_SIZE(protocol));
  11181. memset(user, 0, ARRAY_SIZE(user) );
  11182. memset(password, 0, ARRAY_SIZE(password));
  11183. memset(host, 0, ARRAY_SIZE(host));
  11184. memset(path, 0, ARRAY_SIZE(path));
  11185. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11186. memset(host1, 0, ARRAY_SIZE(host1));
  11187. memset(path1, 0, ARRAY_SIZE(path1));
  11188. /*location: ftp://user:password@host:port/path*/
  11189. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11190. if((access(fnamePlusPath,F_OK))!=-1)
  11191. {
  11192. DEBUG_INFO("fnamePlusPath exist.\n");
  11193. }
  11194. else
  11195. {
  11196. DEBUG_INFO("fnamePlusPath not exist!\n");
  11197. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11198. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11199. goto end;
  11200. }
  11201. if(strchr(locationstr,'@')==NULL)
  11202. {
  11203. sscanf(locationstr,
  11204. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11205. protocol, host, &port, path);
  11206. strcpy(user,"anonymous");
  11207. strcpy(password,"");
  11208. }
  11209. else
  11210. {
  11211. //DEBUG_INFO("pch=%s\n", pch);
  11212. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11213. protocol, user, password, host, &port, path);
  11214. }
  11215. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"sftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11216. {
  11217. DEBUG_INFO("protocol is not ftp/http ! \n");
  11218. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11219. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11220. goto end;
  11221. }
  11222. if(strncmp(locationstr,"http", 4) == 0)
  11223. {
  11224. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11225. sprintf(ftppath,"/%s", path);
  11226. do
  11227. {
  11228. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11229. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11230. sleep(3);
  11231. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11232. if(!isSuccess)
  11233. {
  11234. DEBUG_INFO("Diagnostics fail.\n");
  11235. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11236. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11237. sleep(retryIntervalInt);
  11238. }
  11239. else
  11240. {
  11241. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11242. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11243. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11244. }
  11245. retriesInt--;
  11246. }while((isSuccess == 0)&&(retriesInt >= 0));
  11247. }
  11248. else
  11249. {
  11250. sscanf(host,"%[^/]%s",host1, path1);
  11251. if(strlen(path) > 0)
  11252. sprintf(ftppath,"/%s", path);
  11253. else
  11254. sprintf(ftppath,"/%s", path1);
  11255. int ftppathlen=strlen(ftppath);
  11256. int i=1;
  11257. char filenametemp[50];
  11258. while(i < ftppathlen)
  11259. {
  11260. int len=ftppathlen-i;
  11261. if(ftppath[len]== 47) // '/' ascll code: 47
  11262. {
  11263. DEBUG_INFO("find '/' all right\n");
  11264. break;
  11265. }
  11266. i=i+1;
  11267. }
  11268. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11269. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11270. filenametemp[i+1] = 0;
  11271. if(port == 0)
  11272. port = 21;
  11273. do
  11274. {
  11275. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11276. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11277. sleep(3);
  11278. if(strncmp(locationstr,"sftp", 4) == 0)
  11279. isSuccess = sftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11280. else
  11281. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11282. if(!isSuccess)
  11283. {
  11284. DEBUG_INFO("Diagnostics fail.\n");
  11285. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11286. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11287. sleep(retryIntervalInt);
  11288. }
  11289. else
  11290. {
  11291. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11292. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11293. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11294. }
  11295. retriesInt--;
  11296. }while((!isSuccess)&&(retriesInt >= 0));
  11297. }
  11298. end:
  11299. system("rm -f /mnt/*");
  11300. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  11301. sleep(5);
  11302. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11303. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11304. interLock.isGetDiagnosticGoing = 0;
  11305. pthread_exit(NULL);
  11306. }
  11307. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11308. {
  11309. mtrace();
  11310. int result = FAIL;
  11311. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11312. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11313. {
  11314. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11315. locallistVersion = -1;
  11316. }
  11317. else
  11318. {
  11319. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11320. locallistVersion = 0;
  11321. OCPP_getListVerion();
  11322. }
  11323. //from db.OCPP_getListVerion
  11324. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11325. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11326. sendGetLocalListVersionConfirmation(uuid,"");
  11327. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11328. return result;
  11329. }
  11330. int handleRemoteStartRequest(char *uuid, char *payload)
  11331. {
  11332. mtrace();
  11333. int result = PASS;
  11334. int connectorIdInt=-1;
  11335. int tempIndex = 0;
  11336. char comfirmstr[20]={0};
  11337. char cmdBuf[512];
  11338. json_object *RemoteStartTransaction;
  11339. FILE *fp;
  11340. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11341. if(server_pending == TRUE)
  11342. {
  11343. result = FAIL;
  11344. }
  11345. RemoteStartTransaction = json_tokener_parse(payload);
  11346. if(!is_error(RemoteStartTransaction))
  11347. {
  11348. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11349. {
  11350. if(json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId")) > 0)
  11351. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11352. else
  11353. connectorIdInt = 0;
  11354. }
  11355. else
  11356. {
  11357. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11358. {
  11359. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11360. {
  11361. connectorIdInt = (gun_index+1);
  11362. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11363. break;
  11364. }
  11365. }
  11366. }
  11367. if(connectorIdInt == 0)
  11368. {
  11369. DEBUG_WARN("Connector id shall not equal to 0 or less than 0.\n");
  11370. result = FAIL;
  11371. }
  11372. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11373. {
  11374. DEBUG_WARN("idTag should not be NULL.\n");
  11375. result = FAIL;
  11376. }
  11377. else if(connectorIdInt == -1)
  11378. {
  11379. DEBUG_INFO("Connector id does not specific.\n");
  11380. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11381. {
  11382. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11383. // Required data
  11384. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11385. // Optional data
  11386. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11387. {
  11388. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11389. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11390. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11391. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11392. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11393. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11394. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11395. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11396. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11397. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11398. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11399. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11400. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11401. {
  11402. 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")));
  11403. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11404. 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"));
  11405. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11406. 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"));
  11407. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11408. 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")));
  11409. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11410. {
  11411. 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++)
  11412. {
  11413. 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"));
  11414. 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"));
  11415. 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)
  11416. 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"));
  11417. }
  11418. }
  11419. }
  11420. }
  11421. else
  11422. {
  11423. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11424. }
  11425. }
  11426. }
  11427. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11428. {
  11429. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11430. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11431. // Required data
  11432. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11433. // Optional data
  11434. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11435. {
  11436. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11437. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11438. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11439. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11440. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11441. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11442. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11443. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11444. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11445. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11446. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11447. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11448. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11449. {
  11450. 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")));
  11451. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11452. 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"));
  11453. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11454. 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"));
  11455. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11456. 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")));
  11457. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11458. {
  11459. 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++)
  11460. {
  11461. 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"));
  11462. 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"));
  11463. 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)
  11464. 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"));
  11465. }
  11466. }
  11467. }
  11468. }
  11469. else
  11470. {
  11471. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11472. }
  11473. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') && (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W'))
  11474. {
  11475. DEBUG_INFO("Checking charging status for DW series...\n");
  11476. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11477. {
  11478. if(cpinitateMsg.bits[gun_index].isOnCharging ||
  11479. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL) ||
  11480. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing") != NULL))
  11481. {
  11482. DEBUG_INFO("Found gun-%d is in charging.\n", gun_index);
  11483. if(connectorIdInt != (gun_index+1))
  11484. {
  11485. DEBUG_WARN("DWseries--> Other connector is in charging.\n");
  11486. result = FAIL;
  11487. break;
  11488. }
  11489. }
  11490. }
  11491. }
  11492. }
  11493. else
  11494. {
  11495. DEBUG_WARN("Connector id is over maximun value.\n");
  11496. result = FAIL;
  11497. }
  11498. }
  11499. if(result == PASS)
  11500. {
  11501. if(connectorIdInt > 0)
  11502. {
  11503. DEBUG_INFO("Specified gun-%d type: %d\n", (connectorIdInt -1), gunType[connectorIdInt -1]);
  11504. //check Transaction active
  11505. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11506. {
  11507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11508. {
  11509. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11510. }
  11511. else
  11512. {
  11513. tempIndex = connectorIdInt -1;
  11514. }
  11515. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11516. {
  11517. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11518. {
  11519. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11520. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11521. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11522. {
  11523. //Reserved
  11524. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11525. }
  11526. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11527. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11528. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11529. {
  11530. //Reserved
  11531. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11532. {
  11533. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11534. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11535. goto end;
  11536. }
  11537. }
  11538. else
  11539. {
  11540. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11541. {
  11542. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11543. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11544. goto end;
  11545. }
  11546. }//END FOR ELSE
  11547. }
  11548. }// END FOR CHAdeMO_QUANTITY
  11549. }
  11550. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11551. {
  11552. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11553. {
  11554. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11555. }
  11556. else
  11557. {
  11558. tempIndex = connectorIdInt -1;
  11559. }
  11560. for (int index = 0; index < CCS_QUANTITY; index++)
  11561. {
  11562. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11563. {
  11564. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11565. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11566. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11567. {
  11568. //Reserved
  11569. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11570. }
  11571. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11572. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11573. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11574. {
  11575. //Reserved
  11576. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11577. {
  11578. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11579. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11580. goto end;
  11581. }
  11582. }
  11583. else
  11584. {
  11585. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11586. {
  11587. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11588. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11589. goto end;
  11590. }
  11591. }// END FOR ELSE
  11592. }
  11593. }// END FOR CCS_QUANTITY
  11594. }
  11595. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11596. {
  11597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11598. {
  11599. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11600. }
  11601. else
  11602. {
  11603. tempIndex = connectorIdInt -1;
  11604. }
  11605. for (int index = 0; index < GB_QUANTITY; index++)
  11606. {
  11607. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11608. {
  11609. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11610. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11611. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11612. {
  11613. //Reserved
  11614. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11615. }
  11616. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11617. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11618. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11619. {
  11620. //Reserved
  11621. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11622. {
  11623. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11624. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11625. goto end;
  11626. }
  11627. }
  11628. else
  11629. {
  11630. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11631. {
  11632. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11633. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11634. goto end;
  11635. }
  11636. }// END FOR ELSE
  11637. }
  11638. } // END FOR GB_QUANTITY
  11639. }
  11640. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11641. {
  11642. tempIndex = connectorIdInt -1;
  11643. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11644. {
  11645. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11646. {
  11647. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11648. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11649. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11650. {
  11651. //Reserved
  11652. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11653. }
  11654. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11655. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11656. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11657. {
  11658. //Reserved
  11659. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11660. {
  11661. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11662. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11663. goto end;
  11664. }
  11665. }
  11666. else
  11667. {
  11668. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11669. {
  11670. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11671. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11672. goto end;
  11673. }
  11674. }// END FOR ELSE
  11675. }
  11676. } // END FOR GB_QUANTITY
  11677. }
  11678. else
  11679. {
  11680. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11681. {
  11682. tempIndex = 2;
  11683. }
  11684. else
  11685. {
  11686. tempIndex = connectorIdInt -1;
  11687. }
  11688. for (int index = 0; index < AC_QUANTITY; index++)
  11689. {
  11690. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11691. {
  11692. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11693. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11694. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11695. {
  11696. //Reserved
  11697. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11698. }
  11699. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11700. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11701. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11702. {
  11703. //Reserved
  11704. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11705. {
  11706. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11707. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11708. goto end;
  11709. }
  11710. }
  11711. else
  11712. {
  11713. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11714. {
  11715. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11716. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11717. goto end;
  11718. }
  11719. }//END FOR ELSE
  11720. }
  11721. }// END FOR AC_QUANTITY
  11722. }
  11723. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11724. {
  11725. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11726. {
  11727. // Save profile to file
  11728. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11729. system(cmdBuf);
  11730. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11731. fp = fopen(cmdBuf, "w");
  11732. 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));
  11733. fclose(fp);
  11734. }
  11735. else
  11736. {
  11737. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11738. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11739. goto end;
  11740. }
  11741. }
  11742. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11743. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11744. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11745. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11746. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11747. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11748. }
  11749. else
  11750. {
  11751. uint8_t isHasIdleConnector = FALSE;
  11752. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11753. {
  11754. DEBUG_INFO("Check not specified gun-%d type: %d\n", gun_index, gunType[gun_index]);
  11755. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11756. {
  11757. isHasIdleConnector = TRUE;
  11758. break;
  11759. }
  11760. }
  11761. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11762. {
  11763. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11764. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11765. {
  11766. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11767. {
  11768. // Save profile to file
  11769. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11770. system(cmdBuf);
  11771. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11772. fp = fopen(cmdBuf, "w");
  11773. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11774. fclose(fp);
  11775. refreshStartTimer(&clientTime.RemoteStartWait);
  11776. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11777. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11778. }
  11779. else
  11780. {
  11781. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11782. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11783. }
  11784. }
  11785. else
  11786. {
  11787. refreshStartTimer(&clientTime.RemoteStartWait);
  11788. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11789. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11790. }
  11791. }
  11792. else
  11793. {
  11794. DEBUG_INFO("There is not any connector is idle.\n");
  11795. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11796. }
  11797. }
  11798. }
  11799. else
  11800. {
  11801. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11802. }
  11803. end:
  11804. json_object_put(RemoteStartTransaction);
  11805. sendRemoteStartConfirmation(uuid, comfirmstr);
  11806. return result;
  11807. }
  11808. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11809. {
  11810. mtrace();
  11811. int result = FAIL;
  11812. int match = FALSE;
  11813. int GunNO = 0;
  11814. int tempIndex = 0;
  11815. int transactionIdInt=0;
  11816. int transactionIdIsNULL= TRUE;
  11817. char comfirmstr[20];
  11818. json_object *RemoteStopTransaction;
  11819. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11820. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11821. if(server_pending == TRUE)
  11822. {
  11823. return 0;
  11824. }
  11825. RemoteStopTransaction = json_tokener_parse(payload);
  11826. if(!is_error(RemoteStopTransaction))
  11827. {
  11828. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11829. {
  11830. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11831. transactionIdIsNULL = FALSE;
  11832. }
  11833. }
  11834. json_object_put(RemoteStopTransaction);
  11835. if(transactionIdIsNULL == FALSE)
  11836. {
  11837. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11838. {
  11839. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11840. {
  11841. //check Transaction active
  11842. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11843. {
  11844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11845. {
  11846. tempIndex = ((gun_index==2) ? 1: 0);
  11847. }
  11848. else
  11849. {
  11850. tempIndex = gun_index;
  11851. }
  11852. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11853. {
  11854. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11855. {
  11856. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11857. {
  11858. match = TRUE;
  11859. GunNO = gun_index;
  11860. }
  11861. }
  11862. }// END FOR CHAdeMO_QUANTITY
  11863. }
  11864. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11865. {
  11866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11867. {
  11868. tempIndex = ((gun_index==2) ? 1: 0);
  11869. }
  11870. else
  11871. {
  11872. tempIndex = gun_index;
  11873. }
  11874. for (int index = 0; index < CCS_QUANTITY; index++)
  11875. {
  11876. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11877. {
  11878. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11879. {
  11880. match = TRUE;
  11881. GunNO = gun_index;
  11882. }
  11883. }
  11884. }// END FOR CCS_QUANTITY
  11885. }
  11886. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11887. {
  11888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11889. {
  11890. tempIndex = ((gun_index==2) ? 1: 0);
  11891. }
  11892. else
  11893. {
  11894. tempIndex = gun_index;
  11895. }
  11896. for (int index = 0; index < GB_QUANTITY; index++)
  11897. {
  11898. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11899. {
  11900. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11901. {
  11902. match = TRUE;
  11903. GunNO = gun_index;
  11904. }
  11905. }
  11906. }// END FOR GB_QUANTITY
  11907. }
  11908. else if(gunType[gun_index] == GUN_TYPE_DO)
  11909. {
  11910. tempIndex = gun_index;
  11911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11912. {
  11913. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11914. {
  11915. 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
  11916. {
  11917. match = TRUE;
  11918. GunNO = gun_index;
  11919. }
  11920. }
  11921. }// END FOR GB_QUANTITY
  11922. }
  11923. else
  11924. {
  11925. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11926. {
  11927. tempIndex = 2;
  11928. }
  11929. else
  11930. {
  11931. tempIndex = gun_index;
  11932. }
  11933. for (int index = 0; index < AC_QUANTITY; index++)
  11934. {
  11935. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11936. {
  11937. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11938. {
  11939. match = TRUE;
  11940. GunNO = gun_index;
  11941. }
  11942. }
  11943. }// END FOR CHAdeMO_QUANTITY
  11944. } // END FOR AC ELSE
  11945. }// CHECK IF ResponseTransactionId == transactionIdInt
  11946. }//END FOR
  11947. if( match == TRUE)
  11948. {
  11949. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11950. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11951. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11952. }
  11953. else
  11954. {
  11955. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11956. }
  11957. }
  11958. else
  11959. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11960. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11961. return result;
  11962. }
  11963. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11964. {
  11965. mtrace();
  11966. int result = FAIL;
  11967. int connectorIdInt=0, reservationIdInt=0;
  11968. int tempIndex = 0;
  11969. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11970. char comfirmstr[20]={0};
  11971. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11972. int c = 0;
  11973. char *loc;
  11974. //char *ptr;
  11975. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11976. strcpy(sstrtemp, stringtrimspace(payload));
  11977. //***(1)connectorId ****/
  11978. c=0;
  11979. loc = strstr(sstrtemp, "connectorId");
  11980. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11981. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11982. {
  11983. sstr[c] = loc[strlen("connectorId")+2+c];
  11984. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11985. c++;
  11986. }
  11987. sstr[c] = '\0';
  11988. connectorIdInt = atoi(sstr);
  11989. //***(2)expiryDate ****/
  11990. loc = strstr(sstrtemp, "expiryDate");
  11991. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11992. c = 0;
  11993. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11994. {
  11995. sstr[c] = loc[3+strlen("expiryDate")+c];
  11996. c++;
  11997. }
  11998. sstr[c] = '\0';
  11999. strcpy(expiryDatestr, sstr);
  12000. //***(3)idTag ****/
  12001. loc = strstr(sstrtemp, "idTag");
  12002. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12003. c = 0;
  12004. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  12005. {
  12006. sstr[c] = loc[3+strlen("idTag")+c];
  12007. c++;
  12008. }
  12009. sstr[c] = '\0';
  12010. strcpy(idTagstr, sstr);
  12011. //***(4)parentIdTag ****/
  12012. loc = strstr(sstrtemp, "parentIdTag");
  12013. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12014. c = 0;
  12015. if(loc == NULL)
  12016. {
  12017. strcpy(parentIdTagstr, "");
  12018. }
  12019. else
  12020. {
  12021. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  12022. {
  12023. sstr[c] = loc[3+strlen("parentIdTag")+c];
  12024. c++;
  12025. }
  12026. sstr[c] = '\0';
  12027. strcpy(parentIdTagstr, sstr);
  12028. }
  12029. //***(5)reservationId ****/
  12030. c=0;
  12031. loc = strstr(sstrtemp, "reservationId");
  12032. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12033. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12034. {
  12035. sstr[c] = loc[strlen("reservationId")+2+c];
  12036. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12037. c++;
  12038. }
  12039. sstr[c] = '\0';
  12040. reservationIdInt = atoi(sstr);
  12041. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12042. /*
  12043. enum SYSTEM_STATUS
  12044. {
  12045. SYS_MODE_BOOTING = 0,
  12046. SYS_MODE_IDLE = 1,
  12047. SYS_MODE_AUTHORIZING = 2,
  12048. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12049. SYS_MODE_REASSIGN = 4,
  12050. SYS_MODE_PREPARING = 5,
  12051. SYS_MODE_PREPARE_FOR_EV = 6,
  12052. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12053. SYS_MODE_CHARGING = 8,
  12054. SYS_MODE_TERMINATING = 9,
  12055. SYS_MODE_COMPLETE = 10,
  12056. SYS_MODE_ALARM = 11,
  12057. SYS_MODE_FAULT = 12,
  12058. SYS_MODE_RESERVATION = 13,
  12059. SYS_MODE_BOOKING = 14,
  12060. SYS_MODE_MAINTAIN = 15,
  12061. SYS_MODE_DEBUG = 16,
  12062. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12063. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12064. SYS_MODE_UPDATE = 19
  12065. };
  12066. */
  12067. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12068. {
  12069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12070. goto end;
  12071. }
  12072. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12073. {
  12074. //check Transaction active
  12075. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12076. {
  12077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12078. {
  12079. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12080. }
  12081. else
  12082. {
  12083. tempIndex = connectorIdInt -1;
  12084. }
  12085. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12086. {
  12087. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12088. {
  12089. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12090. {
  12091. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12092. {
  12093. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12094. {
  12095. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12096. {
  12097. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12098. }
  12099. else
  12100. {
  12101. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12103. }
  12104. }
  12105. 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'))
  12106. {
  12107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12108. }
  12109. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12110. {
  12111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12112. }
  12113. else
  12114. {
  12115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12116. }
  12117. }
  12118. 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
  12119. {
  12120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12121. }
  12122. }
  12123. else
  12124. {
  12125. //replace reservation
  12126. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12128. }
  12129. }
  12130. } // END FOR CHAdeMO_QUANTITY
  12131. }
  12132. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12133. {
  12134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12135. {
  12136. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12137. }
  12138. else
  12139. {
  12140. tempIndex = connectorIdInt -1;
  12141. }
  12142. for (int index = 0; index < CCS_QUANTITY; index++)
  12143. {
  12144. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12145. {
  12146. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12147. {
  12148. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12149. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12150. {
  12151. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12152. {
  12153. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12154. {
  12155. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12156. }
  12157. else
  12158. {
  12159. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12160. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12161. }
  12162. }
  12163. 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'))
  12164. {
  12165. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12166. }
  12167. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12168. {
  12169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12170. }
  12171. else
  12172. {
  12173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12174. }
  12175. }
  12176. 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
  12177. {
  12178. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12179. }
  12180. }
  12181. else
  12182. {
  12183. //replace reservation
  12184. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12186. }
  12187. }
  12188. } // END FOR CCS_QUANTITY
  12189. }
  12190. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12191. {
  12192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12193. {
  12194. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12195. }
  12196. else
  12197. {
  12198. tempIndex = connectorIdInt -1;
  12199. }
  12200. for (int index = 0; index < GB_QUANTITY; index++)
  12201. {
  12202. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12203. {
  12204. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12205. {
  12206. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12207. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12208. {
  12209. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12210. {
  12211. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12212. {
  12213. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12214. }
  12215. else
  12216. {
  12217. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12219. }
  12220. }
  12221. 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'))
  12222. {
  12223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12224. }
  12225. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12226. {
  12227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12228. }
  12229. else
  12230. {
  12231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12232. }
  12233. }
  12234. 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
  12235. {
  12236. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12237. }
  12238. }
  12239. else
  12240. {
  12241. //replace reservation
  12242. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12243. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12244. }
  12245. }
  12246. }// END FOR GB_QUANTITY
  12247. }
  12248. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12249. {
  12250. tempIndex = connectorIdInt -1;
  12251. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12252. {
  12253. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12254. {
  12255. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12256. {
  12257. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12258. 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
  12259. {
  12260. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12261. {
  12262. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12263. {
  12264. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12265. }
  12266. else
  12267. {
  12268. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12269. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12270. }
  12271. }
  12272. 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'))
  12273. {
  12274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12275. }
  12276. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12277. {
  12278. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12279. }
  12280. else
  12281. {
  12282. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12283. }
  12284. }
  12285. 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
  12286. {
  12287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12288. }
  12289. }
  12290. else
  12291. {
  12292. //replace reservation
  12293. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12294. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12295. }
  12296. }
  12297. }// END FOR GB_QUANTITY
  12298. }
  12299. else
  12300. {
  12301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12302. {
  12303. tempIndex = 2;
  12304. }
  12305. else
  12306. {
  12307. tempIndex = (connectorIdInt -1);
  12308. }
  12309. for (int index = 0; index < AC_QUANTITY; index++)
  12310. {
  12311. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12312. {
  12313. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12314. {
  12315. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12316. {
  12317. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12318. {
  12319. 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))
  12320. {
  12321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12322. }
  12323. else
  12324. {
  12325. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12327. }
  12328. }
  12329. 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'))
  12330. {
  12331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12332. }
  12333. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12334. {
  12335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12336. }
  12337. else
  12338. {
  12339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12340. }
  12341. }
  12342. 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
  12343. {
  12344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12345. }
  12346. }
  12347. else
  12348. {
  12349. //replace reservation
  12350. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12351. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12352. }
  12353. }
  12354. } // END FOR AC_QUANTITY
  12355. }
  12356. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12357. }
  12358. else if(connectorIdInt == 0)
  12359. {
  12360. //check Transaction active
  12361. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12362. {
  12363. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12364. {
  12365. 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'))
  12366. {
  12367. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12368. goto end;
  12369. }
  12370. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12371. {
  12372. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12373. goto end;
  12374. }
  12375. 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
  12376. {
  12377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12378. goto end;
  12379. }
  12380. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12381. {
  12382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12383. goto end;
  12384. }
  12385. }
  12386. }// END FOR CHAdeMO_QUANTITY
  12387. for (int index = 0; index < CCS_QUANTITY; index++)
  12388. {
  12389. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12390. {
  12391. 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'))
  12392. {
  12393. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12394. goto end;
  12395. }
  12396. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12397. {
  12398. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12399. goto end;
  12400. }
  12401. 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
  12402. {
  12403. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12404. goto end;
  12405. }
  12406. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12407. {
  12408. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12409. goto end;
  12410. }
  12411. }
  12412. } // END FOR CCS_QUANTITY
  12413. for (int index = 0; index < GB_QUANTITY; index++)
  12414. {
  12415. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12416. {
  12417. 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'))
  12418. {
  12419. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12420. goto end;
  12421. }
  12422. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12423. {
  12424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12425. goto end;
  12426. }
  12427. 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
  12428. {
  12429. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12430. goto end;
  12431. }
  12432. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12433. {
  12434. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12435. goto end;
  12436. }
  12437. }
  12438. } // END FOR GB_QUANTITY
  12439. for (int index = 0; index < AC_QUANTITY; index++)
  12440. {
  12441. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12442. {
  12443. 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'))
  12444. {
  12445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12446. goto end;
  12447. }
  12448. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12449. {
  12450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12451. goto end;
  12452. }
  12453. 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
  12454. {
  12455. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12456. goto end;
  12457. }
  12458. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12459. {
  12460. 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))
  12461. {
  12462. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12463. goto end;
  12464. }
  12465. }
  12466. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12467. {
  12468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12469. goto end;
  12470. }
  12471. }
  12472. }// END FOR AC_QUANTITY
  12473. //The connectorId is 0
  12474. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12475. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12476. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12477. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12478. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12479. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12480. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12481. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12482. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12483. result = TRUE;
  12484. return result;
  12485. }
  12486. else
  12487. {
  12488. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12489. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12490. }
  12491. if(strcmp(comfirmstr,"Accepted") == 0)
  12492. {
  12493. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12494. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12495. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12496. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12497. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12498. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12499. result = TRUE;
  12500. return result;
  12501. }
  12502. end:
  12503. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12504. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12505. return result;
  12506. }
  12507. int handleResetRequest(char *uuid, char *payload)
  12508. {
  12509. mtrace();
  12510. int result = FAIL;
  12511. char sstr[10]={0},sstrtemp[30]={ 0 };
  12512. char typestr[10]={0};
  12513. char comfirmstr[20]={0};
  12514. int c = 0;
  12515. char *loc;
  12516. DEBUG_INFO("handleResetRequest...\n");
  12517. strcpy(sstrtemp, stringtrimspace(payload));
  12518. loc = strstr(sstrtemp, "type");
  12519. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12520. c = 0;
  12521. while (loc[3+strlen("type")+c] != '\"')
  12522. {
  12523. sstr[c] = loc[3+strlen("type")+c];
  12524. c++;
  12525. }
  12526. sstr[c] = '\0';
  12527. strcpy(typestr,sstr);
  12528. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12529. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12530. {
  12531. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12532. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12533. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12534. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12535. }
  12536. else
  12537. {
  12538. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12539. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12540. result = PASS;
  12541. }
  12542. sendResetConfirmation(uuid, comfirmstr);
  12543. return result;
  12544. }
  12545. int handleSendLocalListRequest(char *uuid, char *payload)
  12546. {
  12547. mtrace();
  12548. int result = FAIL;
  12549. char comfirmstr[20];
  12550. int checkState_Faulted = FALSE;
  12551. json_object *SendLocalList;
  12552. DEBUG_INFO("handleSendLocalListRequest...\n");
  12553. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12554. {
  12555. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12556. goto end;
  12557. }
  12558. //check Charge Point state
  12559. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12560. {
  12561. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12562. {
  12563. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12564. }
  12565. }
  12566. for (int index = 0; index < CCS_QUANTITY; index++)
  12567. {
  12568. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12569. {
  12570. checkState_Faulted = TRUE; //OCPP Status
  12571. }
  12572. }
  12573. for (int index = 0; index < GB_QUANTITY; index++)
  12574. {
  12575. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].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 < GENERAL_GUN_QUANTITY; index++)
  12582. {
  12583. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12584. {
  12585. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12586. }
  12587. }
  12588. //check Charge Point state
  12589. for (int index = 0; index < AC_QUANTITY; index++)
  12590. {
  12591. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12592. {
  12593. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12594. }
  12595. }
  12596. if(checkState_Faulted == TRUE)
  12597. {
  12598. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12599. goto end;
  12600. }
  12601. // Parsing payload
  12602. SendLocalList = json_tokener_parse(payload);
  12603. if(!is_error(SendLocalList))
  12604. {
  12605. // Required data
  12606. if(json_object_object_get(SendLocalList, "listVersion") != NULL)
  12607. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12608. else
  12609. {
  12610. DEBUG_WARN("listVersion sould not be NULL!\n");
  12611. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12612. goto end;
  12613. }
  12614. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  12615. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12616. else
  12617. {
  12618. DEBUG_WARN("updateType sould not be NULL!\n");
  12619. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12620. goto end;
  12621. }
  12622. // Optional data
  12623. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12624. {
  12625. //Check UpdateType
  12626. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12627. {
  12628. //Local list full update
  12629. DEBUG_INFO("Local list full update.\n");
  12630. locallistVersion = 0;
  12631. OCPP_getListVerion();
  12632. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12633. {
  12634. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12635. goto end;
  12636. }
  12637. OCPP_cleanLocalList();
  12638. }
  12639. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12640. {
  12641. //Local list different update
  12642. DEBUG_INFO("Local list different update.\n");
  12643. locallistVersion = 0;
  12644. OCPP_getListVerion();
  12645. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12646. {
  12647. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12648. goto end;
  12649. }
  12650. }
  12651. else
  12652. {
  12653. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12654. goto end;
  12655. }
  12656. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12657. {
  12658. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12659. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12660. goto end;
  12661. }
  12662. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12663. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12664. {
  12665. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag") != NULL)
  12666. 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"))));
  12667. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12668. {
  12669. 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"))));
  12670. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12671. 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"))));
  12672. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12673. 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"))));
  12674. }
  12675. // Add to db
  12676. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12677. {
  12678. //Local list full update
  12679. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12680. idx,
  12681. ShmOCPP16Data->SendLocalList.ListVersion,
  12682. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12683. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12684. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12685. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12686. // update list
  12687. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12688. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12689. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12690. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12691. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12692. }
  12693. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12694. {
  12695. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12696. idx,
  12697. ShmOCPP16Data->SendLocalList.ListVersion,
  12698. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12699. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12700. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12701. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12702. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12703. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12704. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12705. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12706. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12707. }
  12708. }
  12709. }
  12710. else
  12711. {
  12712. //Check UpdateType
  12713. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12714. {
  12715. //Local list full update
  12716. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12717. OCPP_cleanLocalList();
  12718. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12719. goto end;
  12720. }
  12721. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12722. {
  12723. //Local list different update
  12724. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12725. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12726. goto end;
  12727. }
  12728. }
  12729. result = PASS;
  12730. }
  12731. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12732. end:
  12733. json_object_put(SendLocalList);
  12734. sendSendLocalListConfirmation(uuid, comfirmstr);
  12735. return result;
  12736. }
  12737. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12738. {
  12739. mtrace();
  12740. int result = FAIL;
  12741. struct StructSetChargingProfile SetProfileReq = {0};
  12742. int tempchargingProfileIdInt;
  12743. int tempstackLevelInt;
  12744. int chargingSchedulePeriodCount = 0;
  12745. char comfirmstr[20]={0};
  12746. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12747. char rmFileCmd[128]={0};
  12748. int profileQuantity = 0;
  12749. int replaceableProfileCnt = 0;
  12750. json_object *SetChargingProfile;
  12751. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12752. SetChargingProfile = json_tokener_parse(payload);
  12753. if(!is_error(SetChargingProfile))
  12754. {
  12755. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12756. {
  12757. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12758. }
  12759. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12760. {
  12761. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12762. {
  12763. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12764. }
  12765. else
  12766. {
  12767. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12768. DEBUG_WARN("Cannot find chargingProfileId field.");
  12769. goto end;
  12770. }
  12771. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12772. {
  12773. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12774. }
  12775. else
  12776. {
  12777. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12778. DEBUG_WARN("Cannot find stackLevel field.");
  12779. goto end;
  12780. }
  12781. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12782. {
  12783. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12784. }
  12785. else
  12786. {
  12787. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12788. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12789. goto end;
  12790. }
  12791. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12792. {
  12793. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12794. }
  12795. else
  12796. {
  12797. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12798. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12799. goto end;
  12800. }
  12801. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12802. {
  12803. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12804. }
  12805. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12806. {
  12807. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12808. }
  12809. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12810. {
  12811. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12812. }
  12813. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12814. {
  12815. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12816. }
  12817. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12818. {
  12819. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12820. {
  12821. 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")));
  12822. }
  12823. else
  12824. {
  12825. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12826. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12827. goto end;
  12828. }
  12829. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12830. {
  12831. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12832. }
  12833. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12834. {
  12835. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12836. }
  12837. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12838. {
  12839. 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")));
  12840. }
  12841. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12842. {
  12843. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12844. if(chargingSchedulePeriodCount <= 10)
  12845. {
  12846. 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++)
  12847. {
  12848. 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)
  12849. {
  12850. 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"));
  12851. }
  12852. else
  12853. {
  12854. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12855. DEBUG_WARN("Cannot find startPeriod field.");
  12856. goto end;
  12857. }
  12858. 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)
  12859. {
  12860. 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"));
  12861. }
  12862. else
  12863. {
  12864. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12865. DEBUG_WARN("Cannot find limit field.");
  12866. goto end;
  12867. }
  12868. 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)
  12869. {
  12870. 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"));
  12871. }
  12872. }
  12873. }
  12874. }
  12875. else
  12876. {
  12877. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12878. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12879. goto end;
  12880. }
  12881. }
  12882. else
  12883. {
  12884. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12885. DEBUG_WARN("Cannot find chargingSchedule field.");
  12886. goto end;
  12887. }
  12888. }
  12889. }
  12890. // Profile periods quantity check
  12891. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12892. {
  12893. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12894. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12895. goto end;
  12896. }
  12897. // Check invalid limit
  12898. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12899. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12900. {
  12901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12902. {
  12903. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12904. {
  12905. 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)))) ||
  12906. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12907. {
  12908. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12909. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12910. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12911. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12912. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12913. goto end;
  12914. }
  12915. }
  12916. }
  12917. else
  12918. {
  12919. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12920. {
  12921. 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) ||
  12922. (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)))
  12923. {
  12924. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12925. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12926. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12927. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12928. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12929. goto end;
  12930. }
  12931. }
  12932. }
  12933. }
  12934. // Profile purpose info check
  12935. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12936. {
  12937. FILE *fp;
  12938. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12939. if(SetProfileReq.ConnectorId != 0)
  12940. {
  12941. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12942. DEBUG_WARN("Profile connector id is not 0.\n");
  12943. goto end;
  12944. }
  12945. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12946. if (!fp)
  12947. {
  12948. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12949. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12950. }
  12951. else
  12952. {
  12953. char *line = NULL;
  12954. size_t len = 0;
  12955. while(getline(&line, &len, fp) != -1)
  12956. {
  12957. json_object *obj = NULL;
  12958. obj = json_tokener_parse(line);
  12959. if(is_error(obj))
  12960. {
  12961. DEBUG_ERROR("Parse txProfile from file error.\n");
  12962. }
  12963. else
  12964. {
  12965. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12966. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12967. {
  12968. profileQuantity += 1;
  12969. }
  12970. else
  12971. replaceableProfileCnt += 1;
  12972. }
  12973. }
  12974. }
  12975. fclose(fp);
  12976. }
  12977. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12978. {
  12979. FILE *fp;
  12980. char filename[128]={0};
  12981. int tmpProfileQuantity;
  12982. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12983. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12984. {
  12985. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12986. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12987. goto end;
  12988. }
  12989. if(SetProfileReq.ConnectorId == 0)
  12990. {
  12991. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12992. {
  12993. tmpProfileQuantity = 0;
  12994. memset(filename, 0, ARRAY_SIZE(filename));
  12995. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12996. fp = fopen(filename, "r");
  12997. if (!fp)
  12998. {
  12999. DEBUG_INFO("%s does not create.\n", filename);
  13000. fp = fopen(filename, "w+");
  13001. }
  13002. else
  13003. {
  13004. char *line = NULL;
  13005. size_t len = 0;
  13006. while(getline(&line, &len, fp) != -1)
  13007. {
  13008. json_object *obj = NULL;
  13009. obj = json_tokener_parse(line);
  13010. if(is_error(obj))
  13011. {
  13012. DEBUG_ERROR("Parse txProfile from file error.\n");
  13013. }
  13014. else
  13015. {
  13016. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13017. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13018. {
  13019. tmpProfileQuantity += 1;
  13020. }
  13021. else
  13022. replaceableProfileCnt += 1;
  13023. }
  13024. }
  13025. }
  13026. fclose(fp);
  13027. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  13028. }
  13029. }
  13030. else
  13031. {
  13032. memset(filename, 0, ARRAY_SIZE(filename));
  13033. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13034. fp = fopen(filename, "r");
  13035. if (!fp)
  13036. {
  13037. DEBUG_INFO("%s does not create.\n", filename);
  13038. fp = fopen(filename, "w+");
  13039. }
  13040. else
  13041. {
  13042. char *line = NULL;
  13043. size_t len = 0;
  13044. while(getline(&line, &len, fp) != -1)
  13045. {
  13046. json_object *obj = NULL;
  13047. obj = json_tokener_parse(line);
  13048. if(is_error(obj))
  13049. {
  13050. DEBUG_ERROR("Parse txProfile from file error.\n");
  13051. }
  13052. else
  13053. {
  13054. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13055. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13056. {
  13057. profileQuantity += 1;
  13058. }
  13059. else
  13060. replaceableProfileCnt += 1;
  13061. }
  13062. }
  13063. }
  13064. fclose(fp);
  13065. }
  13066. }
  13067. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13068. {
  13069. int isMatchTransactiodId= FALSE;
  13070. FILE *fp;
  13071. char filename[128]={0};
  13072. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13073. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13074. if(SetProfileReq.ConnectorId == 0)
  13075. {
  13076. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13077. DEBUG_WARN("Profile connector id is 0.\n");
  13078. goto end;
  13079. }
  13080. int tempIndex = 0;
  13081. //check Transaction active
  13082. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13083. {
  13084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13085. {
  13086. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13087. }
  13088. else
  13089. {
  13090. tempIndex = SetProfileReq.ConnectorId -1;
  13091. }
  13092. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13093. {
  13094. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13095. {
  13096. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13097. {
  13098. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13099. {
  13100. isMatchTransactiodId = TRUE;
  13101. break;
  13102. }
  13103. }
  13104. }
  13105. }
  13106. }
  13107. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13108. {
  13109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13110. {
  13111. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13112. }
  13113. else
  13114. {
  13115. tempIndex = SetProfileReq.ConnectorId -1;
  13116. }
  13117. for (int index = 0; index < CCS_QUANTITY; index++)
  13118. {
  13119. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13120. {
  13121. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13122. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13123. {
  13124. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13125. {
  13126. isMatchTransactiodId = TRUE;
  13127. break;
  13128. }
  13129. }
  13130. }
  13131. }
  13132. }
  13133. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13134. {
  13135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13136. {
  13137. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13138. }
  13139. else
  13140. {
  13141. tempIndex = SetProfileReq.ConnectorId -1;
  13142. }
  13143. for (int index = 0; index < GB_QUANTITY; index++)
  13144. {
  13145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13146. {
  13147. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13148. {
  13149. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13150. {
  13151. isMatchTransactiodId = TRUE;
  13152. break;
  13153. }
  13154. }
  13155. }
  13156. }
  13157. }
  13158. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13159. {
  13160. tempIndex = SetProfileReq.ConnectorId -1;
  13161. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13162. {
  13163. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13164. {
  13165. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13166. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13167. {
  13168. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13169. {
  13170. isMatchTransactiodId = TRUE;
  13171. break;
  13172. }
  13173. }
  13174. }
  13175. }
  13176. }
  13177. else
  13178. {
  13179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13180. {
  13181. tempIndex = 2;
  13182. }
  13183. else
  13184. {
  13185. tempIndex = (SetProfileReq.ConnectorId -1);
  13186. }
  13187. for (int index = 0; index < AC_QUANTITY; index++)
  13188. {
  13189. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13190. {
  13191. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13192. {
  13193. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13194. {
  13195. isMatchTransactiodId = TRUE;
  13196. break;
  13197. }
  13198. }
  13199. }
  13200. }
  13201. }
  13202. //check Transaction active
  13203. if(isMatchTransactiodId == FALSE)
  13204. {
  13205. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13206. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13207. goto end;
  13208. }
  13209. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13210. {
  13211. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13212. DEBUG_WARN("Connector id is over max gun number.\n");
  13213. goto end;
  13214. }
  13215. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13216. fp = fopen(filename, "r");
  13217. if (!fp)
  13218. {
  13219. DEBUG_INFO("%s does not create.\n", filename);
  13220. fp = fopen(filename, "w+");
  13221. }
  13222. else
  13223. {
  13224. char *line = NULL;
  13225. size_t len = 0;
  13226. while(getline(&line, &len, fp) != -1)
  13227. {
  13228. json_object *obj = NULL;
  13229. obj = json_tokener_parse(line);
  13230. if(is_error(obj))
  13231. {
  13232. DEBUG_ERROR("Parse txProfile from file error.\n");
  13233. }
  13234. else
  13235. {
  13236. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13237. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13238. {
  13239. profileQuantity += 1;
  13240. }
  13241. else
  13242. replaceableProfileCnt += 1;
  13243. }
  13244. }
  13245. }
  13246. fclose(fp);
  13247. }
  13248. // Check ChargeProfileMaxStackLevel
  13249. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13250. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13251. {
  13252. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13253. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13254. goto end;
  13255. }
  13256. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13257. {
  13258. FILE *fp;
  13259. char dataLine[4096]={0};
  13260. char fnametemp[128]={0};
  13261. int tmpProfileQuantity;
  13262. //Check ChargePointMaxProfile.json exit
  13263. profileQuantity = 0;
  13264. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13265. {
  13266. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13267. //Check Charging Profile Count
  13268. tmpProfileQuantity = 0;
  13269. while(fscanf(fp, "%s", dataLine) != EOF)
  13270. {
  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("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13280. }
  13281. //Check TxDefaultProfile_%d.json
  13282. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13283. {
  13284. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13285. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13286. if((access(fnametemp,F_OK))!=-1)
  13287. {
  13288. fp = fopen(fnametemp, "r");
  13289. //Check Charging Profile Count
  13290. tmpProfileQuantity = 0;
  13291. while(fscanf(fp, "%s", dataLine) != EOF)
  13292. {
  13293. //DEBUG_INFO("word=%s\n",word);
  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. //Check TxProfile_%d.json
  13306. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13307. {
  13308. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13309. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13310. if((access(fnametemp,F_OK))!=-1)
  13311. {
  13312. fp = fopen(fnametemp, "r");
  13313. //Check Charging Profile Count
  13314. tmpProfileQuantity = 0;
  13315. while(fscanf(fp, "%s", dataLine) != EOF)
  13316. {
  13317. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13318. {
  13319. profileQuantity += 1;
  13320. tmpProfileQuantity += 1;
  13321. }
  13322. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13323. }
  13324. fclose(fp);
  13325. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13326. }
  13327. }
  13328. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13329. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13330. // To check total Profile quantity
  13331. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13332. {
  13333. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13334. {
  13335. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13336. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13337. goto end;
  13338. }
  13339. }
  13340. else
  13341. {
  13342. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13343. {
  13344. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13345. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13346. goto end;
  13347. }
  13348. }
  13349. }
  13350. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13351. //**********************************Write to File********************************************************/
  13352. {
  13353. FILE *infile;
  13354. FILE *outfile;
  13355. char dataLine[4096]={0};
  13356. char filename[128]={0};
  13357. int chkChar=0;
  13358. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13359. {
  13360. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13361. {
  13362. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13363. }
  13364. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13365. {
  13366. if(SetProfileReq.ConnectorId==0)
  13367. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13368. else
  13369. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13370. }
  13371. else
  13372. {
  13373. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13374. }
  13375. infile = fopen (filename, "r");
  13376. outfile = fopen (tempfile, "w");
  13377. chkChar = fgetc(infile);
  13378. rewind(infile);
  13379. if(chkChar == EOF)
  13380. {
  13381. // Profile is empty
  13382. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13383. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13384. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13385. fclose(infile);
  13386. fclose(outfile);
  13387. sprintf(rmFileCmd,"rm -f %s",filename);
  13388. system(rmFileCmd);
  13389. rename(tempfile, filename);
  13390. }
  13391. else
  13392. {
  13393. // Profile is not empty
  13394. int ChargingProfileAdded = FALSE;
  13395. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13396. {
  13397. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13398. json_object *tmpChargingProfile;
  13399. tmpChargingProfile = json_tokener_parse(dataLine);
  13400. if(!is_error(SetChargingProfile))
  13401. {
  13402. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13403. {
  13404. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13405. {
  13406. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13407. }
  13408. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13409. {
  13410. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13411. }
  13412. }
  13413. }
  13414. json_object_put(tmpChargingProfile);
  13415. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13416. {
  13417. if(ChargingProfileAdded == FALSE)
  13418. {
  13419. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13420. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13421. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13422. ChargingProfileAdded = TRUE;
  13423. }
  13424. }
  13425. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13426. {
  13427. if(ChargingProfileAdded == FALSE)
  13428. {
  13429. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13430. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13431. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13432. ChargingProfileAdded = TRUE;
  13433. }
  13434. }
  13435. else
  13436. {
  13437. fprintf(outfile,"%s\n",dataLine);
  13438. if(ChargingProfileAdded == FALSE)
  13439. {
  13440. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13441. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13442. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13443. ChargingProfileAdded = TRUE;
  13444. }
  13445. }
  13446. } // end of while loop
  13447. fclose(infile);
  13448. fclose(outfile);
  13449. sprintf(rmFileCmd,"rm -f %s",filename);
  13450. system(rmFileCmd);
  13451. rename(tempfile, filename);
  13452. }
  13453. }
  13454. sleep(1);
  13455. result = TRUE;
  13456. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13457. }
  13458. end:
  13459. json_object_put(SetChargingProfile);
  13460. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13461. {
  13462. if(SetProfileReq.ConnectorId == 0)
  13463. {
  13464. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13465. {
  13466. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13467. }
  13468. }
  13469. else
  13470. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13471. }
  13472. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13473. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13474. return result;
  13475. }
  13476. int handleTriggerMessageRequest(char *uuid, char *payload)
  13477. {
  13478. mtrace();
  13479. int result = FAIL;
  13480. int connectorIdIsNULL = FALSE;
  13481. int connectorIdInt =0;
  13482. char sstr[40]={0},sstrtemp[100]={ 0 };
  13483. char requestedMessagestr[40]={0};
  13484. char comfirmstr[20]={0};
  13485. int c = 0;
  13486. char *loc;
  13487. DEBUG_INFO("handleTriggerMessageRequest\n");
  13488. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13489. strcpy(sstrtemp, stringtrimspace(payload));
  13490. c = 0;
  13491. loc = strstr(sstrtemp, "requestedMessage");
  13492. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13493. {
  13494. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13495. c++;
  13496. }
  13497. sstr[c] = '\0';
  13498. strcpy(requestedMessagestr, sstr);
  13499. c = 0;
  13500. loc = strstr(sstrtemp, "connectorId");
  13501. if(loc == NULL)
  13502. {
  13503. connectorIdIsNULL = TRUE;
  13504. }
  13505. else
  13506. {
  13507. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13508. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13509. {
  13510. sstr[c] = loc[strlen("connectorId")+2+c];
  13511. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13512. c++;
  13513. }
  13514. sstr[c] = '\0';
  13515. connectorIdInt = atoi(sstr);
  13516. }
  13517. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13518. {
  13519. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13520. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13521. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13522. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13523. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13524. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13525. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13526. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13527. {
  13528. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13529. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13530. return TRUE;
  13531. }
  13532. else
  13533. {
  13534. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13535. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13536. }
  13537. }
  13538. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13539. {
  13540. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13541. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13542. return TRUE;
  13543. }
  13544. //==========================
  13545. // Trigger message
  13546. //==========================
  13547. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13548. {
  13549. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13550. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13551. {
  13552. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13553. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13554. }
  13555. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13556. }
  13557. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13558. {
  13559. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13560. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13561. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13562. }
  13563. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13564. {
  13565. //sendBootNotificationRequest();
  13566. server_sign = FALSE;
  13567. }
  13568. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13569. {
  13570. refreshStartTimer(&clientTime.Heartbeat);
  13571. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13572. }
  13573. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13574. {
  13575. if(connectorIdIsNULL == FALSE)
  13576. {
  13577. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13578. {
  13579. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13580. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13581. }
  13582. }
  13583. else
  13584. {
  13585. for(int idx=0;idx< gunTotalNumber;idx++)
  13586. {
  13587. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13588. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13589. }
  13590. }
  13591. }
  13592. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13593. {
  13594. if(connectorIdIsNULL == FALSE)
  13595. {
  13596. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13597. {
  13598. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13599. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13600. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13601. }
  13602. }
  13603. else
  13604. {
  13605. for(int idx=0;idx< gunTotalNumber;idx++)
  13606. {
  13607. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13608. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13609. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13610. }
  13611. }
  13612. }
  13613. return result;
  13614. }
  13615. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13616. {
  13617. mtrace();
  13618. int result = FAIL;
  13619. int connectorIdInt =0;
  13620. char comfirmstr[20]={0};
  13621. int tempIndex = 0;
  13622. json_object *UnlockConnector;
  13623. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13624. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13625. UnlockConnector = json_tokener_parse(payload);
  13626. if(!is_error(UnlockConnector))
  13627. {
  13628. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13629. {
  13630. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13631. }
  13632. }
  13633. json_object_put(UnlockConnector);
  13634. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13635. if(gunTotalNumber == 0)
  13636. {
  13637. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13638. goto end;
  13639. }
  13640. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13641. {
  13642. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13643. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13644. goto end;
  13645. }
  13646. else
  13647. {
  13648. //check Transaction active
  13649. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13650. {
  13651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13652. {
  13653. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13654. }
  13655. else
  13656. {
  13657. tempIndex = connectorIdInt -1;
  13658. }
  13659. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13660. {
  13661. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13662. {
  13663. //stop Transaction
  13664. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13665. }
  13666. }
  13667. }
  13668. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13669. {
  13670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13671. {
  13672. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13673. }
  13674. else
  13675. {
  13676. tempIndex = connectorIdInt -1;
  13677. }
  13678. for (int index = 0; index < CCS_QUANTITY; index++)
  13679. {
  13680. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13681. {
  13682. //stop Transaction
  13683. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13684. }
  13685. }
  13686. }
  13687. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13688. {
  13689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13690. {
  13691. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13692. }
  13693. else
  13694. {
  13695. tempIndex = connectorIdInt -1;
  13696. }
  13697. for (int index = 0; index < GB_QUANTITY; index++)
  13698. {
  13699. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13700. {
  13701. //stop Transaction
  13702. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13703. }
  13704. }
  13705. }
  13706. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13707. {
  13708. tempIndex = connectorIdInt -1;
  13709. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13710. {
  13711. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13712. {
  13713. //stop Transaction
  13714. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13715. }
  13716. }
  13717. }
  13718. else
  13719. {
  13720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13721. {
  13722. tempIndex = 2;
  13723. }
  13724. else
  13725. {
  13726. tempIndex = connectorIdInt-1;
  13727. }
  13728. for (int index = 0; index < AC_QUANTITY; index++)
  13729. {
  13730. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13731. {
  13732. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13733. }
  13734. }
  13735. }
  13736. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13737. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13738. result = TRUE;
  13739. return result;
  13740. }
  13741. end:
  13742. //json_object_put(obj); --- remove temporally
  13743. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13744. return result;
  13745. }
  13746. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13747. {
  13748. mtrace();
  13749. int result = FAIL;
  13750. pthread_t t;
  13751. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13752. sendUpdateFirmwareConfirmation(uuid);
  13753. if(!interLock.isUpdateFirmwareGoing)
  13754. {
  13755. interLock.isUpdateFirmwareGoing = 1;
  13756. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13757. sleep(1);
  13758. }
  13759. else
  13760. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13761. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13762. return result;
  13763. }
  13764. void *UpdateFirmwareProcess(void *data)
  13765. {
  13766. pthread_detach(pthread_self());
  13767. mtrace();
  13768. int retriesInt =0, retryIntervalInt=0;
  13769. char protocol[10], user[64],password[64],host[1280], path[1024], ftppath[1024],host1[256],path1[1024];
  13770. int port=0;
  13771. char locationstr[2048]={0}, retrieveDatestr[36]={0};
  13772. int isSuccess = 0;
  13773. char ftpbuf[2048];
  13774. char temp[2048];
  13775. char * pch;
  13776. char filenametemp[256];
  13777. json_object *UpdateFirmware;
  13778. UpdateFirmware = json_tokener_parse(data);
  13779. if(!is_error(UpdateFirmware))
  13780. {
  13781. // Required data
  13782. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13783. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13784. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13785. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13786. // Optional data
  13787. if(json_object_object_get(UpdateFirmware, "retries"))
  13788. {
  13789. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13790. }
  13791. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13792. {
  13793. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13794. }
  13795. }
  13796. json_object_put(UpdateFirmware);
  13797. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13798. memset(path, 0, ARRAY_SIZE(path));
  13799. // Wait retrieveData
  13800. if(strlen(retrieveDatestr) > 10)
  13801. {
  13802. do
  13803. {
  13804. sleep(1);
  13805. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13806. }
  13807. // Ready to download
  13808. system("rm -f /mnt/*");
  13809. if(strncmp(locationstr,"http", 4) == 0)
  13810. {
  13811. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13812. sprintf(ftppath,"/%s", path);
  13813. DEBUG_INFO("locationstr: %s\n", locationstr);
  13814. DEBUG_INFO("protocol: %s\n",protocol);
  13815. DEBUG_INFO("host: %s\n",host);
  13816. DEBUG_INFO("path: %s\n",path);
  13817. DEBUG_INFO("ftppath: %s\n",ftppath);
  13818. int ftppathlen=strlen(ftppath);
  13819. int i=1;
  13820. while(i < ftppathlen)
  13821. {
  13822. int len=ftppathlen-i;
  13823. if(ftppath[len]== 47) // '/' ascll code: 47
  13824. {
  13825. DEBUG_INFO("compare '/' all right\n");
  13826. break;
  13827. }
  13828. i=i+1;
  13829. }
  13830. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13831. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13832. filenametemp[i+1] = 0;
  13833. do
  13834. {
  13835. sleep(1);
  13836. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13837. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13838. sleep(1);
  13839. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13840. if(!isSuccess)
  13841. {
  13842. sleep(1);
  13843. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13844. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13845. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13846. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13847. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13848. }
  13849. else
  13850. {
  13851. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13852. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13853. }
  13854. retriesInt--;
  13855. }while((isSuccess == 0)&&(retriesInt >= 0));
  13856. }
  13857. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13858. {
  13859. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13860. memset(temp, 0, ARRAY_SIZE(temp));
  13861. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13862. strcpy(ftpbuf, locationstr);
  13863. int ftppathlen=strlen(ftpbuf);
  13864. int i=1;
  13865. while(i < ftppathlen)
  13866. {
  13867. int len=ftppathlen-i;
  13868. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13869. {
  13870. DEBUG_INFO(" compare '/' all right\n");
  13871. break;
  13872. }
  13873. i=i+1;
  13874. }
  13875. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13876. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13877. filenametemp[i+1] = 0;
  13878. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13879. pch=strchr(temp,'@');
  13880. if(pch==NULL)
  13881. {
  13882. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13883. protocol, host, &port, path);
  13884. strcpy(user,"anonymous");
  13885. strcpy(password,"");
  13886. }
  13887. else
  13888. {
  13889. char loginInfo[128];
  13890. sscanf(temp,"%[^:]:%*2[/]%[^@]@", protocol, loginInfo);
  13891. // Check if it contains 'password'
  13892. if(strstr(loginInfo, ":") != NULL)
  13893. {
  13894. sscanf(loginInfo,"%[^:]:%s", user, password);
  13895. }
  13896. else
  13897. {
  13898. strcpy(user,loginInfo);
  13899. strcpy(password,"");
  13900. }
  13901. if(strstr(pch,":") != NULL)
  13902. {
  13903. sscanf(pch,"@%[^:]:%i/%512[^\n]", host, &port, path);
  13904. sprintf(host,"%s/%s", host,path);
  13905. }
  13906. else
  13907. {
  13908. sscanf(pch,"@%s[^\n]", host);
  13909. }
  13910. //sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]", protocol, user, host, &port, path);
  13911. }
  13912. sscanf(host,"%[^/]%s",host1, path1);
  13913. sprintf(ftppath,"%s:/%s", host,path);
  13914. if(port == 0)
  13915. {
  13916. port = 22;
  13917. }
  13918. do
  13919. {
  13920. sleep(1);
  13921. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13922. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13923. sleep(1);
  13924. isSuccess = sftpDownLoadFile(host1, user, password, port, path1, filenametemp, locationstr);
  13925. if(!isSuccess)
  13926. {
  13927. //BulldogUtil.sleepMs(interval*1000);
  13928. DEBUG_INFO("Update firmware request and download file fail.\n");
  13929. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13930. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13931. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13932. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13933. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13934. }
  13935. else
  13936. {
  13937. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13938. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13939. }
  13940. retriesInt--;
  13941. }while((!isSuccess)&&(retriesInt >= 0));
  13942. }
  13943. else if((strncmp(locationstr,"ftp", 3) == 0) || (strncmp(locationstr,"ftps", 4) == 0)) // ftp/ftps
  13944. {
  13945. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13946. memset(temp, 0, ARRAY_SIZE(temp));
  13947. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13948. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13949. int ftppathlen=strlen(ftpbuf);
  13950. int i=1;
  13951. while(i < ftppathlen)
  13952. {
  13953. int len=ftppathlen-i;
  13954. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13955. {
  13956. DEBUG_INFO(" compare '/' all right\n");
  13957. break;
  13958. }
  13959. i=i+1;
  13960. }
  13961. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13962. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13963. filenametemp[i+1] = 0;
  13964. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13965. pch=strchr(temp,'@');
  13966. if(pch==NULL)
  13967. {
  13968. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13969. protocol, host, &port, path);
  13970. strcpy(user,"anonymous");
  13971. strcpy(password,"");
  13972. }
  13973. else
  13974. {
  13975. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13976. protocol, user, password, host, &port, path);
  13977. }
  13978. sscanf(host,"%[^/]%s",host1, path1);
  13979. sprintf(ftppath,"%s", path1);
  13980. //DEBUG_INFO("protocol =%s\n",protocol);
  13981. //DEBUG_INFO("user =%s\n",user);
  13982. //DEBUG_INFO("password =%s\n",password);
  13983. //DEBUG_INFO("host1 =%s\n",host1);
  13984. //DEBUG_INFO("port =%d\n",port);
  13985. //DEBUG_INFO("path1 =%s\n",path1);
  13986. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13987. //ftpFile(host, user, password, port, ftppath, fname);
  13988. //download firmware pthred
  13989. if(port == 0)
  13990. {
  13991. port = 21;
  13992. }
  13993. do
  13994. {
  13995. sleep(1);
  13996. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13997. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13998. sleep(1);
  13999. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  14000. if(!isSuccess)
  14001. {
  14002. //BulldogUtil.sleepMs(interval*1000);
  14003. DEBUG_INFO("Update firmware request and download file fail.\n");
  14004. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14005. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14006. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  14007. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14008. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14009. }
  14010. else
  14011. {
  14012. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14013. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14014. }
  14015. retriesInt--;
  14016. }while((!isSuccess)&&(retriesInt >= 0));
  14017. }
  14018. else
  14019. {
  14020. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14021. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14022. sleep(1);
  14023. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14024. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14025. }
  14026. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  14027. {
  14028. sleep(3);
  14029. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  14030. }
  14031. interLock.isUpdateFirmwareGoing = 0;
  14032. pthread_exit(NULL);
  14033. }
  14034. int handleCertificateSignedRequest(char *uuid, char *payload)
  14035. {
  14036. mtrace();
  14037. int result = PASS;
  14038. json_object *CertificateSigned;
  14039. DEBUG_INFO("handleCertificateSignedRequest...\n");
  14040. CertificateSigned = json_tokener_parse(payload);
  14041. if(!is_error(CertificateSigned))
  14042. {
  14043. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  14044. }
  14045. json_object_put(CertificateSigned);
  14046. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  14047. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  14048. fclose(fp);
  14049. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14050. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  14051. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  14052. {
  14053. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  14054. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  14055. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  14056. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  14057. }
  14058. else
  14059. {
  14060. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  14061. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  14062. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14063. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14064. }
  14065. sendCertificateSignedConfirmation(uuid);
  14066. return result;
  14067. }
  14068. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14069. {
  14070. mtrace();
  14071. int result = PASS;
  14072. json_object *DeleteCertificate;
  14073. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14074. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14075. DeleteCertificate = json_tokener_parse(payload);
  14076. if(!is_error(DeleteCertificate))
  14077. {
  14078. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14079. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14080. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14081. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14082. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14083. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14084. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14085. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14086. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  14087. {
  14088. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  14089. }
  14090. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  14091. {
  14092. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  14093. }
  14094. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  14095. {
  14096. ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  14097. }
  14098. char temp[256] = {0};
  14099. char compareData[256] = {0};
  14100. int isMatch = TRUE;
  14101. // Check CentralSystemRootCertificate
  14102. if(access(ROOTCA_CS,F_OK) != -1)
  14103. {
  14104. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14105. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14106. for(int i = 0; compareData[i]; i++)
  14107. {
  14108. compareData[i] = tolower(compareData[i]);
  14109. }
  14110. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14111. isMatch = FALSE;
  14112. if(isMatch == TRUE)
  14113. {
  14114. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14115. for(int i = 0; compareData[i]; i++)
  14116. {
  14117. compareData[i] = tolower(compareData[i]);
  14118. }
  14119. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14120. isMatch = FALSE;
  14121. }
  14122. if(isMatch == TRUE)
  14123. {
  14124. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14125. for(int i = 0; compareData[i]; i++)
  14126. {
  14127. compareData[i] = tolower(compareData[i]);
  14128. }
  14129. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14130. isMatch = FALSE;
  14131. }
  14132. if(isMatch == TRUE)
  14133. {
  14134. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  14135. sprintf(temp, "rm -f %s", ROOTCA_CS);
  14136. system(temp);
  14137. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14138. goto End;
  14139. }
  14140. }
  14141. // Check ManufacturerRootCertificate
  14142. if(access(ROOTCA_MF,F_OK) != -1)
  14143. {
  14144. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14145. isMatch = TRUE;
  14146. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  14147. for(int i = 0; compareData[i]; i++)
  14148. {
  14149. compareData[i] = tolower(compareData[i]);
  14150. }
  14151. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14152. isMatch = FALSE;
  14153. if(isMatch == TRUE)
  14154. {
  14155. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  14156. for(int i = 0; compareData[i]; i++)
  14157. {
  14158. compareData[i] = tolower(compareData[i]);
  14159. }
  14160. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14161. isMatch = FALSE;
  14162. }
  14163. if(isMatch == TRUE)
  14164. {
  14165. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  14166. for(int i = 0; compareData[i]; i++)
  14167. {
  14168. compareData[i] = tolower(compareData[i]);
  14169. }
  14170. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14171. isMatch = FALSE;
  14172. }
  14173. if(isMatch == TRUE)
  14174. {
  14175. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  14176. sprintf(temp, "rm -f %s", ROOTCA_MF);
  14177. system(temp);
  14178. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14179. goto End;
  14180. }
  14181. }
  14182. // Check certCP
  14183. if(access(CERTIFICATE_CP,F_OK) != -1)
  14184. {
  14185. DEBUG_INFO("Checking certCP...\n");
  14186. isMatch = TRUE;
  14187. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  14188. for(int i = 0; compareData[i]; i++)
  14189. {
  14190. compareData[i] = tolower(compareData[i]);
  14191. }
  14192. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14193. isMatch = FALSE;
  14194. if(isMatch == TRUE)
  14195. {
  14196. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  14197. for(int i = 0; compareData[i]; i++)
  14198. {
  14199. compareData[i] = tolower(compareData[i]);
  14200. }
  14201. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14202. isMatch = FALSE;
  14203. }
  14204. if(isMatch == TRUE)
  14205. {
  14206. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  14207. for(int i = 0; compareData[i]; i++)
  14208. {
  14209. compareData[i] = tolower(compareData[i]);
  14210. }
  14211. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14212. isMatch = FALSE;
  14213. }
  14214. if(isMatch == TRUE)
  14215. {
  14216. DEBUG_INFO("Deleting certCP...\n");
  14217. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14218. system(temp);
  14219. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14220. goto End;
  14221. }
  14222. }
  14223. }
  14224. End:
  14225. json_object_put(DeleteCertificate);
  14226. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14227. sendDeleteCertificateConfirmation(uuid);
  14228. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14229. return result;
  14230. }
  14231. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14232. {
  14233. mtrace();
  14234. int result = PASS;
  14235. json_object *ExtendedTriggerMessage;
  14236. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14237. ExtendedTriggerMessage = json_tokener_parse(payload);
  14238. if(!is_error(ExtendedTriggerMessage))
  14239. {
  14240. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14241. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14242. {
  14243. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14244. }
  14245. else
  14246. {
  14247. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14248. }
  14249. }
  14250. json_object_put(ExtendedTriggerMessage);
  14251. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14252. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14253. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14254. {
  14255. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14256. }
  14257. else
  14258. {
  14259. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14260. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14261. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14262. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14263. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14264. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14265. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14266. {
  14267. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14268. }
  14269. else
  14270. {
  14271. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14272. }
  14273. }
  14274. sendExtendedTriggerMessageConfirmation(uuid);
  14275. //==========================
  14276. // Trigger message
  14277. //==========================
  14278. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14279. {
  14280. //sendBootNotificationRequest();
  14281. server_sign = FALSE;
  14282. }
  14283. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14284. {
  14285. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14286. }
  14287. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14288. {
  14289. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14290. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14291. {
  14292. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14293. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14294. }
  14295. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14296. }
  14297. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14298. {
  14299. refreshStartTimer(&clientTime.Heartbeat);
  14300. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14301. }
  14302. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14303. {
  14304. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14305. {
  14306. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14307. }
  14308. else
  14309. {
  14310. for(int idx=0;idx< gunTotalNumber;idx++)
  14311. {
  14312. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14313. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14314. }
  14315. }
  14316. }
  14317. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14318. {
  14319. char cmdBuf[1024]={0};
  14320. 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);
  14321. system(cmdBuf);
  14322. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14323. }
  14324. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14325. {
  14326. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14327. {
  14328. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14329. }
  14330. else
  14331. {
  14332. for(int idx=0;idx< gunTotalNumber;idx++)
  14333. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14334. }
  14335. }
  14336. return result;
  14337. }
  14338. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14339. {
  14340. mtrace();
  14341. int result = PASS;
  14342. json_object *GetInstalledCertificateIds;
  14343. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14344. GetInstalledCertificateIds = json_tokener_parse(payload);
  14345. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14346. if(!is_error(GetInstalledCertificateIds))
  14347. {
  14348. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14349. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14350. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14351. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14352. // Check CentralSystemRootCertificate
  14353. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14354. {
  14355. if(access(ROOTCA_CS,F_OK) != -1)
  14356. {
  14357. char parseData[512] = {0};
  14358. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14359. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14360. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14361. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14362. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14363. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14364. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14365. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14366. }
  14367. else
  14368. {
  14369. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14370. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14371. }
  14372. }
  14373. // Check ManufacturerRootCertificate
  14374. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14375. {
  14376. if(access(ROOTCA_MF,F_OK) != -1)
  14377. {
  14378. char parseData[512] = {0};
  14379. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14380. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14381. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  14382. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14383. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14384. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14385. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14386. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14387. }
  14388. else
  14389. {
  14390. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14391. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14392. }
  14393. }
  14394. else
  14395. {
  14396. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14397. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14398. }
  14399. }
  14400. json_object_put(GetInstalledCertificateIds);
  14401. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14402. sendGetInstalledCertificateIdsConfirmation(uuid);
  14403. return result;
  14404. }
  14405. void* GetLogProcess(void* data)
  14406. {
  14407. pthread_detach(pthread_self());
  14408. mtrace();
  14409. 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};
  14410. int port=0;
  14411. int isSuccess = FALSE;
  14412. char cmdBuf[2048];
  14413. struct tm *tmNow;
  14414. time_t CurrentTime;
  14415. struct tm tmStart;
  14416. struct tm tmStop;
  14417. CurrentTime = time(NULL);
  14418. tmNow=localtime(&CurrentTime);
  14419. uint16_t targetYear, targetMonth;
  14420. json_object *GetLog;
  14421. DEBUG_INFO("GetLogProcess...\n");
  14422. GetLog = json_tokener_parse(data);
  14423. if(!is_error(GetLog))
  14424. {
  14425. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14426. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14427. if(json_object_object_get(GetLog, "retries") != NULL)
  14428. {
  14429. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14430. }
  14431. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14432. {
  14433. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14434. }
  14435. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14436. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14437. {
  14438. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14439. }
  14440. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14441. {
  14442. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14443. }
  14444. }
  14445. json_object_put(GetLog);
  14446. // Pack log to compress file
  14447. 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) &&
  14448. (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))
  14449. {
  14450. // Pack system log
  14451. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14452. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14453. targetYear = tmStart.tm_year;
  14454. targetMonth = tmStart.tm_mon;
  14455. do
  14456. {
  14457. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14458. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14459. if(targetMonth+1>=13)
  14460. {
  14461. targetYear += 1;
  14462. targetMonth = 1;
  14463. }
  14464. else
  14465. {
  14466. targetMonth += 1;
  14467. }
  14468. }while((targetYear < (tmNow->tm_year+1900)) ||
  14469. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14470. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14471. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14472. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  14473. system(cmdBuf);
  14474. // Pack charging & event log
  14475. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14476. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14477. targetYear = tmStart.tm_year;
  14478. targetMonth = tmStart.tm_mon;
  14479. do
  14480. {
  14481. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14482. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14483. if(targetMonth+1>=13)
  14484. {
  14485. targetYear += 1;
  14486. targetMonth = 1;
  14487. }
  14488. else
  14489. {
  14490. targetMonth += 1;
  14491. }
  14492. }while((targetYear < (tmNow->tm_year+1900)) ||
  14493. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14494. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14495. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14496. system(cmdBuf);
  14497. // Combine log file
  14498. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14499. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14500. }
  14501. else
  14502. {
  14503. system("exec /root/logPackTools 'log' 6");
  14504. }
  14505. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14506. system(cmdBuf);
  14507. checkUploadLog();
  14508. //****************location*******************/
  14509. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14510. {
  14511. DEBUG_INFO("location is <Empty>!\n");
  14512. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14513. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14514. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14515. goto end;
  14516. }
  14517. memset(protocol, 0, ARRAY_SIZE(protocol));
  14518. memset(user, 0, ARRAY_SIZE(user) );
  14519. memset(password, 0, ARRAY_SIZE(password));
  14520. memset(host, 0, ARRAY_SIZE(host));
  14521. memset(path, 0, ARRAY_SIZE(path));
  14522. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14523. memset(host1, 0, ARRAY_SIZE(host1));
  14524. memset(path1, 0, ARRAY_SIZE(path1));
  14525. /*location: ftp://user:password@host:port/path*/
  14526. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14527. if((access(fnamePlusPath,F_OK))!=-1)
  14528. {
  14529. DEBUG_INFO("fnamePlusPath exist.\n");
  14530. }
  14531. else
  14532. {
  14533. DEBUG_INFO("fnamePlusPath not exist!\n");
  14534. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14535. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14536. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14537. goto end;
  14538. }
  14539. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14540. {
  14541. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14542. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14543. protocol, host, &port, path);
  14544. strcpy(user,"anonymous");
  14545. strcpy(password,"");
  14546. }
  14547. else
  14548. {
  14549. //DEBUG_INFO("pch=%s\n", pch);
  14550. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14551. protocol, user, password, host, &port, path);
  14552. }
  14553. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"sftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14554. {
  14555. DEBUG_INFO("protocol is not ftp/http ! \n");
  14556. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14557. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14558. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14559. goto end;
  14560. }
  14561. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14562. {
  14563. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14564. sprintf(ftppath,"/%s", path);
  14565. do
  14566. {
  14567. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14568. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14569. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14570. sleep(3);
  14571. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14572. if(!isSuccess)
  14573. {
  14574. DEBUG_INFO("Diagnostics fail.\n");
  14575. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14576. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14577. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14578. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14579. }
  14580. else
  14581. {
  14582. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14583. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14584. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14585. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14586. }
  14587. ShmOCPP16Data->GetLog.retries--;
  14588. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14589. }
  14590. else
  14591. {
  14592. sscanf(host,"%[^/]%s",host1, path1);
  14593. if(strlen(path) > 0)
  14594. sprintf(ftppath,"/%s", path);
  14595. else
  14596. sprintf(ftppath,"/%s", path1);
  14597. int ftppathlen=strlen(ftppath);
  14598. int i=1;
  14599. char filenametemp[50];
  14600. while(i < ftppathlen)
  14601. {
  14602. int len=ftppathlen-i;
  14603. if(ftppath[len]== 47) // '/' ascll code: 47
  14604. {
  14605. DEBUG_INFO("find '/' all right\n");
  14606. break;
  14607. }
  14608. i=i+1;
  14609. }
  14610. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14611. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14612. filenametemp[i+1] = 0;
  14613. if(port == 0)
  14614. port = 21;
  14615. do
  14616. {
  14617. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14618. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14619. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14620. sleep(3);
  14621. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"sftp", 4) == 0)
  14622. isSuccess = sftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14623. else
  14624. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14625. if(!isSuccess)
  14626. {
  14627. DEBUG_INFO("Diagnostics fail.\n");
  14628. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14629. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14630. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14631. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14632. }
  14633. else
  14634. {
  14635. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14636. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14637. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14638. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14639. }
  14640. ShmOCPP16Data->GetLog.retries--;
  14641. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14642. }
  14643. end:
  14644. system("rm -f /mnt/*");
  14645. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  14646. sleep(5);
  14647. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14648. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14649. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14650. interLock.isGetDiagnosticGoing = 0;
  14651. pthread_exit(NULL);
  14652. }
  14653. int handleGetLogRequest(char *uuid, char *payload)
  14654. {
  14655. mtrace();
  14656. int result = PASS;
  14657. time_t CurrentTime;
  14658. struct tm *tm;
  14659. DEBUG_INFO("handleGetLogRequest...\n");
  14660. pthread_t th_Status;
  14661. CurrentTime = time(NULL);
  14662. tm = localtime(&CurrentTime);
  14663. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14664. 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);
  14665. if(!interLock.isGetDiagnosticGoing)
  14666. {
  14667. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14668. interLock.isGetDiagnosticGoing = 1;
  14669. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14670. sleep(1);
  14671. }
  14672. else
  14673. {
  14674. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14675. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14676. }
  14677. sendGetLogConfirmation(uuid);
  14678. return result;
  14679. }
  14680. int handleInstallCertificateRequest(char *uuid, char *payload)
  14681. {
  14682. mtrace();
  14683. int result = PASS;
  14684. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14685. json_object *InstallCertificate;
  14686. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14687. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14688. InstallCertificate = json_tokener_parse(payload);
  14689. if(!is_error(InstallCertificate))
  14690. {
  14691. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14692. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14693. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14694. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14695. char temp[1024];
  14696. FILE *fp = fopen(tempCert, "w");
  14697. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14698. fclose(fp);
  14699. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14700. char strExpDate[30];
  14701. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14702. fp = popen(temp, "r");
  14703. if(fp)
  14704. {
  14705. while(fgets(temp, sizeof(temp), fp) != NULL)
  14706. {
  14707. if(strstr(temp, "notAfter=") != NULL)
  14708. {
  14709. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14710. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14711. break;
  14712. }
  14713. }
  14714. }
  14715. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14716. struct tm tmExpDate;
  14717. struct timeb tbExpDate;
  14718. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14719. tbExpDate.time = mktime(&tmExpDate);
  14720. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14721. {
  14722. DEBUG_INFO("The enddate is already expired...\n");
  14723. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14724. goto End;
  14725. }
  14726. // Verify certificate with rootCA
  14727. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14728. fp = popen(temp, "r");
  14729. if(fp)
  14730. {
  14731. while(fgets(temp, sizeof(temp), fp) != NULL)
  14732. {
  14733. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14734. {
  14735. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14736. break;
  14737. }
  14738. else
  14739. {
  14740. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14741. }
  14742. }
  14743. }
  14744. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14745. {
  14746. //=====================================================
  14747. // Verify if the certificate is valid or not. (OCSP?)
  14748. //=====================================================
  14749. /*
  14750. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14751. // Get ocsp url
  14752. char ocspUrl[512];
  14753. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14754. fp = popen(temp, "r");
  14755. if(fp)
  14756. {
  14757. while(fgets(temp, sizeof(temp), fp) != NULL)
  14758. {
  14759. if(strstr(temp, "://") != NULL)
  14760. {
  14761. strcpy(ocspUrl, temp);
  14762. break;
  14763. }
  14764. }
  14765. }
  14766. // Get certificate chain for issuer
  14767. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14768. *
  14769. // Execute OCSP
  14770. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14771. fp = popen(temp, "r");
  14772. if(fp)
  14773. {
  14774. while(fgets(temp, sizeof(temp), fp) != NULL)
  14775. {
  14776. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14777. {
  14778. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14779. break;
  14780. }
  14781. }
  14782. }
  14783. system("rm -f /Storage/OCPP/tempChain.pem");
  14784. pclose(fp);
  14785. */
  14786. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14787. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14788. {
  14789. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14790. goto End;
  14791. }
  14792. else
  14793. DEBUG_INFO("OCSP verifying...PASS.\n");
  14794. }
  14795. else
  14796. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14797. }
  14798. End:
  14799. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14800. {
  14801. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14802. {
  14803. if(access(ROOTCA_CS,F_OK) != -1)
  14804. {
  14805. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14806. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14807. rename(tempCert, ROOTCA_CS);
  14808. }
  14809. else
  14810. {
  14811. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14812. rename(tempCert, ROOTCA_CS);
  14813. }
  14814. }
  14815. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14816. {
  14817. if(access(ROOTCA_MF,F_OK) != -1)
  14818. {
  14819. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14820. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14821. rename(tempCert, ROOTCA_MF);
  14822. }
  14823. else
  14824. {
  14825. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14826. rename(tempCert, ROOTCA_MF);
  14827. }
  14828. }
  14829. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14830. }
  14831. sendInstallCertificateConfirmation(uuid);
  14832. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14833. {
  14834. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14835. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14836. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14837. }
  14838. json_object_put(InstallCertificate);
  14839. return result;
  14840. }
  14841. void *SignedUpdateFirmwareProcess(void *data)
  14842. {
  14843. pthread_detach(pthread_self());
  14844. mtrace();
  14845. char protocol[10], user[64],password[64],host[1280], path[1024], ftppath[1024],host1[256],path1[1024];
  14846. int port=0;
  14847. int isSuccess = 0;
  14848. char ftpbuf[2048];
  14849. char temp[2048];
  14850. char * pch;
  14851. char firmwareFileName[256];
  14852. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14853. json_object *SignedUpdateFirmware;
  14854. SignedUpdateFirmware = json_tokener_parse(data);
  14855. if(!is_error(SignedUpdateFirmware))
  14856. {
  14857. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14858. {
  14859. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14860. }
  14861. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14862. {
  14863. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14864. }
  14865. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14866. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14867. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14868. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14869. {
  14870. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14871. }
  14872. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14873. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14874. }
  14875. json_object_put(SignedUpdateFirmware);
  14876. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14877. memset(path, 0, ARRAY_SIZE(path));
  14878. // Wait retrieveData
  14879. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14880. {
  14881. do
  14882. {
  14883. sleep(1);
  14884. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14885. }
  14886. // Ready to download
  14887. system("rm -f /mnt/*");
  14888. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14889. {
  14890. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14891. sprintf(ftppath,"/%s", path);
  14892. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14893. DEBUG_INFO("protocol: %s\n",protocol);
  14894. DEBUG_INFO("host: %s\n",host);
  14895. DEBUG_INFO("path: %s\n",path);
  14896. DEBUG_INFO("ftppath: %s\n",ftppath);
  14897. int ftppathlen=strlen(ftppath);
  14898. int i=1;
  14899. while(i < ftppathlen)
  14900. {
  14901. int len=ftppathlen-i;
  14902. if(ftppath[len]== 47) // '/' ascll code: 47
  14903. {
  14904. DEBUG_INFO("compare '/' all right\n");
  14905. break;
  14906. }
  14907. i=i+1;
  14908. }
  14909. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14910. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14911. firmwareFileName[i+1] = 0;
  14912. do
  14913. {
  14914. sleep(1);
  14915. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14916. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14917. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14918. sleep(1);
  14919. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14920. if(!isSuccess)
  14921. {
  14922. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14923. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14924. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14925. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14926. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14927. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14928. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14929. }
  14930. else
  14931. {
  14932. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14933. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14934. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14935. }
  14936. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14937. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14938. }
  14939. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14940. {
  14941. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14942. memset(temp, 0, ARRAY_SIZE(temp));
  14943. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14944. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14945. int ftppathlen=strlen(ftpbuf);
  14946. int i=1;
  14947. while(i < ftppathlen)
  14948. {
  14949. int len=ftppathlen-i;
  14950. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14951. {
  14952. DEBUG_INFO(" compare '/' all right\n");
  14953. break;
  14954. }
  14955. i=i+1;
  14956. }
  14957. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14958. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14959. firmwareFileName[i+1] = 0;
  14960. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14961. pch=strchr(temp,'@');
  14962. if(pch==NULL)
  14963. {
  14964. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14965. protocol, host, &port, path);
  14966. strcpy(user,"anonymous");
  14967. strcpy(password,"");
  14968. }
  14969. else
  14970. {
  14971. char loginInfo[128];
  14972. sscanf(temp,"%[^:]:%*2[/]%[^@]@", protocol, loginInfo);
  14973. // Check if it contains 'password'
  14974. if(strstr(loginInfo, ":") != NULL)
  14975. {
  14976. sscanf(loginInfo,"%[^:]:%s", user, password);
  14977. }
  14978. else
  14979. {
  14980. strcpy(user,loginInfo);
  14981. strcpy(password,"");
  14982. }
  14983. if(strstr(pch,":") != NULL)
  14984. {
  14985. sscanf(pch,"@%[^:]:%i/%512[^\n]", host, &port, path);
  14986. sprintf(host,"%s/%s", host,path);
  14987. }
  14988. else
  14989. {
  14990. sscanf(pch,"@%s[^\n]", host);
  14991. }
  14992. //sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]", protocol, user, host, &port, path);
  14993. }
  14994. sscanf(host,"%[^/]%s",host1, path1);
  14995. sprintf(ftppath,"%s:/%s", host,path);
  14996. if(port == 0)
  14997. {
  14998. port = 22;
  14999. }
  15000. do
  15001. {
  15002. sleep(1);
  15003. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15004. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15005. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15006. sleep(1);
  15007. isSuccess = sftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15008. if(!isSuccess)
  15009. {
  15010. sleep(1);
  15011. DEBUG_INFO("Update firmware request and download file fail.\n");
  15012. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15013. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15014. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15015. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15016. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15017. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15018. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15019. }
  15020. else
  15021. {
  15022. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15023. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15024. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15025. }
  15026. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15027. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15028. }
  15029. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  15030. {
  15031. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15032. memset(temp, 0, ARRAY_SIZE(temp));
  15033. //DEBUG_INFO("locationstr=%s\n",locationstr);
  15034. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15035. int ftppathlen=strlen(ftpbuf);
  15036. int i=1;
  15037. while(i < ftppathlen)
  15038. {
  15039. int len=ftppathlen-i;
  15040. if(ftpbuf[len]== 47) // '/' ascll code: 47
  15041. {
  15042. DEBUG_INFO(" compare '/' all right\n");
  15043. break;
  15044. }
  15045. i=i+1;
  15046. }
  15047. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15048. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  15049. firmwareFileName[i+1] = 0;
  15050. strncpy(temp, ftpbuf, ftppathlen-i+1);
  15051. pch=strchr(temp,'@');
  15052. if(pch==NULL)
  15053. {
  15054. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15055. protocol, host, &port, path);
  15056. strcpy(user,"anonymous");
  15057. strcpy(password,"");
  15058. }
  15059. else
  15060. {
  15061. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  15062. protocol, user, password, host, &port, path);
  15063. }
  15064. sscanf(host,"%[^/]%s",host1, path1);
  15065. sprintf(ftppath,"%s", path1);
  15066. //DEBUG_INFO("protocol =%s\n",protocol);
  15067. //DEBUG_INFO("user =%s\n",user);
  15068. //DEBUG_INFO("password =%s\n",password);
  15069. //DEBUG_INFO("host1 =%s\n",host1);
  15070. //DEBUG_INFO("port =%d\n",port);
  15071. //DEBUG_INFO("path1 =%s\n",path1);
  15072. //DEBUG_INFO("ftppath=%s\n",ftppath);
  15073. //ftpFile(host, user, password, port, ftppath, fname);
  15074. //download firmware pthred
  15075. if(port == 0)
  15076. {
  15077. port = 21;
  15078. }
  15079. do
  15080. {
  15081. sleep(1);
  15082. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15083. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15084. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15085. sleep(1);
  15086. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15087. if(!isSuccess)
  15088. {
  15089. //BulldogUtil.sleepMs(interval*1000);
  15090. DEBUG_INFO("Update firmware request and download file fail.\n");
  15091. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15092. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15093. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15094. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15095. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15096. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15097. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15098. }
  15099. else
  15100. {
  15101. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15102. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15103. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15104. }
  15105. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15106. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15107. }
  15108. else
  15109. {
  15110. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15111. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15112. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15113. sleep(1);
  15114. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15115. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15116. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15117. }
  15118. // Verify firmware image signature
  15119. struct stat st;
  15120. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15121. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15122. fclose(fp);
  15123. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15124. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15125. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15126. fclose(fp);
  15127. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15128. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15129. if(st.st_size == 0)
  15130. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15131. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15132. {
  15133. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15134. fp = popen(temp, "r");
  15135. if(fp)
  15136. {
  15137. while(fgets(temp, sizeof(temp), fp) != NULL)
  15138. {
  15139. if(strstr(temp, "Verified OK") != NULL)
  15140. {
  15141. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15142. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15143. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15144. }
  15145. else
  15146. {
  15147. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15148. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15149. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15150. sleep(1);
  15151. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15152. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15153. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15154. sleep(1);
  15155. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15156. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15157. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15158. }
  15159. break;
  15160. }
  15161. }
  15162. pclose(fp);
  15163. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15164. }
  15165. interLock.isUpdateFirmwareGoing = 0;
  15166. pthread_exit(NULL);
  15167. }
  15168. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15169. {
  15170. mtrace();
  15171. int result = PASS;
  15172. pthread_t t;
  15173. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15174. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15175. sendSignedUpdateFirmwareConfirmation(uuid);
  15176. if(!interLock.isUpdateFirmwareGoing)
  15177. {
  15178. interLock.isUpdateFirmwareGoing = 1;
  15179. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15180. sleep(1);
  15181. }
  15182. else
  15183. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15184. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15185. return result;
  15186. }
  15187. int handleUnknownRequest(char *uuid, char *payload)
  15188. {
  15189. mtrace();
  15190. int result = PASS;
  15191. DEBUG_INFO("handleUnknownRequest...\n");
  15192. sendUnknownConfirmation(uuid);
  15193. return result;
  15194. }
  15195. //==========================================
  15196. // Handle server response routine
  15197. //==========================================
  15198. void handleAuthorizeResponse(char *payload, int gun_index)
  15199. {
  15200. mtrace();
  15201. char expiryDatestr[36]={0};
  15202. char parentIdTagstr[21]={0};
  15203. char statusstr[20]={0};
  15204. int expiryDateISNULL=FALSE;
  15205. int parentIdTagISNULL=FALSE;
  15206. DEBUG_INFO("handleAuthorizeResponse...\n");
  15207. json_object *Authorize;
  15208. Authorize = json_tokener_parse(payload);
  15209. if(!is_error(Authorize))
  15210. {
  15211. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15212. {
  15213. // Required data
  15214. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15215. // Optional data
  15216. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15217. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15218. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15219. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15220. }
  15221. }
  15222. json_object_put(Authorize);
  15223. if(expiryDateISNULL == FALSE)
  15224. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15225. if(parentIdTagISNULL == FALSE)
  15226. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15227. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15228. //Update idTag information to authorization cache if supproted
  15229. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15230. {
  15231. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15232. }
  15233. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15234. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15235. authorizeRetryTimes = 0;
  15236. }
  15237. void handleBootNotificationResponse(char *payload, int gun_index)
  15238. {
  15239. mtrace();
  15240. char statusStr[12]={0};
  15241. char currentTimeStr[30]={0};
  15242. int intervalInt = 0;
  15243. DEBUG_INFO("handleBootNotificationResponse...\n");
  15244. json_object *BootNotification;
  15245. BootNotification = json_tokener_parse(payload);
  15246. if(!is_error(BootNotification))
  15247. {
  15248. // Required data
  15249. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15250. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15251. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15252. }
  15253. json_object_put(BootNotification);
  15254. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15255. BootNotificationInterval = intervalInt;
  15256. //write back to ShmOCPP16Data->BootNotification
  15257. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15258. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15259. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15260. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15261. {
  15262. BootNotificationInterval = 0;
  15263. if((intervalInt == 0) || (intervalInt >= 10))
  15264. {
  15265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15266. HeartBeatWaitTime = intervalInt;
  15267. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15268. }
  15269. server_sign = TRUE;
  15270. server_pending =FALSE;
  15271. }
  15272. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15273. {
  15274. server_pending = TRUE;
  15275. }
  15276. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15277. srand(time(NULL));
  15278. refreshStartTimer(&clientTime.Heartbeat);
  15279. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15280. SetOcppConnStatus(TRUE);
  15281. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15282. }
  15283. void handleDataTransferResponse(char *payload, int gun_index)
  15284. {
  15285. json_object *DataTransfer = json_tokener_parse(payload);
  15286. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15287. if(!is_error(DataTransfer))
  15288. {
  15289. // Required data
  15290. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15291. // Optional data
  15292. if(json_object_object_get(DataTransfer, "data") != NULL)
  15293. {
  15294. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15295. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15296. if(!is_error(Data))
  15297. {
  15298. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15299. {
  15300. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15301. {
  15302. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15303. }
  15304. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15305. {
  15306. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15307. {
  15308. 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")));
  15309. }
  15310. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15311. {
  15312. 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")));
  15313. }
  15314. }
  15315. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15316. }
  15317. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15318. {
  15319. if(json_object_object_get(Data, "status") != NULL)
  15320. {
  15321. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15322. }
  15323. if(json_object_object_get(Data, "exiResponse") != NULL)
  15324. {
  15325. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15326. }
  15327. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15328. }
  15329. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15330. {
  15331. if(json_object_object_get(Data, "status") != NULL)
  15332. {
  15333. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15334. }
  15335. if(json_object_object_get(Data, "ocspResult") != NULL)
  15336. {
  15337. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15338. }
  15339. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15340. }
  15341. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15342. {
  15343. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15344. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15345. }
  15346. else
  15347. {
  15348. if(json_object_object_get(Data, "msgId") != NULL)
  15349. {
  15350. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15351. {
  15352. 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")));
  15353. }
  15354. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15355. {
  15356. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15357. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15358. }
  15359. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeAct") != NULL)
  15360. {
  15361. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15362. {
  15363. 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")));
  15364. if(json_object_object_get(Data, "occupancySN") != NULL)
  15365. 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")));
  15366. if(json_object_object_get(Data, "startTime") != NULL)
  15367. 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")));
  15368. if(json_object_object_get(Data, "duration") != NULL)
  15369. 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"));
  15370. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15371. 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"));
  15372. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].OccupancyFeeActReq = 0;
  15373. }
  15374. else
  15375. {
  15376. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15377. {
  15378. if(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq)
  15379. {
  15380. strcpy((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].response_status, "Rejected");
  15381. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq = 0;
  15382. }
  15383. }
  15384. }
  15385. }
  15386. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15387. {
  15388. if(json_object_object_get(Data, "occupancySN") != NULL)
  15389. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15390. }
  15391. }
  15392. }
  15393. }
  15394. json_object_put(Data);
  15395. }
  15396. }
  15397. json_object_put(DataTransfer);
  15398. }
  15399. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15400. {
  15401. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15402. //struct json_object *obj;
  15403. // obj = json_tokener_parse(payload);
  15404. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15405. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15406. //No fields are defined.
  15407. }
  15408. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15409. {
  15410. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15411. //struct json_object *obj;
  15412. // obj = json_tokener_parse(payload);
  15413. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15414. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15415. //No fields are defined.
  15416. }
  15417. void handleHeartbeatResponse(char *payload, int gun_index)
  15418. {
  15419. mtrace();
  15420. DEBUG_INFO("handleHeartbeatResponse...\n");
  15421. json_object *Heartbeat;
  15422. Heartbeat = json_tokener_parse(payload);
  15423. if(!is_error(Heartbeat))
  15424. {
  15425. // Required data
  15426. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15427. }
  15428. json_object_put(Heartbeat);
  15429. if(FirstHeartBeat == 0)
  15430. {
  15431. FirstHeartBeat = 1;
  15432. DEBUG_INFO("FirstHeartBeat \n");
  15433. }
  15434. HeartBeatWithNOResponse = 0;
  15435. refreshStartTimer(&clientTime.Heartbeat);
  15436. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15437. }
  15438. void handleMeterValuesResponse(char *payload, int gun_index)
  15439. {
  15440. mtrace();
  15441. DEBUG_INFO("handleMeterValuesResponse...\n");
  15442. isQueueSendable = 1;
  15443. }
  15444. void handleStartTransactionResponse(char *payload, int gun_index)
  15445. {
  15446. mtrace();
  15447. //int transactionIdInt = 0;
  15448. FILE *outfile;
  15449. char data[100]={0};
  15450. DEBUG_INFO("handleStartTransactionResponse...\n");
  15451. json_object *StartTransaction;
  15452. StartTransaction = json_tokener_parse(payload);
  15453. if(!is_error(StartTransaction))
  15454. {
  15455. // Required data
  15456. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15457. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15458. // Optional data
  15459. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15460. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15461. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15462. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15463. }
  15464. json_object_put(StartTransaction);
  15465. OCPP_updatePeriodEnergy(gun_index);
  15466. //-----------Start : write to the Queue TransactionId file -----------------//
  15467. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15468. {}
  15469. else
  15470. {
  15471. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15472. if(log == NULL)
  15473. {
  15474. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15475. return ;
  15476. }
  15477. else
  15478. {
  15479. fclose(log);
  15480. }
  15481. }
  15482. // open file for writing
  15483. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15484. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15485. {
  15486. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15487. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15488. fputs(data, outfile);
  15489. fclose (outfile);
  15490. DEBUG_INFO("Update QueueTransactionId done...\n");
  15491. }
  15492. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15493. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15494. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15495. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15496. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15497. isQueueSendable = 1;
  15498. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15499. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15500. }
  15501. void handleStatusNotificationResponse(char *payload, int gun_index)
  15502. {
  15503. mtrace();
  15504. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15505. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15506. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15507. if(gun_index != 99)
  15508. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15509. }
  15510. void handleStopTransactionnResponse(char *payload, int gun_index)
  15511. {
  15512. mtrace();
  15513. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15514. json_object *StopTransaction;
  15515. StopTransaction = json_tokener_parse(payload);
  15516. if(!is_error(StopTransaction))
  15517. {
  15518. // Optional data
  15519. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15520. {
  15521. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15522. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15523. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15524. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15526. }
  15527. }
  15528. json_object_put(StopTransaction);
  15529. isQueueSendable = 1;
  15530. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15531. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15532. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15533. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15534. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15535. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15536. }
  15537. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15538. {
  15539. mtrace();
  15540. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15541. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15542. }
  15543. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15544. {
  15545. mtrace();
  15546. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15547. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15548. }
  15549. void handleSignCertificateResponse(char *payload, int gun_index)
  15550. {
  15551. mtrace();
  15552. DEBUG_INFO("handleSignCertificateResponse...\n");
  15553. json_object *SignCertificate;
  15554. SignCertificate = json_tokener_parse(payload);
  15555. if(!is_error(SignCertificate))
  15556. {
  15557. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15558. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15559. }
  15560. json_object_put(SignCertificate);
  15561. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15562. }
  15563. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15564. {
  15565. mtrace();
  15566. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15567. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15568. }
  15569. //==========================================
  15570. // Handle Error routine
  15571. //==========================================
  15572. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15573. {
  15574. mtrace();
  15575. #ifdef SystemLogMessage
  15576. DEBUG_INFO("errorCode: %s\n", errorCode);
  15577. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15578. DEBUG_INFO("errorDetails: %s\n", payload);
  15579. #endif
  15580. }
  15581. //===============================================
  15582. // Common routine
  15583. //===============================================
  15584. int initialConfigurationTable(void)
  15585. {
  15586. //clock_t start_t, end_t, total_t;
  15587. FILE *fp;
  15588. FILE *outfile;
  15589. char str[1024]={0};
  15590. int confVersion = 28;
  15591. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15592. //start_t = clock();
  15593. //printf("Starting of the program, start_t = %ld\n", start_t);
  15594. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15595. // Check configuration file size is correct
  15596. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15597. {
  15598. struct stat st;
  15599. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15600. if(st.st_size < 3100)
  15601. {
  15602. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15603. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15604. }
  15605. }
  15606. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15607. {
  15608. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15609. if(outfile == NULL)
  15610. {
  15611. DEBUG_INFO("Error opening file\n");
  15612. return FALSE;
  15613. }
  15614. /*Core Profile*/
  15615. //AllowOfflineTxForUnknownId
  15616. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15620. //AuthorizationCacheEnabled
  15621. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15625. //AuthorizeRemoteTxRequests
  15626. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15630. //BlinkRepeat
  15631. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15635. //ClockAlignedDataInterval
  15636. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15640. //ConnectionTimeOut
  15641. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15643. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15645. else
  15646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15648. //GetConfigurationMaxKeys
  15649. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15653. // HeartbeatInterval
  15654. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15658. // LightIntensity
  15659. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15663. // LocalAuthorizeOffline
  15664. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15668. // LocalPreAuthorize
  15669. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15673. // MaxEnergyOnInvalidId
  15674. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15678. // MeterValuesAlignedData
  15679. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15681. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15682. 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" );
  15683. else
  15684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15686. // MeterValuesAlignedDataMaxLength
  15687. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15691. else
  15692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15694. // MeterValuesSampledData
  15695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15698. 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" );
  15699. else
  15700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15702. // MeterValuesSampledDataMaxLength
  15703. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15705. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15707. else
  15708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15710. // MeterValueSampleInterval
  15711. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15715. // MinimumStatusDuration
  15716. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15719. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15721. // NumberOfConnectors
  15722. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15724. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15725. {
  15726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15727. }
  15728. else
  15729. {
  15730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15731. }
  15732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15733. // ResetRetries
  15734. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15738. // ConnectorPhaseRotation
  15739. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15743. // ConnectorPhaseRotationMaxLength
  15744. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15748. // StopTransactionOnEVSideDisconnect
  15749. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15753. // StopTransactionOnInvalidId
  15754. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15758. // StopTxnAlignedData
  15759. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15763. // StopTxnAlignedDataMaxLength
  15764. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15766. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15767. {
  15768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15769. }
  15770. else
  15771. {
  15772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15773. }
  15774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15775. // StopTxnSampledData
  15776. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15780. // StopTxnSampledDataMaxLength
  15781. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15784. {
  15785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15786. }
  15787. else
  15788. {
  15789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15790. }
  15791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15792. // SupportedFeatureProfiles
  15793. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15797. // SupportedFeatureProfilesMaxLength
  15798. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15802. // TransactionMessageAttempts
  15803. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15806. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15808. // TransactionMessageRetryInterval
  15809. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15812. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15814. // UnlockConnectorOnEVSideDisconnect
  15815. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15819. // WebSocketPingInterval
  15820. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15824. // QueueOffLineMeterValues
  15825. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15829. // AuthorizationKey
  15830. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15834. // SecurityProfile
  15835. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15839. // DefaultPrice
  15840. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15844. // CustomDisplayCostAndPrice
  15845. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15849. // CustomIdleFeeAfterStop
  15850. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15854. // TimeOffset
  15855. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15859. // NextTimeOffsetTransitionDateTime
  15860. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15864. // TimeOffsetNextTransition
  15865. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15869. // SystemUptimeSec
  15870. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15874. // FreeVend
  15875. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15879. // FreeVendIdtag
  15880. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15884. // OcppServer
  15885. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15887. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15889. // MaintainServer
  15890. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15892. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15894. // StatusNotificationPeriodically
  15895. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15899. // StatusNotificationInterval
  15900. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15904. // PreAuthAmount
  15905. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15909. // isEnableLocalPowerSharing
  15910. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15914. // PowerSharingServerIP
  15915. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15917. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15919. // EVCCID_PREFIX
  15920. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15924. // OffLineMaxChargingPower
  15925. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15929. // Configuration Version
  15930. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15934. // Charging profile refresh interval
  15935. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15939. // CpoName
  15940. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15944. // Ocpp Software certificated version
  15945. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15949. // Check certificate of download link
  15950. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  15951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  15952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "FALSE");
  15953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  15954. // RFID endian type
  15955. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  15956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  15957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE"));
  15958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  15959. // Authorization timeout
  15960. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  15961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  15962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "15");
  15963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  15964. // Enable AC charger CCS function
  15965. ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility = 1;
  15966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemName, "Enable15118");
  15967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData, (ShmSysConfigAndInfo->SysConfig.isEnable15118==1?"TRUE":"FALSE"));
  15968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","Enable15118", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData);
  15969. // Wifi SSID
  15970. ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemAccessibility = 1;
  15971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemName, "WifiSsid");
  15972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  15973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WifiSsid", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemData);
  15974. // Wifi password
  15975. ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemAccessibility = 1;
  15976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemName, "WifiPassword");
  15977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  15978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WifiPassword", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemData);
  15979. // Stop Charging By Button
  15980. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemAccessibility = 1;
  15981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemName, "StopChargingByButton");
  15982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData, (ShmSysConfigAndInfo->SysConfig.StopChargingByButton==1?"TRUE":"FALSE"));
  15983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopChargingByButton", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData);
  15984. //* Local Auth List Management Profile*/
  15985. #if 0
  15986. //For OCTT Test Case
  15987. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15990. #endif
  15991. #if 1
  15992. //LocalAuthListEnabled
  15993. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15997. #endif
  15998. //LocalAuthListMaxLength
  15999. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  16002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16003. //SendLocalListMaxLength
  16004. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  16007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16008. //ReserveConnectorZeroSupported
  16009. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16013. //* Smart Charging Profile */
  16014. //ChargeProfileMaxStackLevel
  16015. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  16018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16019. // ChargingScheduleAllowedChargingRateUnit
  16020. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  16023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16024. // ChargingScheduleMaxPeriods
  16025. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16029. // ConnectorSwitch3to1PhaseSupported
  16030. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  16033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16034. // MaxChargingProfilesInstalled
  16035. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  16038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16039. fclose(outfile);
  16040. }
  16041. else
  16042. {
  16043. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  16044. char keystr[60]={0};
  16045. char readonlystr[10]={0};
  16046. char valuestr[501]={0};
  16047. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  16048. if(fp == NULL) {
  16049. DEBUG_INFO("Error opening file");
  16050. return FALSE;
  16051. }
  16052. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  16053. {
  16054. //DEBUG_INFO("Get Configuration \n");
  16055. if(strlen(str) > 0)
  16056. {
  16057. json_object *OCPPConfiguration;
  16058. OCPPConfiguration = json_tokener_parse(str);
  16059. if(json_object_object_get(OCPPConfiguration, "key") != NULL)
  16060. strcpy(keystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"key")));
  16061. if(json_object_object_get(OCPPConfiguration, "readonly") != NULL)
  16062. strcpy(readonlystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"readonly")));
  16063. if(json_object_object_get(OCPPConfiguration, "value") != NULL)
  16064. strcpy(valuestr, json_object_get_string(json_object_object_get(OCPPConfiguration,"value")));
  16065. json_object_put(OCPPConfiguration);
  16066. // DEBUG_INFO("keystr=%s\n",keystr);
  16067. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  16068. // DEBUG_INFO("valuestr=%s\n",valuestr);
  16069. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  16070. {
  16071. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16072. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  16074. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16075. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16076. }
  16077. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  16078. {
  16079. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16080. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  16082. }
  16083. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  16084. {
  16085. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  16087. }
  16088. if(strcmp(keystr, "BlinkRepeat") == 0)
  16089. {
  16090. //Charger.BlinkRepeat = Integer.parseInt(value);
  16091. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  16093. }
  16094. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  16095. {
  16096. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16098. }
  16099. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16100. {
  16101. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16103. }
  16104. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16105. {
  16106. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16108. }
  16109. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16110. {
  16111. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16113. HeartBeatWaitTime = atoi(valuestr);
  16114. }
  16115. if(strcmp(keystr, "LightIntensity") == 0)
  16116. {
  16117. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16119. }
  16120. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16121. {
  16122. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16124. }
  16125. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16126. {
  16127. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16129. }
  16130. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16131. {
  16132. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16134. }
  16135. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16136. {
  16137. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16139. }
  16140. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16141. {
  16142. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16144. }
  16145. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16146. {
  16147. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16149. }
  16150. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16151. {
  16152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16154. }
  16155. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16156. {
  16157. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16159. }
  16160. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16161. {
  16162. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16164. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16165. }
  16166. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16167. {
  16168. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16170. }
  16171. if(strcmp(keystr, "ResetRetries") == 0)
  16172. {
  16173. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16175. }
  16176. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16177. {
  16178. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16180. }
  16181. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16182. {
  16183. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16185. }
  16186. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16187. {
  16188. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16190. }
  16191. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16192. {
  16193. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16195. }
  16196. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16197. {
  16198. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16200. }
  16201. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16202. {
  16203. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16205. }
  16206. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16207. {
  16208. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16210. }
  16211. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16212. {
  16213. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16215. }
  16216. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16217. {
  16218. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16220. }
  16221. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16222. {
  16223. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16225. }
  16226. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16227. {
  16228. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16230. TransactionMessageAttemptsValue = atoi(valuestr);
  16231. }
  16232. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16233. {
  16234. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16236. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16237. }
  16238. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16239. {
  16240. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16242. }
  16243. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16244. {
  16245. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16247. }
  16248. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16249. {
  16250. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16252. }
  16253. if(strcmp(keystr, "AuthorizationKey") == 0)
  16254. {
  16255. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16256. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16258. }
  16259. if(strcmp(keystr, "SecurityProfile") == 0)
  16260. {
  16261. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16263. }
  16264. if(strcmp(keystr, "DefaultPrice") == 0)
  16265. {
  16266. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16268. }
  16269. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16270. {
  16271. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16273. }
  16274. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16275. {
  16276. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16278. }
  16279. if(strcmp(keystr, "TimeOffset") == 0)
  16280. {
  16281. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16283. }
  16284. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16285. {
  16286. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16288. }
  16289. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16290. {
  16291. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16293. }
  16294. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16295. {
  16296. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16298. }
  16299. if(strcmp(keystr, "FreeVend") == 0)
  16300. {
  16301. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16303. }
  16304. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16305. {
  16306. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16308. }
  16309. if(strcmp(keystr, "OcppServer") == 0)
  16310. {
  16311. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16312. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16313. }
  16314. if(strcmp(keystr, "MaintainServer") == 0)
  16315. {
  16316. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16317. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16318. }
  16319. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16320. {
  16321. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16323. }
  16324. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16325. {
  16326. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16328. }
  16329. if(strcmp(keystr, "PreAuthAmount") == 0)
  16330. {
  16331. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16333. }
  16334. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16335. {
  16336. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16338. }
  16339. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16340. {
  16341. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16342. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16343. }
  16344. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16345. {
  16346. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16348. }
  16349. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16350. {
  16351. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16353. }
  16354. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16355. {
  16356. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16358. }
  16359. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16360. {
  16361. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16363. }
  16364. if(strcmp(keystr, "CpoName") == 0)
  16365. {
  16366. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16368. }
  16369. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16370. {
  16371. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16373. }
  16374. if(strcmp(keystr, "AuthDownloadlinkCertificate") == 0)
  16375. {
  16376. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", valuestr);
  16378. }
  16379. if(strcmp(keystr, "RfidEndianType") == 0)
  16380. {
  16381. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE"));
  16383. }
  16384. if(strcmp(keystr, "AuthorizeTimeout") == 0)
  16385. {
  16386. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%s", valuestr);
  16388. }
  16389. if(strcmp(keystr, "Enable15118") == 0)
  16390. {
  16391. ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.isEnable15118==1?"TRUE":"FALSE"));
  16393. }
  16394. if(strcmp(keystr, "WifiSsid") == 0)
  16395. {
  16396. ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  16398. }
  16399. if(strcmp(keystr, "WifiPassword") == 0)
  16400. {
  16401. ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  16403. }
  16404. if(strcmp(keystr, "StopChargingByButton") == 0)
  16405. {
  16406. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.StopChargingByButton==1?"TRUE":"FALSE"));
  16408. }
  16409. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16410. {
  16411. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16413. }
  16414. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16415. {
  16416. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16418. }
  16419. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16420. {
  16421. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16423. }
  16424. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16425. {
  16426. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16428. }
  16429. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16430. {
  16431. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16433. }
  16434. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16435. {
  16436. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16438. }
  16439. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16440. {
  16441. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16443. }
  16444. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16445. {
  16446. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16448. }
  16449. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16450. {
  16451. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16453. }
  16454. }
  16455. }
  16456. fclose(fp);
  16457. }
  16458. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16459. {
  16460. return PASS;
  16461. }
  16462. else
  16463. {
  16464. return FAIL;
  16465. }
  16466. }
  16467. void StoreConfigurationTable(void)
  16468. {
  16469. FILE *outfile;
  16470. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16471. if(outfile == NULL)
  16472. {
  16473. DEBUG_INFO("Error opening file");
  16474. return ;
  16475. }
  16476. /*Core Profile*/
  16477. //AllowOfflineTxForUnknownId
  16478. /*
  16479. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16480. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16483. */
  16484. //DEBUG_INFO("data=%s\n",data);
  16485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16486. //AuthorizationCacheEnabled
  16487. /*
  16488. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16491. */
  16492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16493. //AuthorizeRemoteTxRequests
  16494. /*
  16495. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16498. */
  16499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16500. //BlinkRepeat
  16501. /*
  16502. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16505. */
  16506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16507. //ClockAlignedDataInterval
  16508. /*
  16509. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16512. */
  16513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16514. //ConnectionTimeOut
  16515. /*
  16516. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16519. */
  16520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16521. //GetConfigurationMaxKeys
  16522. /*
  16523. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16526. */
  16527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16528. // HeartbeatInterval
  16529. /*
  16530. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16533. */
  16534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16535. // LightIntensity
  16536. /*
  16537. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16540. */
  16541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16542. // LocalAuthorizeOffline
  16543. /*
  16544. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16547. */
  16548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16549. // LocalPreAuthorize
  16550. /*
  16551. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16554. */
  16555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16556. // MaxEnergyOnInvalidId
  16557. /*
  16558. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16561. */
  16562. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16564. // MeterValuesAlignedData
  16565. /*
  16566. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16569. */
  16570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16571. // MeterValuesAlignedDataMaxLength
  16572. /*
  16573. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16576. */
  16577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16578. // MeterValuesSampledData
  16579. /*
  16580. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16583. */
  16584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16585. // MeterValuesSampledDataMaxLength
  16586. /*
  16587. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16590. */
  16591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16592. // MeterValueSampleInterval
  16593. /*
  16594. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16597. */
  16598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16599. // MinimumStatusDuration
  16600. /*
  16601. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16604. */
  16605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16606. // NumberOfConnectors
  16607. /*
  16608. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16610. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16611. {
  16612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16613. }
  16614. else
  16615. {
  16616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16617. }
  16618. */
  16619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16620. // ResetRetries
  16621. /*
  16622. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16625. */
  16626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16627. // ConnectorPhaseRotation
  16628. /*
  16629. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16632. */
  16633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16634. // ConnectorPhaseRotationMaxLength
  16635. /*
  16636. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16639. */
  16640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16641. // StopTransactionOnEVSideDisconnect
  16642. /*
  16643. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16646. */
  16647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16648. // StopTransactionOnInvalidId
  16649. /*
  16650. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16653. */
  16654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16655. // StopTxnAlignedData
  16656. /*
  16657. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16660. */
  16661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16662. // StopTxnAlignedDataMaxLength
  16663. /*
  16664. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16667. */
  16668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16669. // StopTxnSampledData
  16670. /*
  16671. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16674. */
  16675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16676. // StopTxnSampledDataMaxLength
  16677. /*
  16678. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16681. */
  16682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16683. // SupportedFeatureProfiles
  16684. /*
  16685. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16688. */
  16689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16690. // SupportedFeatureProfilesMaxLength
  16691. /*
  16692. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16695. */
  16696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16697. // TransactionMessageAttempts
  16698. /*
  16699. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16702. */
  16703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16704. // TransactionMessageRetryInterval
  16705. /*
  16706. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16709. */
  16710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16711. // UnlockConnectorOnEVSideDisconnect
  16712. /*
  16713. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16716. */
  16717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16718. // WebSocketPingInterval
  16719. /*
  16720. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16723. */
  16724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16725. // QueueOffLineMeterValues
  16726. /*
  16727. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16730. */
  16731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16732. // AuthorizationKey
  16733. /*
  16734. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16737. */
  16738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16739. // SecurityProfile
  16740. /*
  16741. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16744. */
  16745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16746. // DefaultPrice
  16747. /*
  16748. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16751. */
  16752. json_object *tmp;
  16753. tmp = json_tokener_parse((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16754. if(!is_error(tmp))
  16755. {
  16756. DEBUG_INFO("JSON string type\n");
  16757. json_object *target = json_object_new_object();
  16758. json_object_object_add(target, "key", json_object_new_string("DefaultPrice"));
  16759. json_object_object_add(target, "readonly", (ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility?json_object_new_boolean(0):json_object_new_boolean(1)));
  16760. json_object_object_add(target, "value", json_object_new_string((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData));
  16761. fprintf(outfile, "%s\n", json_object_to_json_string_ext(target, JSON_C_TO_STRING_PLAIN));
  16762. json_object_put(target);
  16763. }
  16764. else
  16765. {
  16766. DEBUG_INFO("Normal string type\n");
  16767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16768. }
  16769. json_object_put(tmp);
  16770. // CustomDisplayCostAndPrice
  16771. /*
  16772. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16775. */
  16776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16777. // CustomIdleFeeAfterStop
  16778. /*
  16779. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16782. */
  16783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16784. // TimeOffset
  16785. /*
  16786. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16789. */
  16790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16791. // NextTimeOffsetTransitionDateTime
  16792. /*
  16793. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16796. */
  16797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16798. // TimeOffsetNextTransition
  16799. /*
  16800. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16803. */
  16804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16805. // SystemUptimeSec
  16806. /*
  16807. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16810. */
  16811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16812. // FreeVend
  16813. /*
  16814. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16817. */
  16818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16819. // FreeVendIdtag
  16820. /*
  16821. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16824. */
  16825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16826. // OcppServer
  16827. /*
  16828. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16831. */
  16832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16833. // MaintainServer
  16834. /*
  16835. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16838. */
  16839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16840. // StatusNotificationPeriodically
  16841. /*
  16842. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16845. */
  16846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16847. // StatusNotificationInterval
  16848. /*
  16849. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16852. */
  16853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16854. // PreAuthAmount
  16855. /*
  16856. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16859. */
  16860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16861. // isEnableLocalPowerSharing
  16862. /*
  16863. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16866. */
  16867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16868. // PowerSharingServerIP
  16869. /*
  16870. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16873. */
  16874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16875. // EVCCID_PREFIX
  16876. /*
  16877. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16880. */
  16881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16882. // OffLineMaxChargingPower
  16883. /*
  16884. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16887. */
  16888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16889. // ConfigurationVersion
  16890. /*
  16891. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16894. */
  16895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16896. // CharingProfileRefreshInterval
  16897. /*
  16898. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16901. */
  16902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16903. // CpoName
  16904. /*
  16905. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16908. */
  16909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16910. // OcppSoftwareVersion
  16911. /*
  16912. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16915. */
  16916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16917. // AuthDownloadlinkCertificate
  16918. /*
  16919. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  16920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  16921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE" );
  16922. */
  16923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  16924. // RfidEndianType
  16925. /*
  16926. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  16927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  16928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "BIG" );
  16929. */
  16930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  16931. // AuthorizeTimeout
  16932. /*
  16933. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  16934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  16935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "60" );
  16936. */
  16937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  16938. // Enable15118
  16939. /*
  16940. ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility = 1;
  16941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemName, "Enable15118");
  16942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData, "TRUE" );
  16943. */
  16944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","Enable15118", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData);
  16945. // WifiSsid
  16946. /*
  16947. ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemAccessibility = 1;
  16948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemName, "WifiSsid");
  16949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemData, "TRUE" );
  16950. */
  16951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WifiSsid", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemData);
  16952. // WifiPassword
  16953. /*
  16954. ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemAccessibility = 1;
  16955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemName, "WifiPassword");
  16956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemData, "TRUE" );
  16957. */
  16958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WifiPassword", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemData);
  16959. // StopChargingByButton
  16960. /*
  16961. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemAccessibility = 1;
  16962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemName, "StopChargingByButton");
  16963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData, "TRUE" );
  16964. */
  16965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopChargingByButton", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData);
  16966. //* Local Auth List Management Profile*/
  16967. //LocalAuthListEnabled
  16968. /*
  16969. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16972. */
  16973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16974. //LocalAuthListMaxLength
  16975. /*
  16976. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16979. */
  16980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16981. //SendLocalListMaxLength
  16982. /*
  16983. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16986. */
  16987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16988. //ReserveConnectorZeroSupported
  16989. /*
  16990. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16993. */
  16994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16995. //* Smart Charging Profile */
  16996. //ChargeProfileMaxStackLevel
  16997. /*
  16998. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  17000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  17001. */
  17002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17003. // ChargingScheduleAllowedChargingRateUnit
  17004. /*
  17005. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  17006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  17007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  17008. */
  17009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17010. // ChargingScheduleMaxPeriods
  17011. /*
  17012. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  17013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  17014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  17015. */
  17016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17017. // ConnectorSwitch3to1PhaseSupported
  17018. /*
  17019. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  17020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  17021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  17022. */
  17023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17024. // MaxChargingProfilesInstalled
  17025. /*
  17026. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  17027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  17028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  17029. */
  17030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17031. fclose(outfile);
  17032. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17033. }
  17034. void getKeyValue(char *keyReq)
  17035. {
  17036. int isEmpty = FALSE;
  17037. int isKnowKey = FALSE;
  17038. DEBUG_INFO("keyReq = %s\n", keyReq);
  17039. if((keyReq == NULL) || (strlen(keyReq) == 0))
  17040. isEmpty = TRUE;
  17041. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  17042. {
  17043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  17044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  17045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17046. {
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  17048. }
  17049. else
  17050. {
  17051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  17052. }
  17053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  17054. isKnowKey = TRUE;
  17055. }
  17056. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  17057. {
  17058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  17059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  17060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17061. {
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  17063. }
  17064. else
  17065. {
  17066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  17067. }
  17068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  17069. isKnowKey = TRUE;
  17070. }
  17071. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  17072. {
  17073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  17074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  17075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17076. {
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  17078. }
  17079. else
  17080. {
  17081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  17082. }
  17083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  17084. isKnowKey = TRUE;
  17085. }
  17086. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  17087. {
  17088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  17089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  17090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17091. {
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  17093. }
  17094. else
  17095. {
  17096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  17097. }
  17098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  17099. isKnowKey = TRUE;
  17100. }
  17101. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  17102. {
  17103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  17104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  17105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17106. {
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  17108. }
  17109. else
  17110. {
  17111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  17112. }
  17113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  17114. isKnowKey = TRUE;
  17115. }
  17116. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  17117. {
  17118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  17119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  17120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17121. {
  17122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  17123. }
  17124. else
  17125. {
  17126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  17127. }
  17128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  17129. isKnowKey = TRUE;
  17130. }
  17131. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  17132. {
  17133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  17134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  17135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17136. {
  17137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  17138. }
  17139. else
  17140. {
  17141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  17142. }
  17143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  17144. isKnowKey = TRUE;
  17145. }
  17146. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  17147. {
  17148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  17149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  17150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17151. {
  17152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  17153. }
  17154. else
  17155. {
  17156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  17157. }
  17158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  17159. isKnowKey = TRUE;
  17160. }
  17161. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17162. {
  17163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17166. {
  17167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17168. }
  17169. else
  17170. {
  17171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17172. }
  17173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17174. isKnowKey = TRUE;
  17175. }
  17176. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17177. {
  17178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17181. {
  17182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17183. }
  17184. else
  17185. {
  17186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17187. }
  17188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17189. isKnowKey = TRUE;
  17190. }
  17191. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17192. {
  17193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17196. {
  17197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17198. }
  17199. else
  17200. {
  17201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17202. }
  17203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17204. isKnowKey = TRUE;
  17205. }
  17206. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17207. {
  17208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17211. {
  17212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17213. }
  17214. else
  17215. {
  17216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17217. }
  17218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17219. isKnowKey = TRUE;
  17220. }
  17221. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17222. {
  17223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17226. {
  17227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17228. }
  17229. else
  17230. {
  17231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17232. }
  17233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17234. isKnowKey = TRUE;
  17235. }
  17236. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17237. {
  17238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17241. {
  17242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17243. }
  17244. else
  17245. {
  17246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17247. }
  17248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17249. isKnowKey = TRUE;
  17250. }
  17251. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17252. {
  17253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17256. {
  17257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17258. }
  17259. else
  17260. {
  17261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17262. }
  17263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17264. isKnowKey = TRUE;
  17265. }
  17266. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17267. {
  17268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17271. {
  17272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17273. }
  17274. else
  17275. {
  17276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17277. }
  17278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17279. isKnowKey = TRUE;
  17280. }
  17281. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17282. {
  17283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17286. {
  17287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17288. }
  17289. else
  17290. {
  17291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17292. }
  17293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17294. isKnowKey = TRUE;
  17295. }
  17296. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17297. {
  17298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17301. {
  17302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17303. }
  17304. else
  17305. {
  17306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17307. }
  17308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17309. isKnowKey = TRUE;
  17310. }
  17311. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17312. {
  17313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17316. {
  17317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17318. }
  17319. else
  17320. {
  17321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17322. }
  17323. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17325. isKnowKey = TRUE;
  17326. }
  17327. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17328. {
  17329. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17332. {
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17334. }
  17335. else
  17336. {
  17337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17338. }
  17339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17340. isKnowKey = TRUE;
  17341. }
  17342. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17343. {
  17344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17347. {
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17349. }
  17350. else
  17351. {
  17352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17353. }
  17354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17355. isKnowKey = TRUE;
  17356. }
  17357. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17358. {
  17359. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17362. {
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17364. }
  17365. else
  17366. {
  17367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17368. }
  17369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17370. isKnowKey = TRUE;
  17371. }
  17372. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17373. {
  17374. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17377. {
  17378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17379. }
  17380. else
  17381. {
  17382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17383. }
  17384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17385. isKnowKey = TRUE;
  17386. }
  17387. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17388. {
  17389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17392. {
  17393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17394. }
  17395. else
  17396. {
  17397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17398. }
  17399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17400. isKnowKey = TRUE;
  17401. }
  17402. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17403. {
  17404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17407. {
  17408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17409. }
  17410. else
  17411. {
  17412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17413. }
  17414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17415. isKnowKey = TRUE;
  17416. }
  17417. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17418. {
  17419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17422. {
  17423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17424. }
  17425. else
  17426. {
  17427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17428. }
  17429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17430. isKnowKey = TRUE;
  17431. }
  17432. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17433. {
  17434. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17437. {
  17438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17439. }
  17440. else
  17441. {
  17442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17443. }
  17444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17445. isKnowKey = TRUE;
  17446. }
  17447. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17448. {
  17449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17452. {
  17453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17454. }
  17455. else
  17456. {
  17457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17458. }
  17459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17460. isKnowKey = TRUE;
  17461. }
  17462. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17463. {
  17464. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17466. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17467. {
  17468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17469. }
  17470. else
  17471. {
  17472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17473. }
  17474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17475. isKnowKey = TRUE;
  17476. }
  17477. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17478. {
  17479. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17482. {
  17483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17484. }
  17485. else
  17486. {
  17487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17488. }
  17489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17490. isKnowKey = TRUE;
  17491. }
  17492. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17493. {
  17494. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17497. {
  17498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17499. }
  17500. else
  17501. {
  17502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17503. }
  17504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17505. isKnowKey = TRUE;
  17506. }
  17507. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17508. {
  17509. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17512. {
  17513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17514. }
  17515. else
  17516. {
  17517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17518. }
  17519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17520. isKnowKey = TRUE;
  17521. }
  17522. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17523. {
  17524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17527. {
  17528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17529. }
  17530. else
  17531. {
  17532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17533. }
  17534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17535. isKnowKey = TRUE;
  17536. }
  17537. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17538. {
  17539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17542. {
  17543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17544. }
  17545. else
  17546. {
  17547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17548. }
  17549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17550. isKnowKey = TRUE;
  17551. }
  17552. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17553. {
  17554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17557. {
  17558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17559. }
  17560. else
  17561. {
  17562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17563. }
  17564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17565. isKnowKey = TRUE;
  17566. }
  17567. /*
  17568. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17569. {
  17570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17573. {
  17574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17575. }
  17576. else
  17577. {
  17578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17579. }
  17580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17581. isKnowKey = TRUE;
  17582. }*/
  17583. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17584. {
  17585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17588. {
  17589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17590. }
  17591. else
  17592. {
  17593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17594. }
  17595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17596. isKnowKey = TRUE;
  17597. }
  17598. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17599. {
  17600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17603. {
  17604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17605. }
  17606. else
  17607. {
  17608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17609. }
  17610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17611. isKnowKey = TRUE;
  17612. }
  17613. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17614. {
  17615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17618. {
  17619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17620. }
  17621. else
  17622. {
  17623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17624. }
  17625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17626. isKnowKey = TRUE;
  17627. }
  17628. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17629. {
  17630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17633. {
  17634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17635. }
  17636. else
  17637. {
  17638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17639. }
  17640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17641. isKnowKey = TRUE;
  17642. }
  17643. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17644. {
  17645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17648. {
  17649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17650. }
  17651. else
  17652. {
  17653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17654. }
  17655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17656. isKnowKey = TRUE;
  17657. }
  17658. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17659. {
  17660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17663. {
  17664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17665. }
  17666. else
  17667. {
  17668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17669. }
  17670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17671. isKnowKey = TRUE;
  17672. }
  17673. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17674. {
  17675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17678. {
  17679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17680. }
  17681. else
  17682. {
  17683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17684. }
  17685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17686. isKnowKey = TRUE;
  17687. }
  17688. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17689. {
  17690. struct sysinfo s_info;
  17691. int error = sysinfo(&s_info);
  17692. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17695. {
  17696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17697. }
  17698. else
  17699. {
  17700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17701. }
  17702. if(error != 0)
  17703. {
  17704. DEBUG_WARN("System uptime get error: %d\n", error);
  17705. }
  17706. else
  17707. {
  17708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17709. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17710. }
  17711. isKnowKey = TRUE;
  17712. }
  17713. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17714. {
  17715. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17718. {
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17720. }
  17721. else
  17722. {
  17723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17724. }
  17725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17726. isKnowKey = TRUE;
  17727. }
  17728. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17729. {
  17730. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17733. {
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17735. }
  17736. else
  17737. {
  17738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17739. }
  17740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17741. isKnowKey = TRUE;
  17742. }
  17743. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17744. {
  17745. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17748. {
  17749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17750. }
  17751. else
  17752. {
  17753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17754. }
  17755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17756. isKnowKey = TRUE;
  17757. }
  17758. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17759. {
  17760. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17763. {
  17764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17765. }
  17766. else
  17767. {
  17768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17769. }
  17770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17771. isKnowKey = TRUE;
  17772. }
  17773. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17774. {
  17775. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17778. {
  17779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17780. }
  17781. else
  17782. {
  17783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17784. }
  17785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17786. isKnowKey = TRUE;
  17787. }
  17788. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17789. {
  17790. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17792. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17793. {
  17794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17795. }
  17796. else
  17797. {
  17798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17799. }
  17800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17801. isKnowKey = TRUE;
  17802. }
  17803. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17804. {
  17805. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17808. {
  17809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17810. }
  17811. else
  17812. {
  17813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17814. }
  17815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17816. isKnowKey = TRUE;
  17817. }
  17818. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17819. {
  17820. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17823. {
  17824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17825. }
  17826. else
  17827. {
  17828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17829. }
  17830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17831. isKnowKey = TRUE;
  17832. }
  17833. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17834. {
  17835. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17838. {
  17839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17840. }
  17841. else
  17842. {
  17843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17844. }
  17845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17846. isKnowKey = TRUE;
  17847. }
  17848. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17849. {
  17850. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17853. {
  17854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17855. }
  17856. else
  17857. {
  17858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17859. }
  17860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17861. isKnowKey = TRUE;
  17862. }
  17863. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17864. {
  17865. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17868. {
  17869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17870. }
  17871. else
  17872. {
  17873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17874. }
  17875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17876. isKnowKey = TRUE;
  17877. }
  17878. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17879. {
  17880. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17883. {
  17884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17885. }
  17886. else
  17887. {
  17888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17889. }
  17890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17891. isKnowKey = TRUE;
  17892. }
  17893. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17894. {
  17895. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17898. {
  17899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17900. }
  17901. else
  17902. {
  17903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17904. }
  17905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17906. isKnowKey = TRUE;
  17907. }
  17908. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17909. {
  17910. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17913. {
  17914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17915. }
  17916. else
  17917. {
  17918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17919. }
  17920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17921. isKnowKey = TRUE;
  17922. }
  17923. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17924. {
  17925. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17928. {
  17929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17930. }
  17931. else
  17932. {
  17933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17934. }
  17935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17936. isKnowKey = TRUE;
  17937. }
  17938. if(isEmpty || strcmp(keyReq, "AuthDownloadlinkCertificate") == 0 )
  17939. {
  17940. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthDownloadlinkCertificate].Item, "AuthDownloadlinkCertificate");
  17941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Key, "AuthDownloadlinkCertificate");
  17942. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  17943. {
  17944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "0"/*"FALSE"*/);
  17945. }
  17946. else
  17947. {
  17948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "1"/*"TRUE"*/);
  17949. }
  17950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData );
  17951. isKnowKey = TRUE;
  17952. }
  17953. if(isEmpty || strcmp(keyReq, "RfidEndianType") == 0 )
  17954. {
  17955. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_RfidEndianType].Item, "RfidEndianType");
  17956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Key, "RfidEndianType");
  17957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  17958. {
  17959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "0"/*"FALSE"*/);
  17960. }
  17961. else
  17962. {
  17963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "1"/*"TRUE"*/);
  17964. }
  17965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Value, (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE"));
  17966. isKnowKey = TRUE;
  17967. }
  17968. if(isEmpty || strcmp(keyReq, "AuthorizeTimeout") == 0 )
  17969. {
  17970. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeTimeout].Item, "AuthorizeTimeout");
  17971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Key, "AuthorizeTimeout");
  17972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  17973. {
  17974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "0"/*"FALSE"*/);
  17975. }
  17976. else
  17977. {
  17978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "1"/*"TRUE"*/);
  17979. }
  17980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  17981. isKnowKey = TRUE;
  17982. }
  17983. if(isEmpty || strcmp(keyReq, "Enable15118") == 0 )
  17984. {
  17985. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_Enable15118].Item, "Enable15118");
  17986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].Key, "Enable15118");
  17987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility == 1)
  17988. {
  17989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].ReadOnly, "0"/*"FALSE"*/);
  17990. }
  17991. else
  17992. {
  17993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].ReadOnly, "1"/*"TRUE"*/);
  17994. }
  17995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].Value, (ShmSysConfigAndInfo->SysConfig.isEnable15118==1?"TRUE":"FALSE"));
  17996. isKnowKey = TRUE;
  17997. }
  17998. if(isEmpty || strcmp(keyReq, "WifiSsid") == 0 )
  17999. {
  18000. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WifiSsid].Item, "WifiSsid");
  18001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiSsid].Key, "WifiSsid");
  18002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemAccessibility == 1)
  18003. {
  18004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiSsid].ReadOnly, "0"/*"FALSE"*/);
  18005. }
  18006. else
  18007. {
  18008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiSsid].ReadOnly, "1"/*"TRUE"*/);
  18009. }
  18010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiSsid].Value, (const char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  18011. isKnowKey = TRUE;
  18012. }
  18013. if(isEmpty || strcmp(keyReq, "WifiPassword") == 0 )
  18014. {
  18015. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WifiPassword].Item, "WifiPassword");
  18016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiPassword].Key, "WifiPassword");
  18017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemAccessibility == 1)
  18018. {
  18019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiPassword].ReadOnly, "0"/*"FALSE"*/);
  18020. }
  18021. else
  18022. {
  18023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiPassword].ReadOnly, "1"/*"TRUE"*/);
  18024. }
  18025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiPassword].Value, (const char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  18026. isKnowKey = TRUE;
  18027. }
  18028. if(isEmpty || strcmp(keyReq, "StopChargingByButton") == 0 )
  18029. {
  18030. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopChargingByButton].Item, "StopChargingByButton");
  18031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopChargingByButton].Key, "StopChargingByButton");
  18032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemAccessibility == 1)
  18033. {
  18034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopChargingByButton].ReadOnly, "0"/*"FALSE"*/);
  18035. }
  18036. else
  18037. {
  18038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopChargingByButton].ReadOnly, "1"/*"TRUE"*/);
  18039. }
  18040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopChargingByButton].Value, (ShmSysConfigAndInfo->SysConfig.StopChargingByButton==1?"TRUE":"FALSE"));
  18041. isKnowKey = TRUE;
  18042. }
  18043. #if 1
  18044. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  18045. {
  18046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  18047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  18048. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  18049. {
  18050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  18051. }
  18052. else
  18053. {
  18054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  18055. }
  18056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  18057. isKnowKey = TRUE;
  18058. }
  18059. #endif
  18060. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  18061. {
  18062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  18063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  18064. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  18065. {
  18066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  18067. }
  18068. else
  18069. {
  18070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  18071. }
  18072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  18073. isKnowKey = TRUE;
  18074. }
  18075. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  18076. {
  18077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  18078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  18079. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  18080. {
  18081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  18082. }
  18083. else
  18084. {
  18085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  18086. }
  18087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  18088. isKnowKey = TRUE;
  18089. }
  18090. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  18091. {
  18092. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  18093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  18094. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  18095. {
  18096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  18097. }
  18098. else
  18099. {
  18100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  18101. }
  18102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  18103. isKnowKey = TRUE;
  18104. }
  18105. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  18106. {
  18107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  18108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  18109. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  18110. {
  18111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  18112. }
  18113. else
  18114. {
  18115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  18116. }
  18117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  18118. isKnowKey = TRUE;
  18119. }
  18120. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  18121. {
  18122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  18123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  18124. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  18125. {
  18126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  18127. }
  18128. else
  18129. {
  18130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  18131. }
  18132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  18133. isKnowKey = TRUE;
  18134. }
  18135. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  18136. {
  18137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  18138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  18139. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  18140. {
  18141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  18142. }
  18143. else
  18144. {
  18145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  18146. }
  18147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  18148. isKnowKey = TRUE;
  18149. }
  18150. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  18151. {
  18152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  18153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  18154. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  18155. {
  18156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  18157. }
  18158. else
  18159. {
  18160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  18161. }
  18162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  18163. isKnowKey = TRUE;
  18164. }
  18165. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  18166. {
  18167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  18168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  18169. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18170. {
  18171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  18172. }
  18173. else
  18174. {
  18175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  18176. }
  18177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  18178. isKnowKey = TRUE;
  18179. }
  18180. //=========================================================
  18181. if(!isEmpty && !isKnowKey)
  18182. {
  18183. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  18184. strcpy(unknownkey[UnknownKeynum], keyReq);
  18185. UnknownKeynum = UnknownKeynum + 1;
  18186. }
  18187. }
  18188. void processUnkownKey(void)
  18189. {
  18190. DEBUG_INFO("processUnkownKey...\n");
  18191. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  18192. for(int index=0; index < UnknownKeynum; index++)
  18193. {
  18194. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  18195. {
  18196. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  18197. }
  18198. }
  18199. }
  18200. int setKeyValue(char *key, char *value)
  18201. {
  18202. int isSuccess = NotSupported;
  18203. int check_ascii=0;
  18204. char str[501]={0};
  18205. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  18206. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  18207. {
  18208. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  18209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  18210. {
  18211. strcpy(str, (const char*)value);
  18212. for(int i = 0; str[i]; i++){
  18213. str[i] = tolower(str[i]);
  18214. }
  18215. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  18216. {
  18217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  18218. isSuccess = ConfigurationStatus_Accepted;
  18219. }
  18220. else
  18221. isSuccess = ConfigurationStatus_Rejected;
  18222. }
  18223. else
  18224. {
  18225. isSuccess = ConfigurationStatus_Rejected;
  18226. }
  18227. }
  18228. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  18229. {
  18230. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  18231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  18232. {
  18233. strcpy(str, (const char*)value);
  18234. for(int i = 0; str[i]; i++){
  18235. str[i] = tolower(str[i]);
  18236. }
  18237. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  18238. {
  18239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  18240. isSuccess = ConfigurationStatus_Accepted;
  18241. }
  18242. else
  18243. isSuccess = ConfigurationStatus_Rejected;
  18244. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  18245. }
  18246. else
  18247. {
  18248. isSuccess = ConfigurationStatus_Rejected;
  18249. }
  18250. }
  18251. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  18252. {
  18253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  18254. {
  18255. strcpy(str, (const char*)value);
  18256. for(int i = 0; str[i]; i++)
  18257. {
  18258. str[i] = tolower(str[i]);
  18259. }
  18260. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  18261. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  18262. {
  18263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  18264. isSuccess = ConfigurationStatus_Accepted;
  18265. }
  18266. else
  18267. isSuccess = ConfigurationStatus_Rejected;
  18268. }
  18269. else
  18270. {
  18271. isSuccess = ConfigurationStatus_Rejected;
  18272. }
  18273. }
  18274. if(strcmp(key, "BlinkRepeat") == 0)
  18275. {
  18276. //Charger.BlinkRepeat = Integer.parseInt(value);
  18277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  18278. {
  18279. check_ascii = value[0];
  18280. if( (check_ascii < 48) || (check_ascii > 57) )
  18281. {
  18282. isSuccess = ConfigurationStatus_Rejected;
  18283. }
  18284. else
  18285. {
  18286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value));
  18287. isSuccess = ConfigurationStatus_Accepted;
  18288. }
  18289. }
  18290. else
  18291. {
  18292. isSuccess = ConfigurationStatus_Rejected;
  18293. }
  18294. }
  18295. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18296. {
  18297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18298. {
  18299. check_ascii = value[0];
  18300. if( (check_ascii < 48) || (check_ascii > 57) )
  18301. {
  18302. isSuccess = ConfigurationStatus_Rejected;
  18303. }
  18304. else
  18305. {
  18306. if((atoi(value) == 0) || (atoi(value) >= 5))
  18307. {
  18308. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value));
  18310. isSuccess = ConfigurationStatus_Accepted;
  18311. }
  18312. else
  18313. isSuccess = ConfigurationStatus_Rejected;
  18314. }
  18315. }
  18316. else
  18317. {
  18318. isSuccess = ConfigurationStatus_Rejected;
  18319. }
  18320. }
  18321. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18322. {
  18323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18324. {
  18325. check_ascii = value[0];
  18326. if( (check_ascii < 48) || (check_ascii > 57) )
  18327. {
  18328. isSuccess = ConfigurationStatus_Rejected;
  18329. }
  18330. else
  18331. {
  18332. if((atoi(value) >= 30) && (atoi(value) <= 3600))
  18333. {
  18334. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18336. isSuccess = ConfigurationStatus_Accepted;
  18337. }
  18338. else
  18339. isSuccess = ConfigurationStatus_Rejected;
  18340. }
  18341. }
  18342. else
  18343. {
  18344. isSuccess = ConfigurationStatus_Rejected;
  18345. }
  18346. }
  18347. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18348. {
  18349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18350. {
  18351. check_ascii = value[0];
  18352. if( (check_ascii < 48) || (check_ascii > 57) )
  18353. {
  18354. isSuccess = ConfigurationStatus_Rejected;
  18355. }
  18356. else
  18357. {
  18358. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value));
  18360. isSuccess = ConfigurationStatus_Accepted;
  18361. }
  18362. }
  18363. else
  18364. {
  18365. isSuccess = ConfigurationStatus_Rejected;
  18366. }
  18367. }
  18368. if(strcmp(key, "HeartbeatInterval") == 0)
  18369. {
  18370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18371. {
  18372. check_ascii = value[0];
  18373. if( (check_ascii < 48) || (check_ascii > 57) )
  18374. {
  18375. isSuccess = ConfigurationStatus_Rejected;
  18376. }
  18377. else
  18378. {
  18379. if((atoi(value) == 0) || (atoi(value) >= 10))
  18380. {
  18381. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18383. HeartBeatWaitTime = atoi(value);
  18384. isSuccess = ConfigurationStatus_Accepted;
  18385. }
  18386. else
  18387. {
  18388. isSuccess = ConfigurationStatus_Rejected;
  18389. }
  18390. }
  18391. }
  18392. else
  18393. {
  18394. isSuccess = ConfigurationStatus_Rejected;
  18395. }
  18396. }
  18397. if(strcmp(key, "LightIntensity") == 0)
  18398. {
  18399. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18400. {
  18401. check_ascii = value[0];
  18402. if( (check_ascii < 48) || (check_ascii > 57) )
  18403. {
  18404. isSuccess = ConfigurationStatus_Rejected;
  18405. }
  18406. else
  18407. {
  18408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value));
  18409. isSuccess = ConfigurationStatus_Accepted;
  18410. }
  18411. }
  18412. else
  18413. {
  18414. isSuccess = ConfigurationStatus_Rejected;
  18415. }
  18416. }
  18417. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18418. {
  18419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18420. {
  18421. strcpy(str, (const char*)value);
  18422. for(int i = 0; str[i]; i++)
  18423. {
  18424. str[i] = tolower(str[i]);
  18425. }
  18426. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  18427. {
  18428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  18429. isSuccess = ConfigurationStatus_Accepted;
  18430. }
  18431. else
  18432. isSuccess = ConfigurationStatus_Rejected;
  18433. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18434. }
  18435. else
  18436. {
  18437. isSuccess = ConfigurationStatus_Rejected;
  18438. }
  18439. }
  18440. if(strcmp(key, "LocalPreAuthorize") == 0)
  18441. {
  18442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18443. {
  18444. strcpy(str, (const char*)value);
  18445. for(int i = 0; str[i]; i++)
  18446. {
  18447. str[i] = tolower(str[i]);
  18448. }
  18449. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  18450. {
  18451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  18452. isSuccess = ConfigurationStatus_Accepted;
  18453. }
  18454. else
  18455. isSuccess = ConfigurationStatus_Rejected;
  18456. }
  18457. else
  18458. {
  18459. isSuccess = ConfigurationStatus_Rejected;
  18460. }
  18461. }
  18462. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18463. {
  18464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18465. {
  18466. check_ascii = value[0];
  18467. if( (check_ascii < 48) || (check_ascii > 57) )
  18468. {
  18469. isSuccess = ConfigurationStatus_Rejected;
  18470. }
  18471. else
  18472. {
  18473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value));
  18474. isSuccess = ConfigurationStatus_Accepted;
  18475. }
  18476. }
  18477. else
  18478. {
  18479. isSuccess = ConfigurationStatus_Rejected;
  18480. }
  18481. }
  18482. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18483. {
  18484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18485. {
  18486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value);
  18487. isSuccess = ConfigurationStatus_Accepted;
  18488. }
  18489. else
  18490. {
  18491. isSuccess = ConfigurationStatus_Rejected;
  18492. }
  18493. }
  18494. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18495. {
  18496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18497. {
  18498. check_ascii = value[0];
  18499. if( (check_ascii < 48) || (check_ascii > 57) )
  18500. {
  18501. isSuccess = ConfigurationStatus_Rejected;
  18502. }
  18503. else
  18504. {
  18505. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18507. isSuccess = ConfigurationStatus_Accepted;
  18508. }
  18509. }
  18510. else
  18511. {
  18512. isSuccess = ConfigurationStatus_Rejected;
  18513. }
  18514. }
  18515. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18516. {
  18517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18518. {
  18519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value);
  18520. isSuccess = ConfigurationStatus_Accepted;
  18521. }
  18522. else
  18523. {
  18524. isSuccess = ConfigurationStatus_Rejected;
  18525. }
  18526. }
  18527. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18528. {
  18529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18530. {
  18531. check_ascii = value[0];
  18532. if( (check_ascii < 48) || (check_ascii > 57) )
  18533. {
  18534. isSuccess = ConfigurationStatus_Rejected;
  18535. }
  18536. else
  18537. {
  18538. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18540. isSuccess = ConfigurationStatus_Accepted;
  18541. }
  18542. }
  18543. else
  18544. {
  18545. isSuccess = ConfigurationStatus_Rejected;
  18546. }
  18547. }
  18548. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18549. {
  18550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18551. {
  18552. check_ascii = value[0];
  18553. if( (check_ascii < 48) || (check_ascii > 57) )
  18554. {
  18555. isSuccess = ConfigurationStatus_Rejected;
  18556. }
  18557. else
  18558. {
  18559. if((atoi(value) == 0) || (atoi(value) >= 3))
  18560. {
  18561. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18563. isSuccess = ConfigurationStatus_Accepted;
  18564. }
  18565. else
  18566. {
  18567. isSuccess = ConfigurationStatus_Rejected;
  18568. }
  18569. }
  18570. }
  18571. else
  18572. {
  18573. isSuccess = ConfigurationStatus_Rejected;
  18574. }
  18575. }
  18576. if(strcmp(key, "MinimumStatusDuration") == 0)
  18577. {
  18578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18579. {
  18580. check_ascii = value[0];
  18581. if( (check_ascii < 48) || (check_ascii > 57) )
  18582. {
  18583. isSuccess = ConfigurationStatus_Rejected;
  18584. }
  18585. else
  18586. {
  18587. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18588. {
  18589. isSuccess = ConfigurationStatus_Rejected;
  18590. }
  18591. else
  18592. {
  18593. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value));
  18595. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18596. isSuccess = ConfigurationStatus_Accepted;
  18597. }
  18598. }
  18599. }
  18600. else
  18601. {
  18602. isSuccess = ConfigurationStatus_Rejected;
  18603. }
  18604. }
  18605. if(strcmp(key, "NumberOfConnectors") == 0)
  18606. {
  18607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18608. {
  18609. check_ascii = value[0];
  18610. if( (check_ascii < 48) || (check_ascii > 57) )
  18611. {
  18612. isSuccess = ConfigurationStatus_Rejected;
  18613. }
  18614. else
  18615. {
  18616. //Charger.ResetRetries = Integer.parseInt(value);
  18617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value));
  18618. isSuccess = ConfigurationStatus_Accepted;
  18619. }
  18620. }
  18621. else
  18622. {
  18623. isSuccess = ConfigurationStatus_Rejected;
  18624. }
  18625. }
  18626. if(strcmp(key, "ResetRetries") == 0)
  18627. {
  18628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18629. {
  18630. check_ascii = value[0];
  18631. if( (check_ascii < 48) || (check_ascii > 57) )
  18632. {
  18633. isSuccess = ConfigurationStatus_Rejected;
  18634. }
  18635. else
  18636. {
  18637. //Charger.ResetRetries = Integer.parseInt(value);
  18638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value));
  18639. isSuccess = ConfigurationStatus_Accepted;
  18640. }
  18641. }
  18642. else
  18643. {
  18644. isSuccess = ConfigurationStatus_Rejected;
  18645. }
  18646. }
  18647. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18648. {
  18649. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18650. {
  18651. strcpy(str, (const char*)value);
  18652. for(int i = 0; str[i]; i++)
  18653. {
  18654. str[i] = tolower(str[i]);
  18655. }
  18656. if(strcmp(str, "notapplicable")== 0)
  18657. {
  18658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable");
  18659. isSuccess = ConfigurationStatus_Accepted;
  18660. }
  18661. else if(strcmp(str, "unknown")== 0)
  18662. {
  18663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown");
  18664. isSuccess = ConfigurationStatus_Accepted;
  18665. }
  18666. else if(strcmp(str, "rst")== 0)
  18667. {
  18668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST");
  18669. isSuccess = ConfigurationStatus_Accepted;
  18670. }
  18671. else if(strcmp(str, "rts")== 0)
  18672. {
  18673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS");
  18674. isSuccess = ConfigurationStatus_Accepted;
  18675. }
  18676. else if(strcmp(str, "srt")== 0)
  18677. {
  18678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT");
  18679. isSuccess = ConfigurationStatus_Accepted;
  18680. }
  18681. else if(strcmp(str, "str")== 0)
  18682. {
  18683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR");
  18684. isSuccess = ConfigurationStatus_Accepted;
  18685. }
  18686. else if(strcmp(str, "trs")== 0)
  18687. {
  18688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS");
  18689. isSuccess = ConfigurationStatus_Accepted;
  18690. }
  18691. else if(strcmp(str, "tsr")== 0)
  18692. {
  18693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR");
  18694. isSuccess = ConfigurationStatus_Accepted;
  18695. }
  18696. else
  18697. {
  18698. isSuccess = ConfigurationStatus_Rejected;
  18699. }
  18700. }
  18701. else
  18702. {
  18703. isSuccess = ConfigurationStatus_Rejected;
  18704. }
  18705. }
  18706. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18707. {
  18708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18709. {
  18710. check_ascii = value[0];
  18711. if( (check_ascii < 48) || (check_ascii > 57) )
  18712. {
  18713. isSuccess = ConfigurationStatus_Rejected;
  18714. }
  18715. else
  18716. {
  18717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value));
  18718. isSuccess = ConfigurationStatus_Accepted;
  18719. }
  18720. }
  18721. else
  18722. {
  18723. isSuccess = ConfigurationStatus_Rejected;
  18724. }
  18725. }
  18726. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18727. {
  18728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18729. {
  18730. strcpy(str, (const char*)value);
  18731. for(int i = 0; str[i]; i++)
  18732. {
  18733. str[i] = tolower(str[i]);
  18734. }
  18735. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18736. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  18737. {
  18738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  18739. isSuccess = ConfigurationStatus_Accepted;
  18740. }
  18741. else
  18742. isSuccess = ConfigurationStatus_Rejected;
  18743. }
  18744. else
  18745. {
  18746. isSuccess = ConfigurationStatus_Rejected;
  18747. }
  18748. }
  18749. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18750. {
  18751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18752. {
  18753. strcpy(str, (const char*)value);
  18754. for(int i = 0; str[i]; i++)
  18755. {
  18756. str[i] = tolower(str[i]);
  18757. }
  18758. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18759. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  18760. {
  18761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  18762. isSuccess = ConfigurationStatus_Accepted;
  18763. }
  18764. else
  18765. isSuccess = ConfigurationStatus_Rejected;
  18766. }
  18767. else
  18768. {
  18769. isSuccess = ConfigurationStatus_Rejected;
  18770. }
  18771. }
  18772. if(strcmp(key, "StopTxnAlignedData") == 0)
  18773. {
  18774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18775. {
  18776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value);
  18777. isSuccess = ConfigurationStatus_Accepted;
  18778. }
  18779. else
  18780. {
  18781. isSuccess = ConfigurationStatus_Rejected;
  18782. }
  18783. }
  18784. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18785. {
  18786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18787. {
  18788. check_ascii = value[0];
  18789. if( (check_ascii < 48) || (check_ascii > 57) )
  18790. {
  18791. isSuccess = ConfigurationStatus_Rejected;
  18792. }
  18793. else
  18794. {
  18795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18796. isSuccess = ConfigurationStatus_Accepted;
  18797. }
  18798. }
  18799. else
  18800. {
  18801. isSuccess = ConfigurationStatus_Rejected;
  18802. }
  18803. }
  18804. if(strcmp(key, "StopTxnSampledData") == 0)
  18805. {
  18806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18807. {
  18808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value);
  18809. isSuccess = ConfigurationStatus_Accepted;
  18810. }
  18811. else
  18812. {
  18813. isSuccess = ConfigurationStatus_Rejected;
  18814. }
  18815. }
  18816. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18817. {
  18818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18819. {
  18820. check_ascii = value[0];
  18821. if( (check_ascii < 48) || (check_ascii > 57) )
  18822. {
  18823. isSuccess = ConfigurationStatus_Rejected;
  18824. }
  18825. else
  18826. {
  18827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value));
  18828. isSuccess = ConfigurationStatus_Accepted;
  18829. }
  18830. }
  18831. else
  18832. {
  18833. isSuccess = ConfigurationStatus_Rejected;
  18834. }
  18835. }
  18836. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18837. {
  18838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18839. {
  18840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value);
  18841. isSuccess = ConfigurationStatus_Accepted;
  18842. }
  18843. else
  18844. {
  18845. isSuccess = ConfigurationStatus_Rejected;
  18846. }
  18847. }
  18848. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18849. {
  18850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18851. {
  18852. check_ascii = value[0];
  18853. if( (check_ascii < 48) || (check_ascii > 57) )
  18854. {
  18855. isSuccess = ConfigurationStatus_Rejected;
  18856. }
  18857. else
  18858. {
  18859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value));
  18860. isSuccess = ConfigurationStatus_Accepted;
  18861. }
  18862. }
  18863. else
  18864. {
  18865. isSuccess = ConfigurationStatus_Rejected;
  18866. }
  18867. }
  18868. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18869. {
  18870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18871. {
  18872. check_ascii = value[0];
  18873. if( (check_ascii < 48) || (check_ascii > 57) )
  18874. {
  18875. isSuccess = ConfigurationStatus_Rejected;
  18876. }
  18877. else
  18878. {
  18879. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value));
  18881. TransactionMessageAttemptsValue = atoi(value);
  18882. isSuccess = ConfigurationStatus_Accepted;
  18883. }
  18884. }
  18885. else
  18886. {
  18887. isSuccess = ConfigurationStatus_Rejected;
  18888. }
  18889. }
  18890. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18891. {
  18892. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18893. {
  18894. check_ascii = value[0];
  18895. if( (check_ascii < 48) || (check_ascii > 57) )
  18896. {
  18897. isSuccess = ConfigurationStatus_Rejected;
  18898. }
  18899. else
  18900. {
  18901. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value));
  18903. TransactionMessageRetryIntervalValue = atoi(value);
  18904. isSuccess = ConfigurationStatus_Accepted;
  18905. }
  18906. }
  18907. else
  18908. {
  18909. isSuccess = ConfigurationStatus_Rejected;
  18910. }
  18911. }
  18912. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18913. {
  18914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18915. {
  18916. strcpy(str, (const char*)value);
  18917. for(int i = 0; str[i]; i++)
  18918. {
  18919. str[i] = tolower(str[i]);
  18920. }
  18921. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18922. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  18923. {
  18924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  18925. isSuccess = ConfigurationStatus_Accepted;
  18926. }
  18927. else
  18928. isSuccess = ConfigurationStatus_Rejected;
  18929. }
  18930. else
  18931. {
  18932. isSuccess = ConfigurationStatus_Rejected;
  18933. }
  18934. }
  18935. if(strcmp(key, "WebSocketPingInterval") == 0)
  18936. {
  18937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18938. {
  18939. check_ascii = value[0];
  18940. if( (check_ascii < 48) || (check_ascii > 57) )
  18941. {
  18942. isSuccess = ConfigurationStatus_Rejected;
  18943. }
  18944. else
  18945. {
  18946. if((atoi(value) == 0) || (atoi(value) >= 10))
  18947. {
  18948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value));
  18949. isSuccess = ConfigurationStatus_Accepted;
  18950. }
  18951. else
  18952. isSuccess = ConfigurationStatus_Rejected;
  18953. }
  18954. }
  18955. else
  18956. {
  18957. isSuccess = ConfigurationStatus_Rejected;
  18958. }
  18959. }
  18960. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18961. {
  18962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18963. {
  18964. strcpy(str, (const char*)value);
  18965. for(int i = 0; str[i]; i++)
  18966. {
  18967. str[i] = tolower(str[i]);
  18968. }
  18969. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  18970. {
  18971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  18972. isSuccess = ConfigurationStatus_Accepted;
  18973. }
  18974. else
  18975. isSuccess = ConfigurationStatus_Rejected;
  18976. }
  18977. else
  18978. {
  18979. isSuccess = ConfigurationStatus_Rejected;
  18980. }
  18981. }
  18982. if(strcmp(key, "AuthorizationKey") == 0)
  18983. {
  18984. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18985. {
  18986. strcpy(str, (const char*)value);
  18987. int strlength = strlen(str);
  18988. char capture[3];
  18989. char stackItem = 0;
  18990. char password[21] = {0};
  18991. printf("String length: %d\n", strlength);
  18992. for(int idx=0; idx<(strlength/2); idx++)
  18993. {
  18994. capture[0] = str[(idx*2)];
  18995. capture[1] = str[(idx*2)+1];
  18996. capture[2] = 0;
  18997. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18998. sprintf(password,"%s%c", password, stackItem);
  18999. }
  19000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  19001. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19002. isSuccess = ConfigurationStatus_Accepted;
  19003. }
  19004. else
  19005. {
  19006. isSuccess = ConfigurationStatus_Rejected;
  19007. }
  19008. }
  19009. if(strcmp(key, "SecurityProfile") == 0)
  19010. {
  19011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  19012. {
  19013. check_ascii = value[0];
  19014. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  19015. {
  19016. isSuccess = ConfigurationStatus_Rejected;
  19017. }
  19018. else if(check_ascii == 0x33)
  19019. {
  19020. isSuccess = NotSupported;
  19021. }
  19022. else
  19023. {
  19024. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  19025. {
  19026. if(((check_ascii - 0x30) == 1) ||
  19027. ((check_ascii - 0x30) == 2) ||
  19028. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  19029. {
  19030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value));
  19031. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  19032. isSuccess = ConfigurationStatus_Accepted;
  19033. }
  19034. else
  19035. isSuccess = ConfigurationStatus_Rejected;
  19036. }
  19037. else
  19038. isSuccess = ConfigurationStatus_Rejected;
  19039. }
  19040. }
  19041. else
  19042. {
  19043. isSuccess = ConfigurationStatus_Rejected;
  19044. }
  19045. }
  19046. if(strcmp(key, "DefaultPrice") == 0)
  19047. {
  19048. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  19049. {
  19050. strcpy(str, (const char*)value);
  19051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  19052. isSuccess = ConfigurationStatus_Accepted;
  19053. }
  19054. else
  19055. {
  19056. isSuccess = ConfigurationStatus_Rejected;
  19057. }
  19058. }
  19059. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  19060. {
  19061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  19062. {
  19063. strcpy(str, (const char*)value);
  19064. for(int i = 0; str[i]; i++)
  19065. {
  19066. str[i] = tolower(str[i]);
  19067. }
  19068. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19069. {
  19070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19071. isSuccess = ConfigurationStatus_Accepted;
  19072. }
  19073. else
  19074. isSuccess = ConfigurationStatus_Rejected;
  19075. }
  19076. else
  19077. {
  19078. isSuccess = ConfigurationStatus_Rejected;
  19079. }
  19080. }
  19081. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  19082. {
  19083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  19084. {
  19085. strcpy(str, (const char*)value);
  19086. for(int i = 0; str[i]; i++)
  19087. {
  19088. str[i] = tolower(str[i]);
  19089. }
  19090. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19091. {
  19092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19093. isSuccess = ConfigurationStatus_Accepted;
  19094. }
  19095. else
  19096. isSuccess = ConfigurationStatus_Rejected;
  19097. }
  19098. else
  19099. {
  19100. isSuccess = ConfigurationStatus_Rejected;
  19101. }
  19102. }
  19103. if(strcmp(key, "TimeOffset") == 0)
  19104. {
  19105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  19106. {
  19107. strcpy(str, (const char*)value);
  19108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  19109. isSuccess = ConfigurationStatus_Accepted;
  19110. }
  19111. else
  19112. {
  19113. isSuccess = ConfigurationStatus_Rejected;
  19114. }
  19115. }
  19116. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  19117. {
  19118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  19119. {
  19120. strcpy(str, (const char*)value);
  19121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  19122. isSuccess = ConfigurationStatus_Accepted;
  19123. }
  19124. else
  19125. {
  19126. isSuccess = ConfigurationStatus_Rejected;
  19127. }
  19128. }
  19129. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  19130. {
  19131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  19132. {
  19133. strcpy(str, (const char*)value);
  19134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  19135. isSuccess = ConfigurationStatus_Accepted;
  19136. }
  19137. else
  19138. {
  19139. isSuccess = ConfigurationStatus_Rejected;
  19140. }
  19141. }
  19142. if(strcmp(key, "SystemUptimeSec") == 0)
  19143. {
  19144. isSuccess = NotSupported;
  19145. }
  19146. if(strcmp(key, "FreeVend") == 0)
  19147. {
  19148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  19149. {
  19150. strcpy(str, (const char*)value);
  19151. for(int i = 0; str[i]; i++)
  19152. {
  19153. str[i] = tolower(str[i]);
  19154. }
  19155. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19156. {
  19157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19158. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0);
  19159. isSuccess = ConfigurationStatus_Accepted;
  19160. }
  19161. else
  19162. isSuccess = ConfigurationStatus_Rejected;
  19163. }
  19164. else
  19165. {
  19166. isSuccess = ConfigurationStatus_Rejected;
  19167. }
  19168. }
  19169. if(strcmp(key, "FreeVendIdtag") == 0)
  19170. {
  19171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  19172. {
  19173. strcpy(str, (const char*)value);
  19174. if(strlen(str) <= 20)
  19175. {
  19176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str);
  19177. isSuccess = ConfigurationStatus_Accepted;
  19178. }
  19179. else
  19180. {
  19181. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  19182. isSuccess = ConfigurationStatus_Rejected;
  19183. }
  19184. }
  19185. else
  19186. {
  19187. isSuccess = ConfigurationStatus_Rejected;
  19188. }
  19189. }
  19190. if(strcmp(key, "OcppServer") == 0)
  19191. {
  19192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  19193. {
  19194. strcpy(str, (const char*)value);
  19195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str);
  19196. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str);
  19197. isSuccess = ConfigurationStatus_Accepted;
  19198. }
  19199. else
  19200. {
  19201. isSuccess = ConfigurationStatus_Rejected;
  19202. }
  19203. }
  19204. if(strcmp(key, "MaintainServer") == 0)
  19205. {
  19206. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  19207. {
  19208. strcpy(str, (const char*)value);
  19209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str);
  19210. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str);
  19211. isSuccess = ConfigurationStatus_Accepted;
  19212. }
  19213. else
  19214. {
  19215. isSuccess = ConfigurationStatus_Rejected;
  19216. }
  19217. }
  19218. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  19219. {
  19220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  19221. {
  19222. strcpy(str, (const char*)value);
  19223. for(int i = 0; str[i]; i++)
  19224. {
  19225. str[i] = tolower(str[i]);
  19226. }
  19227. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19228. {
  19229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19230. isSuccess = ConfigurationStatus_Accepted;
  19231. }
  19232. else
  19233. isSuccess = ConfigurationStatus_Rejected;
  19234. }
  19235. else
  19236. {
  19237. isSuccess = ConfigurationStatus_Rejected;
  19238. }
  19239. }
  19240. if(strcmp(key, "StatusNotificationInterval") == 0)
  19241. {
  19242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  19243. {
  19244. check_ascii = value[0];
  19245. if( (check_ascii < 48) || (check_ascii > 57) )
  19246. {
  19247. isSuccess = ConfigurationStatus_Rejected;
  19248. }
  19249. else
  19250. {
  19251. if((atoi(value) == 0) || (atoi(value) >= 10))
  19252. {
  19253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value));
  19254. isSuccess = ConfigurationStatus_Accepted;
  19255. }
  19256. else
  19257. isSuccess = ConfigurationStatus_Rejected;
  19258. }
  19259. }
  19260. else
  19261. {
  19262. isSuccess = ConfigurationStatus_Rejected;
  19263. }
  19264. }
  19265. if(strcmp(key, "PreAuthAmount") == 0)
  19266. {
  19267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  19268. {
  19269. check_ascii = value[0];
  19270. if( (check_ascii < 48) || (check_ascii > 57) )
  19271. {
  19272. isSuccess = ConfigurationStatus_Rejected;
  19273. }
  19274. else
  19275. {
  19276. if(atof(value) >= 0)
  19277. {
  19278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value));
  19279. isSuccess = ConfigurationStatus_Accepted;
  19280. }
  19281. else
  19282. isSuccess = ConfigurationStatus_Rejected;
  19283. }
  19284. }
  19285. else
  19286. {
  19287. isSuccess = ConfigurationStatus_Rejected;
  19288. }
  19289. }
  19290. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  19291. {
  19292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  19293. {
  19294. check_ascii = value[0];
  19295. if( (check_ascii < 48) || (check_ascii > 57) )
  19296. {
  19297. isSuccess = ConfigurationStatus_Rejected;
  19298. }
  19299. else
  19300. {
  19301. if(atoi(value) >= 0)
  19302. {
  19303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  19304. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  19305. isSuccess = ConfigurationStatus_Accepted;
  19306. }
  19307. else
  19308. isSuccess = ConfigurationStatus_Rejected;
  19309. }
  19310. }
  19311. else
  19312. {
  19313. isSuccess = ConfigurationStatus_Rejected;
  19314. }
  19315. }
  19316. if(strcmp(key, "PowerSharingServerIP") == 0)
  19317. {
  19318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  19319. {
  19320. strcpy(str, (const char*)value);
  19321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str);
  19322. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str);
  19323. isSuccess = ConfigurationStatus_Accepted;
  19324. }
  19325. else
  19326. {
  19327. isSuccess = ConfigurationStatus_Rejected;
  19328. }
  19329. }
  19330. if(strcmp(key, "EVCCID_PREFIX") == 0)
  19331. {
  19332. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  19333. {
  19334. strcpy(str, (const char*)value);
  19335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str);
  19336. isSuccess = ConfigurationStatus_Accepted;
  19337. }
  19338. else
  19339. {
  19340. isSuccess = ConfigurationStatus_Rejected;
  19341. }
  19342. }
  19343. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19344. {
  19345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19346. {
  19347. if(atoi(value) > modelnameInfo.ratedPower)
  19348. {
  19349. isSuccess = ConfigurationStatus_Rejected;
  19350. }
  19351. else{
  19352. strcpy(str, (const char*)value);
  19353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str);
  19354. isSuccess = ConfigurationStatus_Accepted;
  19355. }
  19356. }
  19357. else
  19358. {
  19359. isSuccess = ConfigurationStatus_Rejected;
  19360. }
  19361. }
  19362. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19363. {
  19364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19365. {
  19366. if((atoi(value) != 0) && (atoi(value) < 5))
  19367. {
  19368. isSuccess = ConfigurationStatus_Rejected;
  19369. }
  19370. else{
  19371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%d", atoi(value));
  19372. isSuccess = ConfigurationStatus_Accepted;
  19373. }
  19374. }
  19375. else
  19376. {
  19377. isSuccess = ConfigurationStatus_Rejected;
  19378. }
  19379. }
  19380. if(strcmp(key, "CpoName") == 0)
  19381. {
  19382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19383. {
  19384. strcpy(str, (const char*)value);
  19385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str);
  19386. isSuccess = ConfigurationStatus_Accepted;
  19387. }
  19388. else
  19389. {
  19390. isSuccess = ConfigurationStatus_Rejected;
  19391. }
  19392. }
  19393. if(strcmp(key, "OcppSoftwareVersion") == 0)
  19394. {
  19395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  19396. {
  19397. strcpy(str, (const char*)value);
  19398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", str);
  19399. isSuccess = ConfigurationStatus_Accepted;
  19400. }
  19401. else
  19402. {
  19403. isSuccess = ConfigurationStatus_Rejected;
  19404. }
  19405. }
  19406. if(strcmp(key, "AuthDownloadlinkCertificate") == 0)
  19407. {
  19408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  19409. {
  19410. strcpy(str, (const char*)value);
  19411. for(int i = 0; str[i]; i++)
  19412. {
  19413. str[i] = tolower(str[i]);
  19414. }
  19415. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19416. {
  19417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19418. isSuccess = ConfigurationStatus_Accepted;
  19419. }
  19420. else
  19421. isSuccess = ConfigurationStatus_Rejected;
  19422. }
  19423. else
  19424. {
  19425. isSuccess = ConfigurationStatus_Rejected;
  19426. }
  19427. }
  19428. if(strcmp(key, "RfidEndianType") == 0)
  19429. {
  19430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  19431. {
  19432. strcpy(str, (const char*)value);
  19433. for(int i = 0; str[i]; i++)
  19434. {
  19435. str[i] = tolower(str[i]);
  19436. }
  19437. if((strcmp(str, "big")==0) || (strcmp(str, "little")==0))
  19438. {
  19439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "%s", str);
  19440. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = (strcmp(str, "big")==0)?1:0;
  19441. isSuccess = ConfigurationStatus_Accepted;
  19442. }
  19443. else
  19444. isSuccess = ConfigurationStatus_Rejected;
  19445. }
  19446. else
  19447. {
  19448. isSuccess = ConfigurationStatus_Rejected;
  19449. }
  19450. }
  19451. if(strcmp(key, "AuthorizeTimeout") == 0)
  19452. {
  19453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  19454. {
  19455. check_ascii = value[0];
  19456. if((check_ascii < 48) || (check_ascii > 57))
  19457. {
  19458. isSuccess = ConfigurationStatus_Rejected;
  19459. }
  19460. else
  19461. {
  19462. if((atoi(value) >= 10) && (atoi(value) <= 300))
  19463. {
  19464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%d", atoi(value));
  19465. isSuccess = ConfigurationStatus_Accepted;
  19466. }
  19467. else
  19468. {
  19469. isSuccess = ConfigurationStatus_Rejected;
  19470. }
  19471. }
  19472. }
  19473. else
  19474. {
  19475. isSuccess = ConfigurationStatus_Rejected;
  19476. }
  19477. }
  19478. if(strcmp(key, "Enable15118") == 0)
  19479. {
  19480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility == 1)
  19481. {
  19482. strcpy(str, (const char*)value);
  19483. for(int i = 0; str[i]; i++)
  19484. {
  19485. str[i] = tolower(str[i]);
  19486. }
  19487. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19488. {
  19489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19490. ShmSysConfigAndInfo->SysConfig.isEnable15118 = (strcmp(str, "true")==0)?1:0;
  19491. isSuccess = ConfigurationStatus_Accepted;
  19492. }
  19493. else
  19494. isSuccess = ConfigurationStatus_Rejected;
  19495. }
  19496. else
  19497. {
  19498. isSuccess = ConfigurationStatus_Rejected;
  19499. }
  19500. }
  19501. if(strcmp(key, "WifiSsid") == 0)
  19502. {
  19503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemAccessibility == 1)
  19504. {
  19505. strcpy(str, (const char*)value);
  19506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemData, str);
  19507. sprintf((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiSsid].ItemData);
  19508. isSuccess = ConfigurationStatus_Accepted;
  19509. }
  19510. else
  19511. {
  19512. isSuccess = ConfigurationStatus_Rejected;
  19513. }
  19514. }
  19515. if(strcmp(key, "WifiPassword") == 0)
  19516. {
  19517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemAccessibility == 1)
  19518. {
  19519. strcpy(str, (const char*)value);
  19520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemData, str);
  19521. sprintf((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WifiPassword].ItemData);
  19522. isSuccess = ConfigurationStatus_Accepted;
  19523. }
  19524. else
  19525. {
  19526. isSuccess = ConfigurationStatus_Rejected;
  19527. }
  19528. }
  19529. if(strcmp(key, "StopChargingByButton") == 0)
  19530. {
  19531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemAccessibility == 1)
  19532. {
  19533. strcpy(str, (const char*)value);
  19534. for(int i = 0; str[i]; i++)
  19535. {
  19536. str[i] = tolower(str[i]);
  19537. }
  19538. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19539. {
  19540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19541. ShmSysConfigAndInfo->SysConfig.StopChargingByButton = (strcmp(str, "true")==0)?1:0;
  19542. isSuccess = ConfigurationStatus_Accepted;
  19543. }
  19544. else
  19545. isSuccess = ConfigurationStatus_Rejected;
  19546. }
  19547. else
  19548. {
  19549. isSuccess = ConfigurationStatus_Rejected;
  19550. }
  19551. }
  19552. #if 0
  19553. //For OCPP Test Case
  19554. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19555. {
  19556. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19557. {
  19558. strcpy(str, (const char*)value);
  19559. for(int i = 0; str[i]; i++)
  19560. {
  19561. str[i] = tolower(str[i]);
  19562. }
  19563. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19564. {
  19565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19566. isSuccess = ConfigurationStatus_Accepted;
  19567. }
  19568. else
  19569. isSuccess = ConfigurationStatus_Rejected;
  19570. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19571. }
  19572. else
  19573. {
  19574. isSuccess = ConfigurationStatus_Rejected;
  19575. }
  19576. }
  19577. #endif
  19578. #if 1
  19579. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19580. {
  19581. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19582. {
  19583. strcpy(str, (const char*)value);
  19584. for(int i = 0; str[i]; i++)
  19585. {
  19586. str[i] = tolower(str[i]);
  19587. }
  19588. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19589. {
  19590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19591. isSuccess = ConfigurationStatus_Accepted;
  19592. }
  19593. else
  19594. isSuccess = ConfigurationStatus_Rejected;
  19595. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19596. }
  19597. else
  19598. {
  19599. isSuccess = ConfigurationStatus_Rejected;
  19600. }
  19601. }
  19602. #endif
  19603. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19604. {
  19605. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19606. {
  19607. check_ascii = value[0];
  19608. if( (check_ascii < 48) || (check_ascii > 57) )
  19609. {
  19610. isSuccess = ConfigurationStatus_Rejected;
  19611. }
  19612. else
  19613. {
  19614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value));
  19615. isSuccess = ConfigurationStatus_Accepted;
  19616. }
  19617. }
  19618. else
  19619. {
  19620. isSuccess = ConfigurationStatus_Rejected;
  19621. }
  19622. }
  19623. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19624. {
  19625. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19626. {
  19627. check_ascii = value[0];
  19628. if( (check_ascii < 48) || (check_ascii > 57) )
  19629. {
  19630. isSuccess = ConfigurationStatus_Rejected;
  19631. }
  19632. else
  19633. {
  19634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value));
  19635. isSuccess = ConfigurationStatus_Accepted;
  19636. }
  19637. }
  19638. else
  19639. {
  19640. isSuccess = ConfigurationStatus_Rejected;
  19641. }
  19642. }
  19643. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19644. {
  19645. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19646. {
  19647. strcpy(str, (const char*)value);
  19648. for(int i = 0; str[i]; i++)
  19649. {
  19650. str[i] = tolower(str[i]);
  19651. }
  19652. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19653. {
  19654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19655. isSuccess = ConfigurationStatus_Accepted;
  19656. }
  19657. else
  19658. isSuccess = ConfigurationStatus_Rejected;
  19659. }
  19660. else
  19661. {
  19662. isSuccess = ConfigurationStatus_Rejected;
  19663. }
  19664. }
  19665. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19666. {
  19667. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19668. {
  19669. check_ascii = value[0];
  19670. if( (check_ascii < 48) || (check_ascii > 57) )
  19671. {
  19672. isSuccess = ConfigurationStatus_Rejected;
  19673. }
  19674. else
  19675. {
  19676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value));
  19677. isSuccess = ConfigurationStatus_Accepted;
  19678. }
  19679. }
  19680. else
  19681. {
  19682. isSuccess = ConfigurationStatus_Rejected;
  19683. }
  19684. }
  19685. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19686. {
  19687. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19688. {
  19689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value);
  19690. isSuccess = ConfigurationStatus_Accepted;
  19691. }
  19692. else
  19693. {
  19694. isSuccess = ConfigurationStatus_Rejected;
  19695. }
  19696. }
  19697. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19698. {
  19699. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19700. {
  19701. check_ascii = value[0];
  19702. if( (check_ascii < 48) || (check_ascii > 57) )
  19703. {
  19704. isSuccess = ConfigurationStatus_Rejected;
  19705. }
  19706. else
  19707. {
  19708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value));
  19709. isSuccess = ConfigurationStatus_Accepted;
  19710. }
  19711. }
  19712. else
  19713. {
  19714. isSuccess = ConfigurationStatus_Rejected;
  19715. }
  19716. }
  19717. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19718. {
  19719. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19720. {
  19721. strcpy(str, (const char*)value);
  19722. for(int i = 0; str[i]; i++)
  19723. {
  19724. str[i] = tolower(str[i]);
  19725. }
  19726. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  19727. {
  19728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  19729. isSuccess = ConfigurationStatus_Accepted;
  19730. }
  19731. else
  19732. isSuccess = ConfigurationStatus_Rejected;
  19733. }
  19734. else
  19735. {
  19736. isSuccess = ConfigurationStatus_Rejected;
  19737. }
  19738. }
  19739. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19740. {
  19741. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19742. {
  19743. check_ascii = value[0];
  19744. if( (check_ascii < 48) || (check_ascii > 57) )
  19745. {
  19746. isSuccess = ConfigurationStatus_Rejected;
  19747. }
  19748. else
  19749. {
  19750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value));
  19751. isSuccess = ConfigurationStatus_Accepted;
  19752. }
  19753. }
  19754. else
  19755. {
  19756. isSuccess = ConfigurationStatus_Rejected;
  19757. }
  19758. }
  19759. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19760. return isSuccess;
  19761. }
  19762. int TransactionMessageAttemptsGet(void)
  19763. {
  19764. return TransactionMessageAttemptsValue;
  19765. }
  19766. int FirstHeartBeatResponse(void)
  19767. {
  19768. return FirstHeartBeat;
  19769. }
  19770. int TransactionMessageRetryIntervalGet(void)
  19771. {
  19772. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19773. }
  19774. int ReadHttpStatus(int sock)
  19775. {
  19776. //char c;
  19777. char buff[1024]="",*ptr=buff+1;
  19778. int bytes_received, status;
  19779. DEBUG_INFO("Begin Response ..\n");
  19780. while((bytes_received = recv(sock, ptr, 1, 0))){
  19781. if(bytes_received==-1){
  19782. perror("ReadHttpStatus");
  19783. exit(1);
  19784. }
  19785. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19786. ptr++;
  19787. }
  19788. *ptr=0;
  19789. ptr=buff+1;
  19790. sscanf(ptr,"%*s %d ", &status);
  19791. DEBUG_INFO("%s\n",ptr);
  19792. DEBUG_INFO("status=%d\n",status);
  19793. DEBUG_INFO("End Response ..\n");
  19794. return (bytes_received>0)?status:0;
  19795. }
  19796. //the only filed that it parsed is 'Content-Length'
  19797. int ParseHeader(int sock)
  19798. {
  19799. //char c;
  19800. char buff[1024]="",*ptr=buff+4;
  19801. int bytes_received;
  19802. DEBUG_INFO("Begin HEADER ..\n");
  19803. while((bytes_received = recv(sock, ptr, 1, 0))){
  19804. if(bytes_received==-1){
  19805. perror("Parse Header");
  19806. exit(1);
  19807. }
  19808. if(
  19809. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19810. (ptr[-1]=='\r') && (*ptr=='\n' )
  19811. ) break;
  19812. ptr++;
  19813. }
  19814. *ptr=0;
  19815. ptr=buff+4;
  19816. //printf("%s",ptr);
  19817. if(bytes_received){
  19818. ptr=strstr(ptr,"Content-Length:");
  19819. if(ptr){
  19820. sscanf(ptr,"%*s %d",&bytes_received);
  19821. }else
  19822. bytes_received=-1; //unknown size
  19823. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19824. }
  19825. DEBUG_INFO("End HEADER ..\n");
  19826. return bytes_received ;
  19827. }
  19828. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19829. {
  19830. int result = TRUE;
  19831. char rmFileCmd[300]={0};
  19832. char FilePath[256]={0};
  19833. char ftpbuf[2048];
  19834. int systemresult;
  19835. sprintf(FilePath,"/mnt/%s",filename);
  19836. system("ping 8.8.8.8 &");
  19837. if((access(FilePath,F_OK))!=-1)
  19838. {
  19839. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19840. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19841. system(rmFileCmd);
  19842. }
  19843. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19844. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19845. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19846. else
  19847. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19848. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19849. systemresult = system(ftpbuf);
  19850. if(systemresult != 0)
  19851. {
  19852. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19853. result = FALSE;
  19854. }
  19855. system("pkill ping");
  19856. return result;
  19857. }
  19858. int sftpDownLoadFile(char *host, char *user, char *password, int port, char *path, char *filename,char *url)
  19859. {
  19860. int result = TRUE;
  19861. char rmFileCmd[300]={0};
  19862. char FilePath[256]={0};
  19863. char ftpbuf[2048];
  19864. int systemresult;
  19865. sprintf(FilePath,"/mnt/%s",filename);
  19866. system("ping 8.8.8.8 &");
  19867. if((access(FilePath,F_OK))!=-1)
  19868. {
  19869. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19870. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19871. system(rmFileCmd);
  19872. }
  19873. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19874. if(strlen(password)>0)
  19875. sprintf(ftpbuf,"timeout -t 360 sshpass -p '%s' scp -P %d %s@%s:%s%s %s", password, port, user, host, path, filename, FilePath);
  19876. else
  19877. sprintf(ftpbuf,"timeout -t 360 sshpass scp -P %d %s@%s:%s%s %s", port, user, host, path, filename, FilePath);
  19878. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19879. systemresult = system(ftpbuf);
  19880. if(systemresult != 0)
  19881. {
  19882. DEBUG_WARN("sshpass scp error!\n");
  19883. result = FALSE;
  19884. }
  19885. system("pkill ping");
  19886. return result;
  19887. }
  19888. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19889. {
  19890. int result = TRUE;
  19891. char rmFileCmd[300]={0};
  19892. char FilePath[256]={0};
  19893. char ftpbuf[2048];
  19894. int systemresult;
  19895. sprintf(FilePath,"/mnt/%s",filename);
  19896. system("ping 8.8.8.8 &");
  19897. if((access(FilePath,F_OK))!=-1)
  19898. {
  19899. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19900. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19901. system(rmFileCmd);
  19902. }
  19903. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19904. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19905. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19906. else
  19907. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19908. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19909. systemresult = system(ftpbuf);
  19910. if(systemresult != 0)
  19911. {
  19912. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19913. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --ca-certificate=/root/cacert.pem",filename, url);
  19914. else
  19915. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --no-check-certificate",filename, url);
  19916. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19917. systemresult = system(ftpbuf);
  19918. if(systemresult != 0)
  19919. {
  19920. DEBUG_WARN("FTP download fail!\n");
  19921. result = FALSE;
  19922. }
  19923. }
  19924. system("pkill ping");
  19925. return result;
  19926. }
  19927. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19928. {
  19929. char rmFileCmd[100]={0};
  19930. char FilePath[100]={0};
  19931. char buf[512];
  19932. int systemresult = 0;
  19933. //DEBUG_INFO("filename=%s\n",filename);
  19934. //DEBUG_INFO("url=%s\n",url);
  19935. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19936. if((access(FilePath,F_OK))!=-1)
  19937. {
  19938. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19939. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19940. system(rmFileCmd);
  19941. }
  19942. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19943. if(fp == NULL)
  19944. {
  19945. DEBUG_INFO("log is NULL\n");
  19946. return FALSE;
  19947. }
  19948. else
  19949. {
  19950. fprintf(fp, "%s\n", url);
  19951. fprintf(fp, "%s\n", filename);
  19952. fclose(fp);
  19953. }
  19954. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19955. if(phpFP == NULL)
  19956. {
  19957. DEBUG_INFO("PHP upload fail.\n");
  19958. return FALSE;
  19959. }
  19960. else
  19961. {
  19962. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19963. {
  19964. if(strstr(buf, "result") != NULL)
  19965. {
  19966. sscanf(buf, "result: %d", &systemresult);
  19967. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19968. }
  19969. }
  19970. pclose(phpFP);
  19971. }
  19972. if(systemresult != 1)
  19973. {
  19974. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19975. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19976. if(phpFP == NULL)
  19977. {
  19978. DEBUG_WARN("PHP PUT upload fail.\n");
  19979. return FALSE;
  19980. }
  19981. else
  19982. {
  19983. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19984. {
  19985. if(strstr(buf, "result") != NULL)
  19986. {
  19987. sscanf(buf, "result: %d", &systemresult);
  19988. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19989. }
  19990. }
  19991. pclose(phpFP);
  19992. }
  19993. }
  19994. if(systemresult != 1)
  19995. {
  19996. DEBUG_WARN("PHP PUT upload fail.\n");
  19997. return FALSE;
  19998. }
  19999. return TRUE;
  20000. }
  20001. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  20002. {
  20003. int result = FALSE;
  20004. char ftpbuf[200];
  20005. int systemresult;
  20006. /*
  20007. // Domaind name transfer to IP address
  20008. struct hostent* server;
  20009. char *IPbuffer;
  20010. server = gethostbyname(location);
  20011. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  20012. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  20013. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  20014. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  20015. systemresult = system(ftpbuf);
  20016. if(systemresult != 0)
  20017. {
  20018. DEBUG_INFO("ftpput error!\n");
  20019. }
  20020. else
  20021. {
  20022. result = TRUE;
  20023. DEBUG_INFO("ftpput OK!\n");
  20024. }
  20025. return result;
  20026. }
  20027. int sftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  20028. {
  20029. int result = FALSE;
  20030. char ftpbuf[200];
  20031. int systemresult;
  20032. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  20033. sprintf(ftpbuf, "sshpass -p %s scp %s -P %d %s@%s:%s%s", password, fnamePlusPath, port, user, location, path, filename);
  20034. DEBUG_INFO("sftp command: %s\n",ftpbuf);
  20035. systemresult = system(ftpbuf);
  20036. if(systemresult != 0)
  20037. {
  20038. DEBUG_INFO("sshpass error!\n");
  20039. }
  20040. else
  20041. {
  20042. result = TRUE;
  20043. DEBUG_INFO("sshpass OK!\n");
  20044. }
  20045. return result;
  20046. }
  20047. int GetOcppServerURL()
  20048. {
  20049. int result = FALSE;
  20050. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  20051. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  20052. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  20053. struct yuarel url;
  20054. char urlStr[512];
  20055. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  20056. {
  20057. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  20058. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  20059. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  20060. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  20061. if(yuarel_parse(&url, urlStr) != -1)
  20062. {
  20063. sprintf(OcppProtocol, "%s", url.scheme);
  20064. sprintf(OcppHost, "%s", url.host);
  20065. if(url.path == NULL)
  20066. OcppTempPath[0] = '\0';
  20067. else
  20068. {
  20069. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  20070. {
  20071. sprintf(OcppTempPath, "%s/", url.path);
  20072. }
  20073. else
  20074. {
  20075. sprintf(OcppTempPath, "%s", url.path);
  20076. }
  20077. }
  20078. if(url.port == 0)
  20079. {
  20080. if(strcmp(OcppProtocol, "wss") == 0)
  20081. OcppPort = 443;
  20082. else
  20083. OcppPort = 80;
  20084. }
  20085. else
  20086. OcppPort = url.port;
  20087. result = TRUE;
  20088. }
  20089. }
  20090. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  20091. {
  20092. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  20093. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  20094. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  20095. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  20096. if(yuarel_parse(&url, urlStr) != -1)
  20097. {
  20098. sprintf(OcppProtocol, "%s", url.scheme);
  20099. sprintf(OcppHost, "%s", url.host);
  20100. if(url.path == NULL)
  20101. OcppTempPath[0] = '\0';
  20102. else
  20103. sprintf(OcppTempPath, "%s", url.path);
  20104. if(url.port == 0)
  20105. {
  20106. if(strcmp(OcppProtocol, "wss") == 0)
  20107. OcppPort = 443;
  20108. else
  20109. OcppPort = 80;
  20110. }
  20111. else
  20112. OcppPort = url.port;
  20113. result = TRUE;
  20114. }
  20115. }
  20116. else
  20117. {
  20118. strcpy(OcppHost,"");
  20119. }
  20120. return result;
  20121. }
  20122. int GetOcppPath()
  20123. {
  20124. int result = FALSE;
  20125. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  20126. {
  20127. if(OcppTempPath == NULL)
  20128. {
  20129. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20130. }
  20131. else
  20132. {
  20133. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20134. }
  20135. result = TRUE;
  20136. goto End;
  20137. }
  20138. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  20139. {
  20140. if(OcppTempPath == NULL)
  20141. {
  20142. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  20143. }
  20144. else
  20145. {
  20146. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  20147. }
  20148. result = TRUE;
  20149. goto End;
  20150. }
  20151. else
  20152. {
  20153. strcpy(OcppPath,"");
  20154. }
  20155. End:
  20156. return result;
  20157. }
  20158. int GetOcppPort()
  20159. {
  20160. return OcppPort;
  20161. }
  20162. int GetOcppConnStatus(void)
  20163. {
  20164. return ShmOCPP16Data->OcppConnStatus;
  20165. }
  20166. void SetOcppConnStatus(uint8_t status)
  20167. {
  20168. ShmOCPP16Data->OcppConnStatus = status;
  20169. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  20170. }
  20171. int GetHeartBeatWithNOResponse(void)
  20172. {
  20173. return HeartBeatWithNOResponse;
  20174. }
  20175. void SetHeartBeatWithNOResponse(void)
  20176. {
  20177. HeartBeatWithNOResponse = 0;
  20178. }
  20179. void GetStartTransactionIdTag(int gun_index)
  20180. {
  20181. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  20182. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  20183. }
  20184. int GetStartTransactionId(int gun_index)
  20185. {
  20186. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  20187. }
  20188. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  20189. {
  20190. char ch;
  20191. FILE *fptr1;
  20192. int temptransactionId;
  20193. char str[100]={0};
  20194. temptransactionId = 0;
  20195. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  20196. {
  20197. DEBUG_INFO("IdTag is empty.\n");
  20198. return temptransactionId;
  20199. }
  20200. /*------ Read the file ----------------*/
  20201. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  20202. if (!fptr1)
  20203. {
  20204. DEBUG_INFO("QueueTransactionId file open error.\n");
  20205. //printf(" File not found or unable to open the input file!!\n");
  20206. return temptransactionId;
  20207. }
  20208. ch=fgetc(fptr1);
  20209. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  20210. rewind(fptr1);
  20211. if(ch!=EOF)
  20212. {
  20213. // printf("%c",ch);
  20214. while (fgets(str, 100, fptr1) != NULL)
  20215. {
  20216. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20217. if(str[0]=='\0')
  20218. {
  20219. break;
  20220. }
  20221. char *revbuf[8] = {0}; // Variable store string split
  20222. int num = 0;// Quantity after string split
  20223. DEBUG_INFO("Transaction queue data= %s\n", str);
  20224. splitstring(str,",",revbuf,&num); // String split
  20225. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  20226. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  20227. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  20228. DEBUG_INFO("------------------------------\n");
  20229. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  20230. {
  20231. if(isStopTransaction)
  20232. {
  20233. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  20234. {
  20235. temptransactionId = atoi(revbuf[2]);
  20236. //break;
  20237. }
  20238. }
  20239. else
  20240. {
  20241. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  20242. {
  20243. temptransactionId = atoi(revbuf[2]);
  20244. //break;
  20245. }
  20246. }
  20247. }
  20248. }
  20249. }
  20250. else
  20251. DEBUG_INFO("EOF\n");
  20252. fclose(fptr1);
  20253. /*------- End of reading ---------------*/
  20254. return temptransactionId;
  20255. }
  20256. void SetTransactionIdZero(int transactionId)
  20257. {
  20258. char ch;
  20259. FILE *fptr1, *fptr2;
  20260. int temptransactionId = 0;
  20261. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  20262. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  20263. if (!fptr1)
  20264. {
  20265. //printf(" File not found or unable to open the input file!!\n");
  20266. return ;
  20267. }
  20268. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  20269. if (!fptr2)
  20270. {
  20271. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  20272. fclose(fptr1);
  20273. return ;
  20274. }
  20275. ch=fgetc(fptr1);
  20276. rewind(fptr1);
  20277. if(ch!=EOF)
  20278. {
  20279. // copy all contents to the temporary file except the specific line
  20280. while (fgets(str, 100, fptr1) != NULL)
  20281. {
  20282. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20283. if(str[0]=='\0')
  20284. {
  20285. break;
  20286. }
  20287. char *revbuf[8] = {0};
  20288. int num = 0;
  20289. strcpy(strtemp, str);
  20290. splitstring(str,",",revbuf,&num);
  20291. if(revbuf[2][0] != '\0')
  20292. {
  20293. temptransactionId = atoi(revbuf[2]);
  20294. if(transactionId != temptransactionId)
  20295. {
  20296. fprintf(fptr2, "%s\n", strtemp);
  20297. }
  20298. }
  20299. }
  20300. }
  20301. fclose(fptr1);
  20302. fclose(fptr2);
  20303. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  20304. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  20305. /*------ Read the file ----------------*/
  20306. }
  20307. int InternetDisconnect(void)
  20308. {
  20309. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  20310. }
  20311. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  20312. void storeTempStopTransaction(int gun_index)
  20313. {
  20314. char guid[37]={0};
  20315. int tempIndex = 0;
  20316. char TempStopTransaction[256];
  20317. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20318. DEBUG_INFO("storeTempStopTransaction...\n");
  20319. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  20320. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  20321. //=========================== Stop Transaction Time ===============================================
  20322. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  20323. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  20324. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20325. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20326. {
  20327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20328. {
  20329. tempIndex = ((gun_index==2) ? 1: 0);
  20330. }
  20331. else
  20332. {
  20333. tempIndex = gun_index;
  20334. }
  20335. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20336. {
  20337. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20338. {
  20339. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  20340. }
  20341. }// END OF CHAdeMO_QUANTITY
  20342. }
  20343. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20344. {
  20345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20346. {
  20347. tempIndex = ((gun_index==2) ? 1: 0);
  20348. }
  20349. else
  20350. {
  20351. tempIndex = gun_index;
  20352. }
  20353. for (int index = 0; index < CCS_QUANTITY; index++)
  20354. {
  20355. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20356. {
  20357. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  20358. }
  20359. }// END OF CCS_QUANTITY
  20360. }
  20361. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20362. {
  20363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20364. {
  20365. tempIndex = ((gun_index==2) ? 1: 0);
  20366. }
  20367. else
  20368. {
  20369. tempIndex = gun_index;
  20370. }
  20371. for (int index = 0; index < GB_QUANTITY; index++)
  20372. {
  20373. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20374. {
  20375. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  20376. }
  20377. }// END OF GB_QUANTITY
  20378. }
  20379. else if(gunType[gun_index] == GUN_TYPE_DO)
  20380. {
  20381. tempIndex = gun_index;
  20382. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20383. {
  20384. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20385. {
  20386. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  20387. }
  20388. }
  20389. }
  20390. else
  20391. {
  20392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20393. {
  20394. tempIndex = 2;
  20395. }
  20396. else
  20397. {
  20398. tempIndex = gun_index;
  20399. }
  20400. for (int index = 0; index < AC_QUANTITY; index++)
  20401. {
  20402. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20403. {
  20404. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  20405. }
  20406. }// END OF AC_QUANTITY
  20407. }
  20408. //======================================== Message create ==============================================
  20409. json_object *StopTransaction = json_object_new_object();
  20410. json_object *transactionDatas = json_object_new_array();
  20411. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20412. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20413. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20414. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20415. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20416. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20417. meterValueBufferQuery(gun_index, transactionDatas);
  20418. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20419. random_uuid(guid);
  20420. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20421. ,MESSAGE_TYPE_CALL
  20422. ,guid
  20423. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20424. json_object_put(StopTransaction);
  20425. // Check File "TempStopTransaction" Exist
  20426. if((access(TempStopTransaction,F_OK))!=-1)
  20427. {
  20428. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20429. fclose(fopen(TempStopTransaction, "w"));
  20430. }
  20431. else
  20432. {
  20433. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20434. FILE *log = fopen(TempStopTransaction, "w+");
  20435. if(log == NULL)
  20436. {
  20437. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20438. return ;
  20439. }
  20440. else
  20441. {
  20442. fclose(log);
  20443. }
  20444. }
  20445. //Add TempStopTransaction | Update TempStopTransaction
  20446. // open file for writing
  20447. FILE *outfile;
  20448. outfile = fopen (TempStopTransaction, "a");
  20449. //DEBUG_INFO("data = %s\n", queuedata);
  20450. fputs(queuedata, outfile);
  20451. fputs("\n", outfile);
  20452. fclose (outfile);
  20453. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20454. OCPP_updatePeriodEnergy(gun_index);
  20455. }
  20456. void checkTempStopTransaction(int gun_index)
  20457. {
  20458. FILE *fptr1;
  20459. char ch;
  20460. char str[QUEUE_MESSAGE_LENGTH]={0};
  20461. char guid[37]={0};
  20462. char tempdata[65]={0};
  20463. char connectorStr[2]={0};
  20464. char TempStopTransaction[256];
  20465. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20466. fptr1 = fopen(TempStopTransaction, "r");
  20467. //TempStopTransaction格式: 槍號,StopTransaction封包
  20468. if (!fptr1)
  20469. {
  20470. //printf(" File not found or unable to open the input file!!\n");
  20471. return ;
  20472. }
  20473. ch=fgetc(fptr1);
  20474. //printf(" Now the content of the file %s is : \n",fname);
  20475. rewind(fptr1);
  20476. if(ch!=EOF)
  20477. {
  20478. // copy all contents to the temporary file except the specific line
  20479. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  20480. {
  20481. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20482. if(str[0]=='\0')
  20483. {
  20484. break;
  20485. }
  20486. //TempStopTransaction格式: 槍號,StopTransaction封包
  20487. strncpy(connectorStr, str, 1);
  20488. if(atoi(connectorStr) != (gun_index+1))
  20489. {
  20490. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  20491. fclose(fptr1);
  20492. return ;
  20493. }
  20494. //random_uuid(guid);
  20495. strncpy(guid, str+6, 36); //copy guid
  20496. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  20497. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  20498. {
  20499. //DEBUG_INFO("StopTransaction mapitem pass\n");
  20500. }
  20501. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  20502. OCPP_insert_transaction_msg(NO, str);
  20503. memset(str,0,ARRAY_SIZE(str));
  20504. }
  20505. }
  20506. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  20507. fclose(fptr1);
  20508. remove(TempStopTransaction); // remove the original file
  20509. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20510. }
  20511. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  20512. {
  20513. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20514. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  20515. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  20516. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  20517. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  20518. }
  20519. void FillTransactionId(int ConnectorId, int TransactionId)
  20520. {
  20521. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20522. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  20523. }
  20524. int GetWebSocketPingInterval(void)
  20525. {
  20526. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  20527. }
  20528. int GetServerSign(void)
  20529. {
  20530. return server_sign;
  20531. }
  20532. uint8_t GetOcppSecurityProfile()
  20533. {
  20534. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  20535. }
  20536. void MergeCertificates()
  20537. {
  20538. char cmdBuf[2048]={0};
  20539. if(access(ROOTCA_CS,F_OK) != -1)
  20540. {
  20541. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  20542. }
  20543. else
  20544. {
  20545. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20546. }
  20547. system(cmdBuf);
  20548. }
  20549. void GetOcppChargerBoxId(uint8_t *data)
  20550. {
  20551. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20552. }
  20553. void GetOcppSecurityPassword(uint8_t *data)
  20554. {
  20555. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20556. }
  20557. void SetOcppVersion(uint8_t *version)
  20558. {
  20559. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20560. DEBUG_INFO("ocpp version: %s\n", version);
  20561. if(strstr((char*)version, "ocpp1.6") != NULL)
  20562. {
  20563. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20564. }
  20565. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20566. {
  20567. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20568. system("pkill OcppBackend");
  20569. }
  20570. }
  20571. void SetServerSign(int value)
  20572. {
  20573. server_sign = value;
  20574. }
  20575. int GetBootNotificationInterval(void)
  20576. {
  20577. return BootNotificationInterval;
  20578. }
  20579. int GetInternetConn(void)
  20580. {
  20581. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20582. }
  20583. int GetBackendConnectionTimeout(void)
  20584. {
  20585. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20586. }
  20587. int isConnectorInitMode(int gun_index)
  20588. {
  20589. int tempIndex = 0;
  20590. int result = TRUE;
  20591. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20592. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20593. {
  20594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20595. {
  20596. tempIndex = ((gun_index==2) ? 1: 0);
  20597. }
  20598. else
  20599. {
  20600. tempIndex = gun_index;
  20601. }
  20602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20603. {
  20604. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20605. {
  20606. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20607. } //end of the same index
  20608. }//end of for CHAdeMO_QUANTITY
  20609. }
  20610. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20611. {
  20612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20613. {
  20614. tempIndex = ((gun_index==2) ? 1: 0);
  20615. }
  20616. else
  20617. {
  20618. tempIndex = gun_index;
  20619. }
  20620. for (int index = 0; index < CCS_QUANTITY; index++)
  20621. {
  20622. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20623. {
  20624. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20625. } //end of the same index
  20626. } // end of for CCS_QUANTITY
  20627. }
  20628. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20629. {
  20630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20631. {
  20632. tempIndex = ((gun_index==2) ? 1: 0);
  20633. }
  20634. else
  20635. {
  20636. tempIndex = gun_index;
  20637. }
  20638. for (int index = 0; index < GB_QUANTITY; index++)
  20639. {
  20640. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20641. {
  20642. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20643. } //end of the same index
  20644. } // end of for GB_QUANTITY
  20645. }
  20646. else if(gunType[gun_index] == GUN_TYPE_DO)
  20647. {
  20648. tempIndex = gun_index;
  20649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20650. {
  20651. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20652. {
  20653. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20654. } //end of the same index
  20655. }
  20656. }
  20657. else
  20658. {
  20659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20660. {
  20661. tempIndex = 2;
  20662. }
  20663. else
  20664. {
  20665. tempIndex = gun_index;
  20666. }
  20667. for (int index = 0; index < AC_QUANTITY; index++)
  20668. {
  20669. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20670. {
  20671. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20672. }//end of the same index
  20673. }//end of for AC_QUANTITY
  20674. }
  20675. return result;
  20676. }
  20677. void refreshProcDogTimer()
  20678. {
  20679. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20680. }
  20681. void InitialSystemValue(void)
  20682. {
  20683. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20684. locallistVersion=0;
  20685. BootNotificationInterval = 0;
  20686. authorizeRetryTimes = 0;
  20687. GunStatusInterval = 10;
  20688. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20689. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20690. //Heart Beat
  20691. HeartBeatWithNOResponse = 0;
  20692. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20693. if(HeartBeatWaitTime == 0)
  20694. FirstHeartBeat = TRUE;
  20695. else
  20696. FirstHeartBeat = FALSE;
  20697. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20698. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20699. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20700. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20701. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20702. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20703. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20704. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20705. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20706. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20707. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20708. //Status && ConnectorPlugIn Setting
  20709. Connector0PreviousSystemStatus = 99;
  20710. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20711. {
  20712. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20713. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20714. }
  20715. for (int index = 0; index < CCS_QUANTITY; index++)
  20716. {
  20717. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20718. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20719. }
  20720. for (int index = 0; index < GB_QUANTITY; index++)
  20721. {
  20722. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20723. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20724. }
  20725. for (int index = 0; index < AC_QUANTITY; index++)
  20726. {
  20727. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20728. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20729. }
  20730. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20731. {
  20732. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20733. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20734. }
  20735. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20736. {
  20737. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20738. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20739. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20740. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20741. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20742. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20743. }
  20744. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20745. refreshStartTimer(&clientTime.Heartbeat);
  20746. sleep(1);
  20747. }
  20748. void LWS_Send(char *str)
  20749. {
  20750. //=====================================================
  20751. // Check InternetConn 0: disconnected, 1: connected
  20752. //====================================================
  20753. if(GetOcppConnStatus() == 0)
  20754. {
  20755. DEBUG_INFO("offline now !!!\n");
  20756. return;
  20757. }
  20758. // Only disable isWebsocketSendable operation initiated by charger
  20759. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20760. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20761. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20762. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20763. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20764. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20765. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20766. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20767. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20768. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20769. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20770. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20771. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20772. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20773. {
  20774. isWebsocketSendable = 0;
  20775. }
  20776. pthread_mutex_lock(&lock_send);
  20777. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20778. sprintf((char *)SendBuffer, "%s", str);
  20779. SendBufLen = strlen(str);
  20780. pthread_mutex_unlock(&lock_send);
  20781. lws_callback_on_writable(wsi_client);
  20782. //lws_service(context, 0);
  20783. //sleep(1);
  20784. }
  20785. void LWS_SendNow(char *str)
  20786. {
  20787. //=====================================================
  20788. // Check InternetConn 0: disconnected, 1: connected
  20789. //====================================================
  20790. if(GetOcppConnStatus() == 0)
  20791. {
  20792. DEBUG_INFO("offline now !!!\n");
  20793. return;
  20794. }
  20795. // Only disable isWebsocketSendable operation initiated by charger
  20796. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20797. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20798. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20799. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20800. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20801. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20802. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20803. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20804. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20805. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20806. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20807. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20808. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20809. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20810. {
  20811. isWebsocketSendable = 0;
  20812. }
  20813. pthread_mutex_lock(&lock_send);
  20814. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20815. sprintf((char *)SendBuffer, "%s", str);
  20816. SendBufLen = strlen(str);
  20817. pthread_mutex_unlock(&lock_send);
  20818. lws_callback_on_writable(wsi_client);
  20819. lws_service(context, 0);
  20820. //sleep(1);
  20821. }