MessageHandler.c 451 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916
  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 (strstr(ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL) ? (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 = (strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL) ? (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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  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(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2803. {
  2804. idx_sample=4;
  2805. //sampledValue = NULL;
  2806. //***********************************************(6)SOC******************************************************/
  2807. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2808. {
  2809. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2810. {
  2811. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2812. {
  2813. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2814. }
  2815. }
  2816. for (int index = 0; index < CCS_QUANTITY; index++)
  2817. {
  2818. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2819. {
  2820. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2821. }
  2822. }
  2823. for (int index = 0; index < GB_QUANTITY; index++)
  2824. {
  2825. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2826. {
  2827. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2828. }
  2829. }
  2830. }
  2831. else
  2832. {
  2833. for (int index = 0; index < AC_QUANTITY; index++)
  2834. {
  2835. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2836. {
  2837. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2838. }
  2839. }
  2840. }//END FOR AC ELSE
  2841. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2842. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2843. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[SoC]);
  2844. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2847. sprintf(message + strlen(message),",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2848. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2849. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2850. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2851. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2852. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2853. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2854. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2855. );
  2856. }
  2857. //}
  2858. sprintf(message + strlen(message)," ] } ] } ]");
  2859. //free(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue);
  2860. }
  2861. LWS_Send(message);
  2862. //memset(mapItem, 0, sizeof(data_struct_t));
  2863. // Put request guid to hash map
  2864. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2865. 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*/)
  2866. {
  2867. result = PASS;
  2868. DEBUG_INFO("MeterValues mapitem pass\n");
  2869. }
  2870. strcpy(queuedata, message);
  2871. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2872. //#ifdef SystemLogMessage
  2873. //DEBUG_INFO(">>>>>MeerValues request\n");
  2874. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2875. //#endif
  2876. return result;
  2877. }
  2878. //==========================================
  2879. // send confirm routine
  2880. //==========================================
  2881. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2882. {
  2883. mtrace();
  2884. int result = FAIL;
  2885. char message[100]={0};
  2886. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2887. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2888. LWS_Send(message);
  2889. result = TRUE;
  2890. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2891. return result;
  2892. }
  2893. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2894. {
  2895. mtrace();
  2896. int result = FAIL;
  2897. char message[100]={0};
  2898. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2899. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2900. LWS_Send(message);
  2901. result = TRUE;
  2902. return result;
  2903. }
  2904. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2905. {
  2906. mtrace();
  2907. int result = FAIL;
  2908. char message[100]={0};
  2909. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2910. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2911. LWS_Send(message);
  2912. result = TRUE;
  2913. return result;
  2914. }
  2915. int sendClearCacheConfirmation(char *uuid,char *payload)
  2916. {
  2917. mtrace();
  2918. int result = FAIL;
  2919. char message[500]={0};
  2920. // int count = 0;
  2921. // int gun_index = 0;
  2922. // char guid[37];
  2923. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2924. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2925. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2926. LWS_Send(message);
  2927. return result;
  2928. }
  2929. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2930. {
  2931. mtrace();
  2932. int result = FAIL;
  2933. char message[500]={0};
  2934. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2935. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2936. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2937. LWS_Send(message);
  2938. return result;
  2939. }
  2940. int sendDataTransferConfirmation(char *uuid,char *payload)
  2941. {
  2942. mtrace();
  2943. char statusStr[20]={0};
  2944. char dataStr[10]={0};
  2945. char sstr[20]={0};
  2946. int c = 0;
  2947. char *loc;
  2948. int result = FAIL;
  2949. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2950. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2951. /**********************status**************************/
  2952. loc = strstr(payload, "status");
  2953. memset(sstr ,0, sizeof(sstr) );
  2954. c = 0;
  2955. while (loc[3+strlen("status")+c] != '\"')
  2956. {
  2957. sstr[c] = loc[3+strlen("status")+c];
  2958. c++;
  2959. }
  2960. sstr[c] = '\0';
  2961. strcpy(statusStr, sstr);
  2962. /**********************data**************************/
  2963. loc = strstr(payload, "data");
  2964. memset(sstr ,0, sizeof(sstr) );
  2965. c = 0;
  2966. while (loc[3+strlen("data")+c] != '\"')
  2967. {
  2968. sstr[c] = loc[3+strlen("data")+c];
  2969. c++;
  2970. }
  2971. sstr[c] = '\0';
  2972. strcpy(dataStr, sstr);
  2973. return result;
  2974. }
  2975. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2976. {
  2977. mtrace();
  2978. int result = FAIL;
  2979. char message[1000]={0};
  2980. double diff_f = 0.0;
  2981. int diff_i = 0;
  2982. struct tm tp;
  2983. DEBUG_ERROR("handle sendGetCompositeScheduleConfirmation ...\n");
  2984. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2985. tp.tm_isdst = -1;
  2986. time_t utc = mktime(&tp);
  2987. time_t t = time(NULL);
  2988. diff_f = difftime(t, utc);
  2989. diff_i = (int)diff_f;
  2990. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2991. #if 0 //remove temporally
  2992. 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}"
  2993. ,MESSAGE_TYPE_CALLRESULT
  2994. ,uuid
  2995. ,payload
  2996. ,connectorIdInt
  2997. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2998. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2999. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3000. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3001. #endif
  3002. if(nPeriod == 0)
  3003. {
  3004. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3005. ,MESSAGE_TYPE_CALLRESULT
  3006. ,uuid
  3007. ,payload
  3008. ,connectorIdInt
  3009. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule);
  3010. }
  3011. else
  3012. {
  3013. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3014. ,MESSAGE_TYPE_CALLRESULT
  3015. ,uuid
  3016. ,payload
  3017. ,connectorIdInt
  3018. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3019. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3020. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3021. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3022. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3023. #if 1 // remove temporally
  3024. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3025. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3026. {
  3027. if (idx_sample == 0)
  3028. {
  3029. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3030. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  3031. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3032. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3033. }
  3034. else
  3035. {
  3036. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3037. , (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diff_i /*-1*/)
  3038. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3039. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3040. }
  3041. }
  3042. #endif
  3043. sprintf(message + strlen(message), "]}}]");
  3044. }
  3045. LWS_Send(message);
  3046. result = TRUE;
  3047. return result;
  3048. }
  3049. int sendGetConfigurationConfirmation(char *uuid)
  3050. {
  3051. mtrace();
  3052. int result = FAIL;
  3053. int MaxKeySupported = 0;
  3054. int sentConfigurationNumber= 0;
  3055. int sentunConfigurationNumber= 0;
  3056. char message[4000]={0};
  3057. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3058. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3059. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3060. ,MESSAGE_TYPE_CALLRESULT
  3061. ,uuid );
  3062. //configuration key
  3063. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3064. {
  3065. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3066. {
  3067. if (sentConfigurationNumber == 0)
  3068. {
  3069. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3070. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3071. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3072. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3073. }
  3074. else
  3075. {
  3076. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3077. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3078. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3079. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3080. }
  3081. sentConfigurationNumber = sentConfigurationNumber + 1;
  3082. }
  3083. }
  3084. sprintf(message + strlen(message), "]");
  3085. if(UnknownKeynum != 0)
  3086. {
  3087. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3088. //unkown key
  3089. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3090. {
  3091. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3092. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3093. if(sentunConfigurationNumber == 0)
  3094. {
  3095. sprintf(message + strlen(message), "\"%s\""
  3096. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3097. }
  3098. else
  3099. {
  3100. sprintf(message + strlen(message), ",\"%s\""
  3101. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3102. }
  3103. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3104. }
  3105. sprintf(message + strlen(message), "]");
  3106. }
  3107. sprintf(message + strlen(message), "} ]");
  3108. LWS_Send(message);
  3109. #if 0
  3110. printf("error 1-0\n");
  3111. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3112. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3113. #endif
  3114. return result;
  3115. }
  3116. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3117. {
  3118. mtrace();
  3119. int result = FAIL;
  3120. char message[400]={0};
  3121. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3122. if(strcmp(payload,"")==0)
  3123. {
  3124. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3125. }
  3126. else
  3127. {
  3128. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3129. }
  3130. LWS_Send(message);
  3131. result = TRUE;
  3132. return result;
  3133. }
  3134. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3135. {
  3136. mtrace();
  3137. int result = FAIL;
  3138. char message[80]={0};
  3139. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3140. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3141. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3142. LWS_Send(message);
  3143. result = TRUE;
  3144. return result;
  3145. }
  3146. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3147. {
  3148. mtrace();
  3149. int result = FAIL;
  3150. char message[80]={0};
  3151. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3152. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3153. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3154. LWS_Send(message);
  3155. result = TRUE;
  3156. return result;
  3157. }
  3158. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3159. {
  3160. mtrace();
  3161. int result = FAIL;
  3162. char message[80]={0};
  3163. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3164. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3165. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3166. LWS_Send(message);
  3167. result = TRUE;
  3168. return result;
  3169. }
  3170. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3171. {
  3172. mtrace();
  3173. int result = FAIL;
  3174. char message[80]={0};
  3175. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3176. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3177. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3178. LWS_Send(message);
  3179. result = TRUE;
  3180. return result;
  3181. }
  3182. int sendResetConfirmation(char *uuid,char *payload)
  3183. {
  3184. mtrace();
  3185. int result = FAIL;
  3186. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3187. char message[80]={0};
  3188. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3189. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3190. LWS_Send(message);
  3191. result = TRUE;
  3192. return result;
  3193. }
  3194. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3195. {
  3196. mtrace();
  3197. int result = FAIL;
  3198. char message[500]={0};
  3199. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3200. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3201. LWS_Send(message);
  3202. result = TRUE;
  3203. return result;
  3204. }
  3205. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3206. {
  3207. mtrace();
  3208. int result = FAIL;
  3209. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3210. char message[80]={0};
  3211. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3212. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3213. LWS_Send(message);
  3214. result = TRUE;
  3215. return result;
  3216. }
  3217. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3218. {
  3219. mtrace();
  3220. int result = FAIL;
  3221. char message[80]={0};
  3222. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3223. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3224. LWS_Send(message);
  3225. result = TRUE;
  3226. return result;
  3227. }
  3228. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3229. {
  3230. mtrace();
  3231. int result = FAIL;
  3232. char message[80]={0};
  3233. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3234. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3235. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3236. LWS_Send(message);
  3237. result = TRUE;
  3238. return result;
  3239. }
  3240. int sendUpdateFirmwareConfirmation(char *uuid)
  3241. {
  3242. mtrace();
  3243. int result = FAIL;
  3244. char message[60]={0};
  3245. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3246. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3247. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3248. LWS_Send(message);
  3249. result = TRUE;
  3250. return result;
  3251. }
  3252. //==========================================
  3253. // send CallError routine
  3254. //==========================================
  3255. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3256. {
  3257. mtrace();
  3258. //int result = FAIL;
  3259. char message[220]={0};
  3260. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3261. #ifdef SystemLogMessage
  3262. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3263. uniqueId, action, errorCode, errorDescription);
  3264. #endif
  3265. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3266. LWS_Send(message);
  3267. //result = TRUE;
  3268. }
  3269. //==========================================
  3270. // Handle server request routine Start
  3271. //==========================================
  3272. #define GUN_NUM 1
  3273. int handleCancelReservationRequest(char *uuid, char *payload)
  3274. {
  3275. mtrace();
  3276. int result = FAIL;
  3277. int gunNO = 0;
  3278. int reservationIdInt =0;
  3279. char comfirmstr[20];
  3280. int c = 0;
  3281. char *loc;
  3282. char sstr[100]={0};
  3283. DEBUG_INFO("handle CancelReservationRequest\n");
  3284. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3285. c = 0;
  3286. loc = strstr(payload, "reservationId");
  3287. memset(sstr ,0, sizeof(sstr) );
  3288. while (loc[strlen("reservationId")+2+c] != '}')
  3289. {
  3290. sstr[c] = loc[strlen("reservationId")+2+c];
  3291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3292. c++;
  3293. }
  3294. sstr[c] = '\0';
  3295. reservationIdInt = atoi(sstr);
  3296. memset(comfirmstr, 0, sizeof comfirmstr);
  3297. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3298. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3299. //check Transaction active
  3300. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3301. {
  3302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3303. {
  3304. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3305. {
  3306. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3307. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3308. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3309. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3310. goto end;
  3311. }
  3312. }
  3313. for (int index = 0; index < CCS_QUANTITY; index++)
  3314. {
  3315. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3316. {
  3317. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3318. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3319. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3320. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3321. goto end;
  3322. }
  3323. }
  3324. for (int index = 0; index < GB_QUANTITY; index++)
  3325. {
  3326. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3327. {
  3328. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3329. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3330. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3331. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3332. goto end;
  3333. }
  3334. }
  3335. }
  3336. else
  3337. {
  3338. for (int index = 0; index < AC_QUANTITY; index++)
  3339. {
  3340. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3341. {
  3342. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3343. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3344. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3345. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3346. goto end;
  3347. }
  3348. }
  3349. }// END FOR AC ELSE
  3350. //The reservationId does NOT match the reservationId
  3351. sendCancelReservationConfirmation(uuid, comfirmstr);
  3352. end:
  3353. // Fill in ocpp packet uuid
  3354. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3355. return result;
  3356. }
  3357. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3358. {
  3359. mtrace();
  3360. int result = FAIL;
  3361. int gunIndex = 0;
  3362. char sstr[90]={0};
  3363. char typeStr[16]={0};
  3364. char comfirmstr[20];
  3365. int specificId = FALSE;
  3366. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3367. char *loc;
  3368. //int intervalInt = 0;
  3369. int c = 0;
  3370. /*** connectorId ****/
  3371. c = 0;
  3372. loc = strstr(payload, "connectorId");
  3373. memset(sstr ,0, sizeof(sstr) );
  3374. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3375. {
  3376. sstr[c] = loc[strlen("connectorId")+2+c];
  3377. c++;
  3378. }
  3379. sstr[c] = '\0';
  3380. gunIndex = atoi(sstr);
  3381. /***type ****/
  3382. loc = strstr(payload, "type");
  3383. memset(sstr ,0, sizeof(sstr) );
  3384. c = 0;
  3385. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3386. {
  3387. sstr[c] = loc[3+strlen("type")+c];
  3388. c++;
  3389. }
  3390. sstr[c] = '\0';
  3391. strcpy(typeStr, sstr);
  3392. if(gunIndex != 0)
  3393. {
  3394. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3395. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3396. }
  3397. else
  3398. {
  3399. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3400. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3401. }
  3402. memset(comfirmstr, 0, sizeof comfirmstr);
  3403. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3404. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3405. {
  3406. specificId = TRUE;
  3407. }
  3408. if(specificId == FALSE)
  3409. goto end;
  3410. if(gunIndex != 0)
  3411. {
  3412. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3413. }
  3414. else
  3415. {
  3416. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3417. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3418. }
  3419. /*
  3420. enum _SYSTEM_STATUS
  3421. {
  3422. S_BOOTING = 0,
  3423. S_IDLE, = 1
  3424. S_AUTHORIZING, =2
  3425. S_REASSIGN_CHECK, =3
  3426. S_REASSIGN, =4
  3427. S_PRECHARGE, =5
  3428. S_PREPARING_FOR_EV, =6
  3429. S_PREPARING_FOR_EVSE, =7
  3430. S_CHARGING, =8
  3431. S_TERMINATING, =9
  3432. S_COMPLETE, =10
  3433. S_ALARM, =11
  3434. S_FAULT =12
  3435. }
  3436. */
  3437. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3438. {
  3439. //check Transaction active
  3440. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3441. {
  3442. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3443. {
  3444. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3445. {
  3446. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3447. {
  3448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3449. }
  3450. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3451. {
  3452. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3453. }
  3454. else
  3455. {
  3456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3457. }
  3458. goto end;
  3459. }
  3460. }//END FOR CHAdeMO_QUANTITY
  3461. for (int index = 0; index < CCS_QUANTITY; index++)
  3462. {
  3463. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3464. {
  3465. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3466. {
  3467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3468. }
  3469. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3470. {
  3471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3472. }
  3473. else
  3474. {
  3475. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3476. }
  3477. goto end;
  3478. }
  3479. }//END FOR CCS_QUANTITY
  3480. for (int index = 0; index < GB_QUANTITY; index++)
  3481. {
  3482. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3483. {
  3484. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3485. {
  3486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3487. }
  3488. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3489. {
  3490. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3491. }
  3492. else
  3493. {
  3494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3495. }
  3496. goto end;
  3497. }
  3498. }// END FOR GB_QUANTITY
  3499. }
  3500. else
  3501. {
  3502. for (int index = 0; index < AC_QUANTITY; index++)
  3503. {
  3504. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3505. {
  3506. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3507. {
  3508. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3509. }
  3510. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3511. {
  3512. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3513. }
  3514. else
  3515. {
  3516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3517. }
  3518. goto end;
  3519. }
  3520. }//END FOR AC_QUANTITY
  3521. }// END FOR AC ELSE
  3522. }//END FOR AvailabilityTypeStr[Inoperative]
  3523. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3524. {
  3525. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3526. //check Transaction active
  3527. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3528. {
  3529. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3530. {
  3531. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3532. {
  3533. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3534. goto end;
  3535. }
  3536. }//END FOR CHAdeMO_QUANTITY
  3537. for (int index = 0; index < CCS_QUANTITY; index++)
  3538. {
  3539. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3540. {
  3541. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3542. goto end;
  3543. }
  3544. }//END FOR CCS_QUANTITY
  3545. for (int index = 0; index < GB_QUANTITY; index++)
  3546. {
  3547. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3548. {
  3549. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3551. goto end;
  3552. }
  3553. }// END FOR GB_QUANTITY
  3554. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3555. }
  3556. else
  3557. {
  3558. for (int index = 0; index < AC_QUANTITY; index++)
  3559. {
  3560. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3561. {
  3562. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3563. goto end;
  3564. }
  3565. }//END FOR CHAdeMO_QUANTITY
  3566. }//END FOR AC ELSE
  3567. }//END FOR AvailabilityTypeStr[Operative]
  3568. end:
  3569. if(gunIndex != 0)
  3570. {
  3571. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3572. }
  3573. else
  3574. {
  3575. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3576. }
  3577. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3578. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3579. return result;
  3580. }
  3581. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3582. {
  3583. mtrace();
  3584. int result = FAIL;
  3585. char sstr[100]={0};
  3586. char keystr[40]={0};
  3587. char valuestr[16]={0};
  3588. char *loc;
  3589. int c = 0;
  3590. char comfirmstr[20];
  3591. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3592. /***key ****/
  3593. loc = strstr(payload, "key");
  3594. memset(sstr ,0, sizeof(sstr) );
  3595. c = 0;
  3596. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3597. {
  3598. sstr[c] = loc[3+strlen("key")+c];
  3599. c++;
  3600. }
  3601. sstr[c] = '\0';
  3602. strcpy(keystr, sstr);
  3603. /***value ****/
  3604. loc = strstr(payload, "value");
  3605. memset(sstr ,0, sizeof(sstr) );
  3606. c = 0;
  3607. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3608. {
  3609. sstr[c] = loc[3+strlen("value")+c];
  3610. c++;
  3611. }
  3612. sstr[c] = '\0';
  3613. strcpy(valuestr, sstr);
  3614. if((uuid==NULL) || (payload ==NULL) )
  3615. {
  3616. #ifdef Debug
  3617. DEBUG_INFO("payload is null\n");
  3618. #endif
  3619. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3620. }
  3621. else
  3622. {
  3623. int status = setKeyValue(keystr, valuestr);
  3624. switch(status)
  3625. {
  3626. case ConfigurationStatus_Accepted:
  3627. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3628. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3629. break;
  3630. case ConfigurationStatus_Rejected:
  3631. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3632. break;
  3633. case RebootRequired:
  3634. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3635. break;
  3636. case NotSupported:
  3637. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3638. break;
  3639. default:
  3640. break;
  3641. }
  3642. }
  3643. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3644. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3645. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3646. return result;
  3647. }
  3648. int handleClearCacheRequest(char *uuid, char *payload)
  3649. {
  3650. mtrace();
  3651. int result = FAIL;
  3652. char comfirmstr[20];
  3653. int fd;
  3654. char rmFileCmd[100]={0};
  3655. struct stat stats;
  3656. DEBUG_ERROR("handle ClearCacheRequest\n");
  3657. stat("../Storage/OCPP", &stats);
  3658. // Check for directory existence
  3659. if (S_ISDIR(stats.st_mode) == 1)
  3660. {
  3661. //DEBUG_ERROR("\n OCPP directory exist \n");
  3662. }
  3663. else
  3664. {
  3665. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3666. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3667. system(rmFileCmd);
  3668. }
  3669. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  3670. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3671. {
  3672. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3673. }
  3674. else
  3675. {
  3676. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3677. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3678. if(log == NULL)
  3679. {
  3680. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3681. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3682. goto end;
  3683. }
  3684. else
  3685. {
  3686. fclose(log);
  3687. }
  3688. }
  3689. fd = open(AuthorizationCache_JSON,O_RDWR);
  3690. if(fd < 0)
  3691. {
  3692. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3693. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3694. }
  3695. else
  3696. {
  3697. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3698. //* 清空?�件 */
  3699. ftruncate(fd,0);
  3700. //* ?�新设置?�件?�移??*/
  3701. lseek(fd,0,SEEK_SET);
  3702. close(fd);
  3703. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3704. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3705. }
  3706. end:
  3707. sendClearCacheConfirmation(uuid, comfirmstr);
  3708. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3709. return result;
  3710. }
  3711. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3712. {
  3713. mtrace();
  3714. int result = FAIL;
  3715. int resultRename;
  3716. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3717. char chargingProfilePurposeStr[26]={0};
  3718. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3719. char tempchargingProfilePurposeStr[26]={0};
  3720. char sstr[160]={0};//sstr[200]={ 0 };
  3721. char str[100]={0};
  3722. int c = 0;
  3723. //int i = 0;
  3724. //char * pch;
  3725. char *loc;
  3726. char fname[200];
  3727. char comfirmstr[20]={0};
  3728. char word[1000]={0};
  3729. int clearflag = FALSE;
  3730. int chargingProfileIdIsNULL = FALSE;
  3731. int connectorIsNULL = FALSE;
  3732. int chargingProfilePurposeIsNULL = FALSE;
  3733. int stackLevelIsNULL = FALSE;
  3734. FILE *fptr1, *fptr2;
  3735. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3736. int n_chargingProfile=0;
  3737. char sLineWord[1060]={0};
  3738. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3739. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3740. //***id ****/
  3741. c = 0;
  3742. loc = strstr(payload, "id");
  3743. memset(sstr ,0, sizeof(sstr) );
  3744. if(loc == NULL)
  3745. {
  3746. chargingProfileIdIsNULL = TRUE;
  3747. }
  3748. else
  3749. {
  3750. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3751. {
  3752. sstr[c] = loc[strlen("id")+2+c];
  3753. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3754. c++;
  3755. }
  3756. sstr[c] = '\0';
  3757. chargingProfileIdInt = atoi(sstr);
  3758. }
  3759. //***connectorId ****/
  3760. c=0;
  3761. loc = strstr(payload, "connectorId");
  3762. memset(sstr ,0, sizeof(sstr) );
  3763. if(loc == NULL)
  3764. {
  3765. connectorIsNULL = TRUE;
  3766. }
  3767. else
  3768. {
  3769. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3770. {
  3771. sstr[c] = loc[strlen("connectorId")+2+c];
  3772. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3773. c++;
  3774. }
  3775. sstr[c] = '\0';
  3776. connectorIdInt = atoi(sstr);
  3777. }
  3778. //***chargingProfilePurpose ****/
  3779. loc = strstr(payload, "chargingProfilePurpose");
  3780. memset(sstr ,0, sizeof(sstr) );
  3781. c = 0;
  3782. if(loc == NULL)
  3783. {
  3784. chargingProfilePurposeIsNULL = TRUE;
  3785. }
  3786. else
  3787. {
  3788. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3789. {
  3790. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3791. c++;
  3792. }
  3793. sstr[c] = '\0';
  3794. strcpy(chargingProfilePurposeStr, sstr);
  3795. }
  3796. //***stackLevel ****/
  3797. c=0;
  3798. loc = strstr(payload, "stackLevel");
  3799. memset(sstr ,0, sizeof(sstr) );
  3800. if(loc == NULL)
  3801. {
  3802. stackLevelIsNULL = TRUE;
  3803. }
  3804. else
  3805. {
  3806. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3807. {
  3808. sstr[c] = loc[strlen("stackLevel")+2+c];
  3809. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3810. c++;
  3811. }
  3812. sstr[c] = '\0';
  3813. stackLevelInt = atoi(sstr);
  3814. }
  3815. if(connectorIsNULL == FALSE)
  3816. {
  3817. switch(connectorIdInt)
  3818. {
  3819. case 0:
  3820. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3821. {
  3822. strcpy(fname, ChargePointMaxProfile_JSON);
  3823. }
  3824. // else
  3825. // {
  3826. // strcpy(fname, TxDefaultProfile_0_JSON);
  3827. // }
  3828. break;
  3829. case 1:
  3830. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3831. {
  3832. strcpy(fname, TxDefaultProfile_1_JSON);
  3833. }
  3834. // else
  3835. // {
  3836. // strcpy(fname, TxProfile_1_JSON);
  3837. // }
  3838. break;
  3839. case 2:
  3840. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3841. {
  3842. strcpy(fname, TxDefaultProfile_2_JSON);
  3843. }
  3844. // else
  3845. // {
  3846. // strcpy(fname, TxProfile_2_JSON);
  3847. // }
  3848. break;
  3849. default:
  3850. strcpy(fname, ChargePointMaxProfile_JSON );
  3851. break;
  3852. }
  3853. }
  3854. else
  3855. {
  3856. strcpy(fname, ChargePointMaxProfile_JSON );
  3857. }
  3858. fptr1 = fopen(fname, "r");
  3859. if (!fptr1)
  3860. {
  3861. //file not exist
  3862. DEBUG_ERROR("Unable to open the input file!!\n");
  3863. fptr1 = fopen(fname, "w+");
  3864. }
  3865. fclose(fptr1);
  3866. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3867. {
  3868. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3869. goto end;
  3870. }
  3871. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3872. {
  3873. //clear the whole contents of a file in C
  3874. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3875. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3876. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3877. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3878. fclose(fopen(TxProfile_1_JSON, "w"));
  3879. fclose(fopen(TxProfile_2_JSON, "w"));
  3880. #if 0
  3881. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3882. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3883. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3884. #endif
  3885. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3886. }
  3887. else
  3888. {
  3889. fptr1 = fopen(fname, "r");
  3890. fptr2 = fopen(temp, "w+");
  3891. while(fscanf(fptr1, "%s", word) != EOF)
  3892. {
  3893. //DEBUG_INFO("word=%s\n",word);
  3894. if(strcmp(word, "chargingProfileId") == 0)
  3895. {
  3896. n_chargingProfile = n_chargingProfile + 1;
  3897. DEBUG_INFO("chargingProfileId Found\n");
  3898. }
  3899. }
  3900. rewind(fptr1);
  3901. //search Charging Profile Element
  3902. //int i= 0;
  3903. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3904. {
  3905. //*************************tempconnectorIdInt*********************************/
  3906. loc = strstr(sLineWord, "connectorId");
  3907. c = 0;
  3908. memset(sstr ,0, sizeof(sstr) );
  3909. while (loc[strlen("connectorId")+2+c] != ',')
  3910. {
  3911. sstr[c] = loc[strlen("connectorId")+2+c];
  3912. c++;
  3913. }
  3914. sstr[c] = '\0';
  3915. tempconnectorIdInt = atoi(sstr);
  3916. //chargingProfileId
  3917. c = 0;
  3918. loc = strstr(sLineWord, "chargingProfileId");
  3919. memset(sstr ,0, sizeof(sstr) );
  3920. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3921. {
  3922. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3923. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3924. c++;
  3925. }
  3926. sstr[c] = '\0';
  3927. tempchargingProfileIdInt = atoi(sstr);
  3928. //stackLevel
  3929. c = 0;
  3930. loc = strstr(sLineWord, "stackLevel");
  3931. memset(sstr ,0, sizeof(sstr) );
  3932. while (loc[strlen("stackLevel")+2+c] != ',')
  3933. {
  3934. sstr[c] = loc[strlen("stackLevel")+2+c];
  3935. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3936. c++;
  3937. }
  3938. sstr[c] = '\0';
  3939. tempstackLevelInt = atoi(sstr);
  3940. c = 0;
  3941. loc = strstr(sLineWord, "chargingProfilePurpose");
  3942. memset(sstr ,0, sizeof(sstr) );
  3943. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3944. {
  3945. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3946. c++;
  3947. }
  3948. sstr[c] = '\0';
  3949. strcpy(tempchargingProfilePurposeStr, sstr);
  3950. if(chargingProfileIdIsNULL == FALSE)
  3951. {
  3952. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3953. {
  3954. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3955. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3956. clearflag = TRUE;
  3957. continue;
  3958. }
  3959. else
  3960. {
  3961. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3962. //json_object_array_add(newHeatMap, jsonitem);
  3963. fprintf(fptr2, sLineWord);//writing data into file
  3964. }
  3965. }
  3966. else
  3967. {
  3968. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3969. {
  3970. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3971. {
  3972. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3973. clearflag = TRUE;
  3974. continue;
  3975. }
  3976. }
  3977. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3978. {
  3979. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3980. {
  3981. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3982. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3983. {
  3984. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3985. clearflag = TRUE;
  3986. continue;
  3987. }
  3988. }
  3989. }
  3990. else
  3991. {
  3992. //json_object_array_add(newHeatMap, jsonitem);
  3993. fprintf(fptr2, sLineWord);//writing data into file
  3994. }
  3995. }
  3996. memset(sLineWord, 0, sizeof sLineWord);
  3997. }
  3998. if(clearflag == FALSE)
  3999. {
  4000. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4001. goto end;
  4002. }
  4003. fclose(fptr1);
  4004. fclose(fptr2);
  4005. sprintf(str,"rm -f %s",fname);
  4006. system(str);
  4007. resultRename = rename(temp, fname);
  4008. if(resultRename == 0)
  4009. {
  4010. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4011. }
  4012. else
  4013. {
  4014. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4015. }
  4016. }
  4017. end:
  4018. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4019. return result;
  4020. }
  4021. int handleDataTransferRequest(char *uuid, char *payload)
  4022. {
  4023. mtrace();
  4024. int result = FAIL;
  4025. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4026. char tempvendorId[255]={0};
  4027. char tempmessageId[50]={0};
  4028. char tempdata[50]={0};
  4029. char sstr[160]={0};//sstr[200]={ 0 };
  4030. char message[80]={0};
  4031. int c = 0;
  4032. char *loc;
  4033. DEBUG_INFO("handle DataTransferRequest\n");
  4034. if((uuid != NULL) && (payload != NULL))
  4035. {
  4036. //===============================
  4037. // vendorId
  4038. //===============================
  4039. c = 0;
  4040. loc = strstr(payload, "vendorId");
  4041. while (loc[strlen("vendorId")+3+c] != '\"')
  4042. {
  4043. sstr[c] = loc[strlen("vendorId")+3+c];
  4044. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4045. c++;
  4046. }
  4047. sstr[c] = '\0';
  4048. strcpy(tempvendorId,sstr);
  4049. //===============================
  4050. // messageId
  4051. //===============================
  4052. memset(sstr ,0, sizeof(sstr) );
  4053. c = 0;
  4054. loc = strstr(payload, "messageId");
  4055. while (loc[strlen("messageId")+3+c] != '\"')
  4056. {
  4057. sstr[c] = loc[strlen("messageId")+3+c];
  4058. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4059. c++;
  4060. }
  4061. sstr[c] = '\0';
  4062. strcpy(tempmessageId,sstr);
  4063. //===============================
  4064. // data
  4065. //===============================
  4066. memset(sstr ,0, sizeof(sstr) );
  4067. c = 0;
  4068. loc = strstr(payload, "data");
  4069. printf("loc=%s\n",loc);
  4070. while (loc[strlen("data")+3+c] != '\"')
  4071. {
  4072. sstr[c] = loc[strlen("data")+3+c];
  4073. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4074. c++;
  4075. }
  4076. sstr[c] = '\0';
  4077. strcpy(tempdata,sstr);
  4078. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4079. }
  4080. else
  4081. {
  4082. char guid[37]={0};
  4083. random_uuid(guid);
  4084. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4085. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4086. }
  4087. LWS_Send(message);
  4088. return result;
  4089. }
  4090. #if 0
  4091. long long diff_tm(struct tm *a, struct tm *b) {
  4092. return a->tm_sec - b->tm_sec
  4093. + 60LL * (a->tm_min - b->tm_min)
  4094. + 3600LL * (a->tm_hour - b->tm_hour)
  4095. + 86400LL * (a->tm_yday - b->tm_yday)
  4096. + (a->tm_year - 70) * 31536000LL
  4097. - (a->tm_year - 69) / 4 * 86400LL
  4098. + (a->tm_year - 1) / 100 * 86400LL
  4099. - (a->tm_year + 299) / 400 * 86400LL
  4100. - (b->tm_year - 70) * 31536000LL
  4101. + (b->tm_year - 69) / 4 * 86400LL
  4102. - (b->tm_year - 1) / 100 * 86400LL
  4103. + (b->tm_year + 299) /400 * 86400LL;
  4104. }
  4105. #endif
  4106. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4107. {
  4108. mtrace();
  4109. int result = FAIL;
  4110. int connectorIdInt, durationInt;
  4111. char chargingRateUnitStr[4]={0};
  4112. //int tempconnectorIdInt,
  4113. int tempdurationInt;
  4114. float tempminChargingRateFloat = 0.0;
  4115. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4116. int tempStartPeriodInt=0;
  4117. float tempLimitInt=0.0;//0.1;
  4118. int tempNumberPhasesInt=0;
  4119. char fname[200];
  4120. char comfirmstr[20];
  4121. //float totallimit =0.0;
  4122. float MinChargingRate =0.0;
  4123. double diff_t;
  4124. struct tm tp;
  4125. //int clearflag = FALSE;
  4126. FILE *fptr1;//, *fptr2;
  4127. //char temp[] = "../Storage/OCPP/temp.json";
  4128. int c = 0;
  4129. //int i = 0;
  4130. char * pch;
  4131. char *loc;
  4132. char sstr[200]={ 0 };
  4133. int n_chargingProfile = 0;
  4134. int n_SchedulePeriods = 0;
  4135. char SchedulePeriodList[10][200]={0};
  4136. char sLineWord[800]={0};
  4137. //int n_periods = 0;
  4138. char word[1000]={0};
  4139. int confirmPeriods = 0;
  4140. struct StructProfile ChargePointMaxProfile;
  4141. struct StructProfile TxDefaultProfile;
  4142. struct StructProfile TxProfile;
  4143. struct StructProfile TxDefaultProfiletemp[2]={0};
  4144. int TxDefaultProfileFileIsNull=FALSE;
  4145. int ChargePointMaxProfileIsNull=FALSE;
  4146. int TxProfileIsNull=FALSE;
  4147. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4148. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4149. memset(&TxProfile,0,sizeof(struct StructProfile));
  4150. c=0;
  4151. loc = strstr(payload, "connectorId");
  4152. memset(sstr ,0, sizeof(sstr) );
  4153. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4154. {
  4155. sstr[c] = loc[strlen("connectorId")+2+c];
  4156. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4157. c++;
  4158. }
  4159. sstr[c] = '\0';
  4160. connectorIdInt = atoi(sstr);
  4161. c=0;
  4162. loc = strstr(payload, "duration");
  4163. memset(sstr ,0, sizeof(sstr) );
  4164. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4165. {
  4166. sstr[c] = loc[strlen("duration")+2+c];
  4167. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4168. c++;
  4169. }
  4170. sstr[c] = '\0';
  4171. durationInt = atoi(sstr);
  4172. c = 0;
  4173. loc = strstr(payload, "chargingRateUnit");
  4174. memset(sstr ,0, sizeof(sstr) );
  4175. if(loc == NULL)
  4176. {
  4177. }
  4178. else
  4179. {
  4180. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4181. {
  4182. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4183. c++;
  4184. }
  4185. sstr[c] = '\0';
  4186. strcpy(chargingRateUnitStr, sstr);
  4187. }
  4188. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4189. if(connectorIdInt==0) // connectorId is 0
  4190. {
  4191. //******************************ChargePointMaxProfile*****************************************************/
  4192. strcpy(fname, ChargePointMaxProfile_JSON );
  4193. char word[30]={0};
  4194. char sLineWord[1060]={0};
  4195. int n_chargingProfile=0;
  4196. ChargePointMaxProfileIsNull=TRUE;
  4197. if((access(fname,F_OK))!=-1)
  4198. {
  4199. fptr1 = fopen(fname, "r");
  4200. int c;
  4201. c = fgetc(fptr1);
  4202. //DEBUG_INFO("c:%d\n",c);
  4203. rewind(fptr1);
  4204. if(c == EOF)
  4205. {
  4206. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4207. ChargePointMaxProfileIsNull=TRUE;
  4208. fclose(fptr1);
  4209. }
  4210. else
  4211. {
  4212. ChargePointMaxProfileIsNull=FALSE;
  4213. while(fscanf(fptr1, "%s", word) != EOF)
  4214. {
  4215. if(strcmp(word, "chargingProfileId") == 0)
  4216. {
  4217. n_chargingProfile = n_chargingProfile + 1;
  4218. printf("Found\n");
  4219. }
  4220. }
  4221. rewind(fptr1);
  4222. //search Charging Profile Element
  4223. int i= 0;
  4224. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4225. #if 0
  4226. /***********connectorId****************/
  4227. c = 0;
  4228. loc = strstr(sLineWord, "connectorId");
  4229. // printf("loc=%s\n",loc);
  4230. memset(sstr ,0, sizeof(sstr) );
  4231. while (loc[strlen("connectorId")+2+c] != ',')
  4232. {
  4233. sstr[c] = loc[strlen("connectorId")+2+c];
  4234. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4235. c++;
  4236. }
  4237. sstr[c] = '\0';
  4238. tempconnectorIdInt = atoi(sstr);
  4239. #endif
  4240. //***********validFrom**************/
  4241. c = 0;
  4242. loc = strstr(sLineWord, "validFrom");
  4243. //DEBUG_INFO("loc=%s\n",loc);
  4244. memset(sstr ,0, sizeof(sstr) );
  4245. if(loc != NULL)
  4246. {
  4247. while (loc[3+strlen("validFrom")+c] != '\"')
  4248. {
  4249. sstr[c] = loc[3+strlen("validFrom")+c];
  4250. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4251. c++;
  4252. }
  4253. sstr[c] = '\0';
  4254. DEBUG_INFO("validFrom=%s\n",sstr);
  4255. strcpy(tempvalidFromStr,sstr);
  4256. }
  4257. else
  4258. {
  4259. strcpy(tempvalidFromStr,"");
  4260. }
  4261. //**********startSchedule**********/
  4262. c = 0;
  4263. loc = strstr(sLineWord, "startSchedule");
  4264. //DEBUG_INFO("loc=%s\n",loc);
  4265. memset(sstr ,0, sizeof(sstr) );
  4266. while (loc[3+strlen("startSchedule")+c] != '\"')
  4267. {
  4268. sstr[c] = loc[3+strlen("startSchedule")+c];
  4269. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4270. c++;
  4271. }
  4272. sstr[c] = '\0';
  4273. strcpy(tempstartScheduleStr, sstr);
  4274. //**********startSchedule**********/
  4275. c = 0;
  4276. loc = strstr(sLineWord, "chargingRateUnit");
  4277. memset(sstr ,0, sizeof(sstr) );
  4278. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4279. {
  4280. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4281. c++;
  4282. }
  4283. sstr[c] = '\0';
  4284. strcpy(tempchargingRateUnitStr, sstr);
  4285. //**********minChargingRate*******/
  4286. c = 0;
  4287. loc = strstr(sLineWord, "minChargingRate");
  4288. //printf("loc=%s\n",loc);
  4289. if(loc != NULL)
  4290. {
  4291. memset(sstr ,0, sizeof(sstr) );
  4292. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4293. {
  4294. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4295. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4296. c++;
  4297. }
  4298. sstr[c] = '\0';
  4299. tempminChargingRateFloat = atof(sstr);
  4300. }
  4301. else
  4302. {
  4303. tempminChargingRateFloat = 0.0;
  4304. }
  4305. //
  4306. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4307. tp.tm_isdst = -1;
  4308. time_t utc = mktime(&tp);
  4309. // current time
  4310. time_t t = time(NULL);
  4311. diff_t = difftime(t, utc);
  4312. //parsing strings to words
  4313. i = 0;
  4314. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4315. loc = loc+3+strlen("chargingSchedulePeriod");
  4316. pch = strtok(loc ,"{");
  4317. while (pch != NULL)
  4318. {
  4319. strcpy(SchedulePeriodList[i], pch);
  4320. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4321. //printf ("%s\n",pch);
  4322. pch = strtok (NULL, "{");
  4323. i = i + 1;
  4324. }
  4325. n_SchedulePeriods = i;
  4326. for(int i=0;i<n_SchedulePeriods;i++)
  4327. {
  4328. //*************startPeriod****************/
  4329. c = 0;
  4330. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4331. memset(sstr ,0, sizeof(sstr) );
  4332. while (loc[strlen("startPeriod")+2+c] != ',')
  4333. {
  4334. sstr[c] = loc[strlen("startPeriod")+2+c];
  4335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4336. c++;
  4337. }
  4338. sstr[c] = '\0';
  4339. tempStartPeriodInt = atoi(sstr);
  4340. //*************limit****************/
  4341. c = 0;
  4342. loc = strstr(SchedulePeriodList[i], "limit");
  4343. memset(sstr ,0, sizeof(sstr) );
  4344. while (loc[strlen("limit")+2+c] != ',')
  4345. {
  4346. sstr[c] = loc[strlen("limit")+2+c];
  4347. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4348. c++;
  4349. }
  4350. sstr[c] = '\0';
  4351. tempLimitInt = atof(sstr);
  4352. //*************numberPhases****************/
  4353. c = 0;
  4354. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4355. memset(sstr ,0, sizeof(sstr) );
  4356. while (loc[strlen("numberPhases")+2+c] != ',')
  4357. {
  4358. sstr[c] = loc[strlen("numberPhases")+2+c];
  4359. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4360. c++;
  4361. }
  4362. sstr[c] = '\0';
  4363. tempNumberPhasesInt = atoi(sstr);
  4364. ChargePointMaxProfile.Duration = durationInt;
  4365. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4366. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4367. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4368. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4369. }
  4370. if(MinChargingRate < tempminChargingRateFloat)
  4371. MinChargingRate = tempminChargingRateFloat;
  4372. }
  4373. }// End of file ChargingProfile
  4374. } //THE END OF ACCESS ChargePointMaxProfile
  4375. //******************************TxDefaultProfile***********************************************/
  4376. strcpy(fname, TxDefaultProfile_0_JSON);
  4377. memset(word, 0, 30);
  4378. memset(sLineWord, 0, 1060);
  4379. //char word[30]={0};
  4380. //char sLineWord[1060]={0};
  4381. n_chargingProfile=0;
  4382. TxDefaultProfileFileIsNull=TRUE;
  4383. if((access(fname,F_OK))!=-1)
  4384. {
  4385. fptr1 = fopen(fname, "r");
  4386. c = 0;
  4387. c = fgetc(fptr1);
  4388. //DEBUG_INFO("c:%d\n",c);
  4389. rewind(fptr1);
  4390. if(c == EOF)
  4391. {
  4392. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4393. TxDefaultProfileFileIsNull=TRUE;
  4394. fclose(fptr1);
  4395. }
  4396. else
  4397. {
  4398. TxDefaultProfileFileIsNull=FALSE;
  4399. while(fscanf(fptr1, "%s", word) != EOF)
  4400. {
  4401. if(strcmp(word, "chargingProfileId") == 0)
  4402. {
  4403. n_chargingProfile = n_chargingProfile + 1;
  4404. printf("Found\n");
  4405. }
  4406. }
  4407. rewind(fptr1);
  4408. //search Charging Profile Element
  4409. int i= 0;
  4410. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4411. #if 0
  4412. /***********connectorId****************/
  4413. c = 0;
  4414. loc = strstr(sLineWord, "connectorId");
  4415. // printf("loc=%s\n",loc);
  4416. memset(sstr ,0, sizeof(sstr) );
  4417. while (loc[strlen("connectorId")+2+c] != ',')
  4418. {
  4419. sstr[c] = loc[strlen("connectorId")+2+c];
  4420. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4421. c++;
  4422. }
  4423. sstr[c] = '\0';
  4424. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4425. tempconnectorIdInt = atoi(sstr);
  4426. #endif
  4427. //***********validFrom**************/
  4428. c = 0;
  4429. loc = strstr(sLineWord, "validFrom");
  4430. //DEBUG_INFO("loc=%s\n",loc);
  4431. memset(sstr ,0, sizeof(sstr) );
  4432. if(loc != NULL)
  4433. {
  4434. while (loc[3+strlen("validFrom")+c] != '\"')
  4435. {
  4436. sstr[c] = loc[3+strlen("validFrom")+c];
  4437. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4438. c++;
  4439. }
  4440. sstr[c] = '\0';
  4441. DEBUG_INFO("validFrom=%s\n",sstr);
  4442. strcpy(tempvalidFromStr,sstr);
  4443. }
  4444. else
  4445. {
  4446. strcpy(tempvalidFromStr,"");
  4447. }
  4448. //**********startSchedule**********/
  4449. c = 0;
  4450. loc = strstr(sLineWord, "startSchedule");
  4451. //DEBUG_INFO("loc=%s\n",loc);
  4452. memset(sstr ,0, sizeof(sstr) );
  4453. while (loc[3+strlen("startSchedule")+c] != '\"')
  4454. {
  4455. sstr[c] = loc[3+strlen("startSchedule")+c];
  4456. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4457. c++;
  4458. }
  4459. sstr[c] = '\0';
  4460. strcpy(tempstartScheduleStr, sstr);
  4461. DEBUG_INFO(" debug 3-1\n");
  4462. //**********startSchedule**********/
  4463. c = 0;
  4464. loc = strstr(sLineWord, "chargingRateUnit");
  4465. memset(sstr ,0, sizeof(sstr) );
  4466. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4467. {
  4468. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4469. c++;
  4470. }
  4471. sstr[c] = '\0';
  4472. strcpy(tempchargingRateUnitStr, sstr);
  4473. //**********minChargingRate*******/
  4474. c = 0;
  4475. loc = strstr(sLineWord, "minChargingRate");
  4476. //printf("loc=%s\n",loc);
  4477. if(loc != NULL)
  4478. {
  4479. memset(sstr ,0, sizeof(sstr) );
  4480. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4481. {
  4482. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4483. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4484. c++;
  4485. }
  4486. sstr[c] = '\0';
  4487. tempminChargingRateFloat = atof(sstr);
  4488. }
  4489. else
  4490. {
  4491. tempminChargingRateFloat = 0.0;
  4492. }
  4493. //
  4494. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4495. tp.tm_isdst = -1;
  4496. time_t utc = mktime(&tp);
  4497. // current time
  4498. time_t t = time(NULL);
  4499. diff_t = difftime(t, utc);
  4500. //parsing strings to words
  4501. i = 0;
  4502. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4503. loc = loc+3+strlen("chargingSchedulePeriod");
  4504. pch = strtok(loc ,"{");
  4505. while (pch != NULL)
  4506. {
  4507. strcpy(SchedulePeriodList[i], pch);
  4508. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4509. //printf ("%s\n",pch);
  4510. pch = strtok (NULL, "{");
  4511. i = i + 1;
  4512. }
  4513. n_SchedulePeriods = i;
  4514. for(int i=0;i<n_SchedulePeriods;i++)
  4515. {
  4516. //*************startPeriod****************/
  4517. c = 0;
  4518. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4519. memset(sstr ,0, sizeof(sstr) );
  4520. while (loc[strlen("startPeriod")+2+c] != ',')
  4521. {
  4522. sstr[c] = loc[strlen("startPeriod")+2+c];
  4523. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4524. c++;
  4525. }
  4526. sstr[c] = '\0';
  4527. tempStartPeriodInt = atoi(sstr);
  4528. //*************limit****************/
  4529. c = 0;
  4530. loc = strstr(SchedulePeriodList[i], "limit");
  4531. memset(sstr ,0, sizeof(sstr) );
  4532. while (loc[strlen("limit")+2+c] != ',')
  4533. {
  4534. sstr[c] = loc[strlen("limit")+2+c];
  4535. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4536. c++;
  4537. }
  4538. sstr[c] = '\0';
  4539. tempLimitInt = atof(sstr);
  4540. //*************numberPhases****************/
  4541. c = 0;
  4542. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4543. memset(sstr ,0, sizeof(sstr) );
  4544. while (loc[strlen("numberPhases")+2+c] != ',')
  4545. {
  4546. sstr[c] = loc[strlen("numberPhases")+2+c];
  4547. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4548. c++;
  4549. }
  4550. sstr[c] = '\0';
  4551. tempNumberPhasesInt = atoi(sstr);
  4552. TxDefaultProfile.Duration = durationInt;
  4553. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4554. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4555. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4556. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4557. }
  4558. if(MinChargingRate < tempminChargingRateFloat)
  4559. MinChargingRate = tempminChargingRateFloat;
  4560. }
  4561. }
  4562. }// the end of ACCESS TxDefaultProfile
  4563. // Composite Schedule
  4564. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4565. {
  4566. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4567. {
  4568. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4569. {
  4570. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4571. }
  4572. else
  4573. {
  4574. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4575. }
  4576. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4577. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4578. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4579. }
  4580. }
  4581. //* Define temporary variables */
  4582. struct tm *gtime;
  4583. time_t now;
  4584. char buf[28];
  4585. /* Read the current system time */
  4586. time(&now);
  4587. /* Convert the system time to GMT (now UTC) */
  4588. gtime = gmtime(&now);
  4589. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4590. // make .conf
  4591. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  4592. //MaxChargingProfilesInstalled is 10
  4593. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4594. memset(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4595. //nPeriod = 1;
  4596. if(chargingRateUnitStr[0] != 0)
  4597. {
  4598. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4599. }
  4600. else
  4601. {
  4602. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  4603. }
  4604. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4605. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4606. confirmPeriods = 1;
  4607. }
  4608. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4609. {
  4610. //*****************************ChargePointMaxProfile******************************************/
  4611. strcpy(fname, ChargePointMaxProfile_JSON);
  4612. ChargePointMaxProfileIsNull=TRUE;
  4613. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4614. {
  4615. fptr1 = fopen(fname, "r");
  4616. int c;
  4617. c = fgetc(fptr1);
  4618. //DEBUG_INFO("c:%d\n",c);
  4619. rewind(fptr1);
  4620. if(c == EOF)
  4621. {
  4622. DEBUG_INFO("\n End of file reached.");
  4623. ChargePointMaxProfileIsNull=TRUE;
  4624. fclose(fptr1);
  4625. }
  4626. else
  4627. {
  4628. ChargePointMaxProfileIsNull=FALSE;
  4629. while(fscanf(fptr1, "%s", word) != EOF)
  4630. {
  4631. if(strcmp(word, "chargingProfileId") == 0)
  4632. {
  4633. n_chargingProfile = n_chargingProfile + 1;
  4634. }
  4635. }
  4636. rewind(fptr1);
  4637. //search Charging Profile Element
  4638. int i = 0;
  4639. int j = 0;
  4640. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4641. #if 0
  4642. /***********connectorId****************/
  4643. c = 0;
  4644. loc = strstr(sLineWord, "connectorId");
  4645. memset(sstr ,0, sizeof(sstr) );
  4646. while (loc[strlen("connectorId")+2+c] != ',')
  4647. {
  4648. sstr[c] = loc[strlen("connectorId")+2+c];
  4649. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4650. c++;
  4651. }
  4652. sstr[c] = '\0';
  4653. tempconnectorIdInt = atoi(sstr);
  4654. #endif
  4655. //***********validFrom**************/
  4656. c = 0;
  4657. loc = strstr(sLineWord, "validFrom");
  4658. if(loc != NULL)
  4659. {
  4660. memset(sstr ,0, sizeof(sstr) );
  4661. while (loc[3+strlen("validFrom")+c] != '\"')
  4662. {
  4663. sstr[c] = loc[3+strlen("validFrom")+c];
  4664. c++;
  4665. }
  4666. sstr[c] = '\0';
  4667. strcpy(tempvalidFromStr,sstr);
  4668. }
  4669. else
  4670. {
  4671. strcpy(tempvalidFromStr,"");
  4672. }
  4673. //***********validFrom**************/
  4674. c = 0;
  4675. loc = strstr(sLineWord, "duration");
  4676. if(loc != NULL)
  4677. {
  4678. memset(sstr ,0, sizeof(sstr) );
  4679. while (loc[2+strlen("duration")+c] != ',')
  4680. {
  4681. sstr[c] = loc[2+strlen("duration")+c];
  4682. c++;
  4683. }
  4684. sstr[c] = '\0';
  4685. tempdurationInt = atoi(sstr);
  4686. }
  4687. else
  4688. {
  4689. tempdurationInt = 0;
  4690. }
  4691. //**********startSchedule**********/
  4692. c = 0;
  4693. loc = strstr(sLineWord, "startSchedule");
  4694. memset(sstr ,0, sizeof(sstr) );
  4695. while (loc[3+strlen("startSchedule")+c] != '\"')
  4696. {
  4697. sstr[c] = loc[3+strlen("startSchedule")+c];
  4698. c++;
  4699. }
  4700. sstr[c] = '\0';
  4701. strcpy(tempstartScheduleStr, sstr);
  4702. //**********startSchedule**********/
  4703. c = 0;
  4704. loc = strstr(sLineWord, "chargingRateUnit");
  4705. memset(sstr ,0, sizeof(sstr) );
  4706. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4707. {
  4708. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4709. c++;
  4710. }
  4711. sstr[c] = '\0';
  4712. strcpy(tempchargingRateUnitStr, sstr);
  4713. //**********minChargingRate*******/
  4714. c = 0;
  4715. loc = strstr(sLineWord, "minChargingRate");
  4716. if(loc != NULL)
  4717. {
  4718. memset(sstr ,0, sizeof(sstr) );
  4719. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4720. {
  4721. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4722. c++;
  4723. }
  4724. sstr[c] = '\0';
  4725. tempminChargingRateFloat = atof(sstr);
  4726. }
  4727. else
  4728. {
  4729. tempminChargingRateFloat = 0.0;
  4730. }
  4731. //
  4732. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4733. tp.tm_isdst = -1;
  4734. time_t utc = mktime(&tp);
  4735. time_t t = time(NULL);
  4736. diff_t = difftime(t, utc);
  4737. DEBUG_INFO("diff_t=%f\n",diff_t);
  4738. DEBUG_INFO(" debug 5 -1\n");
  4739. //parsing strings to words
  4740. i = 0;
  4741. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4742. loc = loc+3+strlen("chargingSchedulePeriod");
  4743. pch = strtok(loc ,"{");
  4744. while (pch != NULL)
  4745. {
  4746. strcpy(SchedulePeriodList[i], pch);
  4747. pch = strtok (NULL, "{");
  4748. i = i + 1;
  4749. }
  4750. n_SchedulePeriods = i;
  4751. for(int i=0;i<n_SchedulePeriods;i++)
  4752. {
  4753. //*************startPeriod****************/
  4754. c = 0;
  4755. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4756. memset(sstr ,0, sizeof(sstr) );
  4757. while (loc[strlen("startPeriod")+2+c] != ',')
  4758. {
  4759. sstr[c] = loc[strlen("startPeriod")+2+c];
  4760. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4761. c++;
  4762. }
  4763. sstr[c] = '\0';
  4764. tempStartPeriodInt = atoi(sstr);
  4765. //*************limit****************/
  4766. c = 0;
  4767. loc = strstr(SchedulePeriodList[i], "limit");
  4768. memset(sstr ,0, sizeof(sstr) );
  4769. while (loc[strlen("limit")+2+c] != ',')
  4770. {
  4771. sstr[c] = loc[strlen("limit")+2+c];
  4772. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4773. c++;
  4774. }
  4775. sstr[c] = '\0';
  4776. tempLimitInt = atof(sstr);
  4777. //*************numberPhases****************/
  4778. c = 0;
  4779. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4780. memset(sstr ,0, sizeof(sstr) );
  4781. while (loc[strlen("numberPhases")+2+c] != '}')
  4782. {
  4783. sstr[c] = loc[strlen("numberPhases")+2+c];
  4784. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4785. c++;
  4786. }
  4787. sstr[c] = '\0';
  4788. tempNumberPhasesInt = atoi(sstr);
  4789. if(j == 0)
  4790. {
  4791. ChargePointMaxProfile.Duration = tempdurationInt;
  4792. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4793. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4794. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4795. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4796. }
  4797. }
  4798. if(MinChargingRate < tempminChargingRateFloat)
  4799. {
  4800. MinChargingRate = tempminChargingRateFloat;
  4801. }
  4802. if(confirmPeriods < n_SchedulePeriods)
  4803. {
  4804. confirmPeriods = n_SchedulePeriods;
  4805. }
  4806. j = j + 1;
  4807. }
  4808. fclose(fptr1);
  4809. }
  4810. }// the end of access file ChargePointMaxProfile
  4811. //****************************TxDefaultProfile************************************************/
  4812. switch(connectorIdInt)
  4813. {
  4814. case 0:
  4815. break;
  4816. case 1:
  4817. strcpy(fname, TxDefaultProfile_1_JSON );
  4818. break;
  4819. case 2:
  4820. strcpy(fname, TxDefaultProfile_2_JSON );
  4821. break;
  4822. default:
  4823. strcpy(fname, TxDefaultProfile_1_JSON );
  4824. break;
  4825. }
  4826. TxDefaultProfileFileIsNull=TRUE;
  4827. if((access(fname,F_OK))!=-1)
  4828. {
  4829. fptr1 = fopen(fname, "r");
  4830. c = 0;
  4831. c = fgetc(fptr1);
  4832. //DEBUG_INFO("c:%d\n",c);
  4833. rewind(fptr1);
  4834. if(c == EOF)
  4835. {
  4836. DEBUG_INFO("\n End of file reached.");
  4837. TxDefaultProfileFileIsNull=TRUE;
  4838. fclose(fptr1);
  4839. }
  4840. else
  4841. {
  4842. TxDefaultProfileFileIsNull=FALSE;
  4843. while(fscanf(fptr1, "%s", word) != EOF)
  4844. {
  4845. if(strcmp(word, "chargingProfileId") == 0)
  4846. {
  4847. n_chargingProfile = n_chargingProfile + 1;
  4848. }
  4849. }
  4850. rewind(fptr1);
  4851. //search Charging Profile Element
  4852. int i = 0;
  4853. int j = 0;
  4854. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4855. #if 0
  4856. /***********connectorId****************/
  4857. c = 0;
  4858. loc = strstr(sLineWord, "connectorId");
  4859. memset(sstr ,0, sizeof(sstr) );
  4860. while (loc[strlen("connectorId")+2+c] != ',')
  4861. {
  4862. sstr[c] = loc[strlen("connectorId")+2+c];
  4863. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4864. c++;
  4865. }
  4866. sstr[c] = '\0';
  4867. tempconnectorIdInt = atoi(sstr);
  4868. #endif
  4869. //***********validFrom**************/
  4870. c = 0;
  4871. loc = strstr(sLineWord, "validFrom");
  4872. if(loc != NULL)
  4873. {
  4874. memset(sstr ,0, sizeof(sstr) );
  4875. while (loc[3+strlen("validFrom")+c] != '\"')
  4876. {
  4877. sstr[c] = loc[3+strlen("validFrom")+c];
  4878. c++;
  4879. }
  4880. sstr[c] = '\0';
  4881. strcpy(tempvalidFromStr,sstr);
  4882. }
  4883. else
  4884. {
  4885. strcpy(tempvalidFromStr,"");
  4886. }
  4887. //***********validFrom**************/
  4888. c = 0;
  4889. loc = strstr(sLineWord, "duration");
  4890. if(loc != NULL)
  4891. {
  4892. memset(sstr ,0, sizeof(sstr) );
  4893. while (loc[2+strlen("duration")+c] != ',')
  4894. {
  4895. sstr[c] = loc[2+strlen("duration")+c];
  4896. c++;
  4897. }
  4898. sstr[c] = '\0';
  4899. tempdurationInt = atoi(sstr);
  4900. }
  4901. else
  4902. {
  4903. tempdurationInt = 0;
  4904. }
  4905. //**********startSchedule**********/
  4906. c = 0;
  4907. loc = strstr(sLineWord, "startSchedule");
  4908. memset(sstr ,0, sizeof(sstr) );
  4909. while (loc[3+strlen("startSchedule")+c] != '\"')
  4910. {
  4911. sstr[c] = loc[3+strlen("startSchedule")+c];
  4912. c++;
  4913. }
  4914. sstr[c] = '\0';
  4915. strcpy(tempstartScheduleStr, sstr);
  4916. //**********startSchedule**********/
  4917. c = 0;
  4918. loc = strstr(sLineWord, "chargingRateUnit");
  4919. memset(sstr ,0, sizeof(sstr) );
  4920. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4921. {
  4922. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4923. c++;
  4924. }
  4925. sstr[c] = '\0';
  4926. strcpy(tempchargingRateUnitStr, sstr);
  4927. //**********minChargingRate*******/
  4928. c = 0;
  4929. loc = strstr(sLineWord, "minChargingRate");
  4930. if(loc != NULL)
  4931. {
  4932. memset(sstr ,0, sizeof(sstr) );
  4933. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4934. {
  4935. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4936. c++;
  4937. }
  4938. sstr[c] = '\0';
  4939. tempminChargingRateFloat = atof(sstr);
  4940. }
  4941. else
  4942. {
  4943. tempminChargingRateFloat = 0.0;
  4944. }
  4945. //
  4946. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4947. tp.tm_isdst = -1;
  4948. time_t utc = mktime(&tp);
  4949. time_t t = time(NULL);
  4950. diff_t = difftime(t, utc);
  4951. DEBUG_INFO("diff_t=%f\n",diff_t);
  4952. DEBUG_INFO(" debug 5 -1\n");
  4953. //parsing strings to words
  4954. i = 0;
  4955. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4956. loc = loc+3+strlen("chargingSchedulePeriod");
  4957. pch = strtok(loc ,"{");
  4958. while (pch != NULL)
  4959. {
  4960. strcpy(SchedulePeriodList[i], pch);
  4961. pch = strtok (NULL, "{");
  4962. i = i + 1;
  4963. }
  4964. n_SchedulePeriods = i;
  4965. for(int i=0;i<n_SchedulePeriods;i++)
  4966. {
  4967. //*************startPeriod****************/
  4968. c = 0;
  4969. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4970. memset(sstr ,0, sizeof(sstr) );
  4971. while (loc[strlen("startPeriod")+2+c] != ',')
  4972. {
  4973. sstr[c] = loc[strlen("startPeriod")+2+c];
  4974. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4975. c++;
  4976. }
  4977. sstr[c] = '\0';
  4978. tempStartPeriodInt = atoi(sstr);
  4979. //*************limit****************/
  4980. c = 0;
  4981. loc = strstr(SchedulePeriodList[i], "limit");
  4982. memset(sstr ,0, sizeof(sstr) );
  4983. while (loc[strlen("limit")+2+c] != ',')
  4984. {
  4985. sstr[c] = loc[strlen("limit")+2+c];
  4986. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4987. c++;
  4988. }
  4989. sstr[c] = '\0';
  4990. tempLimitInt = atof(sstr);
  4991. //*************numberPhases****************/
  4992. c = 0;
  4993. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4994. memset(sstr ,0, sizeof(sstr) );
  4995. while (loc[strlen("numberPhases")+2+c] != '}')
  4996. {
  4997. sstr[c] = loc[strlen("numberPhases")+2+c];
  4998. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4999. c++;
  5000. }
  5001. sstr[c] = '\0';
  5002. tempNumberPhasesInt = atoi(sstr);
  5003. if(j == 0)
  5004. {
  5005. TxDefaultProfile.Duration = tempdurationInt;
  5006. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5007. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5008. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5009. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5010. }
  5011. else
  5012. {
  5013. //other stack level charging Profile
  5014. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5015. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5016. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5017. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5018. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5019. }
  5020. }
  5021. if(MinChargingRate < tempminChargingRateFloat)
  5022. MinChargingRate = tempminChargingRateFloat;
  5023. if(confirmPeriods < n_SchedulePeriods)
  5024. confirmPeriods = n_SchedulePeriods;
  5025. j = j + 1;
  5026. }
  5027. fclose(fptr1);
  5028. //Stacking Charging Profiles
  5029. for(int l=0; l <(j-1) ;l++)
  5030. {
  5031. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5032. {
  5033. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5034. {
  5035. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5036. {
  5037. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5038. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5039. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5040. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5041. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5042. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5043. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5044. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5045. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5046. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5047. }
  5048. else
  5049. {
  5050. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5051. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5052. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5053. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5054. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5055. }
  5056. }
  5057. }
  5058. }
  5059. //end of Stacking Charging Profiles
  5060. }
  5061. }// the end of ACCESS TxDefaultProfile
  5062. //****************************TxProfile************************************************/
  5063. switch(connectorIdInt)
  5064. {
  5065. case 0:
  5066. break;
  5067. case 1:
  5068. strcpy(fname, TxProfile_1_JSON );
  5069. break;
  5070. case 2:
  5071. strcpy(fname, TxProfile_2_JSON );
  5072. break;
  5073. default:
  5074. strcpy(fname, TxProfile_1_JSON );
  5075. break;
  5076. }
  5077. TxProfileIsNull=TRUE;
  5078. if((access(fname,F_OK))!=-1)
  5079. {
  5080. fptr1 = fopen(fname, "r");
  5081. c = 0;
  5082. c = fgetc(fptr1);
  5083. //DEBUG_INFO("c:%d\n",c);
  5084. rewind(fptr1);
  5085. if(c == EOF)
  5086. {
  5087. DEBUG_INFO("\n End of file reached.");
  5088. TxProfileIsNull=TRUE;
  5089. fclose(fptr1);
  5090. }
  5091. else
  5092. {
  5093. TxProfileIsNull=FALSE;
  5094. while(fscanf(fptr1, "%s", word) != EOF)
  5095. {
  5096. if(strcmp(word, "chargingProfileId") == 0)
  5097. {
  5098. n_chargingProfile = n_chargingProfile + 1;
  5099. }
  5100. }
  5101. rewind(fptr1);
  5102. //search Charging Profile Element
  5103. int i= 0;
  5104. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5105. #if 0
  5106. /***********connectorId****************/
  5107. c = 0;
  5108. loc = strstr(sLineWord, "connectorId");
  5109. memset(sstr ,0, sizeof(sstr) );
  5110. while (loc[strlen("connectorId")+2+c] != ',')
  5111. {
  5112. sstr[c] = loc[strlen("connectorId")+2+c];
  5113. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5114. c++;
  5115. }
  5116. sstr[c] = '\0';
  5117. tempconnectorIdInt = atoi(sstr);
  5118. #endif
  5119. //***********validFrom**************/
  5120. c = 0;
  5121. loc = strstr(sLineWord, "validFrom");
  5122. if(loc != NULL)
  5123. {
  5124. memset(sstr ,0, sizeof(sstr) );
  5125. while (loc[3+strlen("validFrom")+c] != '\"')
  5126. {
  5127. sstr[c] = loc[3+strlen("validFrom")+c];
  5128. c++;
  5129. }
  5130. sstr[c] = '\0';
  5131. strcpy(tempvalidFromStr,sstr);
  5132. }
  5133. else
  5134. {
  5135. strcpy(tempvalidFromStr,"");
  5136. }
  5137. //**********startSchedule**********/
  5138. c = 0;
  5139. loc = strstr(sLineWord, "startSchedule");
  5140. memset(sstr ,0, sizeof(sstr) );
  5141. while (loc[3+strlen("startSchedule")+c] != '\"')
  5142. {
  5143. sstr[c] = loc[3+strlen("startSchedule")+c];
  5144. c++;
  5145. }
  5146. sstr[c] = '\0';
  5147. strcpy(tempstartScheduleStr, sstr);
  5148. //**********startSchedule**********/
  5149. c = 0;
  5150. loc = strstr(sLineWord, "chargingRateUnit");
  5151. memset(sstr ,0, sizeof(sstr) );
  5152. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5153. {
  5154. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5155. c++;
  5156. }
  5157. sstr[c] = '\0';
  5158. strcpy(tempchargingRateUnitStr, sstr);
  5159. //**********minChargingRate*******/
  5160. c = 0;
  5161. loc = strstr(sLineWord, "minChargingRate");
  5162. if(loc != NULL)
  5163. {
  5164. memset(sstr ,0, sizeof(sstr) );
  5165. while (loc[3+strlen("minChargingRate")+c] != '\"')
  5166. {
  5167. sstr[c] = loc[3+strlen("minChargingRate")+c];
  5168. c++;
  5169. }
  5170. sstr[c] = '\0';
  5171. tempminChargingRateFloat = atof(sstr);
  5172. }
  5173. else
  5174. {
  5175. tempminChargingRateFloat = 0.0;
  5176. }
  5177. //
  5178. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5179. tp.tm_isdst = -1;
  5180. time_t utc = mktime(&tp);
  5181. time_t t = time(NULL);
  5182. diff_t = difftime(t, utc);
  5183. DEBUG_INFO("diff_t=%f\n",diff_t);
  5184. //parsing strings to words
  5185. i = 0;
  5186. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5187. loc = loc+3+strlen("chargingSchedulePeriod");
  5188. pch = strtok(loc ,"{");
  5189. while (pch != NULL)
  5190. {
  5191. strcpy(SchedulePeriodList[i], pch);
  5192. pch = strtok (NULL, "{");
  5193. i = i + 1;
  5194. }
  5195. n_SchedulePeriods = i;
  5196. for(int i=0;i<n_SchedulePeriods;i++)
  5197. {
  5198. //*************startPeriod****************/
  5199. c = 0;
  5200. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5201. memset(sstr ,0, sizeof(sstr) );
  5202. while (loc[strlen("startPeriod")+2+c] != ',')
  5203. {
  5204. sstr[c] = loc[strlen("startPeriod")+2+c];
  5205. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5206. c++;
  5207. }
  5208. sstr[c] = '\0';
  5209. tempStartPeriodInt = atoi(sstr);
  5210. //*************limit****************/
  5211. c = 0;
  5212. loc = strstr(SchedulePeriodList[i], "limit");
  5213. memset(sstr ,0, sizeof(sstr) );
  5214. while (loc[strlen("limit")+2+c] != ',')
  5215. {
  5216. sstr[c] = loc[strlen("limit")+2+c];
  5217. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5218. c++;
  5219. }
  5220. sstr[c] = '\0';
  5221. tempLimitInt = atof(sstr);
  5222. //*************numberPhases****************/
  5223. c = 0;
  5224. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5225. memset(sstr ,0, sizeof(sstr) );
  5226. while (loc[strlen("numberPhases")+2+c] != '}')
  5227. {
  5228. sstr[c] = loc[strlen("numberPhases")+2+c];
  5229. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5230. c++;
  5231. }
  5232. sstr[c] = '\0';
  5233. tempNumberPhasesInt = atoi(sstr);
  5234. TxProfile.Duration = durationInt;
  5235. TxProfile.TotalPeriod = n_SchedulePeriods;
  5236. TxProfile.Period[i].Limit = tempLimitInt;
  5237. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5238. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5239. }
  5240. if(MinChargingRate < tempminChargingRateFloat)
  5241. MinChargingRate = tempminChargingRateFloat;
  5242. if(confirmPeriods < n_SchedulePeriods)
  5243. confirmPeriods = n_SchedulePeriods;
  5244. }
  5245. fclose(fptr1);
  5246. }
  5247. }// the end of ACCESS TxProfile
  5248. //CompositeSchedule
  5249. int period=0;
  5250. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5251. {
  5252. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5253. {
  5254. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5255. {
  5256. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5257. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5258. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5259. period = period + 1;
  5260. }
  5261. else
  5262. {
  5263. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5264. {
  5265. }
  5266. else
  5267. {
  5268. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5269. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5270. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5271. period = period + 1;
  5272. }
  5273. }
  5274. }
  5275. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5276. {
  5277. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5278. {
  5279. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5280. {
  5281. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5282. }
  5283. else
  5284. {
  5285. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5286. }
  5287. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5288. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5289. period = period + 1;
  5290. }
  5291. }
  5292. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5293. {
  5294. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5295. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5296. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5297. period = period + 1;
  5298. }
  5299. }
  5300. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5301. {
  5302. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5303. {
  5304. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5305. {
  5306. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5307. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5308. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5309. period = period + 1;
  5310. }
  5311. else
  5312. {
  5313. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5314. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5315. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5316. period = period + 1;
  5317. }
  5318. }
  5319. }
  5320. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5321. {
  5322. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5323. {
  5324. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5325. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5326. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5327. period = period + 1;
  5328. }
  5329. }
  5330. confirmPeriods = period;
  5331. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5332. //* Define temporary variables */
  5333. struct tm *gtime;
  5334. time_t now;
  5335. char buf[28];
  5336. //* Read the current system time */
  5337. time(&now);
  5338. //* Convert the system time to GMT (now UTC) */
  5339. gtime = gmtime(&now);
  5340. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5341. // make .conf
  5342. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  5343. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  5344. //DEBUG_INFO(" debug 11\n");
  5345. // if(chargingRateUnitStr[0] != 0)
  5346. // {
  5347. // strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  5348. // }
  5349. // else
  5350. {
  5351. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5352. }
  5353. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5354. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5355. }
  5356. else
  5357. {
  5358. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5359. }
  5360. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5361. return result;
  5362. }
  5363. int handleGetConfigurationRequest(char *uuid, char *payload)
  5364. {
  5365. mtrace();
  5366. int result = FAIL;
  5367. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5368. //struct json_object *jsonitem;
  5369. int MaxKeySupported = 0;
  5370. int n_keys = 0;
  5371. char requestKey[43][50]={0};
  5372. char search[]="[";
  5373. char sstr[500]={ 0 };
  5374. //int pos;
  5375. int l, c = 0;
  5376. int i = 0;
  5377. char *delim = "\",\"";
  5378. char * pch;
  5379. char *loc = strstr(payload, search);
  5380. //********************* Parsing String ***********************************/
  5381. if(loc == NULL) {
  5382. DEBUG_INFO("no key match in Configuration \n");
  5383. }
  5384. else {
  5385. //pos = loc - payload;
  5386. l = strlen(loc)-4;
  5387. while (c < l)
  5388. {
  5389. sstr[c] = loc[c+2];
  5390. c++;
  5391. }
  5392. sstr[c] = '\0';
  5393. //parsing strings to words
  5394. pch = strtok(sstr,delim);
  5395. if(pch == NULL)
  5396. {
  5397. strcpy(requestKey[0], sstr);
  5398. }
  5399. else
  5400. {
  5401. while (pch != NULL)
  5402. {
  5403. strcpy(requestKey[i], pch);
  5404. pch = strtok (NULL, delim);
  5405. i = i + 1;
  5406. }
  5407. n_keys = i;
  5408. }
  5409. }
  5410. UnknownKeynum = 0;
  5411. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5412. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5413. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5414. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5415. if(n_keys != 0)
  5416. {
  5417. for(int i=0;i<n_keys;i++)
  5418. {
  5419. getKeyValue(requestKey[i]);
  5420. //json_object_put(jsonitem);
  5421. }
  5422. }
  5423. else
  5424. {
  5425. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5426. getKeyValue("");
  5427. }
  5428. processUnkownKey();
  5429. sendGetConfigurationConfirmation(uuid);
  5430. return result;
  5431. }
  5432. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5433. {
  5434. mtrace();
  5435. int result = FAIL;
  5436. //void *ret; //
  5437. char fnamePlusPath[50]="";
  5438. char fname[16]="";
  5439. pthread_t t; // pthread 變數
  5440. time_t rawtime;
  5441. struct tm * timeinfo;
  5442. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5443. system("exec /root/logPackTools 'log' 6");
  5444. //char buffer [128];
  5445. time (&rawtime);
  5446. //printf("%ld\n", rawtime);
  5447. timeinfo = localtime (&rawtime);
  5448. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5449. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5450. if((access(fnamePlusPath,F_OK))!=-1)
  5451. {
  5452. DEBUG_INFO("fnamePlusPath exist.\n");
  5453. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5454. }
  5455. else
  5456. {
  5457. DEBUG_INFO("fnamePlusPath not exist!\n");
  5458. }
  5459. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5460. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5461. pthread_join(t, NULL/*&ret*/);
  5462. return result;
  5463. }
  5464. void* GetDiagnosticsProcess(void* data)
  5465. {
  5466. mtrace();
  5467. int retriesInt=0, retryIntervalInt=0;
  5468. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5469. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5470. 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};
  5471. int port=0;
  5472. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5473. char fname[16]="";
  5474. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5475. int c = 0;
  5476. char *loc;
  5477. int isSuccess = FALSE;
  5478. char ftpbuf[200]={0};
  5479. //char temp[100]={0};
  5480. char * pch;
  5481. // [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"}]
  5482. char *str = (char*) data; // ?��?輸入資�?
  5483. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5484. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5485. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5486. //****************location*******************/
  5487. c = 0;
  5488. memset(sstr ,0, sizeof(sstr) );
  5489. loc = strstr(str, "location");
  5490. while (loc[3+strlen("location")+c] != '\"')
  5491. {
  5492. sstr[c] = loc[3+strlen("location")+c];
  5493. c++;
  5494. }
  5495. sstr[c] = '\0';
  5496. strcpy(locationstr,sstr);
  5497. if(strcmp(locationstr,"")==0)
  5498. {
  5499. DEBUG_INFO("location is <Empty>!\n");
  5500. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5501. goto end;
  5502. }
  5503. //****************retries*******************/
  5504. c = 0;
  5505. loc = strstr(str, "retries");
  5506. if(loc == NULL)
  5507. {
  5508. retriesIsNULL = TRUE;
  5509. }
  5510. else
  5511. {
  5512. while (loc[strlen("retries")+2+c] != ',')
  5513. {
  5514. sstr[c] = loc[strlen("retries")+2+c];
  5515. c++;
  5516. }
  5517. sstr[c] = '\0';
  5518. retriesInt = atoi(sstr);
  5519. }
  5520. if(retriesIsNULL == TRUE)
  5521. {
  5522. retriesInt = 0;
  5523. }
  5524. //****************retryInterval*******************/
  5525. c = 0;
  5526. loc = strstr(str, "retryInterval");
  5527. if(loc == NULL)
  5528. {
  5529. retryIntervalIsNULL = TRUE;
  5530. }
  5531. else
  5532. {
  5533. while (loc[strlen("retryInterval")+2+c] != ',')
  5534. {
  5535. sstr[c] = loc[strlen("retryInterval")+2+c];
  5536. c++;
  5537. }
  5538. sstr[c] = '\0';
  5539. retryIntervalInt = atoi(sstr);
  5540. }
  5541. //****************startTime*******************/
  5542. c = 0;
  5543. memset(sstr ,0, sizeof(sstr) );
  5544. loc = strstr(str, "startTime");
  5545. if(loc == NULL)
  5546. {
  5547. startTimeIsNULL = TRUE;
  5548. }
  5549. else
  5550. {
  5551. while (loc[3+strlen("startTime")+c] != '\"')
  5552. {
  5553. sstr[c] = loc[3+strlen("startTime")+c];
  5554. c++;
  5555. }
  5556. sstr[c] = '\0';
  5557. strcpy(startTimestr,sstr);
  5558. }
  5559. //****************stopTime*******************/
  5560. c = 0;
  5561. memset(sstr ,0, sizeof(sstr) );
  5562. loc = strstr(str, "stopTime");
  5563. if(loc == NULL)
  5564. {
  5565. stopTimeIsNULL = TRUE;
  5566. }
  5567. else
  5568. {
  5569. while (loc[3+strlen("stopTime")+c] != '\"')
  5570. {
  5571. sstr[c] = loc[3+strlen("stopTime")+c];
  5572. c++;
  5573. }
  5574. sstr[c] = '\0';
  5575. strcpy(stopTimestr,sstr);
  5576. }
  5577. memset(protocol, 0, sizeof(protocol));
  5578. memset(user, 0, sizeof(user) );
  5579. memset(password, 0, sizeof(password));
  5580. memset(host, 0, sizeof(host));
  5581. memset(path, 0, sizeof(path));
  5582. memset(ftppath, 0, sizeof(ftppath));
  5583. memset(host1, 0, sizeof(host1));
  5584. memset(path1, 0, sizeof(path1));
  5585. /*location: ftp://user:password@host:port/path*/
  5586. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5587. // protocol, user, password, host, &port, path);
  5588. #if 0 // remove for temporally
  5589. //zip files in /Storage
  5590. system("exec /root/logPackTools 'log' 6");
  5591. #endif
  5592. // system("exec /root/Module_WebService 'log' 6");
  5593. time_t rawtime;
  5594. struct tm * timeinfo;
  5595. //char buffer [128];
  5596. time (&rawtime);
  5597. //printf("%ld\n", rawtime);
  5598. timeinfo = localtime (&rawtime);
  5599. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5600. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5601. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5602. if((access(fnamePlusPath,F_OK))!=-1)
  5603. {
  5604. DEBUG_INFO("fnamePlusPath exist.\n");
  5605. }
  5606. else
  5607. {
  5608. DEBUG_INFO("fnamePlusPath not exist!\n");
  5609. goto end;
  5610. }
  5611. pch=strchr(locationstr,'@');
  5612. if(pch==NULL)
  5613. {
  5614. sscanf(locationstr,
  5615. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5616. protocol, host, &port, path);
  5617. strcpy(user,"anonymous");
  5618. strcpy(password,"");
  5619. }
  5620. else
  5621. {
  5622. DEBUG_INFO("pch=%s\n", pch);
  5623. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5624. protocol, user, password, host, &port, path);
  5625. }
  5626. if(strcmp(protocol,"ftp")!=0)
  5627. {
  5628. DEBUG_INFO("protocol is not ftp!\n");
  5629. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5630. goto end;
  5631. }
  5632. sscanf(host,"%[^/]%s",host1, path1);
  5633. sprintf(ftppath,"%s", path1);
  5634. DEBUG_INFO("protocol =%s\n",protocol);
  5635. DEBUG_INFO("user =%s\n",user);
  5636. DEBUG_INFO("password =%s\n",password);
  5637. DEBUG_INFO("host1 =%s\n",host1);
  5638. DEBUG_INFO("port =%d\n",port);
  5639. DEBUG_INFO("path1 =%s\n",path1);
  5640. DEBUG_INFO("ftppath=%s\n",ftppath);
  5641. int ftppathlen=strlen(ftppath);
  5642. int i=1;
  5643. char filenametemp[50];
  5644. while(i < ftppathlen)
  5645. {
  5646. int len=ftppathlen-i;
  5647. if(ftppath[len]== 47) // '/' ascll code: 47
  5648. {
  5649. DEBUG_INFO("find '/' all right\n");
  5650. break;
  5651. }
  5652. i=i+1;
  5653. }
  5654. memset(filenametemp, 0, sizeof(filenametemp));
  5655. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5656. filenametemp[i+1] = 0;
  5657. //httpDownLoadFile(host, ftppath, fname);
  5658. memset(ftpbuf, 0, sizeof(ftpbuf));
  5659. if(port == 0)
  5660. port = 21;
  5661. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5662. do{
  5663. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5664. sleep(retryIntervalInt);
  5665. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5666. if(!isSuccess)
  5667. {
  5668. //BulldogUtil.sleepMs(interval*1000);
  5669. DEBUG_INFO("Diagnostics fail.\n");
  5670. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5671. }
  5672. else
  5673. {
  5674. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5675. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5676. //isUpdateRequest = TRUE;
  5677. }
  5678. end:
  5679. // json_object_put(obj);
  5680. DiagnosticsStatusNotificationStatus = 0; //Idle
  5681. pthread_exit(NULL/*(void *) fname*/); // ?��?子執行�?
  5682. }
  5683. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5684. {
  5685. mtrace();
  5686. int result = FAIL;
  5687. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5688. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5689. {
  5690. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5691. localversion = -1;
  5692. }
  5693. else
  5694. {
  5695. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5696. OCPP_getListVerion();
  5697. }
  5698. //from db.OCPP_getListVerion
  5699. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5700. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5701. sendGetLocalListVersionConfirmation(uuid,"");
  5702. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5703. return result;
  5704. }
  5705. int handleRemoteStartRequest(char *uuid, char *payload)
  5706. {
  5707. mtrace();
  5708. int result = FAIL;
  5709. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5710. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5711. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5712. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5713. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5714. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5715. int chargingSchedulePeriodCount = 0;
  5716. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5717. int c = 0;
  5718. char *loc;
  5719. char comfirmstr[20]={0};
  5720. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5721. if(server_pending == TRUE)
  5722. {
  5723. return 0;
  5724. }
  5725. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5726. //**********connectorId****************/
  5727. c = 0;
  5728. memset(sstr ,0, sizeof(sstr) );
  5729. loc = strstr(payload, "connectorId");
  5730. if(loc == NULL)
  5731. {
  5732. connectorIdIsNULL = TRUE;
  5733. }
  5734. else
  5735. {
  5736. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5737. {
  5738. sstr[c] = loc[strlen("connectorId")+2+c];
  5739. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5740. c++;
  5741. }
  5742. sstr[c] = '\0';
  5743. connectorIdInt = atoi(sstr);
  5744. }
  5745. if(connectorIdIsNULL == TRUE) // need to discussion
  5746. {
  5747. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5748. goto end;
  5749. }
  5750. //****************idTag*******************/
  5751. c = 0;
  5752. memset(sstr ,0, sizeof(sstr) );
  5753. loc = strstr(payload, "idTag");
  5754. while (loc[3+strlen("idTag")+c] != '\"')
  5755. {
  5756. sstr[c] = loc[3+strlen("idTag")+c];
  5757. c++;
  5758. }
  5759. sstr[c] = '\0';
  5760. strcpy(idTagstr,sstr);
  5761. //****************chargingProfile*******************/
  5762. c = 0;
  5763. memset(sstr ,0, sizeof(sstr) );
  5764. loc = strstr(payload, "chargingProfile");
  5765. if(loc == NULL)
  5766. {
  5767. chargingProfileIsNULL = TRUE;
  5768. }
  5769. else
  5770. {
  5771. //****************chargingProfileId*******************/
  5772. c=0;
  5773. loc = strstr(payload, "chargingProfileId");
  5774. memset(sstr ,0, sizeof(sstr) );
  5775. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5776. {
  5777. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5778. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5779. c++;
  5780. }
  5781. sstr[c] = '\0';
  5782. chargingProfileIdInt = atoi(sstr);
  5783. //****************transactionId*******************/
  5784. loc = strstr(payload, "transactionId");
  5785. if(loc == NULL)
  5786. {
  5787. transactionIdIsNULL = TRUE;
  5788. }
  5789. else
  5790. {
  5791. c=0;
  5792. memset(sstr ,0, sizeof(sstr) );
  5793. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5794. {
  5795. sstr[c] = loc[strlen("transactionId")+2+c];
  5796. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5797. c++;
  5798. }
  5799. sstr[c] = '\0';
  5800. transactionIdInt = atoi(sstr);
  5801. }
  5802. //****************stackLevel*******************/
  5803. c=0;
  5804. loc = strstr(payload, "stackLevel");
  5805. memset(sstr ,0, sizeof(sstr) );
  5806. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5807. {
  5808. sstr[c] = loc[strlen("stackLevel")+2+c];
  5809. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5810. c++;
  5811. }
  5812. sstr[c] = '\0';
  5813. stackLevelInt = atoi(sstr);
  5814. //****************chargingProfilePurpose*******************/
  5815. c = 0;
  5816. memset(sstr ,0, sizeof(sstr) );
  5817. loc = strstr(payload, "chargingProfilePurpose");
  5818. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5819. {
  5820. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5821. c++;
  5822. }
  5823. sstr[c] = '\0';
  5824. strcpy(chargingProfilePurposestr,sstr);
  5825. //****************chargingProfileKind*******************/
  5826. c = 0;
  5827. memset(sstr ,0, sizeof(sstr) );
  5828. loc = strstr(payload, "chargingProfileKind");
  5829. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5830. {
  5831. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5832. c++;
  5833. }
  5834. sstr[c] = '\0';
  5835. strcpy(chargingProfileKindstr,sstr);
  5836. //****************recurrencyKind*******************/
  5837. loc = strstr(payload, "recurrencyKind");
  5838. if(loc == NULL)
  5839. {
  5840. recurrencyKindIsNULL = TRUE;
  5841. }
  5842. else
  5843. {
  5844. c = 0;
  5845. memset(sstr ,0, sizeof(sstr) );
  5846. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5847. {
  5848. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5849. c++;
  5850. }
  5851. sstr[c] = '\0';
  5852. strcpy(recurrencyKindstr,sstr);
  5853. }
  5854. //****************validFrom*******************/
  5855. loc = strstr(payload, "validFrom");
  5856. if(loc == NULL)
  5857. {
  5858. validFromIsNULL = TRUE;
  5859. }
  5860. else
  5861. {
  5862. c = 0;
  5863. memset(sstr ,0, sizeof(sstr) );
  5864. while (loc[3+strlen("validFrom")+c] != '\"')
  5865. {
  5866. sstr[c] = loc[3+strlen("validFrom")+c];
  5867. c++;
  5868. }
  5869. sstr[c] = '\0';
  5870. strcpy(validFromstr,sstr);
  5871. }
  5872. //****************validTo*******************/
  5873. loc = strstr(payload, "validTo");
  5874. if(loc == NULL)
  5875. {
  5876. validToIsNULL = TRUE;
  5877. }
  5878. else
  5879. {
  5880. c = 0;
  5881. memset(sstr ,0, sizeof(sstr) );
  5882. while (loc[3+strlen("validTo")+c] != '\"')
  5883. {
  5884. sstr[c] = loc[3+strlen("validTo")+c];
  5885. c++;
  5886. }
  5887. sstr[c] = '\0';
  5888. strcpy(validTostr,sstr);
  5889. }
  5890. //****************chargingSchedule*******************/
  5891. loc = strstr(payload, "chargingSchedule");
  5892. if(loc != NULL)
  5893. {
  5894. //****************duration*******************/
  5895. loc = strstr(payload, "duration");
  5896. if(loc == NULL)
  5897. {
  5898. durationIsNULL = TRUE;
  5899. }
  5900. else
  5901. {
  5902. c=0;
  5903. memset(sstr ,0, sizeof(sstr) );
  5904. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5905. {
  5906. sstr[c] = loc[strlen("duration")+2+c];
  5907. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5908. c++;
  5909. }
  5910. sstr[c] = '\0';
  5911. durationInt = atoi(sstr);
  5912. }
  5913. //****************startSchedule******************/
  5914. loc = strstr(payload, "startSchedule");
  5915. if(loc == NULL)
  5916. {
  5917. startScheduleIsNULL = TRUE;
  5918. }
  5919. else
  5920. {
  5921. c = 0;
  5922. memset(sstr ,0, sizeof(sstr) );
  5923. while (loc[3+strlen("startSchedule")+c] != '\"')
  5924. {
  5925. sstr[c] = loc[3+strlen("startSchedule")+c];
  5926. c++;
  5927. }
  5928. sstr[c] = '\0';
  5929. strcpy(startSchedulestr,sstr);
  5930. }
  5931. //****************chargingRateUnit*******************/
  5932. c = 0;
  5933. memset(sstr ,0, sizeof(sstr) );
  5934. loc = strstr(payload, "chargingRateUnit");
  5935. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5936. {
  5937. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5938. c++;
  5939. }
  5940. sstr[c] = '\0';
  5941. strcpy(chargingRateUnitstr,sstr);
  5942. //****************minChargingRate*******************/
  5943. loc = strstr(payload, "minChargingRate");
  5944. if(loc == NULL)
  5945. {
  5946. minChargingRateIsNULL = TRUE;
  5947. }
  5948. else
  5949. {
  5950. c=0;
  5951. memset(sstr ,0, sizeof(sstr) );
  5952. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5953. {
  5954. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5955. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5956. c++;
  5957. }
  5958. sstr[c] = '\0';
  5959. minChargingRateflaot = atof(sstr);
  5960. }
  5961. //****************chargingSchedulePeriod count*******************/
  5962. int what_len = strlen("startPeriod");
  5963. char *where = payload;
  5964. while ((where = strstr(where, "startPeriod"))) {
  5965. where += what_len;
  5966. chargingSchedulePeriodCount++;
  5967. }
  5968. where = payload;
  5969. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5970. {
  5971. //****************startPeriod*******************/
  5972. c=0;
  5973. loc = strstr(where, "startPeriod");
  5974. memset(sstr ,0, sizeof(sstr) );
  5975. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5976. {
  5977. sstr[c] = loc[strlen("startPeriod")+2+c];
  5978. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5979. c++;
  5980. }
  5981. sstr[c] = '\0';
  5982. startPeriodInt[periodNums] = atoi(sstr);
  5983. //****************limit*******************/
  5984. c=0;
  5985. loc = strstr(where, "limit");
  5986. memset(sstr ,0, sizeof(sstr) );
  5987. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5988. {
  5989. sstr[c] = loc[strlen("limit")+2+c];
  5990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5991. c++;
  5992. }
  5993. sstr[c] = '\0';
  5994. limitflaot[periodNums] = atof(sstr);
  5995. //****************numberPhases*******************/
  5996. loc = strstr(where, "numberPhases");
  5997. if(loc == NULL)
  5998. {
  5999. numberPhasesIsNULL = TRUE;
  6000. }
  6001. else
  6002. {
  6003. c=0;
  6004. memset(sstr ,0, sizeof(sstr) );
  6005. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6006. {
  6007. sstr[c] = loc[strlen("numberPhases")+2+c];
  6008. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6009. c++;
  6010. }
  6011. sstr[c] = '\0';
  6012. numberPhasesInt[periodNums] = atoi(sstr);
  6013. }
  6014. where = loc;
  6015. }
  6016. }
  6017. }
  6018. /*
  6019. enum _SYSTEM_STATUS
  6020. {
  6021. S_BOOTING = 0,
  6022. S_IDLE, = 1
  6023. S_AUTHORIZING, =2
  6024. S_REASSIGN_CHECK, =3
  6025. S_REASSIGN, =4
  6026. S_PRECHARGE, =5
  6027. S_PREPARING_FOR_EV, =6
  6028. S_PREPARING_FOR_EVSE, =7
  6029. S_CHARGING, =8
  6030. S_TERMINATING, =9
  6031. S_COMPLETE, =10
  6032. S_ALARM, =11
  6033. S_FAULT =12
  6034. }
  6035. */
  6036. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6037. {
  6038. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6039. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6040. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6041. //check Transaction active
  6042. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6043. {
  6044. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6045. {
  6046. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6047. {
  6048. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6049. {
  6050. //Reserved
  6051. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6052. }
  6053. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6054. {
  6055. //Reserved
  6056. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6057. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6058. goto end;
  6059. }
  6060. else
  6061. {
  6062. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6063. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6064. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6065. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6066. {
  6067. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6068. goto end;
  6069. }
  6070. }//END FOR ELSE
  6071. }
  6072. }// END FOR CHAdeMO_QUANTITY
  6073. for (int index = 0; index < CCS_QUANTITY; index++)
  6074. {
  6075. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6076. {
  6077. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6078. {
  6079. //Reserved
  6080. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6081. }
  6082. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6083. {
  6084. //Reserved
  6085. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6086. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6087. goto end;
  6088. }
  6089. else
  6090. {
  6091. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6092. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6093. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6094. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6095. {
  6096. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6097. goto end;
  6098. }
  6099. }// END FOR ELSE
  6100. }
  6101. }// END FOR CCS_QUANTITY
  6102. for (int index = 0; index < GB_QUANTITY; index++)
  6103. {
  6104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6105. {
  6106. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6107. {
  6108. //Reserved
  6109. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6110. }
  6111. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6112. {
  6113. //Reserved
  6114. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6115. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6116. goto end;
  6117. }
  6118. else
  6119. {
  6120. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6121. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6122. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6123. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6124. {
  6125. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6126. goto end;
  6127. }
  6128. }// END FOR ELSE
  6129. }
  6130. } // END FOR GB_QUANTITY
  6131. }
  6132. else
  6133. {
  6134. for (int index = 0; index < AC_QUANTITY; index++)
  6135. {
  6136. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6137. {
  6138. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6139. {
  6140. //Reserved
  6141. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6142. }
  6143. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6144. {
  6145. //Reserved
  6146. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6147. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6148. goto end;
  6149. }
  6150. else
  6151. {
  6152. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6153. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6154. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6155. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6156. {
  6157. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6158. goto end;
  6159. }
  6160. }//END FOR ELSE
  6161. }
  6162. }// END FOR AC_QUANTITY
  6163. }
  6164. if(chargingProfileIsNULL == FALSE)
  6165. {
  6166. //ChargingProfile
  6167. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6168. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6169. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6170. if(recurrencyKindIsNULL == FALSE) //OPTION
  6171. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6172. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6173. if(transactionIdIsNULL == FALSE) // OPTION
  6174. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6175. if(validFromIsNULL == FALSE) // OPTION
  6176. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6177. if(validToIsNULL == FALSE) //OPTION
  6178. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6179. //ChargingSchedule
  6180. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6181. if(durationIsNULL == FALSE) //OPTION
  6182. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6183. if(minChargingRateIsNULL == FALSE) //OPTION
  6184. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6185. if(startScheduleIsNULL == FALSE) //OPTION
  6186. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6187. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6188. {
  6189. //ChargingSchedulePeriod
  6190. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6191. if(numberPhasesIsNULL == FALSE)
  6192. {
  6193. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6194. }
  6195. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6196. }
  6197. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6198. {
  6199. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6200. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6201. }
  6202. else
  6203. {
  6204. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6205. }
  6206. }
  6207. else
  6208. {
  6209. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6210. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6211. }
  6212. }
  6213. else
  6214. {
  6215. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6216. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6217. }
  6218. end:
  6219. if(connectorIdIsNULL == FALSE)
  6220. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6221. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6222. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6223. //OCPP send RemoteStartConfirmation by first.
  6224. sendRemoteStartConfirmation(uuid, comfirmstr);
  6225. return result;
  6226. }
  6227. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6228. {
  6229. mtrace();
  6230. int result = FAIL;
  6231. int match = FALSE;
  6232. int GunNO = 0;
  6233. int transactionIdInt=0;
  6234. int transactionIdIsNULL= FALSE;
  6235. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6236. int c = 0;
  6237. char *loc;
  6238. char comfirmstr[20];
  6239. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6240. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6241. if(server_pending == TRUE)
  6242. {
  6243. return 0;
  6244. }
  6245. c=0;
  6246. loc = strstr(payload, "transactionId");
  6247. if(loc == NULL)
  6248. {
  6249. transactionIdIsNULL= TRUE;
  6250. }
  6251. else
  6252. {
  6253. memset(sstr ,0, sizeof(sstr) );
  6254. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6255. {
  6256. sstr[c] = loc[strlen("transactionId")+2+c];
  6257. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6258. c++;
  6259. }
  6260. sstr[c] = '\0';
  6261. transactionIdInt = atoi(sstr);
  6262. }
  6263. if(transactionIdIsNULL == FALSE)
  6264. {
  6265. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6266. {
  6267. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6268. {
  6269. //check Transaction active
  6270. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6271. {
  6272. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6273. {
  6274. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6275. {
  6276. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6277. {
  6278. match = TRUE;
  6279. GunNO = gun_index;
  6280. }
  6281. }
  6282. }// END FOR CHAdeMO_QUANTITY
  6283. for (int index = 0; index < CCS_QUANTITY; index++)
  6284. {
  6285. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6286. {
  6287. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6288. {
  6289. match = TRUE;
  6290. GunNO = gun_index;
  6291. }
  6292. }
  6293. }// END FOR CCS_QUANTITY
  6294. for (int index = 0; index < GB_QUANTITY; index++)
  6295. {
  6296. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6297. {
  6298. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6299. {
  6300. match = TRUE;
  6301. GunNO = gun_index;
  6302. }
  6303. }
  6304. }// END FOR GB_QUANTITY
  6305. }
  6306. else
  6307. {
  6308. for (int index = 0; index < AC_QUANTITY; index++)
  6309. {
  6310. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6311. {
  6312. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6313. {
  6314. match = TRUE;
  6315. GunNO = gun_index;
  6316. }
  6317. }
  6318. }// END FOR CHAdeMO_QUANTITY
  6319. }// END FOR AC ELSE
  6320. }// CHECK IF ResponseTransactionId == transactionIdInt
  6321. }//END FOR
  6322. if( match == TRUE)
  6323. {
  6324. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6325. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6326. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6327. }
  6328. else
  6329. {
  6330. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6331. }
  6332. }
  6333. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6334. return result;
  6335. }
  6336. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6337. {
  6338. mtrace();
  6339. int result = FAIL;
  6340. int connectorIdInt=0, reservationIdInt=0;
  6341. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6342. char comfirmstr[20]={0};
  6343. char sstr[180]={ 0 };
  6344. int c = 0;
  6345. char *loc;
  6346. //char *ptr;
  6347. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6348. //***(1)connectorId ****/
  6349. c=0;
  6350. loc = strstr(payload, "connectorId");
  6351. memset(sstr ,0, sizeof(sstr) );
  6352. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6353. {
  6354. sstr[c] = loc[strlen("connectorId")+2+c];
  6355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6356. c++;
  6357. }
  6358. sstr[c] = '\0';
  6359. connectorIdInt = atoi(sstr);
  6360. //***(2)expiryDate ****/
  6361. loc = strstr(payload, "expiryDate");
  6362. memset(sstr ,0, sizeof(sstr) );
  6363. c = 0;
  6364. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6365. {
  6366. sstr[c] = loc[3+strlen("expiryDate")+c];
  6367. c++;
  6368. }
  6369. sstr[c] = '\0';
  6370. strcpy(expiryDatestr, sstr);
  6371. //***(3)idTag ****/
  6372. loc = strstr(payload, "idTag");
  6373. memset(sstr ,0, sizeof(sstr) );
  6374. c = 0;
  6375. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6376. {
  6377. sstr[c] = loc[3+strlen("idTag")+c];
  6378. c++;
  6379. }
  6380. sstr[c] = '\0';
  6381. strcpy(idTagstr, sstr);
  6382. //***(4)parentIdTag ****/
  6383. loc = strstr(payload, "parentIdTag");
  6384. memset(sstr ,0, sizeof(sstr) );
  6385. c = 0;
  6386. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6387. {
  6388. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6389. c++;
  6390. }
  6391. sstr[c] = '\0';
  6392. strcpy(parentIdTagstr, sstr);
  6393. //***(5)reservationId ****/
  6394. c=0;
  6395. loc = strstr(payload, "reservationId");
  6396. memset(sstr ,0, sizeof(sstr) );
  6397. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6398. {
  6399. sstr[c] = loc[strlen("reservationId")+2+c];
  6400. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6401. c++;
  6402. }
  6403. sstr[c] = '\0';
  6404. reservationIdInt = atoi(sstr);
  6405. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6406. /*
  6407. enum _SYSTEM_STATUS
  6408. {
  6409. S_BOOTING = 0,
  6410. S_IDLE, = 1
  6411. S_AUTHORIZING, =2
  6412. S_REASSIGN_CHECK, =3
  6413. S_REASSIGN, =4
  6414. S_PRECHARGE, =5
  6415. S_PREPARING_FOR_EV, =6
  6416. S_PREPARING_FOR_EVSE, =7
  6417. S_CHARGING, =8
  6418. S_TERMINATING, =9
  6419. S_COMPLETE, =10
  6420. S_ALARM, =11
  6421. S_FAULT =12
  6422. }
  6423. */
  6424. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6425. {
  6426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6427. goto end;
  6428. }
  6429. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6430. {
  6431. //check Transaction active
  6432. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6433. {
  6434. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6435. {
  6436. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6437. {
  6438. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6439. {
  6440. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6441. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6442. {
  6443. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6444. {
  6445. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6446. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6447. }
  6448. 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'))
  6449. {
  6450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6451. }
  6452. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6453. {
  6454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6455. }
  6456. else
  6457. {
  6458. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6459. }
  6460. }
  6461. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6462. {
  6463. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6464. }
  6465. }
  6466. else
  6467. {
  6468. //replace reservation
  6469. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6470. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6471. }
  6472. }
  6473. } // END FOR CHAdeMO_QUANTITY
  6474. for (int index = 0; index < CCS_QUANTITY; index++)
  6475. {
  6476. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6477. {
  6478. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6479. {
  6480. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6481. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6482. {
  6483. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6484. {
  6485. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6487. }
  6488. 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'))
  6489. {
  6490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6491. }
  6492. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6493. {
  6494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6495. }
  6496. else
  6497. {
  6498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6499. }
  6500. }
  6501. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6502. {
  6503. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6504. }
  6505. }
  6506. else
  6507. {
  6508. //replace reservation
  6509. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6510. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6511. }
  6512. }
  6513. } // END FOR CCS_QUANTITY
  6514. for (int index = 0; index < GB_QUANTITY; index++)
  6515. {
  6516. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6517. {
  6518. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6519. {
  6520. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6521. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6522. {
  6523. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6524. {
  6525. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6527. }
  6528. 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'))
  6529. {
  6530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6531. }
  6532. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6533. {
  6534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6535. }
  6536. else
  6537. {
  6538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6539. }
  6540. }
  6541. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6542. {
  6543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6544. }
  6545. }
  6546. else
  6547. {
  6548. //replace reservation
  6549. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6551. }
  6552. }
  6553. }// END FOR GB_QUANTITY
  6554. }
  6555. else
  6556. {
  6557. for (int index = 0; index < AC_QUANTITY; index++)
  6558. {
  6559. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6560. {
  6561. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6562. {
  6563. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6564. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6565. {
  6566. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6567. {
  6568. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6569. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6570. }
  6571. 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'))
  6572. {
  6573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6574. }
  6575. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6576. {
  6577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6578. }
  6579. else
  6580. {
  6581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6582. }
  6583. }
  6584. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6585. {
  6586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6587. }
  6588. }
  6589. else
  6590. {
  6591. //replace reservation
  6592. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6594. }
  6595. }
  6596. } // END FOR AC_QUANTITY
  6597. }//END FOR AC ELSE
  6598. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6599. }
  6600. else if(connectorIdInt == 0)
  6601. {
  6602. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6603. {
  6604. //check Transaction active
  6605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6606. {
  6607. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6608. {
  6609. 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'))
  6610. {
  6611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6612. goto end;
  6613. }
  6614. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6615. {
  6616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6617. goto end;
  6618. }
  6619. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6620. {
  6621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6622. goto end;
  6623. }
  6624. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6625. {
  6626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6627. goto end;
  6628. }
  6629. }
  6630. }// END FOR CHAdeMO_QUANTITY
  6631. for (int index = 0; index < CCS_QUANTITY; index++)
  6632. {
  6633. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6634. {
  6635. 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'))
  6636. {
  6637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6638. }
  6639. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6640. {
  6641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6642. }
  6643. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6644. {
  6645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6646. }
  6647. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6648. {
  6649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6650. }
  6651. }
  6652. } // END FOR CCS_QUANTITY
  6653. for (int index = 0; index < GB_QUANTITY; index++)
  6654. {
  6655. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6656. {
  6657. 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'))
  6658. {
  6659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6660. }
  6661. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6662. {
  6663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6664. }
  6665. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6666. {
  6667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6668. }
  6669. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6670. {
  6671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6672. }
  6673. }
  6674. } // END FOR GB_QUANTITY
  6675. }
  6676. else
  6677. {
  6678. for (int index = 0; index < AC_QUANTITY; index++)
  6679. {
  6680. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6681. {
  6682. 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'))
  6683. {
  6684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6685. goto end;
  6686. }
  6687. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6688. {
  6689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6690. goto end;
  6691. }
  6692. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6693. {
  6694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6695. goto end;
  6696. }
  6697. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6698. {
  6699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6700. goto end;
  6701. }
  6702. }
  6703. }// END FOR AC_QUANTITY
  6704. }
  6705. //The connectorId is 0
  6706. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6708. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6709. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6710. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6711. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6712. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6713. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6714. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6715. result = TRUE;
  6716. return result;
  6717. }
  6718. else
  6719. {
  6720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6721. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6722. }
  6723. if(strcmp(comfirmstr,"Accepted") == 0)
  6724. {
  6725. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6726. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6727. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6728. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6729. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6730. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6731. result = TRUE;
  6732. return result;
  6733. }
  6734. end:
  6735. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6736. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6737. return result;
  6738. }
  6739. int handleResetRequest(char *uuid, char *payload)
  6740. {
  6741. mtrace();
  6742. int result = FAIL;
  6743. char sstr[10]={0};
  6744. char typestr[10]={0};
  6745. char comfirmstr[20]={0};
  6746. int c = 0;
  6747. char *loc;
  6748. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6749. DEBUG_INFO("handleResetRequest ...\n");
  6750. loc = strstr(payload, "type");
  6751. memset(sstr ,0, sizeof(sstr) );
  6752. c = 0;
  6753. while (loc[3+strlen("type")+c] != '\"')
  6754. {
  6755. sstr[c] = loc[3+strlen("type")+c];
  6756. c++;
  6757. }
  6758. sstr[c] = '\0';
  6759. strcpy(typestr,sstr);
  6760. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6761. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6762. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6763. {
  6764. //check Transaction active
  6765. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6766. {
  6767. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6768. {
  6769. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6770. {
  6771. //0: unplug, 1: Plug-in
  6772. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6773. }
  6774. }
  6775. for (int index = 0; index < CCS_QUANTITY; index++)
  6776. {
  6777. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6778. {
  6779. //0: unplug, 1: Plug-in
  6780. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6781. }
  6782. }
  6783. for (int index = 0; index < GB_QUANTITY; index++)
  6784. {
  6785. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6786. {
  6787. //0: unplug, 1: Plug-in
  6788. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6789. }
  6790. }
  6791. }
  6792. else
  6793. {
  6794. for (int index = 0; index < AC_QUANTITY; index++)
  6795. {
  6796. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6797. {
  6798. //0: unplug, 1: Plug-in
  6799. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6800. }
  6801. }
  6802. }// END FOR AC ELSE
  6803. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6804. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6805. result = TRUE;
  6806. return result;
  6807. }
  6808. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6809. {
  6810. //check Transaction active
  6811. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6812. {
  6813. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6814. {
  6815. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6816. {
  6817. //0: unplug, 1: Plug-in
  6818. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6819. }
  6820. }
  6821. for (int index = 0; index < CCS_QUANTITY; index++)
  6822. {
  6823. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6824. {
  6825. //0: unplug, 1: Plug-in
  6826. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6827. }
  6828. }
  6829. for (int index = 0; index < GB_QUANTITY; index++)
  6830. {
  6831. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6832. {
  6833. //0: unplug, 1: Plug-in
  6834. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6835. }
  6836. }
  6837. }
  6838. else
  6839. {
  6840. for (int index = 0; index < AC_QUANTITY; index++)
  6841. {
  6842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6843. {
  6844. //0: unplug, 1: Plug-in
  6845. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6846. }
  6847. }
  6848. }// END FOR AC ELSE
  6849. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6850. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6851. result = TRUE;
  6852. return result;
  6853. }
  6854. else
  6855. {
  6856. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6857. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6858. goto errorend;
  6859. }
  6860. errorend:
  6861. sendResetConfirmation(uuid, comfirmstr);
  6862. return result;
  6863. }
  6864. int handleSendLocalListRequest(char *uuid, char *payload)
  6865. {
  6866. mtrace();
  6867. int result = FAIL;
  6868. int listVersionInt;
  6869. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6870. char listsearch[]="listVersion";
  6871. char updateTypesearch[]="updateType";
  6872. char localAuthorizationListsearch[]="localAuthorizationList";
  6873. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6874. char CardList[500][160]={0};
  6875. char updateTypestr[15]={0};
  6876. char idTagstr[20]={0};
  6877. char parentIdTag[20]={0};
  6878. char expiryDate[30]={0};
  6879. char idTagstatus[16]={0};
  6880. int c = 0;
  6881. int i = 0;
  6882. char *delim1 = "}";
  6883. char * pch;
  6884. char *loc;
  6885. //char *ptr;
  6886. char comfirmstr[20];
  6887. //int n_localAuthorizations = 0;
  6888. int checkState_Faulted = FALSE;
  6889. DEBUG_INFO("handleSendLocalListRequest\n");
  6890. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6891. {
  6892. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6893. goto end;
  6894. }
  6895. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6896. {
  6897. //check Charge Point state
  6898. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6899. {
  6900. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6901. {
  6902. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6903. }
  6904. }
  6905. for (int index = 0; index < CCS_QUANTITY; index++)
  6906. {
  6907. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6908. {
  6909. checkState_Faulted = TRUE; //OCPP Status
  6910. }
  6911. }
  6912. for (int index = 0; index < GB_QUANTITY; index++)
  6913. {
  6914. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6915. {
  6916. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6917. }
  6918. }
  6919. }
  6920. else
  6921. {
  6922. //check Charge Point state
  6923. for (int index = 0; index < AC_QUANTITY; index++)
  6924. {
  6925. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6926. {
  6927. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6928. }
  6929. }
  6930. }// END FOR AC ELSE
  6931. if(checkState_Faulted == TRUE)
  6932. {
  6933. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6934. goto end;
  6935. }
  6936. //listVersion
  6937. c = 0;
  6938. loc = strstr(payload, listsearch);
  6939. while (loc[strlen("listVersion")+2+c] != ',')
  6940. {
  6941. sstr[c] = loc[strlen("listVersion")+2+c];
  6942. c++;
  6943. }
  6944. sstr[c] = '\0';
  6945. listVersionInt = atoi(sstr);
  6946. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6947. //updateType
  6948. loc = strstr(payload, updateTypesearch);
  6949. c = 0;
  6950. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6951. {
  6952. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6953. c++;
  6954. }
  6955. sstr[c] = '\0';
  6956. strcpy(updateTypestr, sstr);
  6957. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6958. //localAuthorizationList
  6959. memset(sstr ,0, sizeof(sstr) );
  6960. loc = strstr(payload, localAuthorizationListsearch);
  6961. if(loc != NULL) // localAuthorizationList is not NULL
  6962. {
  6963. //Check UpdateType
  6964. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6965. {
  6966. //Local list full update
  6967. printf("Local list full update.\n");
  6968. OCPP_cleanLocalList();
  6969. }
  6970. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6971. {
  6972. //Local list different update
  6973. printf("Local list different update.\n");
  6974. OCPP_getListVerion();
  6975. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6976. {
  6977. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6978. goto end;
  6979. }
  6980. }
  6981. else
  6982. {
  6983. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6984. goto end;
  6985. }
  6986. c = 0;
  6987. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6988. {
  6989. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6991. c++;
  6992. }
  6993. sstr[c] = '\0';
  6994. //parsing strings to words
  6995. i = 0;
  6996. pch = strtok(sstr,delim1);
  6997. while (pch != NULL)
  6998. {
  6999. strcpy(CardList[i], pch);
  7000. pch = strtok (NULL, delim1);
  7001. i = i + 1;
  7002. }
  7003. //local Authorizations List Numbers
  7004. //n_localAuthorizations = i;
  7005. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7006. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7007. c= 0;
  7008. while(c < i)
  7009. {
  7010. //Search "IdToken"
  7011. memset(sstr ,0, sizeof(sstr) );
  7012. loc = strstr(CardList[c], "idTag");
  7013. int j = 0;
  7014. while (loc[3+strlen("idTag")+j] != '\"')
  7015. {
  7016. sstr[j] = loc[3+strlen("idTag")+j];
  7017. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7018. j++;
  7019. }
  7020. sstr[j] = '\0';
  7021. strcpy(idTagstr, sstr);
  7022. //Search "expiryDate"
  7023. memset(sstr ,0, sizeof(sstr) );
  7024. loc = strstr(CardList[c], "expiryDate");
  7025. j = 0;
  7026. while (loc[3+strlen("expiryDate")+j] != '\"')
  7027. {
  7028. sstr[j] = loc[3+strlen("expiryDate")+j];
  7029. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7030. j++;
  7031. }
  7032. sstr[j] = '\0';
  7033. strcpy(expiryDate, sstr);
  7034. //Search "parentIdTag"
  7035. memset(sstr ,0, sizeof(sstr) );
  7036. loc = strstr(CardList[c], "parentIdTag");
  7037. j = 0;
  7038. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7039. {
  7040. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7041. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7042. j++;
  7043. }
  7044. sstr[j] = '\0';
  7045. strcpy(parentIdTag, sstr);
  7046. //Search "status"
  7047. memset(sstr ,0, sizeof(sstr) );
  7048. loc = strstr(CardList[c], "status");
  7049. j = 0;
  7050. while (loc[3+strlen("status")+j] != '\"')
  7051. {
  7052. sstr[j] = loc[3+strlen("status")+j];
  7053. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7054. j++;
  7055. }
  7056. sstr[j] = '\0';
  7057. strcpy(idTagstatus, sstr);
  7058. OCPP_getIdTag(idTagstr);
  7059. //OCPP_getIdTag("test"); For Test
  7060. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7061. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7062. {
  7063. //Local list full update
  7064. DEBUG_INFO("Local list full update.\n");
  7065. // update list
  7066. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7067. OCPP_get_TableAuthlocalAllData();
  7068. }
  7069. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7070. {
  7071. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7072. {
  7073. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7074. }
  7075. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7076. {
  7077. OCPP_deleteIdTag(idTagstr);
  7078. }
  7079. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7080. {
  7081. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7082. }
  7083. }
  7084. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7085. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7086. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7087. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7088. c++;
  7089. }
  7090. }
  7091. else
  7092. {
  7093. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7094. {
  7095. //Local list different update
  7096. DEBUG_INFO("Local list different update.\n");
  7097. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7098. goto end;
  7099. }
  7100. }
  7101. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7102. end:
  7103. sendSendLocalListConfirmation(uuid, comfirmstr);
  7104. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7105. #if 0
  7106. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7107. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7108. #endif
  7109. return result;
  7110. }
  7111. /*
  7112. enum _SYSTEM_STATUS
  7113. {
  7114. S_BOOTING = 0,
  7115. S_IDLE, =1
  7116. S_AUTHORIZING, =2
  7117. S_REASSIGN_CHECK, =3
  7118. S_REASSIGN, =4
  7119. S_PRECHARGE, =5
  7120. S_PREPARING_FOR_EV, =6
  7121. S_PREPARING_FOR_EVSE, =7
  7122. S_CHARGING, =8
  7123. S_TERMINATING, =9
  7124. S_COMPLETE, =10
  7125. S_ALARM, =11
  7126. S_FAULT =12
  7127. };
  7128. */
  7129. #define MAX 200
  7130. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7131. {
  7132. mtrace();
  7133. int result = FAIL;
  7134. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7135. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7136. char chargingProfilePurposeStr[30]={0};
  7137. char chargingProfileKindStr[16]={0};
  7138. char recurrencyKindStr[10]={0};
  7139. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7140. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7141. int chargingSchedulePeriodCount = 0;
  7142. //int updateflag = FALSE;
  7143. char comfirmstr[20]={0};
  7144. int meet= FALSE;
  7145. char sstr[10]={0};
  7146. int c = 0;
  7147. char *loc;
  7148. FILE *fptr1;//, *fptr2;
  7149. //int lno=0;//, linectr = 0;
  7150. //int modifyflag = FALSE;
  7151. char filename[MAX]={0};
  7152. char tempfile[] = "../Storage/OCPP/temp.json";
  7153. int resultRename=0;
  7154. char rmFileCmd[50]={0};
  7155. char tempchargingProfilePurposeStr[30]={0};
  7156. //[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}}}]
  7157. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7158. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7159. //*********************connectorId***************************/
  7160. loc = strstr(payload, "connectorId");
  7161. c = 0;
  7162. memset(sstr ,0, sizeof(sstr) );
  7163. while (loc[strlen("connectorId")+2+c] != ',')
  7164. {
  7165. sstr[c] = loc[strlen("connectorId")+2+c];
  7166. c++;
  7167. }
  7168. sstr[c] = '\0';
  7169. connectorIdInt = atoi(sstr);
  7170. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7171. {
  7172. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7173. }
  7174. else
  7175. {
  7176. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7177. }
  7178. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7179. //*********************chargingProfileId***************************/
  7180. loc = strstr(payload, "chargingProfileId");
  7181. c = 0;
  7182. memset(sstr ,0, sizeof(sstr) );
  7183. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7184. {
  7185. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7186. c++;
  7187. }
  7188. sstr[c] = '\0';
  7189. chargingProfileIdInt = atoi(sstr);
  7190. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7191. {
  7192. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7193. }
  7194. else
  7195. {
  7196. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7197. }
  7198. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7199. //*********************transactionId***************************/
  7200. loc = strstr(payload, "transactionId");
  7201. if(loc != NULL)
  7202. {
  7203. c = 0;
  7204. memset(sstr ,0, sizeof(sstr) );
  7205. while (loc[strlen("transactionId")+2+c] != ',')
  7206. {
  7207. sstr[c] = loc[strlen("transactionId")+2+c];
  7208. c++;
  7209. }
  7210. sstr[c] = '\0';
  7211. transactionIdInt = atoi(sstr);
  7212. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7213. {
  7214. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7215. }
  7216. else
  7217. {
  7218. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7219. }
  7220. }
  7221. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7222. //*********************stackLevel***************************/
  7223. loc = strstr(payload, "stackLevel");
  7224. c = 0;
  7225. memset(sstr ,0, sizeof(sstr) );
  7226. while (loc[strlen("stackLevel")+2+c] != ',')
  7227. {
  7228. sstr[c] = loc[strlen("stackLevel")+2+c];
  7229. c++;
  7230. }
  7231. sstr[c] = '\0';
  7232. stackLevelInt = atoi(sstr);
  7233. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7234. {
  7235. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7236. }
  7237. else
  7238. {
  7239. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7240. }
  7241. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7242. //*********************chargingProfilePurpose***************************/
  7243. loc = strstr(payload, "chargingProfilePurpose");
  7244. c = 0;
  7245. memset(sstr ,0, sizeof(sstr) );
  7246. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7247. {
  7248. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7249. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7250. c++;
  7251. }
  7252. sstr[c] = '\0';
  7253. strcpy(chargingProfilePurposeStr,sstr);
  7254. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7255. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7256. {
  7257. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7258. }
  7259. else
  7260. {
  7261. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7262. }
  7263. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7264. //*********************chargingProfileKind***************************/
  7265. loc = strstr(payload, "chargingProfileKind");
  7266. c = 0;
  7267. memset(sstr ,0, sizeof(sstr) );
  7268. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7269. {
  7270. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7271. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7272. c++;
  7273. }
  7274. sstr[c] = '\0';
  7275. strcpy(chargingProfileKindStr,sstr);
  7276. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7277. {
  7278. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7279. }
  7280. else
  7281. {
  7282. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7283. }
  7284. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7285. //*********************recurrencyKind***************************/
  7286. loc = strstr(payload, "recurrencyKind");
  7287. if(loc != NULL)
  7288. {
  7289. c = 0;
  7290. memset(sstr ,0, sizeof(sstr) );
  7291. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7292. {
  7293. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7295. c++;
  7296. }
  7297. sstr[c] = '\0';
  7298. strcpy(recurrencyKindStr,sstr);
  7299. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7300. {
  7301. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7302. }
  7303. else
  7304. {
  7305. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7306. }
  7307. }
  7308. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7309. //*********************validFrom***************************/
  7310. loc = strstr(payload, "validFrom");
  7311. if(loc != NULL)
  7312. {
  7313. c = 0;
  7314. memset(sstr ,0, sizeof(sstr) );
  7315. while (loc[3+strlen("validFrom")+c] != '\"')
  7316. {
  7317. sstr[c] = loc[3+strlen("validFrom")+c];
  7318. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7319. c++;
  7320. }
  7321. sstr[c] = '\0';
  7322. strcpy(validFromStr,sstr);
  7323. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7324. {
  7325. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7326. }
  7327. else
  7328. {
  7329. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7330. }
  7331. }
  7332. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7333. //*********************validTo***************************/
  7334. loc = strstr(payload, "validTo");
  7335. if(loc != NULL)
  7336. {
  7337. c = 0;
  7338. memset(sstr ,0, sizeof(sstr) );
  7339. while (loc[3+strlen("validTo")+c] != '\"')
  7340. {
  7341. sstr[c] = loc[3+strlen("validTo")+c];
  7342. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7343. c++;
  7344. }
  7345. sstr[c] = '\0';
  7346. strcpy(validToStr,sstr);
  7347. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7348. {
  7349. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7350. }
  7351. else
  7352. {
  7353. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7354. }
  7355. }
  7356. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7357. //*********************duration***************************/
  7358. loc = strstr(payload, "duration");
  7359. if(loc != NULL)
  7360. {
  7361. c = 0;
  7362. memset(sstr ,0, sizeof(sstr) );
  7363. while (loc[strlen("duration")+2+c] != ',')
  7364. {
  7365. sstr[c] = loc[strlen("duration")+2+c];
  7366. c++;
  7367. }
  7368. sstr[c] = '\0';
  7369. durationInt = atoi(sstr);
  7370. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7371. {
  7372. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7373. }
  7374. else
  7375. {
  7376. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7377. }
  7378. }
  7379. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7380. //*********************startSchedule***************************/
  7381. loc = strstr(payload, "startSchedule");
  7382. if(loc != NULL)
  7383. {
  7384. c = 0;
  7385. memset(sstr ,0, sizeof(sstr) );
  7386. while (loc[3+strlen("startSchedule")+c] != '\"')
  7387. {
  7388. sstr[c] = loc[3+strlen("startSchedule")+c];
  7389. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7390. c++;
  7391. }
  7392. sstr[c] = '\0';
  7393. strcpy(startScheduleStr,sstr);
  7394. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7395. {
  7396. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7397. }
  7398. else
  7399. {
  7400. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7401. }
  7402. }
  7403. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7404. //*********************chargingRateUnit***************************/
  7405. loc = strstr(payload, "chargingRateUnit");
  7406. if(loc != NULL)
  7407. {
  7408. c = 0;
  7409. memset(sstr ,0, sizeof(sstr) );
  7410. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7411. {
  7412. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7413. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7414. c++;
  7415. }
  7416. sstr[c] = '\0';
  7417. strcpy(chargingRateUnitStr,sstr);
  7418. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7419. {
  7420. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7421. }
  7422. else
  7423. {
  7424. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7425. }
  7426. }
  7427. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7428. //****************chargingSchedulePeriod count start*******************/
  7429. int what_len = strlen("startPeriod");
  7430. char *where = payload;
  7431. if (what_len)
  7432. while ((where = strstr(where, "startPeriod"))) {
  7433. where += what_len;
  7434. chargingSchedulePeriodCount++;
  7435. }
  7436. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7437. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7438. where = payload;
  7439. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7440. {
  7441. //****************startPeriod*******************/
  7442. c=0;
  7443. loc = strstr(where, "startPeriod");
  7444. memset(sstr ,0, sizeof(sstr) );
  7445. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7446. {
  7447. sstr[c] = loc[strlen("startPeriod")+2+c];
  7448. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7449. c++;
  7450. }
  7451. sstr[c] = '\0';
  7452. startPeriodInt[periodNums] = atoi(sstr);
  7453. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7454. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7455. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7456. {
  7457. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7458. }
  7459. else
  7460. {
  7461. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7462. }
  7463. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7464. //****************limit*******************/
  7465. c=0;
  7466. loc = strstr(where, "limit");
  7467. memset(sstr ,0, sizeof(sstr) );
  7468. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7469. {
  7470. sstr[c] = loc[strlen("limit")+2+c];
  7471. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7472. c++;
  7473. }
  7474. sstr[c] = '\0';
  7475. limitflaot[periodNums] = atof(sstr);
  7476. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7477. {
  7478. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7479. }
  7480. else
  7481. {
  7482. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7483. }
  7484. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7485. //****************numberPhases*******************/
  7486. loc = strstr(where, "numberPhases");
  7487. if(loc != NULL)
  7488. {
  7489. c=0;
  7490. memset(sstr ,0, sizeof(sstr) );
  7491. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7492. {
  7493. sstr[c] = loc[strlen("numberPhases")+2+c];
  7494. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7495. c++;
  7496. }
  7497. sstr[c] = '\0';
  7498. numberPhasesInt[periodNums] = atoi(sstr);
  7499. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7500. {
  7501. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7502. }
  7503. else
  7504. {
  7505. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7506. }
  7507. }
  7508. where = loc;
  7509. }
  7510. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7511. //****************chargingSchedulePeriod count end*******************/
  7512. //*********************minChargingRate***************************/
  7513. loc = strstr(payload, "minChargingRate");
  7514. if(loc != NULL)
  7515. {
  7516. c = 0;
  7517. memset(sstr ,0, sizeof(sstr) );
  7518. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7519. {
  7520. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7521. c++;
  7522. }
  7523. sstr[c] = '\0';
  7524. minChargingRateFloat = atof(sstr);
  7525. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7526. {
  7527. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7528. }
  7529. else
  7530. {
  7531. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7532. }
  7533. }
  7534. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7535. DEBUG_INFO("-------------------------------------------------------------\n");
  7536. DEBUG_INFO(" Input the file name to be opened : ");
  7537. //fgets(fname, MAX, stdin);
  7538. //fname[strlen(fname) - 1] = '\0';
  7539. #if 0
  7540. switch(connectorIdInt)
  7541. {
  7542. case 0:
  7543. strcpy(filename, ChargingProfile_0_JSON );
  7544. break;
  7545. case 1:
  7546. strcpy(filename, ChargingProfile_1_JSON );
  7547. break;
  7548. case 2:
  7549. strcpy(filename, ChargingProfile_2_JSON );
  7550. break;
  7551. default:
  7552. strcpy(filename, ChargingProfile_0_JSON );
  7553. break;
  7554. }
  7555. fptr1 = fopen(filename, "r");
  7556. if (!fptr1)
  7557. {
  7558. //file not exist
  7559. DEBUG_INFO("Unable to open the input file!!\n");
  7560. fptr1 = fopen(filename, "w+");
  7561. }
  7562. fclose(fptr1);
  7563. #endif
  7564. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7565. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7566. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7567. {
  7568. //printf("set chargingProfile 1-2\n");
  7569. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7570. if(connectorIdInt != 0)
  7571. {
  7572. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7573. goto end;
  7574. }
  7575. strcpy(filename, ChargePointMaxProfile_JSON );
  7576. fptr1 = fopen(filename, "r");
  7577. if (!fptr1)
  7578. {
  7579. //file not exist
  7580. DEBUG_INFO("Unable to open the input file!!\n");
  7581. fptr1 = fopen(filename, "w+");
  7582. }
  7583. fclose(fptr1);
  7584. }
  7585. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7586. {
  7587. //printf("set chargingProfile 1-3\n");
  7588. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7589. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7590. {
  7591. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7592. goto end;
  7593. }
  7594. switch(connectorIdInt)
  7595. {
  7596. case 0:
  7597. strcpy(filename, TxDefaultProfile_0_JSON );
  7598. break;
  7599. case 1:
  7600. strcpy(filename, TxDefaultProfile_1_JSON );
  7601. break;
  7602. case 2:
  7603. strcpy(filename, TxDefaultProfile_2_JSON );
  7604. break;
  7605. default:
  7606. strcpy(filename, TxDefaultProfile_0_JSON );
  7607. break;
  7608. }
  7609. fptr1 = fopen(filename, "r");
  7610. if (!fptr1)
  7611. {
  7612. //file not exist
  7613. DEBUG_INFO("Unable to open the input file!!\n");
  7614. fptr1 = fopen(filename, "w+");
  7615. }
  7616. fclose(fptr1);
  7617. }
  7618. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7619. {
  7620. //printf("set chargingProfile 1-4\n");
  7621. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7622. //check Transaction active
  7623. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7624. {
  7625. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7626. {
  7627. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7628. {
  7629. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7630. {
  7631. meet = TRUE;
  7632. break;
  7633. }
  7634. }
  7635. }
  7636. }
  7637. for (int index = 0; index < CCS_QUANTITY; index++)
  7638. {
  7639. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7640. {
  7641. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7642. {
  7643. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7644. {
  7645. meet = TRUE;
  7646. break;
  7647. }
  7648. }
  7649. }
  7650. }
  7651. for (int index = 0; index < GB_QUANTITY; index++)
  7652. {
  7653. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7654. {
  7655. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7656. {
  7657. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7658. {
  7659. meet = TRUE;
  7660. break;
  7661. }
  7662. }
  7663. }
  7664. }
  7665. if(meet == FALSE)
  7666. {
  7667. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7668. goto end;
  7669. }
  7670. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7671. {
  7672. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7673. goto end;
  7674. }
  7675. switch(connectorIdInt)
  7676. {
  7677. case 0:
  7678. break;
  7679. case 1:
  7680. strcpy(filename, TxProfile_1_JSON);
  7681. break;
  7682. case 2:
  7683. strcpy(filename, TxProfile_2_JSON);
  7684. break;
  7685. default:
  7686. strcpy(filename, TxProfile_1_JSON);
  7687. break;
  7688. }
  7689. fptr1 = fopen(filename, "r");
  7690. if (!fptr1)
  7691. {
  7692. //file not exist
  7693. DEBUG_INFO("Unable to open the input file!!\n");
  7694. fptr1 = fopen(filename, "w+");
  7695. }
  7696. fclose(fptr1);
  7697. }
  7698. //**********************************Write to File********************************************************/
  7699. FILE *infile;
  7700. FILE *outfile;
  7701. // open file for writing
  7702. infile = fopen (filename, "r");
  7703. outfile = fopen (tempfile, "w");
  7704. int d =0;
  7705. d = fgetc(infile);
  7706. DEBUG_INFO("d:%d\n",d);
  7707. rewind(infile);
  7708. //*检测到文件结束标识返回1,否则返回0。*/
  7709. if(d == EOF)
  7710. {
  7711. DEBUG_INFO("ChargingProfile content is NULL\n");
  7712. fprintf(outfile,"[%s]\n",payload);
  7713. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7714. fclose(infile);
  7715. fclose(outfile);
  7716. sprintf(rmFileCmd,"rm -f %s",filename);
  7717. system(rmFileCmd);
  7718. resultRename = rename(tempfile, filename);
  7719. if(resultRename == 0)
  7720. {
  7721. DEBUG_INFO("File chargingProfile renamed successfully");
  7722. }
  7723. else
  7724. {
  7725. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7726. }
  7727. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7728. //system(rmFileCmd);
  7729. }
  7730. else
  7731. {
  7732. char buf[1000]={0};
  7733. while (fgets(buf, sizeof(buf), infile) != NULL)
  7734. {
  7735. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7736. //*************************tempconnectorIdInt*********************************/
  7737. loc = strstr(buf, "connectorId");
  7738. c = 0;
  7739. memset(sstr ,0, sizeof(sstr) );
  7740. while (loc[strlen("connectorId")+2+c] != ',')
  7741. {
  7742. sstr[c] = loc[strlen("connectorId")+2+c];
  7743. c++;
  7744. }
  7745. sstr[c] = '\0';
  7746. tempconnectorIdInt = atoi(sstr);
  7747. //*************************tempchargingProfileIdInt*********************************/
  7748. loc = strstr(buf, "chargingProfileId");
  7749. c = 0;
  7750. memset(sstr ,0, sizeof(sstr) );
  7751. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7752. {
  7753. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7754. c++;
  7755. }
  7756. sstr[c] = '\0';
  7757. tempchargingProfileIdInt = atoi(sstr);
  7758. //*************************tempstackLevelInt*********************************/
  7759. loc = strstr(buf, "stackLevel");
  7760. c = 0;
  7761. memset(sstr ,0, sizeof(sstr) );
  7762. while (loc[strlen("stackLevel")+2+c] != ',')
  7763. {
  7764. sstr[c] = loc[strlen("stackLevel")+2+c];
  7765. c++;
  7766. }
  7767. sstr[c] = '\0';
  7768. tempstackLevelInt = atoi(sstr);
  7769. //*************************tempchargingProfilePurposeStr*********************************/
  7770. loc = strstr(payload, "chargingProfilePurpose");
  7771. c = 0;
  7772. memset(sstr ,0, sizeof(sstr) );
  7773. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7774. {
  7775. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7777. c++;
  7778. }
  7779. sstr[c] = '\0';
  7780. strcpy(tempchargingProfilePurposeStr,sstr);
  7781. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7782. {
  7783. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7784. {
  7785. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7786. fprintf(outfile,"[%s]\n",payload);
  7787. }
  7788. else
  7789. {
  7790. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7791. if(tempstackLevelInt < stackLevelInt)
  7792. {
  7793. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7794. fprintf(outfile,"[%s]\n",payload);
  7795. fprintf(outfile,"[%s]\n",buf);
  7796. }
  7797. else
  7798. {
  7799. fprintf(outfile,"[%s]\n",buf);
  7800. fprintf(outfile,"[%s]\n",payload);
  7801. }
  7802. }
  7803. DEBUG_INFO("update set chargingProfile to file\n");
  7804. }
  7805. else
  7806. {
  7807. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7808. {
  7809. fprintf(outfile,"[%s]\n",payload);
  7810. fprintf(outfile,"[%s]\n",buf);
  7811. }
  7812. else if(tempstackLevelInt < stackLevelInt)
  7813. {
  7814. fprintf(outfile,"[%s]\n",payload);
  7815. fprintf(outfile,"[%s]\n",buf);
  7816. }
  7817. else
  7818. {
  7819. fprintf(outfile,"[%s]\n",buf);
  7820. fprintf(outfile,"[%s]\n",payload);
  7821. }
  7822. fprintf(outfile,"[%s]\n",buf);
  7823. DEBUG_INFO("add set chargingProfile to file\n");
  7824. }
  7825. } // end of while loop
  7826. fclose(infile);
  7827. fclose(outfile);
  7828. sprintf(rmFileCmd,"rm -f %s",filename);
  7829. system(rmFileCmd);
  7830. resultRename = rename(tempfile, filename);
  7831. if(resultRename == 0)
  7832. {
  7833. DEBUG_INFO("File chargingProfile renamed successfully");
  7834. }
  7835. else
  7836. {
  7837. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7838. }
  7839. result = TRUE;
  7840. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7841. }
  7842. end:
  7843. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7844. return result;
  7845. return result;
  7846. }
  7847. int handleTriggerMessageRequest(char *uuid, char *payload)
  7848. {
  7849. mtrace();
  7850. int result = FAIL;
  7851. int connectorIdIsNULL = FALSE;
  7852. int connectorIdInt =0;
  7853. char sstr[40]={0};
  7854. char requestedMessagestr[40]={0};
  7855. char comfirmstr[20]={0};
  7856. int c = 0;
  7857. char *loc;
  7858. DEBUG_INFO("handleTriggerMessageRequest\n");
  7859. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7860. c = 0;
  7861. loc = strstr(payload, "requestedMessage");
  7862. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7863. {
  7864. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7865. c++;
  7866. }
  7867. sstr[c] = '\0';
  7868. strcpy(requestedMessagestr, sstr);
  7869. c = 0;
  7870. loc = strstr(payload, "connectorId");
  7871. if(loc == NULL)
  7872. {
  7873. connectorIdIsNULL = TRUE;
  7874. }
  7875. else
  7876. {
  7877. memset(sstr ,0, sizeof(sstr) );
  7878. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7879. {
  7880. sstr[c] = loc[strlen("connectorId")+2+c];
  7881. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7882. c++;
  7883. }
  7884. sstr[c] = '\0';
  7885. connectorIdInt = atoi(sstr);
  7886. }
  7887. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7888. {
  7889. //connectorIdInt = json_object_get_int(connectorId);
  7890. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7891. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7892. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7893. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7894. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7895. }
  7896. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7897. {
  7898. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7899. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7900. return TRUE;
  7901. }
  7902. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7903. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7904. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7905. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7906. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7907. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7908. {
  7909. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7910. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7911. return TRUE;
  7912. }
  7913. else
  7914. {
  7915. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7916. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7917. }
  7918. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7919. {
  7920. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7921. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7922. }
  7923. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7924. {
  7925. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7926. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7927. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7928. }
  7929. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7930. {
  7931. sendBootNotificationRequest();
  7932. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7933. }
  7934. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7935. {
  7936. sendHeartbeatRequest(connectorIdInt);
  7937. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7938. }
  7939. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7940. {
  7941. if(connectorIdIsNULL == FALSE)
  7942. {
  7943. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7944. {
  7945. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7946. sendMeterValuesRequest(connectorIdInt -1);
  7947. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7948. }
  7949. }
  7950. else
  7951. {
  7952. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7953. {
  7954. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7955. sendMeterValuesRequest(idx);
  7956. }
  7957. }
  7958. }
  7959. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7960. {
  7961. if(connectorIdIsNULL == FALSE)
  7962. {
  7963. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7964. {
  7965. sendStatusNotificationRequest(connectorIdInt -1);
  7966. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7967. }
  7968. }
  7969. else
  7970. {
  7971. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7972. sendStatusNotificationRequest(idx);
  7973. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7974. }
  7975. }
  7976. return result;
  7977. }
  7978. int handleUnlockConnectorRequest(char *uuid, char *payload)
  7979. {
  7980. mtrace();
  7981. int result = FAIL;
  7982. char sstr[6]={0};
  7983. int connectorIdInt =0;
  7984. char comfirmstr[20]={0};
  7985. int c = 0;
  7986. char *loc;
  7987. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  7988. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  7989. c = 0;
  7990. loc = strstr(payload, "connectorId");
  7991. memset(sstr ,0, sizeof(sstr) );
  7992. while (loc[strlen("connectorId")+2+c] != '}')
  7993. {
  7994. sstr[c] = loc[strlen("connectorId")+2+c];
  7995. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7996. c++;
  7997. }
  7998. sstr[c] = '\0';
  7999. connectorIdInt = atoi(sstr);
  8000. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8001. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8002. {
  8003. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8004. goto end;
  8005. }
  8006. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8007. {
  8008. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8009. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8010. goto end;
  8011. }
  8012. else
  8013. {
  8014. //check Transaction active
  8015. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  8016. {
  8017. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8018. {
  8019. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8020. {
  8021. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8022. }
  8023. }
  8024. for (int index = 0; index < CCS_QUANTITY; index++)
  8025. {
  8026. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8027. {
  8028. //stop Transaction
  8029. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8030. }
  8031. }
  8032. for (int index = 0; index < GB_QUANTITY; index++)
  8033. {
  8034. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8035. {
  8036. //stop Transaction
  8037. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8038. }
  8039. }
  8040. }
  8041. else
  8042. {
  8043. for (int index = 0; index < AC_QUANTITY; index++)
  8044. {
  8045. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8046. {
  8047. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8048. }
  8049. }
  8050. }// END FOR AC ELSE
  8051. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8052. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8053. result = TRUE;
  8054. return result;
  8055. }
  8056. end:
  8057. //json_object_put(obj); --- remove temporally
  8058. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8059. return result;
  8060. }
  8061. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8062. {
  8063. mtrace();
  8064. int result = FAIL;
  8065. pthread_t t;
  8066. sendUpdateFirmwareConfirmation(uuid);
  8067. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8068. ////pthread_join(t, NULL); //
  8069. pthread_detach(t);
  8070. //sendUpdateFirmwareConfirmation(uuid);
  8071. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8072. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8073. return result;
  8074. }
  8075. void *UpdateFirmwareProcess(void *data)
  8076. {
  8077. mtrace();
  8078. int retriesInt =0, retryIntervalInt=0;
  8079. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8080. int port=0;
  8081. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8082. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8083. //char comfirmstr[20];
  8084. int isSuccess = 0;
  8085. char ftpbuf[200];
  8086. char temp[100];
  8087. char * pch;
  8088. int retriesISNULL=FALSE;
  8089. int retryInterval=FALSE;
  8090. int c = 0;
  8091. //int i = 0;
  8092. char *loc;
  8093. char sstr[300]={ 0 };
  8094. char *str = (char*) data; // ?��?輸入資�?
  8095. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8096. //***************location **************/
  8097. loc = strstr(str, "location");
  8098. memset(sstr ,0, sizeof(sstr) );
  8099. c = 0;
  8100. while (loc[3+strlen("location")+c] != '\"')
  8101. {
  8102. sstr[c] = loc[3+strlen("location")+c];
  8103. c++;
  8104. }
  8105. sstr[c] = '\0';
  8106. strcpy(locationstr, sstr);
  8107. //***************retries**************/
  8108. c = 0;
  8109. loc = strstr(str, "retries");
  8110. if(loc == NULL)
  8111. {
  8112. retriesISNULL=TRUE;
  8113. }
  8114. else
  8115. {
  8116. memset(sstr ,0, sizeof(sstr) );
  8117. while (loc[strlen("retries")+2+c] != ',')
  8118. {
  8119. sstr[c] = loc[strlen("retries")+2+c];
  8120. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8121. c++;
  8122. }
  8123. sstr[c] = '\0';
  8124. }
  8125. if(retriesISNULL == FALSE)
  8126. {
  8127. retriesInt = atoi(sstr);
  8128. }
  8129. //***************retrieveDate **************/
  8130. loc = strstr(str, "retrieveDate");
  8131. memset(sstr ,0, sizeof(sstr) );
  8132. c = 0;
  8133. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8134. {
  8135. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8136. c++;
  8137. }
  8138. sstr[c] = '\0';
  8139. strcpy(retrieveDatestr, sstr);
  8140. //***************retryInterval **************/
  8141. c = 0;
  8142. loc = strstr(str, "retryInterval");
  8143. memset(sstr ,0, sizeof(sstr) );
  8144. if(loc == NULL)
  8145. {
  8146. retryInterval=TRUE;
  8147. }
  8148. else
  8149. {
  8150. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8151. {
  8152. sstr[c] = loc[strlen("retryInterval")+2+c];
  8153. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8154. c++;
  8155. }
  8156. sstr[c] = '\0';
  8157. }
  8158. if(retryInterval==FALSE)
  8159. {
  8160. retryIntervalInt = atoi(sstr);
  8161. }
  8162. memset(ftppath, 0, sizeof(ftppath));
  8163. memset(path, 0, sizeof(path));
  8164. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8165. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8166. if(strncmp(locationstr,"http", 4) == 0)
  8167. {
  8168. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8169. protocol, host, path);
  8170. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8171. // protocol, user, password, host, path);
  8172. sprintf(ftppath,"/%s", path);
  8173. DEBUG_INFO("protocol =%s\n",protocol);
  8174. DEBUG_INFO("host =%s\n",host);
  8175. DEBUG_INFO("path =%s\n",path);
  8176. DEBUG_INFO("ftppath=%s\n",ftppath);
  8177. int ftppathlen=strlen(ftppath);
  8178. int i=1;
  8179. char filenametemp[50];
  8180. while(i < ftppathlen)
  8181. {
  8182. int len=ftppathlen-i;
  8183. if(ftppath[len]== 47) // '/' ascll code: 47
  8184. {
  8185. DEBUG_INFO("compare '/' all right\n");
  8186. break;
  8187. }
  8188. i=i+1;
  8189. }
  8190. memset(filenametemp, 0, sizeof(filenametemp));
  8191. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8192. filenametemp[i+1] = 0;
  8193. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8194. do{
  8195. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8196. sleep(retryIntervalInt);
  8197. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8198. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8199. if(!isSuccess)
  8200. {
  8201. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8202. }
  8203. else
  8204. {
  8205. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8206. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8207. isUpdateRequest = TRUE;
  8208. }
  8209. }
  8210. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8211. {
  8212. memset(ftpbuf, 0, sizeof(ftpbuf));
  8213. memset(temp, 0, sizeof(temp));
  8214. DEBUG_INFO("locationstr=%s\n",locationstr);
  8215. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8216. int ftppathlen=strlen(ftpbuf);
  8217. int i=1;
  8218. char filenametemp[50];
  8219. while(i < ftppathlen)
  8220. {
  8221. int len=ftppathlen-i;
  8222. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8223. {
  8224. DEBUG_INFO(" compare '/' all right\n");
  8225. break;
  8226. }
  8227. i=i+1;
  8228. }
  8229. memset(filenametemp, 0, sizeof(filenametemp));
  8230. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8231. filenametemp[i+1] = 0;
  8232. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8233. pch=strchr(temp,'@');
  8234. if(pch==NULL)
  8235. {
  8236. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8237. protocol, host, &port, path);
  8238. strcpy(user,"anonymous");
  8239. strcpy(password,"");
  8240. }
  8241. else
  8242. {
  8243. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8244. protocol, user, password, host, &port, path);
  8245. }
  8246. sscanf(host,"%[^/]%s",host1, path1);
  8247. sprintf(ftppath,"%s", path1);
  8248. DEBUG_INFO("protocol =%s\n",protocol);
  8249. DEBUG_INFO("user =%s\n",user);
  8250. DEBUG_INFO("password =%s\n",password);
  8251. DEBUG_INFO("host1 =%s\n",host1);
  8252. DEBUG_INFO("port =%d\n",port);
  8253. DEBUG_INFO("path1 =%s\n",path1);
  8254. DEBUG_INFO("ftppath=%s\n",ftppath);
  8255. //ftpFile(host, user, password, port, ftppath, fname);
  8256. //download firmware pthred
  8257. if(port == 0)
  8258. {
  8259. port = 21;
  8260. }
  8261. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8262. do{
  8263. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8264. sleep(retryIntervalInt);
  8265. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8266. if(!isSuccess)
  8267. {
  8268. //BulldogUtil.sleepMs(interval*1000);
  8269. DEBUG_INFO("Update firmware request and download file fail.\n");
  8270. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8271. }
  8272. else
  8273. {
  8274. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8275. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8276. isUpdateRequest = TRUE;
  8277. }
  8278. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8279. }
  8280. else
  8281. {
  8282. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8283. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8284. }
  8285. pthread_exit(NULL);
  8286. }
  8287. //==========================================
  8288. // Handle server response routine
  8289. //==========================================
  8290. void handleAuthorizeResponse(char *payload, int gun_index)
  8291. {
  8292. mtrace();
  8293. char expiryDatestr[30]={0};
  8294. char parentIdTagstr[20]={0};
  8295. char statusstr[20]={0};
  8296. char expiryDatestrtemp[30]={0};
  8297. char parentIdTagstrtemp[20]={0};
  8298. char IdTagstrtemp[20]={0};
  8299. char statusstrtemp[20]={0};
  8300. int expiryDateISNULL=FALSE;
  8301. int parentIdTagISNULL=FALSE;
  8302. char sstr[160]={ 0 };
  8303. char* filename = AuthorizationCache_JSON;
  8304. char tempfile[] = "../Storage/OCPP/temp.json";
  8305. int c = 0;
  8306. char *loc;
  8307. int resultRename=0;
  8308. int responseIdTagInfoAsZero= 0;
  8309. char rmFileCmd[50]={0};
  8310. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8311. //***********expiryDate*************/
  8312. loc = strstr(payload, "expiryDate");
  8313. memset(sstr ,0, sizeof(sstr) );
  8314. c = 0;
  8315. if(loc == NULL)
  8316. {
  8317. expiryDateISNULL = TRUE;
  8318. }
  8319. else
  8320. {
  8321. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8322. {
  8323. sstr[c] = loc[3+strlen("expiryDate")+c];
  8324. c++;
  8325. }
  8326. sstr[c] = '\0';
  8327. strcpy(expiryDatestr, sstr);
  8328. }
  8329. //***********parentIdTag*************/
  8330. loc = strstr(payload, "parentIdTag");
  8331. memset(sstr ,0, sizeof(sstr) );
  8332. c = 0;
  8333. if(loc == NULL)
  8334. {
  8335. parentIdTagISNULL = TRUE;
  8336. }
  8337. else
  8338. {
  8339. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8340. {
  8341. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8342. c++;
  8343. }
  8344. sstr[c] = '\0';
  8345. strcpy(parentIdTagstr, sstr);
  8346. }
  8347. //***********status*************/
  8348. loc = strstr(payload, "status");
  8349. memset(sstr ,0, sizeof(sstr) );
  8350. c = 0;
  8351. while (loc[3+strlen("status")+c] != '\"')
  8352. {
  8353. sstr[c] = loc[3+strlen("status")+c];
  8354. c++;
  8355. }
  8356. sstr[c] = '\0';
  8357. strcpy(statusstr, sstr);
  8358. //#ifdef SystemLogMessage
  8359. // if(expiryDateISNULL == FALSE)
  8360. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8361. // if(parentIdTagISNULL == FALSE)
  8362. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8363. // DEBUG_INFO("status: %s\n", statusstr);
  8364. //#endif
  8365. if(expiryDateISNULL == FALSE)
  8366. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8367. if(parentIdTagISNULL == FALSE)
  8368. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8369. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8370. //Update idTag information to authorization cache if supproted
  8371. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8372. {
  8373. if((access(filename,F_OK))!=-1)
  8374. {
  8375. DEBUG_INFO("AuthorizationCache exist.\n");
  8376. }
  8377. else
  8378. {
  8379. DEBUG_INFO("AuthorizationCache not exist\n");
  8380. FILE *log = fopen(filename, "w+");
  8381. if(log == NULL)
  8382. {
  8383. DEBUG_INFO("log is NULL\n");
  8384. goto out;
  8385. }
  8386. else
  8387. {
  8388. fclose(log);
  8389. }
  8390. }
  8391. FILE *infile;
  8392. FILE *outfile;
  8393. // open file for writing
  8394. infile = fopen (filename, "r");
  8395. outfile = fopen (tempfile, "w");
  8396. //*检测到文件结束标识返回1,否则返回0。*/
  8397. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8398. int c;
  8399. c = fgetc(infile);
  8400. //DEBUG_INFO("c:%d\n",c);
  8401. rewind(infile);
  8402. if(c == EOF)
  8403. {
  8404. DEBUG_INFO("Orignal File is NULL\n");
  8405. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8406. {
  8407. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8408. }
  8409. else
  8410. {
  8411. strcpy(expiryDatestrtemp, "");
  8412. }
  8413. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8414. {
  8415. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8416. }
  8417. else
  8418. {
  8419. //write Authorize IdTag
  8420. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8421. }
  8422. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8423. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8424. fclose(infile);
  8425. fclose(outfile);
  8426. sprintf(rmFileCmd,"rm -f %s",filename);
  8427. system(rmFileCmd);
  8428. resultRename = rename(tempfile, filename);
  8429. if(resultRename == 0)
  8430. {
  8431. DEBUG_INFO("File renamed successfully");
  8432. }
  8433. else
  8434. {
  8435. DEBUG_INFO("Error: unable to rename the file");
  8436. }
  8437. }
  8438. else
  8439. {
  8440. char buf[160]={0};
  8441. //DEBUG_INFO("Orignal File is not NULL\n");
  8442. while (fgets(buf, sizeof(buf), infile) != NULL)
  8443. {
  8444. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8445. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8446. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8447. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8448. memset(statusstr, 0, sizeof(statusstrtemp));
  8449. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8450. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8451. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8452. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8453. //------------------IdTag-----------------------
  8454. loc = strstr(buf, "idTag");
  8455. memset(sstr ,0, sizeof(sstr) );
  8456. c = 0;
  8457. while (loc[3+strlen("idTag")+c] != '\"')
  8458. {
  8459. sstr[c] = loc[3+strlen("idTag")+c];
  8460. c++;
  8461. }
  8462. sstr[c] = '\0';
  8463. strcpy(IdTagstrtemp,sstr);
  8464. //*********************expiryDate***************/
  8465. loc = strstr(buf, "expiryDate");
  8466. memset(sstr ,0, sizeof(sstr) );
  8467. c = 0;
  8468. while (loc[3+strlen("expiryDate")+c] != '\"')
  8469. {
  8470. sstr[c] = loc[3+strlen("expiryDate")+c];
  8471. c++;
  8472. }
  8473. sstr[c] = '\0';
  8474. strcpy(expiryDatestr,sstr);
  8475. //*********************parentIdTag***************/
  8476. loc = strstr(buf, "parentIdTag");
  8477. memset(sstr ,0, sizeof(sstr) );
  8478. c = 0;
  8479. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8480. {
  8481. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8482. c++;
  8483. }
  8484. sstr[c] = '\0';
  8485. strcpy(parentIdTagstr,sstr);
  8486. //*********************status***************/
  8487. loc = strstr(buf, "status");
  8488. memset(sstr ,0, sizeof(sstr) );
  8489. c = 0;
  8490. while (loc[3+strlen("status")+c] != '\"')
  8491. {
  8492. sstr[c] = loc[3+strlen("status")+c];
  8493. c++;
  8494. }
  8495. sstr[c] = '\0';
  8496. strcpy(statusstr,sstr);
  8497. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8498. {
  8499. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8500. responseIdTagInfoAsZero = 1;
  8501. }
  8502. else
  8503. {
  8504. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8505. }
  8506. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8507. {
  8508. //modify item
  8509. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8510. {
  8511. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8512. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8513. }
  8514. else
  8515. {
  8516. strcpy(expiryDatestrtemp, "");
  8517. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8518. }
  8519. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8520. {
  8521. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8522. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8523. }
  8524. else
  8525. {
  8526. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8527. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8528. }
  8529. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8530. }
  8531. else
  8532. {
  8533. //wrie original item
  8534. strcpy(expiryDatestrtemp, expiryDatestr);
  8535. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8536. strcpy(statusstrtemp, statusstr);
  8537. }
  8538. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8539. }
  8540. fclose(infile);
  8541. fclose(outfile);
  8542. sprintf(rmFileCmd,"rm -f %s",filename);
  8543. system(rmFileCmd);
  8544. resultRename = rename(tempfile, filename);
  8545. if(resultRename == 0)
  8546. {
  8547. DEBUG_INFO("File renamed successfully");
  8548. }
  8549. else
  8550. {
  8551. DEBUG_INFO("Error: unable to rename the file");
  8552. }
  8553. }
  8554. }
  8555. out:
  8556. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8557. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8558. authorizeRetryTimes = 0;
  8559. }
  8560. void handleBootNotificationResponse(char *payload, int gun_index)
  8561. {
  8562. mtrace();
  8563. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8564. char statusStr[12]={0};
  8565. char currentTimeStr[30]={0};
  8566. char *loc;
  8567. int intervalInt = 0;
  8568. int c = 0;
  8569. //double diff_t;
  8570. struct tm tp;
  8571. char buf[28]={0};
  8572. char timebuf[50]={0};
  8573. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8574. //*** interval ****/
  8575. c = 0;
  8576. loc = strstr(payload, "interval");
  8577. //printf("loc=%s\n",loc);
  8578. memset(sstr ,0, sizeof(sstr) );
  8579. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8580. {
  8581. sstr[c] = loc[strlen("interval")+2+c];
  8582. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8583. c++;
  8584. }
  8585. sstr[c] = '\0';
  8586. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8587. intervalInt = atoi(sstr);
  8588. //***status ****/
  8589. loc = strstr(payload, "status");
  8590. memset(sstr ,0, sizeof(sstr) );
  8591. c = 0;
  8592. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8593. {
  8594. sstr[c] = loc[3+strlen("status")+c];
  8595. c++;
  8596. }
  8597. sstr[c] = '\0';
  8598. strcpy(statusStr, sstr);
  8599. //***currentTime ****/
  8600. loc = strstr(payload, "currentTime");
  8601. //printf("loc=%s\n",loc);
  8602. memset(sstr ,0, sizeof(sstr) );
  8603. c = 0;
  8604. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8605. {
  8606. sstr[c] = loc[3+strlen("currentTime")+c];
  8607. c++;
  8608. }
  8609. sstr[c] = '\0';
  8610. strcpy(currentTimeStr, sstr);
  8611. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8612. HeartBeatWaitTime = BootNotificationInterval;
  8613. //#ifdef SystemLogMessage
  8614. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8615. // DEBUG_INFO("interval: %d\n", intervalInt);
  8616. // DEBUG_INFO("status: %s\n", statusStr);
  8617. //#endif
  8618. //write back to ShmOCPP16Data->BootNotification
  8619. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8620. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8621. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8622. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8623. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8624. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8625. {
  8626. server_sign = TRUE;
  8627. server_pending =FALSE;
  8628. }
  8629. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8630. {
  8631. server_pending = TRUE;
  8632. }
  8633. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8634. tp.tm_isdst = -1;
  8635. //time_t utc = mktime(&tp);
  8636. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8637. memset(timebuf, 0, sizeof timebuf);
  8638. sprintf(timebuf,"date -s '%s'",buf);
  8639. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8640. system(timebuf);
  8641. //==============================================
  8642. // RTC sync
  8643. //==============================================
  8644. system("/sbin/hwclock -w --systohc");
  8645. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8646. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8647. }
  8648. void handleDataTransferResponse(char *payload, int gun_index)
  8649. {
  8650. char sstr[160]={0};//sstr[200]={ 0 };
  8651. int c = 0;
  8652. char *loc;
  8653. DEBUG_INFO("handleDataTransferResponse ...\n");
  8654. loc = strstr(payload, "status");
  8655. printf("loc=%s\n",loc);
  8656. c = 0;
  8657. while (loc[3+strlen("status")+c] != '\"')
  8658. {
  8659. sstr[c] = loc[3+strlen("status")+c];
  8660. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8661. c++;
  8662. }
  8663. sstr[c] = '\0';
  8664. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8665. //#ifdef SystemLogMessage
  8666. //DEBUG_INFO("data: %s\n", payload);
  8667. //#endif
  8668. }
  8669. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8670. {
  8671. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8672. //struct json_object *obj;
  8673. // obj = json_tokener_parse(payload);
  8674. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8675. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8676. //No fields are defined.
  8677. }
  8678. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8679. {
  8680. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8681. //struct json_object *obj;
  8682. // obj = json_tokener_parse(payload);
  8683. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8684. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8685. //No fields are defined.
  8686. }
  8687. void handleHeartbeatResponse(char *payload, int gun_index)
  8688. {
  8689. mtrace();
  8690. //double diff_t;
  8691. struct tm tp;
  8692. char buf[28]={0};
  8693. char timebuf[50]={0};
  8694. char sstr[30]={ 0 };
  8695. int c = 0;
  8696. char *loc;
  8697. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8698. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8699. c = 0;
  8700. loc = strstr(payload, "currentTime");
  8701. memset(sstr ,0, sizeof(sstr) );
  8702. while (loc[3+strlen("currentTime")+c] != '\"')
  8703. {
  8704. sstr[c] = loc[3+strlen("currentTime")+c];
  8705. c++;
  8706. }
  8707. sstr[c] = '\0';
  8708. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8709. // #ifdef SystemLogMessage
  8710. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8711. // #endif
  8712. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8713. tp.tm_isdst = -1;
  8714. //time_t utc = mktime(&tp);
  8715. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8716. memset(timebuf, 0, sizeof timebuf);
  8717. sprintf(timebuf,"date -s '%s'",buf);
  8718. system(timebuf);
  8719. //==============================================
  8720. // RTC sync
  8721. //==============================================
  8722. system("/sbin/hwclock -w --systohc");
  8723. if(FirstHeartBeat == 0)
  8724. {
  8725. FirstHeartBeat = 1;
  8726. }
  8727. }
  8728. void handleMeterValuesResponse(char *payload, int gun_index)
  8729. {
  8730. mtrace();
  8731. //struct json_object *obj;
  8732. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8733. //No fields are defined.
  8734. }
  8735. void handleStartTransactionResponse(char *payload, int gun_index)
  8736. {
  8737. mtrace();
  8738. char sstr[30]={ 0 };
  8739. int c = 0;
  8740. char *loc;
  8741. int transactionIdInt = 0;
  8742. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8743. DEBUG_INFO("handleStartTransactionResponse\n");
  8744. //****************expiryDate********************/
  8745. loc = strstr(payload, "expiryDate");
  8746. if(loc == NULL)
  8747. {
  8748. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8749. }
  8750. else
  8751. {
  8752. c = 0;
  8753. memset(sstr ,0, sizeof(sstr) );
  8754. while (loc[3+strlen("expiryDate")+c] != '\"')
  8755. {
  8756. sstr[c] = loc[3+strlen("expiryDate")+c];
  8757. c++;
  8758. }
  8759. sstr[c] = '\0';
  8760. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8761. }
  8762. //****************parentIdTag********************/
  8763. loc = strstr(payload, "parentIdTag");
  8764. if(loc == NULL)
  8765. {
  8766. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8767. }
  8768. else
  8769. {
  8770. c = 0;
  8771. memset(sstr ,0, sizeof(sstr) );
  8772. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8773. {
  8774. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8775. c++;
  8776. }
  8777. sstr[c] = '\0';
  8778. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8779. }
  8780. //****************status********************/
  8781. loc = strstr(payload, "status");
  8782. if(loc == NULL)
  8783. {
  8784. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8785. }
  8786. else
  8787. {
  8788. c = 0;
  8789. memset(sstr ,0, sizeof(sstr) );
  8790. while (loc[3+strlen("status")+c] != '\"')
  8791. {
  8792. sstr[c] = loc[3+strlen("status")+c];
  8793. c++;
  8794. }
  8795. sstr[c] = '\0';
  8796. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8797. }
  8798. //****************transactionId********************/
  8799. c=0;
  8800. loc = strstr(payload, "transactionId");
  8801. memset(sstr ,0, sizeof(sstr) );
  8802. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8803. {
  8804. sstr[c] = loc[strlen("transactionId")+2+c];
  8805. c++;
  8806. }
  8807. sstr[c] = '\0';
  8808. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8809. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8810. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8811. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8812. #ifdef SystemLogMessage
  8813. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8814. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8815. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8816. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8817. #endif
  8818. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8819. {
  8820. //add Charging Record
  8821. SettingChargingRecord(gun_index, transactionIdInt);
  8822. }
  8823. }
  8824. void handleStatusNotificationResponse(char *payload, int gun_index)
  8825. {
  8826. mtrace();
  8827. printf("handleStatusNotificationResponse\n");
  8828. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8829. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8830. }
  8831. void handleStopTransactionnResponse(char *payload, int gun_index)
  8832. {
  8833. mtrace();
  8834. char sstr[30]={ 0 };
  8835. int c = 0;
  8836. char *loc;
  8837. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8838. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8839. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8840. loc = strstr(payload, "idTagInfo");
  8841. //***********************idTagInfo************************/
  8842. if(loc != NULL)
  8843. {
  8844. //***********************expiryDate************************/
  8845. loc = strstr(payload, "expiryDate");
  8846. if(loc != NULL)
  8847. {
  8848. memset(sstr ,0, sizeof(sstr) );
  8849. c = 0;
  8850. while (loc[3+strlen("expiryDate")+c] != '\"')
  8851. {
  8852. sstr[c] = loc[3+strlen("expiryDate")+c];
  8853. c++;
  8854. }
  8855. sstr[c] = '\0';
  8856. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8857. }
  8858. //***********************parentIdTag************************/
  8859. loc = strstr(payload, "parentIdTag");
  8860. if(loc != NULL)
  8861. {
  8862. memset(sstr ,0, sizeof(sstr) );
  8863. c = 0;
  8864. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8865. {
  8866. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8867. c++;
  8868. }
  8869. sstr[c] = '\0';
  8870. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8871. }
  8872. //***********************status************************/
  8873. loc = strstr(payload, "status");
  8874. memset(sstr ,0, sizeof(sstr) );
  8875. c = 0;
  8876. while (loc[3+strlen("status")+c] != '\"')
  8877. {
  8878. sstr[c] = loc[3+strlen("status")+c];
  8879. c++;
  8880. }
  8881. sstr[c] = '\0';
  8882. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8883. }
  8884. #ifdef SystemLogMessage
  8885. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8886. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8887. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8888. #endif
  8889. }
  8890. //==========================================
  8891. // Handle Error routine
  8892. //==========================================
  8893. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8894. {
  8895. mtrace();
  8896. #ifdef SystemLogMessage
  8897. DEBUG_INFO("errorCode: %s\n", errorCode);
  8898. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8899. DEBUG_INFO("errorDetails: %s\n", payload);
  8900. #endif
  8901. }
  8902. //===============================================
  8903. // Common routine
  8904. //===============================================
  8905. int initialConfigurationTable(void)
  8906. {
  8907. printf("initialConfigurationTable \n");
  8908. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8909. /*Core Profile*/
  8910. //AllowOfflineTxForUnknownId
  8911. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8912. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8915. //AuthorizationCacheEnabled
  8916. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8919. //AuthorizeRemoteTxRequests
  8920. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8923. //BlinkRepeat
  8924. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8927. //ClockAlignedDataInterval
  8928. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8931. //ConnectionTimeOut
  8932. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8935. //GetConfigurationMaxKeys
  8936. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8939. // HeartbeatInterval
  8940. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8943. // LightIntensity
  8944. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8947. // LocalAuthorizeOffline
  8948. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  8949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8951. // LocalPreAuthorize
  8952. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  8953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8955. // MaxEnergyOnInvalidId
  8956. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  8958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  8959. // MeterValuesAlignedData
  8960. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  8961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  8962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  8963. // MeterValuesAlignedDataMaxLength
  8964. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  8965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  8966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  8967. // MeterValuesSampledData
  8968. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  8969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  8970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  8971. // MeterValuesSampledDataMaxLength
  8972. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  8973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  8974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  8975. // MeterValueSampleInterval
  8976. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  8977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  8978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  8979. // MinimumStatusDuration
  8980. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  8981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  8982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  8983. // NumberOfConnectors
  8984. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  8985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  8986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  8987. // ResetRetries
  8988. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  8989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  8990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  8991. // ConnectorPhaseRotation
  8992. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  8993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  8994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  8995. // ConnectorPhaseRotationMaxLength
  8996. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  8997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  8998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  8999. // StopTransactionOnEVSideDisconnect
  9000. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9003. // StopTransactionOnInvalidId
  9004. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9007. // StopTxnAlignedData
  9008. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9011. // StopTxnAlignedDataMaxLength
  9012. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9015. // StopTxnSampledData
  9016. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9019. // StopTxnSampledDataMaxLength
  9020. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9023. // SupportedFeatureProfiles
  9024. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9027. // SupportedFeatureProfilesMaxLength
  9028. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9031. // TransactionMessageAttempts
  9032. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9035. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9036. // TransactionMessageRetryInterval
  9037. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9040. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9041. // UnlockConnectorOnEVSideDisconnect
  9042. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9045. // WebSocketPingInterval
  9046. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9049. //* Local Auth List Management Profile*/
  9050. #if 0
  9051. //For OCTT Test Case
  9052. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9055. #endif
  9056. #if 1
  9057. //LocalAuthListEnabled
  9058. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9061. #endif
  9062. //LocalAuthListMaxLength
  9063. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9066. //SendLocalListMaxLength
  9067. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9070. //ReserveConnectorZeroSupported
  9071. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9074. //* Smart Charging Profile */
  9075. //ChargeProfileMaxStackLevel
  9076. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9079. // ChargingScheduleAllowedChargingRateUnit
  9080. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9083. // ChargingScheduleMaxPeriods
  9084. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9087. // ConnectorSwitch3to1PhaseSupported
  9088. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9091. // MaxChargingProfilesInstalled
  9092. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9095. return 0;
  9096. }
  9097. void getKeyValue(char *keyReq)
  9098. {
  9099. int isEmpty = FALSE;
  9100. int isKnowKey = FALSE;
  9101. //int unKnowIndex = 0;
  9102. DEBUG_INFO("getKeyValue \n");
  9103. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9104. isEmpty = TRUE;
  9105. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9106. {
  9107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9110. {
  9111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9112. }
  9113. else
  9114. {
  9115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9116. }
  9117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9118. isKnowKey = TRUE;
  9119. }
  9120. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9121. {
  9122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9125. {
  9126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9127. }
  9128. else
  9129. {
  9130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9131. }
  9132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9133. isKnowKey = TRUE;
  9134. }
  9135. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9136. {
  9137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9140. {
  9141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9142. }
  9143. else
  9144. {
  9145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9146. }
  9147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9148. isKnowKey = TRUE;
  9149. }
  9150. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9151. {
  9152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9155. {
  9156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9157. }
  9158. else
  9159. {
  9160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9161. }
  9162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9163. isKnowKey = TRUE;
  9164. }
  9165. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9166. {
  9167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9170. {
  9171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9172. }
  9173. else
  9174. {
  9175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9176. }
  9177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9178. isKnowKey = TRUE;
  9179. }
  9180. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9181. {
  9182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9185. {
  9186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9187. }
  9188. else
  9189. {
  9190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9191. }
  9192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9193. isKnowKey = TRUE;
  9194. }
  9195. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9196. {
  9197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9200. {
  9201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9202. }
  9203. else
  9204. {
  9205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9206. }
  9207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9208. isKnowKey = TRUE;
  9209. }
  9210. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9211. {
  9212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9215. {
  9216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9217. }
  9218. else
  9219. {
  9220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9221. }
  9222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9223. isKnowKey = TRUE;
  9224. }
  9225. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9226. {
  9227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9230. {
  9231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9232. }
  9233. else
  9234. {
  9235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9236. }
  9237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9238. isKnowKey = TRUE;
  9239. }
  9240. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9241. {
  9242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9245. {
  9246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9247. }
  9248. else
  9249. {
  9250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9251. }
  9252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9253. isKnowKey = TRUE;
  9254. }
  9255. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9256. {
  9257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9260. {
  9261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9262. }
  9263. else
  9264. {
  9265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9266. }
  9267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9268. isKnowKey = TRUE;
  9269. }
  9270. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9271. {
  9272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9275. {
  9276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9277. }
  9278. else
  9279. {
  9280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9281. }
  9282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9283. isKnowKey = TRUE;
  9284. }
  9285. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9286. {
  9287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9290. {
  9291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9292. }
  9293. else
  9294. {
  9295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9296. }
  9297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9298. isKnowKey = TRUE;
  9299. }
  9300. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9301. {
  9302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9305. {
  9306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9307. }
  9308. else
  9309. {
  9310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9311. }
  9312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9313. isKnowKey = TRUE;
  9314. }
  9315. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9316. {
  9317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9320. {
  9321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9322. }
  9323. else
  9324. {
  9325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9326. }
  9327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9328. isKnowKey = TRUE;
  9329. }
  9330. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9331. {
  9332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9335. {
  9336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9337. }
  9338. else
  9339. {
  9340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9341. }
  9342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9343. isKnowKey = TRUE;
  9344. }
  9345. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9346. {
  9347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9350. {
  9351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9352. }
  9353. else
  9354. {
  9355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9356. }
  9357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9358. isKnowKey = TRUE;
  9359. }
  9360. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9361. {
  9362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9365. {
  9366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9367. }
  9368. else
  9369. {
  9370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9371. }
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9373. isKnowKey = TRUE;
  9374. }
  9375. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9376. {
  9377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9380. {
  9381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9382. }
  9383. else
  9384. {
  9385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9386. }
  9387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9388. isKnowKey = TRUE;
  9389. }
  9390. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9391. {
  9392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9395. {
  9396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9397. }
  9398. else
  9399. {
  9400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9401. }
  9402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9403. isKnowKey = TRUE;
  9404. }
  9405. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9406. {
  9407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9410. {
  9411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9412. }
  9413. else
  9414. {
  9415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9416. }
  9417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9418. isKnowKey = TRUE;
  9419. }
  9420. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9421. {
  9422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9425. {
  9426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9427. }
  9428. else
  9429. {
  9430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9431. }
  9432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9433. isKnowKey = TRUE;
  9434. }
  9435. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9436. {
  9437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9440. {
  9441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9442. }
  9443. else
  9444. {
  9445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9446. }
  9447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9448. isKnowKey = TRUE;
  9449. }
  9450. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9451. {
  9452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9455. {
  9456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9457. }
  9458. else
  9459. {
  9460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9461. }
  9462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9463. isKnowKey = TRUE;
  9464. }
  9465. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9466. {
  9467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9470. {
  9471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9472. }
  9473. else
  9474. {
  9475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9476. }
  9477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9478. isKnowKey = TRUE;
  9479. }
  9480. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9481. {
  9482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9485. {
  9486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9487. }
  9488. else
  9489. {
  9490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9491. }
  9492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9493. isKnowKey = TRUE;
  9494. }
  9495. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9496. {
  9497. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9500. {
  9501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9502. }
  9503. else
  9504. {
  9505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9506. }
  9507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9508. isKnowKey = TRUE;
  9509. }
  9510. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9511. {
  9512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9515. {
  9516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9517. }
  9518. else
  9519. {
  9520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9521. }
  9522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9523. isKnowKey = TRUE;
  9524. }
  9525. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9526. {
  9527. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9530. {
  9531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9532. }
  9533. else
  9534. {
  9535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9536. }
  9537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9538. isKnowKey = TRUE;
  9539. }
  9540. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9541. {
  9542. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9545. {
  9546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9547. }
  9548. else
  9549. {
  9550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9551. }
  9552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9553. isKnowKey = TRUE;
  9554. }
  9555. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9556. {
  9557. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9560. {
  9561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9562. }
  9563. else
  9564. {
  9565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9566. }
  9567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9568. isKnowKey = TRUE;
  9569. }
  9570. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9571. {
  9572. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9574. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9575. {
  9576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9577. }
  9578. else
  9579. {
  9580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9581. }
  9582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9583. isKnowKey = TRUE;
  9584. }
  9585. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9586. {
  9587. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9590. {
  9591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9592. }
  9593. else
  9594. {
  9595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9596. }
  9597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9598. isKnowKey = TRUE;
  9599. }
  9600. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9601. {
  9602. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9605. {
  9606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9607. }
  9608. else
  9609. {
  9610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9611. }
  9612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9613. isKnowKey = TRUE;
  9614. }
  9615. #if 0
  9616. //For OCTT Test Case
  9617. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9618. {
  9619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9621. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9622. {
  9623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9624. }
  9625. else
  9626. {
  9627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9628. }
  9629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9630. isKnowKey = TRUE;
  9631. }
  9632. #endif
  9633. #if 1
  9634. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9635. {
  9636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9638. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9639. {
  9640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9641. }
  9642. else
  9643. {
  9644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9645. }
  9646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9647. isKnowKey = TRUE;
  9648. }
  9649. #endif
  9650. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9651. {
  9652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9654. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9655. {
  9656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9657. }
  9658. else
  9659. {
  9660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9661. }
  9662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9663. isKnowKey = TRUE;
  9664. }
  9665. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9666. {
  9667. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9669. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9670. {
  9671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9672. }
  9673. else
  9674. {
  9675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9676. }
  9677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9678. isKnowKey = TRUE;
  9679. }
  9680. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9681. {
  9682. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9684. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9685. {
  9686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9687. }
  9688. else
  9689. {
  9690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9691. }
  9692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9693. isKnowKey = TRUE;
  9694. }
  9695. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9696. {
  9697. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9699. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9700. {
  9701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9702. }
  9703. else
  9704. {
  9705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9706. }
  9707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9708. isKnowKey = TRUE;
  9709. }
  9710. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9711. {
  9712. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9714. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9715. {
  9716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9717. }
  9718. else
  9719. {
  9720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9721. }
  9722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9723. isKnowKey = TRUE;
  9724. }
  9725. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9726. {
  9727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9729. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9730. {
  9731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9732. }
  9733. else
  9734. {
  9735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9736. }
  9737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9738. isKnowKey = TRUE;
  9739. }
  9740. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9741. {
  9742. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9744. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9745. {
  9746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9747. }
  9748. else
  9749. {
  9750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9751. }
  9752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9753. isKnowKey = TRUE;
  9754. }
  9755. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9756. {
  9757. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9759. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9760. {
  9761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9762. }
  9763. else
  9764. {
  9765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9766. }
  9767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9768. isKnowKey = TRUE;
  9769. }
  9770. //=========================================================
  9771. if(!isEmpty && !isKnowKey)
  9772. {
  9773. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9774. strcpy(unknownkey[UnknownKeynum], keyReq);
  9775. UnknownKeynum = UnknownKeynum + 1;
  9776. }
  9777. }
  9778. void processUnkownKey(void)
  9779. {
  9780. DEBUG_INFO("processUnkownKey\n");
  9781. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9782. for(int index=0; index < UnknownKeynum; index++)
  9783. {
  9784. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9785. {
  9786. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9787. }
  9788. }
  9789. }
  9790. int setKeyValue(char *key, char *value)
  9791. {
  9792. int isSuccess = NotSupported;
  9793. int check_ascii=0;
  9794. #ifdef Debug
  9795. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9796. #endif
  9797. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9798. {
  9799. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9801. {
  9802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9803. isSuccess = ConfigurationStatus_Accepted;
  9804. }
  9805. else
  9806. {
  9807. isSuccess = ConfigurationStatus_Rejected;
  9808. }
  9809. }
  9810. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9811. {
  9812. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9814. {
  9815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9816. isSuccess = ConfigurationStatus_Accepted;
  9817. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9818. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9819. }
  9820. else
  9821. {
  9822. isSuccess = ConfigurationStatus_Rejected;
  9823. }
  9824. }
  9825. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9826. {
  9827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9828. {
  9829. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9831. isSuccess = ConfigurationStatus_Accepted;
  9832. }
  9833. else
  9834. {
  9835. isSuccess = ConfigurationStatus_Rejected;
  9836. }
  9837. }
  9838. if(strcmp(key, "BlinkRepeat") == 0)
  9839. {
  9840. //Charger.BlinkRepeat = Integer.parseInt(value);
  9841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9842. {
  9843. check_ascii = value[0];
  9844. if( (check_ascii < 48) || (check_ascii > 57) )
  9845. {
  9846. isSuccess = ConfigurationStatus_Rejected;
  9847. }
  9848. else
  9849. {
  9850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9851. isSuccess = ConfigurationStatus_Accepted;
  9852. }
  9853. }
  9854. else
  9855. {
  9856. isSuccess = ConfigurationStatus_Rejected;
  9857. }
  9858. }
  9859. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9860. {
  9861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9862. {
  9863. check_ascii = value[0];
  9864. if( (check_ascii < 48) || (check_ascii > 57) )
  9865. {
  9866. isSuccess = ConfigurationStatus_Rejected;
  9867. }
  9868. else
  9869. {
  9870. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9872. isSuccess = ConfigurationStatus_Accepted;
  9873. }
  9874. }
  9875. else
  9876. {
  9877. isSuccess = ConfigurationStatus_Rejected;
  9878. }
  9879. }
  9880. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9881. {
  9882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9883. {
  9884. check_ascii = value[0];
  9885. if( (check_ascii < 48) || (check_ascii > 57) )
  9886. {
  9887. isSuccess = ConfigurationStatus_Rejected;
  9888. }
  9889. else
  9890. {
  9891. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9893. isSuccess = ConfigurationStatus_Accepted;
  9894. }
  9895. }
  9896. else
  9897. {
  9898. isSuccess = ConfigurationStatus_Rejected;
  9899. }
  9900. }
  9901. if(strcmp(key, "HeartbeatInterval") == 0)
  9902. {
  9903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9904. {
  9905. check_ascii = value[0];
  9906. if( (check_ascii < 48) || (check_ascii > 57) )
  9907. {
  9908. isSuccess = ConfigurationStatus_Rejected;
  9909. }
  9910. else
  9911. {
  9912. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9914. HeartBeatWaitTime = atoi(value);
  9915. isSuccess = ConfigurationStatus_Accepted;
  9916. }
  9917. }
  9918. else
  9919. {
  9920. isSuccess = ConfigurationStatus_Rejected;
  9921. }
  9922. }
  9923. if(strcmp(key, "LightIntensity") == 0)
  9924. {
  9925. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9926. {
  9927. check_ascii = value[0];
  9928. if( (check_ascii < 48) || (check_ascii > 57) )
  9929. {
  9930. isSuccess = ConfigurationStatus_Rejected;
  9931. }
  9932. else
  9933. {
  9934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9935. isSuccess = ConfigurationStatus_Accepted;
  9936. }
  9937. }
  9938. else
  9939. {
  9940. isSuccess = ConfigurationStatus_Rejected;
  9941. }
  9942. }
  9943. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9944. {
  9945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9946. {
  9947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9948. isSuccess = ConfigurationStatus_Accepted;
  9949. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9950. }
  9951. else
  9952. {
  9953. isSuccess = ConfigurationStatus_Rejected;
  9954. }
  9955. }
  9956. if(strcmp(key, "LocalPreAuthorize") == 0)
  9957. {
  9958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9959. {
  9960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9961. isSuccess = ConfigurationStatus_Accepted;
  9962. }
  9963. else
  9964. {
  9965. isSuccess = ConfigurationStatus_Rejected;
  9966. }
  9967. }
  9968. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  9969. {
  9970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9971. {
  9972. check_ascii = value[0];
  9973. if( (check_ascii < 48) || (check_ascii > 57) )
  9974. {
  9975. isSuccess = ConfigurationStatus_Rejected;
  9976. }
  9977. else
  9978. {
  9979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  9980. isSuccess = ConfigurationStatus_Accepted;
  9981. }
  9982. }
  9983. else
  9984. {
  9985. isSuccess = ConfigurationStatus_Rejected;
  9986. }
  9987. }
  9988. if(strcmp(key, "MeterValuesAlignedData") == 0)
  9989. {
  9990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9991. {
  9992. //int valueLength = strlen(value);
  9993. for(int i = 0; value[i]; i++){
  9994. value[i] = tolower(value[i]);
  9995. }
  9996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  9997. isSuccess = ConfigurationStatus_Accepted;
  9998. }
  9999. else
  10000. {
  10001. isSuccess = ConfigurationStatus_Rejected;
  10002. }
  10003. }
  10004. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10005. {
  10006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10007. {
  10008. //int valueLength = strlen(value);
  10009. for(int i = 0; value[i]; i++){
  10010. value[i] = tolower(value[i]);
  10011. }
  10012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10013. isSuccess = ConfigurationStatus_Accepted;
  10014. }
  10015. else
  10016. {
  10017. isSuccess = ConfigurationStatus_Rejected;
  10018. }
  10019. }
  10020. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10021. {
  10022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10023. {
  10024. check_ascii = value[0];
  10025. if( (check_ascii < 48) || (check_ascii > 57) )
  10026. {
  10027. isSuccess = ConfigurationStatus_Rejected;
  10028. }
  10029. else
  10030. {
  10031. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10033. isSuccess = ConfigurationStatus_Accepted;
  10034. }
  10035. #ifdef Debug
  10036. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10037. #endif
  10038. }
  10039. else
  10040. {
  10041. isSuccess = ConfigurationStatus_Rejected;
  10042. #ifdef Debug
  10043. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10044. #endif
  10045. }
  10046. }
  10047. if(strcmp(key, "MinimumStatusDuration") == 0)
  10048. {
  10049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10050. {
  10051. check_ascii = value[0];
  10052. if( (check_ascii < 48) || (check_ascii > 57) )
  10053. {
  10054. isSuccess = ConfigurationStatus_Rejected;
  10055. }
  10056. else
  10057. {
  10058. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10060. isSuccess = ConfigurationStatus_Accepted;
  10061. }
  10062. }
  10063. else
  10064. {
  10065. isSuccess = ConfigurationStatus_Rejected;
  10066. }
  10067. }
  10068. if(strcmp(key, "ResetRetries") == 0)
  10069. {
  10070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10071. {
  10072. check_ascii = value[0];
  10073. if( (check_ascii < 48) || (check_ascii > 57) )
  10074. {
  10075. isSuccess = ConfigurationStatus_Rejected;
  10076. }
  10077. else
  10078. {
  10079. //Charger.ResetRetries = Integer.parseInt(value);
  10080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10081. isSuccess = ConfigurationStatus_Accepted;
  10082. }
  10083. }
  10084. else
  10085. {
  10086. isSuccess = ConfigurationStatus_Rejected;
  10087. }
  10088. }
  10089. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10090. {
  10091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10092. {
  10093. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10094. //int valueLength = strlen(value);
  10095. for(int i = 0; value[i]; i++){
  10096. value[i] = tolower(value[i]);
  10097. }
  10098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10099. isSuccess = ConfigurationStatus_Accepted;
  10100. }
  10101. else
  10102. {
  10103. isSuccess = ConfigurationStatus_Rejected;
  10104. }
  10105. }
  10106. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10107. {
  10108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10109. {
  10110. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].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, "StopTransactionOnInvalidId") == 0)
  10120. {
  10121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10122. {
  10123. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10125. isSuccess = ConfigurationStatus_Accepted;
  10126. }
  10127. else
  10128. {
  10129. isSuccess = ConfigurationStatus_Rejected;
  10130. }
  10131. }
  10132. if(strcmp(key, "StopTxnAlignedData") == 0)
  10133. {
  10134. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10135. {
  10136. //Charger.StopTxnAlignedData = value.toLowerCase();
  10137. //int valueLength = strlen(value);
  10138. for(int i = 0; value[i]; i++){
  10139. value[i] = tolower(value[i]);
  10140. }
  10141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10142. isSuccess = ConfigurationStatus_Accepted;
  10143. }
  10144. else
  10145. {
  10146. isSuccess = ConfigurationStatus_Rejected;
  10147. }
  10148. }
  10149. if(strcmp(key, "StopTxnSampledData") == 0)
  10150. {
  10151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10152. {
  10153. //Charger.StopTxnSampledData = value.toLowerCase();
  10154. //int valueLength = strlen(value);
  10155. for(int i = 0; value[i]; i++){
  10156. value[i] = tolower(value[i]);
  10157. }
  10158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10159. isSuccess = ConfigurationStatus_Accepted;
  10160. }
  10161. else
  10162. {
  10163. isSuccess = ConfigurationStatus_Rejected;
  10164. }
  10165. }
  10166. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10167. {
  10168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10169. {
  10170. check_ascii = value[0];
  10171. if( (check_ascii < 48) || (check_ascii > 57) )
  10172. {
  10173. isSuccess = ConfigurationStatus_Rejected;
  10174. }
  10175. else
  10176. {
  10177. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10179. TransactionMessageAttemptsValue = atoi(value);
  10180. isSuccess = ConfigurationStatus_Accepted;
  10181. }
  10182. }
  10183. else
  10184. {
  10185. isSuccess = ConfigurationStatus_Rejected;
  10186. }
  10187. }
  10188. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10189. {
  10190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10191. {
  10192. check_ascii = value[0];
  10193. if( (check_ascii < 48) || (check_ascii > 57) )
  10194. {
  10195. isSuccess = ConfigurationStatus_Rejected;
  10196. }
  10197. else
  10198. {
  10199. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10201. TransactionMessageRetryIntervalValue = atoi(value);
  10202. isSuccess = ConfigurationStatus_Accepted;
  10203. }
  10204. }
  10205. else
  10206. {
  10207. isSuccess = ConfigurationStatus_Rejected;
  10208. }
  10209. }
  10210. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10211. {
  10212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10213. {
  10214. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10216. isSuccess = ConfigurationStatus_Accepted;
  10217. }
  10218. else
  10219. {
  10220. isSuccess = ConfigurationStatus_Rejected;
  10221. }
  10222. }
  10223. if(strcmp(key, "WebSocketPingInterval") == 0)
  10224. {
  10225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10226. {
  10227. check_ascii = value[0];
  10228. if( (check_ascii < 48) || (check_ascii > 57) )
  10229. {
  10230. isSuccess = ConfigurationStatus_Rejected;
  10231. }
  10232. else
  10233. {
  10234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10235. isSuccess = ConfigurationStatus_Accepted;
  10236. }
  10237. }
  10238. else
  10239. {
  10240. isSuccess = ConfigurationStatus_Rejected;
  10241. }
  10242. }
  10243. #if 0
  10244. //For OCPP Test Case
  10245. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10246. {
  10247. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10248. {
  10249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10250. isSuccess = ConfigurationStatus_Accepted;
  10251. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10252. }
  10253. else
  10254. {
  10255. isSuccess = ConfigurationStatus_Rejected;
  10256. }
  10257. }
  10258. #endif
  10259. #if 1
  10260. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10261. {
  10262. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10263. {
  10264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10265. isSuccess = ConfigurationStatus_Accepted;
  10266. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10267. }
  10268. else
  10269. {
  10270. isSuccess = ConfigurationStatus_Rejected;
  10271. }
  10272. }
  10273. #endif
  10274. return isSuccess;
  10275. }
  10276. int updateSetting(char *key, char *value)
  10277. {
  10278. mtrace();
  10279. int isSuccess = FALSE;
  10280. char string[1000]={0}, buffer[1000]={0};
  10281. char strtemp[50]={0};
  10282. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10283. int pos, c = 0;
  10284. char *loc;
  10285. int pos1=0;
  10286. FILE *f = fopen("/var/www/settings1", "r");
  10287. if(f == NULL)
  10288. {
  10289. #ifdef Debug
  10290. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10291. #endif
  10292. return isSuccess;
  10293. }
  10294. fseek(f, 0, SEEK_END);
  10295. long fsize = ftell(f);
  10296. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10297. fread(string, 1, fsize, f);
  10298. fclose(f);
  10299. string[fsize] = 0;
  10300. loc = strstr(string, key);
  10301. if(loc != NULL)
  10302. {
  10303. DEBUG_INFO("key exist!\n");
  10304. pos = loc - string-1;
  10305. f = fopen("/var/www/settings1", "w");
  10306. strncpy(buffer, string, pos);
  10307. fprintf(f, "%s", buffer);
  10308. memset(sstr ,0, sizeof(sstr) );
  10309. c = 0;
  10310. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10311. {
  10312. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10313. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10314. c++;
  10315. }
  10316. sstr[c] = '\0';
  10317. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10318. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10319. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10320. memset(buffer ,0, sizeof(buffer) );
  10321. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10322. //printf("buffer=%s",buffer);
  10323. fprintf(f, "%s", buffer);
  10324. fclose(f);
  10325. }
  10326. else
  10327. {
  10328. printf("key not exist!\n");
  10329. f = fopen("/var/www/settings1", "w+");
  10330. fputs(string, f);
  10331. fseek(f, -1, SEEK_CUR);
  10332. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10333. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10334. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10335. fclose(f);
  10336. }
  10337. isSuccess = TRUE;
  10338. return isSuccess;
  10339. }
  10340. int TransactionMessageAttemptsGet(void)
  10341. {
  10342. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10343. }
  10344. int FirstHeartBeatResponse(void)
  10345. {
  10346. return FirstHeartBeat;
  10347. }
  10348. int TransactionMessageRetryIntervalGet(void)
  10349. {
  10350. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10351. }
  10352. #define SA struct sockaddr
  10353. #define MAXBUF 1024
  10354. //static int m_socket_data;
  10355. //static int sockfd;
  10356. int ReadHttpStatus(int sock){
  10357. //char c;
  10358. char buff[1024]="",*ptr=buff+1;
  10359. int bytes_received, status;
  10360. DEBUG_INFO("Begin Response ..\n");
  10361. while((bytes_received = recv(sock, ptr, 1, 0))){
  10362. if(bytes_received==-1){
  10363. perror("ReadHttpStatus");
  10364. exit(1);
  10365. }
  10366. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10367. ptr++;
  10368. }
  10369. *ptr=0;
  10370. ptr=buff+1;
  10371. sscanf(ptr,"%*s %d ", &status);
  10372. DEBUG_INFO("%s\n",ptr);
  10373. DEBUG_INFO("status=%d\n",status);
  10374. DEBUG_INFO("End Response ..\n");
  10375. return (bytes_received>0)?status:0;
  10376. }
  10377. //the only filed that it parsed is 'Content-Length'
  10378. int ParseHeader(int sock){
  10379. //char c;
  10380. char buff[1024]="",*ptr=buff+4;
  10381. int bytes_received;
  10382. DEBUG_INFO("Begin HEADER ..\n");
  10383. while((bytes_received = recv(sock, ptr, 1, 0))){
  10384. if(bytes_received==-1){
  10385. perror("Parse Header");
  10386. exit(1);
  10387. }
  10388. if(
  10389. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10390. (ptr[-1]=='\r') && (*ptr=='\n' )
  10391. ) break;
  10392. ptr++;
  10393. }
  10394. *ptr=0;
  10395. ptr=buff+4;
  10396. //printf("%s",ptr);
  10397. if(bytes_received){
  10398. ptr=strstr(ptr,"Content-Length:");
  10399. if(ptr){
  10400. sscanf(ptr,"%*s %d",&bytes_received);
  10401. }else
  10402. bytes_received=-1; //unknown size
  10403. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10404. }
  10405. DEBUG_INFO("End HEADER ..\n");
  10406. return bytes_received ;
  10407. }
  10408. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10409. {
  10410. char rmFileCmd[100]={0};
  10411. char FilePath[100]={0};
  10412. char ftpbuf[200];
  10413. int systemresult;
  10414. DEBUG_INFO("filename=%s\n",filename);
  10415. DEBUG_INFO("url=%s\n",url);
  10416. sprintf(FilePath,"../mnt/%s",filename);
  10417. if((access(FilePath,F_OK))!=-1)
  10418. {
  10419. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10420. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10421. system(rmFileCmd);
  10422. }
  10423. memset(ftpbuf, 0, sizeof(ftpbuf));
  10424. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10425. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10426. systemresult = system(ftpbuf);
  10427. DEBUG_INFO("systemresult=%d\n",systemresult);
  10428. if(systemresult != 0)
  10429. {
  10430. DEBUG_INFO("http DownLoad error!\n");
  10431. return FALSE;
  10432. }
  10433. return TRUE;
  10434. }
  10435. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10436. {
  10437. char rmFileCmd[100]={0};
  10438. char FilePath[100]={0};
  10439. char ftpbuf[200];
  10440. int systemresult;
  10441. //char temp[100];
  10442. #if 0
  10443. struct hostent* server;
  10444. char *IPbuffer;
  10445. server = gethostbyname(location);
  10446. // To convert an Internet network
  10447. // address into ASCII string
  10448. IPbuffer = inet_ntoa(*((struct in_addr*)
  10449. server->h_addr_list[0]));
  10450. #endif
  10451. sprintf(FilePath,"../mnt/%s",filename);
  10452. if((access(FilePath,F_OK))!=-1)
  10453. {
  10454. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10455. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10456. system(rmFileCmd);
  10457. }
  10458. memset(ftpbuf, 0, sizeof(ftpbuf));
  10459. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10460. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10461. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10462. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10463. systemresult = system(ftpbuf);
  10464. DEBUG_INFO("systemresult=%d\n",systemresult);
  10465. if(systemresult != 0)
  10466. {
  10467. printf("ftpget error!\n");
  10468. return FALSE;
  10469. }
  10470. return TRUE;
  10471. }
  10472. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10473. {
  10474. struct hostent* server;
  10475. char *IPbuffer;
  10476. char ftpbuf[200];
  10477. int systemresult;
  10478. // To retrieve host information
  10479. server = gethostbyname(location);
  10480. // To convert an Internet network
  10481. // address into ASCII string
  10482. IPbuffer = inet_ntoa(*((struct in_addr*)
  10483. server->h_addr_list[0]));
  10484. memset(ftpbuf, 0, sizeof(ftpbuf));
  10485. /* format : ftpput -u username -p passwd IP target source*/
  10486. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10487. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10488. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10489. systemresult = system(ftpbuf);
  10490. DEBUG_INFO("systemresult=%d\n",systemresult);
  10491. if(systemresult != 0)
  10492. {
  10493. DEBUG_INFO("ftpput error!\n");
  10494. return FALSE;
  10495. }
  10496. return TRUE;
  10497. }
  10498. int SettingChargingRecord(int target, int transactionId)
  10499. {
  10500. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  10501. {
  10502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10503. {
  10504. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10505. {
  10506. addBuff(target, transactionId, 0);
  10507. return TRUE;
  10508. }
  10509. }
  10510. for (int index = 0; index < CCS_QUANTITY; index++)
  10511. {
  10512. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10513. {
  10514. addBuff(target, transactionId, 0);
  10515. return TRUE;
  10516. }
  10517. }
  10518. for (int index = 0; index < GB_QUANTITY; index++)
  10519. {
  10520. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10521. {
  10522. addBuff(target, transactionId, 0);
  10523. return TRUE;
  10524. }
  10525. }
  10526. }
  10527. else
  10528. {
  10529. for (int index = 0; index < AC_QUANTITY; index++)
  10530. {
  10531. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10532. {
  10533. addBuff(target, transactionId, 0);
  10534. return TRUE;
  10535. }
  10536. }
  10537. }
  10538. return FALSE;
  10539. }
  10540. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10541. {
  10542. int isSuccess = FALSE;
  10543. //char *query = NULL;
  10544. sqlite3_stmt *stmt;
  10545. int rc; // return code
  10546. char str[20];
  10547. sprintf(str,"%d",user_id);
  10548. 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 */
  10549. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10550. rc = sqlite3_step(stmt); /* 3 */
  10551. if (rc != SQLITE_DONE) {
  10552. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10553. goto out;
  10554. }
  10555. sqlite3_finalize(stmt);
  10556. // free(query);
  10557. out:
  10558. //----------------------
  10559. // close SQLite database
  10560. //----------------------
  10561. sqlite3_close(db);
  10562. printf("database closed.\n");
  10563. return isSuccess;
  10564. }
  10565. /**
  10566. * Place the contents of the specified file into a memory buffer
  10567. *
  10568. * @param[in] filename The path and name of the file to read
  10569. * @param[out] filebuffer A pointer to the contents in memory
  10570. * @return status 0 success, 1 on failure
  10571. */
  10572. int get_file_contents(const char* filename, char** outbuffer) {
  10573. FILE* file = NULL;
  10574. long filesize;
  10575. const int blocksize = 1;
  10576. size_t readsize;
  10577. char* filebuffer;
  10578. // Open the file
  10579. file = fopen(filename, "r");
  10580. if (NULL == file)
  10581. {
  10582. printf("'%s' not opened\n", filename);
  10583. exit(EXIT_FAILURE);
  10584. }
  10585. // Determine the file size
  10586. fseek(file, 0, SEEK_END);
  10587. filesize = ftell(file);
  10588. rewind (file);
  10589. // Allocate memory for the file contents
  10590. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10591. *outbuffer = filebuffer;
  10592. if (filebuffer == NULL)
  10593. {
  10594. fputs ("malloc out-of-memory", stderr);
  10595. exit(EXIT_FAILURE);
  10596. }
  10597. // Read in the file
  10598. readsize = fread(filebuffer, blocksize, filesize, file);
  10599. if (readsize != filesize)
  10600. {
  10601. fputs ("didn't read file completely",stderr);
  10602. exit(EXIT_FAILURE);
  10603. }
  10604. // Clean exit
  10605. fclose(file);
  10606. return EXIT_SUCCESS;
  10607. }
  10608. static int selectSqlCount = 0;
  10609. static int callback(void *data, int argc, char **argv, char **azColName){
  10610. int i;
  10611. printf("%s: ", (const char*)data);
  10612. selectSqlCount = argc;
  10613. for(i = 0; i<argc; i++){
  10614. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10615. }
  10616. printf("\n");
  10617. return 0;
  10618. }
  10619. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10620. //int i;
  10621. //printf("%s:\n", (const char*)data);
  10622. localversion = argv[5] ? atoi(argv[5]) : 0;
  10623. printf("localversion=%d\n", localversion);
  10624. return 0;
  10625. }
  10626. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10627. //int i;
  10628. //printf("%s:\n", (const char*)data);
  10629. //idTag
  10630. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10631. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10632. //parentIdTag
  10633. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10634. //expir_date
  10635. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10636. //status
  10637. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10638. //version
  10639. idTagQuery.listVersionInt = atoi(argv[5]);
  10640. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10641. return 0;
  10642. }
  10643. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10644. int i;
  10645. //printf("%s:\n", (const char*)data);
  10646. #if 1
  10647. for(i=0; i<argc; i++){
  10648. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10649. }
  10650. //printf("");
  10651. #endif
  10652. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10653. // printf("localversion=%d\n", localversion);
  10654. return 0;
  10655. }
  10656. /** sqlite3_exec的回调。
  10657. *
  10658. * 向控制台打印查询的结果。
  10659. *
  10660. * @param in data 传递给回调函数的数据。
  10661. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10662. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10663. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10664. * @return 状态码。
  10665. */
  10666. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10667. {
  10668. for (int i = 0; i < n_columns; i++)
  10669. {
  10670. DEBUG_INFO("%s/t", col_values[i]);
  10671. }
  10672. DEBUG_INFO("/n");
  10673. return 0;
  10674. }
  10675. void OCPP_getListVerion()
  10676. {
  10677. int rc = 0;
  10678. // const char* data = "Callback function called";
  10679. char sql[100];
  10680. char zErrMsg[100];
  10681. memset(sql, 0, 100);
  10682. memset(zErrMsg, 0, 100);
  10683. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10684. /* Execute SQL statement */
  10685. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10686. DEBUG_INFO("rc=%d\n",rc);
  10687. if( rc != SQLITE_OK ){
  10688. DEBUG_INFO("SQL error: %s", zErrMsg);
  10689. //sqlite3_free(zErrMsg);
  10690. }else{
  10691. DEBUG_INFO("Operation done successfully");
  10692. }
  10693. }
  10694. void OCPP_getIdTag(char *idTag)
  10695. {
  10696. int rc = 0;
  10697. // const char* data = "Callback function called";
  10698. char sql[100];
  10699. char zErrMsg[100];
  10700. memset(sql, 0, 100);
  10701. memset(zErrMsg, 0, 100);
  10702. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10703. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10704. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10705. /* Execute SQL statement */
  10706. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10707. if( rc != SQLITE_OK ){
  10708. DEBUG_INFO("SQL error: %s", zErrMsg);
  10709. //sqlite3_free(zErrMsg);
  10710. }else{
  10711. printf("Operation done successfully");
  10712. }
  10713. //return ver;
  10714. }
  10715. void OCPP_get_TableAuthlocalAllData(void)
  10716. {
  10717. int rc = 0;
  10718. // const char* data = "Callback function called";
  10719. char sql[100];
  10720. char zErrMsg[100];
  10721. memset(sql, 0, 100);
  10722. memset(zErrMsg, 0, 100);
  10723. sprintf(sql,"select * from ocpp_auth_local ");
  10724. /* Execute SQL statement */
  10725. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10726. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10727. if( rc != SQLITE_OK ){
  10728. DEBUG_INFO("SQL error: %s", zErrMsg);
  10729. //sqlite3_free(zErrMsg);
  10730. }else{
  10731. DEBUG_INFO("Operation done successfully");
  10732. }
  10733. //return ver;
  10734. }
  10735. int OCPP_cleanLocalList()
  10736. {
  10737. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10738. char *errMsg = 0;
  10739. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10740. if (SQLITE_OK != rc)
  10741. {
  10742. DEBUG_INFO("%s\n",errMsg);
  10743. return FALSE;
  10744. }
  10745. else
  10746. {
  10747. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10748. }
  10749. return TRUE;
  10750. }
  10751. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10752. {
  10753. int isSuccess = FALSE;
  10754. int ret = 0;
  10755. //const char* data = "Callback function called";
  10756. char sql[200];
  10757. char zErrMsg[100];
  10758. memset(sql, 0, 200);
  10759. memset(zErrMsg, 0, 100);
  10760. 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);
  10761. //* Execute SQL statement */
  10762. //zErrMsg = 0;
  10763. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10764. if( ret != SQLITE_OK ){
  10765. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10766. // free(zErrMsg);
  10767. // free(sql);
  10768. return isSuccess;
  10769. }
  10770. DEBUG_INFO("successfully Insert records created\n");
  10771. isSuccess = TRUE;
  10772. return isSuccess;
  10773. }
  10774. void OCPP_deleteIdTag(char *idTag)
  10775. {
  10776. //int ver = 0;
  10777. //int isSuccess = FALSE;
  10778. int rc = 0;
  10779. char sql[100];
  10780. char zErrMsg[100];
  10781. memset(sql, 0, 100);
  10782. memset(zErrMsg, 0, 100);
  10783. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10784. //* Execute SQL statement */
  10785. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10786. if( rc != SQLITE_OK ){
  10787. DEBUG_INFO("SQL error: %s", zErrMsg);
  10788. //sqlite3_free(zErrMsg);
  10789. }else{
  10790. DEBUG_INFO("Operation done successfully");
  10791. }
  10792. }
  10793. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10794. {
  10795. int isSuccess = FALSE;
  10796. int ret = 0;
  10797. const char* data = "Callback function called";
  10798. char sql[200];
  10799. char zErrMsg[100];
  10800. memset(sql, 0, 200);
  10801. memset(zErrMsg, 0, 100);
  10802. //* selectFromTable */
  10803. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10804. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10805. //* Execute SQL statement */
  10806. selectSqlCount = 0;
  10807. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10808. if( ret != SQLITE_OK ){
  10809. printf("Error SQL: %s\n", zErrMsg);
  10810. }
  10811. printf("successfully select operation done\n");
  10812. memset(sql, 0, 200);
  10813. memset(zErrMsg, 0, 100);
  10814. if(selectSqlCount == 0)
  10815. {
  10816. //Insert
  10817. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  10818. 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);
  10819. DEBUG_INFO("sql:%s\n", sql);
  10820. //* Execute SQL statement */
  10821. //zErrMsg = 0;
  10822. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10823. if( ret != SQLITE_OK ){
  10824. printf("SQL error: %s\n", zErrMsg);
  10825. return isSuccess;
  10826. }
  10827. DEBUG_INFO("successfully Insert records created\n");
  10828. isSuccess = TRUE;
  10829. }
  10830. else
  10831. {
  10832. //Update
  10833. //* Create merged SQL statement */
  10834. 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);
  10835. /* Execute SQL statement */
  10836. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10837. if( ret != SQLITE_OK ){
  10838. printf("SQL error: %s\n", zErrMsg);
  10839. //sqlite3_free(zErrMsg);
  10840. //sqlite3_free(sql);
  10841. return isSuccess;
  10842. }
  10843. DEBUG_INFO("Successfully operation done \n");
  10844. isSuccess = TRUE;
  10845. }
  10846. return isSuccess;
  10847. }
  10848. char *GetOcppServerURL()
  10849. {
  10850. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10851. memset(OcppHost, 0, sizeof(OcppHost));
  10852. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10853. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10854. {
  10855. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10856. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10857. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10858. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10859. DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10860. DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10861. DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10862. DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10863. goto End;
  10864. }
  10865. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10866. {
  10867. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10868. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10869. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10870. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10871. DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10872. DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10873. DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10874. DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10875. goto End;
  10876. }
  10877. else
  10878. {
  10879. strcpy(OcppHost,"");
  10880. }
  10881. End:
  10882. return OcppHost;
  10883. }
  10884. char *GetOcppPath()
  10885. {
  10886. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10887. {
  10888. if(OcppTempPath == NULL)
  10889. {
  10890. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10891. }
  10892. else
  10893. {
  10894. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10895. }
  10896. goto End;
  10897. }
  10898. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10899. {
  10900. if(OcppTempPath == NULL)
  10901. {
  10902. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10903. }
  10904. else
  10905. {
  10906. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10907. }
  10908. goto End;
  10909. }
  10910. else
  10911. {
  10912. strcpy(OcppHost,"");
  10913. }
  10914. End:
  10915. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10916. return OcppPath;
  10917. }
  10918. int GetOcppPort()
  10919. {
  10920. return OcppPort;
  10921. }
  10922. int GetOcppConnStatus(void)
  10923. {
  10924. return ShmOCPP16Data->OcppConnStatus;
  10925. }
  10926. void SetOcppConnStatus(uint8_t status)
  10927. {
  10928. ShmOCPP16Data->OcppConnStatus = status;
  10929. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  10930. if(status == FALSE)
  10931. {
  10932. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  10933. {
  10934. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  10935. }
  10936. else
  10937. {
  10938. SystemInitial = AC_QUANTITY;
  10939. }
  10940. }
  10941. }
  10942. #if 0
  10943. void Send(struct json_object *message)
  10944. {
  10945. printf("Send -1 \n");
  10946. printf("message=%s\n",json_object_to_json_string(message));
  10947. LWS_Send(json_object_to_json_string(message));
  10948. }
  10949. #endif
  10950. void LWS_Send(char * str)
  10951. {
  10952. #if 1
  10953. //=====================================================
  10954. // Check InternetConn 0: disconnected, 1: connected
  10955. //====================================================
  10956. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  10957. {
  10958. DEBUG_INFO("\n offline now !!!\n");
  10959. return;
  10960. }
  10961. #endif
  10962. pthread_mutex_lock(&lock);
  10963. memset(SendBuffer,0,SendBufLen);
  10964. sprintf((char *)SendBuffer, "%s", str);
  10965. pthread_mutex_unlock(&lock);
  10966. lws_callback_on_writable(wsi_client);
  10967. lws_service(context, 10000);//timeout_ms
  10968. //usleep(10000); // 等�??��?微�?
  10969. //DEBUG_INFO("Send message end\n");
  10970. }