MessageHandler.c 1010 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472
  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 = 0;
  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 ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. //============================================
  90. // OCPP California Pricing Requirements
  91. //============================================
  92. static char dmsVersion[21] = {0};
  93. extern sqlite3 *db;
  94. int TransactionMessageAttemptsGet(void);
  95. int TransactionMessageRetryIntervalGet(void);
  96. int GetOcppConnStatus(void);
  97. void SetOcppConnStatus(uint8_t status);
  98. int setKeyValue(char *key, char *value);
  99. void OCPP_get_TableAuthlocalAllData(void);
  100. void processUnkownKey(void);
  101. struct InterLock
  102. {
  103. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  104. unsigned char isGetDiagnosticGoing:1;
  105. unsigned char isUpdateFirmwareGoing:1;
  106. }interLock;
  107. struct ClientTime
  108. {
  109. struct timespec Heartbeat;
  110. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  111. struct timespec StartTransaction;
  112. struct timespec StopTransaction;
  113. struct timespec MeterValues[CONNECTOR_QUANTITY];
  114. struct timespec RemoteStartWait;
  115. struct timespec TcciQueryDeduct;
  116. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  117. }clientTime;
  118. typedef union
  119. {
  120. //Operations Initiated by Central System
  121. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  122. struct
  123. {
  124. //CsMsgValue[0]
  125. unsigned char StatusNotificationReq:1; //bit 0,
  126. unsigned char StatusNotificationConf:1; //bit 1,
  127. unsigned char TriggerMeterValue:1; //bit 2,
  128. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  129. unsigned char isOnCharging:1; //bit 4,
  130. unsigned char :3; //bit5~7
  131. }bits[CONNECTOR_QUANTITY];
  132. }CpinitiateMsg;
  133. CpinitiateMsg cpinitateMsg;
  134. //GetConfiguration Array
  135. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  136. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  138. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  139. static char *ChargePointErrorCodeStr[] = {
  140. MACROSTR(ConnectorLockFailure),
  141. MACROSTR(EVCommunicationError),
  142. MACROSTR(GroundFailure),
  143. MACROSTR(HighTemperature),
  144. MACROSTR(InternalError),
  145. MACROSTR(LocalListConflict),
  146. MACROSTR(NoError),
  147. MACROSTR(OtherError),
  148. MACROSTR(OverCurrentFailure),
  149. MACROSTR(OverVoltage),
  150. MACROSTR(PowerMeterFailure),
  151. MACROSTR(PowerSwitchFailure),
  152. MACROSTR(ReaderFailure),
  153. MACROSTR(ResetFailure),
  154. MACROSTR(UnderVoltage),
  155. MACROSTR(WeakSignal)
  156. };
  157. static char * ChargePointStatusStr[] = {
  158. MACROSTR(Available),
  159. MACROSTR(Preparing),
  160. MACROSTR(Charging),
  161. MACROSTR(SuspendedEVSE),
  162. MACROSTR(SuspendedEV),
  163. MACROSTR(Finishing),
  164. MACROSTR(Reserved),
  165. MACROSTR(Unavailable),
  166. MACROSTR(Faulted)
  167. };
  168. static char *RegistrationStatusStr[] = {
  169. MACROSTR(Accepted),
  170. MACROSTR(Pending),
  171. MACROSTR(Rejected)
  172. };
  173. static char *AvailabilityTypeStr[] = {
  174. MACROSTR(Inoperative),
  175. MACROSTR(Operative)
  176. };
  177. static char *AvailabilityStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(Scheduled)
  181. };
  182. static char *ConfigurationStatusStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(RebootRequired),
  186. MACROSTR(NotSupported)
  187. };
  188. static char *ClearCacheStatusStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Rejected)
  191. };
  192. static char *ChargingProfilePurposeTypeStr[] = {
  193. MACROSTR(ChargePointMaxProfile),
  194. MACROSTR(TxDefaultProfile),
  195. MACROSTR(TxProfile)
  196. };
  197. static char *ChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Rejected),
  200. MACROSTR(NotSupported)
  201. };
  202. static char *ClearChargingProfileStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Unknown)
  205. };
  206. static char *GetCompositeScheduleStatusStr[] = {
  207. MACROSTR(Accepted),
  208. MACROSTR(Rejected)
  209. };
  210. static char *UpdateTypeStr[] = {
  211. MACROSTR(Differential),
  212. MACROSTR(Full)
  213. };
  214. static char *UpdateStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Failed),
  217. MACROSTR(NotSupported),
  218. MACROSTR(VersionMismatch)
  219. };
  220. static char *RemoteStartStopStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Rejected)
  223. };
  224. static char *ReservationStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Faulted),
  227. MACROSTR(Occupied),
  228. MACROSTR(Rejected),
  229. MACROSTR(Unavailable)
  230. };
  231. static char *ResetTypeStr[] = {
  232. MACROSTR(Hard),
  233. MACROSTR(Soft)
  234. };
  235. static char *ResetStatusStr[] = {
  236. MACROSTR(Accepted),
  237. MACROSTR(Rejected)
  238. };
  239. static char * DiagnosticsStatusStr[] = {
  240. MACROSTR(Idle),
  241. MACROSTR(Uploaded),
  242. MACROSTR(UploadFailed),
  243. MACROSTR(Uploading)
  244. };
  245. static char * FirmwareStatusStr[] = {
  246. MACROSTR(Downloaded),
  247. MACROSTR(DownloadFailed),
  248. MACROSTR(Downloading),
  249. MACROSTR(Idle),
  250. MACROSTR(InstallationFailed),
  251. MACROSTR(Installing),
  252. MACROSTR(Installed)
  253. };
  254. static char * MessageTriggerStr[] = {
  255. MACROSTR(BootNotification),
  256. MACROSTR(DiagnosticsStatusNotification),
  257. MACROSTR(FirmwareStatusNotification),
  258. MACROSTR(Heartbeat),
  259. MACROSTR(MeterValues),
  260. MACROSTR(StatusNotification)
  261. };
  262. static char * TriggerMessageStatusStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected),
  265. MACROSTR(NotImplemented)
  266. };
  267. static char * UnlockStatusStr[] = {
  268. MACROSTR(Unlocked),
  269. MACROSTR(UnlockFailed),
  270. MACROSTR(NotSupported)
  271. };
  272. #if 0
  273. static char * StopTransactionReasonStr[] = {
  274. MACROSTR(EmergencyStop),
  275. MACROSTR(EVDisconnected),
  276. MACROSTR(HardReset),
  277. MACROSTR(Local),
  278. MACROSTR(Other),
  279. MACROSTR(PowerLoss),
  280. MACROSTR(Reboot),
  281. MACROSTR(Remote),
  282. MACROSTR(SoftReset),
  283. MACROSTR(UnlockCommand),
  284. MACROSTR(DeAuthorized)
  285. };
  286. #endif
  287. static char * CancelReservationStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Rejected)
  290. };
  291. static char * ReadingContextStr[] = {
  292. MACROSTR(Interruption.Begin),
  293. MACROSTR(Interruption.End),
  294. MACROSTR(Other),
  295. MACROSTR(Sample.Clock),
  296. MACROSTR(Sample.Periodic),
  297. MACROSTR(Transaction.Begin),
  298. MACROSTR(Transaction.End),
  299. MACROSTR(Trigger)
  300. };
  301. static char * ValueFormatStr[] = {
  302. MACROSTR(Raw),
  303. MACROSTR(SignedData)
  304. };
  305. static char * MeasurandStr[] = {
  306. MACROSTR(Current.Export),
  307. MACROSTR(Current.Import),
  308. MACROSTR(Current.Offered),
  309. MACROSTR(Energy.Active.Export.Register),
  310. MACROSTR(Energy.Active.Import.Register),
  311. MACROSTR(Energy.Reactive.Export.Register),
  312. MACROSTR(Energy.Reactive.Import.Register),
  313. MACROSTR(Energy.Active.Export.Interval),
  314. MACROSTR(Energy.Active.Import.Interval),
  315. MACROSTR(Energy.Reactive.Export.Interval),
  316. MACROSTR(Energy.Reactive.Import.Interval),
  317. MACROSTR(Frequency),
  318. MACROSTR(Power.Active.Export),
  319. MACROSTR(Power.Active.Import),
  320. MACROSTR(Power.Factor),
  321. MACROSTR(Power.Offered),
  322. MACROSTR(Power.Reactive.ExportMACROSTR),
  323. MACROSTR(Power.Reactive.Import),
  324. MACROSTR(RPM),
  325. MACROSTR(SoC),
  326. MACROSTR(Temperature),
  327. MACROSTR(Voltage)
  328. };
  329. static char * LocationStr[] = {
  330. MACROSTR(Body),
  331. MACROSTR(Cable),
  332. MACROSTR(EV),
  333. MACROSTR(Inlet),
  334. MACROSTR(Outlet)
  335. };
  336. static char * PhaseStr[] = {
  337. MACROSTR(L1),
  338. MACROSTR(L2),
  339. MACROSTR(L3),
  340. MACROSTR(N),
  341. MACROSTR(L1-N),
  342. MACROSTR(L2-N),
  343. MACROSTR(L3-N),
  344. MACROSTR(L1-L2),
  345. MACROSTR(L2-L3),
  346. MACROSTR(L3-L1)
  347. };
  348. static char * UnitOfMeasureStr[] = {
  349. MACROSTR(Wh),
  350. MACROSTR(kWh),
  351. MACROSTR(varh),
  352. MACROSTR(kvarh),
  353. MACROSTR(W),
  354. MACROSTR(kW),
  355. MACROSTR(VA),
  356. MACROSTR(kVA),
  357. MACROSTR(var),
  358. MACROSTR(kvar),
  359. MACROSTR(A),
  360. MACROSTR(V),
  361. MACROSTR(Celsius),
  362. MACROSTR(Fahrenheit),
  363. MACROSTR(K),
  364. MACROSTR(Percent)
  365. };
  366. //=========================================
  367. // Certificate related routine
  368. //=========================================
  369. int certVerify(char *privateKey, char *cert)
  370. {
  371. int result = PASS;
  372. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  373. // Load certificate file
  374. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  375. {
  376. DEBUG_ERROR("Load certificate error!\n");
  377. result = FAIL;
  378. }
  379. // Load private key file
  380. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  381. {
  382. DEBUG_ERROR("Load private key error!\n");
  383. result = FAIL;
  384. }
  385. if(!SSL_CTX_check_private_key(ctx))
  386. {
  387. result = FAIL;
  388. }
  389. SSL_CTX_free(ctx);
  390. return result;
  391. }
  392. //=========================================
  393. // TTIA routine
  394. //=========================================
  395. int sendTTIAInfo(uint8_t gun_index)
  396. {
  397. static int sn = 0;
  398. int result = FAIL;
  399. struct hostent *server;
  400. int udp_socket_fd;
  401. struct sockaddr_in dest_addr = {0};
  402. uint8_t tx_buf[80] = {0};
  403. uint8_t logBuf[256]= {0};
  404. uint8_t tx_len, tempIndex, socStart, socEnd;
  405. uint16_t PresentChargedEnergy;
  406. struct tm tmStart, tmEnd;
  407. DEBUG_INFO("sendTTIAInfo...\n");
  408. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  409. {
  410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  411. {
  412. tempIndex = ((gun_index==2) ? 1: 0);
  413. }
  414. else
  415. {
  416. tempIndex = gun_index;
  417. }
  418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  419. {
  420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  421. {
  422. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  423. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  424. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  425. }
  426. }
  427. }
  428. else if(gunType[gun_index] == GUN_TYPE_CCS)
  429. {
  430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  431. {
  432. tempIndex = ((gun_index==2) ? 1: 0);
  433. }
  434. else
  435. {
  436. tempIndex = gun_index;
  437. }
  438. for (int index = 0; index < CCS_QUANTITY; index++)
  439. {
  440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  441. {
  442. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  443. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  444. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  445. }
  446. }
  447. }
  448. else if(gunType[gun_index] == GUN_TYPE_GBT)
  449. {
  450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  451. {
  452. tempIndex = ((gun_index==2) ? 1: 0);
  453. }
  454. else
  455. {
  456. tempIndex = gun_index;
  457. }
  458. for (int index = 0; index < GB_QUANTITY; index++)
  459. {
  460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  461. {
  462. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  463. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  464. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  465. }
  466. }
  467. }
  468. else if(gunType[gun_index] == GUN_TYPE_DO)
  469. {
  470. tempIndex = gun_index;
  471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  472. {
  473. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  474. {
  475. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  476. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  477. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  478. }
  479. }
  480. }
  481. else
  482. {
  483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  484. {
  485. tempIndex = 2;
  486. }
  487. else
  488. {
  489. tempIndex = gun_index;
  490. }
  491. for (int index = 0; index < AC_QUANTITY; index++)
  492. {
  493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  494. {
  495. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  496. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  497. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  498. }
  499. }// END
  500. }
  501. // Message assembly
  502. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  503. tx_buf[4] = 0x02; // Protocol Version
  504. tx_buf[5] = 0xb0; // Message ID
  505. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  506. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  507. tx_buf[8] = 0x00; // CarID low byte
  508. tx_buf[9] = 0x00; // CarID high byte
  509. tx_buf[10] = 0x00; // ID Storage
  510. tx_buf[11] = 0x00; // Driver lowest byte
  511. tx_buf[12] = 0x00; // Driver 2nd byte
  512. tx_buf[13] = 0x00; // Driver 3rd byte
  513. tx_buf[14] = 0x00; // Driver highest byte
  514. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  515. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  516. tx_buf[17] = 0x00; // Reserve
  517. tx_buf[18] = 60 & 0xff; // Payload length low byte
  518. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  519. // EVSE provider
  520. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  521. // EVSE provider
  522. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  523. // EVSE id
  524. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  525. // Connector id
  526. tx_buf[37] = gun_index;
  527. // EVSE station
  528. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  529. // Vehicle SN
  530. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  531. // Mileage
  532. tx_buf[61] = 0x00; // lowest byte
  533. tx_buf[62] = 0x00; // 2nd byte
  534. tx_buf[63] = 0x00; // highest byte
  535. // Start date time 6 bytes
  536. 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))
  537. {
  538. struct tm *tmTarget;
  539. struct timeb tbTarget;
  540. tmStart.tm_year -= 1900;
  541. tmStart.tm_mon -= 1;
  542. tmStart.tm_gmtoff = 0;
  543. tbTarget.time = mktime(&tmStart);
  544. tbTarget.timezone = 0;
  545. tbTarget.time += (8*3600);
  546. tmTarget = gmtime(&tbTarget.time);
  547. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  548. tx_buf[65] = (tmTarget->tm_mon+1);
  549. tx_buf[66] = tmTarget->tm_mday;
  550. tx_buf[67] = tmTarget->tm_hour;
  551. tx_buf[68] = tmTarget->tm_min;
  552. tx_buf[69] = tmTarget->tm_sec;
  553. }
  554. // Stop date time 6 bytes
  555. 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))
  556. {
  557. struct tm *tmTarget;
  558. struct timeb tbTarget;
  559. tmEnd.tm_year -= 1900;
  560. tmEnd.tm_mon -= 1;
  561. tmEnd.tm_gmtoff = 0;
  562. tbTarget.time = mktime(&tmEnd);
  563. tbTarget.timezone = 0;
  564. tbTarget.time += (8*3600);
  565. tmTarget = gmtime(&tbTarget.time);
  566. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  567. tx_buf[71] = (tmTarget->tm_mon+1);
  568. tx_buf[72] = tmTarget->tm_mday;
  569. tx_buf[73] = tmTarget->tm_hour;
  570. tx_buf[74] = tmTarget->tm_min;
  571. tx_buf[75] = tmTarget->tm_sec;
  572. }
  573. // Session energy 2 bytes
  574. tx_buf[76] = PresentChargedEnergy & 0xff;
  575. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  576. // Start SOC 1 byte
  577. tx_buf[78] = socStart;
  578. // Stop SOC 1 byte
  579. tx_buf[79] = socEnd;
  580. // Open socket
  581. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  582. if(udp_socket_fd == -1)
  583. {
  584. DEBUG_ERROR("UDP socket create failed!\n");
  585. }
  586. else
  587. {
  588. // Get server DNS entry
  589. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  590. if (server == NULL)
  591. {
  592. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  593. }
  594. else
  595. {
  596. // Build the server's Internet address
  597. bzero((char *) &dest_addr, sizeof(dest_addr));
  598. dest_addr.sin_family = AF_INET;
  599. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  600. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  601. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  602. {
  603. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  604. {
  605. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  606. }
  607. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  608. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  609. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  610. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  611. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  612. DEBUG_TTIA_INFO("---------- Header ----------\n");
  613. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  614. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  615. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  616. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  617. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  618. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  619. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  620. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  621. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  622. DEBUG_TTIA_INFO("Len: 0x3C\n");
  623. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  624. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  625. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  626. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  627. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  628. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  629. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  630. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  631. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  632. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  633. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  634. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  635. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  636. DEBUG_TTIA_INFO("=========================================\n");
  637. sn++;
  638. result = PASS;
  639. }
  640. else
  641. {
  642. DEBUG_ERROR("UDP sent out fail.\n");
  643. }
  644. }
  645. }
  646. return result;
  647. }
  648. //=========================================
  649. // Save configuration
  650. //=========================================
  651. int runShellCmd(const char*cmd)
  652. {
  653. int result = FAIL;
  654. char buf[256];
  655. FILE *fp;
  656. fp = popen(cmd, "r");
  657. if(fp != NULL)
  658. {
  659. while(fgets(buf, sizeof(buf), fp) != NULL)
  660. {
  661. DEBUG_INFO("%s\n", buf);
  662. }
  663. result = PASS;
  664. }
  665. pclose(fp);
  666. return result;
  667. }
  668. int StoreUsrConfigData(struct SysConfigData *UsrData)
  669. {
  670. int result = PASS;
  671. int fd,wrd;
  672. unsigned int i,Chk;
  673. unsigned char *ptr, *BufTmp;
  674. int MtdBlockSize = 0x300000;
  675. Chk=0;
  676. ptr=(unsigned char *)UsrData;
  677. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  678. {
  679. memset(BufTmp,0,MtdBlockSize);
  680. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  681. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  682. Chk+=*(BufTmp+i);
  683. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  684. // Output configuration to file.
  685. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  686. if (fd < 0)
  687. {
  688. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  689. free(BufTmp);
  690. return 0;
  691. }
  692. wrd=write(fd, BufTmp, MtdBlockSize);
  693. close(fd);
  694. if(wrd<MtdBlockSize)
  695. {
  696. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  697. free(BufTmp);
  698. return 0;
  699. }
  700. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  701. DEBUG_INFO("Erase /dev/mtd10.\n");
  702. runShellCmd("flash_erase /dev/mtd10 0 0");
  703. DEBUG_INFO("Write /dev/mtd10.\n");
  704. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  705. DEBUG_INFO("Erase /dev/mtd11.\n");
  706. runShellCmd("flash_erase /dev/mtd11 0 0");
  707. DEBUG_INFO("Write /dev/mtd11.\n");
  708. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  709. system("rm -f /mnt/EvseConfig.bin");
  710. DEBUG_INFO("EvseConfig write to flash OK\n");
  711. }
  712. else
  713. {
  714. DEBUG_ERROR("alloc BlockSize NG\r\n");
  715. result = FAIL;
  716. }
  717. if(BufTmp!=NULL)
  718. free(BufTmp);
  719. return result;
  720. }
  721. //=========================================
  722. // Sqlite3 related function
  723. //=========================================
  724. static int selectSqlCount = 0;
  725. static int callback(void *data, int argc, char **argv, char **azColName){
  726. int i;
  727. //printf("%s: ", (const char*)data);
  728. selectSqlCount = argc;
  729. for(i = 0; i<argc; i++){
  730. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  731. }
  732. //printf("\n");
  733. return 0;
  734. }
  735. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  736. //int i;
  737. //printf("%s:\n", (const char*)data);
  738. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  739. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  740. return 0;
  741. }
  742. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  743. //printf("%s:\n", (const char*)data);
  744. //idTag
  745. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  746. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  747. //parentIdTag
  748. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  749. //expir_date
  750. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  751. //status
  752. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  753. //version
  754. if(columenCount > 5)
  755. idTagQuery.listVersionInt = atoi(columnValue[5]);
  756. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  757. return 0;
  758. }
  759. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  760. {
  761. // localversion = argv[5] ? atoi(argv[5]) : 0;
  762. // printf("localversion=%d\n", localversion);
  763. return 0;
  764. }
  765. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  766. {
  767. for (int i = 0; i < n_columns; i++)
  768. {
  769. DEBUG_INFO("%s\t", col_values[i]);
  770. }
  771. DEBUG_INFO("\n");
  772. return 0;
  773. }
  774. int OCPP_cleanLocalCache()
  775. {
  776. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  777. char *errMsg = 0;
  778. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  779. if (SQLITE_OK != rc)
  780. {
  781. DEBUG_INFO("SQL error: %s\n",errMsg);
  782. return FALSE;
  783. }
  784. return TRUE;
  785. }
  786. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  787. {
  788. int isSuccess = TRUE;
  789. int ret = 0;
  790. //const char* data = "Callback function called";
  791. char sql[300];
  792. char zErrMsg[200];
  793. memset(sql, 0, 300);
  794. memset(zErrMsg, 0, 200);
  795. 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);
  796. //* Execute SQL statement */
  797. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  798. if( ret != SQLITE_OK )
  799. {
  800. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  801. isSuccess = FALSE;
  802. }
  803. return isSuccess;
  804. }
  805. void OCPP_getIdTagFromLocalCache(char idTag[])
  806. {
  807. int rc = 0;
  808. char sql[100];
  809. char zErrMsg[100];
  810. memset(sql, 0, 100);
  811. memset(zErrMsg, 0, 100);
  812. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  813. memset(&idTagQuery, 0, sizeof(idTagQuery));
  814. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. }
  822. void OCPP_getListVerion()
  823. {
  824. int rc = 0;
  825. // const char* data = "Callback function called";
  826. char sql[100];
  827. char zErrMsg[100];
  828. memset(sql, 0, 100);
  829. memset(zErrMsg, 0, 100);
  830. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  831. /* Execute SQL statement */
  832. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  833. if( rc != SQLITE_OK )
  834. {
  835. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  836. }
  837. }
  838. void OCPP_get_TableAuthlocalAllData(void)
  839. {
  840. int rc = 0;
  841. char sql[100];
  842. char zErrMsg[100];
  843. memset(sql, 0, 100);
  844. memset(zErrMsg, 0, 100);
  845. sprintf(sql,"select * from ocpp_auth_local ");
  846. /* Execute SQL statement */
  847. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  848. if( rc != SQLITE_OK )
  849. {
  850. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  851. }
  852. //return ver;
  853. }
  854. int OCPP_cleanLocalList()
  855. {
  856. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  857. char *errMsg = 0;
  858. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  859. if (SQLITE_OK != rc)
  860. {
  861. DEBUG_INFO("%s\n",errMsg);
  862. return FALSE;
  863. }
  864. return TRUE;
  865. }
  866. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  867. {
  868. int isSuccess = FALSE;
  869. int ret = 0;
  870. //const char* data = "Callback function called";
  871. char sql[300];
  872. char zErrMsg[200];
  873. memset(sql, 0, 300);
  874. memset(zErrMsg, 0, 200);
  875. 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);
  876. //* Execute SQL statement */
  877. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  878. if( ret != SQLITE_OK )
  879. {
  880. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  881. return isSuccess;
  882. }
  883. memset(sql, 0, 300);
  884. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  885. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  886. if( ret != SQLITE_OK )
  887. {
  888. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  889. return isSuccess;
  890. }
  891. isSuccess = TRUE;
  892. return isSuccess;
  893. }
  894. void OCPP_getIdTagFromLocalList(char idTag[])
  895. {
  896. int rc = 0;
  897. // const char* data = "Callback function called";
  898. char sql[100];
  899. char zErrMsg[100];
  900. memset(sql, 0, 100);
  901. memset(zErrMsg, 0, 100);
  902. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  903. memset(&idTagQuery, 0, sizeof(idTagQuery));
  904. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  905. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  906. /* Execute SQL statement */
  907. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  908. if( rc != SQLITE_OK )
  909. {
  910. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  911. }
  912. //return ver;
  913. }
  914. void OCPP_deleteIdTagFromLocalList(char idTag[])
  915. {
  916. //int ver = 0;
  917. //int isSuccess = FALSE;
  918. int rc = 0;
  919. char sql[100];
  920. char zErrMsg[100];
  921. memset(sql, 0, 100);
  922. memset(zErrMsg, 0, 100);
  923. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  924. //* Execute SQL statement */
  925. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  926. if( rc != SQLITE_OK )
  927. {
  928. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  929. }
  930. }
  931. int getCurrentYear()
  932. {
  933. int result = 0;
  934. time_t CurrentTime;
  935. struct tm *tm;
  936. CurrentTime = time(NULL);
  937. tm=localtime(&CurrentTime);
  938. result = (tm->tm_year + 1900);
  939. return result;
  940. }
  941. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  942. {
  943. int result = PASS;
  944. char* errMsg = NULL;
  945. char sqlStr[8192];
  946. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  947. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  948. {
  949. result = FAIL;
  950. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  951. }
  952. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  953. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  954. {
  955. result = FAIL;
  956. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  957. }
  958. return result;
  959. }
  960. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  961. {
  962. int isSuccess = TRUE;
  963. int tempIndex;
  964. json_object *EnergyDataTransfer = json_object_new_object();
  965. json_object *periodEnergys = json_object_new_object();
  966. char sql[1024];
  967. char zErrMsg[200];
  968. memset(sql, 0, ARRAY_SIZE(sql));
  969. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  970. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  971. {
  972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  973. {
  974. tempIndex = ((gun_index==2) ? 1: 0);
  975. }
  976. else
  977. {
  978. tempIndex = gun_index;
  979. }
  980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  981. {
  982. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  983. {
  984. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  985. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  986. {
  987. uint8_t period[3];
  988. sprintf((char*)period, "%d", idxPeriod);
  989. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  990. }
  991. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  992. } //end of the same index
  993. }//end of for CHAdeMO_QUANTITY
  994. }
  995. else if(gunType[gun_index] == GUN_TYPE_CCS)
  996. {
  997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  998. {
  999. tempIndex = ((gun_index==2) ? 1: 0);
  1000. }
  1001. else
  1002. {
  1003. tempIndex = gun_index;
  1004. }
  1005. for (int index = 0; index < CCS_QUANTITY; index++)
  1006. {
  1007. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1008. {
  1009. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1010. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1011. {
  1012. uint8_t period[3];
  1013. sprintf((char*)period, "%d", idxPeriod);
  1014. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1015. }
  1016. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1017. } //end of the same index
  1018. } // end of for CCS_QUANTITY
  1019. }
  1020. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1021. {
  1022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1023. {
  1024. tempIndex = ((gun_index==2) ? 1: 0);
  1025. }
  1026. else
  1027. {
  1028. tempIndex = gun_index;
  1029. }
  1030. for (int index = 0; index < GB_QUANTITY; index++)
  1031. {
  1032. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1033. {
  1034. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1035. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1036. {
  1037. uint8_t period[3];
  1038. sprintf((char*)period, "%d", idxPeriod);
  1039. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1040. }
  1041. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1042. } //end of the same index
  1043. } // end of for GB_QUANTITY
  1044. }
  1045. else if(gunType[gun_index] == GUN_TYPE_DO)
  1046. {
  1047. tempIndex = gun_index;
  1048. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1049. {
  1050. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1051. {
  1052. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1053. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1054. {
  1055. uint8_t period[3];
  1056. sprintf((char*)period, "%d", idxPeriod);
  1057. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1058. }
  1059. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1060. } //end of the same index
  1061. }
  1062. }
  1063. else
  1064. {
  1065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1066. {
  1067. tempIndex = 2;
  1068. }
  1069. else
  1070. {
  1071. tempIndex = gun_index;
  1072. }
  1073. for (int index = 0; index < AC_QUANTITY; index++)
  1074. {
  1075. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1076. {
  1077. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1078. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1079. {
  1080. uint8_t period[3];
  1081. sprintf((char*)period, "%d", idxPeriod);
  1082. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1083. }
  1084. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1085. }//end of the same index
  1086. }//end of for AC_QUANTITY
  1087. }
  1088. 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));
  1089. json_object_put(EnergyDataTransfer);
  1090. //* Execute SQL statement */
  1091. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1092. {
  1093. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1094. isSuccess = FALSE;
  1095. }
  1096. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1097. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1098. {
  1099. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1100. isSuccess = FALSE;
  1101. }
  1102. return isSuccess;
  1103. }
  1104. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1105. {
  1106. int isSuccess = TRUE;
  1107. char sql[512];
  1108. char zErrMsg[200];
  1109. int rows, cols;
  1110. char **resultData;
  1111. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1112. /* Execute SQL statement */
  1113. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1114. {
  1115. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1116. isSuccess = FALSE;
  1117. }
  1118. else
  1119. {
  1120. if((rows > 0) && (atoi(resultData[4]) > 0))
  1121. {
  1122. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1123. }
  1124. else
  1125. {
  1126. DEBUG_WARN("There is not match transaction data.\n");
  1127. isSuccess = FALSE;
  1128. }
  1129. }
  1130. return isSuccess;
  1131. }
  1132. 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)
  1133. {
  1134. int result = PASS;
  1135. char* errMsg = NULL;
  1136. char sqlStr[8192];
  1137. 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');",
  1138. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1139. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1140. {
  1141. result = FAIL;
  1142. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1143. }
  1144. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1145. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1146. {
  1147. result = FAIL;
  1148. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1149. }
  1150. return result;
  1151. }
  1152. int OCPP_update_deduct_info(int txId, char *creditNo)
  1153. {
  1154. int result = PASS;
  1155. char* errMsg = NULL;
  1156. char sqlStr[8192];
  1157. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1158. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1159. {
  1160. result = FAIL;
  1161. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1162. }
  1163. return result;
  1164. }
  1165. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1166. {
  1167. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1168. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1169. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1170. atoi(columnValue[1]),
  1171. columnValue[2],
  1172. atoi(columnValue[3])==1?"true":"false",
  1173. atoi(columnValue[4])==1?"true":"false",
  1174. columnValue[5],
  1175. columnValue[9]);
  1176. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1177. return 0;
  1178. }
  1179. void OCPP_query_deduct_info()
  1180. {
  1181. int rc = 0;
  1182. char sql[100];
  1183. char zErrMsg[100];
  1184. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1185. /* Execute SQL statement */
  1186. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1187. if( rc != SQLITE_OK )
  1188. {
  1189. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1190. }
  1191. }
  1192. void reportReaderStatus(int gun_index)
  1193. {
  1194. struct timeval tmnow;
  1195. struct tm *tm;
  1196. char buf[28];//, usec_buf[6];
  1197. gettimeofday(&tmnow, NULL);
  1198. time_t t;
  1199. t = time(NULL);
  1200. /*UTC time and date*/
  1201. tm = gmtime(&t);
  1202. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1203. #if 0 // remove temporally
  1204. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1205. strcat(buf,".");
  1206. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1207. strcat(buf,usec_buf);
  1208. #endif
  1209. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1210. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1211. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1212. (gun_index+1),
  1213. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1214. buf,
  1215. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1216. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1217. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1218. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1219. }
  1220. //==========================================
  1221. // Check time passed since today
  1222. //==========================================
  1223. long long DiffTimebWithNow(struct timeb ST)
  1224. {
  1225. //return milli-second
  1226. struct timeb ET;
  1227. long long StartTime,StopTime;
  1228. ftime(&ET);
  1229. StartTime=(long long)ST.time;
  1230. StopTime=(long long)ET.time;
  1231. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1232. }
  1233. int getTimePassSinceToday(uint8_t gun_index)
  1234. {
  1235. int result = -1;
  1236. static time_t lastTime[4];
  1237. time_t t;
  1238. struct tm *tmStartToday;
  1239. struct timeb tbStartToday;
  1240. t=time(NULL);
  1241. if(difftime(t, lastTime[gun_index])>0)
  1242. {
  1243. tmStartToday=localtime(&t);
  1244. tmStartToday->tm_hour = 0;
  1245. tmStartToday->tm_min = 0;
  1246. tmStartToday->tm_sec = 0;
  1247. tbStartToday.time = mktime(tmStartToday);
  1248. tbStartToday.millitm = 0;
  1249. result = DiffTimebWithNow(tbStartToday)/1000;
  1250. lastTime[gun_index] = t;
  1251. }
  1252. return result;
  1253. }
  1254. void getNowDatetime(uint8_t *data)
  1255. {
  1256. time_t t = time(NULL);
  1257. struct tm tm = *localtime(&t);
  1258. 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);
  1259. }
  1260. int syncDateTimeRTC(uint8_t *data)
  1261. {
  1262. struct ParsingResult
  1263. {
  1264. int result;
  1265. int scanedElement;
  1266. int year;
  1267. int month;
  1268. int mday;
  1269. int hour;
  1270. int min;
  1271. int sec;
  1272. int tz_hour;
  1273. int tz_min;
  1274. float minSec;
  1275. }result;
  1276. struct tm tmOrg;
  1277. struct tm *tmTarget;
  1278. struct timeb tbTarget;
  1279. char buf[128];
  1280. memset(&result, 0x00, sizeof(struct ParsingResult));
  1281. result.result = PASS;
  1282. if(strstr((char*)data, ".") != NULL)
  1283. {
  1284. // Original data with mini second
  1285. if(strstr((char*)data, "Z") != NULL)
  1286. {
  1287. // Original data with Z
  1288. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1289. &result.year,
  1290. &result.month,
  1291. &result.mday,
  1292. &result.hour,
  1293. &result.min,
  1294. &result.sec,
  1295. &result.minSec);
  1296. }
  1297. else
  1298. {
  1299. // Original data without Z
  1300. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1301. &result.year,
  1302. &result.month,
  1303. &result.mday,
  1304. &result.hour,
  1305. &result.min,
  1306. &result.sec,
  1307. &result.minSec,
  1308. &result.tz_hour,
  1309. &result.tz_min);
  1310. }
  1311. }
  1312. else
  1313. {
  1314. // Original data without mini second
  1315. if(strstr((char*)data, "Z") != NULL)
  1316. {
  1317. // Original data with Z
  1318. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1319. &result.year,
  1320. &result.month,
  1321. &result.mday,
  1322. &result.hour,
  1323. &result.min,
  1324. &result.sec);
  1325. }
  1326. else
  1327. {
  1328. // Original data without Z
  1329. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1330. &result.year,
  1331. &result.month,
  1332. &result.mday,
  1333. &result.hour,
  1334. &result.min,
  1335. &result.sec,
  1336. &result.tz_hour,
  1337. &result.tz_min);
  1338. }
  1339. }
  1340. tmOrg.tm_year = result.year - 1900;
  1341. tmOrg.tm_mon = result.month - 1;
  1342. tmOrg.tm_mday = result.mday;
  1343. tmOrg.tm_hour = result.hour;
  1344. tmOrg.tm_min = result.min;
  1345. tmOrg.tm_sec = result.sec;
  1346. tmOrg.tm_gmtoff = 0;
  1347. tbTarget.time = mktime(&tmOrg);
  1348. tbTarget.timezone = 0;
  1349. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1350. tmTarget = gmtime(&tbTarget.time);
  1351. 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);
  1352. //DEBUG_INFO(" org date time: %s\n", data);
  1353. //DEBUG_INFO("parse date time: %s\n", buf);
  1354. system(buf);
  1355. system("/sbin/hwclock -w --systohc");
  1356. if(result.scanedElement < 6)
  1357. result.result = FAIL;
  1358. return result.result;
  1359. }
  1360. //==========================================
  1361. // GetCompositeSchedule logic related function
  1362. //==========================================
  1363. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1364. {
  1365. //return milli-second
  1366. unsigned int StartTime,StopTime;
  1367. StartTime=(unsigned int)ST.time;
  1368. StopTime=(unsigned int)ET.time;
  1369. return (StopTime-StartTime);
  1370. }
  1371. int DiffTimebWithNowSec(struct timeb ST)
  1372. {
  1373. //return milli-second
  1374. struct timeb ET;
  1375. unsigned int StartTime,StopTime;
  1376. ftime(&ET);
  1377. StartTime=(unsigned int)ST.time;
  1378. StopTime=(unsigned int)ET.time;
  1379. return (StopTime-StartTime);
  1380. }
  1381. int getStartStop(uint8_t *start, uint8_t *stop)
  1382. {
  1383. struct ParsingResult
  1384. {
  1385. int result;
  1386. int scanedElement;
  1387. int year;
  1388. int month;
  1389. int mday;
  1390. int hour;
  1391. int min;
  1392. int sec;
  1393. int tz_hour;
  1394. int tz_min;
  1395. float minSec;
  1396. };
  1397. struct ParsingResult parseStart;
  1398. struct ParsingResult parseStop;
  1399. int result = -1;
  1400. struct tm tmStart;
  1401. struct timeb tbStart;
  1402. struct tm tmStop;
  1403. struct timeb tbStop;
  1404. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1405. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1406. // Scan start & stop date time
  1407. if(strstr((char*)start, ".") != NULL)
  1408. {
  1409. // Original data with mini second
  1410. if(strstr((char*)start, "Z") != NULL)
  1411. {
  1412. // Original data with Z
  1413. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1414. &parseStart.year,
  1415. &parseStart.month,
  1416. &parseStart.mday,
  1417. &parseStart.hour,
  1418. &parseStart.min,
  1419. &parseStart.sec,
  1420. &parseStart.minSec);
  1421. }
  1422. else
  1423. {
  1424. // Original data without Z
  1425. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1426. &parseStart.year,
  1427. &parseStart.month,
  1428. &parseStart.mday,
  1429. &parseStart.hour,
  1430. &parseStart.min,
  1431. &parseStart.sec,
  1432. &parseStart.minSec,
  1433. &parseStart.tz_hour,
  1434. &parseStart.tz_min);
  1435. }
  1436. }
  1437. else
  1438. {
  1439. // Original data without mini second
  1440. if(strstr((char*)start, "Z") != NULL)
  1441. {
  1442. // Original data with Z
  1443. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1444. &parseStart.year,
  1445. &parseStart.month,
  1446. &parseStart.mday,
  1447. &parseStart.hour,
  1448. &parseStart.min,
  1449. &parseStart.sec);
  1450. }
  1451. else
  1452. {
  1453. // Original data without Z
  1454. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1455. &parseStart.year,
  1456. &parseStart.month,
  1457. &parseStart.mday,
  1458. &parseStart.hour,
  1459. &parseStart.min,
  1460. &parseStart.sec,
  1461. &parseStart.tz_hour,
  1462. &parseStart.tz_min);
  1463. }
  1464. }
  1465. if(strstr((char*)stop, ".") != NULL)
  1466. {
  1467. // Original data with mini second
  1468. if(strstr((char*)stop, "Z") != NULL)
  1469. {
  1470. // Original data with Z
  1471. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1472. &parseStop.year,
  1473. &parseStop.month,
  1474. &parseStop.mday,
  1475. &parseStop.hour,
  1476. &parseStop.min,
  1477. &parseStop.sec,
  1478. &parseStop.minSec);
  1479. }
  1480. else
  1481. {
  1482. // Original data without Z
  1483. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1484. &parseStop.year,
  1485. &parseStop.month,
  1486. &parseStop.mday,
  1487. &parseStop.hour,
  1488. &parseStop.min,
  1489. &parseStop.sec,
  1490. &parseStop.minSec,
  1491. &parseStop.tz_hour,
  1492. &parseStop.tz_min);
  1493. }
  1494. }
  1495. else
  1496. {
  1497. // Original data without mini second
  1498. if(strstr((char*)stop, "Z") != NULL)
  1499. {
  1500. // Original data with Z
  1501. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1502. &parseStop.year,
  1503. &parseStop.month,
  1504. &parseStop.mday,
  1505. &parseStop.hour,
  1506. &parseStop.min,
  1507. &parseStop.sec);
  1508. }
  1509. else
  1510. {
  1511. // Original data without Z
  1512. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1513. &parseStop.year,
  1514. &parseStop.month,
  1515. &parseStop.mday,
  1516. &parseStop.hour,
  1517. &parseStop.min,
  1518. &parseStop.sec,
  1519. &parseStop.tz_hour,
  1520. &parseStop.tz_min);
  1521. }
  1522. }
  1523. // Calculate date time difference
  1524. if((parseStart.scanedElement >=6) &&
  1525. (parseStop.scanedElement >=6))
  1526. {
  1527. //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);
  1528. //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);
  1529. tmStart.tm_year = parseStart.year - 1900;
  1530. tmStart.tm_mon = parseStart.month - 1;
  1531. tmStart.tm_mday = parseStart.mday;
  1532. tmStart.tm_hour = parseStart.hour;
  1533. tmStart.tm_min = parseStart.min;
  1534. tmStart.tm_sec = parseStart.sec;
  1535. tmStart.tm_gmtoff = 0;
  1536. tbStart.time = mktime(&tmStart);
  1537. tbStart.timezone = 0;
  1538. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1539. tmStop.tm_year = parseStop.year - 1900;
  1540. tmStop.tm_mon = parseStop.month - 1;
  1541. tmStop.tm_mday = parseStop.mday;
  1542. tmStop.tm_hour = parseStop.hour;
  1543. tmStop.tm_min = parseStop.min;
  1544. tmStop.tm_sec = parseStop.sec;
  1545. tmStop.tm_gmtoff = 0;
  1546. tbStop.time = mktime(&tmStop);
  1547. tbStop.timezone = 0;
  1548. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1549. result = DiffTimebSec(tbStart, tbStop);
  1550. //DEBUG_INFO("getStartStop(): %d\n", result);
  1551. }
  1552. else
  1553. {
  1554. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1555. }
  1556. return result;
  1557. }
  1558. int isOvertNow(uint8_t *start)
  1559. {
  1560. int result = NO;
  1561. struct ParsingResult
  1562. {
  1563. int result;
  1564. int scanedElement;
  1565. int year;
  1566. int month;
  1567. int mday;
  1568. int hour;
  1569. int min;
  1570. int sec;
  1571. int tz_hour;
  1572. int tz_min;
  1573. float minSec;
  1574. }parsingResult;
  1575. struct tm tmStart;
  1576. struct timeb tbStart;
  1577. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1578. if(strstr((char*)start, ".") != NULL)
  1579. {
  1580. // Original data with mini second
  1581. if(strstr((char*)start, "Z") != NULL)
  1582. {
  1583. // Original data with Z
  1584. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1585. &parsingResult.year,
  1586. &parsingResult.month,
  1587. &parsingResult.mday,
  1588. &parsingResult.hour,
  1589. &parsingResult.min,
  1590. &parsingResult.sec,
  1591. &parsingResult.minSec);
  1592. }
  1593. else
  1594. {
  1595. // Original data without Z
  1596. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1597. &parsingResult.year,
  1598. &parsingResult.month,
  1599. &parsingResult.mday,
  1600. &parsingResult.hour,
  1601. &parsingResult.min,
  1602. &parsingResult.sec,
  1603. &parsingResult.minSec,
  1604. &parsingResult.tz_hour,
  1605. &parsingResult.tz_min);
  1606. }
  1607. }
  1608. else
  1609. {
  1610. // Original data without mini second
  1611. if(strstr((char*)start, "Z") != NULL)
  1612. {
  1613. // Original data with Z
  1614. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1615. &parsingResult.year,
  1616. &parsingResult.month,
  1617. &parsingResult.mday,
  1618. &parsingResult.hour,
  1619. &parsingResult.min,
  1620. &parsingResult.sec);
  1621. }
  1622. else
  1623. {
  1624. // Original data without Z
  1625. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1626. &parsingResult.year,
  1627. &parsingResult.month,
  1628. &parsingResult.mday,
  1629. &parsingResult.hour,
  1630. &parsingResult.min,
  1631. &parsingResult.sec,
  1632. &parsingResult.tz_hour,
  1633. &parsingResult.tz_min);
  1634. }
  1635. }
  1636. if(parsingResult.scanedElement >= 6)
  1637. {
  1638. tmStart.tm_year = parsingResult.year - 1900;
  1639. tmStart.tm_mon = parsingResult.month - 1;
  1640. tmStart.tm_mday = parsingResult.mday;
  1641. tmStart.tm_hour = parsingResult.hour;
  1642. tmStart.tm_min = parsingResult.min;
  1643. tmStart.tm_sec = parsingResult.sec;
  1644. tmStart.tm_gmtoff = 0;
  1645. tbStart.time = mktime(&tmStart);
  1646. tbStart.timezone = 0;
  1647. tbStart.millitm = 0;
  1648. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1649. if(DiffTimebWithNowSec(tbStart) <= 0)
  1650. result = NO;
  1651. else
  1652. result = YES;
  1653. }
  1654. else
  1655. {
  1656. DEBUG_WARN("Start date parsing error.\n");
  1657. }
  1658. return result;
  1659. }
  1660. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1661. {
  1662. struct ParsingResult
  1663. {
  1664. int result;
  1665. int scanedElement;
  1666. int year;
  1667. int month;
  1668. int mday;
  1669. int hour;
  1670. int min;
  1671. int sec;
  1672. int tz_hour;
  1673. int tz_min;
  1674. float minSec;
  1675. };
  1676. struct ParsingResult parseStart;
  1677. struct ParsingResult parseStop;
  1678. int result = -1;
  1679. struct tm tmStart;
  1680. struct timeb tbStart;
  1681. struct tm tmStop;
  1682. struct timeb tbStop;
  1683. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1684. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1685. // Scan start & stop date time
  1686. if(strstr((char*)start, ".") != NULL)
  1687. {
  1688. // Original data with mini second
  1689. if(strstr((char*)start, "Z") != NULL)
  1690. {
  1691. // Original data with Z
  1692. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1693. &parseStart.year,
  1694. &parseStart.month,
  1695. &parseStart.mday,
  1696. &parseStart.hour,
  1697. &parseStart.min,
  1698. &parseStart.sec,
  1699. &parseStart.minSec);
  1700. }
  1701. else
  1702. {
  1703. // Original data without Z
  1704. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1705. &parseStart.year,
  1706. &parseStart.month,
  1707. &parseStart.mday,
  1708. &parseStart.hour,
  1709. &parseStart.min,
  1710. &parseStart.sec,
  1711. &parseStart.minSec,
  1712. &parseStart.tz_hour,
  1713. &parseStart.tz_min);
  1714. }
  1715. }
  1716. else
  1717. {
  1718. // Original data without mini second
  1719. if(strstr((char*)start, "Z") != NULL)
  1720. {
  1721. // Original data with Z
  1722. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1723. &parseStart.year,
  1724. &parseStart.month,
  1725. &parseStart.mday,
  1726. &parseStart.hour,
  1727. &parseStart.min,
  1728. &parseStart.sec);
  1729. }
  1730. else
  1731. {
  1732. // Original data without Z
  1733. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1734. &parseStart.year,
  1735. &parseStart.month,
  1736. &parseStart.mday,
  1737. &parseStart.hour,
  1738. &parseStart.min,
  1739. &parseStart.sec,
  1740. &parseStart.tz_hour,
  1741. &parseStart.tz_min);
  1742. }
  1743. }
  1744. if(strstr((char*)stop, ".") != NULL)
  1745. {
  1746. // Original data with mini second
  1747. if(strstr((char*)stop, "Z") != NULL)
  1748. {
  1749. // Original data with Z
  1750. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1751. &parseStop.year,
  1752. &parseStop.month,
  1753. &parseStop.mday,
  1754. &parseStop.hour,
  1755. &parseStop.min,
  1756. &parseStop.sec,
  1757. &parseStop.minSec);
  1758. }
  1759. else
  1760. {
  1761. // Original data without Z
  1762. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1763. &parseStop.year,
  1764. &parseStop.month,
  1765. &parseStop.mday,
  1766. &parseStop.hour,
  1767. &parseStop.min,
  1768. &parseStop.sec,
  1769. &parseStop.minSec,
  1770. &parseStop.tz_hour,
  1771. &parseStop.tz_min);
  1772. }
  1773. }
  1774. else
  1775. {
  1776. // Original data without mini second
  1777. if(strstr((char*)stop, "Z") != NULL)
  1778. {
  1779. // Original data with Z
  1780. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1781. &parseStop.year,
  1782. &parseStop.month,
  1783. &parseStop.mday,
  1784. &parseStop.hour,
  1785. &parseStop.min,
  1786. &parseStop.sec);
  1787. }
  1788. else
  1789. {
  1790. // Original data without Z
  1791. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1792. &parseStop.year,
  1793. &parseStop.month,
  1794. &parseStop.mday,
  1795. &parseStop.hour,
  1796. &parseStop.min,
  1797. &parseStop.sec,
  1798. &parseStop.tz_hour,
  1799. &parseStop.tz_min);
  1800. }
  1801. }
  1802. // Calculate date time difference
  1803. if((parseStart.scanedElement >=6) &&
  1804. (parseStop.scanedElement >=6))
  1805. {
  1806. //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);
  1807. //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);
  1808. tmStart.tm_year = parseStart.year - 1900;
  1809. tmStart.tm_mon = parseStart.month - 1;
  1810. tmStart.tm_mday = parseStart.mday;
  1811. tmStart.tm_hour = parseStart.hour;
  1812. tmStart.tm_min = parseStart.min;
  1813. tmStart.tm_sec = parseStart.sec;
  1814. tmStart.tm_gmtoff = 0;
  1815. tbStart.time = mktime(&tmStart);
  1816. tbStart.timezone = 0;
  1817. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1818. tmStop.tm_year = parseStop.year - 1900;
  1819. tmStop.tm_mon = parseStop.month - 1;
  1820. tmStop.tm_mday = parseStop.mday;
  1821. tmStop.tm_hour = parseStop.hour;
  1822. tmStop.tm_min = parseStop.min;
  1823. tmStop.tm_sec = parseStop.sec;
  1824. tmStop.tm_gmtoff = 0;
  1825. tbStop.time = mktime(&tmStop);
  1826. tbStop.timezone = 0;
  1827. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1828. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1829. //DEBUG_INFO("getStartStop(): %d\n", result);
  1830. }
  1831. else
  1832. {
  1833. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1834. }
  1835. return result;
  1836. }
  1837. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1838. {
  1839. FILE *fp;
  1840. char profileFileName[128];
  1841. char *line = NULL;
  1842. size_t len = 0;
  1843. time_t CurrentTime;
  1844. struct tm *tmComposite;
  1845. struct StructChargingProfile maxProfile;
  1846. struct StructChargingProfile compositeProfile;
  1847. uint8_t limitMax=0;
  1848. int compositePeriodIdx = 0;
  1849. //uint8_t isDurationNull = FALSE;
  1850. CurrentTime = time(NULL);
  1851. tmComposite=localtime(&CurrentTime);
  1852. 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);
  1853. if(isUnitA)
  1854. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1855. else
  1856. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1857. compositeProfile.ChargingSchedule.Duration = durationReq;
  1858. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1859. {
  1860. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1861. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1862. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1863. }
  1864. compositeProfile.ChargingProfileId = 0;
  1865. compositeProfile.StackLevel = 99 ;
  1866. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1867. maxProfile.ChargingProfileId = -1;
  1868. maxProfile.ChargingSchedule.Duration = -1;
  1869. system("rm -f /tmp/*.json");
  1870. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1871. // Search max profile
  1872. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1873. if((access(profileFileName, F_OK))!=-1)
  1874. {
  1875. fp = fopen(profileFileName, "r");
  1876. while(getline(&line, &len, fp) != -1)
  1877. {
  1878. json_object *obj = NULL;
  1879. obj = json_tokener_parse(line);
  1880. if(is_error(obj))
  1881. {
  1882. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1883. }
  1884. else
  1885. {
  1886. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1887. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1888. )
  1889. {
  1890. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1891. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1892. )
  1893. {
  1894. struct tm tmFrom, tmTo;
  1895. struct timeb tbFrom, tbTo;
  1896. 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) &&
  1897. (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))
  1898. {
  1899. tmFrom.tm_year -= 1900;
  1900. tmFrom.tm_mon -= 1;
  1901. tbFrom.time = mktime(&tmFrom);
  1902. tmTo.tm_year -= 1900;
  1903. tmTo.tm_mon -= 1;
  1904. tbTo.time = mktime(&tmTo);
  1905. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1906. {
  1907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1908. {
  1909. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1910. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1912. }
  1913. if(maxProfile.ChargingProfileId == -1)
  1914. DEBUG_INFO("MaxProfile found.\n");
  1915. else
  1916. DEBUG_INFO("MaxProfile updated.\n");
  1917. // Required item
  1918. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1919. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1920. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1921. if(isUnitA)
  1922. {
  1923. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1924. 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++)
  1925. {
  1926. 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"));
  1927. 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?
  1928. 3:
  1929. 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")));
  1930. 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")));
  1931. }
  1932. }
  1933. else
  1934. {
  1935. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1936. 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++)
  1937. {
  1938. 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"));
  1939. 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?
  1940. 3:
  1941. 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")));
  1942. 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));
  1943. }
  1944. }
  1945. // Optional item
  1946. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1947. {
  1948. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1949. }
  1950. else
  1951. {
  1952. sprintf((char*)maxProfile.ValidFrom, " ");
  1953. }
  1954. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1955. {
  1956. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1957. }
  1958. else
  1959. {
  1960. sprintf((char*)maxProfile.ValidTo, " ");
  1961. }
  1962. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1963. {
  1964. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1965. }
  1966. else
  1967. {
  1968. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1969. }
  1970. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1971. {
  1972. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1973. }
  1974. else
  1975. {
  1976. maxProfile.TransactionId = -1;
  1977. }
  1978. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1979. {
  1980. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1981. }
  1982. else
  1983. {
  1984. maxProfile.ChargingSchedule.Duration = 86400;
  1985. //isDurationNull = TRUE;
  1986. }
  1987. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1988. {
  1989. 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")));
  1990. }
  1991. else
  1992. {
  1993. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1994. }
  1995. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1996. {
  1997. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1998. }
  1999. else
  2000. {
  2001. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2002. }
  2003. }
  2004. }
  2005. }
  2006. else
  2007. {
  2008. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2009. {
  2010. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2011. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2013. }
  2014. if(maxProfile.ChargingProfileId == -1)
  2015. DEBUG_INFO("MaxProfile found.\n");
  2016. else
  2017. DEBUG_INFO("MaxProfile updated.\n");
  2018. // Required item
  2019. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2020. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2021. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2022. if(isUnitA)
  2023. {
  2024. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2025. 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++)
  2026. {
  2027. 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"));
  2028. 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?
  2029. 3:
  2030. 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")));
  2031. 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")));
  2032. }
  2033. }
  2034. else
  2035. {
  2036. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2037. 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++)
  2038. {
  2039. 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"));
  2040. 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?
  2041. 3:
  2042. 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")));
  2043. 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));
  2044. }
  2045. }
  2046. // Optional item
  2047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2048. {
  2049. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2050. }
  2051. else
  2052. {
  2053. sprintf((char*)maxProfile.ValidFrom, " ");
  2054. }
  2055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2056. {
  2057. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2058. }
  2059. else
  2060. {
  2061. sprintf((char*)maxProfile.ValidTo, " ");
  2062. }
  2063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2064. {
  2065. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2066. }
  2067. else
  2068. {
  2069. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2070. }
  2071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2072. {
  2073. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2074. }
  2075. else
  2076. {
  2077. maxProfile.TransactionId = -1;
  2078. }
  2079. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2080. {
  2081. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2082. }
  2083. else
  2084. {
  2085. maxProfile.ChargingSchedule.Duration = 86400;
  2086. //isDurationNull = TRUE;
  2087. }
  2088. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2089. {
  2090. 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")));
  2091. }
  2092. else
  2093. {
  2094. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2095. }
  2096. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2097. {
  2098. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2099. }
  2100. else
  2101. {
  2102. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2103. }
  2104. }
  2105. }
  2106. }
  2107. json_object_put(obj);
  2108. }
  2109. fclose(fp);
  2110. /*
  2111. if(maxProfile.ChargingProfileId !=-1)
  2112. {
  2113. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2114. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2115. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2116. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2117. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2118. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2119. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2120. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2121. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2122. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2123. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2124. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2125. {
  2126. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2127. {
  2128. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2129. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2130. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2131. }
  2132. }
  2133. }
  2134. else
  2135. DEBUG_INFO("MaxProfile not found.\n");
  2136. DEBUG_INFO("------------------------------------\n");*/
  2137. }
  2138. if(maxProfile.ChargingProfileId != -1)
  2139. {
  2140. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2141. {
  2142. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2143. {
  2144. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2145. 0:
  2146. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2147. }
  2148. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2149. {
  2150. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2151. {
  2152. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2153. 0:
  2154. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2155. if(idxPeriod > 0)
  2156. {
  2157. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2158. {
  2159. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2160. }
  2161. }
  2162. }
  2163. }
  2164. }
  2165. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2166. {
  2167. if(maxProfile.ChargingSchedule.Duration != -1)
  2168. {
  2169. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2170. }
  2171. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2172. {
  2173. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2174. {
  2175. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2176. if(idxPeriod > 0)
  2177. {
  2178. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2179. {
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. else
  2187. {
  2188. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2189. {
  2190. if(maxProfile.ChargingSchedule.Duration != -1)
  2191. {
  2192. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2193. 0:
  2194. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2195. }
  2196. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2197. {
  2198. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2199. {
  2200. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2201. 0:
  2202. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2203. if(idxPeriod > 0)
  2204. {
  2205. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2206. {
  2207. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2208. }
  2209. }
  2210. }
  2211. }
  2212. }
  2213. else
  2214. {
  2215. if(maxProfile.ChargingSchedule.Duration != -1)
  2216. {
  2217. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2218. 0:
  2219. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2220. }
  2221. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2222. {
  2223. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2224. {
  2225. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2226. 0:
  2227. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2228. if(idxPeriod > 0)
  2229. {
  2230. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2231. {
  2232. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2233. }
  2234. }
  2235. }
  2236. }
  2237. }
  2238. }
  2239. /*
  2240. DEBUG_INFO("MaxProfile after align.\n");
  2241. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2242. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2243. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2244. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2245. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2246. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2247. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2248. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2249. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2250. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2251. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2252. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2253. {
  2254. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2255. {
  2256. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2257. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2258. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2259. }
  2260. }
  2261. DEBUG_INFO("------------------------------------\n");*/
  2262. }
  2263. // Find each profile period quantity
  2264. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2265. {
  2266. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2267. limitMax = idx+1;
  2268. }
  2269. if(maxProfile.ChargingProfileId != -1)
  2270. {
  2271. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2272. {
  2273. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2274. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2275. (maxProfile.ChargingSchedule.Duration > 0))
  2276. {
  2277. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2278. {
  2279. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2280. compositePeriodIdx++;
  2281. }
  2282. else
  2283. {
  2284. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2285. }
  2286. }
  2287. }
  2288. }
  2289. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2290. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2291. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2292. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2293. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2294. {
  2295. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2296. {
  2297. compositeProfile.ChargingProfileId = 1;
  2298. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2299. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2300. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2301. }
  2302. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2303. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2304. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2305. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2306. }
  2307. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2308. if(line)
  2309. free(line);
  2310. }
  2311. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2312. {
  2313. FILE *fp;
  2314. char profileFileName[128];
  2315. char *line = NULL;
  2316. size_t len = 0;
  2317. time_t CurrentTime;
  2318. struct tm *tmComposite;
  2319. struct StructChargingProfile maxProfile;
  2320. struct StructChargingProfile defaultTxProfile;
  2321. struct StructChargingProfile txProfile;
  2322. struct StructChargingProfile compositeProfile;
  2323. struct StructChargingSchedulePeriod tmpPeriod;
  2324. uint8_t limitMax=0;
  2325. uint8_t limitDef=0;
  2326. uint8_t limitTx=0;
  2327. int compositePeriodIdx = 0;
  2328. CurrentTime = time(NULL);
  2329. tmComposite=localtime(&CurrentTime);
  2330. 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);
  2331. if(isUnitA)
  2332. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2333. else
  2334. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2335. compositeProfile.ChargingSchedule.Duration = durationReq;
  2336. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2337. {
  2338. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2339. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2340. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2341. }
  2342. compositeProfile.ChargingProfileId = 0;
  2343. compositeProfile.StackLevel = 99 ;
  2344. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2345. maxProfile.ChargingProfileId = -1;
  2346. defaultTxProfile.ChargingProfileId = -1;
  2347. txProfile.ChargingProfileId = -1;
  2348. maxProfile.ChargingSchedule.Duration = -1;
  2349. defaultTxProfile.ChargingSchedule.Duration = -1;
  2350. txProfile.ChargingSchedule.Duration = -1;
  2351. system("rm -f /tmp/*.json");
  2352. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2353. /*
  2354. * Search valid charging profile
  2355. */
  2356. //DEBUG_INFO("====================================\n");
  2357. // Search tx profile
  2358. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2359. if((access(profileFileName, F_OK))!=-1)
  2360. {
  2361. fp = fopen(profileFileName, "r");
  2362. while(getline(&line, &len, fp) != -1)
  2363. {
  2364. json_object *obj = NULL;
  2365. obj = json_tokener_parse(line);
  2366. if(is_error(obj))
  2367. {
  2368. DEBUG_ERROR("Parse txProfile from file error.\n");
  2369. }
  2370. else
  2371. {
  2372. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2373. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2374. )
  2375. {
  2376. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2377. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2378. )
  2379. {
  2380. struct tm tmFrom, tmTo;
  2381. struct timeb tbFrom, tbTo;
  2382. 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) &&
  2383. (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))
  2384. {
  2385. tmFrom.tm_year -= 1900;
  2386. tmFrom.tm_mon -= 1;
  2387. tbFrom.time = mktime(&tmFrom);
  2388. tmTo.tm_year -= 1900;
  2389. tmTo.tm_mon -= 1;
  2390. tbTo.time = mktime(&tmTo);
  2391. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2392. {
  2393. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2394. {
  2395. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2396. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2397. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2398. }
  2399. if(txProfile.ChargingProfileId == -1)
  2400. DEBUG_INFO("TxProfile found.\n");
  2401. else
  2402. DEBUG_INFO("TxProfile updated.\n");
  2403. // Required item
  2404. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2405. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2406. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2407. if(isUnitA)
  2408. {
  2409. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2410. 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++)
  2411. {
  2412. 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"));
  2413. 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?
  2414. 3:
  2415. 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")));
  2416. 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")));
  2417. }
  2418. }
  2419. else
  2420. {
  2421. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2422. 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++)
  2423. {
  2424. 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"));
  2425. 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?
  2426. 3:
  2427. 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")));
  2428. 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));
  2429. }
  2430. }
  2431. // Optional item
  2432. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2433. {
  2434. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2435. }
  2436. else
  2437. {
  2438. sprintf((char*)txProfile.ValidFrom, " ");
  2439. }
  2440. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2441. {
  2442. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2443. }
  2444. else
  2445. {
  2446. sprintf((char*)txProfile.ValidTo, " ");
  2447. }
  2448. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2449. {
  2450. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2451. }
  2452. else
  2453. {
  2454. sprintf((char*)txProfile.RecurrencyKind, " ");
  2455. }
  2456. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2457. {
  2458. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2459. }
  2460. else
  2461. {
  2462. txProfile.TransactionId = -1;
  2463. }
  2464. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2465. {
  2466. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2467. }
  2468. else
  2469. {
  2470. txProfile.ChargingSchedule.Duration = 86400;
  2471. }
  2472. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2473. {
  2474. 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")));
  2475. }
  2476. else
  2477. {
  2478. 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));
  2479. }
  2480. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2481. {
  2482. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2483. }
  2484. else
  2485. {
  2486. txProfile.ChargingSchedule.MinChargingRate = -1;
  2487. }
  2488. }
  2489. }
  2490. }
  2491. else
  2492. {
  2493. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2494. {
  2495. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2496. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2497. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2498. }
  2499. if(txProfile.ChargingProfileId == -1)
  2500. DEBUG_INFO("TxProfile found.\n");
  2501. else
  2502. DEBUG_INFO("TxProfile updated.\n");
  2503. // Required item
  2504. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2505. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2506. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2507. if(isUnitA)
  2508. {
  2509. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2510. 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++)
  2511. {
  2512. 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"));
  2513. 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?
  2514. 3:
  2515. 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")));
  2516. 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")));
  2517. }
  2518. }
  2519. else
  2520. {
  2521. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2522. 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++)
  2523. {
  2524. 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"));
  2525. 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?
  2526. 3:
  2527. 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")));
  2528. 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));
  2529. }
  2530. }
  2531. // Optional item
  2532. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2533. {
  2534. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2535. }
  2536. else
  2537. {
  2538. sprintf((char*)txProfile.ValidFrom, " ");
  2539. }
  2540. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2541. {
  2542. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2543. }
  2544. else
  2545. {
  2546. sprintf((char*)txProfile.ValidTo, " ");
  2547. }
  2548. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2549. {
  2550. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2551. }
  2552. else
  2553. {
  2554. sprintf((char*)txProfile.RecurrencyKind, " ");
  2555. }
  2556. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2557. {
  2558. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2559. }
  2560. else
  2561. {
  2562. txProfile.TransactionId = -1;
  2563. }
  2564. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2565. {
  2566. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2567. }
  2568. else
  2569. {
  2570. txProfile.ChargingSchedule.Duration = 86400;
  2571. }
  2572. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2573. {
  2574. 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")));
  2575. }
  2576. else
  2577. {
  2578. 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));
  2579. }
  2580. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2581. {
  2582. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2583. }
  2584. else
  2585. {
  2586. txProfile.ChargingSchedule.MinChargingRate = -1;
  2587. }
  2588. }
  2589. }
  2590. }
  2591. json_object_put(obj);
  2592. }
  2593. fclose(fp);
  2594. /*
  2595. if(txProfile.ChargingProfileId != -1)
  2596. {
  2597. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2598. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2599. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2600. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2601. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2602. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2603. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2604. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2605. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2606. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2607. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2608. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2609. {
  2610. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2611. {
  2612. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2613. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2614. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2615. }
  2616. }
  2617. }
  2618. else
  2619. DEBUG_INFO("TxProfile not found.\n");*/
  2620. }
  2621. // Search default tx profile
  2622. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2623. if((access(profileFileName, F_OK))==-1)
  2624. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2625. if((access(profileFileName, F_OK))!=-1)
  2626. {
  2627. fp = fopen(profileFileName, "r");
  2628. while(getline(&line, &len, fp) != -1)
  2629. {
  2630. json_object *obj = NULL;
  2631. obj = json_tokener_parse(line);
  2632. if(is_error(obj))
  2633. {
  2634. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2635. }
  2636. else
  2637. {
  2638. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2639. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2640. )
  2641. {
  2642. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2643. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2644. )
  2645. {
  2646. struct tm tmFrom, tmTo;
  2647. struct timeb tbFrom, tbTo;
  2648. 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) &&
  2649. (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))
  2650. {
  2651. tmFrom.tm_year -= 1900;
  2652. tmFrom.tm_mon -= 1;
  2653. tbFrom.time = mktime(&tmFrom);
  2654. tmTo.tm_year -= 1900;
  2655. tmTo.tm_mon -= 1;
  2656. tbTo.time = mktime(&tmTo);
  2657. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2658. {
  2659. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2660. {
  2661. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2662. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2663. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2664. }
  2665. if(defaultTxProfile.ChargingProfileId == -1)
  2666. DEBUG_INFO("TxDefaultProfile found.\n");
  2667. else
  2668. DEBUG_INFO("TxDefaultProfile updated.\n");
  2669. // Required item
  2670. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2671. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2672. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2673. if(isUnitA)
  2674. {
  2675. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2676. 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++)
  2677. {
  2678. 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"));
  2679. 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?
  2680. 3:
  2681. 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")));
  2682. 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")));
  2683. }
  2684. }
  2685. else
  2686. {
  2687. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2688. 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++)
  2689. {
  2690. 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"));
  2691. 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?
  2692. 3:
  2693. 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")));
  2694. 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));
  2695. }
  2696. }
  2697. // Optional item
  2698. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2699. {
  2700. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2701. }
  2702. else
  2703. {
  2704. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2705. }
  2706. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2707. {
  2708. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2709. }
  2710. else
  2711. {
  2712. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2713. }
  2714. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2715. {
  2716. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2717. }
  2718. else
  2719. {
  2720. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2721. }
  2722. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2723. {
  2724. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2725. }
  2726. else
  2727. {
  2728. defaultTxProfile.TransactionId = -1;
  2729. }
  2730. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2731. {
  2732. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2733. }
  2734. else
  2735. {
  2736. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2737. }
  2738. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2739. {
  2740. 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")));
  2741. }
  2742. else
  2743. {
  2744. 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));
  2745. }
  2746. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2747. {
  2748. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2749. }
  2750. else
  2751. {
  2752. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2753. }
  2754. }
  2755. }
  2756. }
  2757. else
  2758. {
  2759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2760. {
  2761. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2762. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2763. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2764. }
  2765. if(defaultTxProfile.ChargingProfileId == -1)
  2766. DEBUG_INFO("TxDefaultProfile found.\n");
  2767. else
  2768. DEBUG_INFO("TxDefaultProfile updated.\n");
  2769. // Required item
  2770. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2771. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2772. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2773. if(isUnitA)
  2774. {
  2775. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2776. 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++)
  2777. {
  2778. 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"));
  2779. 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?
  2780. 3:
  2781. 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")));
  2782. 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")));
  2783. }
  2784. }
  2785. else
  2786. {
  2787. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2788. 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++)
  2789. {
  2790. 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"));
  2791. 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?
  2792. 3:
  2793. 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")));
  2794. 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));
  2795. }
  2796. }
  2797. // Optional item
  2798. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2799. {
  2800. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2801. }
  2802. else
  2803. {
  2804. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2805. }
  2806. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2807. {
  2808. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2809. }
  2810. else
  2811. {
  2812. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2813. }
  2814. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2815. {
  2816. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2817. }
  2818. else
  2819. {
  2820. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2821. }
  2822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2823. {
  2824. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2825. }
  2826. else
  2827. {
  2828. defaultTxProfile.TransactionId = -1;
  2829. }
  2830. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2831. {
  2832. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2833. }
  2834. else
  2835. {
  2836. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2837. }
  2838. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2839. {
  2840. 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")));
  2841. }
  2842. else
  2843. {
  2844. 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));
  2845. }
  2846. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2847. {
  2848. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2849. }
  2850. else
  2851. {
  2852. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2853. }
  2854. }
  2855. }
  2856. }
  2857. json_object_put(obj);
  2858. }
  2859. fclose(fp);
  2860. /*
  2861. if(defaultTxProfile.ChargingProfileId != -1)
  2862. {
  2863. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2864. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2865. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2866. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2867. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2868. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2869. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2870. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2871. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2872. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2873. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2875. {
  2876. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2877. {
  2878. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2879. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2880. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2881. }
  2882. }
  2883. }
  2884. else
  2885. DEBUG_INFO("TxDefaultProfile not found.\n");
  2886. DEBUG_INFO("------------------------------------\n");*/
  2887. }
  2888. // Search max profile
  2889. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2890. if((access(profileFileName, F_OK))!=-1)
  2891. {
  2892. fp = fopen(profileFileName, "r");
  2893. while(getline(&line, &len, fp) != -1)
  2894. {
  2895. json_object *obj = NULL;
  2896. obj = json_tokener_parse(line);
  2897. if(is_error(obj))
  2898. {
  2899. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2900. }
  2901. else
  2902. {
  2903. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2904. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2905. )
  2906. {
  2907. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2908. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2909. )
  2910. {
  2911. struct tm tmFrom, tmTo;
  2912. struct timeb tbFrom, tbTo;
  2913. 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) &&
  2914. (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))
  2915. {
  2916. tmFrom.tm_year -= 1900;
  2917. tmFrom.tm_mon -= 1;
  2918. tbFrom.time = mktime(&tmFrom);
  2919. tmTo.tm_year -= 1900;
  2920. tmTo.tm_mon -= 1;
  2921. tbTo.time = mktime(&tmTo);
  2922. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2923. {
  2924. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2925. {
  2926. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2927. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2928. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2929. }
  2930. if(maxProfile.ChargingProfileId == -1)
  2931. DEBUG_INFO("MaxProfile found.\n");
  2932. else
  2933. DEBUG_INFO("MaxProfile updated.\n");
  2934. // Required item
  2935. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2936. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2937. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2938. if(isUnitA)
  2939. {
  2940. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2941. 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++)
  2942. {
  2943. 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"));
  2944. 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?
  2945. 3:
  2946. 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")));
  2947. 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")));
  2948. }
  2949. }
  2950. else
  2951. {
  2952. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2953. 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++)
  2954. {
  2955. 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"));
  2956. 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?
  2957. 3:
  2958. 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")));
  2959. 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));
  2960. }
  2961. }
  2962. // Optional item
  2963. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2964. {
  2965. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2966. }
  2967. else
  2968. {
  2969. sprintf((char*)maxProfile.ValidFrom, " ");
  2970. }
  2971. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2972. {
  2973. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2974. }
  2975. else
  2976. {
  2977. sprintf((char*)maxProfile.ValidTo, " ");
  2978. }
  2979. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2980. {
  2981. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2982. }
  2983. else
  2984. {
  2985. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2986. }
  2987. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2988. {
  2989. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2990. }
  2991. else
  2992. {
  2993. maxProfile.TransactionId = -1;
  2994. }
  2995. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2996. {
  2997. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2998. }
  2999. else
  3000. {
  3001. maxProfile.ChargingSchedule.Duration = 86400;
  3002. }
  3003. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3004. {
  3005. 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")));
  3006. }
  3007. else
  3008. {
  3009. 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));
  3010. }
  3011. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3012. {
  3013. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3014. }
  3015. else
  3016. {
  3017. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3018. }
  3019. }
  3020. }
  3021. }
  3022. else
  3023. {
  3024. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3025. {
  3026. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3027. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3028. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3029. }
  3030. if(maxProfile.ChargingProfileId == -1)
  3031. DEBUG_INFO("MaxProfile found.\n");
  3032. else
  3033. DEBUG_INFO("MaxProfile updated.\n");
  3034. // Required item
  3035. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3036. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3037. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3038. if(isUnitA)
  3039. {
  3040. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3041. 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++)
  3042. {
  3043. 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"));
  3044. 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?
  3045. 3:
  3046. 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")));
  3047. 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")));
  3048. }
  3049. }
  3050. else
  3051. {
  3052. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3053. 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++)
  3054. {
  3055. 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"));
  3056. 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?
  3057. 3:
  3058. 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")));
  3059. 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));
  3060. }
  3061. }
  3062. // Optional item
  3063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3064. {
  3065. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3066. }
  3067. else
  3068. {
  3069. sprintf((char*)maxProfile.ValidFrom, " ");
  3070. }
  3071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3072. {
  3073. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3074. }
  3075. else
  3076. {
  3077. sprintf((char*)maxProfile.ValidTo, " ");
  3078. }
  3079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3080. {
  3081. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3082. }
  3083. else
  3084. {
  3085. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3086. }
  3087. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3088. {
  3089. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3090. }
  3091. else
  3092. {
  3093. maxProfile.TransactionId = -1;
  3094. }
  3095. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3096. {
  3097. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3098. }
  3099. else
  3100. {
  3101. maxProfile.ChargingSchedule.Duration = 86400;
  3102. }
  3103. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3104. {
  3105. 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")));
  3106. }
  3107. else
  3108. {
  3109. 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));
  3110. }
  3111. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3112. {
  3113. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3114. }
  3115. else
  3116. {
  3117. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3118. }
  3119. }
  3120. }
  3121. }
  3122. json_object_put(obj);
  3123. }
  3124. fclose(fp);
  3125. /*
  3126. if(maxProfile.ChargingProfileId !=-1)
  3127. {
  3128. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3129. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3130. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3131. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3132. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3133. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3134. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3135. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3136. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3137. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3138. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3140. {
  3141. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3142. {
  3143. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3144. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3145. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3146. }
  3147. }
  3148. }
  3149. else
  3150. DEBUG_INFO("MaxProfile not found.\n");
  3151. DEBUG_INFO("------------------------------------\n");*/
  3152. }
  3153. /*
  3154. * Align found profile start schedule & periods
  3155. */
  3156. //DEBUG_INFO("====================================\n");
  3157. /*
  3158. // For local test usage, force modify found profile start schedule info
  3159. 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);
  3160. 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);
  3161. 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);
  3162. */
  3163. if(txProfile.ChargingProfileId != -1)
  3164. {
  3165. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3166. {
  3167. if(txProfile.ChargingSchedule.Duration != -1)
  3168. {
  3169. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3170. 0:
  3171. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3172. }
  3173. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3174. {
  3175. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3176. {
  3177. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3178. 0:
  3179. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3180. if(idxPeriod > 0)
  3181. {
  3182. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3183. {
  3184. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3185. }
  3186. }
  3187. }
  3188. }
  3189. }
  3190. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3191. {
  3192. if(txProfile.ChargingSchedule.Duration != -1)
  3193. {
  3194. 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?
  3195. 0:
  3196. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3197. }
  3198. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3199. {
  3200. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3201. {
  3202. 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?
  3203. 0:
  3204. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3205. if(idxPeriod > 0)
  3206. {
  3207. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3208. {
  3209. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3210. }
  3211. }
  3212. }
  3213. }
  3214. }
  3215. else
  3216. {
  3217. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3218. {
  3219. if(txProfile.ChargingSchedule.Duration != -1)
  3220. {
  3221. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3222. 0:
  3223. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3224. }
  3225. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3226. {
  3227. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3228. {
  3229. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3230. 0:
  3231. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3232. if(idxPeriod > 0)
  3233. {
  3234. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3235. {
  3236. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3237. }
  3238. }
  3239. }
  3240. }
  3241. }
  3242. else
  3243. {
  3244. if(txProfile.ChargingSchedule.Duration != -1)
  3245. {
  3246. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3247. 0:
  3248. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3249. }
  3250. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3251. {
  3252. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3253. {
  3254. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3255. 0:
  3256. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3257. if(idxPeriod > 0)
  3258. {
  3259. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3260. {
  3261. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3262. }
  3263. }
  3264. }
  3265. }
  3266. }
  3267. }
  3268. /*
  3269. DEBUG_INFO("txProfile after align.\n");
  3270. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3271. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3272. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3273. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3274. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3275. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3276. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3277. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3278. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3279. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3280. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3282. {
  3283. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3284. {
  3285. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3286. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3287. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3288. }
  3289. }*/
  3290. }
  3291. if(defaultTxProfile.ChargingProfileId != -1)
  3292. {
  3293. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3294. {
  3295. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3296. {
  3297. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3298. 0:
  3299. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3300. }
  3301. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3302. {
  3303. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3304. {
  3305. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3306. 0:
  3307. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3308. if(idxPeriod > 0)
  3309. {
  3310. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3311. {
  3312. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3313. }
  3314. }
  3315. }
  3316. }
  3317. }
  3318. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3319. {
  3320. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3321. {
  3322. 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?
  3323. 0:
  3324. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3325. }
  3326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3327. {
  3328. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3329. {
  3330. 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?
  3331. 0:
  3332. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3333. if(idxPeriod > 0)
  3334. {
  3335. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3336. {
  3337. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3338. }
  3339. }
  3340. }
  3341. }
  3342. }
  3343. else
  3344. {
  3345. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3346. {
  3347. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3348. {
  3349. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3350. 0:
  3351. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3352. }
  3353. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3354. {
  3355. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3356. {
  3357. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3358. 0:
  3359. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3360. if(idxPeriod > 0)
  3361. {
  3362. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3363. {
  3364. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3365. }
  3366. }
  3367. }
  3368. }
  3369. }
  3370. else
  3371. {
  3372. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3373. {
  3374. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3375. 0:
  3376. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3377. }
  3378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3379. {
  3380. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3381. {
  3382. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3383. 0:
  3384. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3385. if(idxPeriod > 0)
  3386. {
  3387. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3388. {
  3389. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3390. }
  3391. }
  3392. }
  3393. }
  3394. }
  3395. }
  3396. /*
  3397. DEBUG_INFO("defaultTxProfile after align.\n");
  3398. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3399. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3400. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3401. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3402. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3403. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3404. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3405. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3406. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3407. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3408. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3409. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3410. {
  3411. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3412. {
  3413. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3414. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3415. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3416. }
  3417. }
  3418. DEBUG_INFO("------------------------------------\n");*/
  3419. }
  3420. if(maxProfile.ChargingProfileId != -1)
  3421. {
  3422. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3423. {
  3424. if(maxProfile.ChargingSchedule.Duration != -1)
  3425. {
  3426. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3427. 0:
  3428. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3429. }
  3430. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3431. {
  3432. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3433. {
  3434. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3435. 0:
  3436. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3437. if(idxPeriod > 0)
  3438. {
  3439. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3440. {
  3441. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3442. }
  3443. }
  3444. }
  3445. }
  3446. }
  3447. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3448. {
  3449. if(maxProfile.ChargingSchedule.Duration != -1)
  3450. {
  3451. 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?
  3452. 0:
  3453. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3454. }
  3455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3456. {
  3457. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3458. {
  3459. 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?
  3460. 0:
  3461. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3462. if(idxPeriod > 0)
  3463. {
  3464. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3465. {
  3466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3467. }
  3468. }
  3469. }
  3470. }
  3471. }
  3472. else
  3473. {
  3474. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3475. {
  3476. if(maxProfile.ChargingSchedule.Duration != -1)
  3477. {
  3478. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3479. 0:
  3480. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3481. }
  3482. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3483. {
  3484. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3485. {
  3486. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3487. 0:
  3488. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3489. if(idxPeriod > 0)
  3490. {
  3491. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3492. {
  3493. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3494. }
  3495. }
  3496. }
  3497. }
  3498. }
  3499. else
  3500. {
  3501. if(maxProfile.ChargingSchedule.Duration != -1)
  3502. {
  3503. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3504. 0:
  3505. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3506. }
  3507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3508. {
  3509. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3510. {
  3511. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3512. 0:
  3513. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3514. if(idxPeriod > 0)
  3515. {
  3516. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3517. {
  3518. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3519. }
  3520. }
  3521. }
  3522. }
  3523. }
  3524. }
  3525. /*
  3526. DEBUG_INFO("MaxProfile after align.\n");
  3527. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3528. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3529. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3530. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3531. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3532. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3533. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3534. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3535. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3536. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3537. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3538. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3539. {
  3540. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3541. {
  3542. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3543. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3544. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3545. }
  3546. }
  3547. DEBUG_INFO("------------------------------------\n");*/
  3548. }
  3549. /*
  3550. * Merge to conposite schedule
  3551. */
  3552. //DEBUG_INFO("====================================\n");
  3553. // Find each profile period quantity
  3554. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3555. {
  3556. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3557. limitMax = idx+1;
  3558. }
  3559. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3560. {
  3561. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3562. limitDef = idx+1;
  3563. }
  3564. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3565. {
  3566. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3567. limitTx = idx+1;
  3568. }
  3569. // TxProfile found, composite schedule based on it
  3570. if(txProfile.ChargingProfileId != -1)
  3571. {
  3572. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3573. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3574. {
  3575. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3576. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3577. (txProfile.ChargingSchedule.Duration > 0))
  3578. {
  3579. if(maxProfile.ChargingProfileId != -1)
  3580. {
  3581. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3582. {
  3583. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3584. {
  3585. if((maxProfile.ChargingSchedule.Duration > 0))
  3586. {
  3587. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3588. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3589. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3590. }
  3591. else
  3592. {
  3593. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3594. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3595. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3596. }
  3597. }
  3598. if(idxMaxPeriod == (limitMax-1))
  3599. {
  3600. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3601. {
  3602. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3603. {
  3604. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3605. compositePeriodIdx++;
  3606. }
  3607. else
  3608. {
  3609. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3610. }
  3611. }
  3612. }
  3613. }
  3614. }
  3615. else
  3616. {
  3617. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3618. {
  3619. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3620. compositePeriodIdx++;
  3621. }
  3622. else
  3623. {
  3624. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3625. }
  3626. }
  3627. }
  3628. if(idxTxPeriod == (limitTx-1))
  3629. {
  3630. if(defaultTxProfile.ChargingProfileId != -1)
  3631. {
  3632. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3633. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3634. {
  3635. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3636. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3637. (defaultTxProfile.ChargingSchedule.Duration>0))
  3638. {
  3639. if(maxProfile.ChargingProfileId != -1)
  3640. {
  3641. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3642. {
  3643. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3644. {
  3645. if((maxProfile.ChargingSchedule.Duration > 0))
  3646. {
  3647. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3648. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3649. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3650. }
  3651. else
  3652. {
  3653. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3654. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3655. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3656. }
  3657. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3658. {
  3659. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3660. {
  3661. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3662. compositePeriodIdx++;
  3663. }
  3664. else
  3665. {
  3666. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3667. }
  3668. }
  3669. // Delete duplicate period
  3670. if(compositePeriodIdx > 1)
  3671. {
  3672. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3673. {
  3674. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3675. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3676. compositePeriodIdx -= 1;
  3677. }
  3678. }
  3679. }
  3680. else
  3681. {
  3682. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3683. {
  3684. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3685. compositePeriodIdx++;
  3686. }
  3687. else
  3688. {
  3689. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3690. }
  3691. break;
  3692. }
  3693. }
  3694. }
  3695. else
  3696. {
  3697. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3698. {
  3699. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3700. compositePeriodIdx++;
  3701. }
  3702. else
  3703. {
  3704. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3705. }
  3706. }
  3707. }
  3708. }
  3709. }
  3710. }
  3711. }
  3712. }
  3713. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3714. else if(defaultTxProfile.ChargingProfileId != -1)
  3715. {
  3716. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3717. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3718. {
  3719. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3720. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3721. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3722. {
  3723. if(maxProfile.ChargingProfileId != -1)
  3724. {
  3725. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3726. {
  3727. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3728. {
  3729. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3730. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3731. if((maxProfile.ChargingSchedule.Duration > 0))
  3732. {
  3733. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3734. }
  3735. else
  3736. {
  3737. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3738. }
  3739. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3740. {
  3741. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3742. {
  3743. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3744. compositePeriodIdx++;
  3745. }
  3746. else
  3747. {
  3748. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3749. }
  3750. }
  3751. // Delete duplicate period
  3752. if(compositePeriodIdx > 1)
  3753. {
  3754. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3755. {
  3756. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3757. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3758. compositePeriodIdx -= 1;
  3759. }
  3760. }
  3761. }
  3762. else
  3763. {
  3764. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3765. {
  3766. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3767. compositePeriodIdx++;
  3768. }
  3769. else
  3770. {
  3771. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3772. }
  3773. break;
  3774. }
  3775. }
  3776. }
  3777. else
  3778. {
  3779. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3780. {
  3781. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3782. compositePeriodIdx++;
  3783. }
  3784. else
  3785. {
  3786. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3787. }
  3788. }
  3789. }
  3790. }
  3791. }
  3792. // Fill other period by MaxProfile
  3793. if(maxProfile.ChargingProfileId != -1)
  3794. {
  3795. if(compositePeriodIdx==0)
  3796. {
  3797. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3798. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3799. {
  3800. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3801. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3802. (maxProfile.ChargingSchedule.Duration > 0))
  3803. {
  3804. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3805. {
  3806. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3807. compositePeriodIdx++;
  3808. }
  3809. else
  3810. {
  3811. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3812. }
  3813. }
  3814. }
  3815. }
  3816. else
  3817. {
  3818. int lastCompositePeriodIdx = compositePeriodIdx;
  3819. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3820. {
  3821. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3822. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3823. (maxProfile.ChargingSchedule.Duration > 0))
  3824. {
  3825. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3826. {
  3827. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3828. {
  3829. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3830. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3831. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3832. }
  3833. else
  3834. {
  3835. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3836. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3837. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3838. }
  3839. }
  3840. if(tmpPeriod.Limit != -1)
  3841. {
  3842. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3843. {
  3844. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3845. {
  3846. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3847. compositePeriodIdx++;
  3848. }
  3849. else
  3850. {
  3851. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3852. }
  3853. }
  3854. // Delete duplicate period
  3855. if(compositePeriodIdx > 1)
  3856. {
  3857. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3858. {
  3859. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3860. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3861. compositePeriodIdx -= 1;
  3862. }
  3863. }
  3864. }
  3865. }
  3866. }
  3867. }
  3868. }
  3869. compositeProfile.ChargingSchedule.Duration = durationReq;
  3870. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3871. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3872. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3873. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3875. {
  3876. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3877. {
  3878. compositeProfile.ChargingProfileId = 1;
  3879. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3880. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3881. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3882. }
  3883. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3884. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3885. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3886. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3887. }
  3888. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3889. if(line)
  3890. free(line);
  3891. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3892. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3893. }
  3894. //==========================================
  3895. // Init all share memory
  3896. //==========================================
  3897. int InitShareMemory()
  3898. {
  3899. int result = PASS;
  3900. int MeterSMId;
  3901. //creat ShmSysConfigAndInfo
  3902. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3903. {
  3904. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3905. result = FAIL;
  3906. }
  3907. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3908. {
  3909. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3910. result = FAIL;
  3911. }
  3912. else
  3913. {}
  3914. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3915. {
  3916. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3917. result = FAIL;
  3918. }
  3919. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3920. {
  3921. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3922. result = FAIL;
  3923. }
  3924. else
  3925. {}
  3926. //creat ShmPsuData
  3927. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3928. {
  3929. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3930. result = FAIL;
  3931. }
  3932. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3933. {
  3934. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3935. result = FAIL;
  3936. }
  3937. else
  3938. {}
  3939. //creat ShmOCPP16Data
  3940. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3941. {
  3942. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3943. result = FAIL;
  3944. }
  3945. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3946. {
  3947. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3948. result = FAIL;
  3949. }
  3950. else
  3951. {}
  3952. /****************************** For Initial Settings************************************************/
  3953. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3954. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3955. // allocate Configuration memory address
  3956. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3957. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3958. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3959. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3960. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3961. //offline MeterValue Interval
  3962. TempMeterValueInterval = 0;
  3963. return result;
  3964. }
  3965. int ProcessShareMemory()
  3966. {
  3967. int result = PASS;
  3968. if(InitShareMemory() == FAIL)
  3969. {
  3970. DEBUG_ERROR("InitShareMemory NG\n");
  3971. if(ShmStatusCodeData!=NULL)
  3972. {
  3973. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3974. }
  3975. result = FAIL;
  3976. }
  3977. // Model name parsing
  3978. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3979. {
  3980. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3981. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3982. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3983. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3984. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3985. ) // 'D' means DC
  3986. {
  3987. // DO series
  3988. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3989. {
  3990. gunTotalNumber += 1;
  3991. gunType[gun_index] = GUN_TYPE_DO;
  3992. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3993. {
  3994. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3995. {
  3996. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3997. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3998. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3999. }
  4000. }
  4001. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4002. {
  4003. case Gun_Type_Chademo:
  4004. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4005. break;
  4006. case Gun_Type_CCS_2:
  4007. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4008. break;
  4009. case Gun_Type_GB:
  4010. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4011. break;
  4012. case Gun_Type_AC:
  4013. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4014. break;
  4015. default:
  4016. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4017. break;
  4018. }
  4019. }
  4020. }
  4021. else
  4022. {
  4023. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4024. {
  4025. gunTotalNumber += 1;
  4026. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4027. {
  4028. case Gun_Type_Chademo:
  4029. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4030. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4031. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4032. {
  4033. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4034. {
  4035. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4036. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4037. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4038. }
  4039. }
  4040. break;
  4041. case Gun_Type_CCS_2:
  4042. gunType[gun_index] = GUN_TYPE_CCS;
  4043. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4044. for (int index = 0; index < CCS_QUANTITY; index++)
  4045. {
  4046. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4047. {
  4048. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4049. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4050. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4051. }
  4052. }
  4053. break;
  4054. case Gun_Type_GB:
  4055. gunType[gun_index] = GUN_TYPE_GBT;
  4056. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4057. for (int index = 0; index < GB_QUANTITY; index++)
  4058. {
  4059. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4060. {
  4061. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4062. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4063. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4064. }
  4065. }
  4066. break;
  4067. case Gun_Type_AC:
  4068. gunType[gun_index] = GUN_TYPE_AC;
  4069. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4070. for (int index = 0; index < AC_QUANTITY; index++)
  4071. {
  4072. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4073. {
  4074. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4075. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4076. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4077. }
  4078. }
  4079. break;
  4080. default:
  4081. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4082. break;
  4083. }
  4084. }
  4085. }
  4086. }
  4087. else
  4088. {
  4089. DEBUG_ERROR("Model name parsing fail.\n");
  4090. result = FAIL;
  4091. }
  4092. if(result != PASS)sleep(5);
  4093. return result;
  4094. }
  4095. void checkRemoteStart(uint8_t connectorIdInt)
  4096. {
  4097. uint8_t tempIndex;
  4098. int result = PASS;
  4099. char cmdBuf[512];
  4100. //check Transaction active
  4101. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4102. {
  4103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4104. {
  4105. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4106. }
  4107. else
  4108. {
  4109. tempIndex = connectorIdInt -1;
  4110. }
  4111. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4112. {
  4113. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4114. {
  4115. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4116. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4117. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4118. {
  4119. //Reserved
  4120. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4121. }
  4122. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4123. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4124. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4125. {
  4126. //Reserved
  4127. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4128. result = FAIL;
  4129. goto end;
  4130. }
  4131. else
  4132. {
  4133. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4134. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4135. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4136. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4137. {
  4138. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4139. result = FAIL;
  4140. goto end;
  4141. }
  4142. }//END FOR ELSE
  4143. }
  4144. }// END FOR CHAdeMO_QUANTITY
  4145. }
  4146. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4147. {
  4148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4149. {
  4150. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4151. }
  4152. else
  4153. {
  4154. tempIndex = connectorIdInt -1;
  4155. }
  4156. for (int index = 0; index < CCS_QUANTITY; index++)
  4157. {
  4158. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4159. {
  4160. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4161. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4162. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4163. {
  4164. //Reserved
  4165. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4166. }
  4167. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4168. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4169. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4170. {
  4171. //Reserved
  4172. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4173. result = FAIL;
  4174. goto end;
  4175. }
  4176. else
  4177. {
  4178. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4179. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4180. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4181. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4182. {
  4183. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4184. result = FAIL;
  4185. goto end;
  4186. }
  4187. }// END FOR ELSE
  4188. }
  4189. }// END FOR CCS_QUANTITY
  4190. }
  4191. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4192. {
  4193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4194. {
  4195. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4196. }
  4197. else
  4198. {
  4199. tempIndex = connectorIdInt -1;
  4200. }
  4201. for (int index = 0; index < GB_QUANTITY; index++)
  4202. {
  4203. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4204. {
  4205. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4206. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4207. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4208. {
  4209. //Reserved
  4210. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4211. }
  4212. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4213. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4214. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4215. {
  4216. //Reserved
  4217. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4218. result = FAIL;
  4219. goto end;
  4220. }
  4221. else
  4222. {
  4223. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4224. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4225. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4226. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4227. {
  4228. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4229. result = FAIL;
  4230. goto end;
  4231. }
  4232. }// END FOR ELSE
  4233. }
  4234. } // END FOR GB_QUANTITY
  4235. }
  4236. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4237. {
  4238. tempIndex = connectorIdInt -1;
  4239. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4240. {
  4241. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4242. {
  4243. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4244. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4245. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4246. {
  4247. //Reserved
  4248. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4249. }
  4250. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4251. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4252. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4253. {
  4254. //Reserved
  4255. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4256. result = FAIL;
  4257. goto end;
  4258. }
  4259. else
  4260. {
  4261. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4262. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4263. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4264. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4265. {
  4266. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4267. result = FAIL;
  4268. goto end;
  4269. }
  4270. }// END FOR ELSE
  4271. }
  4272. } // END FOR GB_QUANTITY
  4273. }
  4274. else
  4275. {
  4276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4277. {
  4278. tempIndex = 2;
  4279. }
  4280. else
  4281. {
  4282. tempIndex = connectorIdInt -1;
  4283. }
  4284. for (int index = 0; index < AC_QUANTITY; index++)
  4285. {
  4286. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4287. {
  4288. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4289. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4290. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4291. {
  4292. //Reserved
  4293. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4294. }
  4295. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4296. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4297. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4298. {
  4299. //Reserved
  4300. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4301. result = FAIL;
  4302. goto end;
  4303. }
  4304. else
  4305. {
  4306. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4307. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4308. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4309. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4310. {
  4311. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4312. result = FAIL;
  4313. goto end;
  4314. }
  4315. }//END FOR ELSE
  4316. }
  4317. }// END FOR AC_QUANTITY
  4318. }
  4319. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4320. {
  4321. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4322. {
  4323. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4324. {
  4325. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4326. system(cmdBuf);
  4327. }
  4328. }
  4329. else
  4330. {
  4331. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4332. result = FAIL;
  4333. }
  4334. }
  4335. end:
  4336. if(result == PASS)
  4337. {
  4338. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4339. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4340. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4341. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4342. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4343. }
  4344. }
  4345. void CheckSystemValue(void)
  4346. {
  4347. char filenmae[100]={0};
  4348. char str[100]={0};
  4349. int tempIndex = 0;
  4350. //===============================
  4351. // send Heartbeat
  4352. //===============================
  4353. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4354. {
  4355. //parameter for test
  4356. sendHeartbeatRequest(0);
  4357. //===========================
  4358. // Reset Waiting Time
  4359. //===========================
  4360. HeartBeatWithNOResponse += 1;
  4361. }
  4362. //===============================
  4363. // Credit deduct report
  4364. //===============================
  4365. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4366. {
  4367. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4368. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4369. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4370. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4371. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4372. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4373. }
  4374. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4375. {
  4376. OCPP_query_deduct_info();
  4377. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4378. }
  4379. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4380. {
  4381. // ClockAlign MeterValue
  4382. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4383. {
  4384. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4385. {
  4386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4387. {
  4388. tempIndex = ((gun_index==2) ? 1: 0);
  4389. }
  4390. else
  4391. {
  4392. tempIndex = gun_index;
  4393. }
  4394. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4395. {
  4396. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4397. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4398. {
  4399. reqClockAlignMeter[gun_index] = 1;
  4400. }
  4401. }// End for CHAdeMO
  4402. }
  4403. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4406. {
  4407. tempIndex = ((gun_index==2) ? 1: 0);
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < CCS_QUANTITY; index++)
  4414. {
  4415. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4416. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4417. {
  4418. reqClockAlignMeter[gun_index] = 1;
  4419. }
  4420. } // End for CCS
  4421. }
  4422. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4423. {
  4424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4425. {
  4426. tempIndex = ((gun_index==2) ? 1: 0);
  4427. }
  4428. else
  4429. {
  4430. tempIndex = gun_index;
  4431. }
  4432. for (int index = 0; index < GB_QUANTITY; index++)
  4433. {
  4434. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4435. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4436. {
  4437. reqClockAlignMeter[gun_index] = 1;
  4438. }
  4439. }// End for GB
  4440. }
  4441. else if(gunType[gun_index] == GUN_TYPE_DO)
  4442. {
  4443. tempIndex = gun_index;
  4444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4445. {
  4446. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4447. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4448. {
  4449. reqClockAlignMeter[gun_index] = 1;
  4450. }
  4451. }
  4452. }
  4453. else
  4454. {
  4455. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4456. {
  4457. tempIndex = 2;
  4458. }
  4459. else
  4460. {
  4461. tempIndex = gun_index;
  4462. }
  4463. for (int index = 0; index < AC_QUANTITY; index++)
  4464. {
  4465. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4466. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4467. {
  4468. reqClockAlignMeter[gun_index] = 1;
  4469. }
  4470. }//End for AC
  4471. }
  4472. }
  4473. }
  4474. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4475. {
  4476. //==========================================
  4477. // Check remote start without connector id
  4478. //==========================================
  4479. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4480. {
  4481. int connectorIdInt = -1;
  4482. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4483. {
  4484. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4485. {
  4486. connectorIdInt = (gun_index+1);
  4487. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4488. checkRemoteStart(connectorIdInt);
  4489. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4490. break;
  4491. }
  4492. }
  4493. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4494. {
  4495. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4496. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4497. }
  4498. }
  4499. //==========================================
  4500. // csu trigger DataTransferReq
  4501. //==========================================
  4502. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4503. {
  4504. sendDataTransferRequest(gun_index);
  4505. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4506. }
  4507. //==========================================
  4508. // CSU Trigger Authorize Request
  4509. //==========================================
  4510. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4511. {
  4512. sendAuthorizeRequest(0);
  4513. authorizeRetryTimes = authorizeRetryTimes + 1;
  4514. if(authorizeRetryTimes < 3)
  4515. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4516. }
  4517. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4518. {
  4519. authorizeRetryTimes = 0;
  4520. SetOcppConnStatus(FALSE);
  4521. server_sign = FALSE;
  4522. }
  4523. 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))
  4524. {
  4525. sendAuthorizeRequest(0);
  4526. }
  4527. //==========================================
  4528. // Charger start transaction
  4529. //==========================================
  4530. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4531. {
  4532. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4533. sendStartTransactionRequest(gun_index);
  4534. refreshStartTimer(&clientTime.StartTransaction);
  4535. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4536. storeTempStopTransaction(gun_index);
  4537. }
  4538. //==========================================
  4539. // Charger stop transaction
  4540. //==========================================
  4541. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4542. {
  4543. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4544. sendStopTransactionRequest(gun_index);
  4545. OCPP_updatePeriodEnergy(gun_index);
  4546. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4547. refreshStartTimer(&clientTime.StopTransaction);
  4548. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4549. }
  4550. //==========================================
  4551. // Charger OCMF message
  4552. //==========================================
  4553. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  4554. {
  4555. sendOcmfByDataTransferRequest(gun_index);
  4556. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  4557. }
  4558. //==========================================
  4559. // Charger status report
  4560. //==========================================
  4561. //--- Check Mode Change ---//
  4562. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4563. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4564. {
  4565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4566. {
  4567. tempIndex = ((gun_index==2) ? 1: 0);
  4568. }
  4569. else
  4570. {
  4571. tempIndex = gun_index;
  4572. }
  4573. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4574. {
  4575. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4576. {
  4577. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4578. {
  4579. // Sent unplug message for California pricing logic
  4580. 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])
  4581. {
  4582. uint8_t ts[36];
  4583. getNowDatetime(ts);
  4584. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4585. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4586. if(strcmp((char*)dmsVersion, "2.0")==0)
  4587. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4588. else
  4589. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4590. sendUnplugByDataTransferRequest(gun_index);
  4591. interLock.isSentUnplug[gun_index] = 1;
  4592. }
  4593. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4594. {
  4595. interLock.isSentUnplug[gun_index] = 0;
  4596. }
  4597. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4598. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4599. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4600. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4601. {
  4602. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4603. if((access(filenmae,F_OK))!=-1)
  4604. {
  4605. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4606. sprintf(str,"rm -f %s",filenmae);
  4607. system(str);
  4608. }
  4609. }
  4610. }
  4611. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4612. #if 1 // for TempStopTransaction
  4613. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4614. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4615. {
  4616. checkTempStopTransaction(gun_index);
  4617. }
  4618. #endif
  4619. }
  4620. }
  4621. }
  4622. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4623. {
  4624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4625. {
  4626. tempIndex = ((gun_index==2) ? 1: 0);
  4627. }
  4628. else
  4629. {
  4630. tempIndex = gun_index;
  4631. }
  4632. for (int index = 0; index < CCS_QUANTITY; index++)
  4633. {
  4634. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4635. {
  4636. 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]*/ )
  4637. {
  4638. // Sent unplug message for California pricing logic
  4639. 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])
  4640. {
  4641. uint8_t ts[36];
  4642. getNowDatetime(ts);
  4643. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4644. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4645. if(strcmp((char*)dmsVersion, "2.0")==0)
  4646. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4647. else
  4648. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4649. sendUnplugByDataTransferRequest(gun_index);
  4650. interLock.isSentUnplug[gun_index] = 1;
  4651. }
  4652. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4653. {
  4654. interLock.isSentUnplug[gun_index] = 0;
  4655. }
  4656. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4657. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4658. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4659. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4660. {
  4661. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4662. if((access(filenmae,F_OK))!=-1)
  4663. {
  4664. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4665. sprintf(str,"rm -f %s",filenmae);
  4666. system(str);
  4667. }
  4668. }
  4669. }
  4670. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4671. #if 1 // for TempStopTransaction
  4672. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4673. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4674. {
  4675. checkTempStopTransaction(gun_index);
  4676. }
  4677. #endif
  4678. }
  4679. }
  4680. }
  4681. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4682. {
  4683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4684. {
  4685. tempIndex = ((gun_index==2) ? 1: 0);
  4686. }
  4687. else
  4688. {
  4689. tempIndex = gun_index;
  4690. }
  4691. for (int index = 0; index < GB_QUANTITY; index++)
  4692. {
  4693. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4694. {
  4695. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4696. {
  4697. // Sent unplug message for California pricing logic
  4698. 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])
  4699. {
  4700. uint8_t ts[36];
  4701. getNowDatetime(ts);
  4702. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4703. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4704. if(strcmp((char*)dmsVersion, "2.0")==0)
  4705. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4706. else
  4707. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4708. sendUnplugByDataTransferRequest(gun_index);
  4709. interLock.isSentUnplug[gun_index] = 1;
  4710. }
  4711. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4712. {
  4713. interLock.isSentUnplug[gun_index] = 0;
  4714. }
  4715. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4716. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4717. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4718. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4719. {
  4720. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4721. if((access(filenmae,F_OK))!=-1)
  4722. {
  4723. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4724. sprintf(str,"rm -f %s",filenmae);
  4725. system(str);
  4726. }
  4727. }
  4728. }
  4729. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4730. #if 1 // for TempStopTransaction
  4731. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4732. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4733. {
  4734. checkTempStopTransaction(gun_index);
  4735. }
  4736. #endif
  4737. }
  4738. }
  4739. }
  4740. else if(gunType[gun_index] == GUN_TYPE_DO)
  4741. {
  4742. tempIndex = gun_index;
  4743. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4744. {
  4745. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4746. {
  4747. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4748. {
  4749. // Sent unplug message for California pricing logic
  4750. 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])
  4751. {
  4752. uint8_t ts[36];
  4753. getNowDatetime(ts);
  4754. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4755. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4756. if(strcmp((char*)dmsVersion, "2.0")==0)
  4757. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4758. else
  4759. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4760. sendUnplugByDataTransferRequest(gun_index);
  4761. interLock.isSentUnplug[gun_index] = 1;
  4762. }
  4763. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4764. {
  4765. interLock.isSentUnplug[gun_index] = 0;
  4766. }
  4767. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4768. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4769. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4770. 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
  4771. {
  4772. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4773. if((access(filenmae,F_OK))!=-1)
  4774. {
  4775. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4776. sprintf(str,"rm -f %s",filenmae);
  4777. system(str);
  4778. }
  4779. }
  4780. }
  4781. 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);
  4782. #if 1 // for TempStopTransaction
  4783. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4784. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4785. {
  4786. checkTempStopTransaction(gun_index);
  4787. }
  4788. #endif
  4789. }
  4790. }
  4791. }
  4792. else
  4793. {
  4794. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4795. {
  4796. tempIndex = 2;
  4797. }
  4798. else
  4799. {
  4800. tempIndex = gun_index;
  4801. }
  4802. for (int index = 0; index < AC_QUANTITY; index++)
  4803. {
  4804. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4805. {
  4806. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4807. {
  4808. // Sent unplug message for California pricing logic
  4809. 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])
  4810. {
  4811. uint8_t ts[36];
  4812. getNowDatetime(ts);
  4813. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "Zerova");
  4814. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4815. if(strcmp((char*)dmsVersion, "2.0")==0)
  4816. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4817. else
  4818. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4819. sendUnplugByDataTransferRequest(gun_index);
  4820. interLock.isSentUnplug[gun_index] = 1;
  4821. }
  4822. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4823. {
  4824. interLock.isSentUnplug[gun_index] = 0;
  4825. }
  4826. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4827. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4828. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4829. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4830. {
  4831. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4832. if((access(filenmae,F_OK))!=-1)
  4833. {
  4834. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4835. sprintf(str,"rm -f %s",filenmae);
  4836. system(str);
  4837. }
  4838. }
  4839. }
  4840. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4841. #if 1 // for TempStopTransaction
  4842. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4843. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4844. {
  4845. checkTempStopTransaction(gun_index);
  4846. }
  4847. #endif
  4848. }
  4849. }// END
  4850. }
  4851. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  4852. (
  4853. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4854. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4855. )
  4856. )
  4857. {
  4858. sendStatusNotificationRequest(gun_index);
  4859. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4860. }
  4861. //==============================================
  4862. // TCCI reader status report
  4863. //==============================================
  4864. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4865. {
  4866. reportReaderStatus(gun_index);
  4867. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4868. }
  4869. //==============================================
  4870. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4871. //==============================================
  4872. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4873. ((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))))
  4874. {
  4875. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4876. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4877. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4878. }
  4879. //==============================================
  4880. // Meter report
  4881. //==============================================
  4882. // Trigger MeterValue
  4883. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4884. {
  4885. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4886. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4887. }
  4888. // Clock-aligned Meter value
  4889. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4890. {
  4891. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4892. reqClockAlignMeter[gun_index] = 0;
  4893. }
  4894. // Sample period MeterValue
  4895. 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))))
  4896. {
  4897. //check Transaction active
  4898. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4899. {
  4900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4901. {
  4902. tempIndex = ((gun_index==2) ? 1: 0);
  4903. }
  4904. else
  4905. {
  4906. tempIndex = gun_index;
  4907. }
  4908. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4909. {
  4910. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4911. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4912. {
  4913. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4914. {
  4915. reqSampleMeter[gun_index] = 1;
  4916. }
  4917. }
  4918. }// End for CHAdeMO
  4919. }
  4920. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4921. {
  4922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4923. {
  4924. tempIndex = ((gun_index==2) ? 1: 0);
  4925. }
  4926. else
  4927. {
  4928. tempIndex = gun_index;
  4929. }
  4930. for (int index = 0; index < CCS_QUANTITY; index++)
  4931. {
  4932. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4933. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4934. {
  4935. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4936. {
  4937. reqSampleMeter[gun_index] = 1;
  4938. }
  4939. }
  4940. } // End for CCS
  4941. }
  4942. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4943. {
  4944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4945. {
  4946. tempIndex = ((gun_index==2) ? 1: 0);
  4947. }
  4948. else
  4949. {
  4950. tempIndex = gun_index;
  4951. }
  4952. for (int index = 0; index < GB_QUANTITY; index++)
  4953. {
  4954. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4955. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4956. {
  4957. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4958. {
  4959. reqSampleMeter[gun_index] = 1;
  4960. }
  4961. }
  4962. }// End for GB
  4963. }
  4964. else if(gunType[gun_index] == GUN_TYPE_DO)
  4965. {
  4966. tempIndex = gun_index;
  4967. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4968. {
  4969. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4970. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4971. {
  4972. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4973. {
  4974. reqSampleMeter[gun_index] = 1;
  4975. }
  4976. }
  4977. }
  4978. }
  4979. else
  4980. {
  4981. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4982. {
  4983. tempIndex = 2;
  4984. }
  4985. else
  4986. {
  4987. tempIndex = gun_index;
  4988. }
  4989. for (int index = 0; index < AC_QUANTITY; index++)
  4990. {
  4991. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4992. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4993. {
  4994. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4995. {
  4996. reqSampleMeter[gun_index] = 1;
  4997. }
  4998. }
  4999. }//End for AC
  5000. }
  5001. if(reqSampleMeter[gun_index] == 1)
  5002. {
  5003. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5004. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5005. storeTempStopTransaction(gun_index);
  5006. reqSampleMeter[gun_index] = 0;
  5007. }
  5008. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5009. }
  5010. //==============================================
  5011. // Check Connector reserved
  5012. //==============================================
  5013. //===============================
  5014. // Check if Reserve is expired
  5015. //===============================
  5016. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5017. {
  5018. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5019. {
  5020. DEBUG_INFO("reserve expired.\n");
  5021. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5022. }
  5023. }//END OF Check if Reserve is expired
  5024. //==========================================
  5025. // csu trigger FirmwareStatusNotificationReq
  5026. //==========================================
  5027. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5028. {
  5029. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5030. }
  5031. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5032. {
  5033. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5034. }
  5035. //==========================================
  5036. // csu trigger DiagnosticsStatusNotificationReq
  5037. //==========================================
  5038. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5039. {
  5040. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5041. }
  5042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5043. {
  5044. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5045. }
  5046. //==========================================
  5047. // csu trigger CancelReservationConf
  5048. //==========================================
  5049. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5050. {
  5051. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5052. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5053. }
  5054. //==========================================
  5055. // csu trigger ChangeAvailabilityConf
  5056. //==========================================
  5057. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5058. {
  5059. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5060. }
  5061. //==========================================
  5062. // csu trigger UnlockConnectorConf
  5063. //==========================================
  5064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5065. {
  5066. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5067. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5068. }
  5069. //==========================================
  5070. // csu trigger ReserveNowConf
  5071. //==========================================
  5072. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5073. {
  5074. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5075. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5076. }
  5077. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  5078. {
  5079. sendSignCertificateRequest();
  5080. }
  5081. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5082. {
  5083. sendSecurityEventNotificationRequest();
  5084. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5085. }
  5086. }
  5087. }
  5088. //==========================================
  5089. // send request routine
  5090. //==========================================
  5091. int sendAuthorizeRequest(int gun_index)
  5092. {
  5093. mtrace();
  5094. int result = FAIL;
  5095. char message[100]={0};
  5096. char guid[37];
  5097. char tempdata[65]={0};
  5098. DEBUG_INFO("sendAuthorizeRequest...\n");
  5099. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5100. //Local Authorize
  5101. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5102. {
  5103. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5104. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5105. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5106. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5107. result = PASS;
  5108. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5109. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5110. authorizeRetryTimes = 0;
  5111. return result;
  5112. }
  5113. 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))||
  5114. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5115. {
  5116. // Query from cache
  5117. DEBUG_INFO("Authorize from cache.\n");
  5118. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5119. // Query from list
  5120. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5121. {
  5122. DEBUG_INFO("Authorize from list.\n");
  5123. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5124. }
  5125. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5126. {
  5127. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5128. {
  5129. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5130. }
  5131. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5132. {
  5133. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5134. }
  5135. if(!GetOcppConnStatus())
  5136. {
  5137. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5138. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5139. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5140. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5141. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5142. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5143. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5144. authorizeRetryTimes = 0;
  5145. return result;
  5146. }
  5147. }
  5148. else
  5149. {
  5150. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5151. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5152. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5153. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5154. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5155. else
  5156. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5157. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5158. result = PASS;
  5159. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5160. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5161. authorizeRetryTimes = 0;
  5162. return result;
  5163. }
  5164. }
  5165. //initialize struct Authorize
  5166. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5167. //get data from shared memory
  5168. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5169. random_uuid(guid);
  5170. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5171. LWS_Send(message);
  5172. sprintf(tempdata, "Authorize,%d", gun_index);
  5173. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5174. {
  5175. result = PASS;
  5176. DEBUG_INFO("Authorize mapItem pass\n");
  5177. }
  5178. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5179. return result;
  5180. }
  5181. int sendBootNotificationRequest(void)
  5182. {
  5183. mtrace();
  5184. int result = FAIL;
  5185. char message[500]={0}, payload[700]={0};
  5186. char guid[37]={0};
  5187. char tempdata[65]={0};
  5188. // Fill BootNotification fields
  5189. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5190. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5191. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5192. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5193. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5194. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5195. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5196. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5197. ShmOCPP16Data->ChargeBoxId
  5198. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5199. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5200. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5201. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5202. ,ShmOCPP16Data->BootNotification.CpIccid
  5203. ,ShmOCPP16Data->BootNotification.CpImsi);
  5204. random_uuid(guid);
  5205. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5206. LWS_Send(message);
  5207. sprintf(tempdata, "BootNotification,0");
  5208. 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*/)
  5209. {
  5210. result = PASS;
  5211. }
  5212. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5213. strcpy(queuedata,message);
  5214. return result;
  5215. }
  5216. int sendDataTransferRequest(int gun_index)
  5217. {
  5218. mtrace();
  5219. char message[1000]={0};
  5220. char guid[37]={0};
  5221. char tempdata[65]={0};
  5222. int result = FAIL;
  5223. random_uuid(guid);
  5224. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5225. MESSAGE_TYPE_CALL,
  5226. guid,
  5227. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5228. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5229. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5230. LWS_Send(message);
  5231. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5232. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5233. {
  5234. result = PASS;
  5235. DEBUG_INFO("DataTransfer mapItem pass\n");
  5236. }
  5237. return result;
  5238. }
  5239. int sendUnplugByDataTransferRequest(int gun_index)
  5240. {
  5241. mtrace();
  5242. char message[1000]={0};
  5243. char guid[37]={0};
  5244. char tempdata[65]={0};
  5245. int result = FAIL;
  5246. random_uuid(guid);
  5247. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5248. (gun_index+1),
  5249. MESSAGE_TYPE_CALL,
  5250. guid,
  5251. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5252. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5253. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5254. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5255. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5256. {
  5257. result = PASS;
  5258. DEBUG_INFO("DataTransfer mapItem pass\n");
  5259. }
  5260. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5261. return result;
  5262. }
  5263. int sendOcmfByDataTransferRequest(int gun_index)
  5264. {
  5265. json_object *DataTransfer = json_object_new_object();
  5266. json_object *data = json_object_new_object();
  5267. mtrace();
  5268. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5269. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5270. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5271. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5272. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5273. json_object_object_add(DataTransfer, "data", data);
  5274. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5275. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5276. char message[3000]={0};
  5277. char guid[37]={0};
  5278. char tempdata[65]={0};
  5279. int result = FAIL;
  5280. random_uuid(guid);
  5281. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5282. (gun_index+1),
  5283. MESSAGE_TYPE_CALL,
  5284. guid,
  5285. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5286. json_object_put(DataTransfer);
  5287. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5288. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5289. {
  5290. result = PASS;
  5291. DEBUG_INFO("DataTransfer mapItem pass\n");
  5292. }
  5293. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5294. return result;
  5295. }
  5296. int sendDiagnosticsStatusNotificationRequest(char *status)
  5297. {
  5298. mtrace();
  5299. int result = FAIL;
  5300. char message[110]={0};
  5301. char guid[37]={0};
  5302. char tempdata[65]={0};
  5303. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5304. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5305. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5306. random_uuid(guid);
  5307. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5308. LWS_SendNow(message);
  5309. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5310. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5311. {
  5312. result = PASS;
  5313. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5314. }
  5315. //#ifdef SystemLogMessage
  5316. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5317. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5318. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5319. //#endif
  5320. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5321. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5322. //record status
  5323. if(strcmp(status,"Idle")==0)
  5324. {
  5325. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5326. }
  5327. else if(strcmp(status,"Uploaded")==0)
  5328. {
  5329. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5330. }
  5331. else if(strcmp(status,"UploadFailed")==0)
  5332. {
  5333. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5334. }
  5335. else if(strcmp(status,"Uploading")==0)
  5336. {
  5337. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5338. }
  5339. return result;
  5340. }
  5341. int sendFirmwareStatusNotificationRequest(char *status)
  5342. {
  5343. mtrace();
  5344. int result = FAIL;
  5345. char message[110]={0};
  5346. char guid[37]={0};
  5347. char tempdata[65]={0};
  5348. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5349. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5350. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5351. random_uuid(guid);
  5352. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5353. LWS_SendNow(message);
  5354. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5355. 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*/)
  5356. {
  5357. result = PASS;
  5358. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5359. }
  5360. //#ifdef SystemLogMessage
  5361. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5362. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5363. //#endif
  5364. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5365. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5366. //record status
  5367. if(strcmp(status,"Downloaded")==0)
  5368. {
  5369. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5370. }
  5371. else if(strcmp(status,"DownloadFailed")==0)
  5372. {
  5373. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5374. }
  5375. else if(strcmp(status,"Downloading")==0)
  5376. {
  5377. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5378. }
  5379. else if(strcmp(status,"Idle")==0)
  5380. {
  5381. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5382. }
  5383. else if(strcmp(status,"InstallationFailed")==0)
  5384. {
  5385. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5386. }
  5387. else if(strcmp(status,"Installing")==0)
  5388. {
  5389. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5390. }
  5391. else if(strcmp(status,"Installed")==0)
  5392. {
  5393. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5394. }
  5395. return result;
  5396. }
  5397. int sendHeartbeatRequest(int gun_index)
  5398. {
  5399. mtrace();
  5400. int result = FAIL;
  5401. char message[80]={0};
  5402. char guid[37]={0};
  5403. char tempdata[65]={0};
  5404. random_uuid(guid);
  5405. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5406. , MESSAGE_TYPE_CALL
  5407. , guid );
  5408. LWS_Send(message);
  5409. sprintf(tempdata, "Heartbeat,%d", 0);
  5410. 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*/)
  5411. {
  5412. result = PASS;
  5413. }
  5414. return result;
  5415. }
  5416. int sendStartTransactionRequest(int gun_index)
  5417. {
  5418. mtrace();
  5419. int result = FAIL;
  5420. char message[250]={0};
  5421. char guid[37]={0};
  5422. struct timeval tmnow;
  5423. struct tm *tm;
  5424. char buf[28];//, usec_buf[6];
  5425. char tempdata[65]={0};
  5426. int tempIndex = 0;
  5427. DEBUG_INFO("sendStartTransactionRequest...\n");
  5428. gettimeofday(&tmnow, NULL);
  5429. time_t t;
  5430. t = time(NULL);
  5431. /*UTC time and date*/
  5432. tm = gmtime(&t);
  5433. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5434. #if 0 // remove temporally
  5435. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5436. strcat(buf,".");
  5437. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5438. strcat(buf,usec_buf);
  5439. #endif
  5440. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5441. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5442. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5443. // clear StartTransaction Response
  5444. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5445. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5446. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5447. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5448. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5449. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5450. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5451. {
  5452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5453. {
  5454. tempIndex = ((gun_index==2) ? 1: 0);
  5455. }
  5456. else
  5457. {
  5458. tempIndex = gun_index;
  5459. }
  5460. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5461. {
  5462. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5463. {
  5464. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5465. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5466. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5467. }
  5468. }
  5469. }
  5470. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5471. {
  5472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5473. {
  5474. tempIndex = ((gun_index==2) ? 1: 0);
  5475. }
  5476. else
  5477. {
  5478. tempIndex = gun_index;
  5479. }
  5480. for (int index = 0; index < CCS_QUANTITY; index++)
  5481. {
  5482. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5483. {
  5484. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5485. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5486. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5487. }
  5488. }
  5489. }
  5490. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5491. {
  5492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5493. {
  5494. tempIndex = ((gun_index==2) ? 1: 0);
  5495. }
  5496. else
  5497. {
  5498. tempIndex = gun_index;
  5499. }
  5500. for (int index = 0; index < GB_QUANTITY; index++)
  5501. {
  5502. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5503. {
  5504. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5505. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5506. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5507. }
  5508. }
  5509. }
  5510. else if(gunType[gun_index] == GUN_TYPE_DO)
  5511. {
  5512. tempIndex = gun_index;
  5513. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5514. {
  5515. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5516. {
  5517. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5518. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5519. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5520. }
  5521. }
  5522. }
  5523. else
  5524. {
  5525. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5526. {
  5527. tempIndex = 2;
  5528. }
  5529. else
  5530. {
  5531. tempIndex = gun_index;
  5532. }
  5533. for (int index = 0; index < AC_QUANTITY; index++)
  5534. {
  5535. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5536. {
  5537. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5538. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5539. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5540. }
  5541. }
  5542. }
  5543. random_uuid(guid);
  5544. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5545. {
  5546. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5547. , gun_index +1
  5548. , MESSAGE_TYPE_CALL
  5549. , guid
  5550. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5551. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5552. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5553. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5554. }
  5555. else
  5556. {
  5557. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5558. , gun_index +1
  5559. , MESSAGE_TYPE_CALL
  5560. , guid
  5561. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5562. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5563. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5564. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5565. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5566. }
  5567. #if 1
  5568. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5569. 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*/)
  5570. {
  5571. result = PASS;
  5572. }
  5573. #endif
  5574. strcpy(queuedata, message);
  5575. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5576. OCPP_insert_transaction_msg(YES, queuedata);
  5577. return result;
  5578. }
  5579. int sendStatusNotificationRequest(int gun_index)
  5580. {
  5581. mtrace();
  5582. int result = FAIL;
  5583. char message[600]={0};
  5584. char guid[37];
  5585. int currentStatus = 0;
  5586. struct timeval tmnow;
  5587. struct tm *tm;
  5588. char buf[28];//, usec_buf[6];
  5589. char tempdata[65]={0};
  5590. int tempIndex = 0;
  5591. uint8_t isStateChanged = TRUE;
  5592. uint8_t isContentIllegal = TRUE;
  5593. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5594. gettimeofday(&tmnow, NULL);
  5595. time_t t;
  5596. t = time(NULL);
  5597. /*UTC time and date*/
  5598. tm = gmtime(&t);
  5599. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5600. #if 0 // remove temporally
  5601. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5602. strcat(buf,".");
  5603. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5604. strcat(buf,usec_buf);
  5605. #endif
  5606. //printf("%s",buf);
  5607. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5608. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5609. // it's option
  5610. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5611. /*
  5612. enum _SYSTEM_STATUS
  5613. {
  5614. S_BOOTING = 0,
  5615. S_IDLE, = 1
  5616. S_AUTHORIZING, =2
  5617. S_REASSIGN_CHECK, =3
  5618. S_REASSIGN, =4
  5619. S_PRECHARGE, =5
  5620. S_PREPARING_FOR_EV, =6
  5621. S_PREPARING_FOR_EVSE, =7
  5622. S_CHARGING, =8
  5623. S_TERMINATING, =9
  5624. S_COMPLETE, =10
  5625. S_ALARM, =11
  5626. S_FAULT =12
  5627. }
  5628. */
  5629. //check Transaction active
  5630. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5631. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5632. {
  5633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5634. {
  5635. tempIndex = ((gun_index==2) ? 1: 0);
  5636. }
  5637. else
  5638. {
  5639. tempIndex = gun_index;
  5640. }
  5641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5642. {
  5643. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5644. {
  5645. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5646. {
  5647. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5648. {
  5649. currentStatus = Preparing; //OCPP Status: Preparing
  5650. }
  5651. else
  5652. {
  5653. currentStatus = Available; //OCPP Status: Available
  5654. }
  5655. }
  5656. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5657. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5658. ) //S_PRECHARGE
  5659. {
  5660. currentStatus = Preparing; //OCPP Status: Preparing
  5661. }
  5662. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5663. {
  5664. currentStatus = Charging; //OCPP Status: Charging
  5665. }
  5666. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5667. {
  5668. currentStatus = Finishing; //OCPP Status: Finishing
  5669. }
  5670. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5671. {
  5672. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5673. }
  5674. 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
  5675. {
  5676. currentStatus = Unavailable; //OCPP Status: Unavailable
  5677. }
  5678. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5679. {
  5680. currentStatus = Faulted; //OCPP Status: Faulted
  5681. }
  5682. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5683. {
  5684. currentStatus = Reserved; //OCPP Status: Reserved
  5685. }
  5686. } //end of the same index
  5687. }//end of for CHAdeMO_QUANTITY
  5688. }
  5689. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5690. {
  5691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5692. {
  5693. tempIndex = ((gun_index==2) ? 1: 0);
  5694. }
  5695. else
  5696. {
  5697. tempIndex = gun_index;
  5698. }
  5699. for (int index = 0; index < CCS_QUANTITY; index++)
  5700. {
  5701. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5702. {
  5703. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5704. {
  5705. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5706. {
  5707. currentStatus = Preparing; //OCPP Status: Preparing
  5708. }
  5709. else
  5710. {
  5711. currentStatus = Available; //OCPP Status: Available
  5712. }
  5713. }
  5714. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5715. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5716. ) //S_PRECHARGE
  5717. {
  5718. currentStatus = Preparing; //OCPP Status: Preparing
  5719. }
  5720. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5721. {
  5722. currentStatus = Charging; //OCPP Status: Charging
  5723. }
  5724. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5725. {
  5726. currentStatus = Finishing; //OCPP Status: Finishing
  5727. }
  5728. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5729. {
  5730. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5731. }
  5732. 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
  5733. {
  5734. currentStatus = Unavailable; //OCPP Status : Unavailable
  5735. }
  5736. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5737. {
  5738. currentStatus = Faulted; //OCPP Status: Faulted
  5739. }
  5740. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5741. {
  5742. currentStatus = Reserved; //OCPP Status: Reserved
  5743. }
  5744. } //end of the same index
  5745. } // end of for CCS_QUANTITY
  5746. }
  5747. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5748. {
  5749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5750. {
  5751. tempIndex = ((gun_index==2) ? 1: 0);
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. for (int index = 0; index < GB_QUANTITY; index++)
  5758. {
  5759. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5760. {
  5761. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5762. {
  5763. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5764. {
  5765. currentStatus = Preparing; //OCPP Status: Preparing
  5766. }
  5767. else
  5768. {
  5769. currentStatus = Available; //OCPP Status: Available
  5770. }
  5771. }
  5772. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5773. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5774. ) //S_PRECHARGE
  5775. {
  5776. currentStatus = Preparing; //OCPP Status: Preparing
  5777. }
  5778. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5779. {
  5780. currentStatus = Charging; //OCPP Status: Charging
  5781. }
  5782. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5783. {
  5784. currentStatus = Finishing; //OCPP Status: Finishing
  5785. }
  5786. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5787. {
  5788. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5789. }
  5790. 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
  5791. {
  5792. currentStatus = Unavailable; //OCPP Status: Unavailable
  5793. }
  5794. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5795. {
  5796. currentStatus = Faulted; //OCPP Status: Faulted
  5797. }
  5798. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5799. {
  5800. currentStatus = Reserved; //OCPP Status: Reserved
  5801. }
  5802. } //end of the same index
  5803. } // end of for GB_QUANTITY
  5804. }
  5805. else if(gunType[gun_index] == GUN_TYPE_DO)
  5806. {
  5807. tempIndex = gun_index;
  5808. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5809. {
  5810. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5811. {
  5812. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5813. {
  5814. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5815. {
  5816. currentStatus = Preparing; //OCPP Status: Preparing
  5817. }
  5818. else
  5819. {
  5820. currentStatus = Available; //OCPP Status: Available
  5821. }
  5822. }
  5823. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5824. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5825. ) //S_PRECHARGE
  5826. {
  5827. currentStatus = Preparing; //OCPP Status: Preparing
  5828. }
  5829. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5830. {
  5831. currentStatus = Charging; //OCPP Status: Charging
  5832. }
  5833. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5834. {
  5835. currentStatus = Finishing; //OCPP Status: Finishing
  5836. }
  5837. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5838. {
  5839. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5840. }
  5841. 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
  5842. {
  5843. currentStatus = Unavailable; //OCPP Status: Unavailable
  5844. }
  5845. 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
  5846. {
  5847. currentStatus = Faulted; //OCPP Status: Faulted
  5848. }
  5849. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5850. {
  5851. currentStatus = Reserved; //OCPP Status: Reserved
  5852. }
  5853. } //end of the same index
  5854. }
  5855. }
  5856. else
  5857. {
  5858. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5859. {
  5860. tempIndex = 2;
  5861. }
  5862. else
  5863. {
  5864. tempIndex = gun_index;
  5865. }
  5866. for (int index = 0; index < AC_QUANTITY; index++)
  5867. {
  5868. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5869. {
  5870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5871. {
  5872. 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))
  5873. {
  5874. currentStatus = Preparing; //OCPP Status: Preparing
  5875. }
  5876. else
  5877. {
  5878. currentStatus = Available; //OCPP Status: Available
  5879. }
  5880. }
  5881. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5882. {
  5883. currentStatus = Preparing; //OCPP Status: Preparing
  5884. }
  5885. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5886. {
  5887. currentStatus = Charging; //OCPP Status: Charging
  5888. }
  5889. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5890. {
  5891. currentStatus = Finishing; //OCPP Status: Finishing
  5892. }
  5893. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5894. {
  5895. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5896. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5897. else
  5898. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5899. }
  5900. 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
  5901. {
  5902. currentStatus = Unavailable; //OCPP Status: Unavailable
  5903. }
  5904. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5905. {
  5906. currentStatus = Faulted; //OCPP Status: Faulted
  5907. }
  5908. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5909. {
  5910. currentStatus = Reserved; //OCPP Status: Reserved
  5911. }
  5912. }//end of the same index
  5913. }//end of for AC_QUANTITY
  5914. }
  5915. //it's option
  5916. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5917. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5918. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5919. {
  5920. isStateChanged = FALSE;
  5921. }
  5922. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5923. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5924. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5925. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5926. isContentIllegal = TRUE;
  5927. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5928. {
  5929. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5930. {
  5931. isContentIllegal = FALSE;
  5932. break;
  5933. }
  5934. }
  5935. if(isContentIllegal)
  5936. {
  5937. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5938. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5939. }
  5940. random_uuid(guid);
  5941. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5942. , MESSAGE_TYPE_CALL
  5943. , guid
  5944. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5945. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5946. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5947. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5948. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5949. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5950. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5951. if((server_sign == TRUE) && isStateChanged)
  5952. {
  5953. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5954. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5955. LWS_Send(message);
  5956. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5957. 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*/)
  5958. {
  5959. //DEBUG_ERROR("statusNotification mapitem pass");
  5960. result = PASS;
  5961. }
  5962. }
  5963. else
  5964. {
  5965. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5966. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5967. result = PASS;
  5968. }
  5969. return result;
  5970. }
  5971. int sendStopTransactionRequest(int gun_index)
  5972. {
  5973. mtrace();
  5974. int result = FAIL;
  5975. //char message[1500]={0};
  5976. char guid[37]={0};
  5977. char tempdata[65]={0};
  5978. int tempIndex = 0;
  5979. char TempStopTransaction[256];
  5980. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5981. //int idx_sample=0;
  5982. DEBUG_INFO("sendStopTransactionRequest \n");
  5983. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5984. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5985. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5986. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5987. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5988. {
  5989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5990. {
  5991. tempIndex = ((gun_index==2) ? 1: 0);
  5992. }
  5993. else
  5994. {
  5995. tempIndex = gun_index;
  5996. }
  5997. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5998. {
  5999. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6000. {
  6001. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6002. }
  6003. }// END OF CHAdeMO_QUANTITY
  6004. }
  6005. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6006. {
  6007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6008. {
  6009. tempIndex = ((gun_index==2) ? 1: 0);
  6010. }
  6011. else
  6012. {
  6013. tempIndex = gun_index;
  6014. }
  6015. for (int index = 0; index < CCS_QUANTITY; index++)
  6016. {
  6017. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6018. {
  6019. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6020. }
  6021. }// END OF CCS_QUANTITY
  6022. }
  6023. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6024. {
  6025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6026. {
  6027. tempIndex = ((gun_index==2) ? 1: 0);
  6028. }
  6029. else
  6030. {
  6031. tempIndex = gun_index;
  6032. }
  6033. for (int index = 0; index < GB_QUANTITY; index++)
  6034. {
  6035. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6036. {
  6037. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6038. }
  6039. }// END OF GB_QUANTITY
  6040. }
  6041. else if(gunType[gun_index] == GUN_TYPE_DO)
  6042. {
  6043. tempIndex = gun_index;
  6044. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6045. {
  6046. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6047. {
  6048. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6049. }
  6050. }// END OF GB_QUANTITY
  6051. }
  6052. else
  6053. {
  6054. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6055. {
  6056. tempIndex = 2;
  6057. }
  6058. else
  6059. {
  6060. tempIndex = gun_index;
  6061. }
  6062. for (int index = 0; index < AC_QUANTITY; index++)
  6063. {
  6064. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6065. {
  6066. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6067. }
  6068. }// END OF AC_QUANTITY
  6069. }
  6070. //====================================== Stop Transaction Time =====================================================
  6071. struct timeval tmnow;
  6072. struct tm *tm;
  6073. char buf[28];//, usec_buf[6];
  6074. gettimeofday(&tmnow, NULL);
  6075. time_t t;
  6076. t = time(NULL);
  6077. /*UTC time and date*/
  6078. tm = gmtime(&t);
  6079. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  6081. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6082. random_uuid(guid);
  6083. /***********************************transactionData******************************************************/
  6084. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6086. //=================================
  6087. // Transaction_Begin
  6088. //=================================
  6089. //=================================
  6090. // Transaction_End
  6091. //=================================
  6092. // ================================= Current.Import L1 ===============================================
  6093. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6094. {
  6095. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6096. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6097. {
  6098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6099. {
  6100. tempIndex = ((gun_index==2) ? 1: 0);
  6101. }
  6102. else
  6103. {
  6104. tempIndex = gun_index;
  6105. }
  6106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6107. {
  6108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6109. {
  6110. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6111. }
  6112. }// End of for CHAdeMO_QUANTITY
  6113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6114. }
  6115. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6116. {
  6117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6118. {
  6119. tempIndex = ((gun_index==2) ? 1: 0);
  6120. }
  6121. else
  6122. {
  6123. tempIndex = gun_index;
  6124. }
  6125. for (int index = 0; index < CCS_QUANTITY; index++)
  6126. {
  6127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6128. {
  6129. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6130. }
  6131. }// End of for CCS_QUANTITY
  6132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6133. }
  6134. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6147. {
  6148. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6149. }
  6150. }// End of for GB_QUANTITY
  6151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6152. }
  6153. else if(gunType[gun_index] == GUN_TYPE_DO)
  6154. {
  6155. tempIndex = gun_index;
  6156. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6157. {
  6158. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6159. {
  6160. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6161. }
  6162. }
  6163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6164. }
  6165. else
  6166. {
  6167. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6168. {
  6169. tempIndex = 2;
  6170. }
  6171. else
  6172. {
  6173. tempIndex = gun_index;
  6174. }
  6175. for (int index = 0; index < AC_QUANTITY; index++)
  6176. {
  6177. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6178. {
  6179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6180. }
  6181. }// End of for AC_QUANTITY
  6182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6183. }
  6184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6189. }
  6190. // ================================= Energy.Active.Import.Interval ==============================================
  6191. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6192. {
  6193. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6194. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6195. {
  6196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6197. {
  6198. tempIndex = ((gun_index==2) ? 1: 0);
  6199. }
  6200. else
  6201. {
  6202. tempIndex = gun_index;
  6203. }
  6204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6205. {
  6206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6207. {
  6208. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6209. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6210. }
  6211. }// END OF CHAdeMO_QUANTITY
  6212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6213. }
  6214. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6215. {
  6216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6217. {
  6218. tempIndex = ((gun_index==2) ? 1: 0);
  6219. }
  6220. else
  6221. {
  6222. tempIndex = gun_index;
  6223. }
  6224. for (int index = 0; index < CCS_QUANTITY; index++)
  6225. {
  6226. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6227. {
  6228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6229. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6230. }
  6231. }// END OF CCS_QUANTITY
  6232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6233. }
  6234. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6235. {
  6236. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6237. {
  6238. tempIndex = ((gun_index==2) ? 1: 0);
  6239. }
  6240. else
  6241. {
  6242. tempIndex = gun_index;
  6243. }
  6244. for (int index = 0; index < GB_QUANTITY; index++)
  6245. {
  6246. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6247. {
  6248. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6249. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6250. }
  6251. }// END OF GB_QUANTITY
  6252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6253. }
  6254. else if(gunType[gun_index] == GUN_TYPE_DO)
  6255. {
  6256. tempIndex = gun_index;
  6257. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6258. {
  6259. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6260. {
  6261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6262. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6263. }
  6264. }
  6265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6266. }
  6267. else
  6268. {
  6269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6270. {
  6271. tempIndex = 2;
  6272. }
  6273. else
  6274. {
  6275. tempIndex = gun_index;
  6276. }
  6277. for (int index = 0; index < AC_QUANTITY; index++)
  6278. {
  6279. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6280. {
  6281. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6282. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6283. }
  6284. }// END OF AC_QUANTITY
  6285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6286. }
  6287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6292. }
  6293. //=================================== Power.Active.Import ==================================================
  6294. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6295. {
  6296. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6297. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6298. {
  6299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6300. {
  6301. tempIndex = ((gun_index==2) ? 1: 0);
  6302. }
  6303. else
  6304. {
  6305. tempIndex = gun_index;
  6306. }
  6307. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6308. {
  6309. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6310. {
  6311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6312. }
  6313. } // End for CHAdeMO_QUANTITY
  6314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6315. }
  6316. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6317. {
  6318. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6319. {
  6320. tempIndex = ((gun_index==2) ? 1: 0);
  6321. }
  6322. else
  6323. {
  6324. tempIndex = gun_index;
  6325. }
  6326. for (int index = 0; index < CCS_QUANTITY; index++)
  6327. {
  6328. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6329. {
  6330. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6331. }
  6332. } // END for CCS_QUANTITY
  6333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6334. }
  6335. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6336. {
  6337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6338. {
  6339. tempIndex = ((gun_index==2) ? 1: 0);
  6340. }
  6341. else
  6342. {
  6343. tempIndex = gun_index;
  6344. }
  6345. for (int index = 0; index < GB_QUANTITY; index++)
  6346. {
  6347. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6348. {
  6349. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6350. }
  6351. }// END for GB_QUANTITY
  6352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6353. }
  6354. else if(gunType[gun_index] == GUN_TYPE_DO)
  6355. {
  6356. tempIndex = gun_index;
  6357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6358. {
  6359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6360. {
  6361. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6362. }
  6363. }
  6364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6365. }
  6366. else
  6367. {
  6368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6369. {
  6370. tempIndex = 2;
  6371. }
  6372. else
  6373. {
  6374. tempIndex = gun_index;
  6375. }
  6376. for (int index = 0; index < AC_QUANTITY; index++)
  6377. {
  6378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6379. {
  6380. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6381. }
  6382. } // END for AC_QUANTITY
  6383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6384. }
  6385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6390. }
  6391. //============================ Voltage L1 ====================================
  6392. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6393. {
  6394. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6395. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6396. {
  6397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6398. {
  6399. tempIndex = ((gun_index==2) ? 1: 0);
  6400. }
  6401. else
  6402. {
  6403. tempIndex = gun_index;
  6404. }
  6405. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6406. {
  6407. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6408. {
  6409. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6410. }
  6411. } // END OF FOR CHAdeMO_QUANTITY
  6412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6413. }
  6414. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6415. {
  6416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6417. {
  6418. tempIndex = ((gun_index==2) ? 1: 0);
  6419. }
  6420. else
  6421. {
  6422. tempIndex = gun_index;
  6423. }
  6424. for (int index = 0; index < CCS_QUANTITY; index++)
  6425. {
  6426. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6427. {
  6428. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6429. }
  6430. } // END OF FOR CCS_QUANTITY
  6431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6432. }
  6433. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6434. {
  6435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6436. {
  6437. tempIndex = ((gun_index==2) ? 1: 0);
  6438. }
  6439. else
  6440. {
  6441. tempIndex = gun_index;
  6442. }
  6443. for (int index = 0; index < GB_QUANTITY; index++)
  6444. {
  6445. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6446. {
  6447. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6448. }
  6449. } // END OF FOR GB_QUANTITY
  6450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6451. }
  6452. else if(gunType[gun_index] == GUN_TYPE_DO)
  6453. {
  6454. tempIndex = gun_index;
  6455. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6456. {
  6457. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6458. {
  6459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6460. }
  6461. }
  6462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6463. }
  6464. else
  6465. {
  6466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6467. {
  6468. tempIndex = 2;
  6469. }
  6470. else
  6471. {
  6472. tempIndex = gun_index;
  6473. }
  6474. for (int index = 0; index < AC_QUANTITY; index++)
  6475. {
  6476. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6477. {
  6478. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6479. }
  6480. } // END OF FOR AC_QUANTITY
  6481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6482. }
  6483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6488. }
  6489. //====================== End SoC ================================
  6490. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6491. {
  6492. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6493. 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))
  6494. {
  6495. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6496. {
  6497. tempIndex = ((gun_index==2) ? 1: 0);
  6498. }
  6499. else
  6500. {
  6501. tempIndex = gun_index;
  6502. }
  6503. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6504. {
  6505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6506. {
  6507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6508. {
  6509. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6510. }
  6511. }
  6512. }
  6513. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6514. {
  6515. for (int index = 0; index < CCS_QUANTITY; index++)
  6516. {
  6517. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6518. {
  6519. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6520. }
  6521. }
  6522. }
  6523. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6524. {
  6525. for (int index = 0; index < GB_QUANTITY; index++)
  6526. {
  6527. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6528. {
  6529. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6530. }
  6531. }
  6532. }
  6533. else if(gunType[gun_index] == GUN_TYPE_DO)
  6534. {
  6535. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6536. {
  6537. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6538. {
  6539. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6540. }
  6541. }
  6542. }
  6543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6549. } // END FOR DC CASE
  6550. }
  6551. // ================================= Current.Import L2 ===============================================
  6552. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6553. {
  6554. // AC 3 phse L2 current
  6555. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6556. {
  6557. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6558. {
  6559. tempIndex = 2;
  6560. }
  6561. else
  6562. {
  6563. tempIndex = gun_index;
  6564. }
  6565. for (int index = 0; index < AC_QUANTITY; index++)
  6566. {
  6567. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6568. {
  6569. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6570. }
  6571. }// End of for AC_QUANTITY
  6572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6573. }
  6574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6579. }
  6580. // ================================= Current.Import L3 ===============================================
  6581. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6582. {
  6583. // AC 3 phse L3 current
  6584. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6585. {
  6586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6587. {
  6588. tempIndex = 2;
  6589. }
  6590. else
  6591. {
  6592. tempIndex = gun_index;
  6593. }
  6594. for (int index = 0; index < AC_QUANTITY; index++)
  6595. {
  6596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6597. {
  6598. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6599. }
  6600. }// End of for AC_QUANTITY
  6601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6602. }
  6603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6608. }
  6609. //============================ Voltage L2 ====================================
  6610. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6611. {
  6612. // AC 3 phse L2 voltage
  6613. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6614. {
  6615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6616. {
  6617. tempIndex = 2;
  6618. }
  6619. else
  6620. {
  6621. tempIndex = gun_index;
  6622. }
  6623. for (int index = 0; index < AC_QUANTITY; index++)
  6624. {
  6625. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6626. {
  6627. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6628. }
  6629. } // END OF FOR AC_QUANTITY
  6630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6631. }
  6632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6637. }
  6638. //============================ Voltage L3 ====================================
  6639. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6640. {
  6641. // AC 3 phse L3 voltage
  6642. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6643. {
  6644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6645. {
  6646. tempIndex = 2;
  6647. }
  6648. else
  6649. {
  6650. tempIndex = gun_index;
  6651. }
  6652. for (int index = 0; index < AC_QUANTITY; index++)
  6653. {
  6654. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6655. {
  6656. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6657. }
  6658. } // END OF FOR AC_QUANTITY
  6659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6660. }
  6661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6666. }
  6667. //====================== Start SoC ================================
  6668. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6669. {
  6670. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6671. 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))
  6672. {
  6673. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6674. {
  6675. tempIndex = ((gun_index==2) ? 1: 0);
  6676. }
  6677. else
  6678. {
  6679. tempIndex = gun_index;
  6680. }
  6681. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6682. {
  6683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6684. {
  6685. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6686. {
  6687. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6688. }
  6689. }
  6690. }
  6691. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6692. {
  6693. for (int index = 0; index < CCS_QUANTITY; index++)
  6694. {
  6695. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6696. {
  6697. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6698. }
  6699. }
  6700. }
  6701. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6702. {
  6703. for (int index = 0; index < GB_QUANTITY; index++)
  6704. {
  6705. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6706. {
  6707. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6708. }
  6709. }
  6710. }
  6711. else if(gunType[gun_index] == GUN_TYPE_DO)
  6712. {
  6713. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6714. {
  6715. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6716. {
  6717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6718. }
  6719. }
  6720. }
  6721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6727. } // END FOR DC CASE
  6728. }
  6729. //================================================ Message create ====================================================
  6730. json_object *StopTransaction = json_object_new_object();
  6731. json_object *transactionDatas = json_object_new_array();
  6732. json_object *sampledValues = json_object_new_array();
  6733. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6734. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6735. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6736. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6737. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6738. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6739. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6740. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6741. {
  6742. json_object *transactionData = json_object_new_object();
  6743. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6744. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6745. {
  6746. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6747. {
  6748. json_object *sampledValue = json_object_new_object();
  6749. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6750. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6751. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6752. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6753. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6754. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6755. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6756. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6757. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6758. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6759. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6760. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6761. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6762. json_object_array_add(sampledValues, sampledValue);
  6763. }
  6764. }
  6765. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6766. json_object_array_add(transactionDatas, transactionData);
  6767. }
  6768. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6769. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6770. ,MESSAGE_TYPE_CALL
  6771. ,guid
  6772. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6773. json_object_put(StopTransaction);
  6774. #if 1 // for TempStopTransaction
  6775. //Delete TempStopTransaction
  6776. if((access(TempStopTransaction,F_OK))!=-1)
  6777. {
  6778. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6779. }
  6780. #endif
  6781. #if 1
  6782. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6783. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6784. {
  6785. result = PASS;
  6786. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6787. }
  6788. #endif
  6789. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6790. OCPP_insert_transaction_msg(NO, queuedata);
  6791. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6792. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6793. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6794. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6795. {
  6796. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6797. }
  6798. //for test
  6799. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6800. return result;
  6801. }
  6802. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6803. {
  6804. mtrace();
  6805. int result = FAIL;
  6806. char guid[37]={0};
  6807. char tempdata[65]={0};
  6808. int tempIndex = 0;
  6809. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6810. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6811. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6812. //set value
  6813. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6814. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6815. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6816. -1);
  6817. random_uuid(guid);
  6818. //UTC Date time
  6819. struct timeval tmnow;
  6820. struct tm *tm;
  6821. char buf[28];//, usec_buf[6];
  6822. gettimeofday(&tmnow, NULL);
  6823. time_t t;
  6824. t = time(NULL);
  6825. /*UTC time and date*/
  6826. tm = gmtime(&t);
  6827. if(dataType == ReadingContext_Sample_Clock)
  6828. {
  6829. struct tm *tmTarget;
  6830. struct timeb tbTarget;
  6831. tbTarget.time = mktime(tm);
  6832. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6833. tmTarget = gmtime(&tbTarget.time);
  6834. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6835. }
  6836. else
  6837. {
  6838. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6839. }
  6840. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6841. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6842. //********************************(1)Current.Import L1************************************************/
  6843. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6844. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6845. (dataType == ReadingContext_Trigger))
  6846. {
  6847. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6848. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6849. {
  6850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6851. {
  6852. tempIndex = ((gun_index==2) ? 1: 0);
  6853. }
  6854. else
  6855. {
  6856. tempIndex = gun_index;
  6857. }
  6858. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6859. {
  6860. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6861. {
  6862. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6863. }
  6864. }
  6865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6866. }
  6867. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6868. {
  6869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6870. {
  6871. tempIndex = ((gun_index==2) ? 1: 0);
  6872. }
  6873. else
  6874. {
  6875. tempIndex = gun_index;
  6876. }
  6877. for (int index = 0; index < CCS_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6880. {
  6881. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6882. }
  6883. }
  6884. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6885. }
  6886. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6887. {
  6888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6889. {
  6890. tempIndex = ((gun_index==2) ? 1: 0);
  6891. }
  6892. else
  6893. {
  6894. tempIndex = gun_index;
  6895. }
  6896. for (int index = 0; index < GB_QUANTITY; index++)
  6897. {
  6898. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6899. {
  6900. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6901. }
  6902. }
  6903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6904. }
  6905. else if(gunType[gun_index] == GUN_TYPE_DO)
  6906. {
  6907. tempIndex = gun_index;
  6908. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6909. {
  6910. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6911. {
  6912. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6913. }
  6914. }
  6915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6916. }
  6917. else
  6918. {
  6919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6920. {
  6921. tempIndex = 2;
  6922. }
  6923. else
  6924. {
  6925. tempIndex = gun_index;
  6926. }
  6927. for (int index = 0; index < AC_QUANTITY; index++)
  6928. {
  6929. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6930. {
  6931. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6932. }
  6933. }
  6934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6935. }
  6936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6941. }
  6942. //********************************(2)Energy.Active.Import.Register ************************************************/
  6943. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6944. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6945. (dataType == ReadingContext_Trigger))
  6946. {
  6947. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6948. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6949. {
  6950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6951. {
  6952. tempIndex = ((gun_index==2) ? 1: 0);
  6953. }
  6954. else
  6955. {
  6956. tempIndex = gun_index;
  6957. }
  6958. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6959. {
  6960. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6961. {
  6962. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6963. }
  6964. }
  6965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6966. }
  6967. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6968. {
  6969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6970. {
  6971. tempIndex = ((gun_index==2) ? 1: 0);
  6972. }
  6973. else
  6974. {
  6975. tempIndex = gun_index;
  6976. }
  6977. for (int index = 0; index < CCS_QUANTITY; index++)
  6978. {
  6979. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6980. {
  6981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6982. }
  6983. }
  6984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6985. }
  6986. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6987. {
  6988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6989. {
  6990. tempIndex = ((gun_index==2) ? 1: 0);
  6991. }
  6992. else
  6993. {
  6994. tempIndex = gun_index;
  6995. }
  6996. for (int index = 0; index < GB_QUANTITY; index++)
  6997. {
  6998. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6999. {
  7000. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7001. }
  7002. }
  7003. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7004. }
  7005. else if(gunType[gun_index] == GUN_TYPE_DO)
  7006. {
  7007. tempIndex = gun_index;
  7008. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7009. {
  7010. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7011. {
  7012. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7013. }
  7014. }
  7015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7016. }
  7017. else
  7018. {
  7019. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7020. {
  7021. tempIndex = 2;
  7022. }
  7023. else
  7024. {
  7025. tempIndex = gun_index;
  7026. }
  7027. for (int index = 0; index < AC_QUANTITY; index++)
  7028. {
  7029. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7030. {
  7031. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7032. }
  7033. }
  7034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7035. }
  7036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7041. }
  7042. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7043. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7044. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7045. (dataType == ReadingContext_Trigger))
  7046. {
  7047. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7049. {
  7050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7051. {
  7052. tempIndex = ((gun_index==2) ? 1: 0);
  7053. }
  7054. else
  7055. {
  7056. tempIndex = gun_index;
  7057. }
  7058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7059. {
  7060. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7061. {
  7062. if(dataType == ReadingContext_Sample_Clock)
  7063. {
  7064. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7065. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7066. }
  7067. else if(dataType == ReadingContext_Sample_Periodic)
  7068. {
  7069. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7070. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7071. }
  7072. else
  7073. {
  7074. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7075. }
  7076. }
  7077. } // END OF FOR CHAdeMO_QUANTITY
  7078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7079. }
  7080. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7081. {
  7082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7083. {
  7084. tempIndex = ((gun_index==2) ? 1: 0);
  7085. }
  7086. else
  7087. {
  7088. tempIndex = gun_index;
  7089. }
  7090. for (int index = 0; index < CCS_QUANTITY; index++)
  7091. {
  7092. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7093. {
  7094. if(dataType == ReadingContext_Sample_Clock)
  7095. {
  7096. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7097. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7098. }
  7099. else if(dataType == ReadingContext_Sample_Periodic)
  7100. {
  7101. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7102. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7103. }
  7104. else
  7105. {
  7106. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7107. }
  7108. }
  7109. } // END OF CCS_QUANTITY
  7110. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7111. }
  7112. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7113. {
  7114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7115. {
  7116. tempIndex = ((gun_index==2) ? 1: 0);
  7117. }
  7118. else
  7119. {
  7120. tempIndex = gun_index;
  7121. }
  7122. for (int index = 0; index < GB_QUANTITY; index++)
  7123. {
  7124. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7125. {
  7126. if(dataType == ReadingContext_Sample_Clock)
  7127. {
  7128. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7129. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7130. }
  7131. else if(dataType == ReadingContext_Sample_Periodic)
  7132. {
  7133. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7134. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7135. }
  7136. else
  7137. {
  7138. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7139. }
  7140. }
  7141. } // END OF GB_QUANTITY
  7142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7143. }
  7144. else if(gunType[gun_index] == GUN_TYPE_DO)
  7145. {
  7146. tempIndex = gun_index;
  7147. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7148. {
  7149. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7150. {
  7151. if(dataType == ReadingContext_Sample_Clock)
  7152. {
  7153. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7154. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7155. }
  7156. else if(dataType == ReadingContext_Sample_Periodic)
  7157. {
  7158. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7159. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7160. }
  7161. else
  7162. {
  7163. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7164. }
  7165. }
  7166. }
  7167. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7168. }
  7169. else
  7170. {
  7171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7172. {
  7173. tempIndex = 2;
  7174. }
  7175. else
  7176. {
  7177. tempIndex = gun_index;
  7178. }
  7179. for (int index = 0; index < AC_QUANTITY; index++)
  7180. {
  7181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7182. {
  7183. if(dataType == ReadingContext_Sample_Clock)
  7184. {
  7185. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7186. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7187. }
  7188. else if(dataType == ReadingContext_Sample_Periodic)
  7189. {
  7190. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7191. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7192. }
  7193. else
  7194. {
  7195. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7196. }
  7197. }
  7198. }
  7199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7200. }
  7201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7206. }
  7207. //********************************(4)Power.Active.Import************************************************/
  7208. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7209. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7210. (dataType == ReadingContext_Trigger))
  7211. {
  7212. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7213. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7214. {
  7215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7216. {
  7217. tempIndex = ((gun_index==2) ? 1: 0);
  7218. }
  7219. else
  7220. {
  7221. tempIndex = gun_index;
  7222. }
  7223. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7224. {
  7225. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7226. {
  7227. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7228. }
  7229. } // END OF FOR
  7230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7231. }
  7232. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7233. {
  7234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7235. {
  7236. tempIndex = ((gun_index==2) ? 1: 0);
  7237. }
  7238. else
  7239. {
  7240. tempIndex = gun_index;
  7241. }
  7242. for (int index = 0; index < CCS_QUANTITY; index++)
  7243. {
  7244. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7245. {
  7246. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7247. }
  7248. }
  7249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7250. }
  7251. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7252. {
  7253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7254. {
  7255. tempIndex = ((gun_index==2) ? 1: 0);
  7256. }
  7257. else
  7258. {
  7259. tempIndex = gun_index;
  7260. }
  7261. for (int index = 0; index < GB_QUANTITY; index++)
  7262. {
  7263. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7264. {
  7265. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7266. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7267. }
  7268. }
  7269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7270. }
  7271. else if(gunType[gun_index] == GUN_TYPE_DO)
  7272. {
  7273. tempIndex = gun_index;
  7274. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7275. {
  7276. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7277. {
  7278. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7279. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7280. }
  7281. }
  7282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7283. }
  7284. else
  7285. {
  7286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7287. {
  7288. tempIndex = 2;
  7289. }
  7290. else
  7291. {
  7292. tempIndex = gun_index;
  7293. }
  7294. for (int index = 0; index < AC_QUANTITY; index++)
  7295. {
  7296. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7297. {
  7298. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7299. }
  7300. }
  7301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7302. }
  7303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7305. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7308. }
  7309. //***********************************************(5)VOLTAGE L1******************************************************/
  7310. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7311. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7312. (dataType == ReadingContext_Trigger))
  7313. {
  7314. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7315. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7316. {
  7317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7318. {
  7319. tempIndex = ((gun_index==2) ? 1: 0);
  7320. }
  7321. else
  7322. {
  7323. tempIndex = gun_index;
  7324. }
  7325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7326. {
  7327. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7328. {
  7329. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7330. }
  7331. }
  7332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7333. }
  7334. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7335. {
  7336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7337. {
  7338. tempIndex = ((gun_index==2) ? 1: 0);
  7339. }
  7340. else
  7341. {
  7342. tempIndex = gun_index;
  7343. }
  7344. for (int index = 0; index < CCS_QUANTITY; index++)
  7345. {
  7346. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7347. {
  7348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7349. }
  7350. }
  7351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7352. }
  7353. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7354. {
  7355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7356. {
  7357. tempIndex = ((gun_index==2) ? 1: 0);
  7358. }
  7359. else
  7360. {
  7361. tempIndex = gun_index;
  7362. }
  7363. for (int index = 0; index < GB_QUANTITY; index++)
  7364. {
  7365. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7366. {
  7367. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7368. }
  7369. }
  7370. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7371. }
  7372. else if(gunType[gun_index] == GUN_TYPE_DO)
  7373. {
  7374. tempIndex = gun_index;
  7375. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7376. {
  7377. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7378. {
  7379. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7380. }
  7381. }
  7382. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7383. }
  7384. else
  7385. {
  7386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7387. {
  7388. tempIndex = 2;
  7389. }
  7390. else
  7391. {
  7392. tempIndex = gun_index;
  7393. }
  7394. for (int index = 0; index < AC_QUANTITY; index++)
  7395. {
  7396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7397. {
  7398. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7399. }
  7400. }
  7401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7402. }
  7403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7408. }
  7409. //***********************************************(6)SOC******************************************************/
  7410. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7411. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7412. (dataType == ReadingContext_Trigger))
  7413. {
  7414. 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))
  7415. {
  7416. //idx_sample=5;
  7417. //sampledValue = NULL;
  7418. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7419. {
  7420. tempIndex = ((gun_index==2) ? 1: 0);
  7421. }
  7422. else
  7423. {
  7424. tempIndex = gun_index;
  7425. }
  7426. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7427. {
  7428. //tempIndex = ((gun_index==2) ? 1: 0);
  7429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7430. {
  7431. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7432. {
  7433. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7434. }
  7435. }
  7436. }
  7437. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7438. {
  7439. //tempIndex = ((gun_index==2) ? 1: 0);
  7440. for (int index = 0; index < CCS_QUANTITY; index++)
  7441. {
  7442. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7443. {
  7444. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7445. }
  7446. }
  7447. }
  7448. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7449. {
  7450. //tempIndex = ((gun_index==2) ? 1: 0);
  7451. for (int index = 0; index < GB_QUANTITY; index++)
  7452. {
  7453. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7454. {
  7455. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7456. }
  7457. }
  7458. }
  7459. else if(gunType[gun_index] == GUN_TYPE_DO)
  7460. {
  7461. //tempIndex = ((gun_index==2) ? 1: 0);
  7462. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7463. {
  7464. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7465. {
  7466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7467. }
  7468. }
  7469. }
  7470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7476. }
  7477. }
  7478. //********************************(7)Current.Import L2************************************************/
  7479. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7480. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7481. (dataType == ReadingContext_Trigger))
  7482. {
  7483. // Only for AC 3 phase
  7484. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7485. {
  7486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7487. {
  7488. tempIndex = 2;
  7489. }
  7490. else
  7491. {
  7492. tempIndex = gun_index;
  7493. }
  7494. for (int index = 0; index < AC_QUANTITY; index++)
  7495. {
  7496. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7497. {
  7498. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7499. }
  7500. }
  7501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7502. }
  7503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7508. }
  7509. //********************************(8)Current.Import L3************************************************/
  7510. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7511. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7512. (dataType == ReadingContext_Trigger))
  7513. {
  7514. // Only for AC 3 phase
  7515. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7516. {
  7517. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7518. {
  7519. tempIndex = 2;
  7520. }
  7521. else
  7522. {
  7523. tempIndex = gun_index;
  7524. }
  7525. for (int index = 0; index < AC_QUANTITY; index++)
  7526. {
  7527. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7528. {
  7529. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7530. }
  7531. }
  7532. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7533. }
  7534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7538. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7539. }
  7540. //***********************************************(9)VOLTAGE L2******************************************************/
  7541. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7542. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7543. (dataType == ReadingContext_Trigger))
  7544. {
  7545. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7546. {
  7547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7548. {
  7549. tempIndex = 2;
  7550. }
  7551. else
  7552. {
  7553. tempIndex = gun_index;
  7554. }
  7555. for (int index = 0; index < AC_QUANTITY; index++)
  7556. {
  7557. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7558. {
  7559. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7560. }
  7561. }
  7562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7563. }
  7564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7568. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7569. }
  7570. //***********************************************(10)VOLTAGE L3******************************************************/
  7571. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7572. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7573. (dataType == ReadingContext_Trigger))
  7574. {
  7575. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7576. {
  7577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7578. {
  7579. tempIndex = 2;
  7580. }
  7581. else
  7582. {
  7583. tempIndex = gun_index;
  7584. }
  7585. for (int index = 0; index < AC_QUANTITY; index++)
  7586. {
  7587. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7588. {
  7589. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7590. }
  7591. }
  7592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7593. }
  7594. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7595. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7596. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7598. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7599. }
  7600. //***********************************************(11)Current.Offered******************************************************/
  7601. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7602. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7603. (dataType == ReadingContext_Trigger))
  7604. {
  7605. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7606. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7607. {
  7608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7609. {
  7610. tempIndex = ((gun_index==2) ? 1: 0);
  7611. }
  7612. else
  7613. {
  7614. tempIndex = gun_index;
  7615. }
  7616. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7617. {
  7618. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7619. {
  7620. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7621. }
  7622. } // END OF FOR CHAdeMO_QUANTITY
  7623. }
  7624. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7625. {
  7626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7627. {
  7628. tempIndex = ((gun_index==2) ? 1: 0);
  7629. }
  7630. else
  7631. {
  7632. tempIndex = gun_index;
  7633. }
  7634. for (int index = 0; index < CCS_QUANTITY; index++)
  7635. {
  7636. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7637. {
  7638. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7639. }
  7640. } // END OF CCS_QUANTITY
  7641. }
  7642. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7643. {
  7644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7645. {
  7646. tempIndex = ((gun_index==2) ? 1: 0);
  7647. }
  7648. else
  7649. {
  7650. tempIndex = gun_index;
  7651. }
  7652. for (int index = 0; index < GB_QUANTITY; index++)
  7653. {
  7654. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7655. {
  7656. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7657. }
  7658. } // END OF GB_QUANTITY
  7659. }
  7660. else if(gunType[gun_index] == GUN_TYPE_DO)
  7661. {
  7662. tempIndex = gun_index;
  7663. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7664. {
  7665. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7666. {
  7667. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7668. }
  7669. }
  7670. }
  7671. else
  7672. {
  7673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7674. {
  7675. tempIndex = 2;
  7676. }
  7677. else
  7678. {
  7679. tempIndex = gun_index;
  7680. }
  7681. for (int index = 0; index < AC_QUANTITY; index++)
  7682. {
  7683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7684. {
  7685. uint16_t currentOffer;
  7686. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7687. {
  7688. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7689. }
  7690. else
  7691. {
  7692. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7693. }
  7694. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7695. }
  7696. }
  7697. }
  7698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7699. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7700. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7703. }
  7704. //***********************************************(12)Power.Offered******************************************************/
  7705. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7706. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7707. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7708. {
  7709. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7710. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7711. {
  7712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7713. {
  7714. tempIndex = ((gun_index==2) ? 1: 0);
  7715. }
  7716. else
  7717. {
  7718. tempIndex = gun_index;
  7719. }
  7720. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7721. {
  7722. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7723. {
  7724. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7725. }
  7726. } // END OF FOR CHAdeMO_QUANTITY
  7727. }
  7728. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7729. {
  7730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7731. {
  7732. tempIndex = ((gun_index==2) ? 1: 0);
  7733. }
  7734. else
  7735. {
  7736. tempIndex = gun_index;
  7737. }
  7738. for (int index = 0; index < CCS_QUANTITY; index++)
  7739. {
  7740. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7741. {
  7742. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7743. }
  7744. } // END OF CCS_QUANTITY
  7745. }
  7746. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7747. {
  7748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7749. {
  7750. tempIndex = ((gun_index==2) ? 1: 0);
  7751. }
  7752. else
  7753. {
  7754. tempIndex = gun_index;
  7755. }
  7756. for (int index = 0; index < GB_QUANTITY; index++)
  7757. {
  7758. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7759. {
  7760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7761. }
  7762. } // END OF GB_QUANTITY
  7763. }
  7764. else if(gunType[gun_index] == GUN_TYPE_DO)
  7765. {
  7766. tempIndex = gun_index;
  7767. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7768. {
  7769. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7770. {
  7771. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7772. }
  7773. }
  7774. }
  7775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7776. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7777. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7778. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7779. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7780. }
  7781. // Message create ====================================================================================================
  7782. if(TRUE)
  7783. {
  7784. json_object *MeterValueReq = json_object_new_object();
  7785. json_object *MeterValues = json_object_new_array();
  7786. json_object *sampledValues = json_object_new_array();
  7787. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7788. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7789. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7790. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7791. {
  7792. json_object *MeterValue = json_object_new_object();
  7793. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7794. {
  7795. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7796. {
  7797. json_object *sampledValue = json_object_new_object();
  7798. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7799. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7800. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7801. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7802. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7803. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7804. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7805. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7806. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7807. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7808. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7809. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7810. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7811. json_object_array_add(sampledValues, sampledValue);
  7812. }
  7813. }
  7814. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7815. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7816. json_object_array_add(MeterValues, MeterValue);
  7817. }
  7818. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7819. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7820. ,gun_index + 1
  7821. ,MESSAGE_TYPE_CALL
  7822. ,guid
  7823. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7824. json_object_put(MeterValueReq);
  7825. }
  7826. // Put request guid to hash map
  7827. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7828. 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*/)
  7829. {
  7830. result = PASS;
  7831. //DEBUG_INFO("MeterValues mapitem pass\n");
  7832. }
  7833. if((dataType != ReadingContext_Trigger) &&
  7834. (dataType != ReadingContext_Sample_Clock) &&
  7835. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7836. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7837. else
  7838. {
  7839. if(FirstHeartBeat)
  7840. LWS_Send(queuedata +2);
  7841. }
  7842. return result;
  7843. }
  7844. int sendLogStatusNotificationRequest(char *status)
  7845. {
  7846. mtrace();
  7847. int result = PASS;
  7848. char message[4096]={0};
  7849. char guid[37]={0};
  7850. char tempdata[128]={0};
  7851. json_object *LogStatusNotification = json_object_new_object();
  7852. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7853. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7854. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7855. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7856. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7857. random_uuid(guid);
  7858. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7859. json_object_put(LogStatusNotification);
  7860. LWS_Send(message);
  7861. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7862. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7863. {
  7864. result = PASS;
  7865. }
  7866. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7867. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7868. return result;
  7869. }
  7870. int sendSecurityEventNotificationRequest()
  7871. {
  7872. mtrace();
  7873. int result = PASS;
  7874. char message[4096]={0};
  7875. char guid[37]={0};
  7876. char tempdata[128]={0};
  7877. json_object *SecurityEventNotification = json_object_new_object();
  7878. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7879. //Stop Transaction Time
  7880. struct timeval tmnow;
  7881. struct tm *tm;
  7882. gettimeofday(&tmnow, NULL);
  7883. time_t t;
  7884. t = time(NULL);
  7885. /*UTC time and date*/
  7886. tm = gmtime(&t);
  7887. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7888. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7889. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7890. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7891. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7892. random_uuid(guid);
  7893. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7894. json_object_put(SecurityEventNotification);
  7895. LWS_Send(message);
  7896. sprintf(tempdata, "SecurityEventNotification,0");
  7897. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7898. {
  7899. result = PASS;
  7900. }
  7901. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7902. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7903. return result;
  7904. }
  7905. int sendSignCertificateRequest()
  7906. {
  7907. mtrace();
  7908. int result = PASS;
  7909. char message[4096]={0};
  7910. char guid[37]={0};
  7911. char tempdata[128]={0};
  7912. json_object *SignCertificate = json_object_new_object();
  7913. DEBUG_INFO("sendSignCertificateRequest...\n");
  7914. // Read csr file content
  7915. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7916. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7917. char *line = NULL;
  7918. size_t len = 0;
  7919. while(getline(&line, &len, fp) != -1)
  7920. {
  7921. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7922. {
  7923. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7924. }
  7925. }
  7926. fclose(fp);
  7927. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7928. random_uuid(guid);
  7929. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7930. json_object_put(SignCertificate);
  7931. LWS_Send(message);
  7932. sprintf(tempdata, "SignCertificate,0");
  7933. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7934. {
  7935. result = PASS;
  7936. }
  7937. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7938. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7939. return result;
  7940. }
  7941. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7942. {
  7943. mtrace();
  7944. int result = PASS;
  7945. char message[4096]={0};
  7946. char guid[37]={0};
  7947. char tempdata[128]={0};
  7948. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  7949. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7950. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7951. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7952. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7953. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7954. random_uuid(guid);
  7955. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7956. json_object_put(SignedFirmwareStatusNotification);
  7957. LWS_Send(message);
  7958. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  7959. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7960. {
  7961. result = PASS;
  7962. }
  7963. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7964. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7965. return result;
  7966. }
  7967. //==========================================
  7968. // send confirm routine
  7969. //==========================================
  7970. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7971. {
  7972. mtrace();
  7973. int result = FAIL;
  7974. char message[100]={0};
  7975. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7976. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7977. LWS_Send(message);
  7978. result = TRUE;
  7979. return result;
  7980. }
  7981. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7982. {
  7983. mtrace();
  7984. int result = FAIL;
  7985. char message[100]={0};
  7986. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7987. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7988. LWS_Send(message);
  7989. result = TRUE;
  7990. return result;
  7991. }
  7992. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7993. {
  7994. mtrace();
  7995. int result = FAIL;
  7996. char message[100]={0};
  7997. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7999. LWS_Send(message);
  8000. result = TRUE;
  8001. return result;
  8002. }
  8003. int sendClearCacheConfirmation(char *uuid,char *payload)
  8004. {
  8005. mtrace();
  8006. int result = FAIL;
  8007. char message[500]={0};
  8008. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8009. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8010. LWS_Send(message);
  8011. return result;
  8012. }
  8013. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8014. {
  8015. mtrace();
  8016. int result = FAIL;
  8017. char message[500]={0};
  8018. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8019. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8020. LWS_Send(message);
  8021. return result;
  8022. }
  8023. int sendDataTransferConfirmation(char *uuid,char *payload)
  8024. {
  8025. mtrace();
  8026. char statusStr[20]={0};
  8027. char dataStr[10]={0};
  8028. char sstr[20]={0};
  8029. int c = 0;
  8030. char *loc;
  8031. int result = FAIL;
  8032. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8033. /**********************status**************************/
  8034. loc = strstr(payload, "status");
  8035. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8036. c = 0;
  8037. while (loc[3+strlen("status")+c] != '\"')
  8038. {
  8039. sstr[c] = loc[3+strlen("status")+c];
  8040. c++;
  8041. }
  8042. sstr[c] = '\0';
  8043. strcpy(statusStr, sstr);
  8044. /**********************data**************************/
  8045. loc = strstr(payload, "data");
  8046. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8047. c = 0;
  8048. while (loc[3+strlen("data")+c] != '\"')
  8049. {
  8050. sstr[c] = loc[3+strlen("data")+c];
  8051. c++;
  8052. }
  8053. sstr[c] = '\0';
  8054. strcpy(dataStr, sstr);
  8055. return result;
  8056. }
  8057. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8058. {
  8059. mtrace();
  8060. int result = FAIL;
  8061. char message[1000]={0};
  8062. int CompositeScheduleIndex = 0;
  8063. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8064. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8065. if(nPeriod == 0)
  8066. {
  8067. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8068. {
  8069. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8070. ,MESSAGE_TYPE_CALLRESULT
  8071. ,uuid
  8072. ,payload
  8073. ,connectorIdInt);
  8074. }
  8075. else
  8076. {
  8077. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8078. ,MESSAGE_TYPE_CALLRESULT
  8079. ,uuid
  8080. ,payload
  8081. ,connectorIdInt
  8082. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8083. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8084. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8085. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8086. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8087. }
  8088. }
  8089. else
  8090. {
  8091. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8092. ,MESSAGE_TYPE_CALLRESULT
  8093. ,uuid
  8094. ,payload
  8095. ,connectorIdInt
  8096. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8097. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8098. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8099. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8100. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8101. {
  8102. if (idx_sample == 0)
  8103. {
  8104. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8105. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8106. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8107. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8108. }
  8109. else
  8110. {
  8111. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8112. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8113. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8114. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8115. }
  8116. }
  8117. sprintf(message + strlen(message), "]}}]");
  8118. }
  8119. LWS_Send(message);
  8120. result = TRUE;
  8121. return result;
  8122. }
  8123. int sendGetConfigurationConfirmation(char *uuid)
  8124. {
  8125. mtrace();
  8126. int result = FAIL;
  8127. int MaxKeySupported = 0;
  8128. int sentConfigurationNumber= 0;
  8129. int sentunConfigurationNumber= 0;
  8130. char message[1024*10]={0};
  8131. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8132. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8133. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8134. ,MESSAGE_TYPE_CALLRESULT
  8135. ,uuid );
  8136. //configuration key
  8137. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8138. {
  8139. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8140. {
  8141. if (sentConfigurationNumber == 0)
  8142. {
  8143. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8144. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8145. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8146. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8147. }
  8148. else
  8149. {
  8150. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8151. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8152. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8153. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8154. }
  8155. sentConfigurationNumber = sentConfigurationNumber + 1;
  8156. }
  8157. }
  8158. sprintf(message + strlen(message), "]");
  8159. if(UnknownKeynum != 0)
  8160. {
  8161. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8162. //unkown key
  8163. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8164. {
  8165. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8166. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8167. if(sentunConfigurationNumber == 0)
  8168. {
  8169. sprintf(message + strlen(message), "\"%s\""
  8170. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8171. }
  8172. else
  8173. {
  8174. sprintf(message + strlen(message), ",\"%s\""
  8175. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8176. }
  8177. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8178. }
  8179. sprintf(message + strlen(message), "]");
  8180. }
  8181. sprintf(message + strlen(message), "}]");
  8182. LWS_Send(message);
  8183. return result;
  8184. }
  8185. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8186. {
  8187. mtrace();
  8188. int result = FAIL;
  8189. char message[400]={0};
  8190. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8191. if(strcmp(payload,"")==0)
  8192. {
  8193. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8194. }
  8195. else
  8196. {
  8197. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8198. }
  8199. LWS_Send(message);
  8200. result = TRUE;
  8201. return result;
  8202. }
  8203. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8204. {
  8205. mtrace();
  8206. int result = FAIL;
  8207. char message[80]={0};
  8208. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8209. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8210. LWS_Send(message);
  8211. result = TRUE;
  8212. return result;
  8213. }
  8214. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8215. {
  8216. mtrace();
  8217. int result = FAIL;
  8218. char message[80]={0};
  8219. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8220. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8221. LWS_Send(message);
  8222. result = TRUE;
  8223. return result;
  8224. }
  8225. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8226. {
  8227. mtrace();
  8228. int result = FAIL;
  8229. char message[80]={0};
  8230. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8231. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8232. LWS_Send(message);
  8233. result = TRUE;
  8234. return result;
  8235. }
  8236. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8237. {
  8238. mtrace();
  8239. int result = FAIL;
  8240. char message[80]={0};
  8241. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8242. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8243. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8244. LWS_Send(message);
  8245. result = TRUE;
  8246. return result;
  8247. }
  8248. int sendResetConfirmation(char *uuid,char *payload)
  8249. {
  8250. mtrace();
  8251. int result = FAIL;
  8252. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8253. char message[80]={0};
  8254. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8255. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8256. LWS_Send(message);
  8257. result = TRUE;
  8258. return result;
  8259. }
  8260. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8261. {
  8262. mtrace();
  8263. int result = FAIL;
  8264. char message[500]={0};
  8265. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8266. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8267. LWS_Send(message);
  8268. result = TRUE;
  8269. return result;
  8270. }
  8271. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8272. {
  8273. mtrace();
  8274. int result = FAIL;
  8275. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8276. char message[80]={0};
  8277. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8278. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8279. LWS_Send(message);
  8280. result = TRUE;
  8281. return result;
  8282. }
  8283. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8284. {
  8285. mtrace();
  8286. int result = FAIL;
  8287. char message[80]={0};
  8288. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8289. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8290. LWS_Send(message);
  8291. result = TRUE;
  8292. return result;
  8293. }
  8294. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8295. {
  8296. mtrace();
  8297. int result = FAIL;
  8298. char message[80]={0};
  8299. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8300. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8301. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8302. LWS_Send(message);
  8303. result = TRUE;
  8304. return result;
  8305. }
  8306. int sendUpdateFirmwareConfirmation(char *uuid)
  8307. {
  8308. mtrace();
  8309. int result = FAIL;
  8310. char message[60]={0};
  8311. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8312. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8313. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8314. LWS_Send(message);
  8315. result = TRUE;
  8316. return result;
  8317. }
  8318. int sendCertificateSignedConfirmation(char *uuid)
  8319. {
  8320. mtrace();
  8321. int result = PASS;
  8322. char message[4096]={0};
  8323. json_object *CertificateSigned = json_object_new_object();
  8324. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8325. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8326. sprintf(message,"[%d,\"%s\",%s]"
  8327. ,MESSAGE_TYPE_CALLRESULT
  8328. ,uuid
  8329. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8330. json_object_put(CertificateSigned);
  8331. LWS_Send(message);
  8332. return result;
  8333. }
  8334. int sendDeleteCertificateConfirmation(char *uuid)
  8335. {
  8336. mtrace();
  8337. int result = PASS;
  8338. char message[4096]={0};
  8339. json_object *DeleteCertificate = json_object_new_object();
  8340. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8341. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8342. sprintf(message,"[%d,\"%s\",%s]"
  8343. ,MESSAGE_TYPE_CALLRESULT
  8344. ,uuid
  8345. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8346. json_object_put(DeleteCertificate);
  8347. LWS_Send(message);
  8348. return result;
  8349. }
  8350. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8351. {
  8352. mtrace();
  8353. int result = PASS;
  8354. char message[4096]={0};
  8355. json_object *ExtendedTriggerMessage = json_object_new_object();
  8356. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8357. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8358. sprintf(message,"[%d,\"%s\",%s]"
  8359. ,MESSAGE_TYPE_CALLRESULT
  8360. ,uuid
  8361. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8362. json_object_put(ExtendedTriggerMessage);
  8363. LWS_Send(message);
  8364. return result;
  8365. }
  8366. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8367. {
  8368. mtrace();
  8369. int result = PASS;
  8370. char message[4096]={0};
  8371. json_object *GetInstalledCertificateIds = json_object_new_object();
  8372. json_object *certificateHashDataDatas = json_object_new_array();
  8373. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8374. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8375. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8376. {
  8377. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8378. {
  8379. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8380. {
  8381. json_object *certificateHashData = json_object_new_object();
  8382. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8383. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8384. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8385. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8386. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8387. }
  8388. }
  8389. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8390. }
  8391. else
  8392. {
  8393. json_object_put(certificateHashDataDatas);
  8394. }
  8395. sprintf(message,"[%d,\"%s\",%s]"
  8396. ,MESSAGE_TYPE_CALLRESULT
  8397. ,uuid
  8398. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8399. json_object_put(GetInstalledCertificateIds);
  8400. LWS_Send(message);
  8401. return result;
  8402. }
  8403. int sendGetLogConfirmation(char *uuid)
  8404. {
  8405. mtrace();
  8406. int result = PASS;
  8407. char message[4096]={0};
  8408. json_object *GetLog = json_object_new_object();
  8409. DEBUG_INFO("sendGetLogConfirmation...\n");
  8410. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8411. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8412. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8413. sprintf(message,"[%d,\"%s\",%s]"
  8414. ,MESSAGE_TYPE_CALLRESULT
  8415. ,uuid
  8416. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8417. json_object_put(GetLog);
  8418. LWS_Send(message);
  8419. return result;
  8420. }
  8421. int sendInstallCertificateConfirmation(char *uuid)
  8422. {
  8423. mtrace();
  8424. int result = PASS;
  8425. char message[4096]={0};
  8426. json_object *InstallCertificate = json_object_new_object();
  8427. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8428. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8429. sprintf(message,"[%d,\"%s\",%s]"
  8430. ,MESSAGE_TYPE_CALLRESULT
  8431. ,uuid
  8432. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8433. json_object_put(InstallCertificate);
  8434. LWS_Send(message);
  8435. return result;
  8436. }
  8437. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8438. {
  8439. mtrace();
  8440. int result = PASS;
  8441. char message[4096]={0};
  8442. json_object *SignedUpdateFirmware = json_object_new_object();
  8443. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8444. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8445. sprintf(message,"[%d,\"%s\",%s]"
  8446. ,MESSAGE_TYPE_CALLRESULT
  8447. ,uuid
  8448. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8449. json_object_put(SignedUpdateFirmware);
  8450. LWS_Send(message);
  8451. return result;
  8452. }
  8453. int sendUnknownConfirmation(char *uuid)
  8454. {
  8455. mtrace();
  8456. int result = PASS;
  8457. char message[256]={0};
  8458. DEBUG_INFO("sendUnknownConfirmation...\n");
  8459. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8460. LWS_Send(message);
  8461. return result;
  8462. }
  8463. //==========================================
  8464. // Handle server request routine Start
  8465. //==========================================
  8466. int handleCancelReservationRequest(char *uuid, char *payload)
  8467. {
  8468. mtrace();
  8469. int result = FAIL;
  8470. int gunNO = 0;
  8471. int reservationIdInt = -1;
  8472. char comfirmstr[20];
  8473. DEBUG_INFO("handleCancelReservationRequest...\n");
  8474. json_object *CancelReservation;
  8475. CancelReservation = json_tokener_parse(payload);
  8476. if(!is_error(CancelReservation))
  8477. {
  8478. // Required data
  8479. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8480. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8481. }
  8482. json_object_put(CancelReservation);
  8483. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8484. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8485. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8486. if(reservationIdInt != -1)
  8487. {
  8488. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8489. //check Transaction active
  8490. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8491. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8492. {
  8493. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8494. {
  8495. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8496. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8497. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8498. {
  8499. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8500. }
  8501. else
  8502. {
  8503. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8504. }
  8505. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8506. goto end;
  8507. }
  8508. }
  8509. for (int index = 0; index < CCS_QUANTITY; index++)
  8510. {
  8511. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8512. {
  8513. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8514. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8515. if(gunType[2] == GUN_TYPE_CCS)
  8516. {
  8517. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8518. }
  8519. else
  8520. {
  8521. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8522. }
  8523. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8524. goto end;
  8525. }
  8526. }
  8527. for (int index = 0; index < GB_QUANTITY; index++)
  8528. {
  8529. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8530. {
  8531. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8532. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8533. if(gunType[2] == GUN_TYPE_GBT)
  8534. {
  8535. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8536. }
  8537. else
  8538. {
  8539. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8540. }
  8541. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8542. goto end;
  8543. }
  8544. }
  8545. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8546. {
  8547. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8548. {
  8549. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8550. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8551. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8552. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8553. goto end;
  8554. }
  8555. }
  8556. for (int index = 0; index < AC_QUANTITY; index++)
  8557. {
  8558. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8559. {
  8560. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8561. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8562. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8563. {
  8564. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8565. }
  8566. else
  8567. {
  8568. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8569. }
  8570. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8571. goto end;
  8572. }
  8573. }
  8574. }
  8575. //The reservationId does NOT match the reservationId
  8576. sendCancelReservationConfirmation(uuid, comfirmstr);
  8577. end:
  8578. // Fill in ocpp packet uuid
  8579. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8580. return result;
  8581. }
  8582. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8583. {
  8584. mtrace();
  8585. int result = FAIL;
  8586. int gunIndex = -1;
  8587. char typeStr[16]={0};
  8588. char comfirmstr[20];
  8589. int specificId = FALSE;
  8590. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8591. json_object *ChangeAvailability;
  8592. ChangeAvailability = json_tokener_parse(payload);
  8593. if(!is_error(ChangeAvailability))
  8594. {
  8595. // Required data
  8596. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8597. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8598. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8599. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8600. }
  8601. json_object_put(ChangeAvailability);
  8602. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8603. {
  8604. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8605. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8606. }
  8607. else if(gunIndex == 0)
  8608. {
  8609. for(int i=0; i < gunTotalNumber; i++)
  8610. {
  8611. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8612. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8613. }
  8614. }
  8615. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8616. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8617. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8618. {
  8619. specificId = TRUE;
  8620. }
  8621. if(specificId == FALSE)
  8622. goto end;
  8623. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8624. {
  8625. //----------------------gunIndex is 0 ------------------------------------------------//
  8626. if(gunIndex == 0)
  8627. {
  8628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8629. {
  8630. for(int i=0; i < gunTotalNumber; i++)
  8631. {
  8632. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8633. {
  8634. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8635. {
  8636. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8637. {
  8638. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8639. goto end;
  8640. }
  8641. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8642. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8643. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8644. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8645. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8646. {
  8647. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8648. goto end;
  8649. }
  8650. }
  8651. }//END FOR CHAdeMO_QUANTITY
  8652. for (int index = 0; index < CCS_QUANTITY; index++)
  8653. {
  8654. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8655. {
  8656. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8657. {
  8658. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8659. goto end;
  8660. }
  8661. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8662. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8663. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8664. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8665. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8666. {
  8667. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8668. goto end;
  8669. }
  8670. }
  8671. }//END FOR CCS_QUANTITY
  8672. for (int index = 0; index < GB_QUANTITY; index++)
  8673. {
  8674. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8675. {
  8676. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8677. {
  8678. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8679. goto end;
  8680. }
  8681. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8682. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8683. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8684. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8685. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8686. {
  8687. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8688. goto end;
  8689. }
  8690. }
  8691. }// END FOR GB_QUANTITY
  8692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8693. {
  8694. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8695. {
  8696. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8697. {
  8698. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8699. goto end;
  8700. }
  8701. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8702. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8703. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8704. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8705. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8706. {
  8707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8708. goto end;
  8709. }
  8710. }
  8711. }// END FOR GENERAL_GUN_QUANTITY
  8712. for (int index = 0; index < AC_QUANTITY; index++)
  8713. {
  8714. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8715. {
  8716. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8717. {
  8718. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8719. goto end;
  8720. }
  8721. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8722. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8723. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8724. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8725. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8726. {
  8727. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8728. goto end;
  8729. }
  8730. }
  8731. }//END FOR AC_QUANTITY
  8732. }// END FOR gunTotalNumber
  8733. }
  8734. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8735. {
  8736. for(int i=0; i < gunTotalNumber; i++)
  8737. {
  8738. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8739. {
  8740. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8741. goto end;
  8742. }
  8743. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8744. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8745. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8746. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8747. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8748. {
  8749. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8750. goto end;
  8751. }
  8752. }
  8753. }
  8754. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8755. goto end;
  8756. }
  8757. //----------------------gunIndex is not 0 ------------------------------------------------//
  8758. //check Transaction active
  8759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8760. {
  8761. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8762. {
  8763. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8764. {
  8765. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8766. goto end;
  8767. }
  8768. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8769. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8770. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8771. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8772. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8773. {
  8774. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8775. goto end;
  8776. }
  8777. else
  8778. {
  8779. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8780. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8781. goto end;
  8782. }
  8783. }
  8784. }//END FOR CHAdeMO_QUANTITY
  8785. for (int index = 0; index < CCS_QUANTITY; index++)
  8786. {
  8787. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8788. {
  8789. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8790. {
  8791. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8792. goto end;
  8793. }
  8794. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8795. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8796. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8797. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8798. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8799. {
  8800. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8801. goto end;
  8802. }
  8803. else
  8804. {
  8805. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8806. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8807. goto end;
  8808. }
  8809. }
  8810. }//END FOR CCS_QUANTITY
  8811. for (int index = 0; index < GB_QUANTITY; index++)
  8812. {
  8813. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8814. {
  8815. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8816. {
  8817. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8818. goto end;
  8819. }
  8820. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8821. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8822. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8823. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8824. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8825. {
  8826. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8827. goto end;
  8828. }
  8829. else
  8830. {
  8831. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8832. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8833. goto end;
  8834. }
  8835. }
  8836. }// END FOR GB_QUANTITY
  8837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8838. {
  8839. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8840. {
  8841. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8842. {
  8843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8844. goto end;
  8845. }
  8846. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8847. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8848. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8849. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8850. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8851. {
  8852. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8853. goto end;
  8854. }
  8855. else
  8856. {
  8857. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8858. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8859. goto end;
  8860. }
  8861. }
  8862. }// END FOR GENERAL_GUN_QUANTITY
  8863. for (int index = 0; index < AC_QUANTITY; index++)
  8864. {
  8865. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8866. {
  8867. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8868. {
  8869. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8870. goto end;
  8871. }
  8872. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8873. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8874. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8875. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8876. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8877. {
  8878. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8879. goto end;
  8880. }
  8881. else
  8882. {
  8883. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8884. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8885. goto end;
  8886. }
  8887. }
  8888. }//END FOR AC_QUANTITY
  8889. }//END FOR AvailabilityTypeStr[Inoperative]
  8890. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8891. {
  8892. //----------------------gunIndex is 0 ------------------------------------------------//
  8893. if(gunIndex == 0)
  8894. {
  8895. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8896. {
  8897. for(int i=0; i < gunTotalNumber; i++)
  8898. {
  8899. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8900. {
  8901. 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
  8902. {
  8903. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8904. goto end;
  8905. }
  8906. }//END FOR CHAdeMO_QUANTITY
  8907. for (int index = 0; index < CCS_QUANTITY; index++)
  8908. {
  8909. 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
  8910. {
  8911. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8912. goto end;
  8913. }
  8914. }//END FOR CCS_QUANTITY
  8915. for (int index = 0; index < GB_QUANTITY; index++)
  8916. {
  8917. 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
  8918. {
  8919. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8920. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8921. goto end;
  8922. }
  8923. }// END FOR GB_QUANTITY
  8924. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8925. {
  8926. 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
  8927. {
  8928. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8929. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8930. goto end;
  8931. }
  8932. }// END FOR GENERAL_GUN_QUANTITY
  8933. for (int index = 0; index < AC_QUANTITY; index++)
  8934. {
  8935. 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
  8936. {
  8937. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8938. goto end;
  8939. }
  8940. }//END FOR CHAdeMO_QUANTITY
  8941. }// END FOR gunTotalNumber
  8942. }
  8943. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8944. {
  8945. for(int i=0; i < gunTotalNumber; i++)
  8946. {
  8947. for (int index = 0; index < AC_QUANTITY; index++)
  8948. {
  8949. 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
  8950. {
  8951. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8952. goto end;
  8953. }
  8954. }//END FOR CHAdeMO_QUANTITY
  8955. } // END FOR gunTotalNumber
  8956. }
  8957. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8958. goto end;
  8959. }
  8960. //----------------------gunIndex is not 0 ------------------------------------------------//
  8961. //check Transaction active
  8962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8963. {
  8964. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8965. {
  8966. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8967. goto end;
  8968. }
  8969. }//END FOR CHAdeMO_QUANTITY
  8970. for (int index = 0; index < CCS_QUANTITY; index++)
  8971. {
  8972. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8973. {
  8974. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8975. goto end;
  8976. }
  8977. }//END FOR CCS_QUANTITY
  8978. for (int index = 0; index < GB_QUANTITY; index++)
  8979. {
  8980. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8981. {
  8982. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8983. goto end;
  8984. }
  8985. }// END FOR GB_QUANTITY
  8986. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8987. {
  8988. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8989. {
  8990. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8991. goto end;
  8992. }
  8993. }// END FOR GENERAL_GUN_QUANTITY
  8994. for (int index = 0; index < AC_QUANTITY; index++)
  8995. {
  8996. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8997. {
  8998. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8999. goto end;
  9000. }
  9001. }//END FOR AC_QUANTITY
  9002. }//END FOR AvailabilityTypeStr[Operative]
  9003. end:
  9004. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9005. {
  9006. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9007. }
  9008. else
  9009. {
  9010. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9011. }
  9012. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9013. {
  9014. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9015. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9016. }
  9017. else if(gunIndex == 0)
  9018. {
  9019. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9020. {
  9021. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9022. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9023. }
  9024. }
  9025. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9026. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9027. return result;
  9028. }
  9029. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9030. {
  9031. mtrace();
  9032. int valueInvalid = NO;
  9033. int result = FAIL;
  9034. char keystr[40]={0};
  9035. char valuestr[501]={0}; //value should be limited in 500 bytes
  9036. char comfirmstr[20]={0};
  9037. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9038. json_object *ChangeConfiguration;
  9039. ChangeConfiguration = json_tokener_parse(payload);
  9040. if(!is_error(ChangeConfiguration))
  9041. {
  9042. // Required data
  9043. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9044. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9045. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9046. {
  9047. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9048. }
  9049. else
  9050. {
  9051. valueInvalid = YES;
  9052. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9053. }
  9054. }
  9055. json_object_put(ChangeConfiguration);
  9056. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9057. {
  9058. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9059. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9060. }
  9061. else
  9062. {
  9063. int status = setKeyValue(keystr, valuestr);
  9064. switch(status)
  9065. {
  9066. case ConfigurationStatus_Accepted:
  9067. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9068. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9069. StoreConfigurationTable();
  9070. break;
  9071. case RebootRequired:
  9072. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9073. StoreConfigurationTable();
  9074. break;
  9075. case NotSupported:
  9076. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9077. break;
  9078. case ConfigurationStatus_Rejected:
  9079. default:
  9080. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9081. break;
  9082. }
  9083. }
  9084. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9085. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9086. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9087. {
  9088. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9089. SetOcppConnStatus(FALSE);
  9090. }
  9091. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9092. {
  9093. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9094. }
  9095. return result;
  9096. }
  9097. int handleClearCacheRequest(char *uuid, char *payload)
  9098. {
  9099. mtrace();
  9100. int result = FAIL;
  9101. char comfirmstr[20];
  9102. char rmFileCmd[100]={0};
  9103. struct stat stats;
  9104. DEBUG_INFO("handleClearCacheRequest...\n");
  9105. stat("/Storage/OCPP", &stats);
  9106. // Check for directory existence
  9107. if (S_ISDIR(stats.st_mode) == 1)
  9108. {}
  9109. else
  9110. {
  9111. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9112. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9113. system(rmFileCmd);
  9114. }
  9115. if(OCPP_cleanLocalCache())
  9116. {
  9117. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9118. }
  9119. else
  9120. {
  9121. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9122. }
  9123. sendClearCacheConfirmation(uuid, comfirmstr);
  9124. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9125. return result;
  9126. }
  9127. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9128. {
  9129. mtrace();
  9130. int result = FAIL;
  9131. int resultRename;
  9132. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9133. char chargingProfilePurposeStr[26]={0};
  9134. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9135. char tempchargingProfilePurposeStr[26]={0};
  9136. char str[100]={0};
  9137. char fname[200]={0};
  9138. char comfirmstr[20]={0};
  9139. char word[1600]={0};
  9140. int clearflag = FALSE;
  9141. int chargingProfileIdIsNULL = FALSE;
  9142. int connectorIsNULL = FALSE;
  9143. int chargingProfilePurposeIsNULL = FALSE;
  9144. int stackLevelIsNULL = FALSE;
  9145. //int GotoEnd = FALSE;
  9146. FILE *fptr1, *fptr2;
  9147. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9148. int n_chargingProfile=0;
  9149. int isEmptyFile = FALSE;
  9150. char sLineWord[1600]={0};
  9151. char chargingProfiles[10][100]={0};
  9152. int ChargeProfileCount = 0;
  9153. int ch;
  9154. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9155. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9156. json_object *ClearChargingProfile;
  9157. ClearChargingProfile = json_tokener_parse(payload);
  9158. if(!is_error(ClearChargingProfile))
  9159. {
  9160. // Optional data
  9161. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9162. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9163. else
  9164. chargingProfileIdIsNULL = TRUE;
  9165. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9166. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9167. else
  9168. connectorIsNULL = TRUE;
  9169. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9170. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9171. else
  9172. chargingProfilePurposeIsNULL = TRUE;
  9173. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9174. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9175. else
  9176. stackLevelIsNULL = TRUE;
  9177. }
  9178. json_object_put(ClearChargingProfile);
  9179. if(connectorIsNULL == FALSE)
  9180. {
  9181. switch(connectorIdInt)
  9182. {
  9183. case 0:
  9184. if(chargingProfilePurposeIsNULL == TRUE)
  9185. {
  9186. int l = 0;
  9187. strcpy(fname, ChargePointMaxProfile_JSON);
  9188. if((access(fname,F_OK))!=-1)
  9189. {
  9190. strcpy(chargingProfiles[l], fname);
  9191. l = l + 1;
  9192. }
  9193. strcpy(fname, TxDefaultProfile_0_JSON);
  9194. if((access(fname,F_OK))!=-1)
  9195. {
  9196. strcpy(chargingProfiles[l], fname);
  9197. l = l + 1;
  9198. }
  9199. ChargeProfileCount = l;
  9200. }
  9201. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9202. {
  9203. strcpy(fname, ChargePointMaxProfile_JSON);
  9204. if((access(fname,F_OK))!=-1)
  9205. {
  9206. strcpy(chargingProfiles[0], fname);
  9207. ChargeProfileCount = 1;
  9208. }
  9209. }
  9210. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9211. {
  9212. strcpy(fname, TxDefaultProfile_0_JSON);
  9213. if((access(fname,F_OK))!=-1)
  9214. {
  9215. strcpy(chargingProfiles[0], fname);
  9216. ChargeProfileCount = 1;
  9217. }
  9218. }
  9219. break;
  9220. default:
  9221. if(chargingProfilePurposeIsNULL == TRUE)
  9222. {
  9223. int m = 0;
  9224. memset(fname, 0, ARRAY_SIZE(fname));
  9225. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9226. if((access(fname,F_OK))!=-1)
  9227. {
  9228. strcpy(chargingProfiles[m], fname);
  9229. m = m + 1;
  9230. }
  9231. memset(fname, 0, ARRAY_SIZE(fname));
  9232. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9233. if((access(fname,F_OK))!=-1)
  9234. {
  9235. strcpy(chargingProfiles[m], fname);
  9236. m = m + 1;
  9237. }
  9238. ChargeProfileCount = m;
  9239. }
  9240. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9241. {
  9242. //strcpy(fname, TxDefaultProfile_1_JSON);
  9243. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9244. if((access(fname,F_OK))!=-1)
  9245. {
  9246. strcpy(chargingProfiles[0], fname);
  9247. ChargeProfileCount = 1;
  9248. }
  9249. }
  9250. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9251. {
  9252. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9253. if((access(fname,F_OK))!=-1)
  9254. {
  9255. strcpy(chargingProfiles[0], fname);
  9256. ChargeProfileCount = 1;
  9257. }
  9258. //strcpy(fname, TxProfile_1_JSON);
  9259. }
  9260. //strcpy(fname, ChargePointMaxProfile_JSON );
  9261. break;
  9262. }
  9263. }
  9264. else // Check all Charging Profiles
  9265. {
  9266. int i = 0;
  9267. char fnametemp[200]={0};
  9268. ChargeProfileCount = 0;
  9269. //Check ChargePointMaxProfile.json exit
  9270. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9271. {
  9272. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9273. i = i + 1;
  9274. }
  9275. //Check TxDefaultProfile_0.json exit
  9276. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9277. {
  9278. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9279. i = i + 1;
  9280. }
  9281. //Check TxDefaultProfile_%d.json
  9282. for(int j=1; j <= gunTotalNumber; j++)
  9283. {
  9284. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9285. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9286. if((access(fnametemp,F_OK))!=-1)
  9287. {
  9288. strcpy(chargingProfiles[i], fnametemp);
  9289. i = i + 1;
  9290. }
  9291. }
  9292. //Check TxProfile_%d.json
  9293. for(int j=1; j <= gunTotalNumber; j++)
  9294. {
  9295. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9296. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9297. if((access(fnametemp,F_OK))!=-1)
  9298. {
  9299. strcpy(chargingProfiles[i], fnametemp);
  9300. i = i + 1;
  9301. }
  9302. }
  9303. ChargeProfileCount = i;
  9304. }// End connectorIsNULL is TRUE
  9305. if(ChargeProfileCount == 0)
  9306. {
  9307. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9308. goto end;
  9309. }
  9310. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9311. {
  9312. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9313. goto end;
  9314. }
  9315. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9316. {
  9317. memset(str, 0, ARRAY_SIZE(str));
  9318. // clear temp file
  9319. sprintf(str,"rm -f %s",temp);
  9320. system(str);
  9321. for(int k=0; k < ChargeProfileCount; k++)
  9322. {
  9323. memset(str, 0, ARRAY_SIZE(str));
  9324. //clear file in C
  9325. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9326. system(str);
  9327. }
  9328. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9329. goto end;
  9330. }
  9331. else if(connectorIsNULL == TRUE)
  9332. {
  9333. for(int k=0; k < ChargeProfileCount; k++)
  9334. {
  9335. fptr1 = fopen(chargingProfiles[k], "r");
  9336. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9337. //Check Charging Profile Count
  9338. while(fscanf(fptr1, "%s", word) != EOF)
  9339. {
  9340. //DEBUG_INFO("word=%s\n",word);
  9341. if(strstr(word, "chargingProfileId")!= NULL)
  9342. {
  9343. //DEBUG_INFO("test chargingProfileId \n");
  9344. n_chargingProfile = n_chargingProfile + 1;
  9345. //DEBUG_INFO("chargingProfileId Found\n");
  9346. }
  9347. }
  9348. rewind(fptr1);
  9349. //search Charging Profile Element
  9350. //int i= 0;
  9351. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9352. {
  9353. json_object *tmpProfilee;
  9354. tmpProfilee = json_tokener_parse(sLineWord);
  9355. if(!is_error(tmpProfilee))
  9356. {
  9357. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9358. {
  9359. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9360. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9361. }
  9362. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9363. {
  9364. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9365. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9366. }
  9367. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9368. {
  9369. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9370. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9371. }
  9372. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9373. {
  9374. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9375. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9376. }
  9377. }
  9378. json_object_put(tmpProfilee);
  9379. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9380. {
  9381. //------- not write to fptr2-------//
  9382. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9383. //clearflag = TRUE;
  9384. }
  9385. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9386. {
  9387. //------- not write to fptr2-------//
  9388. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9389. }
  9390. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9391. {
  9392. //------- not write to fptr2-------//
  9393. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9394. }
  9395. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9396. {
  9397. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9398. }
  9399. else
  9400. {
  9401. fprintf(fptr2, sLineWord);//writing data into file
  9402. }
  9403. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9404. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9405. if(clearflag == TRUE)
  9406. {
  9407. fclose(fptr1);
  9408. fclose(fptr2);
  9409. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9410. system(str);
  9411. // clear temp file
  9412. sprintf(str,"rm -f %s",temp);
  9413. system(str);
  9414. }
  9415. else
  9416. {
  9417. fclose(fptr1);
  9418. fclose(fptr2);
  9419. memset(str, 0, ARRAY_SIZE(str));
  9420. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9421. system(str);
  9422. resultRename = rename(temp, chargingProfiles[k]);
  9423. if(resultRename == 0)
  9424. {
  9425. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9426. }
  9427. else
  9428. {
  9429. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9430. }
  9431. if(comfirmstr[0]== 0)
  9432. {
  9433. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9434. }
  9435. //Check chargingProfile is empty file
  9436. /*------ Read the file ----------------*/
  9437. fptr1=fopen(chargingProfiles[k],"r");
  9438. ch=fgetc(fptr1);
  9439. rewind(fptr1);
  9440. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9441. if(ch!=EOF)
  9442. {
  9443. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9444. {
  9445. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9446. if(sLineWord[0]=='\0')
  9447. {
  9448. isEmptyFile = TRUE;
  9449. break;
  9450. }
  9451. else
  9452. {
  9453. isEmptyFile = FALSE;
  9454. break;
  9455. }
  9456. }
  9457. }
  9458. else
  9459. isEmptyFile = TRUE;
  9460. fclose(fptr1);
  9461. if(isEmptyFile == TRUE)
  9462. {
  9463. memset(str, 0, ARRAY_SIZE(str));
  9464. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9465. system(str);
  9466. }
  9467. }
  9468. }// End of while(int k=0; k < ChargePointCount; k++)
  9469. }
  9470. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9471. {
  9472. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9473. for(int k=0; k < ChargeProfileCount; k++)
  9474. {
  9475. fptr1 = fopen(chargingProfiles[k], "r");
  9476. fptr2 = fopen(temp, "w+");
  9477. //Check Charging Profile Count
  9478. while(fscanf(fptr1, "%s", word) != EOF)
  9479. {
  9480. //DEBUG_INFO("word=%s\n",word);
  9481. if(strstr(word, "chargingProfileId")!= NULL)
  9482. {
  9483. n_chargingProfile = n_chargingProfile + 1;
  9484. }
  9485. }
  9486. rewind(fptr1);
  9487. //search Charging Profile Element
  9488. //int i= 0;
  9489. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9490. {
  9491. json_object *tmpProfilee;
  9492. tmpProfilee = json_tokener_parse(sLineWord);
  9493. if(!is_error(tmpProfilee))
  9494. {
  9495. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9496. {
  9497. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9498. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9499. }
  9500. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9501. {
  9502. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9503. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9504. }
  9505. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9506. {
  9507. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9508. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9509. }
  9510. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9511. {
  9512. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9513. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9514. }
  9515. }
  9516. json_object_put(tmpProfilee);
  9517. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9518. {
  9519. //------- not write to fptr2-------//
  9520. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9521. //clearflag = TRUE;
  9522. }
  9523. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9524. {
  9525. //------- not write to fptr2-------//
  9526. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9527. }
  9528. else if(stackLevelIsNULL == TRUE)
  9529. {
  9530. //Clear Whole File
  9531. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9532. clearflag = TRUE;
  9533. break;
  9534. }
  9535. else
  9536. {
  9537. fprintf(fptr2, sLineWord);//writing data into file
  9538. }
  9539. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9540. }
  9541. if(clearflag == TRUE)
  9542. {
  9543. fclose(fptr1);
  9544. fclose(fptr2);
  9545. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9546. system(str);
  9547. // clear temp file
  9548. sprintf(str,"rm -f %s",temp);
  9549. system(str);
  9550. }
  9551. else
  9552. {
  9553. fclose(fptr1);
  9554. fclose(fptr2);
  9555. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9556. system(str);
  9557. resultRename = rename(temp, chargingProfiles[k]);
  9558. if(resultRename == 0)
  9559. {
  9560. DEBUG_INFO("File ChargingProfile renamed successfully");
  9561. }
  9562. else
  9563. {
  9564. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9565. }
  9566. if(comfirmstr[0]== 0)
  9567. {
  9568. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9569. }
  9570. //Check chargingProfile is empty file
  9571. /*------ Read the file ----------------*/
  9572. fptr1=fopen(chargingProfiles[k],"r");
  9573. ch=fgetc(fptr1);
  9574. rewind(fptr1);
  9575. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9576. if(ch!=EOF)
  9577. {
  9578. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9579. {
  9580. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9581. if(sLineWord[0]=='\0')
  9582. {
  9583. isEmptyFile = TRUE;
  9584. break;
  9585. }
  9586. else
  9587. {
  9588. isEmptyFile = FALSE;
  9589. break;
  9590. }
  9591. }
  9592. }
  9593. else
  9594. isEmptyFile = TRUE;
  9595. fclose(fptr1);
  9596. if(isEmptyFile == TRUE)
  9597. {
  9598. memset(str, 0, ARRAY_SIZE(str));
  9599. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9600. system(str);
  9601. }
  9602. /*------- End of reading ---------------*/
  9603. }
  9604. } // while(int k=0; k < ChargeProfileCount; k++)
  9605. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9606. end:
  9607. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9608. {
  9609. if(connectorIdInt == 0)
  9610. {
  9611. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9612. {
  9613. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9614. }
  9615. }
  9616. else
  9617. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9618. }
  9619. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9620. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9621. return result;
  9622. }
  9623. void createFirmwareVersionByDataTransfer(void)
  9624. {
  9625. json_object *FirmwareDataTransfer = json_object_new_object();
  9626. // AC & DC model
  9627. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9628. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9629. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9630. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9631. // DC model
  9632. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9633. {
  9634. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9635. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9636. (gunType[3] != GUN_TYPE_UNKNOWN))
  9637. {
  9638. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9639. }
  9640. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9641. {
  9642. // DS DM DW
  9643. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9644. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9645. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9646. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9647. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9648. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9649. }
  9650. else
  9651. {
  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, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9655. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9656. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9657. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9658. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9659. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9660. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9661. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9662. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9663. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9664. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9665. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9666. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9667. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9668. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9669. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9670. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9671. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9672. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9673. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9674. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9675. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9676. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9677. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9678. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9679. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9680. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9681. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9682. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9683. }
  9684. }
  9685. // 4G model
  9686. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9687. {
  9688. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9689. }
  9690. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9691. json_object_put(FirmwareDataTransfer);
  9692. }
  9693. int handleDataTransferRequest(char *uuid, char *payload)
  9694. {
  9695. mtrace();
  9696. json_object *response = json_object_new_object();
  9697. int result = FAIL;
  9698. char tempvendorId[255]={0};
  9699. char tempmessageId[50]={0};
  9700. char tempdata[1024]={0};
  9701. char message[2048]={0};
  9702. DEBUG_INFO("handleDataTransferRequest...\n");
  9703. if((uuid != NULL) && (payload != NULL))
  9704. {
  9705. json_object *DataTransfer;
  9706. DataTransfer = json_tokener_parse(payload);
  9707. if(!is_error(DataTransfer))
  9708. {
  9709. // Required data
  9710. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9711. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9712. // Optional data
  9713. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9714. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9715. if(json_object_object_get(DataTransfer, "data") != NULL)
  9716. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9717. result = PASS;
  9718. }
  9719. json_object_put(DataTransfer);
  9720. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9721. {
  9722. // Send all moudle firmware version on EVSE
  9723. createFirmwareVersionByDataTransfer();
  9724. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9725. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9726. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9727. json_object_put(response);
  9728. }
  9729. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9730. {
  9731. system("/usr/bin/run_tmate_restart.sh &");
  9732. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9733. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9734. json_object_put(response);
  9735. }
  9736. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9737. {
  9738. json_object *data;
  9739. data = json_tokener_parse(tempdata);
  9740. if(!is_error(data))
  9741. {
  9742. 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))
  9743. {
  9744. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9745. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9746. if(json_object_object_get(data, "SOC") != NULL)
  9747. {
  9748. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9749. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9750. }
  9751. if(json_object_object_get(data, "Energy") != NULL)
  9752. {
  9753. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9754. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9755. }
  9756. if(json_object_object_get(data, "Duration") != NULL)
  9757. {
  9758. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9759. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9760. }
  9761. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9762. }
  9763. else
  9764. {
  9765. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9766. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9767. }
  9768. }
  9769. else
  9770. {
  9771. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9772. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9773. }
  9774. json_object_put(data);
  9775. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9776. json_object_put(response);
  9777. }
  9778. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9779. {
  9780. json_object *data;
  9781. data = json_tokener_parse(tempdata);
  9782. if(!is_error(data))
  9783. {
  9784. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9785. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9786. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9787. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9788. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9789. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9790. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9791. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9792. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9793. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9794. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9795. }
  9796. else
  9797. {
  9798. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9799. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9800. }
  9801. json_object_put(data);
  9802. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9803. json_object_put(response);
  9804. }
  9805. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9806. {
  9807. json_object *data;
  9808. data = json_tokener_parse(tempdata);
  9809. if(!is_error(data))
  9810. {
  9811. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9812. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9813. if(json_object_object_get(data, "idToken") != NULL)
  9814. {
  9815. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9816. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9817. }
  9818. else
  9819. {
  9820. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9821. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9822. }
  9823. if(json_object_object_get(data, "price") != NULL) //v1.0
  9824. {
  9825. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9826. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9827. }
  9828. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9829. {
  9830. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9831. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9832. }
  9833. else
  9834. {
  9835. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9836. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9837. }
  9838. }
  9839. else
  9840. {
  9841. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9842. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9843. }
  9844. json_object_put(data);
  9845. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9846. json_object_put(response);
  9847. }
  9848. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9849. {
  9850. json_object *data;
  9851. data = json_tokener_parse(tempdata);
  9852. if(!is_error(data))
  9853. {
  9854. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9855. if(json_object_object_get(data, "txId") != NULL)
  9856. {
  9857. // California pricing V1.0
  9858. DEBUG_INFO("California pricing V1.0\n");
  9859. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9860. sprintf((char*)dmsVersion, "1.0");
  9861. for(int idx = 0;idx<gunTotalNumber;idx++)
  9862. {
  9863. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9864. {
  9865. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9866. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9867. if(json_object_object_get(data, "description") != NULL)
  9868. {
  9869. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9870. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9871. }
  9872. else
  9873. {
  9874. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9875. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9876. }
  9877. }
  9878. }
  9879. }
  9880. else if(json_object_object_get(data, "transactionId") != NULL)
  9881. {
  9882. // California pricing V2.0
  9883. DEBUG_INFO("California pricing V2.0\n");
  9884. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9885. sprintf((char*)dmsVersion, "2.0");
  9886. for(int idx=0;idx<gunTotalNumber;idx++)
  9887. {
  9888. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9889. {
  9890. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9891. if(json_object_object_get(data, "timestamp") != NULL)
  9892. {
  9893. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9894. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9895. }
  9896. else
  9897. {
  9898. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9899. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9900. }
  9901. if(json_object_object_get(data, "meterValue") != NULL)
  9902. {
  9903. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9904. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9905. }
  9906. else
  9907. {
  9908. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9909. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9910. }
  9911. if(json_object_object_get(data, "cost") != NULL)
  9912. {
  9913. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9914. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9915. }
  9916. else
  9917. {
  9918. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9919. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9920. }
  9921. if(json_object_object_get(data, "state") != NULL)
  9922. {
  9923. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9924. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9925. }
  9926. else
  9927. {
  9928. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9929. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9930. }
  9931. if(json_object_object_get(data, "chargingPrice") != NULL)
  9932. {
  9933. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9934. {
  9935. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9936. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9937. }
  9938. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9939. {
  9940. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9941. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9942. }
  9943. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9944. {
  9945. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9946. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9947. }
  9948. }
  9949. else
  9950. {
  9951. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9952. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9953. }
  9954. if(json_object_object_get(data, "idlePrice") != NULL)
  9955. {
  9956. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9957. {
  9958. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9959. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9960. }
  9961. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9962. {
  9963. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9964. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9965. }
  9966. }
  9967. if(json_object_object_get(data, "nextPeriod") != NULL)
  9968. {
  9969. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9970. {
  9971. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9972. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9973. }
  9974. else
  9975. {
  9976. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9977. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9978. }
  9979. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9980. {
  9981. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9982. {
  9983. 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")));
  9984. 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"));
  9985. }
  9986. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9987. {
  9988. 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")));
  9989. 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"));
  9990. }
  9991. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9992. {
  9993. 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")));
  9994. 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"));
  9995. }
  9996. }
  9997. else
  9998. {
  9999. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10000. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10001. }
  10002. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10003. {
  10004. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10005. {
  10006. 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")));
  10007. 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"));
  10008. }
  10009. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10010. {
  10011. 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")));
  10012. 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"));
  10013. }
  10014. }
  10015. }
  10016. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10017. {
  10018. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10019. {
  10020. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10021. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10022. }
  10023. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10024. {
  10025. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10026. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10027. }
  10028. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10029. {
  10030. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10031. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10032. }
  10033. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10034. {
  10035. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10036. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10037. }
  10038. }
  10039. }
  10040. }
  10041. }
  10042. else
  10043. {
  10044. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10045. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10046. }
  10047. }
  10048. else
  10049. {
  10050. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10051. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10052. }
  10053. json_object_put(data);
  10054. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10055. json_object_put(response);
  10056. }
  10057. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10058. {
  10059. json_object *data;
  10060. data = json_tokener_parse(tempdata);
  10061. if(!is_error(data))
  10062. {
  10063. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10064. if(json_object_object_get(data, "txId") != NULL)
  10065. {
  10066. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10067. for(int idx = 0;idx<gunTotalNumber;idx++)
  10068. {
  10069. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10070. {
  10071. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10072. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10073. if(json_object_object_get(data, "description") != NULL)
  10074. {
  10075. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10076. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10077. }
  10078. else
  10079. {
  10080. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10081. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10082. }
  10083. }
  10084. }
  10085. }
  10086. else if(json_object_object_get(data, "transactionId") != NULL)
  10087. {
  10088. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10089. for(int idx = 0;idx<gunTotalNumber;idx++)
  10090. {
  10091. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10092. {
  10093. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10094. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10095. if(json_object_object_get(data, "cost") != NULL)
  10096. {
  10097. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10098. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10099. }
  10100. else
  10101. {
  10102. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10103. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10104. }
  10105. if(json_object_object_get(data, "priceText") != NULL)
  10106. {
  10107. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10108. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10109. }
  10110. else
  10111. {
  10112. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10113. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10114. }
  10115. if(json_object_object_get(data, "qrCodeText") != NULL)
  10116. {
  10117. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10118. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10119. }
  10120. }
  10121. }
  10122. }
  10123. else
  10124. {
  10125. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10126. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10127. }
  10128. }
  10129. else
  10130. {
  10131. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10132. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10133. }
  10134. json_object_put(data);
  10135. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10136. json_object_put(response);
  10137. }
  10138. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10139. {
  10140. json_object *data;
  10141. data = json_tokener_parse(tempdata);
  10142. if(!is_error(data))
  10143. {
  10144. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10145. if(json_object_object_get(data, "Content_Type") != NULL)
  10146. {
  10147. 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))
  10148. {
  10149. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10150. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10151. {
  10152. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10153. }
  10154. }
  10155. else
  10156. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10157. }
  10158. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10159. }
  10160. else
  10161. {
  10162. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10163. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10164. }
  10165. json_object_put(data);
  10166. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10167. json_object_put(response);
  10168. }
  10169. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10170. {
  10171. json_object *data;
  10172. data = json_tokener_parse(tempdata);
  10173. if(!is_error(data))
  10174. {
  10175. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10176. if(json_object_object_get(data, "ConnectorId") != NULL)
  10177. {
  10178. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10179. }
  10180. if(json_object_object_get(data, "SerialNo") != NULL)
  10181. {
  10182. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10183. }
  10184. if(json_object_object_get(data, "Page_Index") != NULL)
  10185. {
  10186. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10187. }
  10188. if(json_object_object_get(data, "Duration") != NULL)
  10189. {
  10190. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10191. }
  10192. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10193. }
  10194. else
  10195. {
  10196. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10197. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10198. }
  10199. json_object_put(data);
  10200. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10201. json_object_put(response);
  10202. }
  10203. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10204. {
  10205. json_object *data;
  10206. data = json_tokener_parse(tempdata);
  10207. if(!is_error(data))
  10208. {
  10209. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10210. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10211. {
  10212. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10213. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10214. else
  10215. {
  10216. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10217. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10218. }
  10219. }
  10220. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10221. {
  10222. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10223. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10224. else
  10225. {
  10226. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10227. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10228. }
  10229. }
  10230. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10231. {
  10232. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10233. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10234. else
  10235. {
  10236. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10237. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10238. }
  10239. }
  10240. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10241. {
  10242. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10243. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10244. else
  10245. {
  10246. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10247. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10248. }
  10249. }
  10250. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10251. {
  10252. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10253. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10254. else
  10255. {
  10256. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10257. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10258. }
  10259. }
  10260. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10261. {
  10262. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10263. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10264. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10265. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10266. else
  10267. {
  10268. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10269. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10270. }
  10271. }
  10272. if(json_object_object_get(data, "isAuthentication") != NULL)
  10273. {
  10274. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10275. {
  10276. case 0:
  10277. case 1:
  10278. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10279. break;
  10280. default:
  10281. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10282. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10283. break;
  10284. }
  10285. }
  10286. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10287. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10288. }
  10289. else
  10290. {
  10291. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10292. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10293. }
  10294. json_object_put(data);
  10295. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10296. json_object_put(response);
  10297. }
  10298. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10299. {
  10300. json_object *data;
  10301. data = json_tokener_parse(tempdata);
  10302. if(!is_error(data))
  10303. {
  10304. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10305. {
  10306. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10307. {
  10308. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10309. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10310. }
  10311. else
  10312. {
  10313. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10314. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10315. }
  10316. }
  10317. else
  10318. {
  10319. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10320. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10321. }
  10322. }
  10323. else
  10324. {
  10325. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10326. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10327. }
  10328. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10329. json_object_put(response);
  10330. }
  10331. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10332. {
  10333. json_object *data;
  10334. data = json_tokener_parse(tempdata);
  10335. if(!is_error(data))
  10336. {
  10337. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10338. if(json_object_object_get(data, "stationName") != NULL)
  10339. {
  10340. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10341. }
  10342. else
  10343. {
  10344. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10345. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10346. }
  10347. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10348. {
  10349. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10350. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10351. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10352. }
  10353. }
  10354. else
  10355. {
  10356. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10357. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10358. }
  10359. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10360. json_object_put(response);
  10361. }
  10362. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10363. {
  10364. json_object *data;
  10365. data = json_tokener_parse(tempdata);
  10366. if(!is_error(data))
  10367. {
  10368. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10369. if(json_object_object_get(data, "weatherId") != NULL)
  10370. {
  10371. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10372. }
  10373. else
  10374. {
  10375. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10376. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10377. }
  10378. if(json_object_object_get(data, "Temperature") != NULL)
  10379. {
  10380. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10381. }
  10382. else
  10383. {
  10384. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10385. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10386. }
  10387. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10388. {
  10389. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10390. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10391. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10392. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10393. );
  10394. }
  10395. }
  10396. else
  10397. {
  10398. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10399. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10400. }
  10401. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10402. json_object_put(response);
  10403. }
  10404. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10405. {
  10406. json_object *data;
  10407. data = json_tokener_parse(tempdata);
  10408. if(!is_error(data))
  10409. {
  10410. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10411. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10412. {
  10413. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10414. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10415. }
  10416. else
  10417. {
  10418. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10419. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10420. }
  10421. }
  10422. else
  10423. {
  10424. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10425. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10426. }
  10427. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10428. json_object_put(response);
  10429. }
  10430. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10431. {
  10432. json_object *data;
  10433. data = json_tokener_parse(tempdata);
  10434. if(!is_error(data))
  10435. {
  10436. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10437. {
  10438. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10439. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10440. if(gun_index < gunTotalNumber)
  10441. {
  10442. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10443. {
  10444. json_object *responsedata = json_object_new_object();
  10445. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10446. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10447. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10448. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10449. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10450. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10451. }
  10452. else
  10453. {
  10454. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10455. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10456. }
  10457. }
  10458. else
  10459. {
  10460. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10461. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10462. }
  10463. }
  10464. else
  10465. {
  10466. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10467. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10468. }
  10469. }
  10470. else
  10471. {
  10472. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10473. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10474. }
  10475. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10476. json_object_put(response);
  10477. }
  10478. else
  10479. {
  10480. // Can not find valid message id
  10481. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10482. }
  10483. }
  10484. else
  10485. {
  10486. // Payload is null
  10487. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10488. }
  10489. LWS_Send(message);
  10490. return result;
  10491. }
  10492. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10493. {
  10494. mtrace();
  10495. int result = FAIL;
  10496. int connectorIdInt, durationInt;
  10497. char chargingRateUnitStr[4]={0};
  10498. char comfirmstr[20];
  10499. int confirmPeriods = 0;
  10500. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10501. json_object *GetCompositeSchedule;
  10502. GetCompositeSchedule = json_tokener_parse(payload);
  10503. if(!is_error(GetCompositeSchedule))
  10504. {
  10505. // Required data
  10506. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10507. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10508. else
  10509. connectorIdInt = -1;
  10510. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10511. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10512. else
  10513. durationInt = 86400;
  10514. // Optional data
  10515. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10516. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10517. }
  10518. json_object_put(GetCompositeSchedule);
  10519. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10520. if((connectorIdInt == 0) ||
  10521. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10522. {
  10523. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10524. struct StructChargingProfile tmpProfile[1];
  10525. if(strstr(chargingRateUnitStr, "W") != NULL)
  10526. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10527. else
  10528. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10529. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10530. {
  10531. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10532. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10533. }
  10534. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10535. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10536. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10537. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10538. {
  10539. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10540. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10541. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10542. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10543. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10544. {
  10545. confirmPeriods = idx;
  10546. break;
  10547. }
  10548. }
  10549. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10550. {
  10551. confirmPeriods += 1;
  10552. }
  10553. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10554. }
  10555. else
  10556. {
  10557. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10558. }
  10559. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10560. return result;
  10561. }
  10562. int handleGetConfigurationRequest(char *uuid, char *payload)
  10563. {
  10564. mtrace();
  10565. int result = FAIL;
  10566. int MaxKeySupported = 0;
  10567. int n_keys = 0;
  10568. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10569. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10570. json_object *GetConfiguration;
  10571. GetConfiguration = json_tokener_parse(payload);
  10572. if(!is_error(GetConfiguration))
  10573. {
  10574. // Optional data
  10575. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10576. {
  10577. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10578. {
  10579. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10580. n_keys = idx + 1;
  10581. }
  10582. }
  10583. }
  10584. json_object_put(GetConfiguration);
  10585. UnknownKeynum = 0;
  10586. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10587. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10588. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10589. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10590. if(n_keys != 0)
  10591. {
  10592. for(int i=0;i<n_keys;i++)
  10593. {
  10594. getKeyValue(requestKey[i]);
  10595. }
  10596. }
  10597. else
  10598. {
  10599. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10600. getKeyValue("");
  10601. }
  10602. processUnkownKey();
  10603. sendGetConfigurationConfirmation(uuid);
  10604. return result;
  10605. }
  10606. static char fnamePlusPath[100]={0};
  10607. static char fnamePWithNoPath[60]={0};
  10608. void checkUploadLog(void)
  10609. {
  10610. FILE *fp;
  10611. /* Open the command for reading. */
  10612. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10613. if (fp == NULL) {
  10614. DEBUG_WARN("Failed to run command\n" );
  10615. exit(1);
  10616. }
  10617. int ftppathlen = 0;
  10618. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10619. int i = 0;
  10620. /* Read the output a line at a time - output it. */
  10621. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10622. if(i==0)
  10623. {
  10624. ftppathlen = strlen(fnamePlusPath);
  10625. DEBUG_INFO("%s\n", fnamePlusPath);
  10626. fnamePlusPath[ftppathlen]='\0';
  10627. break;
  10628. }
  10629. i= i+1;
  10630. }
  10631. /* close */
  10632. pclose(fp);
  10633. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10634. {
  10635. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10636. {
  10637. fnamePlusPath[k]='\0';
  10638. }
  10639. }
  10640. i=1;
  10641. //char fname[60]={0};
  10642. while(i < ftppathlen)
  10643. {
  10644. int len=ftppathlen-i;
  10645. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10646. {
  10647. DEBUG_INFO("compare '/' all right\n");
  10648. break;
  10649. }
  10650. i=i+1;
  10651. }
  10652. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10653. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10654. fnamePWithNoPath[i+1] = '\0';
  10655. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10656. {
  10657. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10658. {
  10659. fnamePWithNoPath[j]='\0';
  10660. }
  10661. }
  10662. FILE* fp1 = fopen(fnamePlusPath, "r");
  10663. if (fp1)
  10664. {
  10665. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10666. // file exists
  10667. fclose(fp1);
  10668. }
  10669. else
  10670. {
  10671. // file doesn't exist
  10672. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10673. }
  10674. }
  10675. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10676. {
  10677. mtrace();
  10678. int result = FAIL;
  10679. time_t CurrentTime;
  10680. struct tm *tm;
  10681. pthread_t th_Status;
  10682. CurrentTime = time(NULL);
  10683. tm = localtime(&CurrentTime);
  10684. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10685. 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);
  10686. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10687. if(!interLock.isGetDiagnosticGoing)
  10688. {
  10689. interLock.isGetDiagnosticGoing = 1;
  10690. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  10691. sleep(1);
  10692. }
  10693. else
  10694. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10695. return result;
  10696. }
  10697. void* GetDiagnosticsProcess(void* data)
  10698. {
  10699. pthread_detach(pthread_self());
  10700. mtrace();
  10701. int retriesInt=0, retryIntervalInt=0;
  10702. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10703. 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};
  10704. int port=0;
  10705. int isSuccess = FALSE;
  10706. char cmdBuf[2048];
  10707. struct tm *tmNow;
  10708. time_t CurrentTime;
  10709. struct tm tmStart;
  10710. struct tm tmStop;
  10711. CurrentTime = time(NULL);
  10712. tmNow=localtime(&CurrentTime);
  10713. uint16_t targetYear, targetMonth;
  10714. json_object *GetDiagnostics;
  10715. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10716. GetDiagnostics = json_tokener_parse(data);
  10717. if(!is_error(GetDiagnostics))
  10718. {
  10719. // Required data
  10720. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10721. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10722. // Optional data
  10723. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10724. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10725. else
  10726. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10727. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10728. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10729. else
  10730. retryIntervalInt = 30;
  10731. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10732. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10733. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10734. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10735. }
  10736. json_object_put(GetDiagnostics);
  10737. // Pack log to compress file
  10738. 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) &&
  10739. (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))
  10740. {
  10741. // Pack system log
  10742. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10743. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10744. targetYear = tmStart.tm_year;
  10745. targetMonth = tmStart.tm_mon;
  10746. do
  10747. {
  10748. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10749. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10750. if(targetMonth+1>=13)
  10751. {
  10752. targetYear += 1;
  10753. targetMonth = 1;
  10754. }
  10755. else
  10756. {
  10757. targetMonth += 1;
  10758. }
  10759. }while((targetYear < (tmNow->tm_year+1900)) ||
  10760. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10761. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10762. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10763. system(cmdBuf);
  10764. // Pack charging & event log
  10765. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10766. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10767. targetYear = tmStart.tm_year;
  10768. targetMonth = tmStart.tm_mon;
  10769. do
  10770. {
  10771. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10772. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10773. if(targetMonth+1>=13)
  10774. {
  10775. targetYear += 1;
  10776. targetMonth = 1;
  10777. }
  10778. else
  10779. {
  10780. targetMonth += 1;
  10781. }
  10782. }while((targetYear < (tmNow->tm_year+1900)) ||
  10783. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10784. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10785. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10786. system(cmdBuf);
  10787. // Combine log file
  10788. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10789. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10790. }
  10791. else
  10792. {
  10793. system("exec /root/logPackTools 'log' 6");
  10794. }
  10795. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10796. system(cmdBuf);
  10797. checkUploadLog();
  10798. //****************location*******************/
  10799. if(strcmp(locationstr,"")==0)
  10800. {
  10801. DEBUG_INFO("location is <Empty>!\n");
  10802. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10803. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10804. goto end;
  10805. }
  10806. memset(protocol, 0, ARRAY_SIZE(protocol));
  10807. memset(user, 0, ARRAY_SIZE(user) );
  10808. memset(password, 0, ARRAY_SIZE(password));
  10809. memset(host, 0, ARRAY_SIZE(host));
  10810. memset(path, 0, ARRAY_SIZE(path));
  10811. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10812. memset(host1, 0, ARRAY_SIZE(host1));
  10813. memset(path1, 0, ARRAY_SIZE(path1));
  10814. /*location: ftp://user:password@host:port/path*/
  10815. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10816. if((access(fnamePlusPath,F_OK))!=-1)
  10817. {
  10818. DEBUG_INFO("fnamePlusPath exist.\n");
  10819. }
  10820. else
  10821. {
  10822. DEBUG_INFO("fnamePlusPath not exist!\n");
  10823. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10824. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10825. goto end;
  10826. }
  10827. if(strchr(locationstr,'@')==NULL)
  10828. {
  10829. sscanf(locationstr,
  10830. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10831. protocol, host, &port, path);
  10832. strcpy(user,"anonymous");
  10833. strcpy(password,"");
  10834. }
  10835. else
  10836. {
  10837. //DEBUG_INFO("pch=%s\n", pch);
  10838. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10839. protocol, user, password, host, &port, path);
  10840. }
  10841. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10842. {
  10843. DEBUG_INFO("protocol is not ftp/http ! \n");
  10844. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10845. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10846. goto end;
  10847. }
  10848. if(strncmp(locationstr,"http", 4) == 0)
  10849. {
  10850. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10851. sprintf(ftppath,"/%s", path);
  10852. do
  10853. {
  10854. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10855. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10856. sleep(3);
  10857. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10858. if(!isSuccess)
  10859. {
  10860. DEBUG_INFO("Diagnostics fail.\n");
  10861. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10862. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10863. sleep(retryIntervalInt);
  10864. }
  10865. else
  10866. {
  10867. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10868. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10869. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10870. }
  10871. retriesInt--;
  10872. }while((isSuccess == 0)&&(retriesInt >= 0));
  10873. }
  10874. else
  10875. {
  10876. sscanf(host,"%[^/]%s",host1, path1);
  10877. if(strlen(path) > 0)
  10878. sprintf(ftppath,"/%s", path);
  10879. else
  10880. sprintf(ftppath,"/%s", path1);
  10881. int ftppathlen=strlen(ftppath);
  10882. int i=1;
  10883. char filenametemp[50];
  10884. while(i < ftppathlen)
  10885. {
  10886. int len=ftppathlen-i;
  10887. if(ftppath[len]== 47) // '/' ascll code: 47
  10888. {
  10889. DEBUG_INFO("find '/' all right\n");
  10890. break;
  10891. }
  10892. i=i+1;
  10893. }
  10894. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10895. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10896. filenametemp[i+1] = 0;
  10897. if(port == 0)
  10898. port = 21;
  10899. do
  10900. {
  10901. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10902. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10903. sleep(3);
  10904. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10905. if(!isSuccess)
  10906. {
  10907. DEBUG_INFO("Diagnostics fail.\n");
  10908. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10909. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10910. sleep(retryIntervalInt);
  10911. }
  10912. else
  10913. {
  10914. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10915. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10916. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10917. }
  10918. retriesInt--;
  10919. }while((!isSuccess)&&(retriesInt >= 0));
  10920. }
  10921. end:
  10922. system("rm -f /mnt/*");
  10923. sleep(5);
  10924. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10925. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10926. interLock.isGetDiagnosticGoing = 0;
  10927. pthread_exit(NULL);
  10928. }
  10929. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10930. {
  10931. mtrace();
  10932. int result = FAIL;
  10933. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10934. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10935. {
  10936. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10937. locallistVersion = -1;
  10938. }
  10939. else
  10940. {
  10941. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10942. locallistVersion = 0;
  10943. OCPP_getListVerion();
  10944. }
  10945. //from db.OCPP_getListVerion
  10946. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10947. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10948. sendGetLocalListVersionConfirmation(uuid,"");
  10949. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10950. return result;
  10951. }
  10952. int handleRemoteStartRequest(char *uuid, char *payload)
  10953. {
  10954. mtrace();
  10955. int result = PASS;
  10956. int connectorIdInt=-1;
  10957. int tempIndex = 0;
  10958. char comfirmstr[20]={0};
  10959. char cmdBuf[512];
  10960. json_object *RemoteStartTransaction;
  10961. FILE *fp;
  10962. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10963. if(server_pending == TRUE)
  10964. {
  10965. result = FAIL;
  10966. }
  10967. RemoteStartTransaction = json_tokener_parse(payload);
  10968. if(!is_error(RemoteStartTransaction))
  10969. {
  10970. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10971. {
  10972. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10973. }
  10974. else
  10975. {
  10976. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10977. {
  10978. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10979. {
  10980. connectorIdInt = (gun_index+1);
  10981. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10982. break;
  10983. }
  10984. }
  10985. }
  10986. if(connectorIdInt == 0)
  10987. {
  10988. DEBUG_WARN("Connector id shall not equal 0.\n");
  10989. result = FAIL;
  10990. }
  10991. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  10992. {
  10993. DEBUG_WARN("idTag should not be NULL.\n");
  10994. result = FAIL;
  10995. }
  10996. else if(connectorIdInt == -1)
  10997. {
  10998. DEBUG_INFO("Connector id does not specific.\n");
  10999. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11000. {
  11001. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11002. // Required data
  11003. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11004. // Optional data
  11005. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11006. {
  11007. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11008. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11009. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11010. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11011. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11012. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11013. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11014. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11015. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11016. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11017. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11018. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11019. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11020. {
  11021. 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")));
  11022. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11023. 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"));
  11024. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11025. 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"));
  11026. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11027. 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")));
  11028. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11029. {
  11030. 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++)
  11031. {
  11032. 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"));
  11033. 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"));
  11034. 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)
  11035. 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"));
  11036. }
  11037. }
  11038. }
  11039. }
  11040. else
  11041. {
  11042. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11043. }
  11044. }
  11045. }
  11046. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11047. {
  11048. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11049. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11050. // Required data
  11051. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11052. // Optional data
  11053. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11054. {
  11055. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11056. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11057. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11058. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11059. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11060. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11061. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11062. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11063. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11064. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11065. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11066. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11067. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11068. {
  11069. 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")));
  11070. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11071. 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"));
  11072. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11073. 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"));
  11074. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11075. 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")));
  11076. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11077. {
  11078. 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++)
  11079. {
  11080. 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"));
  11081. 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"));
  11082. 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)
  11083. 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"));
  11084. }
  11085. }
  11086. }
  11087. }
  11088. else
  11089. {
  11090. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11091. }
  11092. }
  11093. else
  11094. {
  11095. DEBUG_WARN("Connector id is over maximun value.\n");
  11096. result = FAIL;
  11097. }
  11098. }
  11099. if(result == PASS)
  11100. {
  11101. if(connectorIdInt > 0)
  11102. {
  11103. //check Transaction active
  11104. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11105. {
  11106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11107. {
  11108. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11109. }
  11110. else
  11111. {
  11112. tempIndex = connectorIdInt -1;
  11113. }
  11114. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11115. {
  11116. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11117. {
  11118. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11119. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11120. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11121. {
  11122. //Reserved
  11123. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11124. }
  11125. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11126. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11127. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11128. {
  11129. //Reserved
  11130. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11131. {
  11132. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11133. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11134. goto end;
  11135. }
  11136. }
  11137. else
  11138. {
  11139. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11140. {
  11141. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11142. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11143. goto end;
  11144. }
  11145. }//END FOR ELSE
  11146. }
  11147. }// END FOR CHAdeMO_QUANTITY
  11148. }
  11149. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11150. {
  11151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11152. {
  11153. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11154. }
  11155. else
  11156. {
  11157. tempIndex = connectorIdInt -1;
  11158. }
  11159. for (int index = 0; index < CCS_QUANTITY; index++)
  11160. {
  11161. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11162. {
  11163. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11164. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11165. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11166. {
  11167. //Reserved
  11168. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11169. }
  11170. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11171. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11172. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11173. {
  11174. //Reserved
  11175. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11176. {
  11177. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11178. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11179. goto end;
  11180. }
  11181. }
  11182. else
  11183. {
  11184. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11185. {
  11186. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11187. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11188. goto end;
  11189. }
  11190. }// END FOR ELSE
  11191. }
  11192. }// END FOR CCS_QUANTITY
  11193. }
  11194. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11195. {
  11196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11197. {
  11198. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11199. }
  11200. else
  11201. {
  11202. tempIndex = connectorIdInt -1;
  11203. }
  11204. for (int index = 0; index < GB_QUANTITY; index++)
  11205. {
  11206. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11207. {
  11208. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11209. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11210. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11211. {
  11212. //Reserved
  11213. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11214. }
  11215. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11216. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11217. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11218. {
  11219. //Reserved
  11220. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11221. {
  11222. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11223. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11224. goto end;
  11225. }
  11226. }
  11227. else
  11228. {
  11229. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11230. {
  11231. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11232. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11233. goto end;
  11234. }
  11235. }// END FOR ELSE
  11236. }
  11237. } // END FOR GB_QUANTITY
  11238. }
  11239. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11240. {
  11241. tempIndex = connectorIdInt -1;
  11242. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11243. {
  11244. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11245. {
  11246. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11247. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11248. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11249. {
  11250. //Reserved
  11251. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11252. }
  11253. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11254. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11255. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11256. {
  11257. //Reserved
  11258. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11259. {
  11260. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11261. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11262. goto end;
  11263. }
  11264. }
  11265. else
  11266. {
  11267. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11268. {
  11269. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11270. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11271. goto end;
  11272. }
  11273. }// END FOR ELSE
  11274. }
  11275. } // END FOR GB_QUANTITY
  11276. }
  11277. else
  11278. {
  11279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11280. {
  11281. tempIndex = 2;
  11282. }
  11283. else
  11284. {
  11285. tempIndex = connectorIdInt -1;
  11286. }
  11287. for (int index = 0; index < AC_QUANTITY; index++)
  11288. {
  11289. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11290. {
  11291. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11292. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11293. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11294. {
  11295. //Reserved
  11296. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11297. }
  11298. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11299. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11300. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11301. {
  11302. //Reserved
  11303. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11304. {
  11305. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11306. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11307. goto end;
  11308. }
  11309. }
  11310. else
  11311. {
  11312. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11313. {
  11314. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11316. goto end;
  11317. }
  11318. }//END FOR ELSE
  11319. }
  11320. }// END FOR AC_QUANTITY
  11321. }
  11322. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11323. {
  11324. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11325. {
  11326. // Save profile to file
  11327. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11328. system(cmdBuf);
  11329. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11330. fp = fopen(cmdBuf, "w");
  11331. 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));
  11332. fclose(fp);
  11333. }
  11334. else
  11335. {
  11336. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11337. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11338. goto end;
  11339. }
  11340. }
  11341. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11342. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11343. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11344. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11345. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11346. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11347. }
  11348. else
  11349. {
  11350. uint8_t isHasIdleConnector = FALSE;
  11351. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11352. {
  11353. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11354. {
  11355. isHasIdleConnector = TRUE;
  11356. break;
  11357. }
  11358. }
  11359. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11360. {
  11361. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11362. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11363. {
  11364. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11365. {
  11366. // Save profile to file
  11367. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11368. system(cmdBuf);
  11369. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11370. fp = fopen(cmdBuf, "w");
  11371. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11372. fclose(fp);
  11373. refreshStartTimer(&clientTime.RemoteStartWait);
  11374. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11375. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11376. }
  11377. else
  11378. {
  11379. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11380. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11381. }
  11382. }
  11383. else
  11384. {
  11385. refreshStartTimer(&clientTime.RemoteStartWait);
  11386. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11387. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11388. }
  11389. }
  11390. else
  11391. {
  11392. DEBUG_INFO("There is not any connector is idle.\n");
  11393. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11394. }
  11395. }
  11396. }
  11397. else
  11398. {
  11399. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11400. }
  11401. end:
  11402. json_object_put(RemoteStartTransaction);
  11403. sendRemoteStartConfirmation(uuid, comfirmstr);
  11404. return result;
  11405. }
  11406. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11407. {
  11408. mtrace();
  11409. int result = FAIL;
  11410. int match = FALSE;
  11411. int GunNO = 0;
  11412. int tempIndex = 0;
  11413. int transactionIdInt=0;
  11414. int transactionIdIsNULL= TRUE;
  11415. char comfirmstr[20];
  11416. json_object *RemoteStopTransaction;
  11417. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11418. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11419. if(server_pending == TRUE)
  11420. {
  11421. return 0;
  11422. }
  11423. RemoteStopTransaction = json_tokener_parse(payload);
  11424. if(!is_error(RemoteStopTransaction))
  11425. {
  11426. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11427. {
  11428. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11429. transactionIdIsNULL = FALSE;
  11430. }
  11431. }
  11432. json_object_put(RemoteStopTransaction);
  11433. if(transactionIdIsNULL == FALSE)
  11434. {
  11435. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11436. {
  11437. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11438. {
  11439. //check Transaction active
  11440. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11441. {
  11442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11443. {
  11444. tempIndex = ((gun_index==2) ? 1: 0);
  11445. }
  11446. else
  11447. {
  11448. tempIndex = gun_index;
  11449. }
  11450. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11451. {
  11452. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11453. {
  11454. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11455. {
  11456. match = TRUE;
  11457. GunNO = gun_index;
  11458. }
  11459. }
  11460. }// END FOR CHAdeMO_QUANTITY
  11461. }
  11462. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11463. {
  11464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11465. {
  11466. tempIndex = ((gun_index==2) ? 1: 0);
  11467. }
  11468. else
  11469. {
  11470. tempIndex = gun_index;
  11471. }
  11472. for (int index = 0; index < CCS_QUANTITY; index++)
  11473. {
  11474. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11475. {
  11476. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11477. {
  11478. match = TRUE;
  11479. GunNO = gun_index;
  11480. }
  11481. }
  11482. }// END FOR CCS_QUANTITY
  11483. }
  11484. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11485. {
  11486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11487. {
  11488. tempIndex = ((gun_index==2) ? 1: 0);
  11489. }
  11490. else
  11491. {
  11492. tempIndex = gun_index;
  11493. }
  11494. for (int index = 0; index < GB_QUANTITY; index++)
  11495. {
  11496. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11497. {
  11498. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11499. {
  11500. match = TRUE;
  11501. GunNO = gun_index;
  11502. }
  11503. }
  11504. }// END FOR GB_QUANTITY
  11505. }
  11506. else if(gunType[gun_index] == GUN_TYPE_DO)
  11507. {
  11508. tempIndex = gun_index;
  11509. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11510. {
  11511. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11512. {
  11513. 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
  11514. {
  11515. match = TRUE;
  11516. GunNO = gun_index;
  11517. }
  11518. }
  11519. }// END FOR GB_QUANTITY
  11520. }
  11521. else
  11522. {
  11523. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11524. {
  11525. tempIndex = 2;
  11526. }
  11527. else
  11528. {
  11529. tempIndex = gun_index;
  11530. }
  11531. for (int index = 0; index < AC_QUANTITY; index++)
  11532. {
  11533. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11534. {
  11535. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11536. {
  11537. match = TRUE;
  11538. GunNO = gun_index;
  11539. }
  11540. }
  11541. }// END FOR CHAdeMO_QUANTITY
  11542. } // END FOR AC ELSE
  11543. }// CHECK IF ResponseTransactionId == transactionIdInt
  11544. }//END FOR
  11545. if( match == TRUE)
  11546. {
  11547. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11548. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11549. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11550. }
  11551. else
  11552. {
  11553. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11554. }
  11555. }
  11556. else
  11557. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11558. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11559. return result;
  11560. }
  11561. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11562. {
  11563. mtrace();
  11564. int result = FAIL;
  11565. int connectorIdInt=0, reservationIdInt=0;
  11566. int tempIndex = 0;
  11567. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11568. char comfirmstr[20]={0};
  11569. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11570. int c = 0;
  11571. char *loc;
  11572. //char *ptr;
  11573. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11574. strcpy(sstrtemp, stringtrimspace(payload));
  11575. //***(1)connectorId ****/
  11576. c=0;
  11577. loc = strstr(sstrtemp, "connectorId");
  11578. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11579. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11580. {
  11581. sstr[c] = loc[strlen("connectorId")+2+c];
  11582. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11583. c++;
  11584. }
  11585. sstr[c] = '\0';
  11586. connectorIdInt = atoi(sstr);
  11587. //***(2)expiryDate ****/
  11588. loc = strstr(sstrtemp, "expiryDate");
  11589. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11590. c = 0;
  11591. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11592. {
  11593. sstr[c] = loc[3+strlen("expiryDate")+c];
  11594. c++;
  11595. }
  11596. sstr[c] = '\0';
  11597. strcpy(expiryDatestr, sstr);
  11598. //***(3)idTag ****/
  11599. loc = strstr(sstrtemp, "idTag");
  11600. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11601. c = 0;
  11602. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11603. {
  11604. sstr[c] = loc[3+strlen("idTag")+c];
  11605. c++;
  11606. }
  11607. sstr[c] = '\0';
  11608. strcpy(idTagstr, sstr);
  11609. //***(4)parentIdTag ****/
  11610. loc = strstr(sstrtemp, "parentIdTag");
  11611. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11612. c = 0;
  11613. if(loc == NULL)
  11614. {
  11615. strcpy(parentIdTagstr, "");
  11616. }
  11617. else
  11618. {
  11619. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11620. {
  11621. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11622. c++;
  11623. }
  11624. sstr[c] = '\0';
  11625. strcpy(parentIdTagstr, sstr);
  11626. }
  11627. //***(5)reservationId ****/
  11628. c=0;
  11629. loc = strstr(sstrtemp, "reservationId");
  11630. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11631. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11632. {
  11633. sstr[c] = loc[strlen("reservationId")+2+c];
  11634. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11635. c++;
  11636. }
  11637. sstr[c] = '\0';
  11638. reservationIdInt = atoi(sstr);
  11639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11640. /*
  11641. enum SYSTEM_STATUS
  11642. {
  11643. SYS_MODE_BOOTING = 0,
  11644. SYS_MODE_IDLE = 1,
  11645. SYS_MODE_AUTHORIZING = 2,
  11646. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11647. SYS_MODE_REASSIGN = 4,
  11648. SYS_MODE_PREPARING = 5,
  11649. SYS_MODE_PREPARE_FOR_EV = 6,
  11650. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11651. SYS_MODE_CHARGING = 8,
  11652. SYS_MODE_TERMINATING = 9,
  11653. SYS_MODE_COMPLETE = 10,
  11654. SYS_MODE_ALARM = 11,
  11655. SYS_MODE_FAULT = 12,
  11656. SYS_MODE_RESERVATION = 13,
  11657. SYS_MODE_BOOKING = 14,
  11658. SYS_MODE_MAINTAIN = 15,
  11659. SYS_MODE_DEBUG = 16,
  11660. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11661. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11662. SYS_MODE_UPDATE = 19
  11663. };
  11664. */
  11665. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11666. {
  11667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11668. goto end;
  11669. }
  11670. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11671. {
  11672. //check Transaction active
  11673. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11674. {
  11675. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11676. {
  11677. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11678. }
  11679. else
  11680. {
  11681. tempIndex = connectorIdInt -1;
  11682. }
  11683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11684. {
  11685. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11686. {
  11687. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11688. {
  11689. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11690. {
  11691. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11692. {
  11693. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11694. {
  11695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11696. }
  11697. else
  11698. {
  11699. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11701. }
  11702. }
  11703. 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'))
  11704. {
  11705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11706. }
  11707. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11708. {
  11709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11710. }
  11711. else
  11712. {
  11713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11714. }
  11715. }
  11716. 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
  11717. {
  11718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11719. }
  11720. }
  11721. else
  11722. {
  11723. //replace reservation
  11724. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11726. }
  11727. }
  11728. } // END FOR CHAdeMO_QUANTITY
  11729. }
  11730. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11731. {
  11732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11733. {
  11734. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11735. }
  11736. else
  11737. {
  11738. tempIndex = connectorIdInt -1;
  11739. }
  11740. for (int index = 0; index < CCS_QUANTITY; index++)
  11741. {
  11742. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11743. {
  11744. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11745. {
  11746. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11747. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11748. {
  11749. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11750. {
  11751. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11752. {
  11753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11754. }
  11755. else
  11756. {
  11757. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11759. }
  11760. }
  11761. 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'))
  11762. {
  11763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11764. }
  11765. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11766. {
  11767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11768. }
  11769. else
  11770. {
  11771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11772. }
  11773. }
  11774. 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
  11775. {
  11776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11777. }
  11778. }
  11779. else
  11780. {
  11781. //replace reservation
  11782. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11783. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11784. }
  11785. }
  11786. } // END FOR CCS_QUANTITY
  11787. }
  11788. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11789. {
  11790. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11791. {
  11792. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11793. }
  11794. else
  11795. {
  11796. tempIndex = connectorIdInt -1;
  11797. }
  11798. for (int index = 0; index < GB_QUANTITY; index++)
  11799. {
  11800. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11801. {
  11802. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11803. {
  11804. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11805. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11806. {
  11807. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11808. {
  11809. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11810. {
  11811. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11812. }
  11813. else
  11814. {
  11815. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11817. }
  11818. }
  11819. 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'))
  11820. {
  11821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11822. }
  11823. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11824. {
  11825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11826. }
  11827. else
  11828. {
  11829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11830. }
  11831. }
  11832. 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
  11833. {
  11834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11835. }
  11836. }
  11837. else
  11838. {
  11839. //replace reservation
  11840. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11842. }
  11843. }
  11844. }// END FOR GB_QUANTITY
  11845. }
  11846. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11847. {
  11848. tempIndex = connectorIdInt -1;
  11849. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11850. {
  11851. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11852. {
  11853. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11854. {
  11855. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11856. 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
  11857. {
  11858. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11859. {
  11860. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11861. {
  11862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11863. }
  11864. else
  11865. {
  11866. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11868. }
  11869. }
  11870. 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'))
  11871. {
  11872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11873. }
  11874. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11875. {
  11876. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11877. }
  11878. else
  11879. {
  11880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11881. }
  11882. }
  11883. 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
  11884. {
  11885. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11886. }
  11887. }
  11888. else
  11889. {
  11890. //replace reservation
  11891. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11893. }
  11894. }
  11895. }// END FOR GB_QUANTITY
  11896. }
  11897. else
  11898. {
  11899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11900. {
  11901. tempIndex = 2;
  11902. }
  11903. else
  11904. {
  11905. tempIndex = (connectorIdInt -1);
  11906. }
  11907. for (int index = 0; index < AC_QUANTITY; index++)
  11908. {
  11909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11910. {
  11911. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11912. {
  11913. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11914. {
  11915. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11916. {
  11917. 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))
  11918. {
  11919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11920. }
  11921. else
  11922. {
  11923. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11925. }
  11926. }
  11927. 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'))
  11928. {
  11929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11930. }
  11931. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11932. {
  11933. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11934. }
  11935. else
  11936. {
  11937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11938. }
  11939. }
  11940. 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
  11941. {
  11942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11943. }
  11944. }
  11945. else
  11946. {
  11947. //replace reservation
  11948. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11950. }
  11951. }
  11952. } // END FOR AC_QUANTITY
  11953. }
  11954. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11955. }
  11956. else if(connectorIdInt == 0)
  11957. {
  11958. //check Transaction active
  11959. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11960. {
  11961. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11962. {
  11963. 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'))
  11964. {
  11965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11966. goto end;
  11967. }
  11968. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11969. {
  11970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11971. goto end;
  11972. }
  11973. 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
  11974. {
  11975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11976. goto end;
  11977. }
  11978. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11979. {
  11980. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11981. goto end;
  11982. }
  11983. }
  11984. }// END FOR CHAdeMO_QUANTITY
  11985. for (int index = 0; index < CCS_QUANTITY; index++)
  11986. {
  11987. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11988. {
  11989. 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'))
  11990. {
  11991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11992. goto end;
  11993. }
  11994. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11995. {
  11996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11997. goto end;
  11998. }
  11999. 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
  12000. {
  12001. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12002. goto end;
  12003. }
  12004. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12005. {
  12006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12007. goto end;
  12008. }
  12009. }
  12010. } // END FOR CCS_QUANTITY
  12011. for (int index = 0; index < GB_QUANTITY; index++)
  12012. {
  12013. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12014. {
  12015. 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'))
  12016. {
  12017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12018. goto end;
  12019. }
  12020. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12021. {
  12022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12023. goto end;
  12024. }
  12025. 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
  12026. {
  12027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12028. goto end;
  12029. }
  12030. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12031. {
  12032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12033. goto end;
  12034. }
  12035. }
  12036. } // END FOR GB_QUANTITY
  12037. for (int index = 0; index < AC_QUANTITY; index++)
  12038. {
  12039. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12040. {
  12041. 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'))
  12042. {
  12043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12044. goto end;
  12045. }
  12046. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12047. {
  12048. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12049. goto end;
  12050. }
  12051. 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
  12052. {
  12053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12054. goto end;
  12055. }
  12056. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12057. {
  12058. 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))
  12059. {
  12060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12061. goto end;
  12062. }
  12063. }
  12064. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12065. {
  12066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12067. goto end;
  12068. }
  12069. }
  12070. }// END FOR AC_QUANTITY
  12071. //The connectorId is 0
  12072. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12074. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12075. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12076. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12077. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12078. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12079. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12080. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12081. result = TRUE;
  12082. return result;
  12083. }
  12084. else
  12085. {
  12086. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12087. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12088. }
  12089. if(strcmp(comfirmstr,"Accepted") == 0)
  12090. {
  12091. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12092. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12093. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12094. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12095. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12096. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12097. result = TRUE;
  12098. return result;
  12099. }
  12100. end:
  12101. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12102. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12103. return result;
  12104. }
  12105. int handleResetRequest(char *uuid, char *payload)
  12106. {
  12107. mtrace();
  12108. int result = FAIL;
  12109. char sstr[10]={0},sstrtemp[30]={ 0 };
  12110. char typestr[10]={0};
  12111. char comfirmstr[20]={0};
  12112. int c = 0;
  12113. char *loc;
  12114. DEBUG_INFO("handleResetRequest...\n");
  12115. strcpy(sstrtemp, stringtrimspace(payload));
  12116. loc = strstr(sstrtemp, "type");
  12117. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12118. c = 0;
  12119. while (loc[3+strlen("type")+c] != '\"')
  12120. {
  12121. sstr[c] = loc[3+strlen("type")+c];
  12122. c++;
  12123. }
  12124. sstr[c] = '\0';
  12125. strcpy(typestr,sstr);
  12126. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12127. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12128. {
  12129. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12130. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12131. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12132. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12133. }
  12134. else
  12135. {
  12136. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12137. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12138. result = PASS;
  12139. }
  12140. sendResetConfirmation(uuid, comfirmstr);
  12141. return result;
  12142. }
  12143. int handleSendLocalListRequest(char *uuid, char *payload)
  12144. {
  12145. mtrace();
  12146. int result = FAIL;
  12147. char comfirmstr[20];
  12148. int checkState_Faulted = FALSE;
  12149. json_object *SendLocalList;
  12150. DEBUG_INFO("handleSendLocalListRequest...\n");
  12151. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12152. {
  12153. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12154. goto end;
  12155. }
  12156. //check Charge Point state
  12157. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12158. {
  12159. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12160. {
  12161. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12162. }
  12163. }
  12164. for (int index = 0; index < CCS_QUANTITY; index++)
  12165. {
  12166. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12167. {
  12168. checkState_Faulted = TRUE; //OCPP Status
  12169. }
  12170. }
  12171. for (int index = 0; index < GB_QUANTITY; index++)
  12172. {
  12173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12174. {
  12175. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12176. }
  12177. }
  12178. //check Charge Point state
  12179. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12180. {
  12181. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12182. {
  12183. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12184. }
  12185. }
  12186. //check Charge Point state
  12187. for (int index = 0; index < AC_QUANTITY; index++)
  12188. {
  12189. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12190. {
  12191. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12192. }
  12193. }
  12194. if(checkState_Faulted == TRUE)
  12195. {
  12196. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12197. goto end;
  12198. }
  12199. // Parsing payload
  12200. SendLocalList = json_tokener_parse(payload);
  12201. if(!is_error(SendLocalList))
  12202. {
  12203. // Required data
  12204. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12205. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12206. // Optional data
  12207. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12208. {
  12209. //Check UpdateType
  12210. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12211. {
  12212. //Local list full update
  12213. DEBUG_INFO("Local list full update.\n");
  12214. locallistVersion = 0;
  12215. OCPP_getListVerion();
  12216. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12217. {
  12218. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12219. goto end;
  12220. }
  12221. OCPP_cleanLocalList();
  12222. }
  12223. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12224. {
  12225. //Local list different update
  12226. DEBUG_INFO("Local list different update.\n");
  12227. locallistVersion = 0;
  12228. OCPP_getListVerion();
  12229. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12230. {
  12231. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12232. goto end;
  12233. }
  12234. }
  12235. else
  12236. {
  12237. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12238. goto end;
  12239. }
  12240. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12241. {
  12242. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12243. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12244. goto end;
  12245. }
  12246. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12247. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12248. {
  12249. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  12250. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12251. {
  12252. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  12253. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12254. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  12255. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12256. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  12257. }
  12258. // Add to db
  12259. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12260. {
  12261. //Local list full update
  12262. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12263. idx,
  12264. ShmOCPP16Data->SendLocalList.ListVersion,
  12265. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12266. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12267. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12268. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12269. // update list
  12270. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12271. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12272. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12273. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12274. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12275. }
  12276. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12277. {
  12278. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12279. idx,
  12280. ShmOCPP16Data->SendLocalList.ListVersion,
  12281. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12282. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12283. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12284. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12285. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12286. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12287. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12288. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12289. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12290. }
  12291. }
  12292. }
  12293. else
  12294. {
  12295. //Check UpdateType
  12296. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12297. {
  12298. //Local list full update
  12299. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12300. OCPP_cleanLocalList();
  12301. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12302. goto end;
  12303. }
  12304. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12305. {
  12306. //Local list different update
  12307. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12308. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12309. goto end;
  12310. }
  12311. }
  12312. result = PASS;
  12313. }
  12314. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12315. end:
  12316. json_object_put(SendLocalList);
  12317. sendSendLocalListConfirmation(uuid, comfirmstr);
  12318. return result;
  12319. }
  12320. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12321. {
  12322. mtrace();
  12323. int result = FAIL;
  12324. struct StructSetChargingProfile SetProfileReq = {0};
  12325. int tempchargingProfileIdInt;
  12326. int tempstackLevelInt;
  12327. int chargingSchedulePeriodCount = 0;
  12328. char comfirmstr[20]={0};
  12329. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12330. char rmFileCmd[128]={0};
  12331. int profileQuantity = 0;
  12332. int replaceableProfileCnt = 0;
  12333. json_object *SetChargingProfile;
  12334. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12335. SetChargingProfile = json_tokener_parse(payload);
  12336. if(!is_error(SetChargingProfile))
  12337. {
  12338. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12339. {
  12340. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12341. }
  12342. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12343. {
  12344. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12345. {
  12346. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12347. }
  12348. else
  12349. {
  12350. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12351. DEBUG_WARN("Cannot find chargingProfileId field.");
  12352. goto end;
  12353. }
  12354. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12355. {
  12356. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12357. }
  12358. else
  12359. {
  12360. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12361. DEBUG_WARN("Cannot find stackLevel field.");
  12362. goto end;
  12363. }
  12364. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12365. {
  12366. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12367. }
  12368. else
  12369. {
  12370. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12371. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12372. goto end;
  12373. }
  12374. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12375. {
  12376. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12377. }
  12378. else
  12379. {
  12380. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12381. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12382. goto end;
  12383. }
  12384. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12385. {
  12386. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12387. }
  12388. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12389. {
  12390. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12391. }
  12392. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12393. {
  12394. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12395. }
  12396. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12397. {
  12398. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12399. }
  12400. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12401. {
  12402. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12403. {
  12404. 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")));
  12405. }
  12406. else
  12407. {
  12408. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12409. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12410. goto end;
  12411. }
  12412. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12413. {
  12414. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12415. }
  12416. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12417. {
  12418. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12419. }
  12420. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12421. {
  12422. 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")));
  12423. }
  12424. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12425. {
  12426. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12427. if(chargingSchedulePeriodCount <= 10)
  12428. {
  12429. 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++)
  12430. {
  12431. 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)
  12432. {
  12433. 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"));
  12434. }
  12435. else
  12436. {
  12437. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12438. DEBUG_WARN("Cannot find startPeriod field.");
  12439. goto end;
  12440. }
  12441. 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)
  12442. {
  12443. 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"));
  12444. }
  12445. else
  12446. {
  12447. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12448. DEBUG_WARN("Cannot find limit field.");
  12449. goto end;
  12450. }
  12451. 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)
  12452. {
  12453. 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"));
  12454. }
  12455. }
  12456. }
  12457. }
  12458. else
  12459. {
  12460. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12461. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12462. goto end;
  12463. }
  12464. }
  12465. else
  12466. {
  12467. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12468. DEBUG_WARN("Cannot find chargingSchedule field.");
  12469. goto end;
  12470. }
  12471. }
  12472. }
  12473. // Profile periods quantity check
  12474. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12475. {
  12476. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12477. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12478. goto end;
  12479. }
  12480. // Check invalid limit
  12481. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12482. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12483. {
  12484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12485. {
  12486. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12487. {
  12488. 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)))) ||
  12489. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12490. {
  12491. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12492. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12493. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12494. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12495. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12496. goto end;
  12497. }
  12498. }
  12499. }
  12500. else
  12501. {
  12502. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12503. {
  12504. 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) ||
  12505. (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)))
  12506. {
  12507. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12508. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12509. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12510. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12511. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12512. goto end;
  12513. }
  12514. }
  12515. }
  12516. }
  12517. // Profile purpose info check
  12518. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12519. {
  12520. FILE *fp;
  12521. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12522. if(SetProfileReq.ConnectorId != 0)
  12523. {
  12524. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12525. DEBUG_WARN("Profile connector id is not 0.\n");
  12526. goto end;
  12527. }
  12528. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12529. if (!fp)
  12530. {
  12531. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12532. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12533. }
  12534. else
  12535. {
  12536. char *line = NULL;
  12537. size_t len = 0;
  12538. while(getline(&line, &len, fp) != -1)
  12539. {
  12540. json_object *obj = NULL;
  12541. obj = json_tokener_parse(line);
  12542. if(is_error(obj))
  12543. {
  12544. DEBUG_ERROR("Parse txProfile from file error.\n");
  12545. }
  12546. else
  12547. {
  12548. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12549. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12550. {
  12551. profileQuantity += 1;
  12552. }
  12553. else
  12554. replaceableProfileCnt += 1;
  12555. }
  12556. }
  12557. }
  12558. fclose(fp);
  12559. }
  12560. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12561. {
  12562. FILE *fp;
  12563. char filename[128]={0};
  12564. int tmpProfileQuantity;
  12565. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12566. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12567. {
  12568. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12569. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12570. goto end;
  12571. }
  12572. if(SetProfileReq.ConnectorId == 0)
  12573. {
  12574. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12575. {
  12576. tmpProfileQuantity = 0;
  12577. memset(filename, 0, ARRAY_SIZE(filename));
  12578. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12579. fp = fopen(filename, "r");
  12580. if (!fp)
  12581. {
  12582. DEBUG_INFO("%s does not create.\n", filename);
  12583. fp = fopen(filename, "w+");
  12584. }
  12585. else
  12586. {
  12587. char *line = NULL;
  12588. size_t len = 0;
  12589. while(getline(&line, &len, fp) != -1)
  12590. {
  12591. json_object *obj = NULL;
  12592. obj = json_tokener_parse(line);
  12593. if(is_error(obj))
  12594. {
  12595. DEBUG_ERROR("Parse txProfile from file error.\n");
  12596. }
  12597. else
  12598. {
  12599. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12600. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12601. {
  12602. tmpProfileQuantity += 1;
  12603. }
  12604. else
  12605. replaceableProfileCnt += 1;
  12606. }
  12607. }
  12608. }
  12609. fclose(fp);
  12610. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12611. }
  12612. }
  12613. else
  12614. {
  12615. memset(filename, 0, ARRAY_SIZE(filename));
  12616. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12617. fp = fopen(filename, "r");
  12618. if (!fp)
  12619. {
  12620. DEBUG_INFO("%s does not create.\n", filename);
  12621. fp = fopen(filename, "w+");
  12622. }
  12623. else
  12624. {
  12625. char *line = NULL;
  12626. size_t len = 0;
  12627. while(getline(&line, &len, fp) != -1)
  12628. {
  12629. json_object *obj = NULL;
  12630. obj = json_tokener_parse(line);
  12631. if(is_error(obj))
  12632. {
  12633. DEBUG_ERROR("Parse txProfile from file error.\n");
  12634. }
  12635. else
  12636. {
  12637. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12638. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12639. {
  12640. profileQuantity += 1;
  12641. }
  12642. else
  12643. replaceableProfileCnt += 1;
  12644. }
  12645. }
  12646. }
  12647. fclose(fp);
  12648. }
  12649. }
  12650. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12651. {
  12652. int isMatchTransactiodId= FALSE;
  12653. FILE *fp;
  12654. char filename[128]={0};
  12655. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12656. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12657. if(SetProfileReq.ConnectorId == 0)
  12658. {
  12659. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12660. DEBUG_WARN("Profile connector id is 0.\n");
  12661. goto end;
  12662. }
  12663. int tempIndex = 0;
  12664. //check Transaction active
  12665. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12666. {
  12667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12668. {
  12669. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12670. }
  12671. else
  12672. {
  12673. tempIndex = SetProfileReq.ConnectorId -1;
  12674. }
  12675. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12676. {
  12677. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12678. {
  12679. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12680. {
  12681. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12682. {
  12683. isMatchTransactiodId = TRUE;
  12684. break;
  12685. }
  12686. }
  12687. }
  12688. }
  12689. }
  12690. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12691. {
  12692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12693. {
  12694. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12695. }
  12696. else
  12697. {
  12698. tempIndex = SetProfileReq.ConnectorId -1;
  12699. }
  12700. for (int index = 0; index < CCS_QUANTITY; index++)
  12701. {
  12702. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12703. {
  12704. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12705. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12706. {
  12707. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12708. {
  12709. isMatchTransactiodId = TRUE;
  12710. break;
  12711. }
  12712. }
  12713. }
  12714. }
  12715. }
  12716. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12717. {
  12718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12719. {
  12720. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12721. }
  12722. else
  12723. {
  12724. tempIndex = SetProfileReq.ConnectorId -1;
  12725. }
  12726. for (int index = 0; index < GB_QUANTITY; index++)
  12727. {
  12728. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12729. {
  12730. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12731. {
  12732. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12733. {
  12734. isMatchTransactiodId = TRUE;
  12735. break;
  12736. }
  12737. }
  12738. }
  12739. }
  12740. }
  12741. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12742. {
  12743. tempIndex = SetProfileReq.ConnectorId -1;
  12744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12745. {
  12746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12747. {
  12748. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12749. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12750. {
  12751. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12752. {
  12753. isMatchTransactiodId = TRUE;
  12754. break;
  12755. }
  12756. }
  12757. }
  12758. }
  12759. }
  12760. else
  12761. {
  12762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12763. {
  12764. tempIndex = 2;
  12765. }
  12766. else
  12767. {
  12768. tempIndex = (SetProfileReq.ConnectorId -1);
  12769. }
  12770. for (int index = 0; index < AC_QUANTITY; index++)
  12771. {
  12772. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12773. {
  12774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12775. {
  12776. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12777. {
  12778. isMatchTransactiodId = TRUE;
  12779. break;
  12780. }
  12781. }
  12782. }
  12783. }
  12784. }
  12785. //check Transaction active
  12786. if(isMatchTransactiodId == FALSE)
  12787. {
  12788. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12789. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12790. goto end;
  12791. }
  12792. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12793. {
  12794. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12795. DEBUG_WARN("Connector id is over max gun number.\n");
  12796. goto end;
  12797. }
  12798. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12799. fp = fopen(filename, "r");
  12800. if (!fp)
  12801. {
  12802. DEBUG_INFO("%s does not create.\n", filename);
  12803. fp = fopen(filename, "w+");
  12804. }
  12805. else
  12806. {
  12807. char *line = NULL;
  12808. size_t len = 0;
  12809. while(getline(&line, &len, fp) != -1)
  12810. {
  12811. json_object *obj = NULL;
  12812. obj = json_tokener_parse(line);
  12813. if(is_error(obj))
  12814. {
  12815. DEBUG_ERROR("Parse txProfile from file error.\n");
  12816. }
  12817. else
  12818. {
  12819. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12820. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12821. {
  12822. profileQuantity += 1;
  12823. }
  12824. else
  12825. replaceableProfileCnt += 1;
  12826. }
  12827. }
  12828. }
  12829. fclose(fp);
  12830. }
  12831. // Check ChargeProfileMaxStackLevel
  12832. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12833. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12834. {
  12835. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12836. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12837. goto end;
  12838. }
  12839. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12840. {
  12841. FILE *fp;
  12842. char dataLine[4096]={0};
  12843. char fnametemp[128]={0};
  12844. int tmpProfileQuantity;
  12845. //Check ChargePointMaxProfile.json exit
  12846. profileQuantity = 0;
  12847. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12848. {
  12849. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12850. //Check Charging Profile Count
  12851. tmpProfileQuantity = 0;
  12852. while(fscanf(fp, "%s", dataLine) != EOF)
  12853. {
  12854. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12855. {
  12856. profileQuantity += 1;
  12857. tmpProfileQuantity += 1;
  12858. }
  12859. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12860. }
  12861. fclose(fp);
  12862. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12863. }
  12864. //Check TxDefaultProfile_%d.json
  12865. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12866. {
  12867. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12868. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12869. if((access(fnametemp,F_OK))!=-1)
  12870. {
  12871. fp = fopen(fnametemp, "r");
  12872. //Check Charging Profile Count
  12873. tmpProfileQuantity = 0;
  12874. while(fscanf(fp, "%s", dataLine) != EOF)
  12875. {
  12876. //DEBUG_INFO("word=%s\n",word);
  12877. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12878. {
  12879. profileQuantity += 1;
  12880. tmpProfileQuantity += 1;
  12881. }
  12882. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12883. }
  12884. fclose(fp);
  12885. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12886. }
  12887. }
  12888. //Check TxProfile_%d.json
  12889. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12890. {
  12891. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12892. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12893. if((access(fnametemp,F_OK))!=-1)
  12894. {
  12895. fp = fopen(fnametemp, "r");
  12896. //Check Charging Profile Count
  12897. tmpProfileQuantity = 0;
  12898. while(fscanf(fp, "%s", dataLine) != EOF)
  12899. {
  12900. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12901. {
  12902. profileQuantity += 1;
  12903. tmpProfileQuantity += 1;
  12904. }
  12905. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12906. }
  12907. fclose(fp);
  12908. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12909. }
  12910. }
  12911. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12912. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12913. // To check total Profile quantity
  12914. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12915. {
  12916. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12917. {
  12918. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12919. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12920. goto end;
  12921. }
  12922. }
  12923. else
  12924. {
  12925. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12926. {
  12927. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12928. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12929. goto end;
  12930. }
  12931. }
  12932. }
  12933. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12934. //**********************************Write to File********************************************************/
  12935. {
  12936. FILE *infile;
  12937. FILE *outfile;
  12938. char dataLine[4096]={0};
  12939. char filename[128]={0};
  12940. int chkChar=0;
  12941. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12942. {
  12943. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12944. {
  12945. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12946. }
  12947. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12948. {
  12949. if(SetProfileReq.ConnectorId==0)
  12950. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12951. else
  12952. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12953. }
  12954. else
  12955. {
  12956. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12957. }
  12958. infile = fopen (filename, "r");
  12959. outfile = fopen (tempfile, "w");
  12960. chkChar = fgetc(infile);
  12961. rewind(infile);
  12962. if(chkChar == EOF)
  12963. {
  12964. // Profile is empty
  12965. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12966. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12967. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12968. fclose(infile);
  12969. fclose(outfile);
  12970. sprintf(rmFileCmd,"rm -f %s",filename);
  12971. system(rmFileCmd);
  12972. rename(tempfile, filename);
  12973. }
  12974. else
  12975. {
  12976. // Profile is not empty
  12977. int ChargingProfileAdded = FALSE;
  12978. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12979. {
  12980. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12981. json_object *tmpChargingProfile;
  12982. tmpChargingProfile = json_tokener_parse(dataLine);
  12983. if(!is_error(SetChargingProfile))
  12984. {
  12985. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12986. {
  12987. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12988. {
  12989. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12990. }
  12991. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12992. {
  12993. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12994. }
  12995. }
  12996. }
  12997. json_object_put(tmpChargingProfile);
  12998. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12999. {
  13000. if(ChargingProfileAdded == FALSE)
  13001. {
  13002. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13003. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13004. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13005. ChargingProfileAdded = TRUE;
  13006. }
  13007. }
  13008. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13009. {
  13010. if(ChargingProfileAdded == FALSE)
  13011. {
  13012. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13013. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13014. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13015. ChargingProfileAdded = TRUE;
  13016. }
  13017. }
  13018. else
  13019. {
  13020. fprintf(outfile,"%s\n",dataLine);
  13021. if(ChargingProfileAdded == FALSE)
  13022. {
  13023. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13024. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13025. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13026. ChargingProfileAdded = TRUE;
  13027. }
  13028. }
  13029. } // end of while loop
  13030. fclose(infile);
  13031. fclose(outfile);
  13032. sprintf(rmFileCmd,"rm -f %s",filename);
  13033. system(rmFileCmd);
  13034. rename(tempfile, filename);
  13035. }
  13036. }
  13037. sleep(1);
  13038. result = TRUE;
  13039. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13040. }
  13041. end:
  13042. json_object_put(SetChargingProfile);
  13043. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13044. {
  13045. if(SetProfileReq.ConnectorId == 0)
  13046. {
  13047. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13048. {
  13049. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13050. }
  13051. }
  13052. else
  13053. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13054. }
  13055. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13056. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13057. return result;
  13058. }
  13059. int handleTriggerMessageRequest(char *uuid, char *payload)
  13060. {
  13061. mtrace();
  13062. int result = FAIL;
  13063. int connectorIdIsNULL = FALSE;
  13064. int connectorIdInt =0;
  13065. char sstr[40]={0},sstrtemp[100]={ 0 };
  13066. char requestedMessagestr[40]={0};
  13067. char comfirmstr[20]={0};
  13068. int c = 0;
  13069. char *loc;
  13070. DEBUG_INFO("handleTriggerMessageRequest\n");
  13071. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13072. strcpy(sstrtemp, stringtrimspace(payload));
  13073. c = 0;
  13074. loc = strstr(sstrtemp, "requestedMessage");
  13075. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13076. {
  13077. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13078. c++;
  13079. }
  13080. sstr[c] = '\0';
  13081. strcpy(requestedMessagestr, sstr);
  13082. c = 0;
  13083. loc = strstr(sstrtemp, "connectorId");
  13084. if(loc == NULL)
  13085. {
  13086. connectorIdIsNULL = TRUE;
  13087. }
  13088. else
  13089. {
  13090. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13091. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13092. {
  13093. sstr[c] = loc[strlen("connectorId")+2+c];
  13094. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13095. c++;
  13096. }
  13097. sstr[c] = '\0';
  13098. connectorIdInt = atoi(sstr);
  13099. }
  13100. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13101. {
  13102. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13103. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13104. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13105. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13106. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13107. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13108. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13109. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13110. {
  13111. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13112. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13113. return TRUE;
  13114. }
  13115. else
  13116. {
  13117. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13118. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13119. }
  13120. }
  13121. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13122. {
  13123. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13124. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13125. return TRUE;
  13126. }
  13127. //==========================
  13128. // Trigger message
  13129. //==========================
  13130. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13131. {
  13132. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13133. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13134. {
  13135. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13136. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13137. }
  13138. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13139. }
  13140. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13141. {
  13142. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13143. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13144. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13145. }
  13146. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13147. {
  13148. //sendBootNotificationRequest();
  13149. server_sign = FALSE;
  13150. }
  13151. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13152. {
  13153. refreshStartTimer(&clientTime.Heartbeat);
  13154. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13155. }
  13156. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13157. {
  13158. if(connectorIdIsNULL == FALSE)
  13159. {
  13160. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13161. {
  13162. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13163. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13164. }
  13165. }
  13166. else
  13167. {
  13168. for(int idx=0;idx< gunTotalNumber;idx++)
  13169. {
  13170. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13171. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13172. }
  13173. }
  13174. }
  13175. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13176. {
  13177. if(connectorIdIsNULL == FALSE)
  13178. {
  13179. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13180. {
  13181. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13182. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13183. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13184. }
  13185. }
  13186. else
  13187. {
  13188. for(int idx=0;idx< gunTotalNumber;idx++)
  13189. {
  13190. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13191. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13192. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13193. }
  13194. }
  13195. }
  13196. return result;
  13197. }
  13198. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13199. {
  13200. mtrace();
  13201. int result = FAIL;
  13202. int connectorIdInt =0;
  13203. char comfirmstr[20]={0};
  13204. int tempIndex = 0;
  13205. json_object *UnlockConnector;
  13206. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13207. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13208. UnlockConnector = json_tokener_parse(payload);
  13209. if(!is_error(UnlockConnector))
  13210. {
  13211. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13212. {
  13213. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13214. }
  13215. }
  13216. json_object_put(UnlockConnector);
  13217. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13218. if(gunTotalNumber == 0)
  13219. {
  13220. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13221. goto end;
  13222. }
  13223. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13224. {
  13225. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13226. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13227. goto end;
  13228. }
  13229. else
  13230. {
  13231. //check Transaction active
  13232. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13233. {
  13234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13235. {
  13236. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13237. }
  13238. else
  13239. {
  13240. tempIndex = connectorIdInt -1;
  13241. }
  13242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13243. {
  13244. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13245. {
  13246. //stop Transaction
  13247. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13248. }
  13249. }
  13250. }
  13251. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13252. {
  13253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13254. {
  13255. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13256. }
  13257. else
  13258. {
  13259. tempIndex = connectorIdInt -1;
  13260. }
  13261. for (int index = 0; index < CCS_QUANTITY; index++)
  13262. {
  13263. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13264. {
  13265. //stop Transaction
  13266. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13267. }
  13268. }
  13269. }
  13270. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13271. {
  13272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13273. {
  13274. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13275. }
  13276. else
  13277. {
  13278. tempIndex = connectorIdInt -1;
  13279. }
  13280. for (int index = 0; index < GB_QUANTITY; index++)
  13281. {
  13282. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13283. {
  13284. //stop Transaction
  13285. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13286. }
  13287. }
  13288. }
  13289. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13290. {
  13291. tempIndex = connectorIdInt -1;
  13292. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13293. {
  13294. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13295. {
  13296. //stop Transaction
  13297. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13298. }
  13299. }
  13300. }
  13301. else
  13302. {
  13303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13304. {
  13305. tempIndex = 2;
  13306. }
  13307. else
  13308. {
  13309. tempIndex = connectorIdInt-1;
  13310. }
  13311. for (int index = 0; index < AC_QUANTITY; index++)
  13312. {
  13313. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13314. {
  13315. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13316. }
  13317. }
  13318. }
  13319. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13320. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13321. result = TRUE;
  13322. return result;
  13323. }
  13324. end:
  13325. //json_object_put(obj); --- remove temporally
  13326. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13327. return result;
  13328. }
  13329. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13330. {
  13331. mtrace();
  13332. int result = FAIL;
  13333. pthread_t t;
  13334. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13335. sendUpdateFirmwareConfirmation(uuid);
  13336. if(!interLock.isUpdateFirmwareGoing)
  13337. {
  13338. interLock.isUpdateFirmwareGoing = 1;
  13339. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13340. sleep(1);
  13341. }
  13342. else
  13343. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13344. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13345. return result;
  13346. }
  13347. void *UpdateFirmwareProcess(void *data)
  13348. {
  13349. pthread_detach(pthread_self());
  13350. mtrace();
  13351. int retriesInt =0, retryIntervalInt=0;
  13352. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13353. int port=0;
  13354. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13355. int isSuccess = 0;
  13356. char ftpbuf[1024];
  13357. char temp[1024];
  13358. char * pch;
  13359. json_object *UpdateFirmware;
  13360. UpdateFirmware = json_tokener_parse(data);
  13361. if(!is_error(UpdateFirmware))
  13362. {
  13363. // Required data
  13364. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13365. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13366. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13367. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13368. // Optional data
  13369. if(json_object_object_get(UpdateFirmware, "retries"))
  13370. {
  13371. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13372. }
  13373. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13374. {
  13375. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13376. }
  13377. }
  13378. json_object_put(UpdateFirmware);
  13379. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13380. memset(path, 0, ARRAY_SIZE(path));
  13381. // Wait retrieveData
  13382. if(strlen(retrieveDatestr) > 10)
  13383. {
  13384. do
  13385. {
  13386. sleep(1);
  13387. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13388. }
  13389. // Ready to download
  13390. system("rm -f /mnt/*");
  13391. if(strncmp(locationstr,"http", 4) == 0)
  13392. {
  13393. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13394. sprintf(ftppath,"/%s", path);
  13395. DEBUG_INFO("locationstr: %s\n", locationstr);
  13396. DEBUG_INFO("protocol: %s\n",protocol);
  13397. DEBUG_INFO("host: %s\n",host);
  13398. DEBUG_INFO("path: %s\n",path);
  13399. DEBUG_INFO("ftppath: %s\n",ftppath);
  13400. int ftppathlen=strlen(ftppath);
  13401. int i=1;
  13402. char filenametemp[50];
  13403. while(i < ftppathlen)
  13404. {
  13405. int len=ftppathlen-i;
  13406. if(ftppath[len]== 47) // '/' ascll code: 47
  13407. {
  13408. DEBUG_INFO("compare '/' all right\n");
  13409. break;
  13410. }
  13411. i=i+1;
  13412. }
  13413. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13414. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13415. filenametemp[i+1] = 0;
  13416. do
  13417. {
  13418. sleep(1);
  13419. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13420. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13421. sleep(1);
  13422. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13423. if(!isSuccess)
  13424. {
  13425. sleep(1);
  13426. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13427. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13428. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13429. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13430. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13431. }
  13432. else
  13433. {
  13434. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13435. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13436. }
  13437. retriesInt--;
  13438. }while((isSuccess == 0)&&(retriesInt >= 0));
  13439. }
  13440. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13441. {
  13442. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13443. memset(temp, 0, ARRAY_SIZE(temp));
  13444. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13445. strcpy(ftpbuf, locationstr);
  13446. int ftppathlen=strlen(ftpbuf);
  13447. int i=1;
  13448. char filenametemp[50];
  13449. while(i < ftppathlen)
  13450. {
  13451. int len=ftppathlen-i;
  13452. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13453. {
  13454. DEBUG_INFO(" compare '/' all right\n");
  13455. break;
  13456. }
  13457. i=i+1;
  13458. }
  13459. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13460. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13461. filenametemp[i+1] = 0;
  13462. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13463. pch=strchr(temp,'@');
  13464. if(pch==NULL)
  13465. {
  13466. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13467. protocol, host, &port, path);
  13468. strcpy(user,"anonymous");
  13469. strcpy(password,"");
  13470. }
  13471. else
  13472. {
  13473. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13474. protocol, user, host, &port, path);
  13475. }
  13476. sscanf(host,"%[^/]%s",host1, path1);
  13477. sprintf(ftppath,"%s:/%s", host,path);
  13478. if(port == 0)
  13479. {
  13480. port = 21;
  13481. }
  13482. do
  13483. {
  13484. sleep(1);
  13485. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13486. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13487. sleep(1);
  13488. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13489. if(!isSuccess)
  13490. {
  13491. //BulldogUtil.sleepMs(interval*1000);
  13492. DEBUG_INFO("Update firmware request and download file fail.\n");
  13493. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13494. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13495. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13496. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13497. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13498. }
  13499. else
  13500. {
  13501. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13502. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13503. }
  13504. retriesInt--;
  13505. }while((!isSuccess)&&(retriesInt >= 0));
  13506. }
  13507. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13508. {
  13509. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13510. memset(temp, 0, ARRAY_SIZE(temp));
  13511. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13512. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13513. int ftppathlen=strlen(ftpbuf);
  13514. int i=1;
  13515. char filenametemp[50];
  13516. while(i < ftppathlen)
  13517. {
  13518. int len=ftppathlen-i;
  13519. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13520. {
  13521. DEBUG_INFO(" compare '/' all right\n");
  13522. break;
  13523. }
  13524. i=i+1;
  13525. }
  13526. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13527. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13528. filenametemp[i+1] = 0;
  13529. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13530. pch=strchr(temp,'@');
  13531. if(pch==NULL)
  13532. {
  13533. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13534. protocol, host, &port, path);
  13535. strcpy(user,"anonymous");
  13536. strcpy(password,"");
  13537. }
  13538. else
  13539. {
  13540. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13541. protocol, user, password, host, &port, path);
  13542. }
  13543. sscanf(host,"%[^/]%s",host1, path1);
  13544. sprintf(ftppath,"%s", path1);
  13545. //DEBUG_INFO("protocol =%s\n",protocol);
  13546. //DEBUG_INFO("user =%s\n",user);
  13547. //DEBUG_INFO("password =%s\n",password);
  13548. //DEBUG_INFO("host1 =%s\n",host1);
  13549. //DEBUG_INFO("port =%d\n",port);
  13550. //DEBUG_INFO("path1 =%s\n",path1);
  13551. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13552. //ftpFile(host, user, password, port, ftppath, fname);
  13553. //download firmware pthred
  13554. if(port == 0)
  13555. {
  13556. port = 21;
  13557. }
  13558. do
  13559. {
  13560. sleep(1);
  13561. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13562. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13563. sleep(1);
  13564. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13565. if(!isSuccess)
  13566. {
  13567. //BulldogUtil.sleepMs(interval*1000);
  13568. DEBUG_INFO("Update firmware request and download file fail.\n");
  13569. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13570. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13571. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13572. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13573. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13574. }
  13575. else
  13576. {
  13577. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13578. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13579. }
  13580. retriesInt--;
  13581. }while((!isSuccess)&&(retriesInt >= 0));
  13582. }
  13583. else
  13584. {
  13585. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13586. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13587. sleep(1);
  13588. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13589. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13590. }
  13591. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13592. {
  13593. sleep(3);
  13594. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13595. }
  13596. interLock.isUpdateFirmwareGoing = 0;
  13597. pthread_exit(NULL);
  13598. }
  13599. int handleCertificateSignedRequest(char *uuid, char *payload)
  13600. {
  13601. mtrace();
  13602. int result = PASS;
  13603. json_object *CertificateSigned;
  13604. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13605. CertificateSigned = json_tokener_parse(payload);
  13606. if(!is_error(CertificateSigned))
  13607. {
  13608. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13609. }
  13610. json_object_put(CertificateSigned);
  13611. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13612. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13613. fclose(fp);
  13614. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13615. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13616. if(certVerify("/Storage/OCPP/certCP.key", "/Storage/OCPP/certCP.crt") == PASS)
  13617. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13618. else
  13619. {
  13620. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  13621. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  13622. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  13623. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  13624. }
  13625. sendCertificateSignedConfirmation(uuid);
  13626. return result;
  13627. }
  13628. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13629. {
  13630. mtrace();
  13631. int result = PASS;
  13632. json_object *DeleteCertificate;
  13633. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13634. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13635. DeleteCertificate = json_tokener_parse(payload);
  13636. if(!is_error(DeleteCertificate))
  13637. {
  13638. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13639. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13640. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13641. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13642. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13643. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13644. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13645. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13646. char temp[256] = {0};
  13647. char compareData[256] = {0};
  13648. int isMatch = TRUE;
  13649. FILE *fp;
  13650. if(access("/Storage/OCPP/CentralSystemRootCertificate.pem",F_OK) != -1)
  13651. {
  13652. // Check CentralSystemRootCertificate
  13653. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  13654. sprintf(temp ,"openssl x509 -noout -serial -in /Storage/OCPP/CentralSystemRootCertificate.pem");
  13655. fp = popen(temp, "r");
  13656. if(fp)
  13657. {
  13658. while(fgets(temp, sizeof(temp), fp) != NULL)
  13659. {
  13660. if(strstr(temp, "serial=") != NULL)
  13661. {
  13662. sscanf(temp, "%*[^=]=%s", compareData);
  13663. break;
  13664. }
  13665. }
  13666. DEBUG_INFO("SerialNumber= %s...\n", compareData);
  13667. }
  13668. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13669. isMatch = FALSE;
  13670. if(isMatch == TRUE)
  13671. {
  13672. memset(compareData, 0, ARRAY_SIZE(compareData));
  13673. sprintf(temp ,"openssl x509 -noout -issuer -in /Storage/OCPP/CentralSystemRootCertificate.pem | openssl dgst -%s", (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13674. fp = popen(temp, "r");
  13675. if(fp)
  13676. {
  13677. while(fgets(temp, sizeof(temp), fp) != NULL)
  13678. {
  13679. strcat(compareData, temp);
  13680. }
  13681. }
  13682. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  13683. isMatch = FALSE;
  13684. }
  13685. if(isMatch == TRUE)
  13686. {
  13687. memset(compareData, 0, ARRAY_SIZE(compareData));
  13688. sprintf(temp ,"openssl x509 -noout -pubkey -in /Storage/OCPP/CentralSystemRootCertificate.pem | openssl dgst -%s", (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13689. fp = popen(temp, "r");
  13690. if(fp)
  13691. {
  13692. while(fgets(temp, sizeof(temp), fp) != NULL)
  13693. {
  13694. strcat(compareData, temp);
  13695. }
  13696. }
  13697. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13698. isMatch = FALSE;
  13699. }
  13700. if(isMatch == TRUE)
  13701. {
  13702. system("rm -f /Storage/OCPP/CentralSystemRootCertificate.pem");
  13703. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  13704. goto End;
  13705. }
  13706. }
  13707. // Check ManufacturerRootCertificate
  13708. if(access("/Storage/OCPP/ManufacturerRootCertificate.pem",F_OK) != -1)
  13709. {
  13710. isMatch = FALSE;
  13711. sprintf(temp ,"openssl x509 -noout -serial -in /Storage/OCPP/ManufacturerRootCertificate.pem");
  13712. fp = popen(temp, "r");
  13713. if(fp)
  13714. {
  13715. while(fgets(temp, sizeof(temp), fp) != NULL)
  13716. {
  13717. if(strstr(temp, "serial=") != NULL)
  13718. {
  13719. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  13720. sscanf(temp, "%*[^=]=%s", compareData);
  13721. break;
  13722. }
  13723. }
  13724. }
  13725. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13726. isMatch = FALSE;
  13727. if(isMatch == TRUE)
  13728. {
  13729. memset(compareData, 0, ARRAY_SIZE(compareData));
  13730. sprintf(temp ,"openssl x509 -noout -issuer -in /Storage/OCPP/ManufacturerRootCertificate.pem | openssl dgst -%s", (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13731. fp = popen(temp, "r");
  13732. if(fp)
  13733. {
  13734. while(fgets(temp, sizeof(temp), fp) != NULL)
  13735. {
  13736. strcat(compareData, temp);
  13737. }
  13738. }
  13739. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  13740. isMatch = FALSE;
  13741. }
  13742. if(isMatch == TRUE)
  13743. {
  13744. memset(compareData, 0, ARRAY_SIZE(compareData));
  13745. sprintf(temp ,"openssl x509 -noout -pubkey -in /Storage/OCPP/ManufacturerRootCertificate.pem | openssl dgst -%s", (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13746. fp = popen(temp, "r");
  13747. if(fp)
  13748. {
  13749. while(fgets(temp, sizeof(temp), fp) != NULL)
  13750. {
  13751. strcat(compareData, temp);
  13752. }
  13753. }
  13754. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13755. isMatch = FALSE;
  13756. }
  13757. if(isMatch == TRUE)
  13758. {
  13759. system("rm -f /Storage/OCPP/ManufacturerRootCertificate.pem");
  13760. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  13761. goto End;
  13762. }
  13763. }
  13764. // Check certCP
  13765. if(access("/Storage/OCPP/certCP.pem",F_OK) != -1)
  13766. {
  13767. isMatch = FALSE;
  13768. sprintf(temp ,"openssl x509 -noout -serial -in /Storage/OCPP/certCP.pem");
  13769. fp = popen(temp, "r");
  13770. if(fp)
  13771. {
  13772. while(fgets(temp, sizeof(temp), fp) != NULL)
  13773. {
  13774. if(strstr(temp, "serial=") != NULL)
  13775. {
  13776. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  13777. sscanf(temp, "%*[^=]=%s", compareData);
  13778. break;
  13779. }
  13780. }
  13781. }
  13782. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13783. isMatch = FALSE;
  13784. if(isMatch == TRUE)
  13785. {
  13786. memset(compareData, 0, ARRAY_SIZE(compareData));
  13787. sprintf(temp ,"openssl x509 -noout -issuer -in /Storage/OCPP/certCP.pem | openssl dgst -%s", (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13788. fp = popen(temp, "r");
  13789. if(fp)
  13790. {
  13791. while(fgets(temp, sizeof(temp), fp) != NULL)
  13792. {
  13793. strcat(compareData, temp);
  13794. }
  13795. }
  13796. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  13797. isMatch = FALSE;
  13798. }
  13799. if(isMatch == TRUE)
  13800. {
  13801. memset(compareData, 0, ARRAY_SIZE(compareData));
  13802. sprintf(temp ,"openssl x509 -noout -pubkey -in /Storage/OCPP/certCP.pem | openssl dgst -%s", (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13803. fp = popen(temp, "r");
  13804. if(fp)
  13805. {
  13806. while(fgets(temp, sizeof(temp), fp) != NULL)
  13807. {
  13808. strcat(compareData, temp);
  13809. }
  13810. }
  13811. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13812. isMatch = FALSE;
  13813. }
  13814. if(isMatch == TRUE)
  13815. {
  13816. system("rm -f /Storage/OCPP/certCP.pem");
  13817. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  13818. goto End;
  13819. }
  13820. }
  13821. }
  13822. End:
  13823. json_object_put(DeleteCertificate);
  13824. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13825. sendDeleteCertificateConfirmation(uuid);
  13826. return result;
  13827. }
  13828. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13829. {
  13830. mtrace();
  13831. int result = PASS;
  13832. json_object *ExtendedTriggerMessage;
  13833. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13834. ExtendedTriggerMessage = json_tokener_parse(payload);
  13835. if(!is_error(ExtendedTriggerMessage))
  13836. {
  13837. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13838. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13839. {
  13840. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13841. }
  13842. else
  13843. {
  13844. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13845. }
  13846. }
  13847. json_object_put(ExtendedTriggerMessage);
  13848. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13849. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13850. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13851. {
  13852. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13853. }
  13854. else
  13855. {
  13856. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13857. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13858. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13859. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13860. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13861. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13862. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13863. {
  13864. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13865. }
  13866. else
  13867. {
  13868. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13869. }
  13870. }
  13871. sendExtendedTriggerMessageConfirmation(uuid);
  13872. //==========================
  13873. // Trigger message
  13874. //==========================
  13875. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13876. {
  13877. //sendBootNotificationRequest();
  13878. server_sign = FALSE;
  13879. }
  13880. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13881. {
  13882. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13883. }
  13884. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13885. {
  13886. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13887. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13888. {
  13889. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13890. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13891. }
  13892. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13893. }
  13894. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13895. {
  13896. refreshStartTimer(&clientTime.Heartbeat);
  13897. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13898. }
  13899. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13900. {
  13901. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13902. {
  13903. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13904. }
  13905. else
  13906. {
  13907. for(int idx=0;idx< gunTotalNumber;idx++)
  13908. {
  13909. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13910. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13911. }
  13912. }
  13913. }
  13914. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13915. {
  13916. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13917. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13918. {
  13919. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  13920. }
  13921. }
  13922. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13923. {
  13924. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13925. {
  13926. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13927. }
  13928. else
  13929. {
  13930. for(int idx=0;idx< gunTotalNumber;idx++)
  13931. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13932. }
  13933. }
  13934. return result;
  13935. }
  13936. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13937. {
  13938. mtrace();
  13939. int result = PASS;
  13940. json_object *GetInstalledCertificateIds;
  13941. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13942. GetInstalledCertificateIds = json_tokener_parse(payload);
  13943. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13944. if(!is_error(GetInstalledCertificateIds))
  13945. {
  13946. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13947. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13948. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  13949. char temp[512] = {0};
  13950. char capturedData[256] = {0};
  13951. char hashType[10] = {0};
  13952. FILE *fp;
  13953. // Check CentralSystemRootCertificate
  13954. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL) && (access("/Storage/OCPP/CentralSystemRootCertificate.pem",F_OK) != -1))
  13955. {
  13956. memset(hashType, 0, ARRAY_SIZE(hashType));
  13957. sprintf(temp ,"openssl x509 -noout -text -in /Storage/OCPP/CentralSystemRootCertificate.pem");
  13958. fp = popen(temp, "r");
  13959. if(fp)
  13960. {
  13961. while(fgets(temp, sizeof(temp), fp) != NULL)
  13962. {
  13963. if(strstr(temp, "Signature Algorithm:") != NULL)
  13964. {
  13965. if(strstr(temp, "sha256") != NULL)
  13966. sprintf((char*)hashType, "SHA256");
  13967. if(strstr(temp, "sha384") != NULL)
  13968. sprintf((char*)hashType, "SHA384");
  13969. if(strstr(temp, "sha512") != NULL)
  13970. sprintf((char*)hashType, "SHA512");
  13971. break;
  13972. }
  13973. }
  13974. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  13975. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, hashType);
  13976. }
  13977. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  13978. sprintf(temp ,"openssl x509 -noout -serial -in /Storage/OCPP/CentralSystemRootCertificate.pem");
  13979. fp = popen(temp, "r");
  13980. if(fp)
  13981. {
  13982. while(fgets(temp, sizeof(temp), fp) != NULL)
  13983. {
  13984. if(strstr(temp, "serial=") != NULL)
  13985. {
  13986. sscanf(temp, "%*[^=]=%s", capturedData);
  13987. break;
  13988. }
  13989. }
  13990. DEBUG_INFO("serialNumber: %s\n", capturedData);
  13991. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, capturedData);
  13992. }
  13993. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  13994. sprintf(temp ,"openssl x509 -noout -issuer -in /Storage/OCPP/CentralSystemRootCertificate.pem | openssl dgst -%s", (char*)hashType);
  13995. fp = popen(temp, "r");
  13996. if(fp)
  13997. {
  13998. while(fgets(temp, sizeof(temp), fp) != NULL)
  13999. {
  14000. if(strstr(temp, "(stdin)=") != NULL)
  14001. {
  14002. sscanf(temp, "%*[^=]=%s", capturedData);
  14003. break;
  14004. }
  14005. }
  14006. stringtrimspace(capturedData);
  14007. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  14008. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, capturedData);
  14009. }
  14010. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  14011. sprintf(temp ,"openssl x509 -noout -pubkey -in /Storage/OCPP/CentralSystemRootCertificate.pem | openssl dgst -%s", (char*)hashType);
  14012. fp = popen(temp, "r");
  14013. if(fp)
  14014. {
  14015. while(fgets(temp, sizeof(temp), fp) != NULL)
  14016. {
  14017. if(strstr(temp, "(stdin)=") != NULL)
  14018. {
  14019. sscanf(temp, "%*[^=]=%s", capturedData);
  14020. break;
  14021. }
  14022. }
  14023. stringtrimspace(capturedData);
  14024. DEBUG_INFO("issuerKeyHash: %s\n", capturedData);
  14025. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, capturedData);
  14026. }
  14027. }
  14028. else
  14029. {
  14030. DEBUG_INFO(">>> No CentralSystemRootCertificate found.\n");
  14031. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14032. }
  14033. // Check ManufacturerRootCertificate
  14034. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL) && (access("/Storage/OCPP/ManufacturerRootCertificate.pem",F_OK) != -1))
  14035. {
  14036. memset(hashType, 0, ARRAY_SIZE(hashType));
  14037. sprintf(temp ,"openssl x509 -noout -text -in /Storage/OCPP/ManufacturerRootCertificate.pem");
  14038. fp = popen(temp, "r");
  14039. if(fp)
  14040. {
  14041. while(fgets(temp, sizeof(temp), fp) != NULL)
  14042. {
  14043. if(strstr(temp, "Signature Algorithm:") != NULL)
  14044. {
  14045. if(strstr(temp, "sha256") != NULL)
  14046. sprintf((char*)hashType, "SHA256");
  14047. if(strstr(temp, "sha384") != NULL)
  14048. sprintf((char*)hashType, "SHA384");
  14049. if(strstr(temp, "sha512") != NULL)
  14050. sprintf((char*)hashType, "SHA512");
  14051. break;
  14052. }
  14053. }
  14054. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  14055. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, hashType);
  14056. }
  14057. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  14058. sprintf(temp ,"openssl x509 -noout -serial -in /Storage/OCPP/ManufacturerRootCertificate.pem");
  14059. fp = popen(temp, "r");
  14060. if(fp)
  14061. {
  14062. while(fgets(temp, sizeof(temp), fp) != NULL)
  14063. {
  14064. if(strstr(temp, "serial=") != NULL)
  14065. {
  14066. sscanf(temp, "%*[^=]=%s", capturedData);
  14067. break;
  14068. }
  14069. }
  14070. DEBUG_INFO("serialNumber: %s\n", capturedData);
  14071. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, capturedData);
  14072. }
  14073. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  14074. sprintf(temp ,"openssl x509 -noout -issuer -in /Storage/OCPP/ManufacturerRootCertificate.pem | openssl dgst -%s", (char*)hashType);
  14075. fp = popen(temp, "r");
  14076. if(fp)
  14077. {
  14078. while(fgets(temp, sizeof(temp), fp) != NULL)
  14079. {
  14080. if(strstr(temp, "(stdin)=") != NULL)
  14081. {
  14082. sscanf(temp, "%*[^=]=%s", capturedData);
  14083. break;
  14084. }
  14085. }
  14086. stringtrimspace(capturedData);
  14087. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  14088. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, capturedData);
  14089. }
  14090. memset(capturedData, 0, ARRAY_SIZE(capturedData));
  14091. sprintf(temp ,"openssl x509 -noout -pubkey -in /Storage/OCPP/ManufacturerRootCertificate.pem | openssl dgst -%s", (char*)hashType);
  14092. fp = popen(temp, "r");
  14093. if(fp)
  14094. {
  14095. while(fgets(temp, sizeof(temp), fp) != NULL)
  14096. {
  14097. if(strstr(temp, "(stdin)=") != NULL)
  14098. {
  14099. sscanf(temp, "%*[^=]=%s", capturedData);
  14100. break;
  14101. }
  14102. }
  14103. stringtrimspace(capturedData);
  14104. DEBUG_INFO("issuerKeyHash: %s\n", capturedData);
  14105. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, capturedData);
  14106. }
  14107. }
  14108. else
  14109. {
  14110. DEBUG_INFO(">>> No ManufacturerRootCertificate found.\n");
  14111. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14112. }
  14113. }
  14114. json_object_put(GetInstalledCertificateIds);
  14115. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14116. sendGetInstalledCertificateIdsConfirmation(uuid);
  14117. return result;
  14118. }
  14119. void* GetLogProcess(void* data)
  14120. {
  14121. pthread_detach(pthread_self());
  14122. mtrace();
  14123. 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};
  14124. int port=0;
  14125. int isSuccess = FALSE;
  14126. char cmdBuf[2048];
  14127. struct tm *tmNow;
  14128. time_t CurrentTime;
  14129. struct tm tmStart;
  14130. struct tm tmStop;
  14131. CurrentTime = time(NULL);
  14132. tmNow=localtime(&CurrentTime);
  14133. uint16_t targetYear, targetMonth;
  14134. json_object *GetLog;
  14135. DEBUG_INFO("GetLogProcess...\n");
  14136. GetLog = json_tokener_parse(data);
  14137. if(!is_error(GetLog))
  14138. {
  14139. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14140. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14141. if(json_object_object_get(GetLog, "retries") != NULL)
  14142. {
  14143. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14144. }
  14145. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14146. {
  14147. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14148. }
  14149. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14150. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14151. {
  14152. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14153. }
  14154. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14155. {
  14156. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14157. }
  14158. }
  14159. json_object_put(GetLog);
  14160. // Pack log to compress file
  14161. 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) &&
  14162. (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))
  14163. {
  14164. // Pack system log
  14165. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14166. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14167. targetYear = tmStart.tm_year;
  14168. targetMonth = tmStart.tm_mon;
  14169. do
  14170. {
  14171. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14172. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14173. if(targetMonth+1>=13)
  14174. {
  14175. targetYear += 1;
  14176. targetMonth = 1;
  14177. }
  14178. else
  14179. {
  14180. targetMonth += 1;
  14181. }
  14182. }while((targetYear < (tmNow->tm_year+1900)) ||
  14183. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14184. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14185. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14186. system(cmdBuf);
  14187. // Pack charging & event log
  14188. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14189. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14190. targetYear = tmStart.tm_year;
  14191. targetMonth = tmStart.tm_mon;
  14192. do
  14193. {
  14194. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14195. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14196. if(targetMonth+1>=13)
  14197. {
  14198. targetYear += 1;
  14199. targetMonth = 1;
  14200. }
  14201. else
  14202. {
  14203. targetMonth += 1;
  14204. }
  14205. }while((targetYear < (tmNow->tm_year+1900)) ||
  14206. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14207. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14208. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14209. system(cmdBuf);
  14210. // Combine log file
  14211. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14212. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14213. }
  14214. else
  14215. {
  14216. system("exec /root/logPackTools 'log' 6");
  14217. }
  14218. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14219. system(cmdBuf);
  14220. checkUploadLog();
  14221. //****************location*******************/
  14222. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14223. {
  14224. DEBUG_INFO("location is <Empty>!\n");
  14225. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14226. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14227. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14228. goto end;
  14229. }
  14230. memset(protocol, 0, ARRAY_SIZE(protocol));
  14231. memset(user, 0, ARRAY_SIZE(user) );
  14232. memset(password, 0, ARRAY_SIZE(password));
  14233. memset(host, 0, ARRAY_SIZE(host));
  14234. memset(path, 0, ARRAY_SIZE(path));
  14235. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14236. memset(host1, 0, ARRAY_SIZE(host1));
  14237. memset(path1, 0, ARRAY_SIZE(path1));
  14238. /*location: ftp://user:password@host:port/path*/
  14239. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14240. if((access(fnamePlusPath,F_OK))!=-1)
  14241. {
  14242. DEBUG_INFO("fnamePlusPath exist.\n");
  14243. }
  14244. else
  14245. {
  14246. DEBUG_INFO("fnamePlusPath not exist!\n");
  14247. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14248. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14249. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14250. goto end;
  14251. }
  14252. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14253. {
  14254. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14255. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14256. protocol, host, &port, path);
  14257. strcpy(user,"anonymous");
  14258. strcpy(password,"");
  14259. }
  14260. else
  14261. {
  14262. //DEBUG_INFO("pch=%s\n", pch);
  14263. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14264. protocol, user, password, host, &port, path);
  14265. }
  14266. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14267. {
  14268. DEBUG_INFO("protocol is not ftp/http ! \n");
  14269. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14270. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14271. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14272. goto end;
  14273. }
  14274. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14275. {
  14276. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14277. sprintf(ftppath,"/%s", path);
  14278. do
  14279. {
  14280. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14281. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14282. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14283. sleep(3);
  14284. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14285. if(!isSuccess)
  14286. {
  14287. DEBUG_INFO("Diagnostics fail.\n");
  14288. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14289. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14290. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14291. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14292. }
  14293. else
  14294. {
  14295. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14296. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14297. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14298. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14299. }
  14300. ShmOCPP16Data->GetLog.retries--;
  14301. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14302. }
  14303. else
  14304. {
  14305. sscanf(host,"%[^/]%s",host1, path1);
  14306. if(strlen(path) > 0)
  14307. sprintf(ftppath,"/%s", path);
  14308. else
  14309. sprintf(ftppath,"/%s", path1);
  14310. int ftppathlen=strlen(ftppath);
  14311. int i=1;
  14312. char filenametemp[50];
  14313. while(i < ftppathlen)
  14314. {
  14315. int len=ftppathlen-i;
  14316. if(ftppath[len]== 47) // '/' ascll code: 47
  14317. {
  14318. DEBUG_INFO("find '/' all right\n");
  14319. break;
  14320. }
  14321. i=i+1;
  14322. }
  14323. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14324. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14325. filenametemp[i+1] = 0;
  14326. if(port == 0)
  14327. port = 21;
  14328. do
  14329. {
  14330. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14331. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14332. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14333. sleep(3);
  14334. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14335. if(!isSuccess)
  14336. {
  14337. DEBUG_INFO("Diagnostics fail.\n");
  14338. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14339. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14340. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14341. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14342. }
  14343. else
  14344. {
  14345. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14346. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14347. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14348. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14349. }
  14350. ShmOCPP16Data->GetLog.retries--;
  14351. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14352. }
  14353. end:
  14354. system("rm -f /mnt/*");
  14355. sleep(5);
  14356. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14357. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14358. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14359. interLock.isGetDiagnosticGoing = 0;
  14360. pthread_exit(NULL);
  14361. }
  14362. int handleGetLogRequest(char *uuid, char *payload)
  14363. {
  14364. mtrace();
  14365. int result = PASS;
  14366. time_t CurrentTime;
  14367. struct tm *tm;
  14368. DEBUG_INFO("handleGetLogRequest...\n");
  14369. pthread_t th_Status;
  14370. CurrentTime = time(NULL);
  14371. tm = localtime(&CurrentTime);
  14372. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14373. 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);
  14374. if(!interLock.isGetDiagnosticGoing)
  14375. {
  14376. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14377. interLock.isGetDiagnosticGoing = 1;
  14378. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14379. sleep(1);
  14380. }
  14381. else
  14382. {
  14383. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14384. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14385. }
  14386. sendGetLogConfirmation(uuid);
  14387. return result;
  14388. }
  14389. int handleInstallCertificateRequest(char *uuid, char *payload)
  14390. {
  14391. mtrace();
  14392. int result = PASS;
  14393. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14394. json_object *InstallCertificate;
  14395. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14396. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14397. InstallCertificate = json_tokener_parse(payload);
  14398. if(!is_error(InstallCertificate))
  14399. {
  14400. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14401. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14402. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14403. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14404. char temp[1024];
  14405. FILE *fp = fopen(tempCert, "w");
  14406. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14407. fclose(fp);
  14408. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14409. char strExpDate[30];
  14410. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14411. fp = popen(temp, "r");
  14412. if(fp)
  14413. {
  14414. while(fgets(temp, sizeof(temp), fp) != NULL)
  14415. {
  14416. if(strstr(temp, "notAfter=") != NULL)
  14417. {
  14418. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14419. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14420. break;
  14421. }
  14422. }
  14423. }
  14424. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14425. struct tm tmExpDate;
  14426. struct timeb tbExpDate;
  14427. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14428. tbExpDate.time = mktime(&tmExpDate);
  14429. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14430. {
  14431. DEBUG_INFO("The enddate is already expired...\n");
  14432. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14433. goto End;
  14434. }
  14435. // Verify certificate with rootCA
  14436. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14437. fp = popen(temp, "r");
  14438. if(fp)
  14439. {
  14440. while(fgets(temp, sizeof(temp), fp) != NULL)
  14441. {
  14442. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14443. {
  14444. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14445. break;
  14446. }
  14447. else
  14448. {
  14449. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14450. }
  14451. }
  14452. }
  14453. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14454. {
  14455. //=====================================================
  14456. // Verify if the certificate is valid or not. (OCSP?)
  14457. //=====================================================
  14458. /*
  14459. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14460. // Get ocsp url
  14461. char ocspUrl[512];
  14462. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14463. fp = popen(temp, "r");
  14464. if(fp)
  14465. {
  14466. while(fgets(temp, sizeof(temp), fp) != NULL)
  14467. {
  14468. if(strstr(temp, "://") != NULL)
  14469. {
  14470. strcpy(ocspUrl, temp);
  14471. }
  14472. }
  14473. }
  14474. // Get certificate chain for issuer
  14475. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14476. *
  14477. // Execute OCSP
  14478. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14479. fp = popen(temp, "r");
  14480. if(fp)
  14481. {
  14482. while(fgets(temp, sizeof(temp), fp) != NULL)
  14483. {
  14484. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14485. {
  14486. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14487. break;
  14488. }
  14489. }
  14490. }
  14491. system("rm -f /Storage/OCPP/tempChain.pem");
  14492. pclose(fp);
  14493. */
  14494. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14495. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14496. {
  14497. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14498. goto End;
  14499. }
  14500. else
  14501. DEBUG_INFO("OCSP verifying...PASS.\n");
  14502. }
  14503. else
  14504. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14505. }
  14506. End:
  14507. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14508. {
  14509. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14510. {
  14511. if(access("/Storage/OCPP/CentralSystemRootCertificate.pem",F_OK) != -1)
  14512. {
  14513. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14514. rename("/Storage/OCPP/CentralSystemRootCertificate.pem", "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14515. rename(tempCert, "/Storage/OCPP/CentralSystemRootCertificate.pem");
  14516. }
  14517. else
  14518. {
  14519. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14520. rename(tempCert, "/Storage/OCPP/CentralSystemRootCertificate.pem");
  14521. }
  14522. }
  14523. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14524. {
  14525. if(access("/Storage/OCPP/ManufacturerRootCertificate.pem",F_OK) != -1)
  14526. {
  14527. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14528. rename("/Storage/OCPP/ManufacturerRootCertificate.pem", "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14529. rename(tempCert, "/Storage/OCPP/ManufacturerRootCertificate.pem");
  14530. }
  14531. else
  14532. {
  14533. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14534. rename(tempCert, "/Storage/OCPP/ManufacturerRootCertificate.pem");
  14535. }
  14536. }
  14537. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14538. }
  14539. sendInstallCertificateConfirmation(uuid);
  14540. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14541. {
  14542. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14543. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14544. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14545. }
  14546. json_object_put(InstallCertificate);
  14547. return result;
  14548. }
  14549. void *SignedUpdateFirmwareProcess(void *data)
  14550. {
  14551. pthread_detach(pthread_self());
  14552. mtrace();
  14553. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14554. int port=0;
  14555. int isSuccess = 0;
  14556. char ftpbuf[1024];
  14557. char temp[1024];
  14558. char * pch;
  14559. char firmwareFileName[50];
  14560. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14561. json_object *SignedUpdateFirmware;
  14562. SignedUpdateFirmware = json_tokener_parse(data);
  14563. if(!is_error(SignedUpdateFirmware))
  14564. {
  14565. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14566. {
  14567. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14568. }
  14569. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14570. {
  14571. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14572. }
  14573. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14574. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14575. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14576. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14577. {
  14578. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14579. }
  14580. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14581. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14582. }
  14583. json_object_put(SignedUpdateFirmware);
  14584. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14585. memset(path, 0, ARRAY_SIZE(path));
  14586. // Wait retrieveData
  14587. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14588. {
  14589. do
  14590. {
  14591. sleep(1);
  14592. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14593. }
  14594. // Ready to download
  14595. system("rm -f /mnt/*");
  14596. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14597. {
  14598. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14599. sprintf(ftppath,"/%s", path);
  14600. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14601. DEBUG_INFO("protocol: %s\n",protocol);
  14602. DEBUG_INFO("host: %s\n",host);
  14603. DEBUG_INFO("path: %s\n",path);
  14604. DEBUG_INFO("ftppath: %s\n",ftppath);
  14605. int ftppathlen=strlen(ftppath);
  14606. int i=1;
  14607. while(i < ftppathlen)
  14608. {
  14609. int len=ftppathlen-i;
  14610. if(ftppath[len]== 47) // '/' ascll code: 47
  14611. {
  14612. DEBUG_INFO("compare '/' all right\n");
  14613. break;
  14614. }
  14615. i=i+1;
  14616. }
  14617. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14618. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14619. firmwareFileName[i+1] = 0;
  14620. do
  14621. {
  14622. sleep(1);
  14623. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14624. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14625. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14626. sleep(1);
  14627. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14628. if(!isSuccess)
  14629. {
  14630. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14631. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14632. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14633. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14634. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14635. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14636. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14637. }
  14638. else
  14639. {
  14640. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14641. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14642. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14643. }
  14644. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14645. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14646. }
  14647. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14648. {
  14649. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14650. memset(temp, 0, ARRAY_SIZE(temp));
  14651. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14652. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14653. int ftppathlen=strlen(ftpbuf);
  14654. int i=1;
  14655. while(i < ftppathlen)
  14656. {
  14657. int len=ftppathlen-i;
  14658. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14659. {
  14660. DEBUG_INFO(" compare '/' all right\n");
  14661. break;
  14662. }
  14663. i=i+1;
  14664. }
  14665. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14666. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14667. firmwareFileName[i+1] = 0;
  14668. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14669. pch=strchr(temp,'@');
  14670. if(pch==NULL)
  14671. {
  14672. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14673. protocol, host, &port, path);
  14674. strcpy(user,"anonymous");
  14675. strcpy(password,"");
  14676. }
  14677. else
  14678. {
  14679. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14680. protocol, user, host, &port, path);
  14681. }
  14682. sscanf(host,"%[^/]%s",host1, path1);
  14683. sprintf(ftppath,"%s:/%s", host,path);
  14684. if(port == 0)
  14685. {
  14686. port = 21;
  14687. }
  14688. do
  14689. {
  14690. sleep(1);
  14691. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14692. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14693. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14694. sleep(1);
  14695. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14696. if(!isSuccess)
  14697. {
  14698. sleep(1);
  14699. DEBUG_INFO("Update firmware request and download file fail.\n");
  14700. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14701. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14702. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14703. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14704. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14705. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14706. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14707. }
  14708. else
  14709. {
  14710. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14711. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14712. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14713. }
  14714. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14715. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14716. }
  14717. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14718. {
  14719. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14720. memset(temp, 0, ARRAY_SIZE(temp));
  14721. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14722. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14723. int ftppathlen=strlen(ftpbuf);
  14724. int i=1;
  14725. while(i < ftppathlen)
  14726. {
  14727. int len=ftppathlen-i;
  14728. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14729. {
  14730. DEBUG_INFO(" compare '/' all right\n");
  14731. break;
  14732. }
  14733. i=i+1;
  14734. }
  14735. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14736. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14737. firmwareFileName[i+1] = 0;
  14738. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14739. pch=strchr(temp,'@');
  14740. if(pch==NULL)
  14741. {
  14742. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14743. protocol, host, &port, path);
  14744. strcpy(user,"anonymous");
  14745. strcpy(password,"");
  14746. }
  14747. else
  14748. {
  14749. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14750. protocol, user, password, host, &port, path);
  14751. }
  14752. sscanf(host,"%[^/]%s",host1, path1);
  14753. sprintf(ftppath,"%s", path1);
  14754. //DEBUG_INFO("protocol =%s\n",protocol);
  14755. //DEBUG_INFO("user =%s\n",user);
  14756. //DEBUG_INFO("password =%s\n",password);
  14757. //DEBUG_INFO("host1 =%s\n",host1);
  14758. //DEBUG_INFO("port =%d\n",port);
  14759. //DEBUG_INFO("path1 =%s\n",path1);
  14760. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14761. //ftpFile(host, user, password, port, ftppath, fname);
  14762. //download firmware pthred
  14763. if(port == 0)
  14764. {
  14765. port = 21;
  14766. }
  14767. do
  14768. {
  14769. sleep(1);
  14770. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14771. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14772. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14773. sleep(1);
  14774. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14775. if(!isSuccess)
  14776. {
  14777. //BulldogUtil.sleepMs(interval*1000);
  14778. DEBUG_INFO("Update firmware request and download file fail.\n");
  14779. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14780. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14781. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14782. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14783. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14784. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14785. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14786. }
  14787. else
  14788. {
  14789. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14790. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14791. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14792. }
  14793. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14794. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14795. }
  14796. else
  14797. {
  14798. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14799. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14800. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14801. sleep(1);
  14802. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14803. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14804. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14805. }
  14806. // Verify firmware image signature
  14807. struct stat st;
  14808. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  14809. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  14810. fclose(fp);
  14811. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  14812. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  14813. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  14814. fclose(fp);
  14815. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  14816. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  14817. if(st.st_size == 0)
  14818. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  14819. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  14820. {
  14821. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  14822. fp = popen(temp, "r");
  14823. if(fp)
  14824. {
  14825. while(fgets(temp, sizeof(temp), fp) != NULL)
  14826. {
  14827. if(strstr(temp, "Verified OK") != NULL)
  14828. {
  14829. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14830. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  14831. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14832. }
  14833. else
  14834. {
  14835. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14836. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  14837. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14838. sleep(1);
  14839. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14840. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  14841. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14842. sleep(1);
  14843. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14844. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14845. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14846. }
  14847. break;
  14848. }
  14849. }
  14850. pclose(fp);
  14851. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  14852. }
  14853. interLock.isUpdateFirmwareGoing = 0;
  14854. pthread_exit(NULL);
  14855. }
  14856. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  14857. {
  14858. mtrace();
  14859. int result = PASS;
  14860. pthread_t t;
  14861. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  14862. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  14863. sendSignedUpdateFirmwareConfirmation(uuid);
  14864. if(!interLock.isUpdateFirmwareGoing)
  14865. {
  14866. interLock.isUpdateFirmwareGoing = 1;
  14867. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  14868. sleep(1);
  14869. }
  14870. else
  14871. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  14872. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  14873. return result;
  14874. }
  14875. int handleUnknownRequest(char *uuid, char *payload)
  14876. {
  14877. mtrace();
  14878. int result = PASS;
  14879. DEBUG_INFO("handleUnknownRequest...\n");
  14880. sendUnknownConfirmation(uuid);
  14881. return result;
  14882. }
  14883. //==========================================
  14884. // Handle server response routine
  14885. //==========================================
  14886. void handleAuthorizeResponse(char *payload, int gun_index)
  14887. {
  14888. mtrace();
  14889. char expiryDatestr[36]={0};
  14890. char parentIdTagstr[21]={0};
  14891. char statusstr[20]={0};
  14892. int expiryDateISNULL=FALSE;
  14893. int parentIdTagISNULL=FALSE;
  14894. DEBUG_INFO("handleAuthorizeResponse...\n");
  14895. json_object *Authorize;
  14896. Authorize = json_tokener_parse(payload);
  14897. if(!is_error(Authorize))
  14898. {
  14899. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  14900. {
  14901. // Required data
  14902. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  14903. // Optional data
  14904. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  14905. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  14906. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  14907. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  14908. }
  14909. }
  14910. json_object_put(Authorize);
  14911. if(expiryDateISNULL == FALSE)
  14912. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  14913. if(parentIdTagISNULL == FALSE)
  14914. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  14915. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  14916. //Update idTag information to authorization cache if supproted
  14917. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  14918. {
  14919. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  14920. }
  14921. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  14922. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  14923. authorizeRetryTimes = 0;
  14924. }
  14925. void handleBootNotificationResponse(char *payload, int gun_index)
  14926. {
  14927. mtrace();
  14928. char statusStr[12]={0};
  14929. char currentTimeStr[30]={0};
  14930. int intervalInt = 0;
  14931. DEBUG_INFO("handleBootNotificationResponse...\n");
  14932. json_object *BootNotification;
  14933. BootNotification = json_tokener_parse(payload);
  14934. if(!is_error(BootNotification))
  14935. {
  14936. // Required data
  14937. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  14938. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  14939. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  14940. }
  14941. json_object_put(BootNotification);
  14942. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14943. BootNotificationInterval = intervalInt;
  14944. //write back to ShmOCPP16Data->BootNotification
  14945. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  14946. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14947. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  14948. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  14949. {
  14950. BootNotificationInterval = 0;
  14951. if((intervalInt == 0) || (intervalInt >= 10))
  14952. {
  14953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  14954. HeartBeatWaitTime = intervalInt;
  14955. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  14956. }
  14957. server_sign = TRUE;
  14958. server_pending =FALSE;
  14959. }
  14960. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  14961. {
  14962. server_pending = TRUE;
  14963. }
  14964. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  14965. srand(time(NULL));
  14966. refreshStartTimer(&clientTime.Heartbeat);
  14967. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  14968. SetOcppConnStatus(TRUE);
  14969. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  14970. }
  14971. void handleDataTransferResponse(char *payload, int gun_index)
  14972. {
  14973. json_object *DataTransfer = json_tokener_parse(payload);
  14974. if(!is_error(DataTransfer))
  14975. {
  14976. // Required data
  14977. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  14978. // Optional data
  14979. if(json_object_object_get(DataTransfer, "data") != NULL)
  14980. {
  14981. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14982. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14983. if(!is_error(Data))
  14984. {
  14985. if(json_object_object_get(Data, "msgId") != NULL)
  14986. {
  14987. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  14988. {
  14989. 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")));
  14990. }
  14991. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  14992. {
  14993. if(json_object_object_get(Data, "ConnectorId") != NULL)
  14994. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  14995. }
  14996. }
  14997. }
  14998. json_object_put(Data);
  14999. }
  15000. }
  15001. json_object_put(DataTransfer);
  15002. }
  15003. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15004. {
  15005. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15006. //struct json_object *obj;
  15007. // obj = json_tokener_parse(payload);
  15008. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15009. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15010. //No fields are defined.
  15011. }
  15012. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15013. {
  15014. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15015. //struct json_object *obj;
  15016. // obj = json_tokener_parse(payload);
  15017. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15018. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15019. //No fields are defined.
  15020. }
  15021. void handleHeartbeatResponse(char *payload, int gun_index)
  15022. {
  15023. mtrace();
  15024. DEBUG_INFO("handleHeartbeatResponse...\n");
  15025. json_object *Heartbeat;
  15026. Heartbeat = json_tokener_parse(payload);
  15027. if(!is_error(Heartbeat))
  15028. {
  15029. // Required data
  15030. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15031. }
  15032. json_object_put(Heartbeat);
  15033. if(FirstHeartBeat == 0)
  15034. {
  15035. FirstHeartBeat = 1;
  15036. DEBUG_INFO("FirstHeartBeat \n");
  15037. }
  15038. HeartBeatWithNOResponse = 0;
  15039. refreshStartTimer(&clientTime.Heartbeat);
  15040. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15041. }
  15042. void handleMeterValuesResponse(char *payload, int gun_index)
  15043. {
  15044. mtrace();
  15045. DEBUG_INFO("handleMeterValuesResponse...\n");
  15046. isQueueSendable = 1;
  15047. }
  15048. void handleStartTransactionResponse(char *payload, int gun_index)
  15049. {
  15050. mtrace();
  15051. //int transactionIdInt = 0;
  15052. FILE *outfile;
  15053. char data[100]={0};
  15054. DEBUG_INFO("handleStartTransactionResponse...\n");
  15055. json_object *StartTransaction;
  15056. StartTransaction = json_tokener_parse(payload);
  15057. if(!is_error(StartTransaction))
  15058. {
  15059. // Required data
  15060. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15061. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15062. // Optional data
  15063. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15064. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15065. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15066. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15067. }
  15068. json_object_put(StartTransaction);
  15069. OCPP_updatePeriodEnergy(gun_index);
  15070. //-----------Start : write to the Queue TransactionId file -----------------//
  15071. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15072. {}
  15073. else
  15074. {
  15075. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15076. if(log == NULL)
  15077. {
  15078. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15079. return ;
  15080. }
  15081. else
  15082. {
  15083. fclose(log);
  15084. }
  15085. }
  15086. // open file for writing
  15087. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15088. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15089. {
  15090. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15091. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15092. fputs(data, outfile);
  15093. fclose (outfile);
  15094. }
  15095. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15096. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15097. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15098. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15099. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15100. isQueueSendable = 1;
  15101. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15102. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15103. }
  15104. void handleStatusNotificationResponse(char *payload, int gun_index)
  15105. {
  15106. mtrace();
  15107. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15108. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15109. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15110. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15111. }
  15112. void handleStopTransactionnResponse(char *payload, int gun_index)
  15113. {
  15114. mtrace();
  15115. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15116. json_object *StopTransaction;
  15117. StopTransaction = json_tokener_parse(payload);
  15118. if(!is_error(StopTransaction))
  15119. {
  15120. // Optional data
  15121. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15122. {
  15123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15124. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15126. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15128. }
  15129. }
  15130. json_object_put(StopTransaction);
  15131. isQueueSendable = 1;
  15132. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15133. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15134. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15135. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15136. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15137. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15138. }
  15139. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15140. {
  15141. mtrace();
  15142. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15143. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15144. }
  15145. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15146. {
  15147. mtrace();
  15148. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15149. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15150. }
  15151. void handleSignCertificateResponse(char *payload, int gun_index)
  15152. {
  15153. mtrace();
  15154. DEBUG_INFO("handleSignCertificateResponse...\n");
  15155. json_object *SignCertificate;
  15156. SignCertificate = json_tokener_parse(payload);
  15157. if(!is_error(SignCertificate))
  15158. {
  15159. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15160. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15161. }
  15162. json_object_put(SignCertificate);
  15163. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15164. }
  15165. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15166. {
  15167. mtrace();
  15168. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15169. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15170. }
  15171. //==========================================
  15172. // Handle Error routine
  15173. //==========================================
  15174. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15175. {
  15176. mtrace();
  15177. #ifdef SystemLogMessage
  15178. DEBUG_INFO("errorCode: %s\n", errorCode);
  15179. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15180. DEBUG_INFO("errorDetails: %s\n", payload);
  15181. #endif
  15182. }
  15183. //===============================================
  15184. // Common routine
  15185. //===============================================
  15186. int initialConfigurationTable(void)
  15187. {
  15188. //clock_t start_t, end_t, total_t;
  15189. FILE *fp;
  15190. FILE *outfile;
  15191. char str[512]={0};
  15192. char sstr[256]={0};
  15193. int c = 0;
  15194. char *loc;
  15195. int confVersion = 20;
  15196. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15197. //start_t = clock();
  15198. //printf("Starting of the program, start_t = %ld\n", start_t);
  15199. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15200. // Check configuration file size is correct
  15201. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15202. {
  15203. struct stat st;
  15204. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15205. if(st.st_size < 3100)
  15206. {
  15207. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15208. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15209. }
  15210. }
  15211. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15212. {
  15213. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15214. if(outfile == NULL)
  15215. {
  15216. DEBUG_INFO("Error opening file\n");
  15217. return FALSE;
  15218. }
  15219. /*Core Profile*/
  15220. //AllowOfflineTxForUnknownId
  15221. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15225. //AuthorizationCacheEnabled
  15226. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15230. //AuthorizeRemoteTxRequests
  15231. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15235. //BlinkRepeat
  15236. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15240. //ClockAlignedDataInterval
  15241. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15245. //ConnectionTimeOut
  15246. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15248. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15250. else
  15251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15253. //GetConfigurationMaxKeys
  15254. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15258. // HeartbeatInterval
  15259. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15263. // LightIntensity
  15264. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15268. // LocalAuthorizeOffline
  15269. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15273. // LocalPreAuthorize
  15274. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15278. // MaxEnergyOnInvalidId
  15279. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15283. // MeterValuesAlignedData
  15284. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15287. 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" );
  15288. else
  15289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15291. // MeterValuesAlignedDataMaxLength
  15292. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15296. else
  15297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15299. // MeterValuesSampledData
  15300. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15302. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15303. 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" );
  15304. else
  15305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15307. // MeterValuesSampledDataMaxLength
  15308. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15310. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15312. else
  15313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15315. // MeterValueSampleInterval
  15316. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15320. // MinimumStatusDuration
  15321. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15324. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15326. // NumberOfConnectors
  15327. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15330. {
  15331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15332. }
  15333. else
  15334. {
  15335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15336. }
  15337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15338. // ResetRetries
  15339. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15343. // ConnectorPhaseRotation
  15344. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15348. // ConnectorPhaseRotationMaxLength
  15349. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15353. // StopTransactionOnEVSideDisconnect
  15354. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15358. // StopTransactionOnInvalidId
  15359. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15363. // StopTxnAlignedData
  15364. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15368. // StopTxnAlignedDataMaxLength
  15369. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15373. // StopTxnSampledData
  15374. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15376. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  15378. else
  15379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  15380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15381. // StopTxnSampledDataMaxLength
  15382. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15385. {
  15386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  15387. }
  15388. else
  15389. {
  15390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  15391. }
  15392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15393. // SupportedFeatureProfiles
  15394. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15398. // SupportedFeatureProfilesMaxLength
  15399. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15403. // TransactionMessageAttempts
  15404. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15407. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15409. // TransactionMessageRetryInterval
  15410. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15413. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15415. // UnlockConnectorOnEVSideDisconnect
  15416. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15420. // WebSocketPingInterval
  15421. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15425. // QueueOffLineMeterValues
  15426. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15430. // AuthorizationKey
  15431. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15435. // SecurityProfile
  15436. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15440. // DefaultPrice
  15441. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15445. // CustomDisplayCostAndPrice
  15446. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15450. // CustomIdleFeeAfterStop
  15451. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15455. // TimeOffset
  15456. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15460. // NextTimeOffsetTransitionDateTime
  15461. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15465. // TimeOffsetNextTransition
  15466. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15470. // SystemUptimeSec
  15471. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15475. // FreeVend
  15476. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15480. // FreeVendIdtag
  15481. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15485. // OcppServer
  15486. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15488. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15490. // MaintainServer
  15491. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15493. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15495. // StatusNotificationPeriodically
  15496. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15500. // StatusNotificationInterval
  15501. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15505. // PreAuthAmount
  15506. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15510. // isEnableLocalPowerSharing
  15511. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15515. // PowerSharingServerIP
  15516. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15518. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15520. // EVCCID_PREFIX
  15521. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15525. // OffLineMaxChargingPower
  15526. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15530. // Configuration Version
  15531. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15535. // Charging profile refresh interval
  15536. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15540. // Ocpp Software certificated version
  15541. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15545. //* Local Auth List Management Profile*/
  15546. #if 0
  15547. //For OCTT Test Case
  15548. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15551. #endif
  15552. #if 1
  15553. //LocalAuthListEnabled
  15554. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15558. #endif
  15559. //LocalAuthListMaxLength
  15560. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15564. //SendLocalListMaxLength
  15565. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15569. //ReserveConnectorZeroSupported
  15570. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15574. //* Smart Charging Profile */
  15575. //ChargeProfileMaxStackLevel
  15576. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15580. // ChargingScheduleAllowedChargingRateUnit
  15581. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15585. // ChargingScheduleMaxPeriods
  15586. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15590. // ConnectorSwitch3to1PhaseSupported
  15591. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15595. // MaxChargingProfilesInstalled
  15596. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15600. fclose(outfile);
  15601. }
  15602. else
  15603. {
  15604. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15605. char keystr[60]={0};
  15606. char readonlystr[10]={0};
  15607. char valuestr[256]={0};
  15608. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15609. if(fp == NULL) {
  15610. DEBUG_INFO("Error opening file");
  15611. return FALSE;
  15612. }
  15613. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15614. {
  15615. //DEBUG_INFO("Get Configuration \n");
  15616. if(strlen(str) > 0)
  15617. {
  15618. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15619. //*************************key*********************************/
  15620. if(strstr(str, "key") != NULL)
  15621. {
  15622. loc = strstr(str, "key");
  15623. c = 0;
  15624. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15625. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15626. {
  15627. sstr[c] = loc[strlen("key")+3+c];
  15628. c++;
  15629. }
  15630. sstr[c] = '\0';
  15631. strcpy(keystr,sstr);
  15632. }
  15633. //*************************readonly*********************************/
  15634. if(strstr(str, "readonly") != NULL)
  15635. {
  15636. loc = strstr(str, "readonly");
  15637. c = 0;
  15638. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15639. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  15640. {
  15641. sstr[c] = loc[strlen("readonly")+2+c];
  15642. c++;
  15643. }
  15644. sstr[c] = '\0';
  15645. strcpy(readonlystr,sstr);
  15646. }
  15647. //*************************value*********************************/
  15648. if(strstr(str, "value") != NULL)
  15649. {
  15650. loc = strstr(str, "value");
  15651. c = 0;
  15652. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15653. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15654. {
  15655. sstr[c] = loc[strlen("value")+3+c];
  15656. c++;
  15657. }
  15658. sstr[c] = '\0';
  15659. strcpy(valuestr,sstr);
  15660. }
  15661. // DEBUG_INFO("keystr=%s\n",keystr);
  15662. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15663. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15664. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15665. {
  15666. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15667. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15669. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15670. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15671. }
  15672. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15673. {
  15674. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15675. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  15677. }
  15678. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  15679. {
  15680. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  15682. }
  15683. if(strcmp(keystr, "BlinkRepeat") == 0)
  15684. {
  15685. //Charger.BlinkRepeat = Integer.parseInt(value);
  15686. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  15688. }
  15689. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  15690. {
  15691. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  15693. }
  15694. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  15695. {
  15696. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  15698. }
  15699. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  15700. {
  15701. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  15703. }
  15704. if(strcmp(keystr, "HeartbeatInterval") == 0)
  15705. {
  15706. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  15708. HeartBeatWaitTime = atoi(valuestr);
  15709. }
  15710. if(strcmp(keystr, "LightIntensity") == 0)
  15711. {
  15712. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  15714. }
  15715. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  15716. {
  15717. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  15719. }
  15720. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  15721. {
  15722. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  15724. }
  15725. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  15726. {
  15727. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  15729. }
  15730. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  15731. {
  15732. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  15734. }
  15735. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  15736. {
  15737. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  15739. }
  15740. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  15741. {
  15742. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  15744. }
  15745. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  15746. {
  15747. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  15749. }
  15750. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  15751. {
  15752. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  15754. }
  15755. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  15756. {
  15757. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  15759. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  15760. }
  15761. if(strcmp(keystr, "NumberOfConnectors") == 0)
  15762. {
  15763. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  15765. }
  15766. if(strcmp(keystr, "ResetRetries") == 0)
  15767. {
  15768. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  15770. }
  15771. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  15772. {
  15773. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  15775. }
  15776. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  15777. {
  15778. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  15780. }
  15781. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  15782. {
  15783. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  15785. }
  15786. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  15787. {
  15788. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  15790. }
  15791. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  15792. {
  15793. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  15795. }
  15796. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  15797. {
  15798. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15800. }
  15801. if(strcmp(keystr, "StopTxnSampledData") == 0)
  15802. {
  15803. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  15805. }
  15806. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  15807. {
  15808. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  15810. }
  15811. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  15812. {
  15813. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  15815. }
  15816. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  15817. {
  15818. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  15820. }
  15821. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  15822. {
  15823. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  15825. TransactionMessageAttemptsValue = atoi(valuestr);
  15826. }
  15827. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  15828. {
  15829. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  15831. TransactionMessageRetryIntervalValue = atoi(valuestr);
  15832. }
  15833. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  15834. {
  15835. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  15837. }
  15838. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  15839. {
  15840. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  15842. }
  15843. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  15844. {
  15845. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  15847. }
  15848. if(strcmp(keystr, "AuthorizationKey") == 0)
  15849. {
  15850. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15851. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  15852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15853. }
  15854. if(strcmp(keystr, "SecurityProfile") == 0)
  15855. {
  15856. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15858. }
  15859. if(strcmp(keystr, "DefaultPrice") == 0)
  15860. {
  15861. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  15863. }
  15864. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  15865. {
  15866. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  15868. }
  15869. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  15870. {
  15871. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  15873. }
  15874. if(strcmp(keystr, "TimeOffset") == 0)
  15875. {
  15876. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  15878. }
  15879. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  15880. {
  15881. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  15883. }
  15884. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  15885. {
  15886. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  15888. }
  15889. if(strcmp(keystr, "SystemUptimeSec") == 0)
  15890. {
  15891. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  15893. }
  15894. if(strcmp(keystr, "FreeVend") == 0)
  15895. {
  15896. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  15898. }
  15899. if(strcmp(keystr, "FreeVendIdtag") == 0)
  15900. {
  15901. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  15903. }
  15904. if(strcmp(keystr, "OcppServer") == 0)
  15905. {
  15906. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15907. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15908. }
  15909. if(strcmp(keystr, "MaintainServer") == 0)
  15910. {
  15911. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15912. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  15913. }
  15914. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  15915. {
  15916. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  15918. }
  15919. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  15920. {
  15921. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  15923. }
  15924. if(strcmp(keystr, "PreAuthAmount") == 0)
  15925. {
  15926. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  15928. }
  15929. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  15930. {
  15931. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15933. }
  15934. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  15935. {
  15936. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15937. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  15938. }
  15939. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  15940. {
  15941. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  15943. }
  15944. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  15945. {
  15946. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  15948. }
  15949. if(strcmp(keystr, "ConfigurationVersion") == 0)
  15950. {
  15951. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  15953. }
  15954. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  15955. {
  15956. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  15958. }
  15959. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  15960. {
  15961. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15962. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  15963. }
  15964. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  15965. {
  15966. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  15968. }
  15969. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  15970. {
  15971. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  15973. }
  15974. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  15975. {
  15976. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  15978. }
  15979. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  15980. {
  15981. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  15983. }
  15984. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  15985. {
  15986. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  15988. }
  15989. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15990. {
  15991. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  15993. }
  15994. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  15995. {
  15996. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  15998. }
  15999. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16000. {
  16001. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16003. }
  16004. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16005. {
  16006. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16008. }
  16009. }
  16010. }
  16011. fclose(fp);
  16012. }
  16013. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16014. {
  16015. return PASS;
  16016. }
  16017. else
  16018. {
  16019. return FAIL;
  16020. }
  16021. }
  16022. void StoreConfigurationTable(void)
  16023. {
  16024. FILE *outfile;
  16025. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16026. if(outfile == NULL)
  16027. {
  16028. DEBUG_INFO("Error opening file");
  16029. return ;
  16030. }
  16031. /*Core Profile*/
  16032. //AllowOfflineTxForUnknownId
  16033. /*
  16034. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16035. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16038. */
  16039. //DEBUG_INFO("data=%s\n",data);
  16040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16041. //AuthorizationCacheEnabled
  16042. /*
  16043. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16046. */
  16047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16048. //AuthorizeRemoteTxRequests
  16049. /*
  16050. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16053. */
  16054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16055. //BlinkRepeat
  16056. /*
  16057. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16060. */
  16061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16062. //ClockAlignedDataInterval
  16063. /*
  16064. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16067. */
  16068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16069. //ConnectionTimeOut
  16070. /*
  16071. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16074. */
  16075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16076. //GetConfigurationMaxKeys
  16077. /*
  16078. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16081. */
  16082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16083. // HeartbeatInterval
  16084. /*
  16085. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16088. */
  16089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16090. // LightIntensity
  16091. /*
  16092. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16095. */
  16096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16097. // LocalAuthorizeOffline
  16098. /*
  16099. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16102. */
  16103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16104. // LocalPreAuthorize
  16105. /*
  16106. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16109. */
  16110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16111. // MaxEnergyOnInvalidId
  16112. /*
  16113. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16116. */
  16117. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16119. // MeterValuesAlignedData
  16120. /*
  16121. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16124. */
  16125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16126. // MeterValuesAlignedDataMaxLength
  16127. /*
  16128. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16131. */
  16132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16133. // MeterValuesSampledData
  16134. /*
  16135. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16138. */
  16139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16140. // MeterValuesSampledDataMaxLength
  16141. /*
  16142. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16145. */
  16146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16147. // MeterValueSampleInterval
  16148. /*
  16149. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16152. */
  16153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16154. // MinimumStatusDuration
  16155. /*
  16156. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16159. */
  16160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16161. // NumberOfConnectors
  16162. /*
  16163. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16166. {
  16167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16168. }
  16169. else
  16170. {
  16171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16172. }
  16173. */
  16174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16175. // ResetRetries
  16176. /*
  16177. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16180. */
  16181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16182. // ConnectorPhaseRotation
  16183. /*
  16184. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16187. */
  16188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16189. // ConnectorPhaseRotationMaxLength
  16190. /*
  16191. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16194. */
  16195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16196. // StopTransactionOnEVSideDisconnect
  16197. /*
  16198. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16201. */
  16202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16203. // StopTransactionOnInvalidId
  16204. /*
  16205. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16208. */
  16209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16210. // StopTxnAlignedData
  16211. /*
  16212. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16215. */
  16216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16217. // StopTxnAlignedDataMaxLength
  16218. /*
  16219. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16222. */
  16223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16224. // StopTxnSampledData
  16225. /*
  16226. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16229. */
  16230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16231. // StopTxnSampledDataMaxLength
  16232. /*
  16233. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16236. */
  16237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16238. // SupportedFeatureProfiles
  16239. /*
  16240. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16243. */
  16244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16245. // SupportedFeatureProfilesMaxLength
  16246. /*
  16247. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16250. */
  16251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16252. // TransactionMessageAttempts
  16253. /*
  16254. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16257. */
  16258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16259. // TransactionMessageRetryInterval
  16260. /*
  16261. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16264. */
  16265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16266. // UnlockConnectorOnEVSideDisconnect
  16267. /*
  16268. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16271. */
  16272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16273. // WebSocketPingInterval
  16274. /*
  16275. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16278. */
  16279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16280. // QueueOffLineMeterValues
  16281. /*
  16282. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16285. */
  16286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16287. // AuthorizationKey
  16288. /*
  16289. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16292. */
  16293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16294. // SecurityProfile
  16295. /*
  16296. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16299. */
  16300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16301. // DefaultPrice
  16302. /*
  16303. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16306. */
  16307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16308. // CustomDisplayCostAndPrice
  16309. /*
  16310. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16313. */
  16314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16315. // CustomIdleFeeAfterStop
  16316. /*
  16317. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16320. */
  16321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16322. // TimeOffset
  16323. /*
  16324. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16327. */
  16328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16329. // NextTimeOffsetTransitionDateTime
  16330. /*
  16331. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16334. */
  16335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16336. // TimeOffsetNextTransition
  16337. /*
  16338. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16341. */
  16342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16343. // SystemUptimeSec
  16344. /*
  16345. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16348. */
  16349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16350. // FreeVend
  16351. /*
  16352. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16355. */
  16356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16357. // FreeVendIdtag
  16358. /*
  16359. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16362. */
  16363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16364. // OcppServer
  16365. /*
  16366. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16369. */
  16370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16371. // MaintainServer
  16372. /*
  16373. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16376. */
  16377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16378. // StatusNotificationPeriodically
  16379. /*
  16380. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16383. */
  16384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16385. // StatusNotificationInterval
  16386. /*
  16387. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16390. */
  16391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16392. // PreAuthAmount
  16393. /*
  16394. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16397. */
  16398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16399. // isEnableLocalPowerSharing
  16400. /*
  16401. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16404. */
  16405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16406. // PowerSharingServerIP
  16407. /*
  16408. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16411. */
  16412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16413. // EVCCID_PREFIX
  16414. /*
  16415. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16418. */
  16419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16420. // OffLineMaxChargingPower
  16421. /*
  16422. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16425. */
  16426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16427. // ConfigurationVersion
  16428. /*
  16429. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16432. */
  16433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16434. // CharingProfileRefreshInterval
  16435. /*
  16436. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16439. */
  16440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16441. // OcppSoftwareVersion
  16442. /*
  16443. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16446. */
  16447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16448. //* Local Auth List Management Profile*/
  16449. //LocalAuthListEnabled
  16450. /*
  16451. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16454. */
  16455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16456. //LocalAuthListMaxLength
  16457. /*
  16458. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16461. */
  16462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16463. //SendLocalListMaxLength
  16464. /*
  16465. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16468. */
  16469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16470. //ReserveConnectorZeroSupported
  16471. /*
  16472. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16475. */
  16476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16477. //* Smart Charging Profile */
  16478. //ChargeProfileMaxStackLevel
  16479. /*
  16480. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16483. */
  16484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16485. // ChargingScheduleAllowedChargingRateUnit
  16486. /*
  16487. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16490. */
  16491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16492. // ChargingScheduleMaxPeriods
  16493. /*
  16494. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16497. */
  16498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16499. // ConnectorSwitch3to1PhaseSupported
  16500. /*
  16501. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16504. */
  16505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16506. // MaxChargingProfilesInstalled
  16507. /*
  16508. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16511. */
  16512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16513. fclose(outfile);
  16514. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16515. }
  16516. void getKeyValue(char *keyReq)
  16517. {
  16518. int isEmpty = FALSE;
  16519. int isKnowKey = FALSE;
  16520. DEBUG_INFO("keyReq = %s\n", keyReq);
  16521. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16522. isEmpty = TRUE;
  16523. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16524. {
  16525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16528. {
  16529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16530. }
  16531. else
  16532. {
  16533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16534. }
  16535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16536. isKnowKey = TRUE;
  16537. }
  16538. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16539. {
  16540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16543. {
  16544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16545. }
  16546. else
  16547. {
  16548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16549. }
  16550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16551. isKnowKey = TRUE;
  16552. }
  16553. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16554. {
  16555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16558. {
  16559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16560. }
  16561. else
  16562. {
  16563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16564. }
  16565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16566. isKnowKey = TRUE;
  16567. }
  16568. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16569. {
  16570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16573. {
  16574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16575. }
  16576. else
  16577. {
  16578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16579. }
  16580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16581. isKnowKey = TRUE;
  16582. }
  16583. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16584. {
  16585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16588. {
  16589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16590. }
  16591. else
  16592. {
  16593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16594. }
  16595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16596. isKnowKey = TRUE;
  16597. }
  16598. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16599. {
  16600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16603. {
  16604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16605. }
  16606. else
  16607. {
  16608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16609. }
  16610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16611. isKnowKey = TRUE;
  16612. }
  16613. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16614. {
  16615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16618. {
  16619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16620. }
  16621. else
  16622. {
  16623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  16624. }
  16625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  16626. isKnowKey = TRUE;
  16627. }
  16628. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  16629. {
  16630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  16631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  16632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16633. {
  16634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  16635. }
  16636. else
  16637. {
  16638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  16639. }
  16640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  16641. isKnowKey = TRUE;
  16642. }
  16643. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  16644. {
  16645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  16646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  16647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16648. {
  16649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  16650. }
  16651. else
  16652. {
  16653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  16654. }
  16655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  16656. isKnowKey = TRUE;
  16657. }
  16658. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  16659. {
  16660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  16661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  16662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16663. {
  16664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  16665. }
  16666. else
  16667. {
  16668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  16669. }
  16670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  16671. isKnowKey = TRUE;
  16672. }
  16673. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  16674. {
  16675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  16676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  16677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16678. {
  16679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  16680. }
  16681. else
  16682. {
  16683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  16684. }
  16685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  16686. isKnowKey = TRUE;
  16687. }
  16688. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  16689. {
  16690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  16691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  16692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16693. {
  16694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16695. }
  16696. else
  16697. {
  16698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16699. }
  16700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  16701. isKnowKey = TRUE;
  16702. }
  16703. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  16704. {
  16705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  16706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  16707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16708. {
  16709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16710. }
  16711. else
  16712. {
  16713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16714. }
  16715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  16716. isKnowKey = TRUE;
  16717. }
  16718. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  16719. {
  16720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  16721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  16722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16723. {
  16724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16725. }
  16726. else
  16727. {
  16728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16729. }
  16730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  16731. isKnowKey = TRUE;
  16732. }
  16733. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  16734. {
  16735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  16736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  16737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16738. {
  16739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  16740. }
  16741. else
  16742. {
  16743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  16744. }
  16745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  16746. isKnowKey = TRUE;
  16747. }
  16748. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  16749. {
  16750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  16751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  16752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16753. {
  16754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16755. }
  16756. else
  16757. {
  16758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16759. }
  16760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  16761. isKnowKey = TRUE;
  16762. }
  16763. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  16764. {
  16765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  16766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  16767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16768. {
  16769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  16770. }
  16771. else
  16772. {
  16773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  16774. }
  16775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  16776. isKnowKey = TRUE;
  16777. }
  16778. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  16779. {
  16780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  16781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  16782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16783. {
  16784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  16785. }
  16786. else
  16787. {
  16788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  16789. }
  16790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  16791. isKnowKey = TRUE;
  16792. }
  16793. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  16794. {
  16795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  16796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  16797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16798. {
  16799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  16800. }
  16801. else
  16802. {
  16803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  16804. }
  16805. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  16806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  16807. isKnowKey = TRUE;
  16808. }
  16809. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  16810. {
  16811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  16812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  16813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16814. {
  16815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  16816. }
  16817. else
  16818. {
  16819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  16820. }
  16821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  16822. isKnowKey = TRUE;
  16823. }
  16824. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  16825. {
  16826. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  16827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  16828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16829. {
  16830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  16831. }
  16832. else
  16833. {
  16834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  16835. }
  16836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  16837. isKnowKey = TRUE;
  16838. }
  16839. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  16840. {
  16841. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  16842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  16843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16844. {
  16845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16846. }
  16847. else
  16848. {
  16849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16850. }
  16851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  16852. isKnowKey = TRUE;
  16853. }
  16854. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  16855. {
  16856. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  16857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  16858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16859. {
  16860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16861. }
  16862. else
  16863. {
  16864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16865. }
  16866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  16867. isKnowKey = TRUE;
  16868. }
  16869. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  16870. {
  16871. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  16872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  16873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16874. {
  16875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  16876. }
  16877. else
  16878. {
  16879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  16880. }
  16881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  16882. isKnowKey = TRUE;
  16883. }
  16884. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  16885. {
  16886. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  16887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  16888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16889. {
  16890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  16891. }
  16892. else
  16893. {
  16894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  16895. }
  16896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  16897. isKnowKey = TRUE;
  16898. }
  16899. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  16900. {
  16901. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  16902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  16903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16904. {
  16905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16906. }
  16907. else
  16908. {
  16909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16910. }
  16911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  16912. isKnowKey = TRUE;
  16913. }
  16914. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  16915. {
  16916. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  16917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  16918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16919. {
  16920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  16921. }
  16922. else
  16923. {
  16924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  16925. }
  16926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  16927. isKnowKey = TRUE;
  16928. }
  16929. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  16930. {
  16931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  16932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  16933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16934. {
  16935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16936. }
  16937. else
  16938. {
  16939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16940. }
  16941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  16942. isKnowKey = TRUE;
  16943. }
  16944. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  16945. {
  16946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  16947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  16948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16949. {
  16950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  16951. }
  16952. else
  16953. {
  16954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  16955. }
  16956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  16957. isKnowKey = TRUE;
  16958. }
  16959. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  16960. {
  16961. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  16962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  16963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16964. {
  16965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16966. }
  16967. else
  16968. {
  16969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16970. }
  16971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  16972. isKnowKey = TRUE;
  16973. }
  16974. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  16975. {
  16976. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  16977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  16978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16979. {
  16980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  16981. }
  16982. else
  16983. {
  16984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  16985. }
  16986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  16987. isKnowKey = TRUE;
  16988. }
  16989. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  16990. {
  16991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  16992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  16993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16994. {
  16995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  16996. }
  16997. else
  16998. {
  16999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17000. }
  17001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17002. isKnowKey = TRUE;
  17003. }
  17004. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17005. {
  17006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17009. {
  17010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17011. }
  17012. else
  17013. {
  17014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17015. }
  17016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17017. isKnowKey = TRUE;
  17018. }
  17019. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17020. {
  17021. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17024. {
  17025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17026. }
  17027. else
  17028. {
  17029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17030. }
  17031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17032. isKnowKey = TRUE;
  17033. }
  17034. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17035. {
  17036. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17039. {
  17040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17041. }
  17042. else
  17043. {
  17044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17045. }
  17046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17047. isKnowKey = TRUE;
  17048. }
  17049. /*
  17050. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17051. {
  17052. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17055. {
  17056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17057. }
  17058. else
  17059. {
  17060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17061. }
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17063. isKnowKey = TRUE;
  17064. }*/
  17065. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17066. {
  17067. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17070. {
  17071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17072. }
  17073. else
  17074. {
  17075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17076. }
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17078. isKnowKey = TRUE;
  17079. }
  17080. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17081. {
  17082. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17085. {
  17086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17087. }
  17088. else
  17089. {
  17090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17091. }
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17093. isKnowKey = TRUE;
  17094. }
  17095. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17096. {
  17097. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17100. {
  17101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17102. }
  17103. else
  17104. {
  17105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17106. }
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17108. isKnowKey = TRUE;
  17109. }
  17110. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17111. {
  17112. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17115. {
  17116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17117. }
  17118. else
  17119. {
  17120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17121. }
  17122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17123. isKnowKey = TRUE;
  17124. }
  17125. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17126. {
  17127. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17130. {
  17131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17132. }
  17133. else
  17134. {
  17135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17136. }
  17137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17138. isKnowKey = TRUE;
  17139. }
  17140. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17141. {
  17142. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17145. {
  17146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17147. }
  17148. else
  17149. {
  17150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17151. }
  17152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17153. isKnowKey = TRUE;
  17154. }
  17155. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17156. {
  17157. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17160. {
  17161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17162. }
  17163. else
  17164. {
  17165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17166. }
  17167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17168. isKnowKey = TRUE;
  17169. }
  17170. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17171. {
  17172. struct sysinfo s_info;
  17173. int error = sysinfo(&s_info);
  17174. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17177. {
  17178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17179. }
  17180. else
  17181. {
  17182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17183. }
  17184. if(error != 0)
  17185. {
  17186. DEBUG_WARN("System uptime get error: %d\n", error);
  17187. }
  17188. else
  17189. {
  17190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17191. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17192. }
  17193. isKnowKey = TRUE;
  17194. }
  17195. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17196. {
  17197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17200. {
  17201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17202. }
  17203. else
  17204. {
  17205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17206. }
  17207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17208. isKnowKey = TRUE;
  17209. }
  17210. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17211. {
  17212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17215. {
  17216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17217. }
  17218. else
  17219. {
  17220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17221. }
  17222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17223. isKnowKey = TRUE;
  17224. }
  17225. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17226. {
  17227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17230. {
  17231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17232. }
  17233. else
  17234. {
  17235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17236. }
  17237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17238. isKnowKey = TRUE;
  17239. }
  17240. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17241. {
  17242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17245. {
  17246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17247. }
  17248. else
  17249. {
  17250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17251. }
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17253. isKnowKey = TRUE;
  17254. }
  17255. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17256. {
  17257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17260. {
  17261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17262. }
  17263. else
  17264. {
  17265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17266. }
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17268. isKnowKey = TRUE;
  17269. }
  17270. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17271. {
  17272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17275. {
  17276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17277. }
  17278. else
  17279. {
  17280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17281. }
  17282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17283. isKnowKey = TRUE;
  17284. }
  17285. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17286. {
  17287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17290. {
  17291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17292. }
  17293. else
  17294. {
  17295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17296. }
  17297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17298. isKnowKey = TRUE;
  17299. }
  17300. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17301. {
  17302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17305. {
  17306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17307. }
  17308. else
  17309. {
  17310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17311. }
  17312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17313. isKnowKey = TRUE;
  17314. }
  17315. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17316. {
  17317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17320. {
  17321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17322. }
  17323. else
  17324. {
  17325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17326. }
  17327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17328. isKnowKey = TRUE;
  17329. }
  17330. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17331. {
  17332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17335. {
  17336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17337. }
  17338. else
  17339. {
  17340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17341. }
  17342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17343. isKnowKey = TRUE;
  17344. }
  17345. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17346. {
  17347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17350. {
  17351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17352. }
  17353. else
  17354. {
  17355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17356. }
  17357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17358. isKnowKey = TRUE;
  17359. }
  17360. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17361. {
  17362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17365. {
  17366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17367. }
  17368. else
  17369. {
  17370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17371. }
  17372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17373. isKnowKey = TRUE;
  17374. }
  17375. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17376. {
  17377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17380. {
  17381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17382. }
  17383. else
  17384. {
  17385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17386. }
  17387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17388. isKnowKey = TRUE;
  17389. }
  17390. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17391. {
  17392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17395. {
  17396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17397. }
  17398. else
  17399. {
  17400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17401. }
  17402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17403. isKnowKey = TRUE;
  17404. }
  17405. #if 1
  17406. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17407. {
  17408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17410. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17411. {
  17412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17413. }
  17414. else
  17415. {
  17416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17417. }
  17418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17419. isKnowKey = TRUE;
  17420. }
  17421. #endif
  17422. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17423. {
  17424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17426. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17427. {
  17428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17429. }
  17430. else
  17431. {
  17432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17433. }
  17434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17435. isKnowKey = TRUE;
  17436. }
  17437. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17438. {
  17439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17441. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17442. {
  17443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17444. }
  17445. else
  17446. {
  17447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17448. }
  17449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17450. isKnowKey = TRUE;
  17451. }
  17452. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17453. {
  17454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17456. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17457. {
  17458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17459. }
  17460. else
  17461. {
  17462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17463. }
  17464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17465. isKnowKey = TRUE;
  17466. }
  17467. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17468. {
  17469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17471. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17472. {
  17473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17474. }
  17475. else
  17476. {
  17477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17478. }
  17479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17480. isKnowKey = TRUE;
  17481. }
  17482. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17483. {
  17484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17486. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17487. {
  17488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17489. }
  17490. else
  17491. {
  17492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17493. }
  17494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17495. isKnowKey = TRUE;
  17496. }
  17497. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17498. {
  17499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17501. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17502. {
  17503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17504. }
  17505. else
  17506. {
  17507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17508. }
  17509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17510. isKnowKey = TRUE;
  17511. }
  17512. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17513. {
  17514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17516. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17517. {
  17518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17519. }
  17520. else
  17521. {
  17522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17523. }
  17524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17525. isKnowKey = TRUE;
  17526. }
  17527. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17528. {
  17529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17531. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17532. {
  17533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17534. }
  17535. else
  17536. {
  17537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17538. }
  17539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17540. isKnowKey = TRUE;
  17541. }
  17542. //=========================================================
  17543. if(!isEmpty && !isKnowKey)
  17544. {
  17545. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17546. strcpy(unknownkey[UnknownKeynum], keyReq);
  17547. UnknownKeynum = UnknownKeynum + 1;
  17548. }
  17549. }
  17550. void processUnkownKey(void)
  17551. {
  17552. DEBUG_INFO("processUnkownKey...\n");
  17553. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17554. for(int index=0; index < UnknownKeynum; index++)
  17555. {
  17556. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17557. {
  17558. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17559. }
  17560. }
  17561. }
  17562. int setKeyValue(char *key, char *value)
  17563. {
  17564. int isSuccess = NotSupported;
  17565. int check_ascii=0;
  17566. char str[501]={0};
  17567. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17568. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17569. {
  17570. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17572. {
  17573. strcpy(str, (const char*)value);
  17574. for(int i = 0; str[i]; i++){
  17575. str[i] = tolower(str[i]);
  17576. }
  17577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17578. isSuccess = ConfigurationStatus_Accepted;
  17579. }
  17580. else
  17581. {
  17582. isSuccess = ConfigurationStatus_Rejected;
  17583. }
  17584. }
  17585. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17586. {
  17587. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17589. {
  17590. strcpy(str, (const char*)value);
  17591. for(int i = 0; str[i]; i++){
  17592. str[i] = tolower(str[i]);
  17593. }
  17594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17595. isSuccess = ConfigurationStatus_Accepted;
  17596. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  17597. }
  17598. else
  17599. {
  17600. isSuccess = ConfigurationStatus_Rejected;
  17601. }
  17602. }
  17603. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  17604. {
  17605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17606. {
  17607. strcpy(str, (const char*)value);
  17608. for(int i = 0; str[i]; i++)
  17609. {
  17610. str[i] = tolower(str[i]);
  17611. }
  17612. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  17613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17614. isSuccess = ConfigurationStatus_Accepted;
  17615. }
  17616. else
  17617. {
  17618. isSuccess = ConfigurationStatus_Rejected;
  17619. }
  17620. }
  17621. if(strcmp(key, "BlinkRepeat") == 0)
  17622. {
  17623. //Charger.BlinkRepeat = Integer.parseInt(value);
  17624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17625. {
  17626. check_ascii = value[0];
  17627. if( (check_ascii < 48) || (check_ascii > 57) )
  17628. {
  17629. isSuccess = ConfigurationStatus_Rejected;
  17630. }
  17631. else
  17632. {
  17633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  17634. isSuccess = ConfigurationStatus_Accepted;
  17635. }
  17636. }
  17637. else
  17638. {
  17639. isSuccess = ConfigurationStatus_Rejected;
  17640. }
  17641. }
  17642. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  17643. {
  17644. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17645. {
  17646. check_ascii = value[0];
  17647. if( (check_ascii < 48) || (check_ascii > 57) )
  17648. {
  17649. isSuccess = ConfigurationStatus_Rejected;
  17650. }
  17651. else
  17652. {
  17653. if((atoi(value) == 0) || (atoi(value) >= 5))
  17654. {
  17655. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  17656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  17657. isSuccess = ConfigurationStatus_Accepted;
  17658. }
  17659. else
  17660. isSuccess = ConfigurationStatus_Rejected;
  17661. }
  17662. }
  17663. else
  17664. {
  17665. isSuccess = ConfigurationStatus_Rejected;
  17666. }
  17667. }
  17668. if(strcmp(key, "ConnectionTimeOut") == 0 )
  17669. {
  17670. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17671. {
  17672. check_ascii = value[0];
  17673. if( (check_ascii < 48) || (check_ascii > 57) )
  17674. {
  17675. isSuccess = ConfigurationStatus_Rejected;
  17676. }
  17677. else
  17678. {
  17679. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  17680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  17681. isSuccess = ConfigurationStatus_Accepted;
  17682. }
  17683. }
  17684. else
  17685. {
  17686. isSuccess = ConfigurationStatus_Rejected;
  17687. }
  17688. }
  17689. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  17690. {
  17691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17692. {
  17693. check_ascii = value[0];
  17694. if( (check_ascii < 48) || (check_ascii > 57) )
  17695. {
  17696. isSuccess = ConfigurationStatus_Rejected;
  17697. }
  17698. else
  17699. {
  17700. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  17701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  17702. isSuccess = ConfigurationStatus_Accepted;
  17703. }
  17704. }
  17705. else
  17706. {
  17707. isSuccess = ConfigurationStatus_Rejected;
  17708. }
  17709. }
  17710. if(strcmp(key, "HeartbeatInterval") == 0)
  17711. {
  17712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17713. {
  17714. check_ascii = value[0];
  17715. if( (check_ascii < 48) || (check_ascii > 57) )
  17716. {
  17717. isSuccess = ConfigurationStatus_Rejected;
  17718. }
  17719. else
  17720. {
  17721. if((atoi(value) == 0) || (atoi(value) >= 10))
  17722. {
  17723. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  17724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  17725. HeartBeatWaitTime = atoi(value);
  17726. isSuccess = ConfigurationStatus_Accepted;
  17727. }
  17728. else
  17729. {
  17730. isSuccess = ConfigurationStatus_Rejected;
  17731. }
  17732. }
  17733. }
  17734. else
  17735. {
  17736. isSuccess = ConfigurationStatus_Rejected;
  17737. }
  17738. }
  17739. if(strcmp(key, "LightIntensity") == 0)
  17740. {
  17741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17742. {
  17743. check_ascii = value[0];
  17744. if( (check_ascii < 48) || (check_ascii > 57) )
  17745. {
  17746. isSuccess = ConfigurationStatus_Rejected;
  17747. }
  17748. else
  17749. {
  17750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  17751. isSuccess = ConfigurationStatus_Accepted;
  17752. }
  17753. }
  17754. else
  17755. {
  17756. isSuccess = ConfigurationStatus_Rejected;
  17757. }
  17758. }
  17759. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  17760. {
  17761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17762. {
  17763. strcpy(str, (const char*)value);
  17764. for(int i = 0; str[i]; i++)
  17765. {
  17766. str[i] = tolower(str[i]);
  17767. }
  17768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17769. isSuccess = ConfigurationStatus_Accepted;
  17770. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  17771. }
  17772. else
  17773. {
  17774. isSuccess = ConfigurationStatus_Rejected;
  17775. }
  17776. }
  17777. if(strcmp(key, "LocalPreAuthorize") == 0)
  17778. {
  17779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17780. {
  17781. strcpy(str, (const char*)value);
  17782. for(int i = 0; str[i]; i++)
  17783. {
  17784. str[i] = tolower(str[i]);
  17785. }
  17786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17787. isSuccess = ConfigurationStatus_Accepted;
  17788. }
  17789. else
  17790. {
  17791. isSuccess = ConfigurationStatus_Rejected;
  17792. }
  17793. }
  17794. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  17795. {
  17796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17797. {
  17798. check_ascii = value[0];
  17799. if( (check_ascii < 48) || (check_ascii > 57) )
  17800. {
  17801. isSuccess = ConfigurationStatus_Rejected;
  17802. }
  17803. else
  17804. {
  17805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  17806. isSuccess = ConfigurationStatus_Accepted;
  17807. }
  17808. }
  17809. else
  17810. {
  17811. isSuccess = ConfigurationStatus_Rejected;
  17812. }
  17813. }
  17814. if(strcmp(key, "MeterValuesAlignedData") == 0)
  17815. {
  17816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17817. {
  17818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  17819. isSuccess = ConfigurationStatus_Accepted;
  17820. }
  17821. else
  17822. {
  17823. isSuccess = ConfigurationStatus_Rejected;
  17824. }
  17825. }
  17826. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  17827. {
  17828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17829. {
  17830. check_ascii = value[0];
  17831. if( (check_ascii < 48) || (check_ascii > 57) )
  17832. {
  17833. isSuccess = ConfigurationStatus_Rejected;
  17834. }
  17835. else
  17836. {
  17837. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  17839. isSuccess = ConfigurationStatus_Accepted;
  17840. }
  17841. }
  17842. else
  17843. {
  17844. isSuccess = ConfigurationStatus_Rejected;
  17845. }
  17846. }
  17847. if(strcmp(key, "MeterValuesSampledData") == 0 )
  17848. {
  17849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17850. {
  17851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  17852. isSuccess = ConfigurationStatus_Accepted;
  17853. }
  17854. else
  17855. {
  17856. isSuccess = ConfigurationStatus_Rejected;
  17857. }
  17858. }
  17859. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  17860. {
  17861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17862. {
  17863. check_ascii = value[0];
  17864. if( (check_ascii < 48) || (check_ascii > 57) )
  17865. {
  17866. isSuccess = ConfigurationStatus_Rejected;
  17867. }
  17868. else
  17869. {
  17870. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  17872. isSuccess = ConfigurationStatus_Accepted;
  17873. }
  17874. }
  17875. else
  17876. {
  17877. isSuccess = ConfigurationStatus_Rejected;
  17878. }
  17879. }
  17880. if(strcmp(key, "MeterValueSampleInterval") == 0)
  17881. {
  17882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17883. {
  17884. check_ascii = value[0];
  17885. if( (check_ascii < 48) || (check_ascii > 57) )
  17886. {
  17887. isSuccess = ConfigurationStatus_Rejected;
  17888. }
  17889. else
  17890. {
  17891. if((atoi(value) == 0) || (atoi(value) >= 3))
  17892. {
  17893. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  17894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  17895. isSuccess = ConfigurationStatus_Accepted;
  17896. }
  17897. else
  17898. {
  17899. isSuccess = ConfigurationStatus_Rejected;
  17900. }
  17901. }
  17902. }
  17903. else
  17904. {
  17905. isSuccess = ConfigurationStatus_Rejected;
  17906. }
  17907. }
  17908. if(strcmp(key, "MinimumStatusDuration") == 0)
  17909. {
  17910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17911. {
  17912. check_ascii = value[0];
  17913. if( (check_ascii < 48) || (check_ascii > 57) )
  17914. {
  17915. isSuccess = ConfigurationStatus_Rejected;
  17916. }
  17917. else
  17918. {
  17919. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  17920. {
  17921. isSuccess = ConfigurationStatus_Rejected;
  17922. }
  17923. else
  17924. {
  17925. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  17926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  17927. server_cycle_Status = atoi(value); //StatusNotification Cycle
  17928. isSuccess = ConfigurationStatus_Accepted;
  17929. }
  17930. }
  17931. }
  17932. else
  17933. {
  17934. isSuccess = ConfigurationStatus_Rejected;
  17935. }
  17936. }
  17937. if(strcmp(key, "NumberOfConnectors") == 0)
  17938. {
  17939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17940. {
  17941. check_ascii = value[0];
  17942. if( (check_ascii < 48) || (check_ascii > 57) )
  17943. {
  17944. isSuccess = ConfigurationStatus_Rejected;
  17945. }
  17946. else
  17947. {
  17948. //Charger.ResetRetries = Integer.parseInt(value);
  17949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  17950. isSuccess = ConfigurationStatus_Accepted;
  17951. }
  17952. }
  17953. else
  17954. {
  17955. isSuccess = ConfigurationStatus_Rejected;
  17956. }
  17957. }
  17958. if(strcmp(key, "ResetRetries") == 0)
  17959. {
  17960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17961. {
  17962. check_ascii = value[0];
  17963. if( (check_ascii < 48) || (check_ascii > 57) )
  17964. {
  17965. isSuccess = ConfigurationStatus_Rejected;
  17966. }
  17967. else
  17968. {
  17969. //Charger.ResetRetries = Integer.parseInt(value);
  17970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  17971. isSuccess = ConfigurationStatus_Accepted;
  17972. }
  17973. }
  17974. else
  17975. {
  17976. isSuccess = ConfigurationStatus_Rejected;
  17977. }
  17978. }
  17979. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  17980. {
  17981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17982. {
  17983. strcpy(str, (const char*)value);
  17984. for(int i = 0; str[i]; i++)
  17985. {
  17986. str[i] = tolower(str[i]);
  17987. }
  17988. if(strcmp(str, "notapplicable")== 0)
  17989. {
  17990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  17991. isSuccess = ConfigurationStatus_Accepted;
  17992. }
  17993. else if(strcmp(str, "unknown")== 0)
  17994. {
  17995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  17996. isSuccess = ConfigurationStatus_Accepted;
  17997. }
  17998. else if(strcmp(str, "rst")== 0)
  17999. {
  18000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18001. isSuccess = ConfigurationStatus_Accepted;
  18002. }
  18003. else if(strcmp(str, "rts")== 0)
  18004. {
  18005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18006. isSuccess = ConfigurationStatus_Accepted;
  18007. }
  18008. else if(strcmp(str, "srt")== 0)
  18009. {
  18010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18011. isSuccess = ConfigurationStatus_Accepted;
  18012. }
  18013. else if(strcmp(str, "str")== 0)
  18014. {
  18015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18016. isSuccess = ConfigurationStatus_Accepted;
  18017. }
  18018. else if(strcmp(str, "trs")== 0)
  18019. {
  18020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18021. isSuccess = ConfigurationStatus_Accepted;
  18022. }
  18023. else if(strcmp(str, "tsr")== 0)
  18024. {
  18025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18026. isSuccess = ConfigurationStatus_Accepted;
  18027. }
  18028. else
  18029. {
  18030. isSuccess = ConfigurationStatus_Rejected;
  18031. }
  18032. }
  18033. else
  18034. {
  18035. isSuccess = ConfigurationStatus_Rejected;
  18036. }
  18037. }
  18038. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18039. {
  18040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18041. {
  18042. check_ascii = value[0];
  18043. if( (check_ascii < 48) || (check_ascii > 57) )
  18044. {
  18045. isSuccess = ConfigurationStatus_Rejected;
  18046. }
  18047. else
  18048. {
  18049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18050. isSuccess = ConfigurationStatus_Accepted;
  18051. }
  18052. }
  18053. else
  18054. {
  18055. isSuccess = ConfigurationStatus_Rejected;
  18056. }
  18057. }
  18058. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18059. {
  18060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18061. {
  18062. strcpy(str, (const char*)value);
  18063. for(int i = 0; str[i]; i++)
  18064. {
  18065. str[i] = tolower(str[i]);
  18066. }
  18067. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18069. isSuccess = ConfigurationStatus_Accepted;
  18070. }
  18071. else
  18072. {
  18073. isSuccess = ConfigurationStatus_Rejected;
  18074. }
  18075. }
  18076. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18077. {
  18078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18079. {
  18080. strcpy(str, (const char*)value);
  18081. for(int i = 0; str[i]; i++)
  18082. {
  18083. str[i] = tolower(str[i]);
  18084. }
  18085. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18087. isSuccess = ConfigurationStatus_Accepted;
  18088. }
  18089. else
  18090. {
  18091. isSuccess = ConfigurationStatus_Rejected;
  18092. }
  18093. }
  18094. if(strcmp(key, "StopTxnAlignedData") == 0)
  18095. {
  18096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18097. {
  18098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18099. isSuccess = ConfigurationStatus_Accepted;
  18100. }
  18101. else
  18102. {
  18103. isSuccess = ConfigurationStatus_Rejected;
  18104. }
  18105. }
  18106. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18107. {
  18108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18109. {
  18110. check_ascii = value[0];
  18111. if( (check_ascii < 48) || (check_ascii > 57) )
  18112. {
  18113. isSuccess = ConfigurationStatus_Rejected;
  18114. }
  18115. else
  18116. {
  18117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18118. isSuccess = ConfigurationStatus_Accepted;
  18119. }
  18120. }
  18121. else
  18122. {
  18123. isSuccess = ConfigurationStatus_Rejected;
  18124. }
  18125. }
  18126. if(strcmp(key, "StopTxnSampledData") == 0)
  18127. {
  18128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18129. {
  18130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18131. isSuccess = ConfigurationStatus_Accepted;
  18132. }
  18133. else
  18134. {
  18135. isSuccess = ConfigurationStatus_Rejected;
  18136. }
  18137. }
  18138. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18139. {
  18140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18141. {
  18142. check_ascii = value[0];
  18143. if( (check_ascii < 48) || (check_ascii > 57) )
  18144. {
  18145. isSuccess = ConfigurationStatus_Rejected;
  18146. }
  18147. else
  18148. {
  18149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18150. isSuccess = ConfigurationStatus_Accepted;
  18151. }
  18152. }
  18153. else
  18154. {
  18155. isSuccess = ConfigurationStatus_Rejected;
  18156. }
  18157. }
  18158. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18159. {
  18160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18161. {
  18162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18163. isSuccess = ConfigurationStatus_Accepted;
  18164. }
  18165. else
  18166. {
  18167. isSuccess = ConfigurationStatus_Rejected;
  18168. }
  18169. }
  18170. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18171. {
  18172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18173. {
  18174. check_ascii = value[0];
  18175. if( (check_ascii < 48) || (check_ascii > 57) )
  18176. {
  18177. isSuccess = ConfigurationStatus_Rejected;
  18178. }
  18179. else
  18180. {
  18181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18182. isSuccess = ConfigurationStatus_Accepted;
  18183. }
  18184. }
  18185. else
  18186. {
  18187. isSuccess = ConfigurationStatus_Rejected;
  18188. }
  18189. }
  18190. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18191. {
  18192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18193. {
  18194. check_ascii = value[0];
  18195. if( (check_ascii < 48) || (check_ascii > 57) )
  18196. {
  18197. isSuccess = ConfigurationStatus_Rejected;
  18198. }
  18199. else
  18200. {
  18201. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18203. TransactionMessageAttemptsValue = atoi(value);
  18204. isSuccess = ConfigurationStatus_Accepted;
  18205. }
  18206. }
  18207. else
  18208. {
  18209. isSuccess = ConfigurationStatus_Rejected;
  18210. }
  18211. }
  18212. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18213. {
  18214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18215. {
  18216. check_ascii = value[0];
  18217. if( (check_ascii < 48) || (check_ascii > 57) )
  18218. {
  18219. isSuccess = ConfigurationStatus_Rejected;
  18220. }
  18221. else
  18222. {
  18223. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18225. TransactionMessageRetryIntervalValue = atoi(value);
  18226. isSuccess = ConfigurationStatus_Accepted;
  18227. }
  18228. }
  18229. else
  18230. {
  18231. isSuccess = ConfigurationStatus_Rejected;
  18232. }
  18233. }
  18234. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18235. {
  18236. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18237. {
  18238. strcpy(str, (const char*)value);
  18239. for(int i = 0; str[i]; i++)
  18240. {
  18241. str[i] = tolower(str[i]);
  18242. }
  18243. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18245. isSuccess = ConfigurationStatus_Accepted;
  18246. }
  18247. else
  18248. {
  18249. isSuccess = ConfigurationStatus_Rejected;
  18250. }
  18251. }
  18252. if(strcmp(key, "WebSocketPingInterval") == 0)
  18253. {
  18254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18255. {
  18256. check_ascii = value[0];
  18257. if( (check_ascii < 48) || (check_ascii > 57) )
  18258. {
  18259. isSuccess = ConfigurationStatus_Rejected;
  18260. }
  18261. else
  18262. {
  18263. if((atoi(value) == 0) || (atoi(value) >= 10))
  18264. {
  18265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18266. isSuccess = ConfigurationStatus_Accepted;
  18267. }
  18268. else
  18269. isSuccess = ConfigurationStatus_Rejected;
  18270. }
  18271. }
  18272. else
  18273. {
  18274. isSuccess = ConfigurationStatus_Rejected;
  18275. }
  18276. }
  18277. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18278. {
  18279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18280. {
  18281. strcpy(str, (const char*)value);
  18282. for(int i = 0; str[i]; i++)
  18283. {
  18284. str[i] = tolower(str[i]);
  18285. }
  18286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18287. isSuccess = ConfigurationStatus_Accepted;
  18288. }
  18289. else
  18290. {
  18291. isSuccess = ConfigurationStatus_Rejected;
  18292. }
  18293. }
  18294. if(strcmp(key, "AuthorizationKey") == 0)
  18295. {
  18296. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18297. {
  18298. strcpy(str, (const char*)value);
  18299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  18300. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18301. isSuccess = ConfigurationStatus_Accepted;
  18302. }
  18303. else
  18304. {
  18305. isSuccess = ConfigurationStatus_Rejected;
  18306. }
  18307. }
  18308. if(strcmp(key, "SecurityProfile") == 0)
  18309. {
  18310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18311. {
  18312. check_ascii = value[0];
  18313. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18314. {
  18315. isSuccess = ConfigurationStatus_Rejected;
  18316. }
  18317. else if(check_ascii == 0x33)
  18318. {
  18319. isSuccess = NotSupported;
  18320. }
  18321. else
  18322. {
  18323. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18324. {
  18325. if(((check_ascii - 0x30) == 1) ||
  18326. (((check_ascii - 0x30) == 2) && (access("/Storage/OCPP/CentralSystemRootCertificate.pem",F_OK) != -1)) ||
  18327. (((check_ascii - 0x30) == 3) && (access("/Storage/OCPP/CentralSystemRootCertificate.pem",F_OK) != -1) && (access("/Storage/OCPP/certCP.pem",F_OK) != -1)))
  18328. {
  18329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18330. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18331. isSuccess = ConfigurationStatus_Accepted;
  18332. }
  18333. else
  18334. isSuccess = ConfigurationStatus_Rejected;
  18335. }
  18336. else
  18337. isSuccess = ConfigurationStatus_Rejected;
  18338. }
  18339. }
  18340. else
  18341. {
  18342. isSuccess = ConfigurationStatus_Rejected;
  18343. }
  18344. }
  18345. if(strcmp(key, "DefaultPrice") == 0)
  18346. {
  18347. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18348. {
  18349. strcpy(str, (const char*)value);
  18350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18351. isSuccess = ConfigurationStatus_Accepted;
  18352. }
  18353. else
  18354. {
  18355. isSuccess = ConfigurationStatus_Rejected;
  18356. }
  18357. }
  18358. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18359. {
  18360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18361. {
  18362. strcpy(str, (const char*)value);
  18363. for(int i = 0; str[i]; i++)
  18364. {
  18365. str[i] = tolower(str[i]);
  18366. }
  18367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18368. isSuccess = ConfigurationStatus_Accepted;
  18369. }
  18370. else
  18371. {
  18372. isSuccess = ConfigurationStatus_Rejected;
  18373. }
  18374. }
  18375. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18376. {
  18377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18378. {
  18379. strcpy(str, (const char*)value);
  18380. for(int i = 0; str[i]; i++)
  18381. {
  18382. str[i] = tolower(str[i]);
  18383. }
  18384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18385. isSuccess = ConfigurationStatus_Accepted;
  18386. }
  18387. else
  18388. {
  18389. isSuccess = ConfigurationStatus_Rejected;
  18390. }
  18391. }
  18392. if(strcmp(key, "TimeOffset") == 0)
  18393. {
  18394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18395. {
  18396. strcpy(str, (const char*)value);
  18397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18398. isSuccess = ConfigurationStatus_Accepted;
  18399. }
  18400. else
  18401. {
  18402. isSuccess = ConfigurationStatus_Rejected;
  18403. }
  18404. }
  18405. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18406. {
  18407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18408. {
  18409. strcpy(str, (const char*)value);
  18410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18411. isSuccess = ConfigurationStatus_Accepted;
  18412. }
  18413. else
  18414. {
  18415. isSuccess = ConfigurationStatus_Rejected;
  18416. }
  18417. }
  18418. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18419. {
  18420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18421. {
  18422. strcpy(str, (const char*)value);
  18423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18424. isSuccess = ConfigurationStatus_Accepted;
  18425. }
  18426. else
  18427. {
  18428. isSuccess = ConfigurationStatus_Rejected;
  18429. }
  18430. }
  18431. if(strcmp(key, "SystemUptimeSec") == 0)
  18432. {
  18433. isSuccess = NotSupported;
  18434. }
  18435. if(strcmp(key, "FreeVend") == 0)
  18436. {
  18437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18438. {
  18439. strcpy(str, (const char*)value);
  18440. for(int i = 0; str[i]; i++)
  18441. {
  18442. str[i] = tolower(str[i]);
  18443. }
  18444. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18446. isSuccess = ConfigurationStatus_Accepted;
  18447. }
  18448. else
  18449. {
  18450. isSuccess = ConfigurationStatus_Rejected;
  18451. }
  18452. }
  18453. if(strcmp(key, "FreeVendIdtag") == 0)
  18454. {
  18455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18456. {
  18457. strcpy(str, (const char*)value);
  18458. if(strlen(str) <= 20)
  18459. {
  18460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18461. isSuccess = ConfigurationStatus_Accepted;
  18462. }
  18463. else
  18464. {
  18465. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18466. isSuccess = ConfigurationStatus_Rejected;
  18467. }
  18468. }
  18469. else
  18470. {
  18471. isSuccess = ConfigurationStatus_Rejected;
  18472. }
  18473. }
  18474. if(strcmp(key, "OcppServer") == 0)
  18475. {
  18476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18477. {
  18478. strcpy(str, (const char*)value);
  18479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18480. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18481. isSuccess = ConfigurationStatus_Accepted;
  18482. }
  18483. else
  18484. {
  18485. isSuccess = ConfigurationStatus_Rejected;
  18486. }
  18487. }
  18488. if(strcmp(key, "MaintainServer") == 0)
  18489. {
  18490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18491. {
  18492. strcpy(str, (const char*)value);
  18493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18494. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18495. isSuccess = ConfigurationStatus_Accepted;
  18496. }
  18497. else
  18498. {
  18499. isSuccess = ConfigurationStatus_Rejected;
  18500. }
  18501. }
  18502. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18503. {
  18504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18505. {
  18506. strcpy(str, (const char*)value);
  18507. for(int i = 0; str[i]; i++)
  18508. {
  18509. str[i] = tolower(str[i]);
  18510. }
  18511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18512. isSuccess = ConfigurationStatus_Accepted;
  18513. }
  18514. else
  18515. {
  18516. isSuccess = ConfigurationStatus_Rejected;
  18517. }
  18518. }
  18519. if(strcmp(key, "StatusNotificationInterval") == 0)
  18520. {
  18521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18522. {
  18523. check_ascii = value[0];
  18524. if( (check_ascii < 48) || (check_ascii > 57) )
  18525. {
  18526. isSuccess = ConfigurationStatus_Rejected;
  18527. }
  18528. else
  18529. {
  18530. if((atoi(value) == 0) || (atoi(value) >= 10))
  18531. {
  18532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18533. isSuccess = ConfigurationStatus_Accepted;
  18534. }
  18535. else
  18536. isSuccess = ConfigurationStatus_Rejected;
  18537. }
  18538. }
  18539. else
  18540. {
  18541. isSuccess = ConfigurationStatus_Rejected;
  18542. }
  18543. }
  18544. if(strcmp(key, "PreAuthAmount") == 0)
  18545. {
  18546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18547. {
  18548. check_ascii = value[0];
  18549. if( (check_ascii < 48) || (check_ascii > 57) )
  18550. {
  18551. isSuccess = ConfigurationStatus_Rejected;
  18552. }
  18553. else
  18554. {
  18555. if(atof(value) >= 0)
  18556. {
  18557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18558. isSuccess = ConfigurationStatus_Accepted;
  18559. }
  18560. else
  18561. isSuccess = ConfigurationStatus_Rejected;
  18562. }
  18563. }
  18564. else
  18565. {
  18566. isSuccess = ConfigurationStatus_Rejected;
  18567. }
  18568. }
  18569. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18570. {
  18571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18572. {
  18573. check_ascii = value[0];
  18574. if( (check_ascii < 48) || (check_ascii > 57) )
  18575. {
  18576. isSuccess = ConfigurationStatus_Rejected;
  18577. }
  18578. else
  18579. {
  18580. if(atoi(value) >= 0)
  18581. {
  18582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18583. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18584. isSuccess = ConfigurationStatus_Accepted;
  18585. }
  18586. else
  18587. isSuccess = ConfigurationStatus_Rejected;
  18588. }
  18589. }
  18590. else
  18591. {
  18592. isSuccess = ConfigurationStatus_Rejected;
  18593. }
  18594. }
  18595. if(strcmp(key, "PowerSharingServerIP") == 0)
  18596. {
  18597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18598. {
  18599. strcpy(str, (const char*)value);
  18600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  18601. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  18602. isSuccess = ConfigurationStatus_Accepted;
  18603. }
  18604. else
  18605. {
  18606. isSuccess = ConfigurationStatus_Rejected;
  18607. }
  18608. }
  18609. if(strcmp(key, "EVCCID_PREFIX") == 0)
  18610. {
  18611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  18612. {
  18613. strcpy(str, (const char*)value);
  18614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  18615. isSuccess = ConfigurationStatus_Accepted;
  18616. }
  18617. else
  18618. {
  18619. isSuccess = ConfigurationStatus_Rejected;
  18620. }
  18621. }
  18622. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  18623. {
  18624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  18625. {
  18626. if(atoi(value) > modelnameInfo.ratedPower)
  18627. {
  18628. isSuccess = ConfigurationStatus_Rejected;
  18629. }
  18630. else{
  18631. strcpy(str, (const char*)value);
  18632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  18633. isSuccess = ConfigurationStatus_Accepted;
  18634. }
  18635. }
  18636. else
  18637. {
  18638. isSuccess = ConfigurationStatus_Rejected;
  18639. }
  18640. }
  18641. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  18642. {
  18643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  18644. {
  18645. if((atoi(value) != 0) && (atoi(value) < 5))
  18646. {
  18647. isSuccess = ConfigurationStatus_Rejected;
  18648. }
  18649. else{
  18650. strcpy(str, (const char*)value);
  18651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  18652. isSuccess = ConfigurationStatus_Accepted;
  18653. }
  18654. }
  18655. else
  18656. {
  18657. isSuccess = ConfigurationStatus_Rejected;
  18658. }
  18659. }
  18660. #if 0
  18661. //For OCPP Test Case
  18662. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  18663. {
  18664. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  18665. {
  18666. strcpy(str, (const char*)value);
  18667. for(int i = 0; str[i]; i++)
  18668. {
  18669. str[i] = tolower(str[i]);
  18670. }
  18671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18672. isSuccess = ConfigurationStatus_Accepted;
  18673. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  18674. }
  18675. else
  18676. {
  18677. isSuccess = ConfigurationStatus_Rejected;
  18678. }
  18679. }
  18680. #endif
  18681. #if 1
  18682. if(strcmp(key, "LocalAuthListEnabled") == 0)
  18683. {
  18684. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  18685. {
  18686. strcpy(str, (const char*)value);
  18687. for(int i = 0; str[i]; i++)
  18688. {
  18689. str[i] = tolower(str[i]);
  18690. }
  18691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18692. isSuccess = ConfigurationStatus_Accepted;
  18693. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  18694. }
  18695. else
  18696. {
  18697. isSuccess = ConfigurationStatus_Rejected;
  18698. }
  18699. }
  18700. #endif
  18701. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  18702. {
  18703. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  18704. {
  18705. check_ascii = value[0];
  18706. if( (check_ascii < 48) || (check_ascii > 57) )
  18707. {
  18708. isSuccess = ConfigurationStatus_Rejected;
  18709. }
  18710. else
  18711. {
  18712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  18713. isSuccess = ConfigurationStatus_Accepted;
  18714. }
  18715. }
  18716. else
  18717. {
  18718. isSuccess = ConfigurationStatus_Rejected;
  18719. }
  18720. }
  18721. if(strcmp(key, "SendLocalListMaxLength") == 0)
  18722. {
  18723. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  18724. {
  18725. check_ascii = value[0];
  18726. if( (check_ascii < 48) || (check_ascii > 57) )
  18727. {
  18728. isSuccess = ConfigurationStatus_Rejected;
  18729. }
  18730. else
  18731. {
  18732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  18733. isSuccess = ConfigurationStatus_Accepted;
  18734. }
  18735. }
  18736. else
  18737. {
  18738. isSuccess = ConfigurationStatus_Rejected;
  18739. }
  18740. }
  18741. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  18742. {
  18743. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  18744. {
  18745. strcpy(str, (const char*)value);
  18746. for(int i = 0; str[i]; i++)
  18747. {
  18748. str[i] = tolower(str[i]);
  18749. }
  18750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18751. isSuccess = ConfigurationStatus_Accepted;
  18752. }
  18753. else
  18754. {
  18755. isSuccess = ConfigurationStatus_Rejected;
  18756. }
  18757. }
  18758. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  18759. {
  18760. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  18761. {
  18762. check_ascii = value[0];
  18763. if( (check_ascii < 48) || (check_ascii > 57) )
  18764. {
  18765. isSuccess = ConfigurationStatus_Rejected;
  18766. }
  18767. else
  18768. {
  18769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  18770. isSuccess = ConfigurationStatus_Accepted;
  18771. }
  18772. }
  18773. else
  18774. {
  18775. isSuccess = ConfigurationStatus_Rejected;
  18776. }
  18777. }
  18778. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  18779. {
  18780. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  18781. {
  18782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  18783. isSuccess = ConfigurationStatus_Accepted;
  18784. }
  18785. else
  18786. {
  18787. isSuccess = ConfigurationStatus_Rejected;
  18788. }
  18789. }
  18790. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  18791. {
  18792. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  18793. {
  18794. check_ascii = value[0];
  18795. if( (check_ascii < 48) || (check_ascii > 57) )
  18796. {
  18797. isSuccess = ConfigurationStatus_Rejected;
  18798. }
  18799. else
  18800. {
  18801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  18802. isSuccess = ConfigurationStatus_Accepted;
  18803. }
  18804. }
  18805. else
  18806. {
  18807. isSuccess = ConfigurationStatus_Rejected;
  18808. }
  18809. }
  18810. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  18811. {
  18812. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  18813. {
  18814. strcpy(str, (const char*)value);
  18815. for(int i = 0; str[i]; i++)
  18816. {
  18817. str[i] = tolower(str[i]);
  18818. }
  18819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18820. isSuccess = ConfigurationStatus_Accepted;
  18821. }
  18822. else
  18823. {
  18824. isSuccess = ConfigurationStatus_Rejected;
  18825. }
  18826. }
  18827. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  18828. {
  18829. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18830. {
  18831. check_ascii = value[0];
  18832. if( (check_ascii < 48) || (check_ascii > 57) )
  18833. {
  18834. isSuccess = ConfigurationStatus_Rejected;
  18835. }
  18836. else
  18837. {
  18838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  18839. isSuccess = ConfigurationStatus_Accepted;
  18840. }
  18841. }
  18842. else
  18843. {
  18844. isSuccess = ConfigurationStatus_Rejected;
  18845. }
  18846. }
  18847. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18848. return isSuccess;
  18849. }
  18850. int TransactionMessageAttemptsGet(void)
  18851. {
  18852. return TransactionMessageAttemptsValue;
  18853. }
  18854. int FirstHeartBeatResponse(void)
  18855. {
  18856. return FirstHeartBeat;
  18857. }
  18858. int TransactionMessageRetryIntervalGet(void)
  18859. {
  18860. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18861. }
  18862. int ReadHttpStatus(int sock)
  18863. {
  18864. //char c;
  18865. char buff[1024]="",*ptr=buff+1;
  18866. int bytes_received, status;
  18867. DEBUG_INFO("Begin Response ..\n");
  18868. while((bytes_received = recv(sock, ptr, 1, 0))){
  18869. if(bytes_received==-1){
  18870. perror("ReadHttpStatus");
  18871. exit(1);
  18872. }
  18873. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  18874. ptr++;
  18875. }
  18876. *ptr=0;
  18877. ptr=buff+1;
  18878. sscanf(ptr,"%*s %d ", &status);
  18879. DEBUG_INFO("%s\n",ptr);
  18880. DEBUG_INFO("status=%d\n",status);
  18881. DEBUG_INFO("End Response ..\n");
  18882. return (bytes_received>0)?status:0;
  18883. }
  18884. //the only filed that it parsed is 'Content-Length'
  18885. int ParseHeader(int sock)
  18886. {
  18887. //char c;
  18888. char buff[1024]="",*ptr=buff+4;
  18889. int bytes_received;
  18890. DEBUG_INFO("Begin HEADER ..\n");
  18891. while((bytes_received = recv(sock, ptr, 1, 0))){
  18892. if(bytes_received==-1){
  18893. perror("Parse Header");
  18894. exit(1);
  18895. }
  18896. if(
  18897. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  18898. (ptr[-1]=='\r') && (*ptr=='\n' )
  18899. ) break;
  18900. ptr++;
  18901. }
  18902. *ptr=0;
  18903. ptr=buff+4;
  18904. //printf("%s",ptr);
  18905. if(bytes_received){
  18906. ptr=strstr(ptr,"Content-Length:");
  18907. if(ptr){
  18908. sscanf(ptr,"%*s %d",&bytes_received);
  18909. }else
  18910. bytes_received=-1; //unknown size
  18911. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  18912. }
  18913. DEBUG_INFO("End HEADER ..\n");
  18914. return bytes_received ;
  18915. }
  18916. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18917. {
  18918. int result = TRUE;
  18919. char rmFileCmd[100]={0};
  18920. char FilePath[100]={0};
  18921. char ftpbuf[200];
  18922. int systemresult;
  18923. sprintf(FilePath,"/mnt/%s",filename);
  18924. system("ping 8.8.8.8 &");
  18925. if((access(FilePath,F_OK))!=-1)
  18926. {
  18927. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18928. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18929. system(rmFileCmd);
  18930. }
  18931. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18932. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18933. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18934. systemresult = system(ftpbuf);
  18935. if(systemresult != 0)
  18936. {
  18937. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  18938. result = FALSE;
  18939. }
  18940. system("pkill ping");
  18941. return result;
  18942. }
  18943. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  18944. {
  18945. int result = TRUE;
  18946. char rmFileCmd[100]={0};
  18947. char FilePath[100]={0};
  18948. char ftpbuf[200];
  18949. int systemresult;
  18950. sprintf(FilePath,"/mnt/%s",filename);
  18951. system("ping 8.8.8.8 &");
  18952. if((access(FilePath,F_OK))!=-1)
  18953. {
  18954. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18955. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18956. system(rmFileCmd);
  18957. }
  18958. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18959. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  18960. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18961. systemresult = system(ftpbuf);
  18962. if(systemresult != 0)
  18963. {
  18964. DEBUG_WARN("scp error!\n");
  18965. result = FALSE;
  18966. }
  18967. system("pkill ping");
  18968. return result;
  18969. }
  18970. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18971. {
  18972. int result = TRUE;
  18973. char rmFileCmd[100]={0};
  18974. char FilePath[100]={0};
  18975. char ftpbuf[200];
  18976. int systemresult;
  18977. sprintf(FilePath,"/mnt/%s",filename);
  18978. system("ping 8.8.8.8 &");
  18979. if((access(FilePath,F_OK))!=-1)
  18980. {
  18981. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18982. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18983. system(rmFileCmd);
  18984. }
  18985. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18986. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18987. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18988. systemresult = system(ftpbuf);
  18989. if(systemresult != 0)
  18990. {
  18991. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18992. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18993. systemresult = system(ftpbuf);
  18994. if(systemresult != 0)
  18995. {
  18996. DEBUG_WARN("FTP download fail!\n");
  18997. result = FALSE;
  18998. }
  18999. }
  19000. system("pkill ping");
  19001. return result;
  19002. }
  19003. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19004. {
  19005. char rmFileCmd[100]={0};
  19006. char FilePath[100]={0};
  19007. char buf[512];
  19008. int systemresult = 0;
  19009. //DEBUG_INFO("filename=%s\n",filename);
  19010. //DEBUG_INFO("url=%s\n",url);
  19011. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19012. if((access(FilePath,F_OK))!=-1)
  19013. {
  19014. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19015. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19016. system(rmFileCmd);
  19017. }
  19018. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19019. if(fp == NULL)
  19020. {
  19021. DEBUG_INFO("log is NULL\n");
  19022. return FALSE;
  19023. }
  19024. else
  19025. {
  19026. fprintf(fp, "%s\n", url);
  19027. fprintf(fp, "%s\n", filename);
  19028. fclose(fp);
  19029. }
  19030. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19031. if(phpFP == NULL)
  19032. {
  19033. DEBUG_INFO("PHP upload fail.\n");
  19034. return FALSE;
  19035. }
  19036. else
  19037. {
  19038. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19039. {
  19040. if(strstr(buf, "result") != NULL)
  19041. {
  19042. sscanf(buf, "result: %d", &systemresult);
  19043. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19044. }
  19045. }
  19046. pclose(phpFP);
  19047. }
  19048. if(systemresult != 1)
  19049. {
  19050. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19051. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19052. if(phpFP == NULL)
  19053. {
  19054. DEBUG_WARN("PHP PUT upload fail.\n");
  19055. return FALSE;
  19056. }
  19057. else
  19058. {
  19059. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19060. {
  19061. if(strstr(buf, "result") != NULL)
  19062. {
  19063. sscanf(buf, "result: %d", &systemresult);
  19064. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19065. }
  19066. }
  19067. pclose(phpFP);
  19068. }
  19069. }
  19070. if(systemresult != 1)
  19071. {
  19072. DEBUG_WARN("PHP PUT upload fail.\n");
  19073. return FALSE;
  19074. }
  19075. return TRUE;
  19076. }
  19077. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19078. {
  19079. int result = FALSE;
  19080. char ftpbuf[200];
  19081. int systemresult;
  19082. /*
  19083. // Domaind name transfer to IP address
  19084. struct hostent* server;
  19085. char *IPbuffer;
  19086. server = gethostbyname(location);
  19087. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19088. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19089. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19090. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19091. systemresult = system(ftpbuf);
  19092. if(systemresult != 0)
  19093. {
  19094. DEBUG_INFO("ftpput error!\n");
  19095. }
  19096. else
  19097. {
  19098. result = TRUE;
  19099. DEBUG_INFO("ftpput OK!\n");
  19100. }
  19101. return result;
  19102. }
  19103. int GetOcppServerURL()
  19104. {
  19105. int result = FALSE;
  19106. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19107. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19108. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19109. struct yuarel url;
  19110. char urlStr[512];
  19111. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19112. {
  19113. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19114. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19115. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19116. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19117. if(yuarel_parse(&url, urlStr) != -1)
  19118. {
  19119. sprintf(OcppProtocol, "%s", url.scheme);
  19120. sprintf(OcppHost, "%s", url.host);
  19121. if(url.path == NULL)
  19122. OcppTempPath[0] = '\0';
  19123. else
  19124. {
  19125. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19126. {
  19127. sprintf(OcppTempPath, "%s/", url.path);
  19128. }
  19129. else
  19130. {
  19131. sprintf(OcppTempPath, "%s", url.path);
  19132. }
  19133. }
  19134. if(url.port == 0)
  19135. {
  19136. if(strcmp(OcppProtocol, "wss") == 0)
  19137. OcppPort = 443;
  19138. else
  19139. OcppPort = 80;
  19140. }
  19141. else
  19142. OcppPort = url.port;
  19143. result = TRUE;
  19144. }
  19145. }
  19146. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19147. {
  19148. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19149. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19150. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19151. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19152. if(yuarel_parse(&url, urlStr) != -1)
  19153. {
  19154. sprintf(OcppProtocol, "%s", url.scheme);
  19155. sprintf(OcppHost, "%s", url.host);
  19156. if(url.path == NULL)
  19157. OcppTempPath[0] = '\0';
  19158. else
  19159. sprintf(OcppTempPath, "%s", url.path);
  19160. if(url.port == 0)
  19161. {
  19162. if(strcmp(OcppProtocol, "wss") == 0)
  19163. OcppPort = 443;
  19164. else
  19165. OcppPort = 80;
  19166. }
  19167. else
  19168. OcppPort = url.port;
  19169. result = TRUE;
  19170. }
  19171. }
  19172. else
  19173. {
  19174. strcpy(OcppHost,"");
  19175. }
  19176. return result;
  19177. }
  19178. int GetOcppPath()
  19179. {
  19180. int result = FALSE;
  19181. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19182. {
  19183. if(OcppTempPath == NULL)
  19184. {
  19185. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19186. }
  19187. else
  19188. {
  19189. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19190. }
  19191. result = TRUE;
  19192. goto End;
  19193. }
  19194. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19195. {
  19196. if(OcppTempPath == NULL)
  19197. {
  19198. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19199. }
  19200. else
  19201. {
  19202. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19203. }
  19204. result = TRUE;
  19205. goto End;
  19206. }
  19207. else
  19208. {
  19209. strcpy(OcppPath,"");
  19210. }
  19211. End:
  19212. return result;
  19213. }
  19214. int GetOcppPort()
  19215. {
  19216. return OcppPort;
  19217. }
  19218. int GetOcppConnStatus(void)
  19219. {
  19220. return ShmOCPP16Data->OcppConnStatus;
  19221. }
  19222. void SetOcppConnStatus(uint8_t status)
  19223. {
  19224. ShmOCPP16Data->OcppConnStatus = status;
  19225. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19226. }
  19227. int GetHeartBeatWithNOResponse(void)
  19228. {
  19229. return HeartBeatWithNOResponse;
  19230. }
  19231. void SetHeartBeatWithNOResponse(void)
  19232. {
  19233. HeartBeatWithNOResponse = 0;
  19234. }
  19235. void GetStartTransactionIdTag(int gun_index)
  19236. {
  19237. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19238. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19239. }
  19240. int GetStartTransactionId(int gun_index)
  19241. {
  19242. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19243. }
  19244. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19245. {
  19246. char ch;
  19247. FILE *fptr1;
  19248. int temptransactionId;
  19249. char str[100]={0};
  19250. temptransactionId = 0;
  19251. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19252. {
  19253. DEBUG_INFO("IdTag is empty.\n");
  19254. return temptransactionId;
  19255. }
  19256. /*------ Read the file ----------------*/
  19257. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19258. if (!fptr1)
  19259. {
  19260. DEBUG_INFO("QueueTransactionId file open error.\n");
  19261. //printf(" File not found or unable to open the input file!!\n");
  19262. return temptransactionId;
  19263. }
  19264. ch=fgetc(fptr1);
  19265. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19266. rewind(fptr1);
  19267. if(ch!=EOF)
  19268. {
  19269. // printf("%c",ch);
  19270. while (fgets(str, 100, fptr1) != NULL)
  19271. {
  19272. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19273. if(str[0]=='\0')
  19274. {
  19275. break;
  19276. }
  19277. char *revbuf[8] = {0}; // Variable store string split
  19278. int num = 0;// Quantity after string split
  19279. DEBUG_INFO("Transaction queue data= %s\n", str);
  19280. splitstring(str,",",revbuf,&num); // String split
  19281. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19282. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19283. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19284. DEBUG_INFO("------------------------------\n");
  19285. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19286. {
  19287. if(isStopTransaction)
  19288. {
  19289. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19290. {
  19291. temptransactionId = atoi(revbuf[2]);
  19292. //break;
  19293. }
  19294. }
  19295. else
  19296. {
  19297. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19298. {
  19299. temptransactionId = atoi(revbuf[2]);
  19300. //break;
  19301. }
  19302. }
  19303. }
  19304. }
  19305. }
  19306. else
  19307. DEBUG_INFO("EOF\n");
  19308. fclose(fptr1);
  19309. /*------- End of reading ---------------*/
  19310. return temptransactionId;
  19311. }
  19312. void SetTransactionIdZero(int transactionId)
  19313. {
  19314. char ch;
  19315. FILE *fptr1, *fptr2;
  19316. int temptransactionId = 0;
  19317. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19318. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19319. if (!fptr1)
  19320. {
  19321. //printf(" File not found or unable to open the input file!!\n");
  19322. return ;
  19323. }
  19324. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19325. if (!fptr2)
  19326. {
  19327. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19328. fclose(fptr1);
  19329. return ;
  19330. }
  19331. ch=fgetc(fptr1);
  19332. rewind(fptr1);
  19333. if(ch!=EOF)
  19334. {
  19335. // copy all contents to the temporary file except the specific line
  19336. while (fgets(str, 100, fptr1) != NULL)
  19337. {
  19338. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19339. if(str[0]=='\0')
  19340. {
  19341. break;
  19342. }
  19343. char *revbuf[8] = {0};
  19344. int num = 0;
  19345. strcpy(strtemp, str);
  19346. splitstring(str,",",revbuf,&num);
  19347. if(revbuf[2][0] != '\0')
  19348. {
  19349. temptransactionId = atoi(revbuf[2]);
  19350. if(transactionId != temptransactionId)
  19351. {
  19352. fprintf(fptr2, "%s\n", strtemp);
  19353. }
  19354. }
  19355. }
  19356. }
  19357. fclose(fptr1);
  19358. fclose(fptr2);
  19359. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19360. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19361. /*------ Read the file ----------------*/
  19362. }
  19363. int InternetDisconnect(void)
  19364. {
  19365. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19366. }
  19367. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19368. void storeTempStopTransaction(int gun_index)
  19369. {
  19370. char guid[37]={0};
  19371. int tempIndex = 0;
  19372. char TempStopTransaction[256];
  19373. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19374. DEBUG_INFO("storeTempStopTransaction...\n");
  19375. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19376. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19377. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  19378. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19379. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19380. {
  19381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19382. {
  19383. tempIndex = ((gun_index==2) ? 1: 0);
  19384. }
  19385. else
  19386. {
  19387. tempIndex = gun_index;
  19388. }
  19389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19390. {
  19391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19392. {
  19393. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19394. }
  19395. }// END OF CHAdeMO_QUANTITY
  19396. }
  19397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19398. {
  19399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19400. {
  19401. tempIndex = ((gun_index==2) ? 1: 0);
  19402. }
  19403. else
  19404. {
  19405. tempIndex = gun_index;
  19406. }
  19407. for (int index = 0; index < CCS_QUANTITY; index++)
  19408. {
  19409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19410. {
  19411. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19412. }
  19413. }// END OF CCS_QUANTITY
  19414. }
  19415. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19416. {
  19417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19418. {
  19419. tempIndex = ((gun_index==2) ? 1: 0);
  19420. }
  19421. else
  19422. {
  19423. tempIndex = gun_index;
  19424. }
  19425. for (int index = 0; index < GB_QUANTITY; index++)
  19426. {
  19427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19428. {
  19429. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19430. }
  19431. }// END OF GB_QUANTITY
  19432. }
  19433. else if(gunType[gun_index] == GUN_TYPE_DO)
  19434. {
  19435. tempIndex = gun_index;
  19436. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19437. {
  19438. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19439. {
  19440. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19441. }
  19442. }
  19443. }
  19444. else
  19445. {
  19446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19447. {
  19448. tempIndex = 2;
  19449. }
  19450. else
  19451. {
  19452. tempIndex = gun_index;
  19453. }
  19454. for (int index = 0; index < AC_QUANTITY; index++)
  19455. {
  19456. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19457. {
  19458. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19459. }
  19460. }// END OF AC_QUANTITY
  19461. }
  19462. //Stop Transaction Time
  19463. struct timeval tmnow;
  19464. struct tm *tm;
  19465. char buf[28];//, usec_buf[6];
  19466. gettimeofday(&tmnow, NULL);
  19467. time_t t;
  19468. t = time(NULL);
  19469. /*UTC time and date*/
  19470. tm = gmtime(&t);
  19471. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  19472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  19473. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19475. random_uuid(guid);
  19476. /***********************************transactionData******************************************************/
  19477. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  19478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  19479. //=================================
  19480. //1. Transaction_Begin
  19481. //=================================
  19482. //============================== Energy.Active.Import.Interval ===========================================
  19483. //=================================
  19484. //2. Transaction_End
  19485. //=================================
  19486. //2.1====================================== Current.Import L1 ==============================================
  19487. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19488. {
  19489. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  19490. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19491. {
  19492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19493. {
  19494. tempIndex = ((gun_index==2) ? 1: 0);
  19495. }
  19496. else
  19497. {
  19498. tempIndex = gun_index;
  19499. }
  19500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19501. {
  19502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19503. {
  19504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19505. }
  19506. }// End of for CHAdeMO_QUANTITY
  19507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19508. }
  19509. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19510. {
  19511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19512. {
  19513. tempIndex = ((gun_index==2) ? 1: 0);
  19514. }
  19515. else
  19516. {
  19517. tempIndex = gun_index;
  19518. }
  19519. for (int index = 0; index < CCS_QUANTITY; index++)
  19520. {
  19521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19522. {
  19523. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19524. }
  19525. }// End of for CCS_QUANTITY
  19526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19527. }
  19528. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19529. {
  19530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19531. {
  19532. tempIndex = ((gun_index==2) ? 1: 0);
  19533. }
  19534. else
  19535. {
  19536. tempIndex = gun_index;
  19537. }
  19538. for (int index = 0; index < GB_QUANTITY; index++)
  19539. {
  19540. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19541. {
  19542. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19543. }
  19544. }// End of for GB_QUANTITY
  19545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19546. }
  19547. else if(gunType[gun_index] == GUN_TYPE_DO)
  19548. {
  19549. tempIndex = gun_index;
  19550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19551. {
  19552. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19553. {
  19554. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19555. }
  19556. }
  19557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19558. }
  19559. else
  19560. {
  19561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19562. {
  19563. tempIndex = 2;
  19564. }
  19565. else
  19566. {
  19567. tempIndex = gun_index;
  19568. }
  19569. for (int index = 0; index < AC_QUANTITY; index++)
  19570. {
  19571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19572. {
  19573. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  19574. }
  19575. }// End of for AC_QUANTITY
  19576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  19577. }
  19578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  19580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  19581. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  19582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  19583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19584. }
  19585. //2.2===================================== Energy.Active.Import.Interval ==========================================
  19586. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  19587. {
  19588. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19589. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19590. {
  19591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19592. {
  19593. tempIndex = ((gun_index==2) ? 1: 0);
  19594. }
  19595. else
  19596. {
  19597. tempIndex = gun_index;
  19598. }
  19599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19600. {
  19601. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19602. {
  19603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  19604. }
  19605. }// END OF CHAdeMO_QUANTITY
  19606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  19607. }
  19608. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19609. {
  19610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19611. {
  19612. tempIndex = ((gun_index==2) ? 1: 0);
  19613. }
  19614. else
  19615. {
  19616. tempIndex = gun_index;
  19617. }
  19618. for (int index = 0; index < CCS_QUANTITY; index++)
  19619. {
  19620. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19621. {
  19622. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  19623. }
  19624. }// END OF CCS_QUANTITY
  19625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  19626. }
  19627. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19628. {
  19629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19630. {
  19631. tempIndex = ((gun_index==2) ? 1: 0);
  19632. }
  19633. else
  19634. {
  19635. tempIndex = gun_index;
  19636. }
  19637. for (int index = 0; index < GB_QUANTITY; index++)
  19638. {
  19639. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19640. {
  19641. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  19642. }
  19643. }// END OF GB_QUANTITY
  19644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  19645. }
  19646. else if(gunType[gun_index] == GUN_TYPE_DO)
  19647. {
  19648. tempIndex = gun_index;
  19649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19650. {
  19651. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19652. {
  19653. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  19654. }
  19655. }
  19656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  19657. }
  19658. else
  19659. {
  19660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19661. {
  19662. tempIndex = 2;
  19663. }
  19664. else
  19665. {
  19666. tempIndex = gun_index;
  19667. }
  19668. for (int index = 0; index < AC_QUANTITY; index++)
  19669. {
  19670. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19671. {
  19672. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  19673. }
  19674. }// END OF AC_QUANTITY
  19675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  19676. }
  19677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  19679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  19680. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  19681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  19682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  19683. }
  19684. //2.3====================================== Power.Active.Import =========================================
  19685. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  19686. {
  19687. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19688. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19689. {
  19690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19691. {
  19692. tempIndex = ((gun_index==2) ? 1: 0);
  19693. }
  19694. else
  19695. {
  19696. tempIndex = gun_index;
  19697. }
  19698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19699. {
  19700. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19701. {
  19702. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19703. }
  19704. } // End for CHAdeMO_QUANTITY
  19705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19706. }
  19707. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19708. {
  19709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19710. {
  19711. tempIndex = ((gun_index==2) ? 1: 0);
  19712. }
  19713. else
  19714. {
  19715. tempIndex = gun_index;
  19716. }
  19717. for (int index = 0; index < CCS_QUANTITY; index++)
  19718. {
  19719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19720. {
  19721. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19722. }
  19723. } // END for CCS_QUANTITY
  19724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19725. }
  19726. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19727. {
  19728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19729. {
  19730. tempIndex = ((gun_index==2) ? 1: 0);
  19731. }
  19732. else
  19733. {
  19734. tempIndex = gun_index;
  19735. }
  19736. for (int index = 0; index < GB_QUANTITY; index++)
  19737. {
  19738. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19739. {
  19740. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19741. }
  19742. }// END for GB_QUANTITY
  19743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19744. }
  19745. else if(gunType[gun_index] == GUN_TYPE_DO)
  19746. {
  19747. tempIndex = gun_index;
  19748. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19749. {
  19750. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19751. {
  19752. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19753. }
  19754. }
  19755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  19756. }
  19757. else
  19758. {
  19759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19760. {
  19761. tempIndex = 2;
  19762. }
  19763. else
  19764. {
  19765. tempIndex = gun_index;
  19766. }
  19767. for (int index = 0; index < AC_QUANTITY; index++)
  19768. {
  19769. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19770. {
  19771. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  19772. }
  19773. } // END for AC_QUANTITY
  19774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  19775. }
  19776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  19778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  19779. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  19780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  19781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  19782. }
  19783. //2.4====================================== Voltage L1 ====================================================
  19784. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  19785. {
  19786. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19787. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19788. {
  19789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19790. {
  19791. tempIndex = ((gun_index==2) ? 1: 0);
  19792. }
  19793. else
  19794. {
  19795. tempIndex = gun_index;
  19796. }
  19797. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19798. {
  19799. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19800. {
  19801. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19802. }
  19803. } // END OF FOR CHAdeMO_QUANTITY
  19804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19805. }
  19806. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19807. {
  19808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19809. {
  19810. tempIndex = ((gun_index==2) ? 1: 0);
  19811. }
  19812. else
  19813. {
  19814. tempIndex = gun_index;
  19815. }
  19816. for (int index = 0; index < CCS_QUANTITY; index++)
  19817. {
  19818. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19819. {
  19820. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19821. }
  19822. } // END OF FOR CCS_QUANTITY
  19823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19824. }
  19825. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19826. {
  19827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19828. {
  19829. tempIndex = ((gun_index==2) ? 1: 0);
  19830. }
  19831. else
  19832. {
  19833. tempIndex = gun_index;
  19834. }
  19835. for (int index = 0; index < GB_QUANTITY; index++)
  19836. {
  19837. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19838. {
  19839. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19840. }
  19841. } // END OF FOR GB_QUANTITY
  19842. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19843. }
  19844. else if(gunType[gun_index] == GUN_TYPE_DO)
  19845. {
  19846. tempIndex = gun_index;
  19847. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19848. {
  19849. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19850. {
  19851. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  19852. }
  19853. }
  19854. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  19855. }
  19856. else
  19857. {
  19858. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19859. {
  19860. tempIndex = 2;
  19861. }
  19862. else
  19863. {
  19864. tempIndex = gun_index;
  19865. }
  19866. for (int index = 0; index < AC_QUANTITY; index++)
  19867. {
  19868. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19869. {
  19870. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  19871. }
  19872. } // END OF FOR AC_QUANTITY
  19873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19874. }
  19875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  19877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  19878. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  19879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  19880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  19881. }
  19882. //2.5============================================== End SoC =========================================================
  19883. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  19884. {
  19885. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19886. 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))
  19887. {
  19888. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  19889. {
  19890. tempIndex = ((gun_index==2) ? 1: 0);
  19891. }
  19892. else
  19893. {
  19894. tempIndex = gun_index;
  19895. }
  19896. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19897. {
  19898. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19899. {
  19900. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19901. {
  19902. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  19903. }
  19904. }
  19905. }
  19906. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19907. {
  19908. for (int index = 0; index < CCS_QUANTITY; index++)
  19909. {
  19910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19911. {
  19912. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  19913. }
  19914. }
  19915. }
  19916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19917. {
  19918. for (int index = 0; index < GB_QUANTITY; index++)
  19919. {
  19920. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19921. {
  19922. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  19923. }
  19924. }
  19925. }
  19926. else if(gunType[gun_index] == GUN_TYPE_DO)
  19927. {
  19928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19929. {
  19930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19931. {
  19932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  19933. }
  19934. }
  19935. }
  19936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  19938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  19940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  19941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19942. } // END FOR DC CASE
  19943. }
  19944. //2.6====================================== Current.Import L2 ==============================================
  19945. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19946. {
  19947. // AC 3 phase L2 current
  19948. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19949. {
  19950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19951. {
  19952. tempIndex = 2;
  19953. }
  19954. else
  19955. {
  19956. tempIndex = gun_index;
  19957. }
  19958. for (int index = 0; index < AC_QUANTITY; index++)
  19959. {
  19960. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19961. {
  19962. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  19963. }
  19964. }// End of for AC_QUANTITY
  19965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  19966. }
  19967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  19969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  19970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  19971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19972. }
  19973. //2.7====================================== Current.Import L3 ==============================================
  19974. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19975. {
  19976. // AC 3 phase L3 current
  19977. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  19978. {
  19979. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19980. {
  19981. tempIndex = 2;
  19982. }
  19983. else
  19984. {
  19985. tempIndex = gun_index;
  19986. }
  19987. for (int index = 0; index < AC_QUANTITY; index++)
  19988. {
  19989. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19990. {
  19991. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  19992. }
  19993. }// End of for AC_QUANTITY
  19994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  19995. }
  19996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  19998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  19999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  20000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20001. }
  20002. //2.9====================================== Voltage L2 ====================================================
  20003. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20004. {
  20005. // AC 3 phase L2 volatge
  20006. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20007. {
  20008. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20009. {
  20010. tempIndex = 2;
  20011. }
  20012. else
  20013. {
  20014. tempIndex = gun_index;
  20015. }
  20016. for (int index = 0; index < AC_QUANTITY; index++)
  20017. {
  20018. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20019. {
  20020. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  20021. }
  20022. } // END OF FOR AC_QUANTITY
  20023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  20024. }
  20025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  20027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  20028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  20029. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20030. }
  20031. //2.10====================================== Voltage L3 ====================================================
  20032. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20033. {
  20034. // AC 3 phase L3 volatge
  20035. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20036. {
  20037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20038. {
  20039. tempIndex = 2;
  20040. }
  20041. else
  20042. {
  20043. tempIndex = gun_index;
  20044. }
  20045. for (int index = 0; index < AC_QUANTITY; index++)
  20046. {
  20047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20048. {
  20049. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  20050. }
  20051. } // END OF FOR AC_QUANTITY
  20052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  20053. }
  20054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  20056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  20057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  20058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20059. }
  20060. //====================== Start SoC ================================
  20061. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20062. {
  20063. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20064. 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))
  20065. {
  20066. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20067. {
  20068. tempIndex = ((gun_index==2) ? 1: 0);
  20069. }
  20070. else
  20071. {
  20072. tempIndex = gun_index;
  20073. }
  20074. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20075. {
  20076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20077. {
  20078. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20079. {
  20080. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  20081. }
  20082. }
  20083. }
  20084. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20085. {
  20086. for (int index = 0; index < CCS_QUANTITY; index++)
  20087. {
  20088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20089. {
  20090. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  20091. }
  20092. }
  20093. }
  20094. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20095. {
  20096. for (int index = 0; index < GB_QUANTITY; index++)
  20097. {
  20098. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20099. {
  20100. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  20101. }
  20102. }
  20103. }
  20104. else if(gunType[gun_index] == GUN_TYPE_DO)
  20105. {
  20106. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20107. {
  20108. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20109. {
  20110. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  20111. }
  20112. }
  20113. }
  20114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  20115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  20116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  20118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  20119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20120. } // END FOR DC CASE
  20121. }
  20122. //======================================== Message create ==============================================
  20123. json_object *StopTransaction = json_object_new_object();
  20124. json_object *transactionDatas = json_object_new_array();
  20125. json_object *sampledValues = json_object_new_array();
  20126. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20127. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20128. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20129. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20130. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20131. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20132. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  20133. {
  20134. json_object *transactionData = json_object_new_object();
  20135. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  20136. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  20137. {
  20138. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  20139. {
  20140. json_object *sampledValue = json_object_new_object();
  20141. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  20142. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  20143. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  20144. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  20145. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  20146. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  20147. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  20148. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  20149. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  20150. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  20151. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  20152. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  20153. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  20154. json_object_array_add(sampledValues, sampledValue);
  20155. }
  20156. }
  20157. json_object_object_add(transactionData, "sampledValue", sampledValues);
  20158. json_object_array_add(transactionDatas, transactionData);
  20159. }
  20160. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20161. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20162. ,MESSAGE_TYPE_CALL
  20163. ,guid
  20164. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20165. json_object_put(StopTransaction);
  20166. // Check File "TempStopTransaction" Exist
  20167. if((access(TempStopTransaction,F_OK))!=-1)
  20168. {
  20169. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20170. fclose(fopen(TempStopTransaction, "w"));
  20171. }
  20172. else
  20173. {
  20174. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20175. FILE *log = fopen(TempStopTransaction, "w+");
  20176. if(log == NULL)
  20177. {
  20178. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20179. return ;
  20180. }
  20181. else
  20182. {
  20183. fclose(log);
  20184. }
  20185. }
  20186. //Add TempStopTransaction | Update TempStopTransaction
  20187. // open file for writing
  20188. FILE *outfile;
  20189. outfile = fopen (TempStopTransaction, "a");
  20190. //DEBUG_INFO("data = %s\n", queuedata);
  20191. fputs(queuedata, outfile);
  20192. fputs("\n", outfile);
  20193. fclose (outfile);
  20194. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20195. OCPP_updatePeriodEnergy(gun_index);
  20196. }
  20197. void checkTempStopTransaction(int gun_index)
  20198. {
  20199. FILE *fptr1;
  20200. char ch;
  20201. char str[QUEUE_MESSAGE_LENGTH]={0};
  20202. char guid[37]={0};
  20203. char tempdata[65]={0};
  20204. char connectorStr[2]={0};
  20205. char TempStopTransaction[256];
  20206. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20207. fptr1 = fopen(TempStopTransaction, "r");
  20208. //TempStopTransaction格式: 槍號,StopTransaction封包
  20209. if (!fptr1)
  20210. {
  20211. //printf(" File not found or unable to open the input file!!\n");
  20212. return ;
  20213. }
  20214. ch=fgetc(fptr1);
  20215. //printf(" Now the content of the file %s is : \n",fname);
  20216. rewind(fptr1);
  20217. if(ch!=EOF)
  20218. {
  20219. // copy all contents to the temporary file except the specific line
  20220. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  20221. {
  20222. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20223. if(str[0]=='\0')
  20224. {
  20225. break;
  20226. }
  20227. //TempStopTransaction格式: 槍號,StopTransaction封包
  20228. strncpy(connectorStr, str, 1);
  20229. if(atoi(connectorStr) != (gun_index+1))
  20230. {
  20231. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  20232. fclose(fptr1);
  20233. return ;
  20234. }
  20235. //random_uuid(guid);
  20236. strncpy(guid, str+6, 36); //copy guid
  20237. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  20238. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  20239. {
  20240. //DEBUG_INFO("StopTransaction mapitem pass\n");
  20241. }
  20242. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  20243. OCPP_insert_transaction_msg(NO, str);
  20244. memset(str,0,ARRAY_SIZE(str));
  20245. }
  20246. }
  20247. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  20248. fclose(fptr1);
  20249. remove(TempStopTransaction); // remove the original file
  20250. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20251. }
  20252. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  20253. {
  20254. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20255. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  20256. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  20257. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  20258. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  20259. }
  20260. void FillTransactionId(int ConnectorId, int TransactionId)
  20261. {
  20262. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20263. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  20264. }
  20265. int GetWebSocketPingInterval(void)
  20266. {
  20267. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  20268. }
  20269. int GetServerSign(void)
  20270. {
  20271. return server_sign;
  20272. }
  20273. uint8_t GetOcppSecurityProfile()
  20274. {
  20275. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  20276. }
  20277. void MergeCertificates()
  20278. {
  20279. if((access("/Storage/OCPP/ManufacturerRootCertificate.pem",F_OK) != -1) && (access("/Storage/OCPP/CentralSystemRootCertificate.pem",F_OK) != -1))
  20280. {
  20281. system("cat /root/cacert.pem /Storage/OCPP/ManufacturerRootCertificate.pem /Storage/OCPP/CentralSystemRootCertificate.pem > /root/certCA.pem");
  20282. }
  20283. else if(access("/Storage/OCPP/CentralSystemRootCertificate.pem",F_OK) != -1)
  20284. {
  20285. system("cat /root/cacert.pem /Storage/OCPP/CentralSystemRootCertificate.pem > /root/certCA.pem");
  20286. }
  20287. else if(access("/Storage/OCPP/ManufacturerRootCertificate.pem",F_OK) != -1)
  20288. {
  20289. system("cat /root/cacert.pem /Storage/OCPP/ManufacturerRootCertificate.pem > /root/certCA.pem");
  20290. }
  20291. else
  20292. {
  20293. system("cat /root/cacert.pem > /root/certCA.pem");
  20294. }
  20295. }
  20296. void GetOcppChargerBoxId(uint8_t *data)
  20297. {
  20298. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20299. }
  20300. void GetOcppSecurityPassword(uint8_t *data)
  20301. {
  20302. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20303. }
  20304. void SetOcppVersion(uint8_t *version)
  20305. {
  20306. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20307. DEBUG_INFO("ocpp version: %s\n", version);
  20308. if(strstr((char*)version, "ocpp1.6") != NULL)
  20309. {
  20310. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20311. }
  20312. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20313. {
  20314. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20315. system("pkill OcppBackend");
  20316. }
  20317. }
  20318. void SetServerSign(int value)
  20319. {
  20320. server_sign = value;
  20321. }
  20322. int GetBootNotificationInterval(void)
  20323. {
  20324. return BootNotificationInterval;
  20325. }
  20326. int GetInternetConn(void)
  20327. {
  20328. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20329. }
  20330. int GetBackendConnectionTimeout(void)
  20331. {
  20332. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20333. }
  20334. int isConnectorInitMode(int gun_index)
  20335. {
  20336. int tempIndex = 0;
  20337. int result = TRUE;
  20338. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20339. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20340. {
  20341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20342. {
  20343. tempIndex = ((gun_index==2) ? 1: 0);
  20344. }
  20345. else
  20346. {
  20347. tempIndex = gun_index;
  20348. }
  20349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20350. {
  20351. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20352. {
  20353. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20354. } //end of the same index
  20355. }//end of for CHAdeMO_QUANTITY
  20356. }
  20357. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20358. {
  20359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20360. {
  20361. tempIndex = ((gun_index==2) ? 1: 0);
  20362. }
  20363. else
  20364. {
  20365. tempIndex = gun_index;
  20366. }
  20367. for (int index = 0; index < CCS_QUANTITY; index++)
  20368. {
  20369. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20370. {
  20371. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20372. } //end of the same index
  20373. } // end of for CCS_QUANTITY
  20374. }
  20375. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20376. {
  20377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20378. {
  20379. tempIndex = ((gun_index==2) ? 1: 0);
  20380. }
  20381. else
  20382. {
  20383. tempIndex = gun_index;
  20384. }
  20385. for (int index = 0; index < GB_QUANTITY; index++)
  20386. {
  20387. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20388. {
  20389. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20390. } //end of the same index
  20391. } // end of for GB_QUANTITY
  20392. }
  20393. else if(gunType[gun_index] == GUN_TYPE_DO)
  20394. {
  20395. tempIndex = gun_index;
  20396. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20397. {
  20398. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20399. {
  20400. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20401. } //end of the same index
  20402. }
  20403. }
  20404. else
  20405. {
  20406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20407. {
  20408. tempIndex = 2;
  20409. }
  20410. else
  20411. {
  20412. tempIndex = gun_index;
  20413. }
  20414. for (int index = 0; index < AC_QUANTITY; index++)
  20415. {
  20416. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20417. {
  20418. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20419. }//end of the same index
  20420. }//end of for AC_QUANTITY
  20421. }
  20422. return result;
  20423. }
  20424. void refreshProcDogTimer()
  20425. {
  20426. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20427. }
  20428. void InitialSystemValue(void)
  20429. {
  20430. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20431. locallistVersion=0;
  20432. BootNotificationInterval = 0;
  20433. authorizeRetryTimes = 0;
  20434. GunStatusInterval = 10;
  20435. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20436. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20437. //Hear Beat
  20438. HeartBeatWithNOResponse = 0;
  20439. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20440. FirstHeartBeat = 0;
  20441. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20442. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20443. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20444. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20445. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20446. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20447. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20448. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20449. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20450. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20451. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20452. //Status && ConnectorPlugIn Setting
  20453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20454. {
  20455. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20456. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20457. }
  20458. for (int index = 0; index < CCS_QUANTITY; index++)
  20459. {
  20460. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20461. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20462. }
  20463. for (int index = 0; index < GB_QUANTITY; index++)
  20464. {
  20465. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20466. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20467. }
  20468. for (int index = 0; index < AC_QUANTITY; index++)
  20469. {
  20470. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20471. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20472. }
  20473. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20474. {
  20475. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20476. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20477. }
  20478. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20479. {
  20480. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20481. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20482. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20483. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20484. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20485. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20486. }
  20487. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20488. refreshStartTimer(&clientTime.Heartbeat);
  20489. sleep(1);
  20490. }
  20491. void LWS_Send(char *str)
  20492. {
  20493. //=====================================================
  20494. // Check InternetConn 0: disconnected, 1: connected
  20495. //====================================================
  20496. if(GetOcppConnStatus() == 0)
  20497. {
  20498. DEBUG_INFO("offline now !!!\n");
  20499. return;
  20500. }
  20501. // Only disable isWebsocketSendable operation initiated by charger
  20502. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20503. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20504. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20505. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20506. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20507. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20508. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20509. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20510. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20511. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20512. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20513. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20514. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20515. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20516. {
  20517. isWebsocketSendable = 0;
  20518. }
  20519. pthread_mutex_lock(&lock_send);
  20520. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20521. sprintf((char *)SendBuffer, "%s", str);
  20522. SendBufLen = strlen(str);
  20523. pthread_mutex_unlock(&lock_send);
  20524. lws_callback_on_writable(wsi_client);
  20525. //lws_service(context, 0);
  20526. //sleep(1);
  20527. }
  20528. void LWS_SendNow(char *str)
  20529. {
  20530. //=====================================================
  20531. // Check InternetConn 0: disconnected, 1: connected
  20532. //====================================================
  20533. if(GetOcppConnStatus() == 0)
  20534. {
  20535. DEBUG_INFO("offline now !!!\n");
  20536. return;
  20537. }
  20538. // Only disable isWebsocketSendable operation initiated by charger
  20539. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20540. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20541. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20542. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20543. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20544. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20545. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20546. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20547. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20548. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20549. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20550. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20551. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20552. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20553. {
  20554. isWebsocketSendable = 0;
  20555. }
  20556. pthread_mutex_lock(&lock_send);
  20557. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20558. sprintf((char *)SendBuffer, "%s", str);
  20559. SendBufLen = strlen(str);
  20560. pthread_mutex_unlock(&lock_send);
  20561. lws_callback_on_writable(wsi_client);
  20562. lws_service(context, 0);
  20563. //sleep(1);
  20564. }