MessageHandler.c 450 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "SystemLogMessage.h"
  24. #include "define.h"
  25. #include "ShareMemory.h"
  26. #include "SystemLogMessage.h"
  27. //#include "config.h"
  28. #include <sys/socket.h>
  29. #include <netinet/in.h>
  30. #include <stdlib.h>
  31. /*for sendfile()*/
  32. #include <sys/sendfile.h>
  33. /*for O_RDONLY*/
  34. #include <fcntl.h>
  35. #include "sqlite3.h"
  36. #include <arpa/inet.h>
  37. //#define _GNU_SOURCE
  38. #include <time.h>
  39. #include "MessageHandler.h"
  40. #include <assert.h>
  41. #include <pthread.h>
  42. #include <mcheck.h>
  43. #define PASS 1
  44. #define FAIL -1
  45. #define FALSE 0
  46. #define TRUE 1 // Option 1
  47. //ChargePointMaxProfile
  48. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  49. //TxDefaultProfile
  50. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  51. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  52. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  53. //TxProfile
  54. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  55. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  56. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  57. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  58. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  59. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  60. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  61. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  62. struct StatusCodeData *ShmStatusCodeData;
  63. struct PsuData *ShmPsuData ;
  64. struct OCPP16Data *ShmOCPP16Data;
  65. // define Macro
  66. #define SystemLogMessage
  67. // OCPP Message Type
  68. #define MESSAGE_TYPE_CALL 2
  69. #define MESSAGE_TYPE_CALLRESULT 3
  70. #define MESSAGE_TYPE_CALLERROR 4
  71. //
  72. #define server_cycle_Status 120
  73. #define MACROSTR(k) #k
  74. //ConfigurationMaxKeys
  75. #define GetConfigurationMaxKeysNUM 43
  76. //char guid[37];
  77. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  78. char queuedata[2000]={0};
  79. //===============================
  80. // Configuration: unknownkey
  81. //===============================
  82. static char unknownkey[10][20]={0};
  83. static int UnknownKeynum = 0;
  84. //===============================
  85. // Gun Total Numbers
  86. //===============================
  87. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  88. static int gunTotalNumber=0;
  89. //===============================
  90. // Local List Version
  91. //===============================
  92. static int localversion=0;
  93. static char idTagAuthorization[32]={0};
  94. //===============================
  95. // OCPP Path
  96. //===============================
  97. char OcppPath[160]={};
  98. char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP other variables
  115. //===============================
  116. int isUpdateRequest = FALSE;
  117. static int HeartBeatWaitTime = 10;
  118. static int FirstHeartBeat = 0;
  119. static int FirmwareStatusNotificationStatus = 3; // Idle
  120. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  121. //========================================
  122. // OCPP status/previous related variables
  123. //========================================
  124. static int GunStatusInterval = 10;
  125. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  126. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  127. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  128. static int GbPreviousSystemStatus[GB_QUANTITY];
  129. static int AcPreviousSystemStatus[AC_QUANTITY];
  130. int TransactionMessageAttemptsValue = 0;
  131. int TransactionMessageRetryIntervalValue = 0;
  132. static struct OCPPAuthLocalElemet
  133. {
  134. int listVersionInt;
  135. char idTagstr[20];
  136. char parentIdTag[20];
  137. char expiryDate[30];
  138. char idTagstatus[16];
  139. }idTagQuery;
  140. extern struct lws *wsi_client;
  141. extern struct lws_context *context;
  142. #if 0
  143. extern unsigned char *SendBuffer;
  144. #endif
  145. extern unsigned char SendBuffer[4096];
  146. extern int SendBufLen;
  147. //extern map_t hashMap;
  148. //extern data_struct_t* mapItem; --- remove for temporally
  149. //extern data_struct_t mapItem[0];
  150. extern char *random_uuid( char buf[37] );
  151. extern void split(char **arr, char *str, const char *del);
  152. extern pthread_mutex_t mutex1;
  153. extern struct Charger_Info Charger;
  154. extern sqlite3 *db;
  155. int TransactionMessageAttemptsGet(void);
  156. int TransactionMessageRetryIntervalGet(void);
  157. int GetOcppConnStatus(void);
  158. void SetOcppConnStatus(uint8_t status);
  159. int updateSetting(char *key, char *value);
  160. int setKeyValue(char *key, char *value);
  161. void OCPP_get_TableAuthlocalAllData(void);
  162. void processUnkownKey(void);
  163. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  164. struct StructOCPPMeterValue
  165. {
  166. unsigned char TimeStamp[28];
  167. struct StructSampledValue SampledValue[10];
  168. };
  169. struct ClientTime
  170. {
  171. unsigned int Heartbeat;
  172. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  173. unsigned int StartTransaction;
  174. unsigned int StopTransaction;
  175. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  176. }clientTime;
  177. typedef union
  178. {
  179. //Operations Initiated by Central System
  180. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  181. struct
  182. {
  183. //CsMsgValue[0]
  184. unsigned char StatusNotificationReq :1; //bit 0,
  185. unsigned char StatusNotificationConf :1; //bit 0,
  186. unsigned char :6; //bit 2~7
  187. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  188. }CpinitiateMsg;
  189. CpinitiateMsg cpinitateMsg;
  190. //==========================================
  191. // Init all Enumeration & Mapping String
  192. //==========================================
  193. /*ChargePointErrorCode*/
  194. typedef enum {
  195. ConnectorLockFailure,
  196. EVCommunicationError,
  197. GroundFailure,
  198. HighTemperature,
  199. InternalError,
  200. LocalListConflict,
  201. NoError,
  202. OtherError,
  203. OverCurrentFailure,
  204. OverVoltage,
  205. PowerMeterFailure,
  206. PowerSwitchFailure,
  207. ReaderFailure,
  208. ResetFailure,
  209. UnderVoltage,
  210. WeakSignal
  211. } ChargePointErrorCode;
  212. #if 0
  213. static char *ChargePointErrorCodeStr[] = {
  214. MACROSTR(ConnectorLockFailure),
  215. MACROSTR(EVCommunicationError),
  216. MACROSTR(GroundFailure),
  217. MACROSTR(HighTemperature),
  218. MACROSTR(InternalError),
  219. MACROSTR(LocalListConflict),
  220. MACROSTR(NoError),
  221. MACROSTR(OtherError),
  222. MACROSTR(OverCurrentFailure),
  223. MACROSTR(OverVoltage),
  224. MACROSTR(PowerMeterFailure),
  225. MACROSTR(PowerSwitchFailure),
  226. MACROSTR(ReaderFailure),
  227. MACROSTR(ResetFailure),
  228. MACROSTR(UnderVoltage),
  229. MACROSTR(WeakSignal)
  230. };
  231. #endif
  232. /*ChargePointStatus*/
  233. typedef enum {
  234. Available =0,
  235. Preparing,
  236. Charging,
  237. SuspendedEVSE,
  238. SuspendedEV,
  239. Finishing,
  240. Reserved,
  241. Unavailable,
  242. Faulted
  243. } ChargePointStatus;
  244. static char * ChargePointStatusStr[] = {
  245. MACROSTR(Available),
  246. MACROSTR(Preparing),
  247. MACROSTR(Charging),
  248. MACROSTR(SuspendedEVSE),
  249. MACROSTR(SuspendedEV),
  250. MACROSTR(Finishing),
  251. MACROSTR(Reserved),
  252. MACROSTR(Unavailable),
  253. MACROSTR(Faulted)
  254. };
  255. /*AvailabilityType*/
  256. typedef enum {
  257. RegistrationStatus_Accepted,
  258. RegistrationStatus_Pending,
  259. RegistrationStatus_Rejected
  260. } RegistrationStatus;
  261. static char *RegistrationStatusStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Pending),
  264. MACROSTR(Rejected)
  265. };
  266. /*AvailabilityType*/
  267. typedef enum {
  268. Inoperative,
  269. Operative
  270. } AvailabilityType;
  271. static char *AvailabilityTypeStr[] = {
  272. MACROSTR(Inoperative),
  273. MACROSTR(Operative)
  274. };
  275. /*AvailabilityStatus*/
  276. typedef enum {
  277. Accepted,
  278. Rejected,
  279. Scheduled
  280. } AvailabilityStatus;
  281. static char *AvailabilityStatusStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Rejected),
  284. MACROSTR(Scheduled)
  285. };
  286. /*ConfigurationStatus*/
  287. typedef enum {
  288. ConfigurationStatus_Accepted,
  289. ConfigurationStatus_Rejected,
  290. RebootRequired,
  291. NotSupported
  292. } ConfigurationStatus;
  293. static char *ConfigurationStatusStr[] = {
  294. MACROSTR(Accepted),
  295. MACROSTR(Rejected),
  296. MACROSTR(RebootRequired),
  297. MACROSTR(NotSupported)
  298. };
  299. /*ClearCacheStatus*/
  300. typedef enum {
  301. ClearCacheStatus_Accepted,
  302. ClearCacheStatus_Rejected
  303. } ClearCacheStatus;
  304. static char *ClearCacheStatusStr[] = {
  305. MACROSTR(Accepted),
  306. MACROSTR(Rejected)
  307. };
  308. /*ChargingProfilePurposeType*/
  309. typedef enum {
  310. ChargePointMaxProfile,
  311. TxDefaultProfile,
  312. TxProfile
  313. } ChargingProfilePurposeType;
  314. static char *ChargingProfilePurposeTypeStr[] = {
  315. MACROSTR(ChargePointMaxProfile),
  316. MACROSTR(TxDefaultProfile),
  317. MACROSTR(TxProfile)
  318. };
  319. /*ChargingProfileStatus*/
  320. typedef enum {
  321. ChargingProfileStatus_Accepted,
  322. ChargingProfileStatus_Rejected,
  323. ChargingProfileStatus_NotSupported
  324. } ChargingProfileStatus;
  325. static char *ChargingProfileStatusStr[] = {
  326. MACROSTR(Accepted),
  327. MACROSTR(Rejected),
  328. MACROSTR(NotSupported)
  329. };
  330. /*ClearChargingProfileStatus*/
  331. typedef enum {
  332. ClearChargingProfileStatus_Accepted,
  333. ClearChargingProfileStatus_Unknown
  334. } ClearChargingProfileStatus;
  335. static char *ClearChargingProfileStatusStr[] = {
  336. MACROSTR(Accepted),
  337. MACROSTR(Unknown)
  338. };
  339. /*GetCompositeScheduleStatus*/
  340. typedef enum {
  341. GetCompositeScheduleStatus_Accepted,
  342. GetCompositeScheduleStatus_Rejected
  343. } GetCompositeScheduleStatus;
  344. static char *GetCompositeScheduleStatusStr[] = {
  345. MACROSTR(Accepted),
  346. MACROSTR(Rejected)
  347. };
  348. /*ChargingRateUnitType*/
  349. typedef enum {
  350. ChargingRateUnitType_W,
  351. ChargingRateUnitType_A
  352. } ChargingRateUnitType;
  353. /*AuthorizationStatus*/
  354. typedef enum {
  355. AuthorizationStatus_Accepted ,
  356. AuthorizationStatus_Blocked ,
  357. AuthorizationStatus_Expired ,
  358. AuthorizationStatus_Invalid ,
  359. AuthorizationStatus_ConcurrentTx
  360. } AuthorizationStatus;
  361. /*UpdateType*/
  362. typedef enum {
  363. Differential ,
  364. Full
  365. } UpdateType;
  366. static char *UpdateTypeStr[] = {
  367. MACROSTR(Differential),
  368. MACROSTR(Full)
  369. };
  370. /*UpdateStatus*/
  371. typedef enum {
  372. UpdateStatus_Accepted ,
  373. UpdateStatus_Failed ,
  374. UpdateStatus_NotSupported ,
  375. UpdateStatus_VersionMismatch
  376. } UpdateStatus;
  377. static char *UpdateStatusStr[] = {
  378. MACROSTR(Accepted),
  379. MACROSTR(Failed),
  380. MACROSTR(NotSupported),
  381. MACROSTR(VersionMismatch)
  382. };
  383. /*RemoteStartStopStatus*/
  384. typedef enum {
  385. RemoteStartStopStatus_Accepted,
  386. RemoteStartStopStatus_Rejected
  387. } RemoteStartStopStatus;
  388. static char *RemoteStartStopStatusStr[] = {
  389. MACROSTR(Accepted),
  390. MACROSTR(Rejected)
  391. };
  392. /*ReservationStatus*/
  393. typedef enum {
  394. ReservationStatus_Accepted,
  395. ReservationStatus_Faulted,
  396. ReservationStatus_Occupied,
  397. ReservationStatus_Rejected,
  398. ReservationStatus_Unavailable
  399. } ReservationStatus;
  400. static char *ReservationStatusStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Faulted),
  403. MACROSTR(Occupied),
  404. MACROSTR(Rejected),
  405. MACROSTR(Unavailable)
  406. };
  407. /*ResetType*/
  408. typedef enum {
  409. Hard,
  410. Soft
  411. } ResetType;
  412. static char *ResetTypeStr[] = {
  413. MACROSTR(Hard),
  414. MACROSTR(Soft)
  415. };
  416. /*ResetStatus*/
  417. typedef enum {
  418. ResetStatus_Accepted,
  419. ResetStatus_Rejected
  420. } ResetStatus;
  421. static char *ResetStatusStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Rejected)
  424. };
  425. /*DiagnosticsStatus*/
  426. typedef enum {
  427. DiagnosticsStatus_Idle,
  428. DiagnosticsStatus_Uploaded,
  429. DiagnosticsStatus_UploadFailed,
  430. DiagnosticsStatus_Uploading
  431. } DiagnosticsStatus;
  432. static char * DiagnosticsStatusStr[] = {
  433. MACROSTR(Idle),
  434. MACROSTR(Uploaded),
  435. MACROSTR(UploadFailed),
  436. MACROSTR(Uploading)
  437. };
  438. /*FirmwareStatus*/
  439. typedef enum {
  440. FirmwareStatus_Downloaded,
  441. FirmwareStatus_DownloadFailed,
  442. FirmwareStatus_Downloading,
  443. FirmwareStatus_Idle,
  444. FirmwareStatus_InstallationFailed,
  445. FirmwareStatus_Installing,
  446. FirmwareStatus_Installed
  447. } FirmwareStatus;
  448. static char * FirmwareStatusStr[] = {
  449. MACROSTR(Downloaded),
  450. MACROSTR(DownloadFailed),
  451. MACROSTR(Downloading),
  452. MACROSTR(Idle),
  453. MACROSTR(InstallationFailed),
  454. MACROSTR(Installing),
  455. MACROSTR(Installed)
  456. };
  457. /*MessageTrigger*/
  458. typedef enum {
  459. BootNotification,
  460. DiagnosticsStatusNotification,
  461. FirmwareStatusNotification,
  462. Heartbeat,
  463. MeterValues,
  464. StatusNotification
  465. } MessageTrigger;
  466. static char * MessageTriggerStr[] = {
  467. MACROSTR(BootNotification),
  468. MACROSTR(DiagnosticsStatusNotification),
  469. MACROSTR(FirmwareStatusNotification),
  470. MACROSTR(Heartbeat),
  471. MACROSTR(MeterValues),
  472. MACROSTR(StatusNotification)
  473. };
  474. /*TriggerMessageStatus*/
  475. typedef enum {
  476. TriggerMessageStatus_Accepted ,
  477. TriggerMessageStatus_Rejected ,
  478. TriggerMessageStatus_NotImplemented
  479. } TriggerMessageStatus;
  480. static char * TriggerMessageStatusStr[] = {
  481. MACROSTR(Accepted),
  482. MACROSTR(Rejected),
  483. MACROSTR(NotImplemented)
  484. };
  485. /*UnlockStatus*/
  486. typedef enum {
  487. Unlocked,
  488. UnlockFailed,
  489. UnlockStatus_NotSupported
  490. } UnlockStatus;
  491. static char * UnlockStatusStr[] = {
  492. MACROSTR(Unlocked),
  493. MACROSTR(UnlockFailed),
  494. MACROSTR(NotSupported)
  495. };
  496. /*StopTransactionReason*/
  497. typedef enum {
  498. EmergencyStop,
  499. EVDisconnected,
  500. HardReset,
  501. Local,
  502. Other,
  503. PowerLoss,
  504. Reboot,
  505. Remote,
  506. SoftReset,
  507. UnlockCommand,
  508. DeAuthorized
  509. } StopTransactionReason;
  510. static char * StopTransactionReasonStr[] = {
  511. MACROSTR(EmergencyStop),
  512. MACROSTR(EVDisconnected),
  513. MACROSTR(HardReset),
  514. MACROSTR(Local),
  515. MACROSTR(Other),
  516. MACROSTR(PowerLoss),
  517. MACROSTR(Reboot),
  518. MACROSTR(Remote),
  519. MACROSTR(SoftReset),
  520. MACROSTR(UnlockCommand),
  521. MACROSTR(DeAuthorized)
  522. };
  523. /*CancelReservationStatus*/
  524. typedef enum {
  525. CancelReservationStatus_Accepted,
  526. CancelReservationStatus_Rejected
  527. } CancelReservationStatus;
  528. static char * CancelReservationStatusStr[] = {
  529. MACROSTR(Accepted),
  530. MACROSTR(Rejected)
  531. };
  532. /*ReadingContext*/
  533. typedef enum {
  534. ReadingContext_Interruption_Begin,
  535. ReadingContext_Interruption_End,
  536. ReadingContext_Other,
  537. ReadingContext_Sample_Clock,
  538. ReadingContext_Sample_Periodic ,
  539. ReadingContext_Transaction_Begin ,
  540. ReadingContext_Transaction_End,
  541. ReadingContext_Trigger
  542. } ReadingContext;
  543. static char * ReadingContextStr[] = {
  544. MACROSTR(Interruption.Begin),
  545. MACROSTR(Interruption.End),
  546. MACROSTR(Other),
  547. MACROSTR(Sample.Clock),
  548. MACROSTR(Sample.Periodic),
  549. MACROSTR(Transaction.Begin),
  550. MACROSTR(Transaction.End),
  551. MACROSTR(Trigger)
  552. };
  553. /*ValueFormat*/
  554. typedef enum {
  555. Raw,
  556. SignedData
  557. } ValueFormat;
  558. static char * ValueFormatStr[] = {
  559. MACROSTR(Raw),
  560. MACROSTR(SignedData)
  561. };
  562. /*Measurand*/
  563. typedef enum {
  564. Current_Export ,
  565. Current_Import,
  566. Current_Offered,
  567. Energy_Active_Export_Register,
  568. Energy_Active_Import_Register,
  569. Energy_Reactive_Export_Register,
  570. Energy_Reactive_Import_Register,
  571. Energy_Active_Export_Interval,
  572. Energy_Active_Import_Interval,
  573. Energy_Reactive_Export_Interval,
  574. Energy_Reactive_Import_Interval,
  575. Frequency,
  576. Power_Active_Export ,
  577. Power_Active_Import,
  578. Power_Factor,
  579. Power_Offered,
  580. Power_Reactive_Export,
  581. Power_Reactive_Import,
  582. RPM,
  583. SoC,
  584. Temperature ,
  585. Voltage
  586. } Measurand;
  587. static char * MeasurandStr[] = {
  588. MACROSTR(Current.Export),
  589. MACROSTR(Current.Import),
  590. MACROSTR(Current.Offered),
  591. MACROSTR(Energy.Active.Export.Register),
  592. MACROSTR(Energy.Active.Import.Register),
  593. MACROSTR(Energy.Reactive.Export.Register),
  594. MACROSTR(Energy.Reactive.Import.Register),
  595. MACROSTR(Energy.Active.Export.Interval),
  596. MACROSTR(Energy.Active.Import.Interval),
  597. MACROSTR(Energy.Reactive.Export.Interval),
  598. MACROSTR(Energy.Reactive.Import.Interval),
  599. MACROSTR(Frequency),
  600. MACROSTR(Power.Active.Export),
  601. MACROSTR(Power.Active.Import),
  602. MACROSTR(Power.Factor),
  603. MACROSTR(Power.Offered),
  604. MACROSTR(Power.Reactive.ExportMACROSTR),
  605. MACROSTR(Power.Reactive.Import),
  606. MACROSTR(RPM),
  607. MACROSTR(SoC),
  608. MACROSTR(Temperature),
  609. MACROSTR(Voltage)
  610. };
  611. /*Location*/
  612. typedef enum {
  613. Location_Body,
  614. Location_Cable,
  615. Location_EV,
  616. Location_Inlet ,
  617. Location_Outlet
  618. } Location;
  619. static char * LocationStr[] = {
  620. MACROSTR(Body),
  621. MACROSTR(Cable),
  622. MACROSTR(EV),
  623. MACROSTR(Inlet),
  624. MACROSTR(Outlet)
  625. };
  626. /*Phase*/
  627. typedef enum {
  628. L1,
  629. L2,
  630. L3,
  631. N,
  632. L1_N,
  633. L2_N,
  634. L3_N,
  635. L1_L2,
  636. L2_L3,
  637. L3_L1
  638. } Phase;
  639. static char * PhaseStr[] = {
  640. MACROSTR(L1),
  641. MACROSTR(L2),
  642. MACROSTR(L3),
  643. MACROSTR(N),
  644. MACROSTR(L1-N),
  645. MACROSTR(L2-N),
  646. MACROSTR(L3-N),
  647. MACROSTR(L1-L2),
  648. MACROSTR(L2-L3),
  649. MACROSTR(L3-L1)
  650. };
  651. /*UnitOfMeasure*/
  652. typedef enum {
  653. UnitOfMeasure_Wh,
  654. UnitOfMeasure_kWh ,
  655. UnitOfMeasure_varh ,
  656. UnitOfMeasure_kvarh ,
  657. UnitOfMeasure_W ,
  658. UnitOfMeasure_kW ,
  659. UnitOfMeasure_VA ,
  660. UnitOfMeasure_kVA ,
  661. UnitOfMeasure_var ,
  662. UnitOfMeasure_kvar ,
  663. UnitOfMeasure_A ,
  664. UnitOfMeasure_V ,
  665. UnitOfMeasure_Celsius ,
  666. UnitOfMeasure_Fahrenheit ,
  667. UnitOfMeasure_K ,
  668. UnitOfMeasure_Percent
  669. } UnitOfMeasure;
  670. static char * UnitOfMeasureStr[] = {
  671. MACROSTR(Wh),
  672. MACROSTR(kWh),
  673. MACROSTR(varh),
  674. MACROSTR(kvarh),
  675. MACROSTR(W),
  676. MACROSTR(kW),
  677. MACROSTR(VA),
  678. MACROSTR(kVA),
  679. MACROSTR(var),
  680. MACROSTR(kvar),
  681. MACROSTR(A),
  682. MACROSTR(V),
  683. MACROSTR(Celsius),
  684. MACROSTR(Fahrenheit),
  685. MACROSTR(K),
  686. MACROSTR(Percent)
  687. };
  688. /*Configuration enum*/
  689. enum CoreProfile {
  690. AllowOfflineTxForUnknownId=0,
  691. AuthorizationCacheEnabled,
  692. AuthorizeRemoteTxRequests,
  693. BlinkRepeat,
  694. ClockAlignedDataInterval,
  695. ConnectionTimeOut,
  696. GetConfigurationMaxKeys,
  697. HeartbeatInterval,
  698. LightIntensity,
  699. LocalAuthorizeOffline,
  700. LocalPreAuthorize,
  701. MaxEnergyOnInvalidId,
  702. MeterValuesAlignedData,
  703. MeterValuesAlignedDataMaxLength,
  704. MeterValuesSampledData,
  705. MeterValuesSampledDataMaxLength,
  706. MeterValueSampleInterval,
  707. MinimumStatusDuration,
  708. NumberOfConnectors,
  709. ResetRetries,
  710. ConnectorPhaseRotation,
  711. ConnectorPhaseRotationMaxLength,
  712. StopTransactionOnEVSideDisconnect,
  713. StopTransactionOnInvalidId,
  714. StopTxnAlignedData,
  715. StopTxnAlignedDataMaxLength,
  716. StopTxnSampledData,
  717. StopTxnSampledDataMaxLength,
  718. SupportedFeatureProfiles,
  719. SupportedFeatureProfilesMaxLength,
  720. TransactionMessageAttempts,
  721. TransactionMessageRetryInterval,
  722. UnlockConnectorOnEVSideDisconnect,
  723. WebSocketPingInterval,
  724. _CoreProfile_CNT
  725. };
  726. enum LocalAuthListManagementProfile{
  727. LocalAuthListEnabled=0,
  728. LocalAuthListMaxLength,
  729. SendLocalListMaxLength,
  730. _LocalAuthListManagementProfile_CNT
  731. };
  732. enum ReservationProfile{
  733. ReserveConnectorZeroSupported
  734. };
  735. enum SmartChargingProfile{
  736. ChargeProfileMaxStackLevel,
  737. ChargingScheduleAllowedChargingRateUnit,
  738. ChargingScheduleMaxPeriods,
  739. ConnectorSwitch3to1PhaseSupported,
  740. MaxChargingProfilesInstalled
  741. };
  742. enum ChargerSystemStatus{
  743. ChargerSystemStatus_Booting,
  744. ChargerSystemStatus_Idle,
  745. ChargerSystemStatus_Authorizing,
  746. ChargerSystemStatus_Preparing,
  747. ChargerSystemStatus_Charging,
  748. ChargerSystemStatus_Terminating,
  749. ChargerSystemStatus_Alarm,
  750. ChargerSystemStatus_Fault
  751. };
  752. enum GetConfigurationKey {
  753. GetConfiguration_AllowOfflineTxForUnknownId=0,
  754. GetConfiguration_AuthorizationCacheEnabled,
  755. GetConfiguration_AuthorizeRemoteTxRequests,
  756. GetConfiguration_BlinkRepeat,
  757. GetConfiguration_ClockAlignedDataInterval,
  758. GetConfiguration_ConnectionTimeOut,
  759. GetConfiguration_GetConfigurationMaxKeys,
  760. GetConfiguration_HeartbeatInterval,
  761. GetConfiguration_LightIntensity,
  762. GetConfiguration_LocalAuthorizeOffline,
  763. GetConfiguration_LocalPreAuthorize,
  764. GetConfiguration_MaxEnergyOnInvalidId,
  765. GetConfiguration_MeterValuesAlignedData,
  766. GetConfiguration_MeterValuesAlignedDataMaxLength,
  767. GetConfiguration_MeterValuesSampledData,
  768. GetConfiguration_MeterValuesSampledDataMaxLength,
  769. GetConfiguration_MeterValueSampleInterval,
  770. GetConfiguration_MinimumStatusDuration,
  771. GetConfiguration_NumberOfConnectors,
  772. GetConfiguration_ResetRetries,
  773. GetConfiguration_ConnectorPhaseRotation,
  774. GetConfiguration_ConnectorPhaseRotationMaxLength,
  775. GetConfiguration_StopTransactionOnEVSideDisconnect,
  776. GetConfiguration_StopTransactionOnInvalidId,
  777. GetConfiguration_StopTxnAlignedData,
  778. GetConfiguration_StopTxnAlignedDataMaxLength,
  779. GetConfiguration_StopTxnSampledData,
  780. GetConfiguration_StopTxnSampledDataMaxLength,
  781. GetConfiguration_SupportedFeatureProfiles,
  782. GetConfiguration_SupportedFeatureProfilesMaxLength,
  783. GetConfiguration_TransactionMessageAttempts,
  784. GetConfiguration_TransactionMessageRetryInterval,
  785. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  786. GetConfiguration_WebSocketPingInterval,
  787. GetConfiguration_LocalAuthListEnabled,
  788. GetConfiguration_LocalAuthListMaxLength,
  789. GetConfiguration_SendLocalListMaxLength,
  790. GetConfiguration_ReserveConnectorZeroSupported,
  791. GetConfiguration_ChargeProfileMaxStackLevel,
  792. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  793. GetConfiguration_ChargingScheduleMaxPeriods,
  794. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  795. GetConfiguration_MaxChargingProfilesInstalled,
  796. };
  797. //GetConfiguration Array
  798. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  799. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  800. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  801. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  802. //==========================================
  803. // Init all share memory
  804. //==========================================
  805. int InitShareMemory()
  806. {
  807. int result = PASS;
  808. int MeterSMId;
  809. //printf("1\n");
  810. //creat ShmSysConfigAndInfo
  811. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  812. {
  813. #ifdef SystemLogMessage
  814. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  815. #endif
  816. result = FAIL;
  817. }
  818. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  819. {
  820. #ifdef SystemLogMessage
  821. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  822. #endif
  823. result = FAIL;
  824. }
  825. else
  826. {}
  827. //printf("2\n");
  828. //creat ShmStatusCodeData
  829. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  830. {
  831. #ifdef SystemLogMessage
  832. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  833. #endif
  834. result = FAIL;
  835. }
  836. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  837. {
  838. #ifdef SystemLogMessage
  839. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  840. #endif
  841. result = FAIL;
  842. }
  843. else
  844. {}
  845. //printf("3\n");
  846. //creat ShmPsuData
  847. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  848. {
  849. #ifdef SystemLogMessage
  850. DEBUG_ERROR("shmget ShmPsuData NG\n");
  851. #endif
  852. result = FAIL;
  853. }
  854. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  855. {
  856. #ifdef SystemLogMessage
  857. DEBUG_ERROR("shmat ShmPsuData NG\n");
  858. #endif
  859. result = FAIL;
  860. }
  861. else
  862. {}
  863. //creat ShmOCPP16Data
  864. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  865. {
  866. #ifdef SystemLogMessage
  867. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  868. #endif
  869. result = FAIL;
  870. }
  871. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  872. {
  873. #ifdef SystemLogMessage
  874. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  875. #endif
  876. result = FAIL;
  877. }
  878. else
  879. {}
  880. /****************************** For TEST ************************************************/
  881. //inital settings
  882. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  883. memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  884. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  885. {
  886. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  887. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  888. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  889. }
  890. // Charger PRE_SYS_MODE
  891. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  892. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  893. clientTime.Heartbeat=time((time_t*)NULL);
  894. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  895. {
  896. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  897. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  898. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  899. }
  900. //HeartBeatWaitTime = 10;
  901. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  902. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  903. // allocate Configuration memory address
  904. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  905. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  906. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  907. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  909. {
  910. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  911. DEBUG_INFO("DC ...\n");
  912. }
  913. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  914. {
  915. SystemInitial = AC_QUANTITY;
  916. DEBUG_INFO("AC ...\n");
  917. }
  918. //Status Setting
  919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  920. {
  921. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  922. }
  923. for (int index = 0; index < CCS_QUANTITY; index++)
  924. {
  925. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  926. }
  927. for (int index = 0; index < GB_QUANTITY; index++)
  928. {
  929. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  930. }
  931. for (int index = 0; index < AC_QUANTITY; index++)
  932. {
  933. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  934. }
  935. //memset(unknownkey, 0, 10);
  936. return result;
  937. }
  938. int ProcessShareMemory()
  939. {
  940. if(InitShareMemory() == FAIL)
  941. {
  942. #ifdef SystemLogMessage
  943. DEBUG_ERROR("InitShareMemory NG\n");
  944. #endif
  945. if(ShmStatusCodeData!=NULL)
  946. {
  947. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  948. }
  949. sleep(5);
  950. return FAIL;
  951. }
  952. return PASS;
  953. }
  954. //---------------------------------------------
  955. // new:
  956. // enum SYSTEM_STATUS
  957. // {
  958. // SYS_MODE_BOOTING = 0,
  959. // SYS_MODE_IDLE = 1,
  960. // SYS_MODE_AUTHORIZING = 2,
  961. // SYS_MODE_PREPARING = 3,
  962. // SYS_MODE_CHARGING = 4,
  963. // SYS_MODE_TERMINATING = 5,
  964. // SYS_MODE_ALARM = 6,
  965. // SYS_MODE_FAULT = 7,
  966. // SYS_MODE_RESERVATION = 8,
  967. // SYS_MODE_BOOKING = 9,
  968. // SYS_MODE_MAINTAIN = 10,
  969. // SYS_MODE_DEBUG = 11,
  970. // SYS_MODE_REASSIGN_CHECK = 12,
  971. // SYS_MODE_REASSIGN = 13,
  972. // SYS_MODE_PRECHARGE = 14,
  973. // SYS_MODE_PREPARING_EV = 15,
  974. // SYS_MODE_PREPARING_EVSE = 16,
  975. // SYS_MODE_COMPLETE = 17
  976. // };
  977. //
  978. // old:
  979. // enum _SYSTEM_STATUS
  980. // {
  981. // S_BOOTING = 0,
  982. // S_IDLE, =1
  983. // S_AUTHORIZING, =2
  984. // S_REASSIGN_CHECK, =3
  985. // S_REASSIGN, =4
  986. // S_PRECHARGE, =5
  987. // S_PREPARING_FOR_EV, =6
  988. // S_PREPARING_FOR_EVSE, =7
  989. // S_CHARGING, =8
  990. // S_TERMINATING, =9
  991. // S_COMPLETE, =10
  992. // S_ALARM, =11
  993. // S_FAULT =12
  994. // };
  995. //
  996. //-----------------------------------------
  997. void CheckSystemValue(void)
  998. {
  999. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1000. int IdleModeCnt = 0;
  1001. char filenmae[100]={0};
  1002. char str[100]={0};
  1003. //===============================
  1004. // send Heartbeat
  1005. //===============================
  1006. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1007. {
  1008. //parameter for test
  1009. sendHeartbeatRequest(0);
  1010. //==============================================
  1011. // Reset Waiting Time
  1012. //==============================================
  1013. clientTime.Heartbeat=time((time_t*)NULL);
  1014. }
  1015. //==============================================
  1016. // Update firmware request
  1017. //==============================================
  1018. if(isUpdateRequest == TRUE )
  1019. {
  1020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1021. {
  1022. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1023. {
  1024. //check SystemStatus
  1025. /*************************DC*******************************/
  1026. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1027. {
  1028. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1029. {
  1030. IdleModeCnt = IdleModeCnt + 1;
  1031. }
  1032. }
  1033. for (int index = 0; index < CCS_QUANTITY; index++)
  1034. {
  1035. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1036. {
  1037. IdleModeCnt = IdleModeCnt + 1;
  1038. }
  1039. }
  1040. for (int index = 0; index < GB_QUANTITY; index++)
  1041. {
  1042. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1043. {
  1044. IdleModeCnt = IdleModeCnt + 1;
  1045. }
  1046. }
  1047. }
  1048. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1049. {
  1050. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1051. isUpdateRequest = FALSE;
  1052. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1053. }
  1054. }
  1055. else
  1056. {
  1057. /*************************AC*******************************/
  1058. for (int index = 0; index < AC_QUANTITY; index++)
  1059. {
  1060. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1061. {
  1062. IdleModeCnt = IdleModeCnt + 1;
  1063. }
  1064. }
  1065. if(IdleModeCnt == AC_QUANTITY)
  1066. {
  1067. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1068. isUpdateRequest = FALSE;
  1069. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1070. }
  1071. }
  1072. }
  1073. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1074. for(int gun_index=0;gun_index < gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY )*/ ;gun_index++)
  1075. {
  1076. //===============================
  1077. // CSU Trigger Reset Conf
  1078. //===============================
  1079. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1080. {
  1081. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1082. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1083. {
  1084. server_sign = FALSE;
  1085. }
  1086. }
  1087. //===============================
  1088. // CSU Trigger Authorize Request
  1089. //===============================
  1090. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1091. {
  1092. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1093. {
  1094. sendAuthorizeRequest(0);
  1095. authorizeRetryTimes = authorizeRetryTimes + 1;
  1096. // authenrequest = TRUE
  1097. if(authorizeRetryTimes < 3)
  1098. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1099. }
  1100. }
  1101. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1102. {
  1103. authorizeRetryTimes = 0;
  1104. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1105. server_sign = FALSE;
  1106. }
  1107. //==============================================
  1108. // Charger start transaction
  1109. //==============================================
  1110. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1111. {
  1112. sendStartTransactionRequest(gun_index);
  1113. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1114. clientTime.StartTransaction = time((time_t*)NULL);
  1115. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1116. }
  1117. //==============================================
  1118. // Charger stop transaction
  1119. //==============================================
  1120. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1121. {
  1122. sendStopTransactionRequest(gun_index);
  1123. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1124. clientTime.StopTransaction = time((time_t*)NULL);
  1125. }
  1126. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1127. //==============================================
  1128. // Charger status report
  1129. //==============================================
  1130. /* Check Mode Change */
  1131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1132. {
  1133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1134. {
  1135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1136. {
  1137. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1138. {
  1139. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1140. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1141. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1142. statusModeChage[gun_index] = TRUE;
  1143. }
  1144. }
  1145. }
  1146. for (int index = 0; index < CCS_QUANTITY; index++)
  1147. {
  1148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1149. {
  1150. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1151. {
  1152. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1153. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1154. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1155. statusModeChage[gun_index] = TRUE;
  1156. }
  1157. }
  1158. }
  1159. for (int index = 0; index < GB_QUANTITY; index++)
  1160. {
  1161. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1162. {
  1163. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1164. {
  1165. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1166. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1167. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1168. statusModeChage[gun_index] = TRUE;
  1169. }
  1170. }
  1171. }
  1172. }
  1173. else //AC
  1174. {
  1175. for (int index = 0; index < AC_QUANTITY; index++)
  1176. {
  1177. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1178. {
  1179. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1180. {
  1181. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1182. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1183. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1184. statusModeChage[gun_index] = TRUE;
  1185. }
  1186. }
  1187. }// END OF FOR
  1188. }// END OF ELSE
  1189. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1190. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1191. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1192. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1193. {
  1194. if(SystemInitial != 0)
  1195. SystemInitial = SystemInitial -1;
  1196. //GunStatusInterval= GunStatusInterval* gun_index;
  1197. sendStatusNotificationRequest(gun_index);
  1198. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1199. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1200. statusModeChage[gun_index] = FALSE;
  1201. //sleep(30); // sleep for 30 seconds
  1202. }
  1203. //==============================================
  1204. // Meter report
  1205. //==============================================
  1206. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1207. {
  1208. //check Transaction active
  1209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1210. {
  1211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1212. {
  1213. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1214. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1215. {
  1216. meterValueSend[gun_index] =1;
  1217. }
  1218. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1219. {
  1220. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1221. if((access(filenmae,F_OK))!=-1)
  1222. {
  1223. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1224. sprintf(str,"rm -f %s",filenmae);
  1225. system(str);
  1226. }
  1227. }
  1228. }// End for CHAdeMO
  1229. for (int index = 0; index < CCS_QUANTITY; index++)
  1230. {
  1231. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1232. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1233. {
  1234. meterValueSend[gun_index] =1;
  1235. }
  1236. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1237. {
  1238. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1239. if((access(filenmae,F_OK))!=-1)
  1240. {
  1241. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1242. sprintf(str,"rm -f %s",filenmae);
  1243. system(str);
  1244. }
  1245. }
  1246. } // End for CCS
  1247. for (int index = 0; index < GB_QUANTITY; index++)
  1248. {
  1249. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1250. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1251. {
  1252. meterValueSend[gun_index] =1;
  1253. }
  1254. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1255. {
  1256. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1257. if((access(filenmae,F_OK))!=-1)
  1258. {
  1259. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1260. sprintf(str,"rm -f %s",filenmae);
  1261. system(str);
  1262. }
  1263. }
  1264. }// End for GB
  1265. }
  1266. else
  1267. {
  1268. for (int index = 0; index < AC_QUANTITY; index++)
  1269. {
  1270. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1271. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1272. {
  1273. meterValueSend[gun_index] =1;
  1274. }
  1275. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1276. {
  1277. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1278. if((access(filenmae,F_OK))!=-1)
  1279. {
  1280. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1281. sprintf(str,"rm -f %s",filenmae);
  1282. system(str);
  1283. }
  1284. }
  1285. }//End for AC
  1286. }//END OF ELSE
  1287. // sleep(1);
  1288. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1289. if(meterValueSend[gun_index] == 1)
  1290. sendMeterValuesRequest(gun_index);
  1291. }
  1292. //==============================================
  1293. // Check Connector reserved
  1294. //==============================================
  1295. //===============================
  1296. // Check if Reserve is expired
  1297. //===============================
  1298. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1299. {
  1300. double diff_t;
  1301. struct tm tp;
  1302. // current time
  1303. time_t t = time(NULL);
  1304. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1305. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1306. tp.tm_isdst = -1;
  1307. time_t utc = mktime(&tp);
  1308. diff_t = difftime(utc, t);
  1309. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1310. if(diff_t <= 0)
  1311. {
  1312. DEBUG_INFO("reserve expired !!! \n");
  1313. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1314. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1315. }
  1316. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1317. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1318. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1319. {
  1320. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1321. }
  1322. else
  1323. {
  1324. //check Transaction active
  1325. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1326. {
  1327. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1328. {
  1329. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1330. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1331. {
  1332. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1333. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1334. {
  1335. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1336. }
  1337. }
  1338. }
  1339. for (int index = 0; index < CCS_QUANTITY; index++)
  1340. {
  1341. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1342. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1343. {
  1344. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1345. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1346. {
  1347. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1348. }
  1349. }
  1350. }
  1351. for (int index = 0; index < GB_QUANTITY; index++)
  1352. {
  1353. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1354. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1355. {
  1356. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1357. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1358. {
  1359. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1360. }
  1361. }
  1362. }
  1363. }
  1364. else //AC
  1365. {
  1366. for (int index = 0; index < AC_QUANTITY; index++)
  1367. {
  1368. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1369. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1370. {
  1371. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1372. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1373. {
  1374. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1375. }
  1376. }
  1377. }
  1378. }// END OF ELSE
  1379. }// END OF check Transaction active
  1380. }//END OF Check if Reserve is expired
  1381. //==========================================
  1382. // csu trigger FirmwareStatusNotificationReq
  1383. //==========================================
  1384. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1385. {
  1386. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1387. }
  1388. //==========================================
  1389. // csu trigger CancelReservationConf
  1390. //==========================================
  1391. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1392. {
  1393. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1394. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1395. }
  1396. //==========================================
  1397. // csu trigger ChangeAvailabilityConf
  1398. //==========================================
  1399. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1400. {
  1401. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1402. }
  1403. //==========================================
  1404. // csu trigger UnlockConnectorConf
  1405. //==========================================
  1406. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1407. {
  1408. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1409. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1410. }
  1411. //==========================================
  1412. // csu trigger ReserveNowConf
  1413. //==========================================
  1414. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1415. {
  1416. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1417. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1418. }
  1419. //==========================================
  1420. // csu trigger DataTransferReq
  1421. //==========================================
  1422. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1423. {
  1424. sendDataTransferRequest(gun_index);
  1425. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1426. }
  1427. }
  1428. }
  1429. //==========================================
  1430. // send request routine
  1431. //==========================================
  1432. int sendAuthorizeRequest(int gun_index)
  1433. {
  1434. mtrace();
  1435. int result = FAIL;
  1436. char message[100]={0};
  1437. char guid[37];
  1438. char tempdata[65]={0};
  1439. DEBUG_INFO("sendAuthorizeRequest \n");
  1440. //Local Authorize
  1441. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1442. {
  1443. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1444. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1445. {
  1446. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1447. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1448. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1449. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1450. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1451. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1452. authorizeRetryTimes = 0;
  1453. return result;
  1454. }
  1455. else
  1456. {
  1457. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1458. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1459. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1460. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1461. result = PASS;
  1462. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1463. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1464. authorizeRetryTimes = 0;
  1465. return result;
  1466. }
  1467. }
  1468. //initailize struct Authorize
  1469. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1470. //get data from shared memory
  1471. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1472. random_uuid(guid);
  1473. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1474. LWS_Send(message);
  1475. sprintf(tempdata, "Authorize,%d", gun_index);
  1476. if(hashmap_operation(0, guid, tempdata) == 1)
  1477. {
  1478. result = PASS;
  1479. DEBUG_ERROR("Authorize mapItem pass\n");
  1480. }
  1481. //#ifdef SystemLogMessage
  1482. //DEBUG_INFO(">>>>>Authorize request\n");
  1483. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1484. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1485. //#endif
  1486. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1487. return result;
  1488. }
  1489. int sendBootNotificationRequest(void)
  1490. {
  1491. mtrace();
  1492. int result = FAIL;
  1493. char message[500]={0}, payload[700]={0};
  1494. char guid[37]={0};
  1495. char tempdata[65]={0};
  1496. int IsGunCharging = FALSE;
  1497. //check Transaction active
  1498. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1499. {
  1500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1501. {
  1502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1503. {
  1504. IsGunCharging = TRUE;
  1505. }
  1506. }
  1507. for (int index = 0; index < CCS_QUANTITY; index++)
  1508. {
  1509. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1510. {
  1511. IsGunCharging = TRUE;
  1512. }
  1513. }
  1514. for (int index = 0; index < GB_QUANTITY; index++)
  1515. {
  1516. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1517. {
  1518. IsGunCharging = TRUE;
  1519. }
  1520. }
  1521. }
  1522. else
  1523. {
  1524. for (int index = 0; index < AC_QUANTITY; index++)
  1525. {
  1526. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1527. {
  1528. IsGunCharging = TRUE;
  1529. }
  1530. }
  1531. }
  1532. if(IsGunCharging == TRUE)
  1533. {
  1534. server_sign = TRUE;
  1535. return result;
  1536. }
  1537. // Fill BootNotification fields
  1538. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1539. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1540. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1541. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1542. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1543. ShmOCPP16Data->ChargeBoxId
  1544. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1545. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1546. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1547. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1548. ,ShmOCPP16Data->BootNotification.CpIccid
  1549. ,ShmOCPP16Data->BootNotification.CpImsi
  1550. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1551. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1552. random_uuid(guid);
  1553. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1554. LWS_Send(message);
  1555. sprintf(tempdata, "BootNotification,0");
  1556. if(hashmap_operation(0, 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*/)
  1557. {
  1558. result = PASS;
  1559. }
  1560. memset(queuedata, 0, sizeof(queuedata));
  1561. strcpy(queuedata,message);
  1562. //#ifdef SystemLogMessage
  1563. //DEBUG_INFO(">>>>>BootNotification request\n");
  1564. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1565. //#endif
  1566. return result;
  1567. }
  1568. int sendDataTransferRequest(int gun_index)
  1569. {
  1570. mtrace();
  1571. char message[1000]={0};
  1572. char guid[37]={0};
  1573. char tempdata[65]={0};
  1574. int result = FAIL;
  1575. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1576. random_uuid(guid);
  1577. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1578. MESSAGE_TYPE_CALL,
  1579. guid,
  1580. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1581. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1582. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1583. LWS_Send(message);
  1584. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1585. if(hashmap_operation(0, 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*/)
  1586. {
  1587. result = PASS;
  1588. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1589. }
  1590. //#ifdef SystemLogMessage
  1591. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1592. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1593. //#endif
  1594. return result;
  1595. }
  1596. int sendDiagnosticsStatusNotificationRequest(char *status)
  1597. {
  1598. mtrace();
  1599. int result = FAIL;
  1600. char message[110]={0};
  1601. char guid[37]={0};
  1602. char tempdata[65]={0};
  1603. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1604. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1605. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1606. random_uuid(guid);
  1607. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1608. LWS_Send(message);
  1609. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1610. if(hashmap_operation(0, guid, tempdata) == 1)
  1611. {
  1612. result = PASS;
  1613. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1614. }
  1615. //#ifdef SystemLogMessage
  1616. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1617. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1618. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1619. //#endif
  1620. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1621. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1622. //record status
  1623. if(strcmp(status,"Idle")==0)
  1624. {
  1625. DiagnosticsStatusNotificationStatus = 0;
  1626. }
  1627. else if(strcmp(status,"Uploaded")==0)
  1628. {
  1629. DiagnosticsStatusNotificationStatus = 1;
  1630. }
  1631. else if(strcmp(status,"UploadFailed")==0)
  1632. {
  1633. DiagnosticsStatusNotificationStatus = 2;
  1634. }
  1635. else if(strcmp(status,"Uploading")==0)
  1636. {
  1637. DiagnosticsStatusNotificationStatus = 3;
  1638. }
  1639. return result;
  1640. }
  1641. int sendFirmwareStatusNotificationRequest(char *status)
  1642. {
  1643. mtrace();
  1644. int result = FAIL;
  1645. char message[110]={0};
  1646. char guid[37]={0};
  1647. char tempdata[65]={0};
  1648. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1649. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1650. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1651. random_uuid(guid);
  1652. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1653. LWS_Send(message);
  1654. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1655. if(hashmap_operation(0, 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*/)
  1656. {
  1657. result = PASS;
  1658. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1659. }
  1660. //#ifdef SystemLogMessage
  1661. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1662. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1663. //#endif
  1664. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1665. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1666. //record status
  1667. if(strcmp(status,"Downloaded")==0)
  1668. {
  1669. FirmwareStatusNotificationStatus = 0;
  1670. }
  1671. else if(strcmp(status,"DownloadFailed")==0)
  1672. {
  1673. FirmwareStatusNotificationStatus = 1;
  1674. }
  1675. else if(strcmp(status,"Downloading")==0)
  1676. {
  1677. FirmwareStatusNotificationStatus = 2;
  1678. }
  1679. else if(strcmp(status,"Idle")==0)
  1680. {
  1681. FirmwareStatusNotificationStatus = 3;
  1682. }
  1683. else if(strcmp(status,"InstallationFailed")==0)
  1684. {
  1685. FirmwareStatusNotificationStatus = 4;
  1686. }
  1687. else if(strcmp(status,"Installing")==0)
  1688. {
  1689. FirmwareStatusNotificationStatus = 5;
  1690. }
  1691. else if(strcmp(status,"Installed")==0)
  1692. {
  1693. FirmwareStatusNotificationStatus = 6;
  1694. }
  1695. return result;
  1696. }
  1697. int sendHeartbeatRequest(int gun_index)
  1698. {
  1699. mtrace();
  1700. int result = FAIL;
  1701. char message[80]={0};
  1702. char guid[37]={0};
  1703. char tempdata[65]={0};
  1704. random_uuid(guid);
  1705. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1706. , MESSAGE_TYPE_CALL
  1707. , guid );
  1708. LWS_Send(message);
  1709. sprintf(tempdata, "Heartbeat,%d", 0);
  1710. if(hashmap_operation(0, 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*/)
  1711. {
  1712. result = PASS;
  1713. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1714. }
  1715. //#ifdef SystemLogMessage
  1716. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1717. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1718. //#endif
  1719. return result;
  1720. }
  1721. int sendStartTransactionRequest(int gun_index)
  1722. {
  1723. mtrace();
  1724. int result = FAIL;
  1725. char message[250]={0};
  1726. char guid[37]={0};
  1727. struct timeval tmnow;
  1728. struct tm *tm;
  1729. char buf[30];//, usec_buf[6];
  1730. char tempdata[65]={0};
  1731. DEBUG_INFO("sendStartTransactionRequest...");
  1732. gettimeofday(&tmnow, NULL);
  1733. time_t t;
  1734. t = time(NULL);
  1735. /*UTC time and date*/
  1736. tm = gmtime(&t);
  1737. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1738. #if 0 // remove temporally
  1739. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1740. strcat(buf,".");
  1741. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1742. strcat(buf,usec_buf);
  1743. #endif
  1744. //printf("Start Charging Time :%s",buf);
  1745. // set value
  1746. if(ShmOCPP16Data->OcppConnStatus == 1 )
  1747. {
  1748. memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1749. }
  1750. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1751. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1752. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1754. {
  1755. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1756. {
  1757. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1758. {
  1759. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1760. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1761. }
  1762. }
  1763. for (int index = 0; index < CCS_QUANTITY; index++)
  1764. {
  1765. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1766. {
  1767. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1768. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1769. }
  1770. }
  1771. for (int index = 0; index < GB_QUANTITY; index++)
  1772. {
  1773. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1774. {
  1775. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1776. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1777. }
  1778. }
  1779. }
  1780. else
  1781. {
  1782. for (int index = 0; index < AC_QUANTITY; index++)
  1783. {
  1784. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1785. {
  1786. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1787. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1788. }
  1789. }
  1790. }//END OF ELSE
  1791. random_uuid(guid);
  1792. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1793. , MESSAGE_TYPE_CALL
  1794. , guid
  1795. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1796. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1797. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1798. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1799. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1800. LWS_Send(message);
  1801. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1802. if(hashmap_operation(0, 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*/)
  1803. {
  1804. result = PASS;
  1805. }
  1806. strcpy(queuedata, message);
  1807. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1808. //#ifdef SystemLogMessage
  1809. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1810. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1811. //#endif
  1812. return result;
  1813. }
  1814. int sendStatusNotificationRequest(int gun_index)
  1815. {
  1816. mtrace();
  1817. int result = FAIL;
  1818. char message[600]={0};
  1819. char guid[37];
  1820. int currentStatus = 0;
  1821. struct timeval tmnow;
  1822. struct tm *tm;
  1823. char buf[30];//, usec_buf[6];
  1824. char tempdata[65]={0};
  1825. gettimeofday(&tmnow, NULL);
  1826. time_t t;
  1827. t = time(NULL);
  1828. /*UTC time and date*/
  1829. tm = gmtime(&t);
  1830. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1831. #if 0 // remove temporally
  1832. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1833. strcat(buf,".");
  1834. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1835. strcat(buf,usec_buf);
  1836. #endif
  1837. printf("%s",buf);
  1838. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1839. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1840. // it's option
  1841. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1842. /*
  1843. enum _SYSTEM_STATUS
  1844. {
  1845. S_BOOTING = 0,
  1846. S_IDLE, = 1
  1847. S_AUTHORIZING, =2
  1848. S_REASSIGN_CHECK, =3
  1849. S_REASSIGN, =4
  1850. S_PRECHARGE, =5
  1851. S_PREPARING_FOR_EV, =6
  1852. S_PREPARING_FOR_EVSE, =7
  1853. S_CHARGING, =8
  1854. S_TERMINATING, =9
  1855. S_COMPLETE, =10
  1856. S_ALARM, =11
  1857. S_FAULT =12
  1858. }
  1859. */
  1860. //check Transaction active
  1861. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1862. {
  1863. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1864. {
  1865. //printf("gun_index=%d\n",gun_index);
  1866. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1867. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1868. {
  1869. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1870. currentStatus = 0; //OCPP Status
  1871. }
  1872. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1873. {
  1874. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1875. currentStatus = 1; //OCPP Status
  1876. }
  1877. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1878. {
  1879. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1880. currentStatus = 2; //OCPP Status
  1881. }
  1882. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1883. {
  1884. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1885. currentStatus = 5; //OCPP Status
  1886. }
  1887. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1888. {
  1889. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1890. currentStatus = 4; //OCPP Status
  1891. }
  1892. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  1893. {
  1894. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1895. currentStatus = 7; //OCPP Status: Unavailable
  1896. }
  1897. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1898. {
  1899. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1900. currentStatus = 8; //OCPP Status: Faulted
  1901. }
  1902. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1903. {
  1904. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1905. currentStatus = 6; //OCPP Status: Reserved
  1906. }
  1907. }//end of for CHAdeMO_QUANTITY
  1908. for (int index = 0; index < CCS_QUANTITY; index++)
  1909. {
  1910. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1911. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1912. {
  1913. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1914. currentStatus = 0; //OCPP Status
  1915. }
  1916. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1917. {
  1918. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1919. currentStatus = 1; //OCPP Status
  1920. }
  1921. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1922. {
  1923. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1924. currentStatus = 2; //OCPP Status
  1925. }
  1926. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1927. {
  1928. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1929. currentStatus = 5; //OCPP Status
  1930. }
  1931. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1932. {
  1933. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1934. currentStatus = 4; //OCPP Status
  1935. }
  1936. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  1937. {
  1938. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1939. currentStatus = 7; //OCPP Status
  1940. }
  1941. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1942. {
  1943. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1944. currentStatus = 8; //OCPP Status
  1945. }
  1946. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1947. {
  1948. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1949. currentStatus = 6; //OCPP Status
  1950. }
  1951. }
  1952. for (int index = 0; index < GB_QUANTITY; index++)
  1953. {
  1954. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1955. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1956. {
  1957. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1958. currentStatus = 0; //OCPP Status
  1959. }
  1960. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1961. {
  1962. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1963. currentStatus = 1; //OCPP Status
  1964. }
  1965. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1966. {
  1967. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1968. currentStatus = 2; //OCPP Status
  1969. }
  1970. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1971. {
  1972. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1973. currentStatus = 5; //OCPP Status
  1974. }
  1975. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1976. {
  1977. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1978. currentStatus = 4; //OCPP Status
  1979. }
  1980. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  1981. {
  1982. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1983. currentStatus = 7; //OCPP Status: Unavailable
  1984. }
  1985. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1986. {
  1987. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1988. currentStatus = 8; //OCPP Status: Faulted
  1989. }
  1990. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1991. {
  1992. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1993. currentStatus = 6; //OCPP Status: Faulted
  1994. }
  1995. }
  1996. }
  1997. else
  1998. {
  1999. for (int index = 0; index < AC_QUANTITY; index++)
  2000. {
  2001. //printf("gun_index=%d\n",gun_index);
  2002. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2003. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2004. {
  2005. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2006. currentStatus = 0; //OCPP Status
  2007. }
  2008. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2009. {
  2010. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2011. currentStatus = 1; //OCPP Status
  2012. }
  2013. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2014. {
  2015. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2016. currentStatus = 2; //OCPP Status
  2017. }
  2018. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2019. {
  2020. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2021. currentStatus = 5; //OCPP Status
  2022. }
  2023. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2024. {
  2025. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2026. currentStatus = 4; //OCPP Status
  2027. }
  2028. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  2029. {
  2030. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2031. currentStatus = 7; //OCPP Status: Unavailable
  2032. }
  2033. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2034. {
  2035. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2036. currentStatus = 8; //OCPP Status: Faulted
  2037. }
  2038. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2039. {
  2040. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2041. currentStatus = 6; //OCPP Status: Reserved
  2042. }
  2043. }//end of for AC_QUANTITY
  2044. }//END OF ELSE
  2045. //it's option
  2046. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2047. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2048. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2049. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2050. random_uuid(guid);
  2051. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2052. , MESSAGE_TYPE_CALL
  2053. , guid
  2054. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2055. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2056. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2057. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2058. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2059. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2060. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2061. LWS_Send(message);
  2062. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2063. if(hashmap_operation(0, 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*/)
  2064. {
  2065. //DEBUG_ERROR("statusNotification mapitem pass");
  2066. result = PASS;
  2067. }
  2068. //#ifdef SystemLogMessage
  2069. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2070. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2071. //#endif
  2072. return result;
  2073. }
  2074. int sendStopTransactionRequest(int gun_index)
  2075. {
  2076. mtrace();
  2077. int result = FAIL;
  2078. char message[1500]={0};
  2079. char guid[37]={0};
  2080. char tempdata[65]={0};
  2081. int idx_sample=0;
  2082. DEBUG_ERROR("sendStopTransactionRequest \n");
  2083. //memset(&(ShmOCPP16Data->StopTransaction[gun_index].TransactionData), 0, sizeof(struct StructMeterValue));
  2084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId/*ShmOCPP16Data->Authorize.IdTag*/);
  2085. //ENERGY_ACTIVE_IMPORT_REGISTER
  2086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2087. {
  2088. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2089. {
  2090. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2091. {
  2092. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2093. //Check Status
  2094. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2095. {
  2096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2097. }
  2098. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2099. }
  2100. }// END OF CHAdeMO_QUANTITY
  2101. for (int index = 0; index < CCS_QUANTITY; index++)
  2102. {
  2103. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2104. {
  2105. //for test
  2106. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2107. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2108. //Check Status
  2109. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2110. {
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2112. }
  2113. else
  2114. {
  2115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2116. }
  2117. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2118. }
  2119. }// END OF CCS_QUANTITY
  2120. for (int index = 0; index < GB_QUANTITY; index++)
  2121. {
  2122. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2123. {
  2124. // for test
  2125. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2126. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2127. //Check Status
  2128. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2129. {
  2130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2131. }
  2132. else
  2133. {
  2134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2135. }
  2136. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2137. }
  2138. }// END OF GB_QUANTITY
  2139. }
  2140. else
  2141. {
  2142. for (int index = 0; index < AC_QUANTITY; index++)
  2143. {
  2144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2145. {
  2146. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2147. //Check Status
  2148. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2149. {
  2150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2151. }
  2152. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2153. }
  2154. }// END OF AC_QUANTITY
  2155. }//END OF ELSE
  2156. //Stop Transaction Time
  2157. struct timeval tmnow;
  2158. struct tm *tm;
  2159. char buf[30];//, usec_buf[6];
  2160. gettimeofday(&tmnow, NULL);
  2161. time_t t;
  2162. t = time(NULL);
  2163. /*UTC time and date*/
  2164. tm = gmtime(&t);
  2165. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2166. #if 0 // remove temporally
  2167. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2168. strcat(buf,".");
  2169. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2170. strcat(buf,usec_buf);
  2171. #endif
  2172. printf("StopTransaction Time %s\n",buf);
  2173. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2175. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2176. random_uuid(guid);
  2177. sprintf(message,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":"
  2178. ,MESSAGE_TYPE_CALL
  2179. ,guid
  2180. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2181. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2182. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2183. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2184. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
  2185. /***********************************transactionData******************************************************/
  2186. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2187. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2188. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2189. {
  2190. //transactionData = json_object_new_object();
  2191. //json_object_object_add(transactionData, "timestamp", json_object_new_string("2019-05-04T18:15:33Z"));
  2192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp, buf/*"2019-05-04T18:15:33Z"*/);
  2193. sprintf(message + strlen(message), "[{\"timestamp\":\"%s\",\"sampledValue\":[", (const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp);
  2194. //=================================
  2195. // Transaction_Begin
  2196. //=================================
  2197. // Energy.Active.Export.Interval
  2198. idx_sample=0;
  2199. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2206. sprintf(message + strlen(message), "{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2207. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2208. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2209. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2210. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2211. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2212. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2213. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2214. );
  2215. //=================================
  2216. // Transaction_End
  2217. //=================================
  2218. //Current.Export
  2219. idx_sample=1;
  2220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2221. {
  2222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2223. {
  2224. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2225. {
  2226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2227. }
  2228. }
  2229. for (int index = 0; index < CCS_QUANTITY; index++)
  2230. {
  2231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2232. {
  2233. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2234. }
  2235. }
  2236. for (int index = 0; index < GB_QUANTITY; index++)
  2237. {
  2238. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2239. {
  2240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2241. }
  2242. }
  2243. }
  2244. else
  2245. {
  2246. for (int index = 0; index < AC_QUANTITY; index++)
  2247. {
  2248. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2249. {
  2250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2251. }
  2252. }
  2253. }// END FOR AC ELSE
  2254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Current_Export/*Energy_Reactive_Export_Register*/]);
  2257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A/*UnitOfMeasure_kWh*/]);
  2260. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2261. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2262. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2263. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2264. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2265. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2266. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2267. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2268. );
  2269. //Energy.Active.Export.Interval
  2270. idx_sample=2;
  2271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2272. {
  2273. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2274. {
  2275. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2276. {
  2277. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2278. }
  2279. }
  2280. for (int index = 0; index < CCS_QUANTITY; index++)
  2281. {
  2282. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2283. {
  2284. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2285. }
  2286. }
  2287. for (int index = 0; index < GB_QUANTITY; index++)
  2288. {
  2289. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2290. {
  2291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2292. }
  2293. }
  2294. }
  2295. else
  2296. {
  2297. for (int index = 0; index < AC_QUANTITY; index++)
  2298. {
  2299. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2300. {
  2301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2302. }
  2303. }
  2304. }// END FOR AC ELSE
  2305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2311. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2312. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2313. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2314. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2315. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2316. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2317. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2318. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2319. );
  2320. //Power.Active.Export
  2321. idx_sample=3;
  2322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2323. {
  2324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2325. {
  2326. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2327. {
  2328. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2329. }
  2330. }
  2331. for (int index = 0; index < CCS_QUANTITY; index++)
  2332. {
  2333. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2334. {
  2335. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2336. }
  2337. }
  2338. for (int index = 0; index < GB_QUANTITY; index++)
  2339. {
  2340. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2341. {
  2342. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2343. }
  2344. }
  2345. }
  2346. else
  2347. {
  2348. for (int index = 0; index < AC_QUANTITY; index++)
  2349. {
  2350. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2351. {
  2352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2353. }
  2354. }
  2355. }// END FOR AC ELSE
  2356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2362. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2363. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2364. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2365. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2366. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2367. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2368. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2369. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2370. );
  2371. //Voltage
  2372. idx_sample=4;
  2373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2374. {
  2375. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2376. {
  2377. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2378. {
  2379. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2380. }
  2381. }
  2382. for (int index = 0; index < CCS_QUANTITY; index++)
  2383. {
  2384. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2385. {
  2386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2387. }
  2388. }
  2389. for (int index = 0; index < GB_QUANTITY; index++)
  2390. {
  2391. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2392. {
  2393. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2394. }
  2395. }
  2396. }
  2397. else
  2398. {
  2399. for (int index = 0; index < AC_QUANTITY; index++)
  2400. {
  2401. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2402. {
  2403. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2404. }
  2405. }
  2406. }// END FOR AC ELSE
  2407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2413. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2414. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2415. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2416. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2417. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2418. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2419. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2420. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2421. );
  2422. //SoC
  2423. idx_sample=5;
  2424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2425. {
  2426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2427. {
  2428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2429. {
  2430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2431. }
  2432. }
  2433. for (int index = 0; index < CCS_QUANTITY; index++)
  2434. {
  2435. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2436. {
  2437. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2438. }
  2439. }
  2440. for (int index = 0; index < GB_QUANTITY; index++)
  2441. {
  2442. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2443. {
  2444. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2445. }
  2446. }
  2447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2453. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2454. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2455. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2456. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2457. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2458. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2459. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2460. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2461. );
  2462. } // END FOR DC CASE
  2463. sprintf(message + strlen(message)," ] } ] } ]");
  2464. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue);
  2465. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);
  2466. }
  2467. LWS_Send(message);
  2468. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2469. if(hashmap_operation(0, guid, tempdata) == 1)
  2470. {
  2471. result = PASS;
  2472. DEBUG_INFO("StopTransaction mapitem pass\n");
  2473. }
  2474. strcpy(queuedata, message);
  2475. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2476. //#ifdef SystemLogMessage
  2477. //DEBUG_INFO(">>>>>StopTransaction request\n");
  2478. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2479. //#endif
  2480. //for test
  2481. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2482. return result;
  2483. }
  2484. int sendMeterValuesRequest(int gun_index)
  2485. {
  2486. mtrace();
  2487. int result = FAIL;
  2488. char message[1500]={0};
  2489. char guid[37]={0};
  2490. int idx_sample=0;
  2491. //int length = 0;
  2492. char tempdata[65]={0};
  2493. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2494. DEBUG_ERROR("gun_index =%d\n",gun_index);
  2495. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2496. {
  2497. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2498. DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2499. DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2500. return result;
  2501. }
  2502. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2503. {
  2504. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2505. }
  2506. //set value
  2507. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2508. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2509. random_uuid(guid);
  2510. sprintf(message,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":"
  2511. ,MESSAGE_TYPE_CALL
  2512. ,guid
  2513. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2514. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId);
  2515. //,comfirmpayload);
  2516. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2517. {
  2518. //allocate memory space
  2519. //ShmOCPP16Data->MeterValues[gun_index].MeterValue = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2520. //UTC Date time
  2521. struct timeval tmnow;
  2522. struct tm *tm;
  2523. char buf[30];//, usec_buf[6];
  2524. gettimeofday(&tmnow, NULL);
  2525. time_t t;
  2526. t = time(NULL);
  2527. /*UTC time and date*/
  2528. tm = gmtime(&t);
  2529. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2530. #if 0 // remove temporally
  2531. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2532. strcat(buf,".");
  2533. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2534. strcat(buf,usec_buf);
  2535. #endif
  2536. // printf("%s",buf);
  2537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp, buf);
  2538. //allocate memory space
  2539. //ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*6);
  2540. sprintf(message + strlen(message),"[{\"timestamp\":\"%s\",\"sampledValue\":[",(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp);
  2541. idx_sample=0;
  2542. //********************************(1)Current.Export************************************************/
  2543. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2544. {
  2545. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2546. {
  2547. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2548. {
  2549. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2550. }
  2551. }
  2552. for (int index = 0; index < CCS_QUANTITY; index++)
  2553. {
  2554. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2555. {
  2556. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2557. }
  2558. }
  2559. for (int index = 0; index < GB_QUANTITY; index++)
  2560. {
  2561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2562. {
  2563. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2564. }
  2565. }
  2566. }
  2567. else
  2568. {
  2569. for (int index = 0; index < AC_QUANTITY; index++)
  2570. {
  2571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2572. {
  2573. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2574. }
  2575. }
  2576. }// END FOR AC ELSE
  2577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Current_Export]);
  2580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2583. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2584. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2585. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2586. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2587. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2588. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2589. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2590. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2591. );
  2592. #if 0
  2593. idx_sample=1;
  2594. //****************************************************(2)Energy.Active.Export.Register*********************************************/
  2595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2596. {
  2597. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2598. {
  2599. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2600. {
  2601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2602. }
  2603. }
  2604. for (int index = 0; index < CCS_QUANTITY; index++)
  2605. {
  2606. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2607. {
  2608. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2609. }
  2610. }
  2611. for (int index = 0; index < GB_QUANTITY; index++)
  2612. {
  2613. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2614. {
  2615. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2616. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2617. }
  2618. }
  2619. }
  2620. else
  2621. {
  2622. for (int index = 0; index < AC_QUANTITY; index++)
  2623. {
  2624. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2625. {
  2626. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2627. }
  2628. }
  2629. }// END FOR AC ELSE
  2630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Register]);
  2633. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2634. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2636. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2637. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2638. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2639. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2640. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2641. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2642. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2643. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2644. );
  2645. #endif
  2646. idx_sample=1;
  2647. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2648. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2649. {
  2650. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2651. {
  2652. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2653. {
  2654. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2655. }
  2656. }
  2657. for (int index = 0; index < CCS_QUANTITY; index++)
  2658. {
  2659. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2660. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2661. {
  2662. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2663. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2664. }
  2665. }
  2666. for (int index = 0; index < GB_QUANTITY; index++)
  2667. {
  2668. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2669. {
  2670. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2671. }
  2672. }
  2673. }
  2674. else
  2675. {
  2676. for (int index = 0; index < AC_QUANTITY; index++)
  2677. {
  2678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2679. {
  2680. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2681. }
  2682. }
  2683. }//END FOR AC ELSE
  2684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2687. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2688. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2689. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2690. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2691. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2692. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2693. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2694. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2695. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2696. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2697. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2698. );
  2699. idx_sample=2;
  2700. //********************************(4)Power.Active.Export************************************************/
  2701. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2702. {
  2703. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2704. {
  2705. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2706. {
  2707. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2708. }
  2709. }
  2710. for (int index = 0; index < CCS_QUANTITY; index++)
  2711. {
  2712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2713. {
  2714. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2715. }
  2716. }
  2717. for (int index = 0; index < GB_QUANTITY; index++)
  2718. {
  2719. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2720. {
  2721. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2722. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2723. }
  2724. }
  2725. }
  2726. else
  2727. {
  2728. for (int index = 0; index < AC_QUANTITY; index++)
  2729. {
  2730. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2731. {
  2732. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2733. }
  2734. }
  2735. }// END FOR AC ELSE
  2736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Power_Active_Export]);
  2739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2742. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2743. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2744. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2745. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2746. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2747. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2748. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2749. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2750. );
  2751. idx_sample=3;
  2752. //***********************************************(5)VOLTAGE******************************************************/
  2753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2754. {
  2755. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2756. {
  2757. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2758. {
  2759. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2760. }
  2761. }
  2762. for (int index = 0; index < CCS_QUANTITY; index++)
  2763. {
  2764. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2765. {
  2766. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2767. }
  2768. }
  2769. for (int index = 0; index < GB_QUANTITY; index++)
  2770. {
  2771. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2772. {
  2773. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2774. }
  2775. }
  2776. }
  2777. else
  2778. {
  2779. for (int index = 0; index < AC_QUANTITY; index++)
  2780. {
  2781. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2782. {
  2783. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2784. }
  2785. }
  2786. }//END FOR AC ELSE
  2787. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2788. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2789. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Voltage]);
  2790. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2793. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2794. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2795. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2796. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2797. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2798. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2799. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2800. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2801. );
  2802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2803. {
  2804. idx_sample=4;
  2805. //sampledValue = NULL;
  2806. //***********************************************(6)SOC******************************************************/
  2807. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2808. {
  2809. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2810. {
  2811. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2812. }
  2813. }
  2814. for (int index = 0; index < CCS_QUANTITY; index++)
  2815. {
  2816. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2817. {
  2818. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2819. }
  2820. }
  2821. for (int index = 0; index < GB_QUANTITY; index++)
  2822. {
  2823. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2824. {
  2825. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2826. }
  2827. }
  2828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2829. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2830. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[SoC]);
  2831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2834. sprintf(message + strlen(message),",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2835. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2836. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2837. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2838. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2839. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2840. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2841. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2842. );
  2843. }
  2844. //}
  2845. sprintf(message + strlen(message)," ] } ] } ]");
  2846. //free(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue);
  2847. }
  2848. LWS_Send(message);
  2849. //memset(mapItem, 0, sizeof(data_struct_t));
  2850. // Put request guid to hash map
  2851. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2852. if(hashmap_operation(0, 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*/)
  2853. {
  2854. result = PASS;
  2855. DEBUG_INFO("MeterValues mapitem pass\n");
  2856. }
  2857. strcpy(queuedata, message);
  2858. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2859. //#ifdef SystemLogMessage
  2860. //DEBUG_INFO(">>>>>MeerValues request\n");
  2861. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2862. //#endif
  2863. return result;
  2864. }
  2865. //==========================================
  2866. // send confirm routine
  2867. //==========================================
  2868. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2869. {
  2870. mtrace();
  2871. int result = FAIL;
  2872. char message[100]={0};
  2873. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2874. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2875. LWS_Send(message);
  2876. result = TRUE;
  2877. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2878. return result;
  2879. }
  2880. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2881. {
  2882. mtrace();
  2883. int result = FAIL;
  2884. char message[100]={0};
  2885. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2886. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2887. LWS_Send(message);
  2888. result = TRUE;
  2889. return result;
  2890. }
  2891. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2892. {
  2893. mtrace();
  2894. int result = FAIL;
  2895. char message[100]={0};
  2896. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2897. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2898. LWS_Send(message);
  2899. result = TRUE;
  2900. return result;
  2901. }
  2902. int sendClearCacheConfirmation(char *uuid,char *payload)
  2903. {
  2904. mtrace();
  2905. int result = FAIL;
  2906. char message[500]={0};
  2907. // int count = 0;
  2908. // int gun_index = 0;
  2909. // char guid[37];
  2910. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2911. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2912. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2913. LWS_Send(message);
  2914. return result;
  2915. }
  2916. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2917. {
  2918. mtrace();
  2919. int result = FAIL;
  2920. char message[500]={0};
  2921. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2922. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2923. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2924. LWS_Send(message);
  2925. return result;
  2926. }
  2927. int sendDataTransferConfirmation(char *uuid,char *payload)
  2928. {
  2929. mtrace();
  2930. char statusStr[20]={0};
  2931. char dataStr[10]={0};
  2932. char sstr[20]={0};
  2933. int c = 0;
  2934. char *loc;
  2935. int result = FAIL;
  2936. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2937. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2938. /**********************status**************************/
  2939. loc = strstr(payload, "status");
  2940. memset(sstr ,0, sizeof(sstr) );
  2941. c = 0;
  2942. while (loc[3+strlen("status")+c] != '\"')
  2943. {
  2944. sstr[c] = loc[3+strlen("status")+c];
  2945. c++;
  2946. }
  2947. sstr[c] = '\0';
  2948. strcpy(statusStr, sstr);
  2949. /**********************data**************************/
  2950. loc = strstr(payload, "data");
  2951. memset(sstr ,0, sizeof(sstr) );
  2952. c = 0;
  2953. while (loc[3+strlen("data")+c] != '\"')
  2954. {
  2955. sstr[c] = loc[3+strlen("data")+c];
  2956. c++;
  2957. }
  2958. sstr[c] = '\0';
  2959. strcpy(dataStr, sstr);
  2960. return result;
  2961. }
  2962. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2963. {
  2964. mtrace();
  2965. int result = FAIL;
  2966. char message[1000]={0};
  2967. double diff_f = 0.0;
  2968. int diff_i = 0;
  2969. struct tm tp;
  2970. DEBUG_ERROR("handle sendGetCompositeScheduleConfirmation ...\n");
  2971. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2972. tp.tm_isdst = -1;
  2973. time_t utc = mktime(&tp);
  2974. time_t t = time(NULL);
  2975. diff_f = difftime(t, utc);
  2976. diff_i = (int)diff_f;
  2977. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2978. #if 0 //remove temporally
  2979. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":6.0,\"numberPhases\":3},{\"startPeriod\":40,\"limit\":10.0,\"numberPhases\":3},{\"startPeriod\":100,\"limit\":8.0,\"numberPhases\":3}"
  2980. ,MESSAGE_TYPE_CALLRESULT
  2981. ,uuid
  2982. ,payload
  2983. ,connectorIdInt
  2984. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2985. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2986. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2987. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2988. #endif
  2989. if(nPeriod == 0)
  2990. {
  2991. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2992. ,MESSAGE_TYPE_CALLRESULT
  2993. ,uuid
  2994. ,payload
  2995. ,connectorIdInt
  2996. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule);
  2997. }
  2998. else
  2999. {
  3000. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3001. ,MESSAGE_TYPE_CALLRESULT
  3002. ,uuid
  3003. ,payload
  3004. ,connectorIdInt
  3005. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3006. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3007. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3008. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3009. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3010. #if 1 // remove temporally
  3011. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3012. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3013. {
  3014. if (idx_sample == 0)
  3015. {
  3016. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3017. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  3018. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3019. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3020. }
  3021. else
  3022. {
  3023. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3024. , (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diff_i /*-1*/)
  3025. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3026. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3027. }
  3028. }
  3029. #endif
  3030. sprintf(message + strlen(message), "]}}]");
  3031. }
  3032. LWS_Send(message);
  3033. result = TRUE;
  3034. return result;
  3035. }
  3036. int sendGetConfigurationConfirmation(char *uuid)
  3037. {
  3038. mtrace();
  3039. int result = FAIL;
  3040. int MaxKeySupported = 0;
  3041. int sentConfigurationNumber= 0;
  3042. int sentunConfigurationNumber= 0;
  3043. char message[4000]={0};
  3044. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3045. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3046. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3047. ,MESSAGE_TYPE_CALLRESULT
  3048. ,uuid );
  3049. //configuration key
  3050. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3051. {
  3052. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3053. {
  3054. if (sentConfigurationNumber == 0)
  3055. {
  3056. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3057. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3058. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3059. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3060. }
  3061. else
  3062. {
  3063. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3064. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3065. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3066. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3067. }
  3068. sentConfigurationNumber = sentConfigurationNumber + 1;
  3069. }
  3070. }
  3071. sprintf(message + strlen(message), "]");
  3072. if(UnknownKeynum != 0)
  3073. {
  3074. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3075. //unkown key
  3076. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3077. {
  3078. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3079. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3080. if(sentunConfigurationNumber == 0)
  3081. {
  3082. sprintf(message + strlen(message), "\"%s\""
  3083. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3084. }
  3085. else
  3086. {
  3087. sprintf(message + strlen(message), ",\"%s\""
  3088. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3089. }
  3090. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3091. }
  3092. sprintf(message + strlen(message), "]");
  3093. }
  3094. sprintf(message + strlen(message), "} ]");
  3095. LWS_Send(message);
  3096. #if 0
  3097. printf("error 1-0\n");
  3098. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3099. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3100. #endif
  3101. return result;
  3102. }
  3103. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3104. {
  3105. mtrace();
  3106. int result = FAIL;
  3107. char message[400]={0};
  3108. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3109. if(strcmp(payload,"")==0)
  3110. {
  3111. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3112. }
  3113. else
  3114. {
  3115. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3116. }
  3117. LWS_Send(message);
  3118. result = TRUE;
  3119. return result;
  3120. }
  3121. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3122. {
  3123. mtrace();
  3124. int result = FAIL;
  3125. char message[80]={0};
  3126. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3127. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3128. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3129. LWS_Send(message);
  3130. result = TRUE;
  3131. return result;
  3132. }
  3133. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3134. {
  3135. mtrace();
  3136. int result = FAIL;
  3137. char message[80]={0};
  3138. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3139. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3140. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3141. LWS_Send(message);
  3142. result = TRUE;
  3143. return result;
  3144. }
  3145. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3146. {
  3147. mtrace();
  3148. int result = FAIL;
  3149. char message[80]={0};
  3150. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3151. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3152. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3153. LWS_Send(message);
  3154. result = TRUE;
  3155. return result;
  3156. }
  3157. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3158. {
  3159. mtrace();
  3160. int result = FAIL;
  3161. char message[80]={0};
  3162. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3163. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3164. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3165. LWS_Send(message);
  3166. result = TRUE;
  3167. return result;
  3168. }
  3169. int sendResetConfirmation(char *uuid,char *payload)
  3170. {
  3171. mtrace();
  3172. int result = FAIL;
  3173. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3174. char message[80]={0};
  3175. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3176. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3177. LWS_Send(message);
  3178. result = TRUE;
  3179. return result;
  3180. }
  3181. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3182. {
  3183. mtrace();
  3184. int result = FAIL;
  3185. char message[500]={0};
  3186. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3187. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3188. LWS_Send(message);
  3189. result = TRUE;
  3190. return result;
  3191. }
  3192. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3193. {
  3194. mtrace();
  3195. int result = FAIL;
  3196. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3197. char message[80]={0};
  3198. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3199. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3200. LWS_Send(message);
  3201. result = TRUE;
  3202. return result;
  3203. }
  3204. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3205. {
  3206. mtrace();
  3207. int result = FAIL;
  3208. char message[80]={0};
  3209. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3210. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3211. LWS_Send(message);
  3212. result = TRUE;
  3213. return result;
  3214. }
  3215. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3216. {
  3217. mtrace();
  3218. int result = FAIL;
  3219. char message[80]={0};
  3220. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3221. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3222. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3223. LWS_Send(message);
  3224. result = TRUE;
  3225. return result;
  3226. }
  3227. int sendUpdateFirmwareConfirmation(char *uuid)
  3228. {
  3229. mtrace();
  3230. int result = FAIL;
  3231. char message[60]={0};
  3232. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3233. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3234. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3235. LWS_Send(message);
  3236. result = TRUE;
  3237. return result;
  3238. }
  3239. //==========================================
  3240. // send CallError routine
  3241. //==========================================
  3242. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3243. {
  3244. mtrace();
  3245. //int result = FAIL;
  3246. char message[220]={0};
  3247. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3248. #ifdef SystemLogMessage
  3249. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3250. uniqueId, action, errorCode, errorDescription);
  3251. #endif
  3252. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3253. LWS_Send(message);
  3254. //result = TRUE;
  3255. }
  3256. //==========================================
  3257. // Handle server request routine Start
  3258. //==========================================
  3259. #define GUN_NUM 1
  3260. int handleCancelReservationRequest(char *uuid, char *payload)
  3261. {
  3262. mtrace();
  3263. int result = FAIL;
  3264. int gunNO = 0;
  3265. int reservationIdInt =0;
  3266. char comfirmstr[20];
  3267. int c = 0;
  3268. char *loc;
  3269. char sstr[100]={0};
  3270. DEBUG_INFO("handle CancelReservationRequest\n");
  3271. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3272. c = 0;
  3273. loc = strstr(payload, "reservationId");
  3274. memset(sstr ,0, sizeof(sstr) );
  3275. while (loc[strlen("reservationId")+2+c] != '}')
  3276. {
  3277. sstr[c] = loc[strlen("reservationId")+2+c];
  3278. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3279. c++;
  3280. }
  3281. sstr[c] = '\0';
  3282. reservationIdInt = atoi(sstr);
  3283. memset(comfirmstr, 0, sizeof comfirmstr);
  3284. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3285. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3286. //check Transaction active
  3287. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3288. {
  3289. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3290. {
  3291. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3292. {
  3293. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3294. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3295. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3296. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3297. goto end;
  3298. }
  3299. }
  3300. for (int index = 0; index < CCS_QUANTITY; index++)
  3301. {
  3302. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3303. {
  3304. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3305. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3306. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3307. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3308. goto end;
  3309. }
  3310. }
  3311. for (int index = 0; index < GB_QUANTITY; index++)
  3312. {
  3313. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3314. {
  3315. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3316. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3317. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3318. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3319. goto end;
  3320. }
  3321. }
  3322. }
  3323. else
  3324. {
  3325. for (int index = 0; index < AC_QUANTITY; index++)
  3326. {
  3327. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3328. {
  3329. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3330. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3331. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3332. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3333. goto end;
  3334. }
  3335. }
  3336. }// END FOR AC ELSE
  3337. //The reservationId does NOT match the reservationId
  3338. sendCancelReservationConfirmation(uuid, comfirmstr);
  3339. end:
  3340. // Fill in ocpp packet uuid
  3341. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3342. return result;
  3343. }
  3344. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3345. {
  3346. mtrace();
  3347. int result = FAIL;
  3348. int gunIndex = 0;
  3349. char sstr[90]={0};
  3350. char typeStr[16]={0};
  3351. char comfirmstr[20];
  3352. int specificId = FALSE;
  3353. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3354. char *loc;
  3355. //int intervalInt = 0;
  3356. int c = 0;
  3357. /*** connectorId ****/
  3358. c = 0;
  3359. loc = strstr(payload, "connectorId");
  3360. memset(sstr ,0, sizeof(sstr) );
  3361. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3362. {
  3363. sstr[c] = loc[strlen("connectorId")+2+c];
  3364. c++;
  3365. }
  3366. sstr[c] = '\0';
  3367. gunIndex = atoi(sstr);
  3368. /***type ****/
  3369. loc = strstr(payload, "type");
  3370. memset(sstr ,0, sizeof(sstr) );
  3371. c = 0;
  3372. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3373. {
  3374. sstr[c] = loc[3+strlen("type")+c];
  3375. c++;
  3376. }
  3377. sstr[c] = '\0';
  3378. strcpy(typeStr, sstr);
  3379. if(gunIndex != 0)
  3380. {
  3381. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3382. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3383. }
  3384. else
  3385. {
  3386. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3387. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3388. }
  3389. memset(comfirmstr, 0, sizeof comfirmstr);
  3390. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3391. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3392. {
  3393. specificId = TRUE;
  3394. }
  3395. if(specificId == FALSE)
  3396. goto end;
  3397. if(gunIndex != 0)
  3398. {
  3399. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3400. }
  3401. else
  3402. {
  3403. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3404. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3405. }
  3406. /*
  3407. enum _SYSTEM_STATUS
  3408. {
  3409. S_BOOTING = 0,
  3410. S_IDLE, = 1
  3411. S_AUTHORIZING, =2
  3412. S_REASSIGN_CHECK, =3
  3413. S_REASSIGN, =4
  3414. S_PRECHARGE, =5
  3415. S_PREPARING_FOR_EV, =6
  3416. S_PREPARING_FOR_EVSE, =7
  3417. S_CHARGING, =8
  3418. S_TERMINATING, =9
  3419. S_COMPLETE, =10
  3420. S_ALARM, =11
  3421. S_FAULT =12
  3422. }
  3423. */
  3424. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3425. {
  3426. //check Transaction active
  3427. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3428. {
  3429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3430. {
  3431. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3432. {
  3433. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3434. {
  3435. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3436. }
  3437. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3438. {
  3439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3440. }
  3441. else
  3442. {
  3443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3444. }
  3445. goto end;
  3446. }
  3447. }//END FOR CHAdeMO_QUANTITY
  3448. for (int index = 0; index < CCS_QUANTITY; index++)
  3449. {
  3450. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3451. {
  3452. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3453. {
  3454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3455. }
  3456. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3457. {
  3458. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3459. }
  3460. else
  3461. {
  3462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3463. }
  3464. goto end;
  3465. }
  3466. }//END FOR CCS_QUANTITY
  3467. for (int index = 0; index < GB_QUANTITY; index++)
  3468. {
  3469. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3470. {
  3471. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3472. {
  3473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3474. }
  3475. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3476. {
  3477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3478. }
  3479. else
  3480. {
  3481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3482. }
  3483. goto end;
  3484. }
  3485. }// END FOR GB_QUANTITY
  3486. }
  3487. else
  3488. {
  3489. for (int index = 0; index < AC_QUANTITY; index++)
  3490. {
  3491. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3492. {
  3493. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3494. {
  3495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3496. }
  3497. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3498. {
  3499. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3500. }
  3501. else
  3502. {
  3503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3504. }
  3505. goto end;
  3506. }
  3507. }//END FOR AC_QUANTITY
  3508. }// END FOR AC ELSE
  3509. }//END FOR AvailabilityTypeStr[Inoperative]
  3510. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3511. {
  3512. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3513. //check Transaction active
  3514. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3515. {
  3516. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3517. {
  3518. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3519. {
  3520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3521. goto end;
  3522. }
  3523. }//END FOR CHAdeMO_QUANTITY
  3524. for (int index = 0; index < CCS_QUANTITY; index++)
  3525. {
  3526. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3527. {
  3528. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3529. goto end;
  3530. }
  3531. }//END FOR CCS_QUANTITY
  3532. for (int index = 0; index < GB_QUANTITY; index++)
  3533. {
  3534. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3535. {
  3536. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3537. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3538. goto end;
  3539. }
  3540. }// END FOR GB_QUANTITY
  3541. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3542. }
  3543. else
  3544. {
  3545. for (int index = 0; index < AC_QUANTITY; index++)
  3546. {
  3547. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3548. {
  3549. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3550. goto end;
  3551. }
  3552. }//END FOR CHAdeMO_QUANTITY
  3553. }//END FOR AC ELSE
  3554. }//END FOR AvailabilityTypeStr[Operative]
  3555. end:
  3556. if(gunIndex != 0)
  3557. {
  3558. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3559. }
  3560. else
  3561. {
  3562. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3563. }
  3564. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3565. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3566. return result;
  3567. }
  3568. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3569. {
  3570. mtrace();
  3571. int result = FAIL;
  3572. char sstr[100]={0};
  3573. char keystr[40]={0};
  3574. char valuestr[16]={0};
  3575. char *loc;
  3576. int c = 0;
  3577. char comfirmstr[20];
  3578. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3579. /***key ****/
  3580. loc = strstr(payload, "key");
  3581. memset(sstr ,0, sizeof(sstr) );
  3582. c = 0;
  3583. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3584. {
  3585. sstr[c] = loc[3+strlen("key")+c];
  3586. c++;
  3587. }
  3588. sstr[c] = '\0';
  3589. strcpy(keystr, sstr);
  3590. /***value ****/
  3591. loc = strstr(payload, "value");
  3592. memset(sstr ,0, sizeof(sstr) );
  3593. c = 0;
  3594. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3595. {
  3596. sstr[c] = loc[3+strlen("value")+c];
  3597. c++;
  3598. }
  3599. sstr[c] = '\0';
  3600. strcpy(valuestr, sstr);
  3601. if((uuid==NULL) || (payload ==NULL) )
  3602. {
  3603. #ifdef Debug
  3604. DEBUG_INFO("payload is null\n");
  3605. #endif
  3606. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3607. }
  3608. else
  3609. {
  3610. int status = setKeyValue(keystr, valuestr);
  3611. switch(status)
  3612. {
  3613. case ConfigurationStatus_Accepted:
  3614. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3615. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3616. break;
  3617. case ConfigurationStatus_Rejected:
  3618. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3619. break;
  3620. case RebootRequired:
  3621. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3622. break;
  3623. case NotSupported:
  3624. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3625. break;
  3626. default:
  3627. break;
  3628. }
  3629. }
  3630. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3631. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3632. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3633. return result;
  3634. }
  3635. int handleClearCacheRequest(char *uuid, char *payload)
  3636. {
  3637. mtrace();
  3638. int result = FAIL;
  3639. char comfirmstr[20];
  3640. int fd;
  3641. char rmFileCmd[100]={0};
  3642. struct stat stats;
  3643. DEBUG_ERROR("handle ClearCacheRequest\n");
  3644. stat("../Storage/OCPP", &stats);
  3645. // Check for directory existence
  3646. if (S_ISDIR(stats.st_mode) == 1)
  3647. {
  3648. //DEBUG_ERROR("\n OCPP directory exist \n");
  3649. }
  3650. else
  3651. {
  3652. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3653. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3654. system(rmFileCmd);
  3655. }
  3656. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  3657. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3658. {
  3659. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3660. }
  3661. else
  3662. {
  3663. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3664. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3665. if(log == NULL)
  3666. {
  3667. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3668. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3669. goto end;
  3670. }
  3671. else
  3672. {
  3673. fclose(log);
  3674. }
  3675. }
  3676. fd = open(AuthorizationCache_JSON,O_RDWR);
  3677. if(fd < 0)
  3678. {
  3679. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3680. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3681. }
  3682. else
  3683. {
  3684. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3685. //* 清空?�件 */
  3686. ftruncate(fd,0);
  3687. //* ?�新设置?�件?�移??*/
  3688. lseek(fd,0,SEEK_SET);
  3689. close(fd);
  3690. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3691. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3692. }
  3693. end:
  3694. sendClearCacheConfirmation(uuid, comfirmstr);
  3695. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3696. return result;
  3697. }
  3698. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3699. {
  3700. mtrace();
  3701. int result = FAIL;
  3702. int resultRename;
  3703. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3704. char chargingProfilePurposeStr[26]={0};
  3705. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3706. char tempchargingProfilePurposeStr[26]={0};
  3707. char sstr[160]={0};//sstr[200]={ 0 };
  3708. char str[100]={0};
  3709. int c = 0;
  3710. //int i = 0;
  3711. //char * pch;
  3712. char *loc;
  3713. char fname[200];
  3714. char comfirmstr[20]={0};
  3715. char word[1000]={0};
  3716. int clearflag = FALSE;
  3717. int chargingProfileIdIsNULL = FALSE;
  3718. int connectorIsNULL = FALSE;
  3719. int chargingProfilePurposeIsNULL = FALSE;
  3720. int stackLevelIsNULL = FALSE;
  3721. FILE *fptr1, *fptr2;
  3722. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3723. int n_chargingProfile=0;
  3724. char sLineWord[1060]={0};
  3725. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3726. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3727. //***id ****/
  3728. c = 0;
  3729. loc = strstr(payload, "id");
  3730. memset(sstr ,0, sizeof(sstr) );
  3731. if(loc == NULL)
  3732. {
  3733. chargingProfileIdIsNULL = TRUE;
  3734. }
  3735. else
  3736. {
  3737. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3738. {
  3739. sstr[c] = loc[strlen("id")+2+c];
  3740. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3741. c++;
  3742. }
  3743. sstr[c] = '\0';
  3744. chargingProfileIdInt = atoi(sstr);
  3745. }
  3746. //***connectorId ****/
  3747. c=0;
  3748. loc = strstr(payload, "connectorId");
  3749. memset(sstr ,0, sizeof(sstr) );
  3750. if(loc == NULL)
  3751. {
  3752. connectorIsNULL = TRUE;
  3753. }
  3754. else
  3755. {
  3756. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3757. {
  3758. sstr[c] = loc[strlen("connectorId")+2+c];
  3759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3760. c++;
  3761. }
  3762. sstr[c] = '\0';
  3763. connectorIdInt = atoi(sstr);
  3764. }
  3765. //***chargingProfilePurpose ****/
  3766. loc = strstr(payload, "chargingProfilePurpose");
  3767. memset(sstr ,0, sizeof(sstr) );
  3768. c = 0;
  3769. if(loc == NULL)
  3770. {
  3771. chargingProfilePurposeIsNULL = TRUE;
  3772. }
  3773. else
  3774. {
  3775. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3776. {
  3777. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3778. c++;
  3779. }
  3780. sstr[c] = '\0';
  3781. strcpy(chargingProfilePurposeStr, sstr);
  3782. }
  3783. //***stackLevel ****/
  3784. c=0;
  3785. loc = strstr(payload, "stackLevel");
  3786. memset(sstr ,0, sizeof(sstr) );
  3787. if(loc == NULL)
  3788. {
  3789. stackLevelIsNULL = TRUE;
  3790. }
  3791. else
  3792. {
  3793. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3794. {
  3795. sstr[c] = loc[strlen("stackLevel")+2+c];
  3796. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3797. c++;
  3798. }
  3799. sstr[c] = '\0';
  3800. stackLevelInt = atoi(sstr);
  3801. }
  3802. if(connectorIsNULL == FALSE)
  3803. {
  3804. switch(connectorIdInt)
  3805. {
  3806. case 0:
  3807. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3808. {
  3809. strcpy(fname, ChargePointMaxProfile_JSON);
  3810. }
  3811. // else
  3812. // {
  3813. // strcpy(fname, TxDefaultProfile_0_JSON);
  3814. // }
  3815. break;
  3816. case 1:
  3817. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3818. {
  3819. strcpy(fname, TxDefaultProfile_1_JSON);
  3820. }
  3821. // else
  3822. // {
  3823. // strcpy(fname, TxProfile_1_JSON);
  3824. // }
  3825. break;
  3826. case 2:
  3827. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3828. {
  3829. strcpy(fname, TxDefaultProfile_2_JSON);
  3830. }
  3831. // else
  3832. // {
  3833. // strcpy(fname, TxProfile_2_JSON);
  3834. // }
  3835. break;
  3836. default:
  3837. strcpy(fname, ChargePointMaxProfile_JSON );
  3838. break;
  3839. }
  3840. }
  3841. else
  3842. {
  3843. strcpy(fname, ChargePointMaxProfile_JSON );
  3844. }
  3845. fptr1 = fopen(fname, "r");
  3846. if (!fptr1)
  3847. {
  3848. //file not exist
  3849. DEBUG_ERROR("Unable to open the input file!!\n");
  3850. fptr1 = fopen(fname, "w+");
  3851. }
  3852. fclose(fptr1);
  3853. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3854. {
  3855. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3856. goto end;
  3857. }
  3858. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3859. {
  3860. //clear the whole contents of a file in C
  3861. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3862. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3863. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3864. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3865. fclose(fopen(TxProfile_1_JSON, "w"));
  3866. fclose(fopen(TxProfile_2_JSON, "w"));
  3867. #if 0
  3868. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3869. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3870. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3871. #endif
  3872. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3873. }
  3874. else
  3875. {
  3876. fptr1 = fopen(fname, "r");
  3877. fptr2 = fopen(temp, "w+");
  3878. while(fscanf(fptr1, "%s", word) != EOF)
  3879. {
  3880. //DEBUG_INFO("word=%s\n",word);
  3881. if(strcmp(word, "chargingProfileId") == 0)
  3882. {
  3883. n_chargingProfile = n_chargingProfile + 1;
  3884. DEBUG_INFO("chargingProfileId Found\n");
  3885. }
  3886. }
  3887. rewind(fptr1);
  3888. //search Charging Profile Element
  3889. //int i= 0;
  3890. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3891. {
  3892. //*************************tempconnectorIdInt*********************************/
  3893. loc = strstr(sLineWord, "connectorId");
  3894. c = 0;
  3895. memset(sstr ,0, sizeof(sstr) );
  3896. while (loc[strlen("connectorId")+2+c] != ',')
  3897. {
  3898. sstr[c] = loc[strlen("connectorId")+2+c];
  3899. c++;
  3900. }
  3901. sstr[c] = '\0';
  3902. tempconnectorIdInt = atoi(sstr);
  3903. //chargingProfileId
  3904. c = 0;
  3905. loc = strstr(sLineWord, "chargingProfileId");
  3906. memset(sstr ,0, sizeof(sstr) );
  3907. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3908. {
  3909. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3910. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3911. c++;
  3912. }
  3913. sstr[c] = '\0';
  3914. tempchargingProfileIdInt = atoi(sstr);
  3915. //stackLevel
  3916. c = 0;
  3917. loc = strstr(sLineWord, "stackLevel");
  3918. memset(sstr ,0, sizeof(sstr) );
  3919. while (loc[strlen("stackLevel")+2+c] != ',')
  3920. {
  3921. sstr[c] = loc[strlen("stackLevel")+2+c];
  3922. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3923. c++;
  3924. }
  3925. sstr[c] = '\0';
  3926. tempstackLevelInt = atoi(sstr);
  3927. c = 0;
  3928. loc = strstr(sLineWord, "chargingProfilePurpose");
  3929. memset(sstr ,0, sizeof(sstr) );
  3930. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3931. {
  3932. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3933. c++;
  3934. }
  3935. sstr[c] = '\0';
  3936. strcpy(tempchargingProfilePurposeStr, sstr);
  3937. if(chargingProfileIdIsNULL == FALSE)
  3938. {
  3939. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3940. {
  3941. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3942. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3943. clearflag = TRUE;
  3944. continue;
  3945. }
  3946. else
  3947. {
  3948. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3949. //json_object_array_add(newHeatMap, jsonitem);
  3950. fprintf(fptr2, sLineWord);//writing data into file
  3951. }
  3952. }
  3953. else
  3954. {
  3955. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3956. {
  3957. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3958. {
  3959. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3960. clearflag = TRUE;
  3961. continue;
  3962. }
  3963. }
  3964. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3965. {
  3966. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3967. {
  3968. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3969. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3970. {
  3971. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3972. clearflag = TRUE;
  3973. continue;
  3974. }
  3975. }
  3976. }
  3977. else
  3978. {
  3979. //json_object_array_add(newHeatMap, jsonitem);
  3980. fprintf(fptr2, sLineWord);//writing data into file
  3981. }
  3982. }
  3983. memset(sLineWord, 0, sizeof sLineWord);
  3984. }
  3985. if(clearflag == FALSE)
  3986. {
  3987. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3988. goto end;
  3989. }
  3990. fclose(fptr1);
  3991. fclose(fptr2);
  3992. sprintf(str,"rm -f %s",fname);
  3993. system(str);
  3994. resultRename = rename(temp, fname);
  3995. if(resultRename == 0)
  3996. {
  3997. DEBUG_ERROR("File ChargingProfile renamed successfully");
  3998. }
  3999. else
  4000. {
  4001. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4002. }
  4003. }
  4004. end:
  4005. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4006. return result;
  4007. }
  4008. int handleDataTransferRequest(char *uuid, char *payload)
  4009. {
  4010. mtrace();
  4011. int result = FAIL;
  4012. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4013. char tempvendorId[255]={0};
  4014. char tempmessageId[50]={0};
  4015. char tempdata[50]={0};
  4016. char sstr[160]={0};//sstr[200]={ 0 };
  4017. char message[80]={0};
  4018. int c = 0;
  4019. char *loc;
  4020. DEBUG_INFO("handle DataTransferRequest\n");
  4021. if((uuid != NULL) && (payload != NULL))
  4022. {
  4023. //===============================
  4024. // vendorId
  4025. //===============================
  4026. c = 0;
  4027. loc = strstr(payload, "vendorId");
  4028. while (loc[strlen("vendorId")+3+c] != '\"')
  4029. {
  4030. sstr[c] = loc[strlen("vendorId")+3+c];
  4031. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4032. c++;
  4033. }
  4034. sstr[c] = '\0';
  4035. strcpy(tempvendorId,sstr);
  4036. //===============================
  4037. // messageId
  4038. //===============================
  4039. memset(sstr ,0, sizeof(sstr) );
  4040. c = 0;
  4041. loc = strstr(payload, "messageId");
  4042. while (loc[strlen("messageId")+3+c] != '\"')
  4043. {
  4044. sstr[c] = loc[strlen("messageId")+3+c];
  4045. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4046. c++;
  4047. }
  4048. sstr[c] = '\0';
  4049. strcpy(tempmessageId,sstr);
  4050. //===============================
  4051. // data
  4052. //===============================
  4053. memset(sstr ,0, sizeof(sstr) );
  4054. c = 0;
  4055. loc = strstr(payload, "data");
  4056. printf("loc=%s\n",loc);
  4057. while (loc[strlen("data")+3+c] != '\"')
  4058. {
  4059. sstr[c] = loc[strlen("data")+3+c];
  4060. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4061. c++;
  4062. }
  4063. sstr[c] = '\0';
  4064. strcpy(tempdata,sstr);
  4065. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4066. }
  4067. else
  4068. {
  4069. char guid[37]={0};
  4070. random_uuid(guid);
  4071. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4072. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4073. }
  4074. LWS_Send(message);
  4075. return result;
  4076. }
  4077. #if 0
  4078. long long diff_tm(struct tm *a, struct tm *b) {
  4079. return a->tm_sec - b->tm_sec
  4080. + 60LL * (a->tm_min - b->tm_min)
  4081. + 3600LL * (a->tm_hour - b->tm_hour)
  4082. + 86400LL * (a->tm_yday - b->tm_yday)
  4083. + (a->tm_year - 70) * 31536000LL
  4084. - (a->tm_year - 69) / 4 * 86400LL
  4085. + (a->tm_year - 1) / 100 * 86400LL
  4086. - (a->tm_year + 299) / 400 * 86400LL
  4087. - (b->tm_year - 70) * 31536000LL
  4088. + (b->tm_year - 69) / 4 * 86400LL
  4089. - (b->tm_year - 1) / 100 * 86400LL
  4090. + (b->tm_year + 299) /400 * 86400LL;
  4091. }
  4092. #endif
  4093. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4094. {
  4095. mtrace();
  4096. int result = FAIL;
  4097. int connectorIdInt, durationInt;
  4098. char chargingRateUnitStr[4]={0};
  4099. //int tempconnectorIdInt,
  4100. int tempdurationInt;
  4101. float tempminChargingRateFloat = 0.0;
  4102. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4103. int tempStartPeriodInt=0;
  4104. float tempLimitInt=0.0;//0.1;
  4105. int tempNumberPhasesInt=0;
  4106. char fname[200];
  4107. char comfirmstr[20];
  4108. //float totallimit =0.0;
  4109. float MinChargingRate =0.0;
  4110. double diff_t;
  4111. struct tm tp;
  4112. //int clearflag = FALSE;
  4113. FILE *fptr1;//, *fptr2;
  4114. //char temp[] = "../Storage/OCPP/temp.json";
  4115. int c = 0;
  4116. //int i = 0;
  4117. char * pch;
  4118. char *loc;
  4119. char sstr[200]={ 0 };
  4120. int n_chargingProfile = 0;
  4121. int n_SchedulePeriods = 0;
  4122. char SchedulePeriodList[10][200]={0};
  4123. char sLineWord[800]={0};
  4124. //int n_periods = 0;
  4125. char word[1000]={0};
  4126. int confirmPeriods = 0;
  4127. struct StructProfile ChargePointMaxProfile;
  4128. struct StructProfile TxDefaultProfile;
  4129. struct StructProfile TxProfile;
  4130. struct StructProfile TxDefaultProfiletemp[2]={0};
  4131. int TxDefaultProfileFileIsNull=FALSE;
  4132. int ChargePointMaxProfileIsNull=FALSE;
  4133. int TxProfileIsNull=FALSE;
  4134. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4135. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4136. memset(&TxProfile,0,sizeof(struct StructProfile));
  4137. c=0;
  4138. loc = strstr(payload, "connectorId");
  4139. memset(sstr ,0, sizeof(sstr) );
  4140. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4141. {
  4142. sstr[c] = loc[strlen("connectorId")+2+c];
  4143. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4144. c++;
  4145. }
  4146. sstr[c] = '\0';
  4147. connectorIdInt = atoi(sstr);
  4148. c=0;
  4149. loc = strstr(payload, "duration");
  4150. memset(sstr ,0, sizeof(sstr) );
  4151. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4152. {
  4153. sstr[c] = loc[strlen("duration")+2+c];
  4154. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4155. c++;
  4156. }
  4157. sstr[c] = '\0';
  4158. durationInt = atoi(sstr);
  4159. c = 0;
  4160. loc = strstr(payload, "chargingRateUnit");
  4161. memset(sstr ,0, sizeof(sstr) );
  4162. if(loc == NULL)
  4163. {
  4164. }
  4165. else
  4166. {
  4167. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4168. {
  4169. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4170. c++;
  4171. }
  4172. sstr[c] = '\0';
  4173. strcpy(chargingRateUnitStr, sstr);
  4174. }
  4175. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4176. if(connectorIdInt==0) // connectorId is 0
  4177. {
  4178. //******************************ChargePointMaxProfile*****************************************************/
  4179. strcpy(fname, ChargePointMaxProfile_JSON );
  4180. char word[30]={0};
  4181. char sLineWord[1060]={0};
  4182. int n_chargingProfile=0;
  4183. ChargePointMaxProfileIsNull=TRUE;
  4184. if((access(fname,F_OK))!=-1)
  4185. {
  4186. fptr1 = fopen(fname, "r");
  4187. int c;
  4188. c = fgetc(fptr1);
  4189. //DEBUG_INFO("c:%d\n",c);
  4190. rewind(fptr1);
  4191. if(c == EOF)
  4192. {
  4193. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4194. ChargePointMaxProfileIsNull=TRUE;
  4195. fclose(fptr1);
  4196. }
  4197. else
  4198. {
  4199. ChargePointMaxProfileIsNull=FALSE;
  4200. while(fscanf(fptr1, "%s", word) != EOF)
  4201. {
  4202. if(strcmp(word, "chargingProfileId") == 0)
  4203. {
  4204. n_chargingProfile = n_chargingProfile + 1;
  4205. printf("Found\n");
  4206. }
  4207. }
  4208. rewind(fptr1);
  4209. //search Charging Profile Element
  4210. int i= 0;
  4211. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4212. #if 0
  4213. /***********connectorId****************/
  4214. c = 0;
  4215. loc = strstr(sLineWord, "connectorId");
  4216. // printf("loc=%s\n",loc);
  4217. memset(sstr ,0, sizeof(sstr) );
  4218. while (loc[strlen("connectorId")+2+c] != ',')
  4219. {
  4220. sstr[c] = loc[strlen("connectorId")+2+c];
  4221. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4222. c++;
  4223. }
  4224. sstr[c] = '\0';
  4225. tempconnectorIdInt = atoi(sstr);
  4226. #endif
  4227. //***********validFrom**************/
  4228. c = 0;
  4229. loc = strstr(sLineWord, "validFrom");
  4230. //DEBUG_INFO("loc=%s\n",loc);
  4231. memset(sstr ,0, sizeof(sstr) );
  4232. if(loc != NULL)
  4233. {
  4234. while (loc[3+strlen("validFrom")+c] != '\"')
  4235. {
  4236. sstr[c] = loc[3+strlen("validFrom")+c];
  4237. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4238. c++;
  4239. }
  4240. sstr[c] = '\0';
  4241. DEBUG_INFO("validFrom=%s\n",sstr);
  4242. strcpy(tempvalidFromStr,sstr);
  4243. }
  4244. else
  4245. {
  4246. strcpy(tempvalidFromStr,"");
  4247. }
  4248. //**********startSchedule**********/
  4249. c = 0;
  4250. loc = strstr(sLineWord, "startSchedule");
  4251. //DEBUG_INFO("loc=%s\n",loc);
  4252. memset(sstr ,0, sizeof(sstr) );
  4253. while (loc[3+strlen("startSchedule")+c] != '\"')
  4254. {
  4255. sstr[c] = loc[3+strlen("startSchedule")+c];
  4256. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4257. c++;
  4258. }
  4259. sstr[c] = '\0';
  4260. strcpy(tempstartScheduleStr, sstr);
  4261. //**********startSchedule**********/
  4262. c = 0;
  4263. loc = strstr(sLineWord, "chargingRateUnit");
  4264. memset(sstr ,0, sizeof(sstr) );
  4265. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4266. {
  4267. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4268. c++;
  4269. }
  4270. sstr[c] = '\0';
  4271. strcpy(tempchargingRateUnitStr, sstr);
  4272. //**********minChargingRate*******/
  4273. c = 0;
  4274. loc = strstr(sLineWord, "minChargingRate");
  4275. //printf("loc=%s\n",loc);
  4276. if(loc != NULL)
  4277. {
  4278. memset(sstr ,0, sizeof(sstr) );
  4279. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4280. {
  4281. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4282. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4283. c++;
  4284. }
  4285. sstr[c] = '\0';
  4286. tempminChargingRateFloat = atof(sstr);
  4287. }
  4288. else
  4289. {
  4290. tempminChargingRateFloat = 0.0;
  4291. }
  4292. //
  4293. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4294. tp.tm_isdst = -1;
  4295. time_t utc = mktime(&tp);
  4296. // current time
  4297. time_t t = time(NULL);
  4298. diff_t = difftime(t, utc);
  4299. //parsing strings to words
  4300. i = 0;
  4301. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4302. loc = loc+3+strlen("chargingSchedulePeriod");
  4303. pch = strtok(loc ,"{");
  4304. while (pch != NULL)
  4305. {
  4306. strcpy(SchedulePeriodList[i], pch);
  4307. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4308. //printf ("%s\n",pch);
  4309. pch = strtok (NULL, "{");
  4310. i = i + 1;
  4311. }
  4312. n_SchedulePeriods = i;
  4313. for(int i=0;i<n_SchedulePeriods;i++)
  4314. {
  4315. //*************startPeriod****************/
  4316. c = 0;
  4317. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4318. memset(sstr ,0, sizeof(sstr) );
  4319. while (loc[strlen("startPeriod")+2+c] != ',')
  4320. {
  4321. sstr[c] = loc[strlen("startPeriod")+2+c];
  4322. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4323. c++;
  4324. }
  4325. sstr[c] = '\0';
  4326. tempStartPeriodInt = atoi(sstr);
  4327. //*************limit****************/
  4328. c = 0;
  4329. loc = strstr(SchedulePeriodList[i], "limit");
  4330. memset(sstr ,0, sizeof(sstr) );
  4331. while (loc[strlen("limit")+2+c] != ',')
  4332. {
  4333. sstr[c] = loc[strlen("limit")+2+c];
  4334. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4335. c++;
  4336. }
  4337. sstr[c] = '\0';
  4338. tempLimitInt = atof(sstr);
  4339. //*************numberPhases****************/
  4340. c = 0;
  4341. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4342. memset(sstr ,0, sizeof(sstr) );
  4343. while (loc[strlen("numberPhases")+2+c] != ',')
  4344. {
  4345. sstr[c] = loc[strlen("numberPhases")+2+c];
  4346. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4347. c++;
  4348. }
  4349. sstr[c] = '\0';
  4350. tempNumberPhasesInt = atoi(sstr);
  4351. ChargePointMaxProfile.Duration = durationInt;
  4352. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4353. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4354. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4355. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4356. }
  4357. if(MinChargingRate < tempminChargingRateFloat)
  4358. MinChargingRate = tempminChargingRateFloat;
  4359. }
  4360. }// End of file ChargingProfile
  4361. } //THE END OF ACCESS ChargePointMaxProfile
  4362. //******************************TxDefaultProfile***********************************************/
  4363. strcpy(fname, TxDefaultProfile_0_JSON);
  4364. memset(word, 0, 30);
  4365. memset(sLineWord, 0, 1060);
  4366. //char word[30]={0};
  4367. //char sLineWord[1060]={0};
  4368. n_chargingProfile=0;
  4369. TxDefaultProfileFileIsNull=TRUE;
  4370. if((access(fname,F_OK))!=-1)
  4371. {
  4372. fptr1 = fopen(fname, "r");
  4373. c = 0;
  4374. c = fgetc(fptr1);
  4375. //DEBUG_INFO("c:%d\n",c);
  4376. rewind(fptr1);
  4377. if(c == EOF)
  4378. {
  4379. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4380. TxDefaultProfileFileIsNull=TRUE;
  4381. fclose(fptr1);
  4382. }
  4383. else
  4384. {
  4385. TxDefaultProfileFileIsNull=FALSE;
  4386. while(fscanf(fptr1, "%s", word) != EOF)
  4387. {
  4388. if(strcmp(word, "chargingProfileId") == 0)
  4389. {
  4390. n_chargingProfile = n_chargingProfile + 1;
  4391. printf("Found\n");
  4392. }
  4393. }
  4394. rewind(fptr1);
  4395. //search Charging Profile Element
  4396. int i= 0;
  4397. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4398. #if 0
  4399. /***********connectorId****************/
  4400. c = 0;
  4401. loc = strstr(sLineWord, "connectorId");
  4402. // printf("loc=%s\n",loc);
  4403. memset(sstr ,0, sizeof(sstr) );
  4404. while (loc[strlen("connectorId")+2+c] != ',')
  4405. {
  4406. sstr[c] = loc[strlen("connectorId")+2+c];
  4407. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4408. c++;
  4409. }
  4410. sstr[c] = '\0';
  4411. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4412. tempconnectorIdInt = atoi(sstr);
  4413. #endif
  4414. //***********validFrom**************/
  4415. c = 0;
  4416. loc = strstr(sLineWord, "validFrom");
  4417. //DEBUG_INFO("loc=%s\n",loc);
  4418. memset(sstr ,0, sizeof(sstr) );
  4419. if(loc != NULL)
  4420. {
  4421. while (loc[3+strlen("validFrom")+c] != '\"')
  4422. {
  4423. sstr[c] = loc[3+strlen("validFrom")+c];
  4424. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4425. c++;
  4426. }
  4427. sstr[c] = '\0';
  4428. DEBUG_INFO("validFrom=%s\n",sstr);
  4429. strcpy(tempvalidFromStr,sstr);
  4430. }
  4431. else
  4432. {
  4433. strcpy(tempvalidFromStr,"");
  4434. }
  4435. //**********startSchedule**********/
  4436. c = 0;
  4437. loc = strstr(sLineWord, "startSchedule");
  4438. //DEBUG_INFO("loc=%s\n",loc);
  4439. memset(sstr ,0, sizeof(sstr) );
  4440. while (loc[3+strlen("startSchedule")+c] != '\"')
  4441. {
  4442. sstr[c] = loc[3+strlen("startSchedule")+c];
  4443. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4444. c++;
  4445. }
  4446. sstr[c] = '\0';
  4447. strcpy(tempstartScheduleStr, sstr);
  4448. DEBUG_INFO(" debug 3-1\n");
  4449. //**********startSchedule**********/
  4450. c = 0;
  4451. loc = strstr(sLineWord, "chargingRateUnit");
  4452. memset(sstr ,0, sizeof(sstr) );
  4453. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4454. {
  4455. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4456. c++;
  4457. }
  4458. sstr[c] = '\0';
  4459. strcpy(tempchargingRateUnitStr, sstr);
  4460. //**********minChargingRate*******/
  4461. c = 0;
  4462. loc = strstr(sLineWord, "minChargingRate");
  4463. //printf("loc=%s\n",loc);
  4464. if(loc != NULL)
  4465. {
  4466. memset(sstr ,0, sizeof(sstr) );
  4467. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4468. {
  4469. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4470. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4471. c++;
  4472. }
  4473. sstr[c] = '\0';
  4474. tempminChargingRateFloat = atof(sstr);
  4475. }
  4476. else
  4477. {
  4478. tempminChargingRateFloat = 0.0;
  4479. }
  4480. //
  4481. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4482. tp.tm_isdst = -1;
  4483. time_t utc = mktime(&tp);
  4484. // current time
  4485. time_t t = time(NULL);
  4486. diff_t = difftime(t, utc);
  4487. //parsing strings to words
  4488. i = 0;
  4489. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4490. loc = loc+3+strlen("chargingSchedulePeriod");
  4491. pch = strtok(loc ,"{");
  4492. while (pch != NULL)
  4493. {
  4494. strcpy(SchedulePeriodList[i], pch);
  4495. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4496. //printf ("%s\n",pch);
  4497. pch = strtok (NULL, "{");
  4498. i = i + 1;
  4499. }
  4500. n_SchedulePeriods = i;
  4501. for(int i=0;i<n_SchedulePeriods;i++)
  4502. {
  4503. //*************startPeriod****************/
  4504. c = 0;
  4505. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4506. memset(sstr ,0, sizeof(sstr) );
  4507. while (loc[strlen("startPeriod")+2+c] != ',')
  4508. {
  4509. sstr[c] = loc[strlen("startPeriod")+2+c];
  4510. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4511. c++;
  4512. }
  4513. sstr[c] = '\0';
  4514. tempStartPeriodInt = atoi(sstr);
  4515. //*************limit****************/
  4516. c = 0;
  4517. loc = strstr(SchedulePeriodList[i], "limit");
  4518. memset(sstr ,0, sizeof(sstr) );
  4519. while (loc[strlen("limit")+2+c] != ',')
  4520. {
  4521. sstr[c] = loc[strlen("limit")+2+c];
  4522. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4523. c++;
  4524. }
  4525. sstr[c] = '\0';
  4526. tempLimitInt = atof(sstr);
  4527. //*************numberPhases****************/
  4528. c = 0;
  4529. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4530. memset(sstr ,0, sizeof(sstr) );
  4531. while (loc[strlen("numberPhases")+2+c] != ',')
  4532. {
  4533. sstr[c] = loc[strlen("numberPhases")+2+c];
  4534. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4535. c++;
  4536. }
  4537. sstr[c] = '\0';
  4538. tempNumberPhasesInt = atoi(sstr);
  4539. TxDefaultProfile.Duration = durationInt;
  4540. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4541. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4542. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4543. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4544. }
  4545. if(MinChargingRate < tempminChargingRateFloat)
  4546. MinChargingRate = tempminChargingRateFloat;
  4547. }
  4548. }
  4549. }// the end of ACCESS TxDefaultProfile
  4550. // Composite Schedule
  4551. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4552. {
  4553. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4554. {
  4555. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4556. {
  4557. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4558. }
  4559. else
  4560. {
  4561. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4562. }
  4563. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4564. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4565. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4566. }
  4567. }
  4568. //* Define temporary variables */
  4569. struct tm *gtime;
  4570. time_t now;
  4571. char buf[28];
  4572. /* Read the current system time */
  4573. time(&now);
  4574. /* Convert the system time to GMT (now UTC) */
  4575. gtime = gmtime(&now);
  4576. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4577. // make .conf
  4578. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  4579. //MaxChargingProfilesInstalled is 10
  4580. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4581. memset(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4582. //nPeriod = 1;
  4583. if(chargingRateUnitStr[0] != 0)
  4584. {
  4585. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4586. }
  4587. else
  4588. {
  4589. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  4590. }
  4591. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4592. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4593. confirmPeriods = 1;
  4594. }
  4595. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4596. {
  4597. //*****************************ChargePointMaxProfile******************************************/
  4598. strcpy(fname, ChargePointMaxProfile_JSON);
  4599. ChargePointMaxProfileIsNull=TRUE;
  4600. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4601. {
  4602. fptr1 = fopen(fname, "r");
  4603. int c;
  4604. c = fgetc(fptr1);
  4605. //DEBUG_INFO("c:%d\n",c);
  4606. rewind(fptr1);
  4607. if(c == EOF)
  4608. {
  4609. DEBUG_INFO("\n End of file reached.");
  4610. ChargePointMaxProfileIsNull=TRUE;
  4611. fclose(fptr1);
  4612. }
  4613. else
  4614. {
  4615. ChargePointMaxProfileIsNull=FALSE;
  4616. while(fscanf(fptr1, "%s", word) != EOF)
  4617. {
  4618. if(strcmp(word, "chargingProfileId") == 0)
  4619. {
  4620. n_chargingProfile = n_chargingProfile + 1;
  4621. }
  4622. }
  4623. rewind(fptr1);
  4624. //search Charging Profile Element
  4625. int i = 0;
  4626. int j = 0;
  4627. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4628. #if 0
  4629. /***********connectorId****************/
  4630. c = 0;
  4631. loc = strstr(sLineWord, "connectorId");
  4632. memset(sstr ,0, sizeof(sstr) );
  4633. while (loc[strlen("connectorId")+2+c] != ',')
  4634. {
  4635. sstr[c] = loc[strlen("connectorId")+2+c];
  4636. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4637. c++;
  4638. }
  4639. sstr[c] = '\0';
  4640. tempconnectorIdInt = atoi(sstr);
  4641. #endif
  4642. //***********validFrom**************/
  4643. c = 0;
  4644. loc = strstr(sLineWord, "validFrom");
  4645. if(loc != NULL)
  4646. {
  4647. memset(sstr ,0, sizeof(sstr) );
  4648. while (loc[3+strlen("validFrom")+c] != '\"')
  4649. {
  4650. sstr[c] = loc[3+strlen("validFrom")+c];
  4651. c++;
  4652. }
  4653. sstr[c] = '\0';
  4654. strcpy(tempvalidFromStr,sstr);
  4655. }
  4656. else
  4657. {
  4658. strcpy(tempvalidFromStr,"");
  4659. }
  4660. //***********validFrom**************/
  4661. c = 0;
  4662. loc = strstr(sLineWord, "duration");
  4663. if(loc != NULL)
  4664. {
  4665. memset(sstr ,0, sizeof(sstr) );
  4666. while (loc[2+strlen("duration")+c] != ',')
  4667. {
  4668. sstr[c] = loc[2+strlen("duration")+c];
  4669. c++;
  4670. }
  4671. sstr[c] = '\0';
  4672. tempdurationInt = atoi(sstr);
  4673. }
  4674. else
  4675. {
  4676. tempdurationInt = 0;
  4677. }
  4678. //**********startSchedule**********/
  4679. c = 0;
  4680. loc = strstr(sLineWord, "startSchedule");
  4681. memset(sstr ,0, sizeof(sstr) );
  4682. while (loc[3+strlen("startSchedule")+c] != '\"')
  4683. {
  4684. sstr[c] = loc[3+strlen("startSchedule")+c];
  4685. c++;
  4686. }
  4687. sstr[c] = '\0';
  4688. strcpy(tempstartScheduleStr, sstr);
  4689. //**********startSchedule**********/
  4690. c = 0;
  4691. loc = strstr(sLineWord, "chargingRateUnit");
  4692. memset(sstr ,0, sizeof(sstr) );
  4693. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4694. {
  4695. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4696. c++;
  4697. }
  4698. sstr[c] = '\0';
  4699. strcpy(tempchargingRateUnitStr, sstr);
  4700. //**********minChargingRate*******/
  4701. c = 0;
  4702. loc = strstr(sLineWord, "minChargingRate");
  4703. if(loc != NULL)
  4704. {
  4705. memset(sstr ,0, sizeof(sstr) );
  4706. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4707. {
  4708. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4709. c++;
  4710. }
  4711. sstr[c] = '\0';
  4712. tempminChargingRateFloat = atof(sstr);
  4713. }
  4714. else
  4715. {
  4716. tempminChargingRateFloat = 0.0;
  4717. }
  4718. //
  4719. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4720. tp.tm_isdst = -1;
  4721. time_t utc = mktime(&tp);
  4722. time_t t = time(NULL);
  4723. diff_t = difftime(t, utc);
  4724. DEBUG_INFO("diff_t=%f\n",diff_t);
  4725. DEBUG_INFO(" debug 5 -1\n");
  4726. //parsing strings to words
  4727. i = 0;
  4728. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4729. loc = loc+3+strlen("chargingSchedulePeriod");
  4730. pch = strtok(loc ,"{");
  4731. while (pch != NULL)
  4732. {
  4733. strcpy(SchedulePeriodList[i], pch);
  4734. pch = strtok (NULL, "{");
  4735. i = i + 1;
  4736. }
  4737. n_SchedulePeriods = i;
  4738. for(int i=0;i<n_SchedulePeriods;i++)
  4739. {
  4740. //*************startPeriod****************/
  4741. c = 0;
  4742. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4743. memset(sstr ,0, sizeof(sstr) );
  4744. while (loc[strlen("startPeriod")+2+c] != ',')
  4745. {
  4746. sstr[c] = loc[strlen("startPeriod")+2+c];
  4747. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4748. c++;
  4749. }
  4750. sstr[c] = '\0';
  4751. tempStartPeriodInt = atoi(sstr);
  4752. //*************limit****************/
  4753. c = 0;
  4754. loc = strstr(SchedulePeriodList[i], "limit");
  4755. memset(sstr ,0, sizeof(sstr) );
  4756. while (loc[strlen("limit")+2+c] != ',')
  4757. {
  4758. sstr[c] = loc[strlen("limit")+2+c];
  4759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4760. c++;
  4761. }
  4762. sstr[c] = '\0';
  4763. tempLimitInt = atof(sstr);
  4764. //*************numberPhases****************/
  4765. c = 0;
  4766. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4767. memset(sstr ,0, sizeof(sstr) );
  4768. while (loc[strlen("numberPhases")+2+c] != '}')
  4769. {
  4770. sstr[c] = loc[strlen("numberPhases")+2+c];
  4771. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4772. c++;
  4773. }
  4774. sstr[c] = '\0';
  4775. tempNumberPhasesInt = atoi(sstr);
  4776. if(j == 0)
  4777. {
  4778. ChargePointMaxProfile.Duration = tempdurationInt;
  4779. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4780. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4781. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4782. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4783. }
  4784. }
  4785. if(MinChargingRate < tempminChargingRateFloat)
  4786. {
  4787. MinChargingRate = tempminChargingRateFloat;
  4788. }
  4789. if(confirmPeriods < n_SchedulePeriods)
  4790. {
  4791. confirmPeriods = n_SchedulePeriods;
  4792. }
  4793. j = j + 1;
  4794. }
  4795. fclose(fptr1);
  4796. }
  4797. }// the end of access file ChargePointMaxProfile
  4798. //****************************TxDefaultProfile************************************************/
  4799. switch(connectorIdInt)
  4800. {
  4801. case 0:
  4802. break;
  4803. case 1:
  4804. strcpy(fname, TxDefaultProfile_1_JSON );
  4805. break;
  4806. case 2:
  4807. strcpy(fname, TxDefaultProfile_2_JSON );
  4808. break;
  4809. default:
  4810. strcpy(fname, TxDefaultProfile_1_JSON );
  4811. break;
  4812. }
  4813. TxDefaultProfileFileIsNull=TRUE;
  4814. if((access(fname,F_OK))!=-1)
  4815. {
  4816. fptr1 = fopen(fname, "r");
  4817. c = 0;
  4818. c = fgetc(fptr1);
  4819. //DEBUG_INFO("c:%d\n",c);
  4820. rewind(fptr1);
  4821. if(c == EOF)
  4822. {
  4823. DEBUG_INFO("\n End of file reached.");
  4824. TxDefaultProfileFileIsNull=TRUE;
  4825. fclose(fptr1);
  4826. }
  4827. else
  4828. {
  4829. TxDefaultProfileFileIsNull=FALSE;
  4830. while(fscanf(fptr1, "%s", word) != EOF)
  4831. {
  4832. if(strcmp(word, "chargingProfileId") == 0)
  4833. {
  4834. n_chargingProfile = n_chargingProfile + 1;
  4835. }
  4836. }
  4837. rewind(fptr1);
  4838. //search Charging Profile Element
  4839. int i = 0;
  4840. int j = 0;
  4841. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4842. #if 0
  4843. /***********connectorId****************/
  4844. c = 0;
  4845. loc = strstr(sLineWord, "connectorId");
  4846. memset(sstr ,0, sizeof(sstr) );
  4847. while (loc[strlen("connectorId")+2+c] != ',')
  4848. {
  4849. sstr[c] = loc[strlen("connectorId")+2+c];
  4850. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4851. c++;
  4852. }
  4853. sstr[c] = '\0';
  4854. tempconnectorIdInt = atoi(sstr);
  4855. #endif
  4856. //***********validFrom**************/
  4857. c = 0;
  4858. loc = strstr(sLineWord, "validFrom");
  4859. if(loc != NULL)
  4860. {
  4861. memset(sstr ,0, sizeof(sstr) );
  4862. while (loc[3+strlen("validFrom")+c] != '\"')
  4863. {
  4864. sstr[c] = loc[3+strlen("validFrom")+c];
  4865. c++;
  4866. }
  4867. sstr[c] = '\0';
  4868. strcpy(tempvalidFromStr,sstr);
  4869. }
  4870. else
  4871. {
  4872. strcpy(tempvalidFromStr,"");
  4873. }
  4874. //***********validFrom**************/
  4875. c = 0;
  4876. loc = strstr(sLineWord, "duration");
  4877. if(loc != NULL)
  4878. {
  4879. memset(sstr ,0, sizeof(sstr) );
  4880. while (loc[2+strlen("duration")+c] != ',')
  4881. {
  4882. sstr[c] = loc[2+strlen("duration")+c];
  4883. c++;
  4884. }
  4885. sstr[c] = '\0';
  4886. tempdurationInt = atoi(sstr);
  4887. }
  4888. else
  4889. {
  4890. tempdurationInt = 0;
  4891. }
  4892. //**********startSchedule**********/
  4893. c = 0;
  4894. loc = strstr(sLineWord, "startSchedule");
  4895. memset(sstr ,0, sizeof(sstr) );
  4896. while (loc[3+strlen("startSchedule")+c] != '\"')
  4897. {
  4898. sstr[c] = loc[3+strlen("startSchedule")+c];
  4899. c++;
  4900. }
  4901. sstr[c] = '\0';
  4902. strcpy(tempstartScheduleStr, sstr);
  4903. //**********startSchedule**********/
  4904. c = 0;
  4905. loc = strstr(sLineWord, "chargingRateUnit");
  4906. memset(sstr ,0, sizeof(sstr) );
  4907. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4908. {
  4909. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4910. c++;
  4911. }
  4912. sstr[c] = '\0';
  4913. strcpy(tempchargingRateUnitStr, sstr);
  4914. //**********minChargingRate*******/
  4915. c = 0;
  4916. loc = strstr(sLineWord, "minChargingRate");
  4917. if(loc != NULL)
  4918. {
  4919. memset(sstr ,0, sizeof(sstr) );
  4920. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4921. {
  4922. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4923. c++;
  4924. }
  4925. sstr[c] = '\0';
  4926. tempminChargingRateFloat = atof(sstr);
  4927. }
  4928. else
  4929. {
  4930. tempminChargingRateFloat = 0.0;
  4931. }
  4932. //
  4933. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4934. tp.tm_isdst = -1;
  4935. time_t utc = mktime(&tp);
  4936. time_t t = time(NULL);
  4937. diff_t = difftime(t, utc);
  4938. DEBUG_INFO("diff_t=%f\n",diff_t);
  4939. DEBUG_INFO(" debug 5 -1\n");
  4940. //parsing strings to words
  4941. i = 0;
  4942. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4943. loc = loc+3+strlen("chargingSchedulePeriod");
  4944. pch = strtok(loc ,"{");
  4945. while (pch != NULL)
  4946. {
  4947. strcpy(SchedulePeriodList[i], pch);
  4948. pch = strtok (NULL, "{");
  4949. i = i + 1;
  4950. }
  4951. n_SchedulePeriods = i;
  4952. for(int i=0;i<n_SchedulePeriods;i++)
  4953. {
  4954. //*************startPeriod****************/
  4955. c = 0;
  4956. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4957. memset(sstr ,0, sizeof(sstr) );
  4958. while (loc[strlen("startPeriod")+2+c] != ',')
  4959. {
  4960. sstr[c] = loc[strlen("startPeriod")+2+c];
  4961. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4962. c++;
  4963. }
  4964. sstr[c] = '\0';
  4965. tempStartPeriodInt = atoi(sstr);
  4966. //*************limit****************/
  4967. c = 0;
  4968. loc = strstr(SchedulePeriodList[i], "limit");
  4969. memset(sstr ,0, sizeof(sstr) );
  4970. while (loc[strlen("limit")+2+c] != ',')
  4971. {
  4972. sstr[c] = loc[strlen("limit")+2+c];
  4973. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4974. c++;
  4975. }
  4976. sstr[c] = '\0';
  4977. tempLimitInt = atof(sstr);
  4978. //*************numberPhases****************/
  4979. c = 0;
  4980. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4981. memset(sstr ,0, sizeof(sstr) );
  4982. while (loc[strlen("numberPhases")+2+c] != '}')
  4983. {
  4984. sstr[c] = loc[strlen("numberPhases")+2+c];
  4985. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4986. c++;
  4987. }
  4988. sstr[c] = '\0';
  4989. tempNumberPhasesInt = atoi(sstr);
  4990. if(j == 0)
  4991. {
  4992. TxDefaultProfile.Duration = tempdurationInt;
  4993. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4994. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4995. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4996. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4997. }
  4998. else
  4999. {
  5000. //other stack level charging Profile
  5001. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5002. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5003. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5004. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5005. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5006. }
  5007. }
  5008. if(MinChargingRate < tempminChargingRateFloat)
  5009. MinChargingRate = tempminChargingRateFloat;
  5010. if(confirmPeriods < n_SchedulePeriods)
  5011. confirmPeriods = n_SchedulePeriods;
  5012. j = j + 1;
  5013. }
  5014. fclose(fptr1);
  5015. //Stacking Charging Profiles
  5016. for(int l=0; l <(j-1) ;l++)
  5017. {
  5018. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5019. {
  5020. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5021. {
  5022. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5023. {
  5024. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5025. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5026. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5027. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5028. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5029. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5030. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5031. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5032. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5033. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5034. }
  5035. else
  5036. {
  5037. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5038. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5039. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5040. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5041. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5042. }
  5043. }
  5044. }
  5045. }
  5046. //end of Stacking Charging Profiles
  5047. }
  5048. }// the end of ACCESS TxDefaultProfile
  5049. //****************************TxProfile************************************************/
  5050. switch(connectorIdInt)
  5051. {
  5052. case 0:
  5053. break;
  5054. case 1:
  5055. strcpy(fname, TxProfile_1_JSON );
  5056. break;
  5057. case 2:
  5058. strcpy(fname, TxProfile_2_JSON );
  5059. break;
  5060. default:
  5061. strcpy(fname, TxProfile_1_JSON );
  5062. break;
  5063. }
  5064. TxProfileIsNull=TRUE;
  5065. if((access(fname,F_OK))!=-1)
  5066. {
  5067. fptr1 = fopen(fname, "r");
  5068. c = 0;
  5069. c = fgetc(fptr1);
  5070. //DEBUG_INFO("c:%d\n",c);
  5071. rewind(fptr1);
  5072. if(c == EOF)
  5073. {
  5074. DEBUG_INFO("\n End of file reached.");
  5075. TxProfileIsNull=TRUE;
  5076. fclose(fptr1);
  5077. }
  5078. else
  5079. {
  5080. TxProfileIsNull=FALSE;
  5081. while(fscanf(fptr1, "%s", word) != EOF)
  5082. {
  5083. if(strcmp(word, "chargingProfileId") == 0)
  5084. {
  5085. n_chargingProfile = n_chargingProfile + 1;
  5086. }
  5087. }
  5088. rewind(fptr1);
  5089. //search Charging Profile Element
  5090. int i= 0;
  5091. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5092. #if 0
  5093. /***********connectorId****************/
  5094. c = 0;
  5095. loc = strstr(sLineWord, "connectorId");
  5096. memset(sstr ,0, sizeof(sstr) );
  5097. while (loc[strlen("connectorId")+2+c] != ',')
  5098. {
  5099. sstr[c] = loc[strlen("connectorId")+2+c];
  5100. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5101. c++;
  5102. }
  5103. sstr[c] = '\0';
  5104. tempconnectorIdInt = atoi(sstr);
  5105. #endif
  5106. //***********validFrom**************/
  5107. c = 0;
  5108. loc = strstr(sLineWord, "validFrom");
  5109. if(loc != NULL)
  5110. {
  5111. memset(sstr ,0, sizeof(sstr) );
  5112. while (loc[3+strlen("validFrom")+c] != '\"')
  5113. {
  5114. sstr[c] = loc[3+strlen("validFrom")+c];
  5115. c++;
  5116. }
  5117. sstr[c] = '\0';
  5118. strcpy(tempvalidFromStr,sstr);
  5119. }
  5120. else
  5121. {
  5122. strcpy(tempvalidFromStr,"");
  5123. }
  5124. //**********startSchedule**********/
  5125. c = 0;
  5126. loc = strstr(sLineWord, "startSchedule");
  5127. memset(sstr ,0, sizeof(sstr) );
  5128. while (loc[3+strlen("startSchedule")+c] != '\"')
  5129. {
  5130. sstr[c] = loc[3+strlen("startSchedule")+c];
  5131. c++;
  5132. }
  5133. sstr[c] = '\0';
  5134. strcpy(tempstartScheduleStr, sstr);
  5135. //**********startSchedule**********/
  5136. c = 0;
  5137. loc = strstr(sLineWord, "chargingRateUnit");
  5138. memset(sstr ,0, sizeof(sstr) );
  5139. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5140. {
  5141. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5142. c++;
  5143. }
  5144. sstr[c] = '\0';
  5145. strcpy(tempchargingRateUnitStr, sstr);
  5146. //**********minChargingRate*******/
  5147. c = 0;
  5148. loc = strstr(sLineWord, "minChargingRate");
  5149. if(loc != NULL)
  5150. {
  5151. memset(sstr ,0, sizeof(sstr) );
  5152. while (loc[3+strlen("minChargingRate")+c] != '\"')
  5153. {
  5154. sstr[c] = loc[3+strlen("minChargingRate")+c];
  5155. c++;
  5156. }
  5157. sstr[c] = '\0';
  5158. tempminChargingRateFloat = atof(sstr);
  5159. }
  5160. else
  5161. {
  5162. tempminChargingRateFloat = 0.0;
  5163. }
  5164. //
  5165. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5166. tp.tm_isdst = -1;
  5167. time_t utc = mktime(&tp);
  5168. time_t t = time(NULL);
  5169. diff_t = difftime(t, utc);
  5170. DEBUG_INFO("diff_t=%f\n",diff_t);
  5171. //parsing strings to words
  5172. i = 0;
  5173. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5174. loc = loc+3+strlen("chargingSchedulePeriod");
  5175. pch = strtok(loc ,"{");
  5176. while (pch != NULL)
  5177. {
  5178. strcpy(SchedulePeriodList[i], pch);
  5179. pch = strtok (NULL, "{");
  5180. i = i + 1;
  5181. }
  5182. n_SchedulePeriods = i;
  5183. for(int i=0;i<n_SchedulePeriods;i++)
  5184. {
  5185. //*************startPeriod****************/
  5186. c = 0;
  5187. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5188. memset(sstr ,0, sizeof(sstr) );
  5189. while (loc[strlen("startPeriod")+2+c] != ',')
  5190. {
  5191. sstr[c] = loc[strlen("startPeriod")+2+c];
  5192. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5193. c++;
  5194. }
  5195. sstr[c] = '\0';
  5196. tempStartPeriodInt = atoi(sstr);
  5197. //*************limit****************/
  5198. c = 0;
  5199. loc = strstr(SchedulePeriodList[i], "limit");
  5200. memset(sstr ,0, sizeof(sstr) );
  5201. while (loc[strlen("limit")+2+c] != ',')
  5202. {
  5203. sstr[c] = loc[strlen("limit")+2+c];
  5204. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5205. c++;
  5206. }
  5207. sstr[c] = '\0';
  5208. tempLimitInt = atof(sstr);
  5209. //*************numberPhases****************/
  5210. c = 0;
  5211. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5212. memset(sstr ,0, sizeof(sstr) );
  5213. while (loc[strlen("numberPhases")+2+c] != '}')
  5214. {
  5215. sstr[c] = loc[strlen("numberPhases")+2+c];
  5216. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5217. c++;
  5218. }
  5219. sstr[c] = '\0';
  5220. tempNumberPhasesInt = atoi(sstr);
  5221. TxProfile.Duration = durationInt;
  5222. TxProfile.TotalPeriod = n_SchedulePeriods;
  5223. TxProfile.Period[i].Limit = tempLimitInt;
  5224. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5225. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5226. }
  5227. if(MinChargingRate < tempminChargingRateFloat)
  5228. MinChargingRate = tempminChargingRateFloat;
  5229. if(confirmPeriods < n_SchedulePeriods)
  5230. confirmPeriods = n_SchedulePeriods;
  5231. }
  5232. fclose(fptr1);
  5233. }
  5234. }// the end of ACCESS TxProfile
  5235. //CompositeSchedule
  5236. int period=0;
  5237. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5238. {
  5239. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5240. {
  5241. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5242. {
  5243. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5244. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5245. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5246. period = period + 1;
  5247. }
  5248. else
  5249. {
  5250. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5251. {
  5252. }
  5253. else
  5254. {
  5255. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5256. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5257. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5258. period = period + 1;
  5259. }
  5260. }
  5261. }
  5262. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5263. {
  5264. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5265. {
  5266. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5267. {
  5268. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5269. }
  5270. else
  5271. {
  5272. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5273. }
  5274. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5275. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5276. period = period + 1;
  5277. }
  5278. }
  5279. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5280. {
  5281. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5282. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5283. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5284. period = period + 1;
  5285. }
  5286. }
  5287. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5288. {
  5289. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5290. {
  5291. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5292. {
  5293. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5294. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5295. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5296. period = period + 1;
  5297. }
  5298. else
  5299. {
  5300. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5301. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5302. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5303. period = period + 1;
  5304. }
  5305. }
  5306. }
  5307. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5308. {
  5309. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5310. {
  5311. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5312. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5313. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5314. period = period + 1;
  5315. }
  5316. }
  5317. confirmPeriods = period;
  5318. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5319. //* Define temporary variables */
  5320. struct tm *gtime;
  5321. time_t now;
  5322. char buf[28];
  5323. //* Read the current system time */
  5324. time(&now);
  5325. //* Convert the system time to GMT (now UTC) */
  5326. gtime = gmtime(&now);
  5327. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5328. // make .conf
  5329. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  5330. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  5331. //DEBUG_INFO(" debug 11\n");
  5332. // if(chargingRateUnitStr[0] != 0)
  5333. // {
  5334. // strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  5335. // }
  5336. // else
  5337. {
  5338. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5339. }
  5340. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5341. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5342. }
  5343. else
  5344. {
  5345. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5346. }
  5347. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5348. return result;
  5349. }
  5350. int handleGetConfigurationRequest(char *uuid, char *payload)
  5351. {
  5352. mtrace();
  5353. int result = FAIL;
  5354. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5355. //struct json_object *jsonitem;
  5356. int MaxKeySupported = 0;
  5357. int n_keys = 0;
  5358. char requestKey[43][50]={0};
  5359. char search[]="[";
  5360. char sstr[500]={ 0 };
  5361. //int pos;
  5362. int l, c = 0;
  5363. int i = 0;
  5364. char *delim = "\",\"";
  5365. char * pch;
  5366. char *loc = strstr(payload, search);
  5367. //********************* Parsing String ***********************************/
  5368. if(loc == NULL) {
  5369. DEBUG_INFO("no key match in Configuration \n");
  5370. }
  5371. else {
  5372. //pos = loc - payload;
  5373. l = strlen(loc)-4;
  5374. while (c < l)
  5375. {
  5376. sstr[c] = loc[c+2];
  5377. c++;
  5378. }
  5379. sstr[c] = '\0';
  5380. //parsing strings to words
  5381. pch = strtok(sstr,delim);
  5382. if(pch == NULL)
  5383. {
  5384. strcpy(requestKey[0], sstr);
  5385. }
  5386. else
  5387. {
  5388. while (pch != NULL)
  5389. {
  5390. strcpy(requestKey[i], pch);
  5391. pch = strtok (NULL, delim);
  5392. i = i + 1;
  5393. }
  5394. n_keys = i;
  5395. }
  5396. }
  5397. UnknownKeynum = 0;
  5398. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5399. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5400. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5401. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5402. if(n_keys != 0)
  5403. {
  5404. for(int i=0;i<n_keys;i++)
  5405. {
  5406. getKeyValue(requestKey[i]);
  5407. //json_object_put(jsonitem);
  5408. }
  5409. }
  5410. else
  5411. {
  5412. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5413. getKeyValue("");
  5414. }
  5415. processUnkownKey();
  5416. sendGetConfigurationConfirmation(uuid);
  5417. return result;
  5418. }
  5419. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5420. {
  5421. mtrace();
  5422. int result = FAIL;
  5423. //void *ret; //
  5424. char fnamePlusPath[50]="";
  5425. char fname[16]="";
  5426. pthread_t t; // pthread 變數
  5427. time_t rawtime;
  5428. struct tm * timeinfo;
  5429. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5430. system("exec /root/logPackTools 'log' 6");
  5431. //char buffer [128];
  5432. time (&rawtime);
  5433. //printf("%ld\n", rawtime);
  5434. timeinfo = localtime (&rawtime);
  5435. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5436. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5437. if((access(fnamePlusPath,F_OK))!=-1)
  5438. {
  5439. DEBUG_INFO("fnamePlusPath exist.\n");
  5440. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5441. }
  5442. else
  5443. {
  5444. DEBUG_INFO("fnamePlusPath not exist!\n");
  5445. }
  5446. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5447. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5448. pthread_join(t, NULL/*&ret*/);
  5449. return result;
  5450. }
  5451. void* GetDiagnosticsProcess(void* data)
  5452. {
  5453. mtrace();
  5454. int retriesInt=0, retryIntervalInt=0;
  5455. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5456. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5457. char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
  5458. int port=0;
  5459. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5460. char fname[16]="";
  5461. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5462. int c = 0;
  5463. char *loc;
  5464. int isSuccess = FALSE;
  5465. char ftpbuf[200]={0};
  5466. //char temp[100]={0};
  5467. char * pch;
  5468. // [2,"137d88c7-a403-4ead-bb2d-fc6ec90531c1","GetDiagnostics",{"location":"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/","retries":0,"retryInterval":0,"startTime":"0001-01-01T00:00:00.000Z","stopTime":"0001-01-01T00:00:00.000Z"}]
  5469. char *str = (char*) data; // ?��?輸入資�?
  5470. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5471. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5472. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5473. //****************location*******************/
  5474. c = 0;
  5475. memset(sstr ,0, sizeof(sstr) );
  5476. loc = strstr(str, "location");
  5477. while (loc[3+strlen("location")+c] != '\"')
  5478. {
  5479. sstr[c] = loc[3+strlen("location")+c];
  5480. c++;
  5481. }
  5482. sstr[c] = '\0';
  5483. strcpy(locationstr,sstr);
  5484. if(strcmp(locationstr,"")==0)
  5485. {
  5486. DEBUG_INFO("location is <Empty>!\n");
  5487. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5488. goto end;
  5489. }
  5490. //****************retries*******************/
  5491. c = 0;
  5492. loc = strstr(str, "retries");
  5493. if(loc == NULL)
  5494. {
  5495. retriesIsNULL = TRUE;
  5496. }
  5497. else
  5498. {
  5499. while (loc[strlen("retries")+2+c] != ',')
  5500. {
  5501. sstr[c] = loc[strlen("retries")+2+c];
  5502. c++;
  5503. }
  5504. sstr[c] = '\0';
  5505. retriesInt = atoi(sstr);
  5506. }
  5507. if(retriesIsNULL == TRUE)
  5508. {
  5509. retriesInt = 0;
  5510. }
  5511. //****************retryInterval*******************/
  5512. c = 0;
  5513. loc = strstr(str, "retryInterval");
  5514. if(loc == NULL)
  5515. {
  5516. retryIntervalIsNULL = TRUE;
  5517. }
  5518. else
  5519. {
  5520. while (loc[strlen("retryInterval")+2+c] != ',')
  5521. {
  5522. sstr[c] = loc[strlen("retryInterval")+2+c];
  5523. c++;
  5524. }
  5525. sstr[c] = '\0';
  5526. retryIntervalInt = atoi(sstr);
  5527. }
  5528. //****************startTime*******************/
  5529. c = 0;
  5530. memset(sstr ,0, sizeof(sstr) );
  5531. loc = strstr(str, "startTime");
  5532. if(loc == NULL)
  5533. {
  5534. startTimeIsNULL = TRUE;
  5535. }
  5536. else
  5537. {
  5538. while (loc[3+strlen("startTime")+c] != '\"')
  5539. {
  5540. sstr[c] = loc[3+strlen("startTime")+c];
  5541. c++;
  5542. }
  5543. sstr[c] = '\0';
  5544. strcpy(startTimestr,sstr);
  5545. }
  5546. //****************stopTime*******************/
  5547. c = 0;
  5548. memset(sstr ,0, sizeof(sstr) );
  5549. loc = strstr(str, "stopTime");
  5550. if(loc == NULL)
  5551. {
  5552. stopTimeIsNULL = TRUE;
  5553. }
  5554. else
  5555. {
  5556. while (loc[3+strlen("stopTime")+c] != '\"')
  5557. {
  5558. sstr[c] = loc[3+strlen("stopTime")+c];
  5559. c++;
  5560. }
  5561. sstr[c] = '\0';
  5562. strcpy(stopTimestr,sstr);
  5563. }
  5564. memset(protocol, 0, sizeof(protocol));
  5565. memset(user, 0, sizeof(user) );
  5566. memset(password, 0, sizeof(password));
  5567. memset(host, 0, sizeof(host));
  5568. memset(path, 0, sizeof(path));
  5569. memset(ftppath, 0, sizeof(ftppath));
  5570. memset(host1, 0, sizeof(host1));
  5571. memset(path1, 0, sizeof(path1));
  5572. /*location: ftp://user:password@host:port/path*/
  5573. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5574. // protocol, user, password, host, &port, path);
  5575. #if 0 // remove for temporally
  5576. //zip files in /Storage
  5577. system("exec /root/logPackTools 'log' 6");
  5578. #endif
  5579. // system("exec /root/Module_WebService 'log' 6");
  5580. time_t rawtime;
  5581. struct tm * timeinfo;
  5582. //char buffer [128];
  5583. time (&rawtime);
  5584. //printf("%ld\n", rawtime);
  5585. timeinfo = localtime (&rawtime);
  5586. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5587. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5588. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5589. if((access(fnamePlusPath,F_OK))!=-1)
  5590. {
  5591. DEBUG_INFO("fnamePlusPath exist.\n");
  5592. }
  5593. else
  5594. {
  5595. DEBUG_INFO("fnamePlusPath not exist!\n");
  5596. goto end;
  5597. }
  5598. pch=strchr(locationstr,'@');
  5599. if(pch==NULL)
  5600. {
  5601. sscanf(locationstr,
  5602. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5603. protocol, host, &port, path);
  5604. strcpy(user,"anonymous");
  5605. strcpy(password,"");
  5606. }
  5607. else
  5608. {
  5609. DEBUG_INFO("pch=%s\n", pch);
  5610. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5611. protocol, user, password, host, &port, path);
  5612. }
  5613. if(strcmp(protocol,"ftp")!=0)
  5614. {
  5615. DEBUG_INFO("protocol is not ftp!\n");
  5616. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5617. goto end;
  5618. }
  5619. sscanf(host,"%[^/]%s",host1, path1);
  5620. sprintf(ftppath,"%s", path1);
  5621. DEBUG_INFO("protocol =%s\n",protocol);
  5622. DEBUG_INFO("user =%s\n",user);
  5623. DEBUG_INFO("password =%s\n",password);
  5624. DEBUG_INFO("host1 =%s\n",host1);
  5625. DEBUG_INFO("port =%d\n",port);
  5626. DEBUG_INFO("path1 =%s\n",path1);
  5627. DEBUG_INFO("ftppath=%s\n",ftppath);
  5628. int ftppathlen=strlen(ftppath);
  5629. int i=1;
  5630. char filenametemp[50];
  5631. while(i < ftppathlen)
  5632. {
  5633. int len=ftppathlen-i;
  5634. if(ftppath[len]== 47) // '/' ascll code: 47
  5635. {
  5636. DEBUG_INFO("find '/' all right\n");
  5637. break;
  5638. }
  5639. i=i+1;
  5640. }
  5641. memset(filenametemp, 0, sizeof(filenametemp));
  5642. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5643. filenametemp[i+1] = 0;
  5644. //httpDownLoadFile(host, ftppath, fname);
  5645. memset(ftpbuf, 0, sizeof(ftpbuf));
  5646. if(port == 0)
  5647. port = 21;
  5648. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5649. do{
  5650. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5651. sleep(retryIntervalInt);
  5652. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5653. if(!isSuccess)
  5654. {
  5655. //BulldogUtil.sleepMs(interval*1000);
  5656. DEBUG_INFO("Diagnostics fail.\n");
  5657. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5658. }
  5659. else
  5660. {
  5661. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5662. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5663. //isUpdateRequest = TRUE;
  5664. }
  5665. end:
  5666. // json_object_put(obj);
  5667. DiagnosticsStatusNotificationStatus = 0; //Idle
  5668. pthread_exit(NULL/*(void *) fname*/); // ?��?子執行�?
  5669. }
  5670. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5671. {
  5672. mtrace();
  5673. int result = FAIL;
  5674. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5675. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5676. {
  5677. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5678. localversion = -1;
  5679. }
  5680. else
  5681. {
  5682. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5683. OCPP_getListVerion();
  5684. }
  5685. //from db.OCPP_getListVerion
  5686. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5687. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5688. sendGetLocalListVersionConfirmation(uuid,"");
  5689. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5690. return result;
  5691. }
  5692. int handleRemoteStartRequest(char *uuid, char *payload)
  5693. {
  5694. mtrace();
  5695. int result = FAIL;
  5696. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5697. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5698. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5699. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5700. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5701. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5702. int chargingSchedulePeriodCount = 0;
  5703. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5704. int c = 0;
  5705. char *loc;
  5706. char comfirmstr[20]={0};
  5707. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5708. if(server_pending == TRUE)
  5709. {
  5710. return 0;
  5711. }
  5712. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5713. //**********connectorId****************/
  5714. c = 0;
  5715. memset(sstr ,0, sizeof(sstr) );
  5716. loc = strstr(payload, "connectorId");
  5717. if(loc == NULL)
  5718. {
  5719. connectorIdIsNULL = TRUE;
  5720. }
  5721. else
  5722. {
  5723. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5724. {
  5725. sstr[c] = loc[strlen("connectorId")+2+c];
  5726. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5727. c++;
  5728. }
  5729. sstr[c] = '\0';
  5730. connectorIdInt = atoi(sstr);
  5731. }
  5732. if(connectorIdIsNULL == TRUE) // need to discussion
  5733. {
  5734. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5735. goto end;
  5736. }
  5737. //****************idTag*******************/
  5738. c = 0;
  5739. memset(sstr ,0, sizeof(sstr) );
  5740. loc = strstr(payload, "idTag");
  5741. while (loc[3+strlen("idTag")+c] != '\"')
  5742. {
  5743. sstr[c] = loc[3+strlen("idTag")+c];
  5744. c++;
  5745. }
  5746. sstr[c] = '\0';
  5747. strcpy(idTagstr,sstr);
  5748. //****************chargingProfile*******************/
  5749. c = 0;
  5750. memset(sstr ,0, sizeof(sstr) );
  5751. loc = strstr(payload, "chargingProfile");
  5752. if(loc == NULL)
  5753. {
  5754. chargingProfileIsNULL = TRUE;
  5755. }
  5756. else
  5757. {
  5758. //****************chargingProfileId*******************/
  5759. c=0;
  5760. loc = strstr(payload, "chargingProfileId");
  5761. memset(sstr ,0, sizeof(sstr) );
  5762. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5763. {
  5764. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5765. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5766. c++;
  5767. }
  5768. sstr[c] = '\0';
  5769. chargingProfileIdInt = atoi(sstr);
  5770. //****************transactionId*******************/
  5771. loc = strstr(payload, "transactionId");
  5772. if(loc == NULL)
  5773. {
  5774. transactionIdIsNULL = TRUE;
  5775. }
  5776. else
  5777. {
  5778. c=0;
  5779. memset(sstr ,0, sizeof(sstr) );
  5780. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5781. {
  5782. sstr[c] = loc[strlen("transactionId")+2+c];
  5783. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5784. c++;
  5785. }
  5786. sstr[c] = '\0';
  5787. transactionIdInt = atoi(sstr);
  5788. }
  5789. //****************stackLevel*******************/
  5790. c=0;
  5791. loc = strstr(payload, "stackLevel");
  5792. memset(sstr ,0, sizeof(sstr) );
  5793. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5794. {
  5795. sstr[c] = loc[strlen("stackLevel")+2+c];
  5796. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5797. c++;
  5798. }
  5799. sstr[c] = '\0';
  5800. stackLevelInt = atoi(sstr);
  5801. //****************chargingProfilePurpose*******************/
  5802. c = 0;
  5803. memset(sstr ,0, sizeof(sstr) );
  5804. loc = strstr(payload, "chargingProfilePurpose");
  5805. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5806. {
  5807. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5808. c++;
  5809. }
  5810. sstr[c] = '\0';
  5811. strcpy(chargingProfilePurposestr,sstr);
  5812. //****************chargingProfileKind*******************/
  5813. c = 0;
  5814. memset(sstr ,0, sizeof(sstr) );
  5815. loc = strstr(payload, "chargingProfileKind");
  5816. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5817. {
  5818. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5819. c++;
  5820. }
  5821. sstr[c] = '\0';
  5822. strcpy(chargingProfileKindstr,sstr);
  5823. //****************recurrencyKind*******************/
  5824. loc = strstr(payload, "recurrencyKind");
  5825. if(loc == NULL)
  5826. {
  5827. recurrencyKindIsNULL = TRUE;
  5828. }
  5829. else
  5830. {
  5831. c = 0;
  5832. memset(sstr ,0, sizeof(sstr) );
  5833. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5834. {
  5835. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5836. c++;
  5837. }
  5838. sstr[c] = '\0';
  5839. strcpy(recurrencyKindstr,sstr);
  5840. }
  5841. //****************validFrom*******************/
  5842. loc = strstr(payload, "validFrom");
  5843. if(loc == NULL)
  5844. {
  5845. validFromIsNULL = TRUE;
  5846. }
  5847. else
  5848. {
  5849. c = 0;
  5850. memset(sstr ,0, sizeof(sstr) );
  5851. while (loc[3+strlen("validFrom")+c] != '\"')
  5852. {
  5853. sstr[c] = loc[3+strlen("validFrom")+c];
  5854. c++;
  5855. }
  5856. sstr[c] = '\0';
  5857. strcpy(validFromstr,sstr);
  5858. }
  5859. //****************validTo*******************/
  5860. loc = strstr(payload, "validTo");
  5861. if(loc == NULL)
  5862. {
  5863. validToIsNULL = TRUE;
  5864. }
  5865. else
  5866. {
  5867. c = 0;
  5868. memset(sstr ,0, sizeof(sstr) );
  5869. while (loc[3+strlen("validTo")+c] != '\"')
  5870. {
  5871. sstr[c] = loc[3+strlen("validTo")+c];
  5872. c++;
  5873. }
  5874. sstr[c] = '\0';
  5875. strcpy(validTostr,sstr);
  5876. }
  5877. //****************chargingSchedule*******************/
  5878. loc = strstr(payload, "chargingSchedule");
  5879. if(loc != NULL)
  5880. {
  5881. //****************duration*******************/
  5882. loc = strstr(payload, "duration");
  5883. if(loc == NULL)
  5884. {
  5885. durationIsNULL = TRUE;
  5886. }
  5887. else
  5888. {
  5889. c=0;
  5890. memset(sstr ,0, sizeof(sstr) );
  5891. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5892. {
  5893. sstr[c] = loc[strlen("duration")+2+c];
  5894. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5895. c++;
  5896. }
  5897. sstr[c] = '\0';
  5898. durationInt = atoi(sstr);
  5899. }
  5900. //****************startSchedule******************/
  5901. loc = strstr(payload, "startSchedule");
  5902. if(loc == NULL)
  5903. {
  5904. startScheduleIsNULL = TRUE;
  5905. }
  5906. else
  5907. {
  5908. c = 0;
  5909. memset(sstr ,0, sizeof(sstr) );
  5910. while (loc[3+strlen("startSchedule")+c] != '\"')
  5911. {
  5912. sstr[c] = loc[3+strlen("startSchedule")+c];
  5913. c++;
  5914. }
  5915. sstr[c] = '\0';
  5916. strcpy(startSchedulestr,sstr);
  5917. }
  5918. //****************chargingRateUnit*******************/
  5919. c = 0;
  5920. memset(sstr ,0, sizeof(sstr) );
  5921. loc = strstr(payload, "chargingRateUnit");
  5922. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5923. {
  5924. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5925. c++;
  5926. }
  5927. sstr[c] = '\0';
  5928. strcpy(chargingRateUnitstr,sstr);
  5929. //****************minChargingRate*******************/
  5930. loc = strstr(payload, "minChargingRate");
  5931. if(loc == NULL)
  5932. {
  5933. minChargingRateIsNULL = TRUE;
  5934. }
  5935. else
  5936. {
  5937. c=0;
  5938. memset(sstr ,0, sizeof(sstr) );
  5939. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5940. {
  5941. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5943. c++;
  5944. }
  5945. sstr[c] = '\0';
  5946. minChargingRateflaot = atof(sstr);
  5947. }
  5948. //****************chargingSchedulePeriod count*******************/
  5949. int what_len = strlen("startPeriod");
  5950. char *where = payload;
  5951. while ((where = strstr(where, "startPeriod"))) {
  5952. where += what_len;
  5953. chargingSchedulePeriodCount++;
  5954. }
  5955. where = payload;
  5956. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5957. {
  5958. //****************startPeriod*******************/
  5959. c=0;
  5960. loc = strstr(where, "startPeriod");
  5961. memset(sstr ,0, sizeof(sstr) );
  5962. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5963. {
  5964. sstr[c] = loc[strlen("startPeriod")+2+c];
  5965. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5966. c++;
  5967. }
  5968. sstr[c] = '\0';
  5969. startPeriodInt[periodNums] = atoi(sstr);
  5970. //****************limit*******************/
  5971. c=0;
  5972. loc = strstr(where, "limit");
  5973. memset(sstr ,0, sizeof(sstr) );
  5974. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5975. {
  5976. sstr[c] = loc[strlen("limit")+2+c];
  5977. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5978. c++;
  5979. }
  5980. sstr[c] = '\0';
  5981. limitflaot[periodNums] = atof(sstr);
  5982. //****************numberPhases*******************/
  5983. loc = strstr(where, "numberPhases");
  5984. if(loc == NULL)
  5985. {
  5986. numberPhasesIsNULL = TRUE;
  5987. }
  5988. else
  5989. {
  5990. c=0;
  5991. memset(sstr ,0, sizeof(sstr) );
  5992. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5993. {
  5994. sstr[c] = loc[strlen("numberPhases")+2+c];
  5995. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5996. c++;
  5997. }
  5998. sstr[c] = '\0';
  5999. numberPhasesInt[periodNums] = atoi(sstr);
  6000. }
  6001. where = loc;
  6002. }
  6003. }
  6004. }
  6005. /*
  6006. enum _SYSTEM_STATUS
  6007. {
  6008. S_BOOTING = 0,
  6009. S_IDLE, = 1
  6010. S_AUTHORIZING, =2
  6011. S_REASSIGN_CHECK, =3
  6012. S_REASSIGN, =4
  6013. S_PRECHARGE, =5
  6014. S_PREPARING_FOR_EV, =6
  6015. S_PREPARING_FOR_EVSE, =7
  6016. S_CHARGING, =8
  6017. S_TERMINATING, =9
  6018. S_COMPLETE, =10
  6019. S_ALARM, =11
  6020. S_FAULT =12
  6021. }
  6022. */
  6023. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6024. {
  6025. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6026. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6027. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6028. //check Transaction active
  6029. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6030. {
  6031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6032. {
  6033. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6034. {
  6035. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6036. {
  6037. //Reserved
  6038. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6039. }
  6040. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6041. {
  6042. //Reserved
  6043. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6044. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6045. goto end;
  6046. }
  6047. else
  6048. {
  6049. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6050. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6051. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6052. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6053. {
  6054. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6055. goto end;
  6056. }
  6057. }//END FOR ELSE
  6058. }
  6059. }// END FOR CHAdeMO_QUANTITY
  6060. for (int index = 0; index < CCS_QUANTITY; index++)
  6061. {
  6062. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6063. {
  6064. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6065. {
  6066. //Reserved
  6067. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6068. }
  6069. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6070. {
  6071. //Reserved
  6072. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6073. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6074. goto end;
  6075. }
  6076. else
  6077. {
  6078. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6079. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6080. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6081. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6082. {
  6083. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6084. goto end;
  6085. }
  6086. }// END FOR ELSE
  6087. }
  6088. }// END FOR CCS_QUANTITY
  6089. for (int index = 0; index < GB_QUANTITY; index++)
  6090. {
  6091. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6092. {
  6093. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6094. {
  6095. //Reserved
  6096. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6097. }
  6098. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6099. {
  6100. //Reserved
  6101. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6102. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6103. goto end;
  6104. }
  6105. else
  6106. {
  6107. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6108. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6109. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6110. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6111. {
  6112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6113. goto end;
  6114. }
  6115. }// END FOR ELSE
  6116. }
  6117. } // END FOR GB_QUANTITY
  6118. }
  6119. else
  6120. {
  6121. for (int index = 0; index < AC_QUANTITY; index++)
  6122. {
  6123. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6124. {
  6125. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6126. {
  6127. //Reserved
  6128. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6129. }
  6130. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6131. {
  6132. //Reserved
  6133. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6134. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6135. goto end;
  6136. }
  6137. else
  6138. {
  6139. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6140. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6141. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6142. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6143. {
  6144. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6145. goto end;
  6146. }
  6147. }//END FOR ELSE
  6148. }
  6149. }// END FOR AC_QUANTITY
  6150. }
  6151. if(chargingProfileIsNULL == FALSE)
  6152. {
  6153. //ChargingProfile
  6154. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6155. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6156. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6157. if(recurrencyKindIsNULL == FALSE) //OPTION
  6158. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6159. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6160. if(transactionIdIsNULL == FALSE) // OPTION
  6161. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6162. if(validFromIsNULL == FALSE) // OPTION
  6163. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6164. if(validToIsNULL == FALSE) //OPTION
  6165. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6166. //ChargingSchedule
  6167. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6168. if(durationIsNULL == FALSE) //OPTION
  6169. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6170. if(minChargingRateIsNULL == FALSE) //OPTION
  6171. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6172. if(startScheduleIsNULL == FALSE) //OPTION
  6173. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6174. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6175. {
  6176. //ChargingSchedulePeriod
  6177. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6178. if(numberPhasesIsNULL == FALSE)
  6179. {
  6180. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6181. }
  6182. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6183. }
  6184. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6185. {
  6186. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6187. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6188. }
  6189. else
  6190. {
  6191. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6192. }
  6193. }
  6194. else
  6195. {
  6196. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6197. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6198. }
  6199. }
  6200. else
  6201. {
  6202. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6203. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6204. }
  6205. end:
  6206. if(connectorIdIsNULL == FALSE)
  6207. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6208. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6209. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6210. //OCPP send RemoteStartConfirmation by first.
  6211. sendRemoteStartConfirmation(uuid, comfirmstr);
  6212. return result;
  6213. }
  6214. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6215. {
  6216. mtrace();
  6217. int result = FAIL;
  6218. int match = FALSE;
  6219. int GunNO = 0;
  6220. int transactionIdInt=0;
  6221. int transactionIdIsNULL= FALSE;
  6222. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6223. int c = 0;
  6224. char *loc;
  6225. char comfirmstr[20];
  6226. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6227. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6228. if(server_pending == TRUE)
  6229. {
  6230. return 0;
  6231. }
  6232. c=0;
  6233. loc = strstr(payload, "transactionId");
  6234. if(loc == NULL)
  6235. {
  6236. transactionIdIsNULL= TRUE;
  6237. }
  6238. else
  6239. {
  6240. memset(sstr ,0, sizeof(sstr) );
  6241. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6242. {
  6243. sstr[c] = loc[strlen("transactionId")+2+c];
  6244. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6245. c++;
  6246. }
  6247. sstr[c] = '\0';
  6248. transactionIdInt = atoi(sstr);
  6249. }
  6250. if(transactionIdIsNULL == FALSE)
  6251. {
  6252. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6253. {
  6254. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6255. {
  6256. //check Transaction active
  6257. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6258. {
  6259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6260. {
  6261. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6262. {
  6263. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6264. {
  6265. match = TRUE;
  6266. GunNO = gun_index;
  6267. }
  6268. }
  6269. }// END FOR CHAdeMO_QUANTITY
  6270. for (int index = 0; index < CCS_QUANTITY; index++)
  6271. {
  6272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6273. {
  6274. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6275. {
  6276. match = TRUE;
  6277. GunNO = gun_index;
  6278. }
  6279. }
  6280. }// END FOR CCS_QUANTITY
  6281. for (int index = 0; index < GB_QUANTITY; index++)
  6282. {
  6283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6284. {
  6285. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6286. {
  6287. match = TRUE;
  6288. GunNO = gun_index;
  6289. }
  6290. }
  6291. }// END FOR GB_QUANTITY
  6292. }
  6293. else
  6294. {
  6295. for (int index = 0; index < AC_QUANTITY; index++)
  6296. {
  6297. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6298. {
  6299. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6300. {
  6301. match = TRUE;
  6302. GunNO = gun_index;
  6303. }
  6304. }
  6305. }// END FOR CHAdeMO_QUANTITY
  6306. }// END FOR AC ELSE
  6307. }// CHECK IF ResponseTransactionId == transactionIdInt
  6308. }//END FOR
  6309. if( match == TRUE)
  6310. {
  6311. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6313. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6314. }
  6315. else
  6316. {
  6317. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6318. }
  6319. }
  6320. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6321. return result;
  6322. }
  6323. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6324. {
  6325. mtrace();
  6326. int result = FAIL;
  6327. int connectorIdInt=0, reservationIdInt=0;
  6328. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6329. char comfirmstr[20]={0};
  6330. char sstr[180]={ 0 };
  6331. int c = 0;
  6332. char *loc;
  6333. //char *ptr;
  6334. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6335. //***(1)connectorId ****/
  6336. c=0;
  6337. loc = strstr(payload, "connectorId");
  6338. memset(sstr ,0, sizeof(sstr) );
  6339. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6340. {
  6341. sstr[c] = loc[strlen("connectorId")+2+c];
  6342. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6343. c++;
  6344. }
  6345. sstr[c] = '\0';
  6346. connectorIdInt = atoi(sstr);
  6347. //***(2)expiryDate ****/
  6348. loc = strstr(payload, "expiryDate");
  6349. memset(sstr ,0, sizeof(sstr) );
  6350. c = 0;
  6351. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6352. {
  6353. sstr[c] = loc[3+strlen("expiryDate")+c];
  6354. c++;
  6355. }
  6356. sstr[c] = '\0';
  6357. strcpy(expiryDatestr, sstr);
  6358. //***(3)idTag ****/
  6359. loc = strstr(payload, "idTag");
  6360. memset(sstr ,0, sizeof(sstr) );
  6361. c = 0;
  6362. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6363. {
  6364. sstr[c] = loc[3+strlen("idTag")+c];
  6365. c++;
  6366. }
  6367. sstr[c] = '\0';
  6368. strcpy(idTagstr, sstr);
  6369. //***(4)parentIdTag ****/
  6370. loc = strstr(payload, "parentIdTag");
  6371. memset(sstr ,0, sizeof(sstr) );
  6372. c = 0;
  6373. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6374. {
  6375. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6376. c++;
  6377. }
  6378. sstr[c] = '\0';
  6379. strcpy(parentIdTagstr, sstr);
  6380. //***(5)reservationId ****/
  6381. c=0;
  6382. loc = strstr(payload, "reservationId");
  6383. memset(sstr ,0, sizeof(sstr) );
  6384. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6385. {
  6386. sstr[c] = loc[strlen("reservationId")+2+c];
  6387. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6388. c++;
  6389. }
  6390. sstr[c] = '\0';
  6391. reservationIdInt = atoi(sstr);
  6392. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6393. /*
  6394. enum _SYSTEM_STATUS
  6395. {
  6396. S_BOOTING = 0,
  6397. S_IDLE, = 1
  6398. S_AUTHORIZING, =2
  6399. S_REASSIGN_CHECK, =3
  6400. S_REASSIGN, =4
  6401. S_PRECHARGE, =5
  6402. S_PREPARING_FOR_EV, =6
  6403. S_PREPARING_FOR_EVSE, =7
  6404. S_CHARGING, =8
  6405. S_TERMINATING, =9
  6406. S_COMPLETE, =10
  6407. S_ALARM, =11
  6408. S_FAULT =12
  6409. }
  6410. */
  6411. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6412. {
  6413. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6414. goto end;
  6415. }
  6416. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6417. {
  6418. //check Transaction active
  6419. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6420. {
  6421. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6422. {
  6423. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6424. {
  6425. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6426. {
  6427. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6428. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6429. {
  6430. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6431. {
  6432. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6434. }
  6435. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6436. {
  6437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6438. }
  6439. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6440. {
  6441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6442. }
  6443. else
  6444. {
  6445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6446. }
  6447. }
  6448. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6449. {
  6450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6451. }
  6452. }
  6453. else
  6454. {
  6455. //replace reservation
  6456. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6457. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6458. }
  6459. }
  6460. } // END FOR CHAdeMO_QUANTITY
  6461. for (int index = 0; index < CCS_QUANTITY; index++)
  6462. {
  6463. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6464. {
  6465. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6466. {
  6467. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6468. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6469. {
  6470. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6471. {
  6472. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6474. }
  6475. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6476. {
  6477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6478. }
  6479. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6480. {
  6481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6482. }
  6483. else
  6484. {
  6485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6486. }
  6487. }
  6488. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6489. {
  6490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6491. }
  6492. }
  6493. else
  6494. {
  6495. //replace reservation
  6496. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6498. }
  6499. }
  6500. } // END FOR CCS_QUANTITY
  6501. for (int index = 0; index < GB_QUANTITY; index++)
  6502. {
  6503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6504. {
  6505. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6506. {
  6507. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6508. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6509. {
  6510. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6511. {
  6512. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6513. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6514. }
  6515. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6516. {
  6517. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6518. }
  6519. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6520. {
  6521. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6522. }
  6523. else
  6524. {
  6525. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6526. }
  6527. }
  6528. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6529. {
  6530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6531. }
  6532. }
  6533. else
  6534. {
  6535. //replace reservation
  6536. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6538. }
  6539. }
  6540. }// END FOR GB_QUANTITY
  6541. }
  6542. else
  6543. {
  6544. for (int index = 0; index < AC_QUANTITY; index++)
  6545. {
  6546. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6547. {
  6548. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6549. {
  6550. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6551. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6552. {
  6553. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6554. {
  6555. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6556. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6557. }
  6558. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6559. {
  6560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6561. }
  6562. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6563. {
  6564. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6565. }
  6566. else
  6567. {
  6568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6569. }
  6570. }
  6571. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6572. {
  6573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6574. }
  6575. }
  6576. else
  6577. {
  6578. //replace reservation
  6579. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6581. }
  6582. }
  6583. } // END FOR AC_QUANTITY
  6584. }//END FOR AC ELSE
  6585. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6586. }
  6587. else if(connectorIdInt == 0)
  6588. {
  6589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6590. {
  6591. //check Transaction active
  6592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6593. {
  6594. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6595. {
  6596. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6597. {
  6598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6599. goto end;
  6600. }
  6601. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6602. {
  6603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6604. goto end;
  6605. }
  6606. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6607. {
  6608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6609. goto end;
  6610. }
  6611. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6612. {
  6613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6614. goto end;
  6615. }
  6616. }
  6617. }// END FOR CHAdeMO_QUANTITY
  6618. for (int index = 0; index < CCS_QUANTITY; index++)
  6619. {
  6620. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6621. {
  6622. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6623. {
  6624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6625. }
  6626. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6627. {
  6628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6629. }
  6630. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6631. {
  6632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6633. }
  6634. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6635. {
  6636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6637. }
  6638. }
  6639. } // END FOR CCS_QUANTITY
  6640. for (int index = 0; index < GB_QUANTITY; index++)
  6641. {
  6642. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6643. {
  6644. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6645. {
  6646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6647. }
  6648. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6649. {
  6650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6651. }
  6652. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6653. {
  6654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6655. }
  6656. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6657. {
  6658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6659. }
  6660. }
  6661. } // END FOR GB_QUANTITY
  6662. }
  6663. else
  6664. {
  6665. for (int index = 0; index < AC_QUANTITY; index++)
  6666. {
  6667. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6668. {
  6669. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6670. {
  6671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6672. goto end;
  6673. }
  6674. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6675. {
  6676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6677. goto end;
  6678. }
  6679. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6680. {
  6681. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6682. goto end;
  6683. }
  6684. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6685. {
  6686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6687. goto end;
  6688. }
  6689. }
  6690. }// END FOR AC_QUANTITY
  6691. }
  6692. //The connectorId is 0
  6693. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6695. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6696. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6697. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6698. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6699. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6700. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6701. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6702. result = TRUE;
  6703. return result;
  6704. }
  6705. else
  6706. {
  6707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6708. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6709. }
  6710. if(strcmp(comfirmstr,"Accepted") == 0)
  6711. {
  6712. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6713. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6714. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6715. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6716. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6717. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6718. result = TRUE;
  6719. return result;
  6720. }
  6721. end:
  6722. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6723. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6724. return result;
  6725. }
  6726. int handleResetRequest(char *uuid, char *payload)
  6727. {
  6728. mtrace();
  6729. int result = FAIL;
  6730. char sstr[10]={0};
  6731. char typestr[10]={0};
  6732. char comfirmstr[20]={0};
  6733. int c = 0;
  6734. char *loc;
  6735. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6736. DEBUG_INFO("handleResetRequest ...\n");
  6737. loc = strstr(payload, "type");
  6738. memset(sstr ,0, sizeof(sstr) );
  6739. c = 0;
  6740. while (loc[3+strlen("type")+c] != '\"')
  6741. {
  6742. sstr[c] = loc[3+strlen("type")+c];
  6743. c++;
  6744. }
  6745. sstr[c] = '\0';
  6746. strcpy(typestr,sstr);
  6747. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6748. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6749. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6750. {
  6751. //check Transaction active
  6752. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6753. {
  6754. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6755. {
  6756. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6757. {
  6758. //0: unplug, 1: Plug-in
  6759. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6760. }
  6761. }
  6762. for (int index = 0; index < CCS_QUANTITY; index++)
  6763. {
  6764. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6765. {
  6766. //0: unplug, 1: Plug-in
  6767. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6768. }
  6769. }
  6770. for (int index = 0; index < GB_QUANTITY; index++)
  6771. {
  6772. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6773. {
  6774. //0: unplug, 1: Plug-in
  6775. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6776. }
  6777. }
  6778. }
  6779. else
  6780. {
  6781. for (int index = 0; index < AC_QUANTITY; index++)
  6782. {
  6783. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6784. {
  6785. //0: unplug, 1: Plug-in
  6786. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6787. }
  6788. }
  6789. }// END FOR AC ELSE
  6790. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6791. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6792. result = TRUE;
  6793. return result;
  6794. }
  6795. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6796. {
  6797. //check Transaction active
  6798. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6799. {
  6800. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6801. {
  6802. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6803. {
  6804. //0: unplug, 1: Plug-in
  6805. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6806. }
  6807. }
  6808. for (int index = 0; index < CCS_QUANTITY; index++)
  6809. {
  6810. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6811. {
  6812. //0: unplug, 1: Plug-in
  6813. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6814. }
  6815. }
  6816. for (int index = 0; index < GB_QUANTITY; index++)
  6817. {
  6818. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6819. {
  6820. //0: unplug, 1: Plug-in
  6821. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6822. }
  6823. }
  6824. }
  6825. else
  6826. {
  6827. for (int index = 0; index < AC_QUANTITY; index++)
  6828. {
  6829. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6830. {
  6831. //0: unplug, 1: Plug-in
  6832. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6833. }
  6834. }
  6835. }// END FOR AC ELSE
  6836. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6837. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6838. result = TRUE;
  6839. return result;
  6840. }
  6841. else
  6842. {
  6843. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6844. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6845. goto errorend;
  6846. }
  6847. errorend:
  6848. sendResetConfirmation(uuid, comfirmstr);
  6849. return result;
  6850. }
  6851. int handleSendLocalListRequest(char *uuid, char *payload)
  6852. {
  6853. mtrace();
  6854. int result = FAIL;
  6855. int listVersionInt;
  6856. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6857. char listsearch[]="listVersion";
  6858. char updateTypesearch[]="updateType";
  6859. char localAuthorizationListsearch[]="localAuthorizationList";
  6860. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6861. char CardList[500][160]={0};
  6862. char updateTypestr[15]={0};
  6863. char idTagstr[20]={0};
  6864. char parentIdTag[20]={0};
  6865. char expiryDate[30]={0};
  6866. char idTagstatus[16]={0};
  6867. int c = 0;
  6868. int i = 0;
  6869. char *delim1 = "}";
  6870. char * pch;
  6871. char *loc;
  6872. //char *ptr;
  6873. char comfirmstr[20];
  6874. //int n_localAuthorizations = 0;
  6875. int checkState_Faulted = FALSE;
  6876. DEBUG_INFO("handleSendLocalListRequest\n");
  6877. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6878. {
  6879. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6880. goto end;
  6881. }
  6882. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6883. {
  6884. //check Charge Point state
  6885. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6886. {
  6887. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6888. {
  6889. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6890. }
  6891. }
  6892. for (int index = 0; index < CCS_QUANTITY; index++)
  6893. {
  6894. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6895. {
  6896. checkState_Faulted = TRUE; //OCPP Status
  6897. }
  6898. }
  6899. for (int index = 0; index < GB_QUANTITY; index++)
  6900. {
  6901. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6902. {
  6903. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6904. }
  6905. }
  6906. }
  6907. else
  6908. {
  6909. //check Charge Point state
  6910. for (int index = 0; index < AC_QUANTITY; index++)
  6911. {
  6912. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6913. {
  6914. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6915. }
  6916. }
  6917. }// END FOR AC ELSE
  6918. if(checkState_Faulted == TRUE)
  6919. {
  6920. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6921. goto end;
  6922. }
  6923. //listVersion
  6924. c = 0;
  6925. loc = strstr(payload, listsearch);
  6926. while (loc[strlen("listVersion")+2+c] != ',')
  6927. {
  6928. sstr[c] = loc[strlen("listVersion")+2+c];
  6929. c++;
  6930. }
  6931. sstr[c] = '\0';
  6932. listVersionInt = atoi(sstr);
  6933. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6934. //updateType
  6935. loc = strstr(payload, updateTypesearch);
  6936. c = 0;
  6937. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6938. {
  6939. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6940. c++;
  6941. }
  6942. sstr[c] = '\0';
  6943. strcpy(updateTypestr, sstr);
  6944. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6945. //localAuthorizationList
  6946. memset(sstr ,0, sizeof(sstr) );
  6947. loc = strstr(payload, localAuthorizationListsearch);
  6948. if(loc != NULL) // localAuthorizationList is not NULL
  6949. {
  6950. //Check UpdateType
  6951. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6952. {
  6953. //Local list full update
  6954. printf("Local list full update.\n");
  6955. OCPP_cleanLocalList();
  6956. }
  6957. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6958. {
  6959. //Local list different update
  6960. printf("Local list different update.\n");
  6961. OCPP_getListVerion();
  6962. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6963. {
  6964. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6965. goto end;
  6966. }
  6967. }
  6968. else
  6969. {
  6970. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6971. goto end;
  6972. }
  6973. c = 0;
  6974. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6975. {
  6976. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6977. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6978. c++;
  6979. }
  6980. sstr[c] = '\0';
  6981. //parsing strings to words
  6982. i = 0;
  6983. pch = strtok(sstr,delim1);
  6984. while (pch != NULL)
  6985. {
  6986. strcpy(CardList[i], pch);
  6987. pch = strtok (NULL, delim1);
  6988. i = i + 1;
  6989. }
  6990. //local Authorizations List Numbers
  6991. //n_localAuthorizations = i;
  6992. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6993. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  6994. c= 0;
  6995. while(c < i)
  6996. {
  6997. //Search "IdToken"
  6998. memset(sstr ,0, sizeof(sstr) );
  6999. loc = strstr(CardList[c], "idTag");
  7000. int j = 0;
  7001. while (loc[3+strlen("idTag")+j] != '\"')
  7002. {
  7003. sstr[j] = loc[3+strlen("idTag")+j];
  7004. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7005. j++;
  7006. }
  7007. sstr[j] = '\0';
  7008. strcpy(idTagstr, sstr);
  7009. //Search "expiryDate"
  7010. memset(sstr ,0, sizeof(sstr) );
  7011. loc = strstr(CardList[c], "expiryDate");
  7012. j = 0;
  7013. while (loc[3+strlen("expiryDate")+j] != '\"')
  7014. {
  7015. sstr[j] = loc[3+strlen("expiryDate")+j];
  7016. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7017. j++;
  7018. }
  7019. sstr[j] = '\0';
  7020. strcpy(expiryDate, sstr);
  7021. //Search "parentIdTag"
  7022. memset(sstr ,0, sizeof(sstr) );
  7023. loc = strstr(CardList[c], "parentIdTag");
  7024. j = 0;
  7025. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7026. {
  7027. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7028. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7029. j++;
  7030. }
  7031. sstr[j] = '\0';
  7032. strcpy(parentIdTag, sstr);
  7033. //Search "status"
  7034. memset(sstr ,0, sizeof(sstr) );
  7035. loc = strstr(CardList[c], "status");
  7036. j = 0;
  7037. while (loc[3+strlen("status")+j] != '\"')
  7038. {
  7039. sstr[j] = loc[3+strlen("status")+j];
  7040. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7041. j++;
  7042. }
  7043. sstr[j] = '\0';
  7044. strcpy(idTagstatus, sstr);
  7045. OCPP_getIdTag(idTagstr);
  7046. //OCPP_getIdTag("test"); For Test
  7047. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7048. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7049. {
  7050. //Local list full update
  7051. DEBUG_INFO("Local list full update.\n");
  7052. // update list
  7053. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7054. OCPP_get_TableAuthlocalAllData();
  7055. }
  7056. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7057. {
  7058. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7059. {
  7060. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7061. }
  7062. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7063. {
  7064. OCPP_deleteIdTag(idTagstr);
  7065. }
  7066. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7067. {
  7068. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7069. }
  7070. }
  7071. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7072. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7073. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7074. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7075. c++;
  7076. }
  7077. }
  7078. else
  7079. {
  7080. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7081. {
  7082. //Local list different update
  7083. DEBUG_INFO("Local list different update.\n");
  7084. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7085. goto end;
  7086. }
  7087. }
  7088. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7089. end:
  7090. sendSendLocalListConfirmation(uuid, comfirmstr);
  7091. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7092. #if 0
  7093. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7094. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7095. #endif
  7096. return result;
  7097. }
  7098. /*
  7099. enum _SYSTEM_STATUS
  7100. {
  7101. S_BOOTING = 0,
  7102. S_IDLE, =1
  7103. S_AUTHORIZING, =2
  7104. S_REASSIGN_CHECK, =3
  7105. S_REASSIGN, =4
  7106. S_PRECHARGE, =5
  7107. S_PREPARING_FOR_EV, =6
  7108. S_PREPARING_FOR_EVSE, =7
  7109. S_CHARGING, =8
  7110. S_TERMINATING, =9
  7111. S_COMPLETE, =10
  7112. S_ALARM, =11
  7113. S_FAULT =12
  7114. };
  7115. */
  7116. #define MAX 200
  7117. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7118. {
  7119. mtrace();
  7120. int result = FAIL;
  7121. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7122. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7123. char chargingProfilePurposeStr[30]={0};
  7124. char chargingProfileKindStr[16]={0};
  7125. char recurrencyKindStr[10]={0};
  7126. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7127. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7128. int chargingSchedulePeriodCount = 0;
  7129. //int updateflag = FALSE;
  7130. char comfirmstr[20]={0};
  7131. int meet= FALSE;
  7132. char sstr[10]={0};
  7133. int c = 0;
  7134. char *loc;
  7135. FILE *fptr1;//, *fptr2;
  7136. //int lno=0;//, linectr = 0;
  7137. //int modifyflag = FALSE;
  7138. char filename[MAX]={0};
  7139. char tempfile[] = "../Storage/OCPP/temp.json";
  7140. int resultRename=0;
  7141. char rmFileCmd[50]={0};
  7142. char tempchargingProfilePurposeStr[30]={0};
  7143. //[2,"d65bcbca-0b07-49c1-b679-e6c6ff9f5627","SetChargingProfile",{"connectorId":0,"csChargingProfiles":{"chargingProfileId":1,"transactionId":0,"stackLevel":0,"chargingProfilePurpose":"TxDefaultProfile","chargingProfileKind":"Absolute","recurrencyKind":"Daily","validFrom":"2019-07-01T02:39:55.000Z","validTo":"2019-07-04T02:39:55.000Z","chargingSchedule":{"duration":86400,"startSchedule":"2019-07-01T02:39:55.000Z","chargingRateUnit":"A","chargingSchedulePeriod":[{"startPeriod":0,"limit":20.0,"numberPhases":3},{"startPeriod":300,"limit":10.0,"numberPhases":3},{"startPeriod":600,"limit":20.0,"numberPhases":3},{"startPeriod":1200,"limit":10.0,"numberPhases":3},{"startPeriod":1800,"limit":20.0,"numberPhases":3},{"startPeriod":2400,"limit":10.0,"numberPhases":3},{"startPeriod":3000,"limit":20.0,"numberPhases":3}],"minChargingRate":20.1}}}]
  7144. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7145. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7146. //*********************connectorId***************************/
  7147. loc = strstr(payload, "connectorId");
  7148. c = 0;
  7149. memset(sstr ,0, sizeof(sstr) );
  7150. while (loc[strlen("connectorId")+2+c] != ',')
  7151. {
  7152. sstr[c] = loc[strlen("connectorId")+2+c];
  7153. c++;
  7154. }
  7155. sstr[c] = '\0';
  7156. connectorIdInt = atoi(sstr);
  7157. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7158. {
  7159. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7160. }
  7161. else
  7162. {
  7163. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7164. }
  7165. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7166. //*********************chargingProfileId***************************/
  7167. loc = strstr(payload, "chargingProfileId");
  7168. c = 0;
  7169. memset(sstr ,0, sizeof(sstr) );
  7170. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7171. {
  7172. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7173. c++;
  7174. }
  7175. sstr[c] = '\0';
  7176. chargingProfileIdInt = atoi(sstr);
  7177. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7178. {
  7179. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7180. }
  7181. else
  7182. {
  7183. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7184. }
  7185. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7186. //*********************transactionId***************************/
  7187. loc = strstr(payload, "transactionId");
  7188. if(loc != NULL)
  7189. {
  7190. c = 0;
  7191. memset(sstr ,0, sizeof(sstr) );
  7192. while (loc[strlen("transactionId")+2+c] != ',')
  7193. {
  7194. sstr[c] = loc[strlen("transactionId")+2+c];
  7195. c++;
  7196. }
  7197. sstr[c] = '\0';
  7198. transactionIdInt = atoi(sstr);
  7199. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7200. {
  7201. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7202. }
  7203. else
  7204. {
  7205. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7206. }
  7207. }
  7208. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7209. //*********************stackLevel***************************/
  7210. loc = strstr(payload, "stackLevel");
  7211. c = 0;
  7212. memset(sstr ,0, sizeof(sstr) );
  7213. while (loc[strlen("stackLevel")+2+c] != ',')
  7214. {
  7215. sstr[c] = loc[strlen("stackLevel")+2+c];
  7216. c++;
  7217. }
  7218. sstr[c] = '\0';
  7219. stackLevelInt = atoi(sstr);
  7220. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7221. {
  7222. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7223. }
  7224. else
  7225. {
  7226. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7227. }
  7228. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7229. //*********************chargingProfilePurpose***************************/
  7230. loc = strstr(payload, "chargingProfilePurpose");
  7231. c = 0;
  7232. memset(sstr ,0, sizeof(sstr) );
  7233. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7234. {
  7235. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7236. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7237. c++;
  7238. }
  7239. sstr[c] = '\0';
  7240. strcpy(chargingProfilePurposeStr,sstr);
  7241. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7242. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7243. {
  7244. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7245. }
  7246. else
  7247. {
  7248. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7249. }
  7250. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7251. //*********************chargingProfileKind***************************/
  7252. loc = strstr(payload, "chargingProfileKind");
  7253. c = 0;
  7254. memset(sstr ,0, sizeof(sstr) );
  7255. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7256. {
  7257. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7258. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7259. c++;
  7260. }
  7261. sstr[c] = '\0';
  7262. strcpy(chargingProfileKindStr,sstr);
  7263. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7264. {
  7265. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7266. }
  7267. else
  7268. {
  7269. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7270. }
  7271. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7272. //*********************recurrencyKind***************************/
  7273. loc = strstr(payload, "recurrencyKind");
  7274. if(loc != NULL)
  7275. {
  7276. c = 0;
  7277. memset(sstr ,0, sizeof(sstr) );
  7278. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7279. {
  7280. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7281. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7282. c++;
  7283. }
  7284. sstr[c] = '\0';
  7285. strcpy(recurrencyKindStr,sstr);
  7286. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7287. {
  7288. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7289. }
  7290. else
  7291. {
  7292. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7293. }
  7294. }
  7295. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7296. //*********************validFrom***************************/
  7297. loc = strstr(payload, "validFrom");
  7298. if(loc != NULL)
  7299. {
  7300. c = 0;
  7301. memset(sstr ,0, sizeof(sstr) );
  7302. while (loc[3+strlen("validFrom")+c] != '\"')
  7303. {
  7304. sstr[c] = loc[3+strlen("validFrom")+c];
  7305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7306. c++;
  7307. }
  7308. sstr[c] = '\0';
  7309. strcpy(validFromStr,sstr);
  7310. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7311. {
  7312. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7313. }
  7314. else
  7315. {
  7316. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7317. }
  7318. }
  7319. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7320. //*********************validTo***************************/
  7321. loc = strstr(payload, "validTo");
  7322. if(loc != NULL)
  7323. {
  7324. c = 0;
  7325. memset(sstr ,0, sizeof(sstr) );
  7326. while (loc[3+strlen("validTo")+c] != '\"')
  7327. {
  7328. sstr[c] = loc[3+strlen("validTo")+c];
  7329. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7330. c++;
  7331. }
  7332. sstr[c] = '\0';
  7333. strcpy(validToStr,sstr);
  7334. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7335. {
  7336. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7337. }
  7338. else
  7339. {
  7340. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7341. }
  7342. }
  7343. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7344. //*********************duration***************************/
  7345. loc = strstr(payload, "duration");
  7346. if(loc != NULL)
  7347. {
  7348. c = 0;
  7349. memset(sstr ,0, sizeof(sstr) );
  7350. while (loc[strlen("duration")+2+c] != ',')
  7351. {
  7352. sstr[c] = loc[strlen("duration")+2+c];
  7353. c++;
  7354. }
  7355. sstr[c] = '\0';
  7356. durationInt = atoi(sstr);
  7357. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7358. {
  7359. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7360. }
  7361. else
  7362. {
  7363. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7364. }
  7365. }
  7366. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7367. //*********************startSchedule***************************/
  7368. loc = strstr(payload, "startSchedule");
  7369. if(loc != NULL)
  7370. {
  7371. c = 0;
  7372. memset(sstr ,0, sizeof(sstr) );
  7373. while (loc[3+strlen("startSchedule")+c] != '\"')
  7374. {
  7375. sstr[c] = loc[3+strlen("startSchedule")+c];
  7376. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7377. c++;
  7378. }
  7379. sstr[c] = '\0';
  7380. strcpy(startScheduleStr,sstr);
  7381. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7382. {
  7383. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7384. }
  7385. else
  7386. {
  7387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7388. }
  7389. }
  7390. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7391. //*********************chargingRateUnit***************************/
  7392. loc = strstr(payload, "chargingRateUnit");
  7393. if(loc != NULL)
  7394. {
  7395. c = 0;
  7396. memset(sstr ,0, sizeof(sstr) );
  7397. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7398. {
  7399. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7400. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7401. c++;
  7402. }
  7403. sstr[c] = '\0';
  7404. strcpy(chargingRateUnitStr,sstr);
  7405. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7406. {
  7407. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7408. }
  7409. else
  7410. {
  7411. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7412. }
  7413. }
  7414. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7415. //****************chargingSchedulePeriod count start*******************/
  7416. int what_len = strlen("startPeriod");
  7417. char *where = payload;
  7418. if (what_len)
  7419. while ((where = strstr(where, "startPeriod"))) {
  7420. where += what_len;
  7421. chargingSchedulePeriodCount++;
  7422. }
  7423. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7424. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7425. where = payload;
  7426. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7427. {
  7428. //****************startPeriod*******************/
  7429. c=0;
  7430. loc = strstr(where, "startPeriod");
  7431. memset(sstr ,0, sizeof(sstr) );
  7432. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7433. {
  7434. sstr[c] = loc[strlen("startPeriod")+2+c];
  7435. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7436. c++;
  7437. }
  7438. sstr[c] = '\0';
  7439. startPeriodInt[periodNums] = atoi(sstr);
  7440. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7441. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7442. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7443. {
  7444. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7445. }
  7446. else
  7447. {
  7448. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7449. }
  7450. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7451. //****************limit*******************/
  7452. c=0;
  7453. loc = strstr(where, "limit");
  7454. memset(sstr ,0, sizeof(sstr) );
  7455. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7456. {
  7457. sstr[c] = loc[strlen("limit")+2+c];
  7458. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7459. c++;
  7460. }
  7461. sstr[c] = '\0';
  7462. limitflaot[periodNums] = atof(sstr);
  7463. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7464. {
  7465. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7466. }
  7467. else
  7468. {
  7469. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7470. }
  7471. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7472. //****************numberPhases*******************/
  7473. loc = strstr(where, "numberPhases");
  7474. if(loc != NULL)
  7475. {
  7476. c=0;
  7477. memset(sstr ,0, sizeof(sstr) );
  7478. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7479. {
  7480. sstr[c] = loc[strlen("numberPhases")+2+c];
  7481. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7482. c++;
  7483. }
  7484. sstr[c] = '\0';
  7485. numberPhasesInt[periodNums] = atoi(sstr);
  7486. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7487. {
  7488. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7489. }
  7490. else
  7491. {
  7492. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7493. }
  7494. }
  7495. where = loc;
  7496. }
  7497. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7498. //****************chargingSchedulePeriod count end*******************/
  7499. //*********************minChargingRate***************************/
  7500. loc = strstr(payload, "minChargingRate");
  7501. if(loc != NULL)
  7502. {
  7503. c = 0;
  7504. memset(sstr ,0, sizeof(sstr) );
  7505. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7506. {
  7507. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7508. c++;
  7509. }
  7510. sstr[c] = '\0';
  7511. minChargingRateFloat = atof(sstr);
  7512. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7513. {
  7514. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7515. }
  7516. else
  7517. {
  7518. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7519. }
  7520. }
  7521. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7522. DEBUG_INFO("-------------------------------------------------------------\n");
  7523. DEBUG_INFO(" Input the file name to be opened : ");
  7524. //fgets(fname, MAX, stdin);
  7525. //fname[strlen(fname) - 1] = '\0';
  7526. #if 0
  7527. switch(connectorIdInt)
  7528. {
  7529. case 0:
  7530. strcpy(filename, ChargingProfile_0_JSON );
  7531. break;
  7532. case 1:
  7533. strcpy(filename, ChargingProfile_1_JSON );
  7534. break;
  7535. case 2:
  7536. strcpy(filename, ChargingProfile_2_JSON );
  7537. break;
  7538. default:
  7539. strcpy(filename, ChargingProfile_0_JSON );
  7540. break;
  7541. }
  7542. fptr1 = fopen(filename, "r");
  7543. if (!fptr1)
  7544. {
  7545. //file not exist
  7546. DEBUG_INFO("Unable to open the input file!!\n");
  7547. fptr1 = fopen(filename, "w+");
  7548. }
  7549. fclose(fptr1);
  7550. #endif
  7551. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7552. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7553. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7554. {
  7555. //printf("set chargingProfile 1-2\n");
  7556. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7557. if(connectorIdInt != 0)
  7558. {
  7559. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7560. goto end;
  7561. }
  7562. strcpy(filename, ChargePointMaxProfile_JSON );
  7563. fptr1 = fopen(filename, "r");
  7564. if (!fptr1)
  7565. {
  7566. //file not exist
  7567. DEBUG_INFO("Unable to open the input file!!\n");
  7568. fptr1 = fopen(filename, "w+");
  7569. }
  7570. fclose(fptr1);
  7571. }
  7572. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7573. {
  7574. //printf("set chargingProfile 1-3\n");
  7575. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7576. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7577. {
  7578. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7579. goto end;
  7580. }
  7581. switch(connectorIdInt)
  7582. {
  7583. case 0:
  7584. strcpy(filename, TxDefaultProfile_0_JSON );
  7585. break;
  7586. case 1:
  7587. strcpy(filename, TxDefaultProfile_1_JSON );
  7588. break;
  7589. case 2:
  7590. strcpy(filename, TxDefaultProfile_2_JSON );
  7591. break;
  7592. default:
  7593. strcpy(filename, TxDefaultProfile_0_JSON );
  7594. break;
  7595. }
  7596. fptr1 = fopen(filename, "r");
  7597. if (!fptr1)
  7598. {
  7599. //file not exist
  7600. DEBUG_INFO("Unable to open the input file!!\n");
  7601. fptr1 = fopen(filename, "w+");
  7602. }
  7603. fclose(fptr1);
  7604. }
  7605. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7606. {
  7607. //printf("set chargingProfile 1-4\n");
  7608. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7609. //check Transaction active
  7610. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7611. {
  7612. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7613. {
  7614. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7615. {
  7616. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7617. {
  7618. meet = TRUE;
  7619. break;
  7620. }
  7621. }
  7622. }
  7623. }
  7624. for (int index = 0; index < CCS_QUANTITY; index++)
  7625. {
  7626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7627. {
  7628. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7629. {
  7630. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7631. {
  7632. meet = TRUE;
  7633. break;
  7634. }
  7635. }
  7636. }
  7637. }
  7638. for (int index = 0; index < GB_QUANTITY; index++)
  7639. {
  7640. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7641. {
  7642. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7643. {
  7644. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7645. {
  7646. meet = TRUE;
  7647. break;
  7648. }
  7649. }
  7650. }
  7651. }
  7652. if(meet == FALSE)
  7653. {
  7654. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7655. goto end;
  7656. }
  7657. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7658. {
  7659. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7660. goto end;
  7661. }
  7662. switch(connectorIdInt)
  7663. {
  7664. case 0:
  7665. break;
  7666. case 1:
  7667. strcpy(filename, TxProfile_1_JSON);
  7668. break;
  7669. case 2:
  7670. strcpy(filename, TxProfile_2_JSON);
  7671. break;
  7672. default:
  7673. strcpy(filename, TxProfile_1_JSON);
  7674. break;
  7675. }
  7676. fptr1 = fopen(filename, "r");
  7677. if (!fptr1)
  7678. {
  7679. //file not exist
  7680. DEBUG_INFO("Unable to open the input file!!\n");
  7681. fptr1 = fopen(filename, "w+");
  7682. }
  7683. fclose(fptr1);
  7684. }
  7685. //**********************************Write to File********************************************************/
  7686. FILE *infile;
  7687. FILE *outfile;
  7688. // open file for writing
  7689. infile = fopen (filename, "r");
  7690. outfile = fopen (tempfile, "w");
  7691. int d =0;
  7692. d = fgetc(infile);
  7693. DEBUG_INFO("d:%d\n",d);
  7694. rewind(infile);
  7695. //*检测到文件结束标识返回1,否则返回0。*/
  7696. if(d == EOF)
  7697. {
  7698. DEBUG_INFO("ChargingProfile content is NULL\n");
  7699. fprintf(outfile,"[%s]\n",payload);
  7700. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7701. fclose(infile);
  7702. fclose(outfile);
  7703. sprintf(rmFileCmd,"rm -f %s",filename);
  7704. system(rmFileCmd);
  7705. resultRename = rename(tempfile, filename);
  7706. if(resultRename == 0)
  7707. {
  7708. DEBUG_INFO("File chargingProfile renamed successfully");
  7709. }
  7710. else
  7711. {
  7712. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7713. }
  7714. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7715. //system(rmFileCmd);
  7716. }
  7717. else
  7718. {
  7719. char buf[1000]={0};
  7720. while (fgets(buf, sizeof(buf), infile) != NULL)
  7721. {
  7722. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7723. //*************************tempconnectorIdInt*********************************/
  7724. loc = strstr(buf, "connectorId");
  7725. c = 0;
  7726. memset(sstr ,0, sizeof(sstr) );
  7727. while (loc[strlen("connectorId")+2+c] != ',')
  7728. {
  7729. sstr[c] = loc[strlen("connectorId")+2+c];
  7730. c++;
  7731. }
  7732. sstr[c] = '\0';
  7733. tempconnectorIdInt = atoi(sstr);
  7734. //*************************tempchargingProfileIdInt*********************************/
  7735. loc = strstr(buf, "chargingProfileId");
  7736. c = 0;
  7737. memset(sstr ,0, sizeof(sstr) );
  7738. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7739. {
  7740. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7741. c++;
  7742. }
  7743. sstr[c] = '\0';
  7744. tempchargingProfileIdInt = atoi(sstr);
  7745. //*************************tempstackLevelInt*********************************/
  7746. loc = strstr(buf, "stackLevel");
  7747. c = 0;
  7748. memset(sstr ,0, sizeof(sstr) );
  7749. while (loc[strlen("stackLevel")+2+c] != ',')
  7750. {
  7751. sstr[c] = loc[strlen("stackLevel")+2+c];
  7752. c++;
  7753. }
  7754. sstr[c] = '\0';
  7755. tempstackLevelInt = atoi(sstr);
  7756. //*************************tempchargingProfilePurposeStr*********************************/
  7757. loc = strstr(payload, "chargingProfilePurpose");
  7758. c = 0;
  7759. memset(sstr ,0, sizeof(sstr) );
  7760. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7761. {
  7762. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7763. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7764. c++;
  7765. }
  7766. sstr[c] = '\0';
  7767. strcpy(tempchargingProfilePurposeStr,sstr);
  7768. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7769. {
  7770. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7771. {
  7772. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7773. fprintf(outfile,"[%s]\n",payload);
  7774. }
  7775. else
  7776. {
  7777. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7778. if(tempstackLevelInt < stackLevelInt)
  7779. {
  7780. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7781. fprintf(outfile,"[%s]\n",payload);
  7782. fprintf(outfile,"[%s]\n",buf);
  7783. }
  7784. else
  7785. {
  7786. fprintf(outfile,"[%s]\n",buf);
  7787. fprintf(outfile,"[%s]\n",payload);
  7788. }
  7789. }
  7790. DEBUG_INFO("update set chargingProfile to file\n");
  7791. }
  7792. else
  7793. {
  7794. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7795. {
  7796. fprintf(outfile,"[%s]\n",payload);
  7797. fprintf(outfile,"[%s]\n",buf);
  7798. }
  7799. else if(tempstackLevelInt < stackLevelInt)
  7800. {
  7801. fprintf(outfile,"[%s]\n",payload);
  7802. fprintf(outfile,"[%s]\n",buf);
  7803. }
  7804. else
  7805. {
  7806. fprintf(outfile,"[%s]\n",buf);
  7807. fprintf(outfile,"[%s]\n",payload);
  7808. }
  7809. fprintf(outfile,"[%s]\n",buf);
  7810. DEBUG_INFO("add set chargingProfile to file\n");
  7811. }
  7812. } // end of while loop
  7813. fclose(infile);
  7814. fclose(outfile);
  7815. sprintf(rmFileCmd,"rm -f %s",filename);
  7816. system(rmFileCmd);
  7817. resultRename = rename(tempfile, filename);
  7818. if(resultRename == 0)
  7819. {
  7820. DEBUG_INFO("File chargingProfile renamed successfully");
  7821. }
  7822. else
  7823. {
  7824. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7825. }
  7826. result = TRUE;
  7827. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7828. }
  7829. end:
  7830. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7831. return result;
  7832. return result;
  7833. }
  7834. int handleTriggerMessageRequest(char *uuid, char *payload)
  7835. {
  7836. mtrace();
  7837. int result = FAIL;
  7838. int connectorIdIsNULL = FALSE;
  7839. int connectorIdInt =0;
  7840. char sstr[40]={0};
  7841. char requestedMessagestr[40]={0};
  7842. char comfirmstr[20]={0};
  7843. int c = 0;
  7844. char *loc;
  7845. DEBUG_INFO("handleTriggerMessageRequest\n");
  7846. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7847. c = 0;
  7848. loc = strstr(payload, "requestedMessage");
  7849. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7850. {
  7851. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7852. c++;
  7853. }
  7854. sstr[c] = '\0';
  7855. strcpy(requestedMessagestr, sstr);
  7856. c = 0;
  7857. loc = strstr(payload, "connectorId");
  7858. if(loc == NULL)
  7859. {
  7860. connectorIdIsNULL = TRUE;
  7861. }
  7862. else
  7863. {
  7864. memset(sstr ,0, sizeof(sstr) );
  7865. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7866. {
  7867. sstr[c] = loc[strlen("connectorId")+2+c];
  7868. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7869. c++;
  7870. }
  7871. sstr[c] = '\0';
  7872. connectorIdInt = atoi(sstr);
  7873. }
  7874. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7875. {
  7876. //connectorIdInt = json_object_get_int(connectorId);
  7877. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7878. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7879. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7880. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7881. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7882. }
  7883. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7884. {
  7885. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7886. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7887. return TRUE;
  7888. }
  7889. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7890. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7891. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7892. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7893. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7894. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7895. {
  7896. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7897. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7898. return TRUE;
  7899. }
  7900. else
  7901. {
  7902. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7903. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7904. }
  7905. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7906. {
  7907. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7908. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7909. }
  7910. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7911. {
  7912. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7913. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7914. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7915. }
  7916. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7917. {
  7918. sendBootNotificationRequest();
  7919. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7920. }
  7921. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7922. {
  7923. sendHeartbeatRequest(connectorIdInt);
  7924. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7925. }
  7926. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7927. {
  7928. if(connectorIdIsNULL == FALSE)
  7929. {
  7930. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7931. {
  7932. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7933. sendMeterValuesRequest(connectorIdInt -1);
  7934. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7935. }
  7936. }
  7937. else
  7938. {
  7939. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7940. {
  7941. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7942. sendMeterValuesRequest(idx);
  7943. }
  7944. }
  7945. }
  7946. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7947. {
  7948. if(connectorIdIsNULL == FALSE)
  7949. {
  7950. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7951. {
  7952. sendStatusNotificationRequest(connectorIdInt -1);
  7953. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7954. }
  7955. }
  7956. else
  7957. {
  7958. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7959. sendStatusNotificationRequest(idx);
  7960. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7961. }
  7962. }
  7963. return result;
  7964. }
  7965. int handleUnlockConnectorRequest(char *uuid, char *payload)
  7966. {
  7967. mtrace();
  7968. int result = FAIL;
  7969. char sstr[6]={0};
  7970. int connectorIdInt =0;
  7971. char comfirmstr[20]={0};
  7972. int c = 0;
  7973. char *loc;
  7974. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  7975. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  7976. c = 0;
  7977. loc = strstr(payload, "connectorId");
  7978. memset(sstr ,0, sizeof(sstr) );
  7979. while (loc[strlen("connectorId")+2+c] != '}')
  7980. {
  7981. sstr[c] = loc[strlen("connectorId")+2+c];
  7982. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7983. c++;
  7984. }
  7985. sstr[c] = '\0';
  7986. connectorIdInt = atoi(sstr);
  7987. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  7988. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  7989. {
  7990. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  7991. goto end;
  7992. }
  7993. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  7994. {
  7995. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  7996. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  7997. goto end;
  7998. }
  7999. else
  8000. {
  8001. //check Transaction active
  8002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8003. {
  8004. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8005. {
  8006. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8007. {
  8008. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8009. }
  8010. }
  8011. for (int index = 0; index < CCS_QUANTITY; index++)
  8012. {
  8013. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8014. {
  8015. //stop Transaction
  8016. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8017. }
  8018. }
  8019. for (int index = 0; index < GB_QUANTITY; index++)
  8020. {
  8021. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8022. {
  8023. //stop Transaction
  8024. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8025. }
  8026. }
  8027. }
  8028. else
  8029. {
  8030. for (int index = 0; index < AC_QUANTITY; index++)
  8031. {
  8032. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8033. {
  8034. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8035. }
  8036. }
  8037. }// END FOR AC ELSE
  8038. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8039. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8040. result = TRUE;
  8041. return result;
  8042. }
  8043. end:
  8044. //json_object_put(obj); --- remove temporally
  8045. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8046. return result;
  8047. }
  8048. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8049. {
  8050. mtrace();
  8051. int result = FAIL;
  8052. pthread_t t;
  8053. sendUpdateFirmwareConfirmation(uuid);
  8054. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8055. ////pthread_join(t, NULL); //
  8056. pthread_detach(t);
  8057. //sendUpdateFirmwareConfirmation(uuid);
  8058. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8059. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8060. return result;
  8061. }
  8062. void *UpdateFirmwareProcess(void *data)
  8063. {
  8064. mtrace();
  8065. int retriesInt =0, retryIntervalInt=0;
  8066. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8067. int port=0;
  8068. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8069. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8070. //char comfirmstr[20];
  8071. int isSuccess = 0;
  8072. char ftpbuf[200];
  8073. char temp[100];
  8074. char * pch;
  8075. int retriesISNULL=FALSE;
  8076. int retryInterval=FALSE;
  8077. int c = 0;
  8078. //int i = 0;
  8079. char *loc;
  8080. char sstr[300]={ 0 };
  8081. char *str = (char*) data; // ?��?輸入資�?
  8082. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8083. //***************location **************/
  8084. loc = strstr(str, "location");
  8085. memset(sstr ,0, sizeof(sstr) );
  8086. c = 0;
  8087. while (loc[3+strlen("location")+c] != '\"')
  8088. {
  8089. sstr[c] = loc[3+strlen("location")+c];
  8090. c++;
  8091. }
  8092. sstr[c] = '\0';
  8093. strcpy(locationstr, sstr);
  8094. //***************retries**************/
  8095. c = 0;
  8096. loc = strstr(str, "retries");
  8097. if(loc == NULL)
  8098. {
  8099. retriesISNULL=TRUE;
  8100. }
  8101. else
  8102. {
  8103. memset(sstr ,0, sizeof(sstr) );
  8104. while (loc[strlen("retries")+2+c] != ',')
  8105. {
  8106. sstr[c] = loc[strlen("retries")+2+c];
  8107. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8108. c++;
  8109. }
  8110. sstr[c] = '\0';
  8111. }
  8112. if(retriesISNULL == FALSE)
  8113. {
  8114. retriesInt = atoi(sstr);
  8115. }
  8116. //***************retrieveDate **************/
  8117. loc = strstr(str, "retrieveDate");
  8118. memset(sstr ,0, sizeof(sstr) );
  8119. c = 0;
  8120. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8121. {
  8122. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8123. c++;
  8124. }
  8125. sstr[c] = '\0';
  8126. strcpy(retrieveDatestr, sstr);
  8127. //***************retryInterval **************/
  8128. c = 0;
  8129. loc = strstr(str, "retryInterval");
  8130. memset(sstr ,0, sizeof(sstr) );
  8131. if(loc == NULL)
  8132. {
  8133. retryInterval=TRUE;
  8134. }
  8135. else
  8136. {
  8137. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8138. {
  8139. sstr[c] = loc[strlen("retryInterval")+2+c];
  8140. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8141. c++;
  8142. }
  8143. sstr[c] = '\0';
  8144. }
  8145. if(retryInterval==FALSE)
  8146. {
  8147. retryIntervalInt = atoi(sstr);
  8148. }
  8149. memset(ftppath, 0, sizeof(ftppath));
  8150. memset(path, 0, sizeof(path));
  8151. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8152. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8153. if(strncmp(locationstr,"http", 4) == 0)
  8154. {
  8155. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8156. protocol, host, path);
  8157. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8158. // protocol, user, password, host, path);
  8159. sprintf(ftppath,"/%s", path);
  8160. DEBUG_INFO("protocol =%s\n",protocol);
  8161. DEBUG_INFO("host =%s\n",host);
  8162. DEBUG_INFO("path =%s\n",path);
  8163. DEBUG_INFO("ftppath=%s\n",ftppath);
  8164. int ftppathlen=strlen(ftppath);
  8165. int i=1;
  8166. char filenametemp[50];
  8167. while(i < ftppathlen)
  8168. {
  8169. int len=ftppathlen-i;
  8170. if(ftppath[len]== 47) // '/' ascll code: 47
  8171. {
  8172. DEBUG_INFO("compare '/' all right\n");
  8173. break;
  8174. }
  8175. i=i+1;
  8176. }
  8177. memset(filenametemp, 0, sizeof(filenametemp));
  8178. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8179. filenametemp[i+1] = 0;
  8180. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8181. do{
  8182. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8183. sleep(retryIntervalInt);
  8184. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8185. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8186. if(!isSuccess)
  8187. {
  8188. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8189. }
  8190. else
  8191. {
  8192. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8193. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8194. isUpdateRequest = TRUE;
  8195. }
  8196. }
  8197. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8198. {
  8199. memset(ftpbuf, 0, sizeof(ftpbuf));
  8200. memset(temp, 0, sizeof(temp));
  8201. DEBUG_INFO("locationstr=%s\n",locationstr);
  8202. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8203. int ftppathlen=strlen(ftpbuf);
  8204. int i=1;
  8205. char filenametemp[50];
  8206. while(i < ftppathlen)
  8207. {
  8208. int len=ftppathlen-i;
  8209. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8210. {
  8211. DEBUG_INFO(" compare '/' all right\n");
  8212. break;
  8213. }
  8214. i=i+1;
  8215. }
  8216. memset(filenametemp, 0, sizeof(filenametemp));
  8217. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8218. filenametemp[i+1] = 0;
  8219. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8220. pch=strchr(temp,'@');
  8221. if(pch==NULL)
  8222. {
  8223. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8224. protocol, host, &port, path);
  8225. strcpy(user,"anonymous");
  8226. strcpy(password,"");
  8227. }
  8228. else
  8229. {
  8230. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8231. protocol, user, password, host, &port, path);
  8232. }
  8233. sscanf(host,"%[^/]%s",host1, path1);
  8234. sprintf(ftppath,"%s", path1);
  8235. DEBUG_INFO("protocol =%s\n",protocol);
  8236. DEBUG_INFO("user =%s\n",user);
  8237. DEBUG_INFO("password =%s\n",password);
  8238. DEBUG_INFO("host1 =%s\n",host1);
  8239. DEBUG_INFO("port =%d\n",port);
  8240. DEBUG_INFO("path1 =%s\n",path1);
  8241. DEBUG_INFO("ftppath=%s\n",ftppath);
  8242. //ftpFile(host, user, password, port, ftppath, fname);
  8243. //download firmware pthred
  8244. if(port == 0)
  8245. {
  8246. port = 21;
  8247. }
  8248. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8249. do{
  8250. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8251. sleep(retryIntervalInt);
  8252. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8253. if(!isSuccess)
  8254. {
  8255. //BulldogUtil.sleepMs(interval*1000);
  8256. DEBUG_INFO("Update firmware request and download file fail.\n");
  8257. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8258. }
  8259. else
  8260. {
  8261. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8262. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8263. isUpdateRequest = TRUE;
  8264. }
  8265. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8266. }
  8267. else
  8268. {
  8269. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8270. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8271. }
  8272. pthread_exit(NULL);
  8273. }
  8274. //==========================================
  8275. // Handle server response routine
  8276. //==========================================
  8277. void handleAuthorizeResponse(char *payload, int gun_index)
  8278. {
  8279. mtrace();
  8280. char expiryDatestr[30]={0};
  8281. char parentIdTagstr[20]={0};
  8282. char statusstr[20]={0};
  8283. char expiryDatestrtemp[30]={0};
  8284. char parentIdTagstrtemp[20]={0};
  8285. char IdTagstrtemp[20]={0};
  8286. char statusstrtemp[20]={0};
  8287. int expiryDateISNULL=FALSE;
  8288. int parentIdTagISNULL=FALSE;
  8289. char sstr[160]={ 0 };
  8290. char* filename = AuthorizationCache_JSON;
  8291. char tempfile[] = "../Storage/OCPP/temp.json";
  8292. int c = 0;
  8293. char *loc;
  8294. int resultRename=0;
  8295. int responseIdTagInfoAsZero= 0;
  8296. char rmFileCmd[50]={0};
  8297. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8298. //***********expiryDate*************/
  8299. loc = strstr(payload, "expiryDate");
  8300. memset(sstr ,0, sizeof(sstr) );
  8301. c = 0;
  8302. if(loc == NULL)
  8303. {
  8304. expiryDateISNULL = TRUE;
  8305. }
  8306. else
  8307. {
  8308. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8309. {
  8310. sstr[c] = loc[3+strlen("expiryDate")+c];
  8311. c++;
  8312. }
  8313. sstr[c] = '\0';
  8314. strcpy(expiryDatestr, sstr);
  8315. }
  8316. //***********parentIdTag*************/
  8317. loc = strstr(payload, "parentIdTag");
  8318. memset(sstr ,0, sizeof(sstr) );
  8319. c = 0;
  8320. if(loc == NULL)
  8321. {
  8322. parentIdTagISNULL = TRUE;
  8323. }
  8324. else
  8325. {
  8326. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8327. {
  8328. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8329. c++;
  8330. }
  8331. sstr[c] = '\0';
  8332. strcpy(parentIdTagstr, sstr);
  8333. }
  8334. //***********status*************/
  8335. loc = strstr(payload, "status");
  8336. memset(sstr ,0, sizeof(sstr) );
  8337. c = 0;
  8338. while (loc[3+strlen("status")+c] != '\"')
  8339. {
  8340. sstr[c] = loc[3+strlen("status")+c];
  8341. c++;
  8342. }
  8343. sstr[c] = '\0';
  8344. strcpy(statusstr, sstr);
  8345. //#ifdef SystemLogMessage
  8346. // if(expiryDateISNULL == FALSE)
  8347. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8348. // if(parentIdTagISNULL == FALSE)
  8349. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8350. // DEBUG_INFO("status: %s\n", statusstr);
  8351. //#endif
  8352. if(expiryDateISNULL == FALSE)
  8353. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8354. if(parentIdTagISNULL == FALSE)
  8355. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8356. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8357. //Update idTag information to authorization cache if supproted
  8358. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8359. {
  8360. if((access(filename,F_OK))!=-1)
  8361. {
  8362. DEBUG_INFO("AuthorizationCache exist.\n");
  8363. }
  8364. else
  8365. {
  8366. DEBUG_INFO("AuthorizationCache not exist\n");
  8367. FILE *log = fopen(filename, "w+");
  8368. if(log == NULL)
  8369. {
  8370. DEBUG_INFO("log is NULL\n");
  8371. goto out;
  8372. }
  8373. else
  8374. {
  8375. fclose(log);
  8376. }
  8377. }
  8378. FILE *infile;
  8379. FILE *outfile;
  8380. // open file for writing
  8381. infile = fopen (filename, "r");
  8382. outfile = fopen (tempfile, "w");
  8383. //*检测到文件结束标识返回1,否则返回0。*/
  8384. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8385. int c;
  8386. c = fgetc(infile);
  8387. //DEBUG_INFO("c:%d\n",c);
  8388. rewind(infile);
  8389. if(c == EOF)
  8390. {
  8391. DEBUG_INFO("Orignal File is NULL\n");
  8392. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8393. {
  8394. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8395. }
  8396. else
  8397. {
  8398. strcpy(expiryDatestrtemp, "");
  8399. }
  8400. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8401. {
  8402. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8403. }
  8404. else
  8405. {
  8406. //write Authorize IdTag
  8407. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8408. }
  8409. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8410. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8411. fclose(infile);
  8412. fclose(outfile);
  8413. sprintf(rmFileCmd,"rm -f %s",filename);
  8414. system(rmFileCmd);
  8415. resultRename = rename(tempfile, filename);
  8416. if(resultRename == 0)
  8417. {
  8418. DEBUG_INFO("File renamed successfully");
  8419. }
  8420. else
  8421. {
  8422. DEBUG_INFO("Error: unable to rename the file");
  8423. }
  8424. }
  8425. else
  8426. {
  8427. char buf[160]={0};
  8428. //DEBUG_INFO("Orignal File is not NULL\n");
  8429. while (fgets(buf, sizeof(buf), infile) != NULL)
  8430. {
  8431. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8432. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8433. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8434. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8435. memset(statusstr, 0, sizeof(statusstrtemp));
  8436. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8437. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8438. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8439. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8440. //------------------IdTag-----------------------
  8441. loc = strstr(buf, "idTag");
  8442. memset(sstr ,0, sizeof(sstr) );
  8443. c = 0;
  8444. while (loc[3+strlen("idTag")+c] != '\"')
  8445. {
  8446. sstr[c] = loc[3+strlen("idTag")+c];
  8447. c++;
  8448. }
  8449. sstr[c] = '\0';
  8450. strcpy(IdTagstrtemp,sstr);
  8451. //*********************expiryDate***************/
  8452. loc = strstr(buf, "expiryDate");
  8453. memset(sstr ,0, sizeof(sstr) );
  8454. c = 0;
  8455. while (loc[3+strlen("expiryDate")+c] != '\"')
  8456. {
  8457. sstr[c] = loc[3+strlen("expiryDate")+c];
  8458. c++;
  8459. }
  8460. sstr[c] = '\0';
  8461. strcpy(expiryDatestr,sstr);
  8462. //*********************parentIdTag***************/
  8463. loc = strstr(buf, "parentIdTag");
  8464. memset(sstr ,0, sizeof(sstr) );
  8465. c = 0;
  8466. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8467. {
  8468. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8469. c++;
  8470. }
  8471. sstr[c] = '\0';
  8472. strcpy(parentIdTagstr,sstr);
  8473. //*********************status***************/
  8474. loc = strstr(buf, "status");
  8475. memset(sstr ,0, sizeof(sstr) );
  8476. c = 0;
  8477. while (loc[3+strlen("status")+c] != '\"')
  8478. {
  8479. sstr[c] = loc[3+strlen("status")+c];
  8480. c++;
  8481. }
  8482. sstr[c] = '\0';
  8483. strcpy(statusstr,sstr);
  8484. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8485. {
  8486. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8487. responseIdTagInfoAsZero = 1;
  8488. }
  8489. else
  8490. {
  8491. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8492. }
  8493. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8494. {
  8495. //modify item
  8496. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8497. {
  8498. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8499. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8500. }
  8501. else
  8502. {
  8503. strcpy(expiryDatestrtemp, "");
  8504. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8505. }
  8506. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8507. {
  8508. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8509. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8510. }
  8511. else
  8512. {
  8513. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8514. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8515. }
  8516. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8517. }
  8518. else
  8519. {
  8520. //wrie original item
  8521. strcpy(expiryDatestrtemp, expiryDatestr);
  8522. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8523. strcpy(statusstrtemp, statusstr);
  8524. }
  8525. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8526. }
  8527. fclose(infile);
  8528. fclose(outfile);
  8529. sprintf(rmFileCmd,"rm -f %s",filename);
  8530. system(rmFileCmd);
  8531. resultRename = rename(tempfile, filename);
  8532. if(resultRename == 0)
  8533. {
  8534. DEBUG_INFO("File renamed successfully");
  8535. }
  8536. else
  8537. {
  8538. DEBUG_INFO("Error: unable to rename the file");
  8539. }
  8540. }
  8541. }
  8542. out:
  8543. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8544. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8545. authorizeRetryTimes = 0;
  8546. }
  8547. void handleBootNotificationResponse(char *payload, int gun_index)
  8548. {
  8549. mtrace();
  8550. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8551. char statusStr[12]={0};
  8552. char currentTimeStr[30]={0};
  8553. char *loc;
  8554. int intervalInt = 0;
  8555. int c = 0;
  8556. //double diff_t;
  8557. struct tm tp;
  8558. char buf[28]={0};
  8559. char timebuf[50]={0};
  8560. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8561. //*** interval ****/
  8562. c = 0;
  8563. loc = strstr(payload, "interval");
  8564. //printf("loc=%s\n",loc);
  8565. memset(sstr ,0, sizeof(sstr) );
  8566. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8567. {
  8568. sstr[c] = loc[strlen("interval")+2+c];
  8569. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8570. c++;
  8571. }
  8572. sstr[c] = '\0';
  8573. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8574. intervalInt = atoi(sstr);
  8575. //***status ****/
  8576. loc = strstr(payload, "status");
  8577. memset(sstr ,0, sizeof(sstr) );
  8578. c = 0;
  8579. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8580. {
  8581. sstr[c] = loc[3+strlen("status")+c];
  8582. c++;
  8583. }
  8584. sstr[c] = '\0';
  8585. strcpy(statusStr, sstr);
  8586. //***currentTime ****/
  8587. loc = strstr(payload, "currentTime");
  8588. //printf("loc=%s\n",loc);
  8589. memset(sstr ,0, sizeof(sstr) );
  8590. c = 0;
  8591. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8592. {
  8593. sstr[c] = loc[3+strlen("currentTime")+c];
  8594. c++;
  8595. }
  8596. sstr[c] = '\0';
  8597. strcpy(currentTimeStr, sstr);
  8598. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8599. HeartBeatWaitTime = BootNotificationInterval;
  8600. //#ifdef SystemLogMessage
  8601. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8602. // DEBUG_INFO("interval: %d\n", intervalInt);
  8603. // DEBUG_INFO("status: %s\n", statusStr);
  8604. //#endif
  8605. //write back to ShmOCPP16Data->BootNotification
  8606. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8607. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8608. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8609. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8610. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8611. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8612. {
  8613. server_sign = TRUE;
  8614. server_pending =FALSE;
  8615. }
  8616. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8617. {
  8618. server_pending = TRUE;
  8619. }
  8620. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8621. tp.tm_isdst = -1;
  8622. //time_t utc = mktime(&tp);
  8623. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8624. memset(timebuf, 0, sizeof timebuf);
  8625. sprintf(timebuf,"date -s '%s'",buf);
  8626. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8627. system(timebuf);
  8628. //==============================================
  8629. // RTC sync
  8630. //==============================================
  8631. system("/sbin/hwclock -w --systohc");
  8632. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8633. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8634. }
  8635. void handleDataTransferResponse(char *payload, int gun_index)
  8636. {
  8637. char sstr[160]={0};//sstr[200]={ 0 };
  8638. int c = 0;
  8639. char *loc;
  8640. DEBUG_INFO("handleDataTransferResponse ...\n");
  8641. loc = strstr(payload, "status");
  8642. printf("loc=%s\n",loc);
  8643. c = 0;
  8644. while (loc[3+strlen("status")+c] != '\"')
  8645. {
  8646. sstr[c] = loc[3+strlen("status")+c];
  8647. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8648. c++;
  8649. }
  8650. sstr[c] = '\0';
  8651. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8652. //#ifdef SystemLogMessage
  8653. //DEBUG_INFO("data: %s\n", payload);
  8654. //#endif
  8655. }
  8656. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8657. {
  8658. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8659. //struct json_object *obj;
  8660. // obj = json_tokener_parse(payload);
  8661. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8662. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8663. //No fields are defined.
  8664. }
  8665. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8666. {
  8667. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8668. //struct json_object *obj;
  8669. // obj = json_tokener_parse(payload);
  8670. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8671. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8672. //No fields are defined.
  8673. }
  8674. void handleHeartbeatResponse(char *payload, int gun_index)
  8675. {
  8676. mtrace();
  8677. //double diff_t;
  8678. struct tm tp;
  8679. char buf[28]={0};
  8680. char timebuf[50]={0};
  8681. char sstr[30]={ 0 };
  8682. int c = 0;
  8683. char *loc;
  8684. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8685. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8686. c = 0;
  8687. loc = strstr(payload, "currentTime");
  8688. memset(sstr ,0, sizeof(sstr) );
  8689. while (loc[3+strlen("currentTime")+c] != '\"')
  8690. {
  8691. sstr[c] = loc[3+strlen("currentTime")+c];
  8692. c++;
  8693. }
  8694. sstr[c] = '\0';
  8695. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8696. // #ifdef SystemLogMessage
  8697. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8698. // #endif
  8699. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8700. tp.tm_isdst = -1;
  8701. //time_t utc = mktime(&tp);
  8702. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8703. memset(timebuf, 0, sizeof timebuf);
  8704. sprintf(timebuf,"date -s '%s'",buf);
  8705. system(timebuf);
  8706. //==============================================
  8707. // RTC sync
  8708. //==============================================
  8709. system("/sbin/hwclock -w --systohc");
  8710. if(FirstHeartBeat == 0)
  8711. {
  8712. FirstHeartBeat = 1;
  8713. }
  8714. }
  8715. void handleMeterValuesResponse(char *payload, int gun_index)
  8716. {
  8717. mtrace();
  8718. //struct json_object *obj;
  8719. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8720. //No fields are defined.
  8721. }
  8722. void handleStartTransactionResponse(char *payload, int gun_index)
  8723. {
  8724. mtrace();
  8725. char sstr[30]={ 0 };
  8726. int c = 0;
  8727. char *loc;
  8728. int transactionIdInt = 0;
  8729. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8730. DEBUG_INFO("handleStartTransactionResponse\n");
  8731. //****************expiryDate********************/
  8732. loc = strstr(payload, "expiryDate");
  8733. if(loc == NULL)
  8734. {
  8735. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8736. }
  8737. else
  8738. {
  8739. c = 0;
  8740. memset(sstr ,0, sizeof(sstr) );
  8741. while (loc[3+strlen("expiryDate")+c] != '\"')
  8742. {
  8743. sstr[c] = loc[3+strlen("expiryDate")+c];
  8744. c++;
  8745. }
  8746. sstr[c] = '\0';
  8747. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8748. }
  8749. //****************parentIdTag********************/
  8750. loc = strstr(payload, "parentIdTag");
  8751. if(loc == NULL)
  8752. {
  8753. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8754. }
  8755. else
  8756. {
  8757. c = 0;
  8758. memset(sstr ,0, sizeof(sstr) );
  8759. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8760. {
  8761. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8762. c++;
  8763. }
  8764. sstr[c] = '\0';
  8765. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8766. }
  8767. //****************status********************/
  8768. loc = strstr(payload, "status");
  8769. if(loc == NULL)
  8770. {
  8771. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8772. }
  8773. else
  8774. {
  8775. c = 0;
  8776. memset(sstr ,0, sizeof(sstr) );
  8777. while (loc[3+strlen("status")+c] != '\"')
  8778. {
  8779. sstr[c] = loc[3+strlen("status")+c];
  8780. c++;
  8781. }
  8782. sstr[c] = '\0';
  8783. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8784. }
  8785. //****************transactionId********************/
  8786. c=0;
  8787. loc = strstr(payload, "transactionId");
  8788. memset(sstr ,0, sizeof(sstr) );
  8789. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8790. {
  8791. sstr[c] = loc[strlen("transactionId")+2+c];
  8792. c++;
  8793. }
  8794. sstr[c] = '\0';
  8795. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8796. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8797. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8798. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8799. #ifdef SystemLogMessage
  8800. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8801. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8802. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8803. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8804. #endif
  8805. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8806. {
  8807. //add Charging Record
  8808. SettingChargingRecord(gun_index, transactionIdInt);
  8809. }
  8810. }
  8811. void handleStatusNotificationResponse(char *payload, int gun_index)
  8812. {
  8813. mtrace();
  8814. printf("handleStatusNotificationResponse\n");
  8815. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8816. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8817. }
  8818. void handleStopTransactionnResponse(char *payload, int gun_index)
  8819. {
  8820. mtrace();
  8821. char sstr[30]={ 0 };
  8822. int c = 0;
  8823. char *loc;
  8824. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8825. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8826. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8827. loc = strstr(payload, "idTagInfo");
  8828. //***********************idTagInfo************************/
  8829. if(loc != NULL)
  8830. {
  8831. //***********************expiryDate************************/
  8832. loc = strstr(payload, "expiryDate");
  8833. if(loc != NULL)
  8834. {
  8835. memset(sstr ,0, sizeof(sstr) );
  8836. c = 0;
  8837. while (loc[3+strlen("expiryDate")+c] != '\"')
  8838. {
  8839. sstr[c] = loc[3+strlen("expiryDate")+c];
  8840. c++;
  8841. }
  8842. sstr[c] = '\0';
  8843. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8844. }
  8845. //***********************parentIdTag************************/
  8846. loc = strstr(payload, "parentIdTag");
  8847. if(loc != NULL)
  8848. {
  8849. memset(sstr ,0, sizeof(sstr) );
  8850. c = 0;
  8851. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8852. {
  8853. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8854. c++;
  8855. }
  8856. sstr[c] = '\0';
  8857. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8858. }
  8859. //***********************status************************/
  8860. loc = strstr(payload, "status");
  8861. memset(sstr ,0, sizeof(sstr) );
  8862. c = 0;
  8863. while (loc[3+strlen("status")+c] != '\"')
  8864. {
  8865. sstr[c] = loc[3+strlen("status")+c];
  8866. c++;
  8867. }
  8868. sstr[c] = '\0';
  8869. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8870. }
  8871. #ifdef SystemLogMessage
  8872. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8873. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8874. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8875. #endif
  8876. }
  8877. //==========================================
  8878. // Handle Error routine
  8879. //==========================================
  8880. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8881. {
  8882. mtrace();
  8883. #ifdef SystemLogMessage
  8884. DEBUG_INFO("errorCode: %s\n", errorCode);
  8885. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8886. DEBUG_INFO("errorDetails: %s\n", payload);
  8887. #endif
  8888. }
  8889. //===============================================
  8890. // Common routine
  8891. //===============================================
  8892. int initialConfigurationTable(void)
  8893. {
  8894. printf("initialConfigurationTable \n");
  8895. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8896. /*Core Profile*/
  8897. //AllowOfflineTxForUnknownId
  8898. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8899. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8902. //AuthorizationCacheEnabled
  8903. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8906. //AuthorizeRemoteTxRequests
  8907. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8910. //BlinkRepeat
  8911. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8914. //ClockAlignedDataInterval
  8915. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8918. //ConnectionTimeOut
  8919. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8922. //GetConfigurationMaxKeys
  8923. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8926. // HeartbeatInterval
  8927. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8930. // LightIntensity
  8931. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8934. // LocalAuthorizeOffline
  8935. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  8936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8938. // LocalPreAuthorize
  8939. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  8940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8942. // MaxEnergyOnInvalidId
  8943. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  8945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  8946. // MeterValuesAlignedData
  8947. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  8948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  8949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  8950. // MeterValuesAlignedDataMaxLength
  8951. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  8952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  8953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  8954. // MeterValuesSampledData
  8955. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  8956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  8957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  8958. // MeterValuesSampledDataMaxLength
  8959. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  8960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  8961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  8962. // MeterValueSampleInterval
  8963. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  8964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  8965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  8966. // MinimumStatusDuration
  8967. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  8968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  8969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  8970. // NumberOfConnectors
  8971. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  8972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  8973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  8974. // ResetRetries
  8975. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  8976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  8977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  8978. // ConnectorPhaseRotation
  8979. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  8980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  8981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  8982. // ConnectorPhaseRotationMaxLength
  8983. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  8984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  8985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  8986. // StopTransactionOnEVSideDisconnect
  8987. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  8988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  8989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  8990. // StopTransactionOnInvalidId
  8991. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  8992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  8993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  8994. // StopTxnAlignedData
  8995. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  8996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  8997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  8998. // StopTxnAlignedDataMaxLength
  8999. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9002. // StopTxnSampledData
  9003. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9006. // StopTxnSampledDataMaxLength
  9007. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9010. // SupportedFeatureProfiles
  9011. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9014. // SupportedFeatureProfilesMaxLength
  9015. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9018. // TransactionMessageAttempts
  9019. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9022. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9023. // TransactionMessageRetryInterval
  9024. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9027. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9028. // UnlockConnectorOnEVSideDisconnect
  9029. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9032. // WebSocketPingInterval
  9033. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9036. //* Local Auth List Management Profile*/
  9037. #if 0
  9038. //For OCTT Test Case
  9039. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9042. #endif
  9043. #if 1
  9044. //LocalAuthListEnabled
  9045. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9048. #endif
  9049. //LocalAuthListMaxLength
  9050. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9053. //SendLocalListMaxLength
  9054. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9057. //ReserveConnectorZeroSupported
  9058. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9061. //* Smart Charging Profile */
  9062. //ChargeProfileMaxStackLevel
  9063. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9066. // ChargingScheduleAllowedChargingRateUnit
  9067. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9070. // ChargingScheduleMaxPeriods
  9071. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9074. // ConnectorSwitch3to1PhaseSupported
  9075. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9078. // MaxChargingProfilesInstalled
  9079. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9082. return 0;
  9083. }
  9084. void getKeyValue(char *keyReq)
  9085. {
  9086. int isEmpty = FALSE;
  9087. int isKnowKey = FALSE;
  9088. //int unKnowIndex = 0;
  9089. DEBUG_INFO("getKeyValue \n");
  9090. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9091. isEmpty = TRUE;
  9092. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9093. {
  9094. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9097. {
  9098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9099. }
  9100. else
  9101. {
  9102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9103. }
  9104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9105. isKnowKey = TRUE;
  9106. }
  9107. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9108. {
  9109. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9112. {
  9113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9114. }
  9115. else
  9116. {
  9117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9118. }
  9119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9120. isKnowKey = TRUE;
  9121. }
  9122. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9123. {
  9124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9127. {
  9128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9129. }
  9130. else
  9131. {
  9132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9133. }
  9134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9135. isKnowKey = TRUE;
  9136. }
  9137. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9138. {
  9139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9142. {
  9143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9144. }
  9145. else
  9146. {
  9147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9148. }
  9149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9150. isKnowKey = TRUE;
  9151. }
  9152. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9153. {
  9154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9157. {
  9158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9159. }
  9160. else
  9161. {
  9162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9163. }
  9164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9165. isKnowKey = TRUE;
  9166. }
  9167. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9168. {
  9169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9172. {
  9173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9174. }
  9175. else
  9176. {
  9177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9178. }
  9179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9180. isKnowKey = TRUE;
  9181. }
  9182. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9183. {
  9184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9187. {
  9188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9189. }
  9190. else
  9191. {
  9192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9193. }
  9194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9195. isKnowKey = TRUE;
  9196. }
  9197. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9198. {
  9199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9202. {
  9203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9204. }
  9205. else
  9206. {
  9207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9208. }
  9209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9210. isKnowKey = TRUE;
  9211. }
  9212. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9213. {
  9214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9217. {
  9218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9219. }
  9220. else
  9221. {
  9222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9223. }
  9224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9225. isKnowKey = TRUE;
  9226. }
  9227. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9228. {
  9229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9232. {
  9233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9234. }
  9235. else
  9236. {
  9237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9238. }
  9239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9240. isKnowKey = TRUE;
  9241. }
  9242. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9243. {
  9244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9247. {
  9248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9249. }
  9250. else
  9251. {
  9252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9253. }
  9254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9255. isKnowKey = TRUE;
  9256. }
  9257. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9258. {
  9259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9262. {
  9263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9264. }
  9265. else
  9266. {
  9267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9268. }
  9269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9270. isKnowKey = TRUE;
  9271. }
  9272. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9273. {
  9274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9277. {
  9278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9279. }
  9280. else
  9281. {
  9282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9283. }
  9284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9285. isKnowKey = TRUE;
  9286. }
  9287. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9288. {
  9289. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9292. {
  9293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9294. }
  9295. else
  9296. {
  9297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9298. }
  9299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9300. isKnowKey = TRUE;
  9301. }
  9302. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9303. {
  9304. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9307. {
  9308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9309. }
  9310. else
  9311. {
  9312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9313. }
  9314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9315. isKnowKey = TRUE;
  9316. }
  9317. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9318. {
  9319. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9322. {
  9323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9324. }
  9325. else
  9326. {
  9327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9328. }
  9329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9330. isKnowKey = TRUE;
  9331. }
  9332. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9333. {
  9334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9337. {
  9338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9339. }
  9340. else
  9341. {
  9342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9343. }
  9344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9345. isKnowKey = TRUE;
  9346. }
  9347. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9348. {
  9349. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9352. {
  9353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9354. }
  9355. else
  9356. {
  9357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9358. }
  9359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9360. isKnowKey = TRUE;
  9361. }
  9362. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9363. {
  9364. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9367. {
  9368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9369. }
  9370. else
  9371. {
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9373. }
  9374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9375. isKnowKey = TRUE;
  9376. }
  9377. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9378. {
  9379. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9382. {
  9383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9384. }
  9385. else
  9386. {
  9387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9388. }
  9389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9390. isKnowKey = TRUE;
  9391. }
  9392. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9393. {
  9394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9397. {
  9398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9399. }
  9400. else
  9401. {
  9402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9403. }
  9404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9405. isKnowKey = TRUE;
  9406. }
  9407. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9408. {
  9409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9412. {
  9413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9414. }
  9415. else
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9418. }
  9419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9420. isKnowKey = TRUE;
  9421. }
  9422. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9423. {
  9424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9427. {
  9428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9429. }
  9430. else
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9433. }
  9434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9435. isKnowKey = TRUE;
  9436. }
  9437. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9438. {
  9439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9442. {
  9443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9444. }
  9445. else
  9446. {
  9447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9448. }
  9449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9450. isKnowKey = TRUE;
  9451. }
  9452. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9453. {
  9454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9457. {
  9458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9459. }
  9460. else
  9461. {
  9462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9463. }
  9464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9465. isKnowKey = TRUE;
  9466. }
  9467. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9468. {
  9469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9472. {
  9473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9474. }
  9475. else
  9476. {
  9477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9478. }
  9479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9480. isKnowKey = TRUE;
  9481. }
  9482. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9483. {
  9484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9487. {
  9488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9489. }
  9490. else
  9491. {
  9492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9493. }
  9494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9495. isKnowKey = TRUE;
  9496. }
  9497. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9498. {
  9499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9502. {
  9503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9504. }
  9505. else
  9506. {
  9507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9508. }
  9509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9510. isKnowKey = TRUE;
  9511. }
  9512. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9513. {
  9514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9517. {
  9518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9519. }
  9520. else
  9521. {
  9522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9523. }
  9524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9525. isKnowKey = TRUE;
  9526. }
  9527. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9528. {
  9529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9532. {
  9533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9534. }
  9535. else
  9536. {
  9537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9538. }
  9539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9540. isKnowKey = TRUE;
  9541. }
  9542. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9543. {
  9544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9547. {
  9548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9549. }
  9550. else
  9551. {
  9552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9553. }
  9554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9555. isKnowKey = TRUE;
  9556. }
  9557. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9558. {
  9559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9562. {
  9563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9564. }
  9565. else
  9566. {
  9567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9568. }
  9569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9570. isKnowKey = TRUE;
  9571. }
  9572. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9573. {
  9574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9577. {
  9578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9579. }
  9580. else
  9581. {
  9582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9583. }
  9584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9585. isKnowKey = TRUE;
  9586. }
  9587. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9588. {
  9589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9592. {
  9593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9594. }
  9595. else
  9596. {
  9597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9598. }
  9599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9600. isKnowKey = TRUE;
  9601. }
  9602. #if 0
  9603. //For OCTT Test Case
  9604. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9605. {
  9606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9608. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9609. {
  9610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9611. }
  9612. else
  9613. {
  9614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9615. }
  9616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9617. isKnowKey = TRUE;
  9618. }
  9619. #endif
  9620. #if 1
  9621. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9622. {
  9623. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9625. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9626. {
  9627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9628. }
  9629. else
  9630. {
  9631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9632. }
  9633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9634. isKnowKey = TRUE;
  9635. }
  9636. #endif
  9637. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9638. {
  9639. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9641. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9642. {
  9643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9644. }
  9645. else
  9646. {
  9647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9648. }
  9649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9650. isKnowKey = TRUE;
  9651. }
  9652. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9653. {
  9654. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9656. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9657. {
  9658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9659. }
  9660. else
  9661. {
  9662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9663. }
  9664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9665. isKnowKey = TRUE;
  9666. }
  9667. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9668. {
  9669. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9671. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9672. {
  9673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9674. }
  9675. else
  9676. {
  9677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9678. }
  9679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9680. isKnowKey = TRUE;
  9681. }
  9682. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9683. {
  9684. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9686. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9687. {
  9688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9689. }
  9690. else
  9691. {
  9692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9693. }
  9694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9695. isKnowKey = TRUE;
  9696. }
  9697. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9698. {
  9699. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9701. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9702. {
  9703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9704. }
  9705. else
  9706. {
  9707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9708. }
  9709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9710. isKnowKey = TRUE;
  9711. }
  9712. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9713. {
  9714. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9716. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9717. {
  9718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9719. }
  9720. else
  9721. {
  9722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9723. }
  9724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9725. isKnowKey = TRUE;
  9726. }
  9727. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9728. {
  9729. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9731. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9732. {
  9733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9734. }
  9735. else
  9736. {
  9737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9738. }
  9739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9740. isKnowKey = TRUE;
  9741. }
  9742. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9743. {
  9744. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9746. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9747. {
  9748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9749. }
  9750. else
  9751. {
  9752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9753. }
  9754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9755. isKnowKey = TRUE;
  9756. }
  9757. //=========================================================
  9758. if(!isEmpty && !isKnowKey)
  9759. {
  9760. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9761. strcpy(unknownkey[UnknownKeynum], keyReq);
  9762. UnknownKeynum = UnknownKeynum + 1;
  9763. }
  9764. }
  9765. void processUnkownKey(void)
  9766. {
  9767. DEBUG_INFO("processUnkownKey\n");
  9768. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9769. for(int index=0; index < UnknownKeynum; index++)
  9770. {
  9771. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9772. {
  9773. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9774. }
  9775. }
  9776. }
  9777. int setKeyValue(char *key, char *value)
  9778. {
  9779. int isSuccess = NotSupported;
  9780. int check_ascii=0;
  9781. #ifdef Debug
  9782. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9783. #endif
  9784. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9785. {
  9786. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9788. {
  9789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9790. isSuccess = ConfigurationStatus_Accepted;
  9791. }
  9792. else
  9793. {
  9794. isSuccess = ConfigurationStatus_Rejected;
  9795. }
  9796. }
  9797. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9798. {
  9799. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9801. {
  9802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9803. isSuccess = ConfigurationStatus_Accepted;
  9804. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9805. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9806. }
  9807. else
  9808. {
  9809. isSuccess = ConfigurationStatus_Rejected;
  9810. }
  9811. }
  9812. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9813. {
  9814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9815. {
  9816. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9818. isSuccess = ConfigurationStatus_Accepted;
  9819. }
  9820. else
  9821. {
  9822. isSuccess = ConfigurationStatus_Rejected;
  9823. }
  9824. }
  9825. if(strcmp(key, "BlinkRepeat") == 0)
  9826. {
  9827. //Charger.BlinkRepeat = Integer.parseInt(value);
  9828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9829. {
  9830. check_ascii = value[0];
  9831. if( (check_ascii < 48) || (check_ascii > 57) )
  9832. {
  9833. isSuccess = ConfigurationStatus_Rejected;
  9834. }
  9835. else
  9836. {
  9837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9838. isSuccess = ConfigurationStatus_Accepted;
  9839. }
  9840. }
  9841. else
  9842. {
  9843. isSuccess = ConfigurationStatus_Rejected;
  9844. }
  9845. }
  9846. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9847. {
  9848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9849. {
  9850. check_ascii = value[0];
  9851. if( (check_ascii < 48) || (check_ascii > 57) )
  9852. {
  9853. isSuccess = ConfigurationStatus_Rejected;
  9854. }
  9855. else
  9856. {
  9857. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9859. isSuccess = ConfigurationStatus_Accepted;
  9860. }
  9861. }
  9862. else
  9863. {
  9864. isSuccess = ConfigurationStatus_Rejected;
  9865. }
  9866. }
  9867. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9868. {
  9869. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9870. {
  9871. check_ascii = value[0];
  9872. if( (check_ascii < 48) || (check_ascii > 57) )
  9873. {
  9874. isSuccess = ConfigurationStatus_Rejected;
  9875. }
  9876. else
  9877. {
  9878. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9880. isSuccess = ConfigurationStatus_Accepted;
  9881. }
  9882. }
  9883. else
  9884. {
  9885. isSuccess = ConfigurationStatus_Rejected;
  9886. }
  9887. }
  9888. if(strcmp(key, "HeartbeatInterval") == 0)
  9889. {
  9890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9891. {
  9892. check_ascii = value[0];
  9893. if( (check_ascii < 48) || (check_ascii > 57) )
  9894. {
  9895. isSuccess = ConfigurationStatus_Rejected;
  9896. }
  9897. else
  9898. {
  9899. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9901. HeartBeatWaitTime = atoi(value);
  9902. isSuccess = ConfigurationStatus_Accepted;
  9903. }
  9904. }
  9905. else
  9906. {
  9907. isSuccess = ConfigurationStatus_Rejected;
  9908. }
  9909. }
  9910. if(strcmp(key, "LightIntensity") == 0)
  9911. {
  9912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9913. {
  9914. check_ascii = value[0];
  9915. if( (check_ascii < 48) || (check_ascii > 57) )
  9916. {
  9917. isSuccess = ConfigurationStatus_Rejected;
  9918. }
  9919. else
  9920. {
  9921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9922. isSuccess = ConfigurationStatus_Accepted;
  9923. }
  9924. }
  9925. else
  9926. {
  9927. isSuccess = ConfigurationStatus_Rejected;
  9928. }
  9929. }
  9930. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9931. {
  9932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9933. {
  9934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9935. isSuccess = ConfigurationStatus_Accepted;
  9936. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9937. }
  9938. else
  9939. {
  9940. isSuccess = ConfigurationStatus_Rejected;
  9941. }
  9942. }
  9943. if(strcmp(key, "LocalPreAuthorize") == 0)
  9944. {
  9945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9946. {
  9947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9948. isSuccess = ConfigurationStatus_Accepted;
  9949. }
  9950. else
  9951. {
  9952. isSuccess = ConfigurationStatus_Rejected;
  9953. }
  9954. }
  9955. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  9956. {
  9957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9958. {
  9959. check_ascii = value[0];
  9960. if( (check_ascii < 48) || (check_ascii > 57) )
  9961. {
  9962. isSuccess = ConfigurationStatus_Rejected;
  9963. }
  9964. else
  9965. {
  9966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  9967. isSuccess = ConfigurationStatus_Accepted;
  9968. }
  9969. }
  9970. else
  9971. {
  9972. isSuccess = ConfigurationStatus_Rejected;
  9973. }
  9974. }
  9975. if(strcmp(key, "MeterValuesAlignedData") == 0)
  9976. {
  9977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9978. {
  9979. //int valueLength = strlen(value);
  9980. for(int i = 0; value[i]; i++){
  9981. value[i] = tolower(value[i]);
  9982. }
  9983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  9984. isSuccess = ConfigurationStatus_Accepted;
  9985. }
  9986. else
  9987. {
  9988. isSuccess = ConfigurationStatus_Rejected;
  9989. }
  9990. }
  9991. if(strcmp(key, "MeterValuesSampledData") == 0 )
  9992. {
  9993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9994. {
  9995. //int valueLength = strlen(value);
  9996. for(int i = 0; value[i]; i++){
  9997. value[i] = tolower(value[i]);
  9998. }
  9999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10000. isSuccess = ConfigurationStatus_Accepted;
  10001. }
  10002. else
  10003. {
  10004. isSuccess = ConfigurationStatus_Rejected;
  10005. }
  10006. }
  10007. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10008. {
  10009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10010. {
  10011. check_ascii = value[0];
  10012. if( (check_ascii < 48) || (check_ascii > 57) )
  10013. {
  10014. isSuccess = ConfigurationStatus_Rejected;
  10015. }
  10016. else
  10017. {
  10018. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10020. isSuccess = ConfigurationStatus_Accepted;
  10021. }
  10022. #ifdef Debug
  10023. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10024. #endif
  10025. }
  10026. else
  10027. {
  10028. isSuccess = ConfigurationStatus_Rejected;
  10029. #ifdef Debug
  10030. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10031. #endif
  10032. }
  10033. }
  10034. if(strcmp(key, "MinimumStatusDuration") == 0)
  10035. {
  10036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10037. {
  10038. check_ascii = value[0];
  10039. if( (check_ascii < 48) || (check_ascii > 57) )
  10040. {
  10041. isSuccess = ConfigurationStatus_Rejected;
  10042. }
  10043. else
  10044. {
  10045. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10047. isSuccess = ConfigurationStatus_Accepted;
  10048. }
  10049. }
  10050. else
  10051. {
  10052. isSuccess = ConfigurationStatus_Rejected;
  10053. }
  10054. }
  10055. if(strcmp(key, "ResetRetries") == 0)
  10056. {
  10057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10058. {
  10059. check_ascii = value[0];
  10060. if( (check_ascii < 48) || (check_ascii > 57) )
  10061. {
  10062. isSuccess = ConfigurationStatus_Rejected;
  10063. }
  10064. else
  10065. {
  10066. //Charger.ResetRetries = Integer.parseInt(value);
  10067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10068. isSuccess = ConfigurationStatus_Accepted;
  10069. }
  10070. }
  10071. else
  10072. {
  10073. isSuccess = ConfigurationStatus_Rejected;
  10074. }
  10075. }
  10076. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10077. {
  10078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10079. {
  10080. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10081. //int valueLength = strlen(value);
  10082. for(int i = 0; value[i]; i++){
  10083. value[i] = tolower(value[i]);
  10084. }
  10085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10086. isSuccess = ConfigurationStatus_Accepted;
  10087. }
  10088. else
  10089. {
  10090. isSuccess = ConfigurationStatus_Rejected;
  10091. }
  10092. }
  10093. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10094. {
  10095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10096. {
  10097. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10099. isSuccess = ConfigurationStatus_Accepted;
  10100. }
  10101. else
  10102. {
  10103. isSuccess = ConfigurationStatus_Rejected;
  10104. }
  10105. }
  10106. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10107. {
  10108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10109. {
  10110. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10112. isSuccess = ConfigurationStatus_Accepted;
  10113. }
  10114. else
  10115. {
  10116. isSuccess = ConfigurationStatus_Rejected;
  10117. }
  10118. }
  10119. if(strcmp(key, "StopTxnAlignedData") == 0)
  10120. {
  10121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10122. {
  10123. //Charger.StopTxnAlignedData = value.toLowerCase();
  10124. //int valueLength = strlen(value);
  10125. for(int i = 0; value[i]; i++){
  10126. value[i] = tolower(value[i]);
  10127. }
  10128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10129. isSuccess = ConfigurationStatus_Accepted;
  10130. }
  10131. else
  10132. {
  10133. isSuccess = ConfigurationStatus_Rejected;
  10134. }
  10135. }
  10136. if(strcmp(key, "StopTxnSampledData") == 0)
  10137. {
  10138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10139. {
  10140. //Charger.StopTxnSampledData = value.toLowerCase();
  10141. //int valueLength = strlen(value);
  10142. for(int i = 0; value[i]; i++){
  10143. value[i] = tolower(value[i]);
  10144. }
  10145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10146. isSuccess = ConfigurationStatus_Accepted;
  10147. }
  10148. else
  10149. {
  10150. isSuccess = ConfigurationStatus_Rejected;
  10151. }
  10152. }
  10153. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10154. {
  10155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10156. {
  10157. check_ascii = value[0];
  10158. if( (check_ascii < 48) || (check_ascii > 57) )
  10159. {
  10160. isSuccess = ConfigurationStatus_Rejected;
  10161. }
  10162. else
  10163. {
  10164. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10166. TransactionMessageAttemptsValue = atoi(value);
  10167. isSuccess = ConfigurationStatus_Accepted;
  10168. }
  10169. }
  10170. else
  10171. {
  10172. isSuccess = ConfigurationStatus_Rejected;
  10173. }
  10174. }
  10175. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10176. {
  10177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10178. {
  10179. check_ascii = value[0];
  10180. if( (check_ascii < 48) || (check_ascii > 57) )
  10181. {
  10182. isSuccess = ConfigurationStatus_Rejected;
  10183. }
  10184. else
  10185. {
  10186. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10188. TransactionMessageRetryIntervalValue = atoi(value);
  10189. isSuccess = ConfigurationStatus_Accepted;
  10190. }
  10191. }
  10192. else
  10193. {
  10194. isSuccess = ConfigurationStatus_Rejected;
  10195. }
  10196. }
  10197. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10198. {
  10199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10200. {
  10201. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10203. isSuccess = ConfigurationStatus_Accepted;
  10204. }
  10205. else
  10206. {
  10207. isSuccess = ConfigurationStatus_Rejected;
  10208. }
  10209. }
  10210. if(strcmp(key, "WebSocketPingInterval") == 0)
  10211. {
  10212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10213. {
  10214. check_ascii = value[0];
  10215. if( (check_ascii < 48) || (check_ascii > 57) )
  10216. {
  10217. isSuccess = ConfigurationStatus_Rejected;
  10218. }
  10219. else
  10220. {
  10221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10222. isSuccess = ConfigurationStatus_Accepted;
  10223. }
  10224. }
  10225. else
  10226. {
  10227. isSuccess = ConfigurationStatus_Rejected;
  10228. }
  10229. }
  10230. #if 0
  10231. //For OCPP Test Case
  10232. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10233. {
  10234. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10235. {
  10236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10237. isSuccess = ConfigurationStatus_Accepted;
  10238. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10239. }
  10240. else
  10241. {
  10242. isSuccess = ConfigurationStatus_Rejected;
  10243. }
  10244. }
  10245. #endif
  10246. #if 1
  10247. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10248. {
  10249. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10250. {
  10251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10252. isSuccess = ConfigurationStatus_Accepted;
  10253. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10254. }
  10255. else
  10256. {
  10257. isSuccess = ConfigurationStatus_Rejected;
  10258. }
  10259. }
  10260. #endif
  10261. return isSuccess;
  10262. }
  10263. int updateSetting(char *key, char *value)
  10264. {
  10265. mtrace();
  10266. int isSuccess = FALSE;
  10267. char string[1000]={0}, buffer[1000]={0};
  10268. char strtemp[50]={0};
  10269. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10270. int pos, c = 0;
  10271. char *loc;
  10272. int pos1=0;
  10273. FILE *f = fopen("/var/www/settings1", "r");
  10274. if(f == NULL)
  10275. {
  10276. #ifdef Debug
  10277. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10278. #endif
  10279. return isSuccess;
  10280. }
  10281. fseek(f, 0, SEEK_END);
  10282. long fsize = ftell(f);
  10283. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10284. fread(string, 1, fsize, f);
  10285. fclose(f);
  10286. string[fsize] = 0;
  10287. loc = strstr(string, key);
  10288. if(loc != NULL)
  10289. {
  10290. DEBUG_INFO("key exist!\n");
  10291. pos = loc - string-1;
  10292. f = fopen("/var/www/settings1", "w");
  10293. strncpy(buffer, string, pos);
  10294. fprintf(f, "%s", buffer);
  10295. memset(sstr ,0, sizeof(sstr) );
  10296. c = 0;
  10297. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10298. {
  10299. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10300. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10301. c++;
  10302. }
  10303. sstr[c] = '\0';
  10304. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10305. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10306. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10307. memset(buffer ,0, sizeof(buffer) );
  10308. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10309. //printf("buffer=%s",buffer);
  10310. fprintf(f, "%s", buffer);
  10311. fclose(f);
  10312. }
  10313. else
  10314. {
  10315. printf("key not exist!\n");
  10316. f = fopen("/var/www/settings1", "w+");
  10317. fputs(string, f);
  10318. fseek(f, -1, SEEK_CUR);
  10319. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10320. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10321. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10322. fclose(f);
  10323. }
  10324. isSuccess = TRUE;
  10325. return isSuccess;
  10326. }
  10327. int TransactionMessageAttemptsGet(void)
  10328. {
  10329. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10330. }
  10331. int FirstHeartBeatResponse(void)
  10332. {
  10333. return FirstHeartBeat;
  10334. }
  10335. int TransactionMessageRetryIntervalGet(void)
  10336. {
  10337. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10338. }
  10339. #define SA struct sockaddr
  10340. #define MAXBUF 1024
  10341. //static int m_socket_data;
  10342. //static int sockfd;
  10343. int ReadHttpStatus(int sock){
  10344. //char c;
  10345. char buff[1024]="",*ptr=buff+1;
  10346. int bytes_received, status;
  10347. DEBUG_INFO("Begin Response ..\n");
  10348. while((bytes_received = recv(sock, ptr, 1, 0))){
  10349. if(bytes_received==-1){
  10350. perror("ReadHttpStatus");
  10351. exit(1);
  10352. }
  10353. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10354. ptr++;
  10355. }
  10356. *ptr=0;
  10357. ptr=buff+1;
  10358. sscanf(ptr,"%*s %d ", &status);
  10359. DEBUG_INFO("%s\n",ptr);
  10360. DEBUG_INFO("status=%d\n",status);
  10361. DEBUG_INFO("End Response ..\n");
  10362. return (bytes_received>0)?status:0;
  10363. }
  10364. //the only filed that it parsed is 'Content-Length'
  10365. int ParseHeader(int sock){
  10366. //char c;
  10367. char buff[1024]="",*ptr=buff+4;
  10368. int bytes_received;
  10369. DEBUG_INFO("Begin HEADER ..\n");
  10370. while((bytes_received = recv(sock, ptr, 1, 0))){
  10371. if(bytes_received==-1){
  10372. perror("Parse Header");
  10373. exit(1);
  10374. }
  10375. if(
  10376. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10377. (ptr[-1]=='\r') && (*ptr=='\n' )
  10378. ) break;
  10379. ptr++;
  10380. }
  10381. *ptr=0;
  10382. ptr=buff+4;
  10383. //printf("%s",ptr);
  10384. if(bytes_received){
  10385. ptr=strstr(ptr,"Content-Length:");
  10386. if(ptr){
  10387. sscanf(ptr,"%*s %d",&bytes_received);
  10388. }else
  10389. bytes_received=-1; //unknown size
  10390. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10391. }
  10392. DEBUG_INFO("End HEADER ..\n");
  10393. return bytes_received ;
  10394. }
  10395. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10396. {
  10397. char rmFileCmd[100]={0};
  10398. char FilePath[100]={0};
  10399. char ftpbuf[200];
  10400. int systemresult;
  10401. DEBUG_INFO("filename=%s\n",filename);
  10402. DEBUG_INFO("url=%s\n",url);
  10403. sprintf(FilePath,"../mnt/%s",filename);
  10404. if((access(FilePath,F_OK))!=-1)
  10405. {
  10406. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10407. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10408. system(rmFileCmd);
  10409. }
  10410. memset(ftpbuf, 0, sizeof(ftpbuf));
  10411. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10412. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10413. systemresult = system(ftpbuf);
  10414. DEBUG_INFO("systemresult=%d\n",systemresult);
  10415. if(systemresult != 0)
  10416. {
  10417. DEBUG_INFO("http DownLoad error!\n");
  10418. return FALSE;
  10419. }
  10420. return TRUE;
  10421. }
  10422. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10423. {
  10424. char rmFileCmd[100]={0};
  10425. char FilePath[100]={0};
  10426. char ftpbuf[200];
  10427. int systemresult;
  10428. //char temp[100];
  10429. #if 0
  10430. struct hostent* server;
  10431. char *IPbuffer;
  10432. server = gethostbyname(location);
  10433. // To convert an Internet network
  10434. // address into ASCII string
  10435. IPbuffer = inet_ntoa(*((struct in_addr*)
  10436. server->h_addr_list[0]));
  10437. #endif
  10438. sprintf(FilePath,"../mnt/%s",filename);
  10439. if((access(FilePath,F_OK))!=-1)
  10440. {
  10441. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10442. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10443. system(rmFileCmd);
  10444. }
  10445. memset(ftpbuf, 0, sizeof(ftpbuf));
  10446. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10447. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10448. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10449. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10450. systemresult = system(ftpbuf);
  10451. DEBUG_INFO("systemresult=%d\n",systemresult);
  10452. if(systemresult != 0)
  10453. {
  10454. printf("ftpget error!\n");
  10455. return FALSE;
  10456. }
  10457. return TRUE;
  10458. }
  10459. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10460. {
  10461. struct hostent* server;
  10462. char *IPbuffer;
  10463. char ftpbuf[200];
  10464. int systemresult;
  10465. // To retrieve host information
  10466. server = gethostbyname(location);
  10467. // To convert an Internet network
  10468. // address into ASCII string
  10469. IPbuffer = inet_ntoa(*((struct in_addr*)
  10470. server->h_addr_list[0]));
  10471. memset(ftpbuf, 0, sizeof(ftpbuf));
  10472. /* format : ftpput -u username -p passwd IP target source*/
  10473. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10474. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10475. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10476. systemresult = system(ftpbuf);
  10477. DEBUG_INFO("systemresult=%d\n",systemresult);
  10478. if(systemresult != 0)
  10479. {
  10480. DEBUG_INFO("ftpput error!\n");
  10481. return FALSE;
  10482. }
  10483. return TRUE;
  10484. }
  10485. int SettingChargingRecord(int target, int transactionId)
  10486. {
  10487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10488. {
  10489. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10490. {
  10491. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10492. {
  10493. addBuff(target, transactionId, 0);
  10494. return TRUE;
  10495. }
  10496. }
  10497. for (int index = 0; index < CCS_QUANTITY; index++)
  10498. {
  10499. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10500. {
  10501. addBuff(target, transactionId, 0);
  10502. return TRUE;
  10503. }
  10504. }
  10505. for (int index = 0; index < GB_QUANTITY; index++)
  10506. {
  10507. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10508. {
  10509. addBuff(target, transactionId, 0);
  10510. return TRUE;
  10511. }
  10512. }
  10513. }
  10514. else
  10515. {
  10516. for (int index = 0; index < AC_QUANTITY; index++)
  10517. {
  10518. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10519. {
  10520. addBuff(target, transactionId, 0);
  10521. return TRUE;
  10522. }
  10523. }
  10524. }
  10525. return FALSE;
  10526. }
  10527. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10528. {
  10529. int isSuccess = FALSE;
  10530. //char *query = NULL;
  10531. sqlite3_stmt *stmt;
  10532. int rc; // return code
  10533. char str[20];
  10534. sprintf(str,"%d",user_id);
  10535. sqlite3_prepare_v2(db, "insert into log_buffer (user_id, cmd_sn, charger_id, gun_type, gun_no, rfid_no, stime, etime, time_len, s_soc, e_soc, stop_reason, power, meter_before, meter_after, charge_price, reserve, surplus_before, surplus_after, service_price, is_pay ,charge_strategy, charge_parameter, vin, vehicle_no, start_method, card_type, is_upload, guid, is_buf2OK) values (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14,?15,?16,?17,?18,?19,?20,?21,?22,?23,?24,?25,?26,?27,?28,?29,?30);", -1, &stmt, NULL); /* 1 */
  10536. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10537. rc = sqlite3_step(stmt); /* 3 */
  10538. if (rc != SQLITE_DONE) {
  10539. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10540. goto out;
  10541. }
  10542. sqlite3_finalize(stmt);
  10543. // free(query);
  10544. out:
  10545. //----------------------
  10546. // close SQLite database
  10547. //----------------------
  10548. sqlite3_close(db);
  10549. printf("database closed.\n");
  10550. return isSuccess;
  10551. }
  10552. /**
  10553. * Place the contents of the specified file into a memory buffer
  10554. *
  10555. * @param[in] filename The path and name of the file to read
  10556. * @param[out] filebuffer A pointer to the contents in memory
  10557. * @return status 0 success, 1 on failure
  10558. */
  10559. int get_file_contents(const char* filename, char** outbuffer) {
  10560. FILE* file = NULL;
  10561. long filesize;
  10562. const int blocksize = 1;
  10563. size_t readsize;
  10564. char* filebuffer;
  10565. // Open the file
  10566. file = fopen(filename, "r");
  10567. if (NULL == file)
  10568. {
  10569. printf("'%s' not opened\n", filename);
  10570. exit(EXIT_FAILURE);
  10571. }
  10572. // Determine the file size
  10573. fseek(file, 0, SEEK_END);
  10574. filesize = ftell(file);
  10575. rewind (file);
  10576. // Allocate memory for the file contents
  10577. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10578. *outbuffer = filebuffer;
  10579. if (filebuffer == NULL)
  10580. {
  10581. fputs ("malloc out-of-memory", stderr);
  10582. exit(EXIT_FAILURE);
  10583. }
  10584. // Read in the file
  10585. readsize = fread(filebuffer, blocksize, filesize, file);
  10586. if (readsize != filesize)
  10587. {
  10588. fputs ("didn't read file completely",stderr);
  10589. exit(EXIT_FAILURE);
  10590. }
  10591. // Clean exit
  10592. fclose(file);
  10593. return EXIT_SUCCESS;
  10594. }
  10595. static int selectSqlCount = 0;
  10596. static int callback(void *data, int argc, char **argv, char **azColName){
  10597. int i;
  10598. printf("%s: ", (const char*)data);
  10599. selectSqlCount = argc;
  10600. for(i = 0; i<argc; i++){
  10601. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10602. }
  10603. printf("\n");
  10604. return 0;
  10605. }
  10606. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10607. //int i;
  10608. //printf("%s:\n", (const char*)data);
  10609. localversion = argv[5] ? atoi(argv[5]) : 0;
  10610. printf("localversion=%d\n", localversion);
  10611. return 0;
  10612. }
  10613. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10614. //int i;
  10615. //printf("%s:\n", (const char*)data);
  10616. //idTag
  10617. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10618. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10619. //parentIdTag
  10620. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10621. //expir_date
  10622. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10623. //status
  10624. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10625. //version
  10626. idTagQuery.listVersionInt = atoi(argv[5]);
  10627. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10628. return 0;
  10629. }
  10630. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10631. int i;
  10632. //printf("%s:\n", (const char*)data);
  10633. #if 1
  10634. for(i=0; i<argc; i++){
  10635. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10636. }
  10637. //printf("");
  10638. #endif
  10639. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10640. // printf("localversion=%d\n", localversion);
  10641. return 0;
  10642. }
  10643. /** sqlite3_exec的回调。
  10644. *
  10645. * 向控制台打印查询的结果。
  10646. *
  10647. * @param in data 传递给回调函数的数据。
  10648. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10649. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10650. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10651. * @return 状态码。
  10652. */
  10653. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10654. {
  10655. for (int i = 0; i < n_columns; i++)
  10656. {
  10657. DEBUG_INFO("%s/t", col_values[i]);
  10658. }
  10659. DEBUG_INFO("/n");
  10660. return 0;
  10661. }
  10662. void OCPP_getListVerion()
  10663. {
  10664. int rc = 0;
  10665. // const char* data = "Callback function called";
  10666. char sql[100];
  10667. char zErrMsg[100];
  10668. memset(sql, 0, 100);
  10669. memset(zErrMsg, 0, 100);
  10670. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10671. /* Execute SQL statement */
  10672. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10673. DEBUG_INFO("rc=%d\n",rc);
  10674. if( rc != SQLITE_OK ){
  10675. DEBUG_INFO("SQL error: %s", zErrMsg);
  10676. //sqlite3_free(zErrMsg);
  10677. }else{
  10678. DEBUG_INFO("Operation done successfully");
  10679. }
  10680. }
  10681. void OCPP_getIdTag(char *idTag)
  10682. {
  10683. int rc = 0;
  10684. // const char* data = "Callback function called";
  10685. char sql[100];
  10686. char zErrMsg[100];
  10687. memset(sql, 0, 100);
  10688. memset(zErrMsg, 0, 100);
  10689. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10690. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10691. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10692. /* Execute SQL statement */
  10693. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10694. if( rc != SQLITE_OK ){
  10695. DEBUG_INFO("SQL error: %s", zErrMsg);
  10696. //sqlite3_free(zErrMsg);
  10697. }else{
  10698. printf("Operation done successfully");
  10699. }
  10700. //return ver;
  10701. }
  10702. void OCPP_get_TableAuthlocalAllData(void)
  10703. {
  10704. int rc = 0;
  10705. // const char* data = "Callback function called";
  10706. char sql[100];
  10707. char zErrMsg[100];
  10708. memset(sql, 0, 100);
  10709. memset(zErrMsg, 0, 100);
  10710. sprintf(sql,"select * from ocpp_auth_local ");
  10711. /* Execute SQL statement */
  10712. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10713. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10714. if( rc != SQLITE_OK ){
  10715. DEBUG_INFO("SQL error: %s", zErrMsg);
  10716. //sqlite3_free(zErrMsg);
  10717. }else{
  10718. DEBUG_INFO("Operation done successfully");
  10719. }
  10720. //return ver;
  10721. }
  10722. int OCPP_cleanLocalList()
  10723. {
  10724. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10725. char *errMsg = 0;
  10726. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10727. if (SQLITE_OK != rc)
  10728. {
  10729. DEBUG_INFO("%s\n",errMsg);
  10730. return FALSE;
  10731. }
  10732. else
  10733. {
  10734. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10735. }
  10736. return TRUE;
  10737. }
  10738. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10739. {
  10740. int isSuccess = FALSE;
  10741. int ret = 0;
  10742. //const char* data = "Callback function called";
  10743. char sql[200];
  10744. char zErrMsg[100];
  10745. memset(sql, 0, 200);
  10746. memset(zErrMsg, 0, 100);
  10747. 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);
  10748. //* Execute SQL statement */
  10749. //zErrMsg = 0;
  10750. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10751. if( ret != SQLITE_OK ){
  10752. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10753. // free(zErrMsg);
  10754. // free(sql);
  10755. return isSuccess;
  10756. }
  10757. DEBUG_INFO("successfully Insert records created\n");
  10758. isSuccess = TRUE;
  10759. return isSuccess;
  10760. }
  10761. void OCPP_deleteIdTag(char *idTag)
  10762. {
  10763. //int ver = 0;
  10764. //int isSuccess = FALSE;
  10765. int rc = 0;
  10766. char sql[100];
  10767. char zErrMsg[100];
  10768. memset(sql, 0, 100);
  10769. memset(zErrMsg, 0, 100);
  10770. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10771. //* Execute SQL statement */
  10772. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10773. if( rc != SQLITE_OK ){
  10774. DEBUG_INFO("SQL error: %s", zErrMsg);
  10775. //sqlite3_free(zErrMsg);
  10776. }else{
  10777. DEBUG_INFO("Operation done successfully");
  10778. }
  10779. }
  10780. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10781. {
  10782. int isSuccess = FALSE;
  10783. int ret = 0;
  10784. const char* data = "Callback function called";
  10785. char sql[200];
  10786. char zErrMsg[100];
  10787. memset(sql, 0, 200);
  10788. memset(zErrMsg, 0, 100);
  10789. //* selectFromTable */
  10790. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10791. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10792. //* Execute SQL statement */
  10793. selectSqlCount = 0;
  10794. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10795. if( ret != SQLITE_OK ){
  10796. printf("Error SQL: %s\n", zErrMsg);
  10797. }
  10798. printf("successfully select operation done\n");
  10799. memset(sql, 0, 200);
  10800. memset(zErrMsg, 0, 100);
  10801. if(selectSqlCount == 0)
  10802. {
  10803. //Insert
  10804. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  10805. sprintf(sql,"INSERT INTO ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ", idTag, parentTage, expiryDate, status, version);
  10806. DEBUG_INFO("sql:%s\n", sql);
  10807. //* Execute SQL statement */
  10808. //zErrMsg = 0;
  10809. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10810. if( ret != SQLITE_OK ){
  10811. printf("SQL error: %s\n", zErrMsg);
  10812. return isSuccess;
  10813. }
  10814. DEBUG_INFO("successfully Insert records created\n");
  10815. isSuccess = TRUE;
  10816. }
  10817. else
  10818. {
  10819. //Update
  10820. //* Create merged SQL statement */
  10821. sprintf(sql, "UPDATE ocpp_auth_local set parent_idtag = '%s', expir_date = '%s', status ='%s', version =%d where idtag='%s'; " "SELECT * from ocpp_auth_local", parentTage, expiryDate, status, version, idTag);
  10822. /* Execute SQL statement */
  10823. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10824. if( ret != SQLITE_OK ){
  10825. printf("SQL error: %s\n", zErrMsg);
  10826. //sqlite3_free(zErrMsg);
  10827. //sqlite3_free(sql);
  10828. return isSuccess;
  10829. }
  10830. DEBUG_INFO("Successfully operation done \n");
  10831. isSuccess = TRUE;
  10832. }
  10833. return isSuccess;
  10834. }
  10835. char *GetOcppServerURL()
  10836. {
  10837. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10838. memset(OcppHost, 0, sizeof(OcppHost));
  10839. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10840. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10841. {
  10842. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10843. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10844. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10845. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10846. DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10847. DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10848. DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10849. DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10850. goto End;
  10851. }
  10852. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10853. {
  10854. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10855. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10856. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10857. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10858. DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10859. DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10860. DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10861. DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10862. goto End;
  10863. }
  10864. else
  10865. {
  10866. strcpy(OcppHost,"");
  10867. }
  10868. End:
  10869. return OcppHost;
  10870. }
  10871. char *GetOcppPath()
  10872. {
  10873. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10874. {
  10875. if(OcppTempPath == NULL)
  10876. {
  10877. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10878. }
  10879. else
  10880. {
  10881. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10882. }
  10883. goto End;
  10884. }
  10885. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10886. {
  10887. if(OcppTempPath == NULL)
  10888. {
  10889. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10890. }
  10891. else
  10892. {
  10893. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10894. }
  10895. goto End;
  10896. }
  10897. else
  10898. {
  10899. strcpy(OcppHost,"");
  10900. }
  10901. End:
  10902. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10903. return OcppPath;
  10904. }
  10905. int GetOcppPort()
  10906. {
  10907. return OcppPort;
  10908. }
  10909. int GetOcppConnStatus(void)
  10910. {
  10911. return ShmOCPP16Data->OcppConnStatus;
  10912. }
  10913. void SetOcppConnStatus(uint8_t status)
  10914. {
  10915. ShmOCPP16Data->OcppConnStatus = status;
  10916. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  10917. if(status == FALSE)
  10918. {
  10919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10920. {
  10921. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  10922. }
  10923. else
  10924. {
  10925. SystemInitial = AC_QUANTITY;
  10926. }
  10927. }
  10928. }
  10929. #if 0
  10930. void Send(struct json_object *message)
  10931. {
  10932. printf("Send -1 \n");
  10933. printf("message=%s\n",json_object_to_json_string(message));
  10934. LWS_Send(json_object_to_json_string(message));
  10935. }
  10936. #endif
  10937. void LWS_Send(char * str)
  10938. {
  10939. #if 1
  10940. //=====================================================
  10941. // Check InternetConn 0: disconnected, 1: connected
  10942. //====================================================
  10943. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  10944. {
  10945. DEBUG_INFO("\n offline now !!!\n");
  10946. return;
  10947. }
  10948. #endif
  10949. pthread_mutex_lock(&lock);
  10950. memset(SendBuffer,0,SendBufLen);
  10951. sprintf((char *)SendBuffer, "%s", str);
  10952. pthread_mutex_unlock(&lock);
  10953. lws_callback_on_writable(wsi_client);
  10954. lws_service(context, 10000);//timeout_ms
  10955. //usleep(10000); // 等�??��?微�?
  10956. //DEBUG_INFO("Send message end\n");
  10957. }