MessageHandler.c 455 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976
  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[2600]={0};
  79. //===============================
  80. // Configuration: unknownkey
  81. //===============================
  82. static char unknownkey[10][20]={0};
  83. static int UnknownKeynum = 0;
  84. //===============================
  85. // Gun Total Numbers
  86. //===============================
  87. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  88. static int gunTotalNumber=0;
  89. //===============================
  90. // Local List Version
  91. //===============================
  92. static int localversion=0;
  93. static char idTagAuthorization[32]={0};
  94. //===============================
  95. // OCPP Path
  96. //===============================
  97. char OcppPath[160]={};
  98. char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP other variables
  115. //===============================
  116. int isUpdateRequest = FALSE;
  117. static int HeartBeatWaitTime = 10;
  118. static int FirstHeartBeat = 0;
  119. static int FirmwareStatusNotificationStatus = 3; // Idle
  120. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  121. static char CurrentChargingProfileScheduleStr[30]={0};
  122. //========================================
  123. // OCPP status/previous related variables
  124. //========================================
  125. static int GunStatusInterval = 10;
  126. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  127. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  128. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  129. static int GbPreviousSystemStatus[GB_QUANTITY];
  130. static int AcPreviousSystemStatus[AC_QUANTITY];
  131. int TransactionMessageAttemptsValue = 0;
  132. int TransactionMessageRetryIntervalValue = 0;
  133. static struct OCPPAuthLocalElemet
  134. {
  135. int listVersionInt;
  136. char idTagstr[20];
  137. char parentIdTag[20];
  138. char expiryDate[30];
  139. char idTagstatus[16];
  140. }idTagQuery;
  141. //=============================================
  142. // OCPP HeartBeat Response Not Receive Counts
  143. //============================================
  144. static int HeartBeatWithNOResponse = 0;
  145. extern struct lws *wsi_client;
  146. extern struct lws_context *context;
  147. #if 0
  148. extern unsigned char *SendBuffer;
  149. #endif
  150. extern unsigned char SendBuffer[4096];
  151. extern int SendBufLen;
  152. //extern map_t hashMap;
  153. //extern data_struct_t* mapItem; --- remove for temporally
  154. //extern data_struct_t mapItem[0];
  155. extern char *random_uuid( char buf[37] );
  156. extern void split(char **arr, char *str, const char *del);
  157. extern pthread_mutex_t mutex1;
  158. extern struct Charger_Info Charger;
  159. extern sqlite3 *db;
  160. int TransactionMessageAttemptsGet(void);
  161. int TransactionMessageRetryIntervalGet(void);
  162. int GetOcppConnStatus(void);
  163. void SetOcppConnStatus(uint8_t status);
  164. int updateSetting(char *key, char *value);
  165. int setKeyValue(char *key, char *value);
  166. void OCPP_get_TableAuthlocalAllData(void);
  167. void processUnkownKey(void);
  168. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  169. struct StructOCPPMeterValue
  170. {
  171. unsigned char TimeStamp[28];
  172. struct StructSampledValue SampledValue[10];
  173. };
  174. struct ClientTime
  175. {
  176. unsigned int Heartbeat;
  177. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  178. unsigned int StartTransaction;
  179. unsigned int StopTransaction;
  180. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  181. }clientTime;
  182. typedef union
  183. {
  184. //Operations Initiated by Central System
  185. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  186. struct
  187. {
  188. //CsMsgValue[0]
  189. unsigned char StatusNotificationReq :1; //bit 0,
  190. unsigned char StatusNotificationConf :1; //bit 0,
  191. unsigned char :6; //bit 2~7
  192. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  193. }CpinitiateMsg;
  194. CpinitiateMsg cpinitateMsg;
  195. //==========================================
  196. // Init all Enumeration & Mapping String
  197. //==========================================
  198. /*ChargePointErrorCode*/
  199. typedef enum {
  200. ConnectorLockFailure,
  201. EVCommunicationError,
  202. GroundFailure,
  203. HighTemperature,
  204. InternalError,
  205. LocalListConflict,
  206. NoError,
  207. OtherError,
  208. OverCurrentFailure,
  209. OverVoltage,
  210. PowerMeterFailure,
  211. PowerSwitchFailure,
  212. ReaderFailure,
  213. ResetFailure,
  214. UnderVoltage,
  215. WeakSignal
  216. } ChargePointErrorCode;
  217. #if 0
  218. static char *ChargePointErrorCodeStr[] = {
  219. MACROSTR(ConnectorLockFailure),
  220. MACROSTR(EVCommunicationError),
  221. MACROSTR(GroundFailure),
  222. MACROSTR(HighTemperature),
  223. MACROSTR(InternalError),
  224. MACROSTR(LocalListConflict),
  225. MACROSTR(NoError),
  226. MACROSTR(OtherError),
  227. MACROSTR(OverCurrentFailure),
  228. MACROSTR(OverVoltage),
  229. MACROSTR(PowerMeterFailure),
  230. MACROSTR(PowerSwitchFailure),
  231. MACROSTR(ReaderFailure),
  232. MACROSTR(ResetFailure),
  233. MACROSTR(UnderVoltage),
  234. MACROSTR(WeakSignal)
  235. };
  236. #endif
  237. /*ChargePointStatus*/
  238. typedef enum {
  239. Available =0,
  240. Preparing,
  241. Charging,
  242. SuspendedEVSE,
  243. SuspendedEV,
  244. Finishing,
  245. Reserved,
  246. Unavailable,
  247. Faulted
  248. } ChargePointStatus;
  249. static char * ChargePointStatusStr[] = {
  250. MACROSTR(Available),
  251. MACROSTR(Preparing),
  252. MACROSTR(Charging),
  253. MACROSTR(SuspendedEVSE),
  254. MACROSTR(SuspendedEV),
  255. MACROSTR(Finishing),
  256. MACROSTR(Reserved),
  257. MACROSTR(Unavailable),
  258. MACROSTR(Faulted)
  259. };
  260. /*AvailabilityType*/
  261. typedef enum {
  262. RegistrationStatus_Accepted,
  263. RegistrationStatus_Pending,
  264. RegistrationStatus_Rejected
  265. } RegistrationStatus;
  266. static char *RegistrationStatusStr[] = {
  267. MACROSTR(Accepted),
  268. MACROSTR(Pending),
  269. MACROSTR(Rejected)
  270. };
  271. /*AvailabilityType*/
  272. typedef enum {
  273. Inoperative,
  274. Operative
  275. } AvailabilityType;
  276. static char *AvailabilityTypeStr[] = {
  277. MACROSTR(Inoperative),
  278. MACROSTR(Operative)
  279. };
  280. /*AvailabilityStatus*/
  281. typedef enum {
  282. Accepted,
  283. Rejected,
  284. Scheduled
  285. } AvailabilityStatus;
  286. static char *AvailabilityStatusStr[] = {
  287. MACROSTR(Accepted),
  288. MACROSTR(Rejected),
  289. MACROSTR(Scheduled)
  290. };
  291. /*ConfigurationStatus*/
  292. typedef enum {
  293. ConfigurationStatus_Accepted,
  294. ConfigurationStatus_Rejected,
  295. RebootRequired,
  296. NotSupported
  297. } ConfigurationStatus;
  298. static char *ConfigurationStatusStr[] = {
  299. MACROSTR(Accepted),
  300. MACROSTR(Rejected),
  301. MACROSTR(RebootRequired),
  302. MACROSTR(NotSupported)
  303. };
  304. /*ClearCacheStatus*/
  305. typedef enum {
  306. ClearCacheStatus_Accepted,
  307. ClearCacheStatus_Rejected
  308. } ClearCacheStatus;
  309. static char *ClearCacheStatusStr[] = {
  310. MACROSTR(Accepted),
  311. MACROSTR(Rejected)
  312. };
  313. /*ChargingProfilePurposeType*/
  314. typedef enum {
  315. ChargePointMaxProfile,
  316. TxDefaultProfile,
  317. TxProfile
  318. } ChargingProfilePurposeType;
  319. static char *ChargingProfilePurposeTypeStr[] = {
  320. MACROSTR(ChargePointMaxProfile),
  321. MACROSTR(TxDefaultProfile),
  322. MACROSTR(TxProfile)
  323. };
  324. /*ChargingProfileStatus*/
  325. typedef enum {
  326. ChargingProfileStatus_Accepted,
  327. ChargingProfileStatus_Rejected,
  328. ChargingProfileStatus_NotSupported
  329. } ChargingProfileStatus;
  330. static char *ChargingProfileStatusStr[] = {
  331. MACROSTR(Accepted),
  332. MACROSTR(Rejected),
  333. MACROSTR(NotSupported)
  334. };
  335. /*ClearChargingProfileStatus*/
  336. typedef enum {
  337. ClearChargingProfileStatus_Accepted,
  338. ClearChargingProfileStatus_Unknown
  339. } ClearChargingProfileStatus;
  340. static char *ClearChargingProfileStatusStr[] = {
  341. MACROSTR(Accepted),
  342. MACROSTR(Unknown)
  343. };
  344. /*GetCompositeScheduleStatus*/
  345. typedef enum {
  346. GetCompositeScheduleStatus_Accepted,
  347. GetCompositeScheduleStatus_Rejected
  348. } GetCompositeScheduleStatus;
  349. static char *GetCompositeScheduleStatusStr[] = {
  350. MACROSTR(Accepted),
  351. MACROSTR(Rejected)
  352. };
  353. /*ChargingRateUnitType*/
  354. typedef enum {
  355. ChargingRateUnitType_W,
  356. ChargingRateUnitType_A
  357. } ChargingRateUnitType;
  358. /*AuthorizationStatus*/
  359. typedef enum {
  360. AuthorizationStatus_Accepted ,
  361. AuthorizationStatus_Blocked ,
  362. AuthorizationStatus_Expired ,
  363. AuthorizationStatus_Invalid ,
  364. AuthorizationStatus_ConcurrentTx
  365. } AuthorizationStatus;
  366. /*UpdateType*/
  367. typedef enum {
  368. Differential ,
  369. Full
  370. } UpdateType;
  371. static char *UpdateTypeStr[] = {
  372. MACROSTR(Differential),
  373. MACROSTR(Full)
  374. };
  375. /*UpdateStatus*/
  376. typedef enum {
  377. UpdateStatus_Accepted ,
  378. UpdateStatus_Failed ,
  379. UpdateStatus_NotSupported ,
  380. UpdateStatus_VersionMismatch
  381. } UpdateStatus;
  382. static char *UpdateStatusStr[] = {
  383. MACROSTR(Accepted),
  384. MACROSTR(Failed),
  385. MACROSTR(NotSupported),
  386. MACROSTR(VersionMismatch)
  387. };
  388. /*RemoteStartStopStatus*/
  389. typedef enum {
  390. RemoteStartStopStatus_Accepted,
  391. RemoteStartStopStatus_Rejected
  392. } RemoteStartStopStatus;
  393. static char *RemoteStartStopStatusStr[] = {
  394. MACROSTR(Accepted),
  395. MACROSTR(Rejected)
  396. };
  397. /*ReservationStatus*/
  398. typedef enum {
  399. ReservationStatus_Accepted,
  400. ReservationStatus_Faulted,
  401. ReservationStatus_Occupied,
  402. ReservationStatus_Rejected,
  403. ReservationStatus_Unavailable
  404. } ReservationStatus;
  405. static char *ReservationStatusStr[] = {
  406. MACROSTR(Accepted),
  407. MACROSTR(Faulted),
  408. MACROSTR(Occupied),
  409. MACROSTR(Rejected),
  410. MACROSTR(Unavailable)
  411. };
  412. /*ResetType*/
  413. typedef enum {
  414. Hard,
  415. Soft
  416. } ResetType;
  417. static char *ResetTypeStr[] = {
  418. MACROSTR(Hard),
  419. MACROSTR(Soft)
  420. };
  421. /*ResetStatus*/
  422. typedef enum {
  423. ResetStatus_Accepted,
  424. ResetStatus_Rejected
  425. } ResetStatus;
  426. static char *ResetStatusStr[] = {
  427. MACROSTR(Accepted),
  428. MACROSTR(Rejected)
  429. };
  430. /*DiagnosticsStatus*/
  431. typedef enum {
  432. DiagnosticsStatus_Idle,
  433. DiagnosticsStatus_Uploaded,
  434. DiagnosticsStatus_UploadFailed,
  435. DiagnosticsStatus_Uploading
  436. } DiagnosticsStatus;
  437. static char * DiagnosticsStatusStr[] = {
  438. MACROSTR(Idle),
  439. MACROSTR(Uploaded),
  440. MACROSTR(UploadFailed),
  441. MACROSTR(Uploading)
  442. };
  443. /*FirmwareStatus*/
  444. typedef enum {
  445. FirmwareStatus_Downloaded,
  446. FirmwareStatus_DownloadFailed,
  447. FirmwareStatus_Downloading,
  448. FirmwareStatus_Idle,
  449. FirmwareStatus_InstallationFailed,
  450. FirmwareStatus_Installing,
  451. FirmwareStatus_Installed
  452. } FirmwareStatus;
  453. static char * FirmwareStatusStr[] = {
  454. MACROSTR(Downloaded),
  455. MACROSTR(DownloadFailed),
  456. MACROSTR(Downloading),
  457. MACROSTR(Idle),
  458. MACROSTR(InstallationFailed),
  459. MACROSTR(Installing),
  460. MACROSTR(Installed)
  461. };
  462. /*MessageTrigger*/
  463. typedef enum {
  464. BootNotification,
  465. DiagnosticsStatusNotification,
  466. FirmwareStatusNotification,
  467. Heartbeat,
  468. MeterValues,
  469. StatusNotification
  470. } MessageTrigger;
  471. static char * MessageTriggerStr[] = {
  472. MACROSTR(BootNotification),
  473. MACROSTR(DiagnosticsStatusNotification),
  474. MACROSTR(FirmwareStatusNotification),
  475. MACROSTR(Heartbeat),
  476. MACROSTR(MeterValues),
  477. MACROSTR(StatusNotification)
  478. };
  479. /*TriggerMessageStatus*/
  480. typedef enum {
  481. TriggerMessageStatus_Accepted ,
  482. TriggerMessageStatus_Rejected ,
  483. TriggerMessageStatus_NotImplemented
  484. } TriggerMessageStatus;
  485. static char * TriggerMessageStatusStr[] = {
  486. MACROSTR(Accepted),
  487. MACROSTR(Rejected),
  488. MACROSTR(NotImplemented)
  489. };
  490. /*UnlockStatus*/
  491. typedef enum {
  492. Unlocked,
  493. UnlockFailed,
  494. UnlockStatus_NotSupported
  495. } UnlockStatus;
  496. static char * UnlockStatusStr[] = {
  497. MACROSTR(Unlocked),
  498. MACROSTR(UnlockFailed),
  499. MACROSTR(NotSupported)
  500. };
  501. /*StopTransactionReason*/
  502. typedef enum {
  503. EmergencyStop,
  504. EVDisconnected,
  505. HardReset,
  506. Local,
  507. Other,
  508. PowerLoss,
  509. Reboot,
  510. Remote,
  511. SoftReset,
  512. UnlockCommand,
  513. DeAuthorized
  514. } StopTransactionReason;
  515. static char * StopTransactionReasonStr[] = {
  516. MACROSTR(EmergencyStop),
  517. MACROSTR(EVDisconnected),
  518. MACROSTR(HardReset),
  519. MACROSTR(Local),
  520. MACROSTR(Other),
  521. MACROSTR(PowerLoss),
  522. MACROSTR(Reboot),
  523. MACROSTR(Remote),
  524. MACROSTR(SoftReset),
  525. MACROSTR(UnlockCommand),
  526. MACROSTR(DeAuthorized)
  527. };
  528. /*CancelReservationStatus*/
  529. typedef enum {
  530. CancelReservationStatus_Accepted,
  531. CancelReservationStatus_Rejected
  532. } CancelReservationStatus;
  533. static char * CancelReservationStatusStr[] = {
  534. MACROSTR(Accepted),
  535. MACROSTR(Rejected)
  536. };
  537. /*ReadingContext*/
  538. typedef enum {
  539. ReadingContext_Interruption_Begin,
  540. ReadingContext_Interruption_End,
  541. ReadingContext_Other,
  542. ReadingContext_Sample_Clock,
  543. ReadingContext_Sample_Periodic ,
  544. ReadingContext_Transaction_Begin ,
  545. ReadingContext_Transaction_End,
  546. ReadingContext_Trigger
  547. } ReadingContext;
  548. static char * ReadingContextStr[] = {
  549. MACROSTR(Interruption.Begin),
  550. MACROSTR(Interruption.End),
  551. MACROSTR(Other),
  552. MACROSTR(Sample.Clock),
  553. MACROSTR(Sample.Periodic),
  554. MACROSTR(Transaction.Begin),
  555. MACROSTR(Transaction.End),
  556. MACROSTR(Trigger)
  557. };
  558. /*ValueFormat*/
  559. typedef enum {
  560. Raw,
  561. SignedData
  562. } ValueFormat;
  563. static char * ValueFormatStr[] = {
  564. MACROSTR(Raw),
  565. MACROSTR(SignedData)
  566. };
  567. /*Measurand*/
  568. typedef enum {
  569. Current_Export ,
  570. Current_Import,
  571. Current_Offered,
  572. Energy_Active_Export_Register,
  573. Energy_Active_Import_Register,
  574. Energy_Reactive_Export_Register,
  575. Energy_Reactive_Import_Register,
  576. Energy_Active_Export_Interval,
  577. Energy_Active_Import_Interval,
  578. Energy_Reactive_Export_Interval,
  579. Energy_Reactive_Import_Interval,
  580. Frequency,
  581. Power_Active_Export ,
  582. Power_Active_Import,
  583. Power_Factor,
  584. Power_Offered,
  585. Power_Reactive_Export,
  586. Power_Reactive_Import,
  587. RPM,
  588. SoC,
  589. Temperature ,
  590. Voltage
  591. } Measurand;
  592. static char * MeasurandStr[] = {
  593. MACROSTR(Current.Export),
  594. MACROSTR(Current.Import),
  595. MACROSTR(Current.Offered),
  596. MACROSTR(Energy.Active.Export.Register),
  597. MACROSTR(Energy.Active.Import.Register),
  598. MACROSTR(Energy.Reactive.Export.Register),
  599. MACROSTR(Energy.Reactive.Import.Register),
  600. MACROSTR(Energy.Active.Export.Interval),
  601. MACROSTR(Energy.Active.Import.Interval),
  602. MACROSTR(Energy.Reactive.Export.Interval),
  603. MACROSTR(Energy.Reactive.Import.Interval),
  604. MACROSTR(Frequency),
  605. MACROSTR(Power.Active.Export),
  606. MACROSTR(Power.Active.Import),
  607. MACROSTR(Power.Factor),
  608. MACROSTR(Power.Offered),
  609. MACROSTR(Power.Reactive.ExportMACROSTR),
  610. MACROSTR(Power.Reactive.Import),
  611. MACROSTR(RPM),
  612. MACROSTR(SoC),
  613. MACROSTR(Temperature),
  614. MACROSTR(Voltage)
  615. };
  616. /*Location*/
  617. typedef enum {
  618. Location_Body,
  619. Location_Cable,
  620. Location_EV,
  621. Location_Inlet ,
  622. Location_Outlet
  623. } Location;
  624. static char * LocationStr[] = {
  625. MACROSTR(Body),
  626. MACROSTR(Cable),
  627. MACROSTR(EV),
  628. MACROSTR(Inlet),
  629. MACROSTR(Outlet)
  630. };
  631. /*Phase*/
  632. typedef enum {
  633. L1,
  634. L2,
  635. L3,
  636. N,
  637. L1_N,
  638. L2_N,
  639. L3_N,
  640. L1_L2,
  641. L2_L3,
  642. L3_L1
  643. } Phase;
  644. static char * PhaseStr[] = {
  645. MACROSTR(L1),
  646. MACROSTR(L2),
  647. MACROSTR(L3),
  648. MACROSTR(N),
  649. MACROSTR(L1-N),
  650. MACROSTR(L2-N),
  651. MACROSTR(L3-N),
  652. MACROSTR(L1-L2),
  653. MACROSTR(L2-L3),
  654. MACROSTR(L3-L1)
  655. };
  656. /*UnitOfMeasure*/
  657. typedef enum {
  658. UnitOfMeasure_Wh,
  659. UnitOfMeasure_kWh ,
  660. UnitOfMeasure_varh ,
  661. UnitOfMeasure_kvarh ,
  662. UnitOfMeasure_W ,
  663. UnitOfMeasure_kW ,
  664. UnitOfMeasure_VA ,
  665. UnitOfMeasure_kVA ,
  666. UnitOfMeasure_var ,
  667. UnitOfMeasure_kvar ,
  668. UnitOfMeasure_A ,
  669. UnitOfMeasure_V ,
  670. UnitOfMeasure_Celsius ,
  671. UnitOfMeasure_Fahrenheit ,
  672. UnitOfMeasure_K ,
  673. UnitOfMeasure_Percent
  674. } UnitOfMeasure;
  675. static char * UnitOfMeasureStr[] = {
  676. MACROSTR(Wh),
  677. MACROSTR(kWh),
  678. MACROSTR(varh),
  679. MACROSTR(kvarh),
  680. MACROSTR(W),
  681. MACROSTR(kW),
  682. MACROSTR(VA),
  683. MACROSTR(kVA),
  684. MACROSTR(var),
  685. MACROSTR(kvar),
  686. MACROSTR(A),
  687. MACROSTR(V),
  688. MACROSTR(Celsius),
  689. MACROSTR(Fahrenheit),
  690. MACROSTR(K),
  691. MACROSTR(Percent)
  692. };
  693. /*Configuration enum*/
  694. enum CoreProfile {
  695. AllowOfflineTxForUnknownId=0,
  696. AuthorizationCacheEnabled,
  697. AuthorizeRemoteTxRequests,
  698. BlinkRepeat,
  699. ClockAlignedDataInterval,
  700. ConnectionTimeOut,
  701. GetConfigurationMaxKeys,
  702. HeartbeatInterval,
  703. LightIntensity,
  704. LocalAuthorizeOffline,
  705. LocalPreAuthorize,
  706. MaxEnergyOnInvalidId,
  707. MeterValuesAlignedData,
  708. MeterValuesAlignedDataMaxLength,
  709. MeterValuesSampledData,
  710. MeterValuesSampledDataMaxLength,
  711. MeterValueSampleInterval,
  712. MinimumStatusDuration,
  713. NumberOfConnectors,
  714. ResetRetries,
  715. ConnectorPhaseRotation,
  716. ConnectorPhaseRotationMaxLength,
  717. StopTransactionOnEVSideDisconnect,
  718. StopTransactionOnInvalidId,
  719. StopTxnAlignedData,
  720. StopTxnAlignedDataMaxLength,
  721. StopTxnSampledData,
  722. StopTxnSampledDataMaxLength,
  723. SupportedFeatureProfiles,
  724. SupportedFeatureProfilesMaxLength,
  725. TransactionMessageAttempts,
  726. TransactionMessageRetryInterval,
  727. UnlockConnectorOnEVSideDisconnect,
  728. WebSocketPingInterval,
  729. _CoreProfile_CNT
  730. };
  731. enum LocalAuthListManagementProfile{
  732. LocalAuthListEnabled=0,
  733. LocalAuthListMaxLength,
  734. SendLocalListMaxLength,
  735. _LocalAuthListManagementProfile_CNT
  736. };
  737. enum ReservationProfile{
  738. ReserveConnectorZeroSupported
  739. };
  740. enum SmartChargingProfile{
  741. ChargeProfileMaxStackLevel,
  742. ChargingScheduleAllowedChargingRateUnit,
  743. ChargingScheduleMaxPeriods,
  744. ConnectorSwitch3to1PhaseSupported,
  745. MaxChargingProfilesInstalled
  746. };
  747. enum ChargerSystemStatus{
  748. ChargerSystemStatus_Booting,
  749. ChargerSystemStatus_Idle,
  750. ChargerSystemStatus_Authorizing,
  751. ChargerSystemStatus_Preparing,
  752. ChargerSystemStatus_Charging,
  753. ChargerSystemStatus_Terminating,
  754. ChargerSystemStatus_Alarm,
  755. ChargerSystemStatus_Fault
  756. };
  757. enum GetConfigurationKey {
  758. GetConfiguration_AllowOfflineTxForUnknownId=0,
  759. GetConfiguration_AuthorizationCacheEnabled,
  760. GetConfiguration_AuthorizeRemoteTxRequests,
  761. GetConfiguration_BlinkRepeat,
  762. GetConfiguration_ClockAlignedDataInterval,
  763. GetConfiguration_ConnectionTimeOut,
  764. GetConfiguration_GetConfigurationMaxKeys,
  765. GetConfiguration_HeartbeatInterval,
  766. GetConfiguration_LightIntensity,
  767. GetConfiguration_LocalAuthorizeOffline,
  768. GetConfiguration_LocalPreAuthorize,
  769. GetConfiguration_MaxEnergyOnInvalidId,
  770. GetConfiguration_MeterValuesAlignedData,
  771. GetConfiguration_MeterValuesAlignedDataMaxLength,
  772. GetConfiguration_MeterValuesSampledData,
  773. GetConfiguration_MeterValuesSampledDataMaxLength,
  774. GetConfiguration_MeterValueSampleInterval,
  775. GetConfiguration_MinimumStatusDuration,
  776. GetConfiguration_NumberOfConnectors,
  777. GetConfiguration_ResetRetries,
  778. GetConfiguration_ConnectorPhaseRotation,
  779. GetConfiguration_ConnectorPhaseRotationMaxLength,
  780. GetConfiguration_StopTransactionOnEVSideDisconnect,
  781. GetConfiguration_StopTransactionOnInvalidId,
  782. GetConfiguration_StopTxnAlignedData,
  783. GetConfiguration_StopTxnAlignedDataMaxLength,
  784. GetConfiguration_StopTxnSampledData,
  785. GetConfiguration_StopTxnSampledDataMaxLength,
  786. GetConfiguration_SupportedFeatureProfiles,
  787. GetConfiguration_SupportedFeatureProfilesMaxLength,
  788. GetConfiguration_TransactionMessageAttempts,
  789. GetConfiguration_TransactionMessageRetryInterval,
  790. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  791. GetConfiguration_WebSocketPingInterval,
  792. GetConfiguration_LocalAuthListEnabled,
  793. GetConfiguration_LocalAuthListMaxLength,
  794. GetConfiguration_SendLocalListMaxLength,
  795. GetConfiguration_ReserveConnectorZeroSupported,
  796. GetConfiguration_ChargeProfileMaxStackLevel,
  797. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  798. GetConfiguration_ChargingScheduleMaxPeriods,
  799. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  800. GetConfiguration_MaxChargingProfilesInstalled,
  801. };
  802. //GetConfiguration Array
  803. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  804. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  805. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  806. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  807. //==========================================
  808. // Init all share memory
  809. //==========================================
  810. int InitShareMemory()
  811. {
  812. int result = PASS;
  813. int MeterSMId;
  814. //printf("1\n");
  815. //creat ShmSysConfigAndInfo
  816. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  817. {
  818. #ifdef SystemLogMessage
  819. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  820. #endif
  821. result = FAIL;
  822. }
  823. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  824. {
  825. #ifdef SystemLogMessage
  826. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  827. #endif
  828. result = FAIL;
  829. }
  830. else
  831. {}
  832. //printf("2\n");
  833. //creat ShmStatusCodeData
  834. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  835. {
  836. #ifdef SystemLogMessage
  837. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  838. #endif
  839. result = FAIL;
  840. }
  841. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  842. {
  843. #ifdef SystemLogMessage
  844. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  845. #endif
  846. result = FAIL;
  847. }
  848. else
  849. {}
  850. //printf("3\n");
  851. //creat ShmPsuData
  852. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  853. {
  854. #ifdef SystemLogMessage
  855. DEBUG_ERROR("shmget ShmPsuData NG\n");
  856. #endif
  857. result = FAIL;
  858. }
  859. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  860. {
  861. #ifdef SystemLogMessage
  862. DEBUG_ERROR("shmat ShmPsuData NG\n");
  863. #endif
  864. result = FAIL;
  865. }
  866. else
  867. {}
  868. //creat ShmOCPP16Data
  869. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  870. {
  871. #ifdef SystemLogMessage
  872. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  873. #endif
  874. result = FAIL;
  875. }
  876. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  877. {
  878. #ifdef SystemLogMessage
  879. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  880. #endif
  881. result = FAIL;
  882. }
  883. else
  884. {}
  885. /****************************** For Initial Settings************************************************/
  886. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  887. //memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  888. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  889. {
  890. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  891. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  892. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  893. }
  894. // Charger PRE_SYS_MODE
  895. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  896. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  897. clientTime.Heartbeat=time((time_t*)NULL);
  898. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  899. {
  900. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  901. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  902. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  903. }
  904. //HeartBeatWaitTime = 10;
  905. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  907. // allocate Configuration memory address
  908. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  909. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  910. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  911. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  913. {
  914. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  915. DEBUG_INFO("DC ...\n");
  916. }
  917. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  918. {
  919. SystemInitial = AC_QUANTITY;
  920. DEBUG_INFO("AC ...\n");
  921. }
  922. //Status Setting
  923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  924. {
  925. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  926. }
  927. for (int index = 0; index < CCS_QUANTITY; index++)
  928. {
  929. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  930. }
  931. for (int index = 0; index < GB_QUANTITY; index++)
  932. {
  933. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  934. }
  935. for (int index = 0; index < AC_QUANTITY; index++)
  936. {
  937. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  938. }
  939. //memset(unknownkey, 0, 10);
  940. return result;
  941. }
  942. int ProcessShareMemory()
  943. {
  944. if(InitShareMemory() == FAIL)
  945. {
  946. #ifdef SystemLogMessage
  947. DEBUG_ERROR("InitShareMemory NG\n");
  948. #endif
  949. if(ShmStatusCodeData!=NULL)
  950. {
  951. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  952. }
  953. sleep(5);
  954. return FAIL;
  955. }
  956. return PASS;
  957. }
  958. //---------------------------------------------
  959. // new:
  960. // enum SYSTEM_STATUS
  961. // {
  962. // SYS_MODE_BOOTING = 0,
  963. // SYS_MODE_IDLE = 1,
  964. // SYS_MODE_AUTHORIZING = 2,
  965. // SYS_MODE_PREPARING = 3,
  966. // SYS_MODE_CHARGING = 4,
  967. // SYS_MODE_TERMINATING = 5,
  968. // SYS_MODE_ALARM = 6,
  969. // SYS_MODE_FAULT = 7,
  970. // SYS_MODE_RESERVATION = 8,
  971. // SYS_MODE_BOOKING = 9,
  972. // SYS_MODE_MAINTAIN = 10,
  973. // SYS_MODE_DEBUG = 11,
  974. // SYS_MODE_REASSIGN_CHECK = 12,
  975. // SYS_MODE_REASSIGN = 13,
  976. // SYS_MODE_PRECHARGE = 14,
  977. // SYS_MODE_PREPARING_EV = 15,
  978. // SYS_MODE_PREPARING_EVSE = 16,
  979. // SYS_MODE_COMPLETE = 17
  980. // };
  981. //
  982. // old:
  983. // enum _SYSTEM_STATUS
  984. // {
  985. // S_BOOTING = 0,
  986. // S_IDLE, =1
  987. // S_AUTHORIZING, =2
  988. // S_REASSIGN_CHECK, =3
  989. // S_REASSIGN, =4
  990. // S_PRECHARGE, =5
  991. // S_PREPARING_FOR_EV, =6
  992. // S_PREPARING_FOR_EVSE, =7
  993. // S_CHARGING, =8
  994. // S_TERMINATING, =9
  995. // S_COMPLETE, =10
  996. // S_ALARM, =11
  997. // S_FAULT =12
  998. // };
  999. //
  1000. //-----------------------------------------
  1001. void CheckSystemValue(void)
  1002. {
  1003. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1004. int IdleModeCnt = 0;
  1005. char filenmae[100]={0};
  1006. char str[100]={0};
  1007. //===============================
  1008. // send Heartbeat
  1009. //===============================
  1010. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1011. {
  1012. //parameter for test
  1013. sendHeartbeatRequest(0);
  1014. //==============================================
  1015. // Reset Waiting Time
  1016. //==============================================
  1017. clientTime.Heartbeat=time((time_t*)NULL);
  1018. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1019. }
  1020. //==============================================
  1021. // Update firmware request
  1022. //==============================================
  1023. if(isUpdateRequest == TRUE )
  1024. {
  1025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1026. {
  1027. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1028. {
  1029. //check SystemStatus
  1030. /*************************DC*******************************/
  1031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1032. {
  1033. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1034. {
  1035. IdleModeCnt = IdleModeCnt + 1;
  1036. }
  1037. }
  1038. for (int index = 0; index < CCS_QUANTITY; index++)
  1039. {
  1040. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1041. {
  1042. IdleModeCnt = IdleModeCnt + 1;
  1043. }
  1044. }
  1045. for (int index = 0; index < GB_QUANTITY; index++)
  1046. {
  1047. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1048. {
  1049. IdleModeCnt = IdleModeCnt + 1;
  1050. }
  1051. }
  1052. }
  1053. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1054. {
  1055. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1056. isUpdateRequest = FALSE;
  1057. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1058. }
  1059. }
  1060. else
  1061. {
  1062. /*************************AC*******************************/
  1063. for (int index = 0; index < AC_QUANTITY; index++)
  1064. {
  1065. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1066. {
  1067. IdleModeCnt = IdleModeCnt + 1;
  1068. }
  1069. }
  1070. if(IdleModeCnt == AC_QUANTITY)
  1071. {
  1072. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1073. isUpdateRequest = FALSE;
  1074. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1075. }
  1076. }
  1077. }
  1078. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1079. for(int gun_index=0;gun_index < gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY )*/ ;gun_index++)
  1080. {
  1081. //===============================
  1082. // CSU Trigger Reset Conf
  1083. //===============================
  1084. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1085. {
  1086. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1087. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1088. {
  1089. server_sign = FALSE;
  1090. }
  1091. }
  1092. //===============================
  1093. // CSU Trigger Authorize Request
  1094. //===============================
  1095. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1096. {
  1097. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1098. {
  1099. sendAuthorizeRequest(0);
  1100. authorizeRetryTimes = authorizeRetryTimes + 1;
  1101. // authenrequest = TRUE
  1102. if(authorizeRetryTimes < 3)
  1103. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1104. }
  1105. }
  1106. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1107. {
  1108. authorizeRetryTimes = 0;
  1109. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1110. server_sign = FALSE;
  1111. }
  1112. //==============================================
  1113. // Charger start transaction
  1114. //==============================================
  1115. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1116. {
  1117. sendStartTransactionRequest(gun_index);
  1118. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1119. clientTime.StartTransaction = time((time_t*)NULL);
  1120. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1121. }
  1122. //==============================================
  1123. // Charger stop transaction
  1124. //==============================================
  1125. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1126. {
  1127. sendStopTransactionRequest(gun_index);
  1128. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1129. clientTime.StopTransaction = time((time_t*)NULL);
  1130. }
  1131. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1132. //==============================================
  1133. // Charger status report
  1134. //==============================================
  1135. /* Check Mode Change */
  1136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1137. {
  1138. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1139. {
  1140. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1141. {
  1142. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1143. {
  1144. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1145. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1146. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1147. statusModeChage[gun_index] = TRUE;
  1148. }
  1149. }
  1150. }
  1151. for (int index = 0; index < CCS_QUANTITY; index++)
  1152. {
  1153. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1154. {
  1155. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1156. {
  1157. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1158. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1160. statusModeChage[gun_index] = TRUE;
  1161. }
  1162. }
  1163. }
  1164. for (int index = 0; index < GB_QUANTITY; index++)
  1165. {
  1166. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1167. {
  1168. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1169. {
  1170. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1171. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1172. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1173. statusModeChage[gun_index] = TRUE;
  1174. }
  1175. }
  1176. }
  1177. }
  1178. else //AC
  1179. {
  1180. for (int index = 0; index < AC_QUANTITY; index++)
  1181. {
  1182. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1183. {
  1184. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1185. {
  1186. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1187. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1188. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1189. statusModeChage[gun_index] = TRUE;
  1190. }
  1191. }
  1192. }// END OF FOR
  1193. }// END OF ELSE
  1194. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1195. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1196. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1197. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1198. {
  1199. if(SystemInitial != 0)
  1200. SystemInitial = SystemInitial -1;
  1201. //GunStatusInterval= GunStatusInterval* gun_index;
  1202. sendStatusNotificationRequest(gun_index);
  1203. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1204. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1205. statusModeChage[gun_index] = FALSE;
  1206. //sleep(30); // sleep for 30 seconds
  1207. }
  1208. //==============================================
  1209. // Meter report
  1210. //==============================================
  1211. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1212. {
  1213. //check Transaction active
  1214. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1215. {
  1216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1217. {
  1218. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1219. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1220. {
  1221. meterValueSend[gun_index] =1;
  1222. }
  1223. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1224. {
  1225. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1226. if((access(filenmae,F_OK))!=-1)
  1227. {
  1228. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1229. sprintf(str,"rm -f %s",filenmae);
  1230. system(str);
  1231. }
  1232. }
  1233. }// End for CHAdeMO
  1234. for (int index = 0; index < CCS_QUANTITY; index++)
  1235. {
  1236. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1237. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1238. {
  1239. meterValueSend[gun_index] =1;
  1240. }
  1241. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1242. {
  1243. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1244. if((access(filenmae,F_OK))!=-1)
  1245. {
  1246. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1247. sprintf(str,"rm -f %s",filenmae);
  1248. system(str);
  1249. }
  1250. }
  1251. } // End for CCS
  1252. for (int index = 0; index < GB_QUANTITY; index++)
  1253. {
  1254. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1255. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1256. {
  1257. meterValueSend[gun_index] =1;
  1258. }
  1259. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1260. {
  1261. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1262. if((access(filenmae,F_OK))!=-1)
  1263. {
  1264. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1265. sprintf(str,"rm -f %s",filenmae);
  1266. system(str);
  1267. }
  1268. }
  1269. }// End for GB
  1270. }
  1271. else
  1272. {
  1273. for (int index = 0; index < AC_QUANTITY; index++)
  1274. {
  1275. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1276. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1277. {
  1278. meterValueSend[gun_index] =1;
  1279. }
  1280. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1281. {
  1282. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1283. if((access(filenmae,F_OK))!=-1)
  1284. {
  1285. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1286. sprintf(str,"rm -f %s",filenmae);
  1287. system(str);
  1288. }
  1289. }
  1290. }//End for AC
  1291. }//END OF ELSE
  1292. // sleep(1);
  1293. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1294. if(meterValueSend[gun_index] == 1)
  1295. sendMeterValuesRequest(gun_index);
  1296. }
  1297. //==============================================
  1298. // Check Connector reserved
  1299. //==============================================
  1300. //===============================
  1301. // Check if Reserve is expired
  1302. //===============================
  1303. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1304. {
  1305. double diff_t;
  1306. struct tm tp;
  1307. // current time
  1308. time_t t = time(NULL);
  1309. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1310. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1311. tp.tm_isdst = -1;
  1312. time_t utc = mktime(&tp);
  1313. diff_t = difftime(utc, t);
  1314. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1315. if(diff_t <= 0)
  1316. {
  1317. DEBUG_INFO("reserve expired !!! \n");
  1318. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1319. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1320. }
  1321. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1322. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1323. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1324. {
  1325. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1326. }
  1327. else
  1328. {
  1329. //check Transaction active
  1330. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1331. {
  1332. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1333. {
  1334. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1335. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1336. {
  1337. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1338. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1339. {
  1340. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1341. }
  1342. }
  1343. }
  1344. for (int index = 0; index < CCS_QUANTITY; index++)
  1345. {
  1346. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1347. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1348. {
  1349. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1350. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1351. {
  1352. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1353. }
  1354. }
  1355. }
  1356. for (int index = 0; index < GB_QUANTITY; index++)
  1357. {
  1358. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1359. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1360. {
  1361. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1362. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1363. {
  1364. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1365. }
  1366. }
  1367. }
  1368. }
  1369. else //AC
  1370. {
  1371. for (int index = 0; index < AC_QUANTITY; index++)
  1372. {
  1373. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1374. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1375. {
  1376. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1377. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1378. {
  1379. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1380. }
  1381. }
  1382. }
  1383. }// END OF ELSE
  1384. }// END OF check Transaction active
  1385. }//END OF Check if Reserve is expired
  1386. //==========================================
  1387. // csu trigger FirmwareStatusNotificationReq
  1388. //==========================================
  1389. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1390. {
  1391. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1392. }
  1393. //==========================================
  1394. // csu trigger CancelReservationConf
  1395. //==========================================
  1396. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1397. {
  1398. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1399. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1400. }
  1401. //==========================================
  1402. // csu trigger ChangeAvailabilityConf
  1403. //==========================================
  1404. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1405. {
  1406. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1407. }
  1408. //==========================================
  1409. // csu trigger UnlockConnectorConf
  1410. //==========================================
  1411. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1412. {
  1413. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1414. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1415. }
  1416. //==========================================
  1417. // csu trigger ReserveNowConf
  1418. //==========================================
  1419. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1420. {
  1421. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1422. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1423. }
  1424. //==========================================
  1425. // csu trigger DataTransferReq
  1426. //==========================================
  1427. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1428. {
  1429. sendDataTransferRequest(gun_index);
  1430. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1431. }
  1432. }
  1433. }
  1434. //==========================================
  1435. // send request routine
  1436. //==========================================
  1437. int sendAuthorizeRequest(int gun_index)
  1438. {
  1439. mtrace();
  1440. int result = FAIL;
  1441. char message[100]={0};
  1442. char guid[37];
  1443. char tempdata[65]={0};
  1444. DEBUG_INFO("sendAuthorizeRequest \n");
  1445. //Local Authorize
  1446. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1447. {
  1448. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1449. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1450. {
  1451. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1452. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1453. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1454. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1455. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1456. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1457. authorizeRetryTimes = 0;
  1458. return result;
  1459. }
  1460. else
  1461. {
  1462. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1463. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1464. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1465. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1466. result = PASS;
  1467. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1468. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1469. authorizeRetryTimes = 0;
  1470. return result;
  1471. }
  1472. }
  1473. //initailize struct Authorize
  1474. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1475. //get data from shared memory
  1476. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1477. random_uuid(guid);
  1478. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1479. LWS_Send(message);
  1480. sprintf(tempdata, "Authorize,%d", gun_index);
  1481. if(hashmap_operation(0, guid, tempdata) == 1)
  1482. {
  1483. result = PASS;
  1484. DEBUG_ERROR("Authorize mapItem pass\n");
  1485. }
  1486. //#ifdef SystemLogMessage
  1487. //DEBUG_INFO(">>>>>Authorize request\n");
  1488. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1489. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1490. //#endif
  1491. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1492. return result;
  1493. }
  1494. int sendBootNotificationRequest(void)
  1495. {
  1496. mtrace();
  1497. int result = FAIL;
  1498. char message[500]={0}, payload[700]={0};
  1499. char guid[37]={0};
  1500. char tempdata[65]={0};
  1501. int IsGunCharging = FALSE;
  1502. //check Transaction active
  1503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1504. {
  1505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1506. {
  1507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1508. {
  1509. IsGunCharging = TRUE;
  1510. }
  1511. }
  1512. for (int index = 0; index < CCS_QUANTITY; index++)
  1513. {
  1514. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1515. {
  1516. IsGunCharging = TRUE;
  1517. }
  1518. }
  1519. for (int index = 0; index < GB_QUANTITY; index++)
  1520. {
  1521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1522. {
  1523. IsGunCharging = TRUE;
  1524. }
  1525. }
  1526. }
  1527. else
  1528. {
  1529. for (int index = 0; index < AC_QUANTITY; index++)
  1530. {
  1531. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1532. {
  1533. IsGunCharging = TRUE;
  1534. }
  1535. }
  1536. }
  1537. if(IsGunCharging == TRUE)
  1538. {
  1539. server_sign = TRUE;
  1540. return result;
  1541. }
  1542. // Fill BootNotification fields
  1543. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1544. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1545. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1546. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1547. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1548. ShmOCPP16Data->ChargeBoxId
  1549. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1550. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1551. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1552. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1553. ,ShmOCPP16Data->BootNotification.CpIccid
  1554. ,ShmOCPP16Data->BootNotification.CpImsi
  1555. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1556. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1557. random_uuid(guid);
  1558. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1559. LWS_Send(message);
  1560. sprintf(tempdata, "BootNotification,0");
  1561. 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*/)
  1562. {
  1563. result = PASS;
  1564. }
  1565. memset(queuedata, 0, sizeof(queuedata));
  1566. strcpy(queuedata,message);
  1567. //#ifdef SystemLogMessage
  1568. //DEBUG_INFO(">>>>>BootNotification request\n");
  1569. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1570. //#endif
  1571. return result;
  1572. }
  1573. int sendDataTransferRequest(int gun_index)
  1574. {
  1575. mtrace();
  1576. char message[1000]={0};
  1577. char guid[37]={0};
  1578. char tempdata[65]={0};
  1579. int result = FAIL;
  1580. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1581. random_uuid(guid);
  1582. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1583. MESSAGE_TYPE_CALL,
  1584. guid,
  1585. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1586. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1587. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1588. LWS_Send(message);
  1589. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1590. 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*/)
  1591. {
  1592. result = PASS;
  1593. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1594. }
  1595. //#ifdef SystemLogMessage
  1596. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1597. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1598. //#endif
  1599. return result;
  1600. }
  1601. int sendDiagnosticsStatusNotificationRequest(char *status)
  1602. {
  1603. mtrace();
  1604. int result = FAIL;
  1605. char message[110]={0};
  1606. char guid[37]={0};
  1607. char tempdata[65]={0};
  1608. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1609. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1610. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1611. random_uuid(guid);
  1612. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1613. LWS_Send(message);
  1614. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1615. if(hashmap_operation(0, guid, tempdata) == 1)
  1616. {
  1617. result = PASS;
  1618. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1619. }
  1620. //#ifdef SystemLogMessage
  1621. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1622. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1623. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1624. //#endif
  1625. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1626. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1627. //record status
  1628. if(strcmp(status,"Idle")==0)
  1629. {
  1630. DiagnosticsStatusNotificationStatus = 0;
  1631. }
  1632. else if(strcmp(status,"Uploaded")==0)
  1633. {
  1634. DiagnosticsStatusNotificationStatus = 1;
  1635. }
  1636. else if(strcmp(status,"UploadFailed")==0)
  1637. {
  1638. DiagnosticsStatusNotificationStatus = 2;
  1639. }
  1640. else if(strcmp(status,"Uploading")==0)
  1641. {
  1642. DiagnosticsStatusNotificationStatus = 3;
  1643. }
  1644. return result;
  1645. }
  1646. int sendFirmwareStatusNotificationRequest(char *status)
  1647. {
  1648. mtrace();
  1649. int result = FAIL;
  1650. char message[110]={0};
  1651. char guid[37]={0};
  1652. char tempdata[65]={0};
  1653. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1654. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1655. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1656. random_uuid(guid);
  1657. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1658. LWS_Send(message);
  1659. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1660. 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*/)
  1661. {
  1662. result = PASS;
  1663. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1664. }
  1665. //#ifdef SystemLogMessage
  1666. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1667. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1668. //#endif
  1669. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1670. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1671. //record status
  1672. if(strcmp(status,"Downloaded")==0)
  1673. {
  1674. FirmwareStatusNotificationStatus = 0;
  1675. }
  1676. else if(strcmp(status,"DownloadFailed")==0)
  1677. {
  1678. FirmwareStatusNotificationStatus = 1;
  1679. }
  1680. else if(strcmp(status,"Downloading")==0)
  1681. {
  1682. FirmwareStatusNotificationStatus = 2;
  1683. }
  1684. else if(strcmp(status,"Idle")==0)
  1685. {
  1686. FirmwareStatusNotificationStatus = 3;
  1687. }
  1688. else if(strcmp(status,"InstallationFailed")==0)
  1689. {
  1690. FirmwareStatusNotificationStatus = 4;
  1691. }
  1692. else if(strcmp(status,"Installing")==0)
  1693. {
  1694. FirmwareStatusNotificationStatus = 5;
  1695. }
  1696. else if(strcmp(status,"Installed")==0)
  1697. {
  1698. FirmwareStatusNotificationStatus = 6;
  1699. }
  1700. return result;
  1701. }
  1702. int sendHeartbeatRequest(int gun_index)
  1703. {
  1704. mtrace();
  1705. int result = FAIL;
  1706. char message[80]={0};
  1707. char guid[37]={0};
  1708. char tempdata[65]={0};
  1709. random_uuid(guid);
  1710. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1711. , MESSAGE_TYPE_CALL
  1712. , guid );
  1713. LWS_Send(message);
  1714. sprintf(tempdata, "Heartbeat,%d", 0);
  1715. 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*/)
  1716. {
  1717. result = PASS;
  1718. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1719. }
  1720. //#ifdef SystemLogMessage
  1721. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1722. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1723. //#endif
  1724. return result;
  1725. }
  1726. int sendStartTransactionRequest(int gun_index)
  1727. {
  1728. mtrace();
  1729. int result = FAIL;
  1730. char message[250]={0};
  1731. char guid[37]={0};
  1732. struct timeval tmnow;
  1733. struct tm *tm;
  1734. char buf[28];//, usec_buf[6];
  1735. char tempdata[65]={0};
  1736. DEBUG_INFO("sendStartTransactionRequest...");
  1737. gettimeofday(&tmnow, NULL);
  1738. time_t t;
  1739. t = time(NULL);
  1740. /*UTC time and date*/
  1741. tm = gmtime(&t);
  1742. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1743. #if 0 // remove temporally
  1744. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1745. strcat(buf,".");
  1746. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1747. strcat(buf,usec_buf);
  1748. #endif
  1749. //printf("Start Charging Time :%s",buf);
  1750. // set value
  1751. //if(ShmOCPP16Data->OcppConnStatus == 1 )
  1752. //{
  1753. //memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1754. //}
  1755. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1756. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1757. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1759. {
  1760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1761. {
  1762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1763. {
  1764. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1765. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1766. }
  1767. }
  1768. for (int index = 0; index < CCS_QUANTITY; index++)
  1769. {
  1770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1771. {
  1772. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1773. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1774. }
  1775. }
  1776. for (int index = 0; index < GB_QUANTITY; index++)
  1777. {
  1778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1779. {
  1780. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1781. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1782. }
  1783. }
  1784. }
  1785. else
  1786. {
  1787. for (int index = 0; index < AC_QUANTITY; index++)
  1788. {
  1789. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1790. {
  1791. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1792. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1793. }
  1794. }
  1795. }//END OF ELSE
  1796. random_uuid(guid);
  1797. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1798. , MESSAGE_TYPE_CALL
  1799. , guid
  1800. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1801. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1802. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1803. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1804. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1805. LWS_Send(message);
  1806. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1807. 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*/)
  1808. {
  1809. result = PASS;
  1810. }
  1811. strcpy(queuedata, message);
  1812. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1813. //#ifdef SystemLogMessage
  1814. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1815. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1816. //#endif
  1817. return result;
  1818. }
  1819. int sendStatusNotificationRequest(int gun_index)
  1820. {
  1821. mtrace();
  1822. int result = FAIL;
  1823. char message[600]={0};
  1824. char guid[37];
  1825. int currentStatus = 0;
  1826. struct timeval tmnow;
  1827. struct tm *tm;
  1828. char buf[28];//, usec_buf[6];
  1829. char tempdata[65]={0};
  1830. gettimeofday(&tmnow, NULL);
  1831. time_t t;
  1832. t = time(NULL);
  1833. /*UTC time and date*/
  1834. tm = gmtime(&t);
  1835. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1836. #if 0 // remove temporally
  1837. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1838. strcat(buf,".");
  1839. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1840. strcat(buf,usec_buf);
  1841. #endif
  1842. printf("%s",buf);
  1843. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1844. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1845. // it's option
  1846. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1847. /*
  1848. enum _SYSTEM_STATUS
  1849. {
  1850. S_BOOTING = 0,
  1851. S_IDLE, = 1
  1852. S_AUTHORIZING, =2
  1853. S_REASSIGN_CHECK, =3
  1854. S_REASSIGN, =4
  1855. S_PRECHARGE, =5
  1856. S_PREPARING_FOR_EV, =6
  1857. S_PREPARING_FOR_EVSE, =7
  1858. S_CHARGING, =8
  1859. S_TERMINATING, =9
  1860. S_COMPLETE, =10
  1861. S_ALARM, =11
  1862. S_FAULT =12
  1863. }
  1864. */
  1865. //check Transaction active
  1866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1867. {
  1868. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1869. {
  1870. //printf("gun_index=%d\n",gun_index);
  1871. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1872. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1873. {
  1874. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1875. currentStatus = 0; //OCPP Status
  1876. }
  1877. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1878. {
  1879. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1880. currentStatus = 1; //OCPP Status
  1881. }
  1882. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1883. {
  1884. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1885. currentStatus = 2; //OCPP Status
  1886. }
  1887. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1888. {
  1889. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1890. currentStatus = 5; //OCPP Status
  1891. }
  1892. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1893. {
  1894. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1895. currentStatus = 4; //OCPP Status
  1896. }
  1897. 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) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) //S_TERMINATING ---> Unavailable
  1898. {
  1899. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1900. currentStatus = 7; //OCPP Status: Unavailable
  1901. }
  1902. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1903. {
  1904. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1905. currentStatus = 8; //OCPP Status: Faulted
  1906. }
  1907. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1908. {
  1909. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1910. currentStatus = 6; //OCPP Status: Reserved
  1911. }
  1912. }//end of for CHAdeMO_QUANTITY
  1913. for (int index = 0; index < CCS_QUANTITY; index++)
  1914. {
  1915. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1916. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1917. {
  1918. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1919. currentStatus = 0; //OCPP Status
  1920. }
  1921. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1922. {
  1923. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1924. currentStatus = 1; //OCPP Status
  1925. }
  1926. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1927. {
  1928. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1929. currentStatus = 2; //OCPP Status
  1930. }
  1931. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1932. {
  1933. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1934. currentStatus = 5; //OCPP Status
  1935. }
  1936. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1937. {
  1938. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1939. currentStatus = 4; //OCPP Status
  1940. }
  1941. 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) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) //S_TERMINATING ---> Unavailable
  1942. {
  1943. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1944. currentStatus = 7; //OCPP Status
  1945. }
  1946. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1947. {
  1948. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1949. currentStatus = 8; //OCPP Status
  1950. }
  1951. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1952. {
  1953. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1954. currentStatus = 6; //OCPP Status
  1955. }
  1956. }
  1957. for (int index = 0; index < GB_QUANTITY; index++)
  1958. {
  1959. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1960. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1961. {
  1962. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1963. currentStatus = 0; //OCPP Status
  1964. }
  1965. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1966. {
  1967. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1968. currentStatus = 1; //OCPP Status
  1969. }
  1970. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1971. {
  1972. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1973. currentStatus = 2; //OCPP Status
  1974. }
  1975. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1976. {
  1977. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1978. currentStatus = 5; //OCPP Status
  1979. }
  1980. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1981. {
  1982. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1983. currentStatus = 4; //OCPP Status
  1984. }
  1985. 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) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE))) //S_TERMINATING ---> Unavailable
  1986. {
  1987. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1988. currentStatus = 7; //OCPP Status: Unavailable
  1989. }
  1990. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1991. {
  1992. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1993. currentStatus = 8; //OCPP Status: Faulted
  1994. }
  1995. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1996. {
  1997. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1998. currentStatus = 6; //OCPP Status: Faulted
  1999. }
  2000. }
  2001. }
  2002. else
  2003. {
  2004. for (int index = 0; index < AC_QUANTITY; index++)
  2005. {
  2006. //printf("gun_index=%d\n",gun_index);
  2007. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2008. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2009. {
  2010. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2011. currentStatus = 0; //OCPP Status
  2012. }
  2013. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2014. {
  2015. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2016. currentStatus = 1; //OCPP Status
  2017. }
  2018. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2019. {
  2020. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2021. currentStatus = 2; //OCPP Status
  2022. }
  2023. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2024. {
  2025. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2026. currentStatus = 5; //OCPP Status
  2027. }
  2028. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2029. {
  2030. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2031. currentStatus = 4; //OCPP Status
  2032. }
  2033. 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) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) //S_TERMINATING ---> Unavailable
  2034. {
  2035. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2036. currentStatus = 7; //OCPP Status: Unavailable
  2037. }
  2038. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2039. {
  2040. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2041. currentStatus = 8; //OCPP Status: Faulted
  2042. }
  2043. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2044. {
  2045. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2046. currentStatus = 6; //OCPP Status: Reserved
  2047. }
  2048. }//end of for AC_QUANTITY
  2049. }//END OF ELSE
  2050. //it's option
  2051. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2052. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2053. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2054. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2055. random_uuid(guid);
  2056. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2057. , MESSAGE_TYPE_CALL
  2058. , guid
  2059. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2060. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2061. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2062. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2063. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2064. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2065. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2066. LWS_Send(message);
  2067. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2068. 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*/)
  2069. {
  2070. //DEBUG_ERROR("statusNotification mapitem pass");
  2071. result = PASS;
  2072. }
  2073. //#ifdef SystemLogMessage
  2074. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2075. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2076. //#endif
  2077. return result;
  2078. }
  2079. int sendStopTransactionRequest(int gun_index)
  2080. {
  2081. mtrace();
  2082. int result = FAIL;
  2083. //char message[1500]={0};
  2084. char guid[37]={0};
  2085. char tempdata[65]={0};
  2086. //int idx_sample=0;
  2087. DEBUG_ERROR("sendStopTransactionRequest \n");
  2088. memset(queuedata, 0, sizeof(queuedata));
  2089. //ENERGY_ACTIVE_IMPORT_REGISTER
  2090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2091. {
  2092. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2093. {
  2094. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2095. {
  2096. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2097. //Check Status
  2098. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2099. {
  2100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2101. }
  2102. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2103. }
  2104. }// END OF CHAdeMO_QUANTITY
  2105. for (int index = 0; index < CCS_QUANTITY; index++)
  2106. {
  2107. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2108. {
  2109. //for test
  2110. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2111. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2112. //Check Status
  2113. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2114. {
  2115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2116. }
  2117. else
  2118. {
  2119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2120. }
  2121. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2122. }
  2123. }// END OF CCS_QUANTITY
  2124. for (int index = 0; index < GB_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2127. {
  2128. // for test
  2129. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2130. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2131. //Check Status
  2132. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2133. {
  2134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2135. }
  2136. else
  2137. {
  2138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2139. }
  2140. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2141. }
  2142. }// END OF GB_QUANTITY
  2143. }
  2144. else
  2145. {
  2146. for (int index = 0; index < AC_QUANTITY; index++)
  2147. {
  2148. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2149. {
  2150. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2151. //Check Status
  2152. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2153. {
  2154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2155. }
  2156. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2157. }
  2158. }// END OF AC_QUANTITY
  2159. }//END OF ELSE
  2160. //Stop Transaction Time
  2161. struct timeval tmnow;
  2162. struct tm *tm;
  2163. char buf[28];//, usec_buf[6];
  2164. gettimeofday(&tmnow, NULL);
  2165. time_t t;
  2166. t = time(NULL);
  2167. /*UTC time and date*/
  2168. tm = gmtime(&t);
  2169. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2170. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2172. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2173. random_uuid(guid);
  2174. /***********************************transactionData******************************************************/
  2175. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2176. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2177. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2179. //=================================
  2180. // Transaction_Begin
  2181. //=================================
  2182. // Energy.Active.Export.Interval
  2183. //idx_sample=0;
  2184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Export_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2191. //=================================
  2192. // Transaction_End
  2193. //=================================
  2194. //Current.Export
  2195. //idx_sample=1;
  2196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2197. {
  2198. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2199. {
  2200. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2201. {
  2202. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2203. }
  2204. }
  2205. for (int index = 0; index < CCS_QUANTITY; index++)
  2206. {
  2207. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2208. {
  2209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2210. }
  2211. }
  2212. for (int index = 0; index < GB_QUANTITY; index++)
  2213. {
  2214. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2215. {
  2216. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2217. }
  2218. }
  2219. }
  2220. else
  2221. {
  2222. for (int index = 0; index < AC_QUANTITY; index++)
  2223. {
  2224. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2225. {
  2226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2227. }
  2228. }
  2229. }// END FOR AC ELSE
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2236. //Energy.Active.Export.Interval
  2237. //idx_sample=2;
  2238. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2239. {
  2240. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2241. {
  2242. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2243. {
  2244. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2245. }
  2246. }
  2247. for (int index = 0; index < CCS_QUANTITY; index++)
  2248. {
  2249. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2250. {
  2251. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2252. }
  2253. }
  2254. for (int index = 0; index < GB_QUANTITY; index++)
  2255. {
  2256. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2257. {
  2258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2259. }
  2260. }
  2261. }
  2262. else
  2263. {
  2264. for (int index = 0; index < AC_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2267. {
  2268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2269. }
  2270. }
  2271. }// END FOR AC ELSE
  2272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2278. //Power.Active.Export
  2279. //idx_sample=3;
  2280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2281. {
  2282. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2283. {
  2284. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2285. {
  2286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2287. }
  2288. }
  2289. for (int index = 0; index < CCS_QUANTITY; index++)
  2290. {
  2291. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2292. {
  2293. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2294. }
  2295. }
  2296. for (int index = 0; index < GB_QUANTITY; index++)
  2297. {
  2298. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2299. {
  2300. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2301. }
  2302. }
  2303. }
  2304. else
  2305. {
  2306. for (int index = 0; index < AC_QUANTITY; index++)
  2307. {
  2308. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2309. {
  2310. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2311. }
  2312. }
  2313. }// END FOR AC ELSE
  2314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2320. //Voltage
  2321. //idx_sample=4;
  2322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2323. {
  2324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2325. {
  2326. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2327. {
  2328. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  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[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  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[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  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[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2353. }
  2354. }
  2355. }// END FOR AC ELSE
  2356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2362. //SoC
  2363. //idx_sample=5;
  2364. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2365. {
  2366. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2367. {
  2368. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2369. {
  2370. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2371. }
  2372. }
  2373. for (int index = 0; index < CCS_QUANTITY; index++)
  2374. {
  2375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2376. {
  2377. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2378. }
  2379. }
  2380. for (int index = 0; index < GB_QUANTITY; index++)
  2381. {
  2382. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2383. {
  2384. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2385. }
  2386. }
  2387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L1_N]);
  2391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2393. } // END FOR DC CASE
  2394. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2395. {
  2396. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2397. ,MESSAGE_TYPE_CALL
  2398. ,guid
  2399. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2400. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2401. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2404. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2406. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2407. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2409. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2412. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2414. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2415. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2417. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2418. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2420. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2421. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2422. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2423. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2424. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2425. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2426. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2427. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2428. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2429. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2430. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2431. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2432. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2433. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2435. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2436. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2444. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2446. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2447. );
  2448. }
  2449. else
  2450. {
  2451. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2452. ,MESSAGE_TYPE_CALL
  2453. ,guid
  2454. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2455. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2456. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2457. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2458. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2459. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2460. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2461. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2462. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2463. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2464. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2465. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2466. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2467. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2468. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2469. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2470. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2471. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2472. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2473. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2474. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2475. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2476. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2477. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2478. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2479. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2480. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2481. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2482. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2483. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2484. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2485. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2486. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2487. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2488. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2489. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2490. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2491. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2492. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2493. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2494. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2495. );
  2496. }
  2497. LWS_Send(queuedata);
  2498. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2499. if(hashmap_operation(0, guid, tempdata) == 1)
  2500. {
  2501. result = PASS;
  2502. DEBUG_INFO("StopTransaction mapitem pass\n");
  2503. }
  2504. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2505. //for test
  2506. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2507. return result;
  2508. }
  2509. int sendMeterValuesRequest(int gun_index)
  2510. {
  2511. mtrace();
  2512. int result = FAIL;
  2513. // char message[1500]={0};
  2514. char guid[37]={0};
  2515. //int idx_sample=0;
  2516. //int length = 0;
  2517. char tempdata[65]={0};
  2518. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2519. DEBUG_ERROR("gun_index =%d\n",gun_index);
  2520. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2521. {
  2522. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2523. DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2524. DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2525. return result;
  2526. }
  2527. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2528. {
  2529. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2530. }
  2531. memset(queuedata, 0, sizeof(queuedata));
  2532. //set value
  2533. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2534. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2535. random_uuid(guid);
  2536. //UTC Date time
  2537. struct timeval tmnow;
  2538. struct tm *tm;
  2539. char buf[28];//, usec_buf[6];
  2540. gettimeofday(&tmnow, NULL);
  2541. time_t t;
  2542. t = time(NULL);
  2543. /*UTC time and date*/
  2544. tm = gmtime(&t);
  2545. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2547. //idx_sample=0;
  2548. //********************************(1)Current.Export************************************************/
  2549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2550. {
  2551. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2552. {
  2553. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2554. {
  2555. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2556. }
  2557. }
  2558. for (int index = 0; index < CCS_QUANTITY; index++)
  2559. {
  2560. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2561. {
  2562. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2563. }
  2564. }
  2565. for (int index = 0; index < GB_QUANTITY; index++)
  2566. {
  2567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2568. {
  2569. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2570. }
  2571. }
  2572. }
  2573. else
  2574. {
  2575. for (int index = 0; index < AC_QUANTITY; index++)
  2576. {
  2577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2578. {
  2579. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2580. }
  2581. }
  2582. }// END FOR AC ELSE
  2583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2587. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2588. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2589. //idx_sample=1;
  2590. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2591. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2592. {
  2593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2594. {
  2595. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2596. {
  2597. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2598. }
  2599. }
  2600. for (int index = 0; index < CCS_QUANTITY; index++)
  2601. {
  2602. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2603. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2604. {
  2605. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2606. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2607. }
  2608. }
  2609. for (int index = 0; index < GB_QUANTITY; index++)
  2610. {
  2611. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2612. {
  2613. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2614. }
  2615. }
  2616. }
  2617. else
  2618. {
  2619. for (int index = 0; index < AC_QUANTITY; index++)
  2620. {
  2621. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2622. {
  2623. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2624. }
  2625. }
  2626. }//END FOR AC ELSE
  2627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1]);
  2631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2633. //idx_sample=2;
  2634. //********************************(4)Power.Active.Export************************************************/
  2635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2636. {
  2637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2638. {
  2639. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2640. {
  2641. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2642. }
  2643. }
  2644. for (int index = 0; index < CCS_QUANTITY; index++)
  2645. {
  2646. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2647. {
  2648. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2649. }
  2650. }
  2651. for (int index = 0; index < GB_QUANTITY; index++)
  2652. {
  2653. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2654. {
  2655. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2656. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2657. }
  2658. }
  2659. }
  2660. else
  2661. {
  2662. for (int index = 0; index < AC_QUANTITY; index++)
  2663. {
  2664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2665. {
  2666. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2667. }
  2668. }
  2669. }// END FOR AC ELSE
  2670. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2671. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2672. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2673. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2676. //idx_sample=3;
  2677. //***********************************************(5)VOLTAGE******************************************************/
  2678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2679. {
  2680. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2681. {
  2682. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2683. {
  2684. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2685. }
  2686. }
  2687. for (int index = 0; index < CCS_QUANTITY; index++)
  2688. {
  2689. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2690. {
  2691. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2692. }
  2693. }
  2694. for (int index = 0; index < GB_QUANTITY; index++)
  2695. {
  2696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2697. {
  2698. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2699. }
  2700. }
  2701. }
  2702. else
  2703. {
  2704. for (int index = 0; index < AC_QUANTITY; index++)
  2705. {
  2706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2707. {
  2708. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2709. }
  2710. }
  2711. }//END FOR AC ELSE
  2712. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2715. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2719. {
  2720. //idx_sample=4;
  2721. //sampledValue = NULL;
  2722. //***********************************************(6)SOC******************************************************/
  2723. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2724. {
  2725. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2726. {
  2727. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2728. }
  2729. }
  2730. for (int index = 0; index < CCS_QUANTITY; index++)
  2731. {
  2732. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2733. {
  2734. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2735. }
  2736. }
  2737. for (int index = 0; index < GB_QUANTITY; index++)
  2738. {
  2739. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2740. {
  2741. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2742. }
  2743. }
  2744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2746. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2747. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  2748. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2749. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2750. }
  2751. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2752. {
  2753. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2754. ,MESSAGE_TYPE_CALL
  2755. ,guid
  2756. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2757. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2758. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2794. );
  2795. }
  2796. else
  2797. {
  2798. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2799. ,MESSAGE_TYPE_CALL
  2800. ,guid
  2801. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2802. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2803. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2832. );
  2833. }
  2834. LWS_Send(queuedata);
  2835. // Put request guid to hash map
  2836. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2837. 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*/)
  2838. {
  2839. result = PASS;
  2840. DEBUG_INFO("MeterValues mapitem pass\n");
  2841. }
  2842. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2843. return result;
  2844. }
  2845. //==========================================
  2846. // send confirm routine
  2847. //==========================================
  2848. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2849. {
  2850. mtrace();
  2851. int result = FAIL;
  2852. char message[100]={0};
  2853. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2854. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2855. LWS_Send(message);
  2856. result = TRUE;
  2857. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2858. return result;
  2859. }
  2860. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2861. {
  2862. mtrace();
  2863. int result = FAIL;
  2864. char message[100]={0};
  2865. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2866. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2867. LWS_Send(message);
  2868. result = TRUE;
  2869. return result;
  2870. }
  2871. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2872. {
  2873. mtrace();
  2874. int result = FAIL;
  2875. char message[100]={0};
  2876. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2877. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2878. LWS_Send(message);
  2879. result = TRUE;
  2880. return result;
  2881. }
  2882. int sendClearCacheConfirmation(char *uuid,char *payload)
  2883. {
  2884. mtrace();
  2885. int result = FAIL;
  2886. char message[500]={0};
  2887. // int count = 0;
  2888. // int gun_index = 0;
  2889. // char guid[37];
  2890. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2891. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2892. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2893. LWS_Send(message);
  2894. return result;
  2895. }
  2896. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2897. {
  2898. mtrace();
  2899. int result = FAIL;
  2900. char message[500]={0};
  2901. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2902. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2903. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2904. LWS_Send(message);
  2905. return result;
  2906. }
  2907. int sendDataTransferConfirmation(char *uuid,char *payload)
  2908. {
  2909. mtrace();
  2910. char statusStr[20]={0};
  2911. char dataStr[10]={0};
  2912. char sstr[20]={0};
  2913. int c = 0;
  2914. char *loc;
  2915. int result = FAIL;
  2916. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2917. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2918. /**********************status**************************/
  2919. loc = strstr(payload, "status");
  2920. memset(sstr ,0, sizeof(sstr) );
  2921. c = 0;
  2922. while (loc[3+strlen("status")+c] != '\"')
  2923. {
  2924. sstr[c] = loc[3+strlen("status")+c];
  2925. c++;
  2926. }
  2927. sstr[c] = '\0';
  2928. strcpy(statusStr, sstr);
  2929. /**********************data**************************/
  2930. loc = strstr(payload, "data");
  2931. memset(sstr ,0, sizeof(sstr) );
  2932. c = 0;
  2933. while (loc[3+strlen("data")+c] != '\"')
  2934. {
  2935. sstr[c] = loc[3+strlen("data")+c];
  2936. c++;
  2937. }
  2938. sstr[c] = '\0';
  2939. strcpy(dataStr, sstr);
  2940. return result;
  2941. }
  2942. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2943. {
  2944. mtrace();
  2945. int result = FAIL;
  2946. char message[1000]={0};
  2947. double diff_f = 0.0;
  2948. int diff_i = 0;
  2949. int diffSeconds = 0;
  2950. struct tm tp;
  2951. int TimeZero = FALSE;
  2952. int CompositeScheduleIndex = 0;
  2953. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2954. #if 0
  2955. if(connectorIdInt > 0)
  2956. {
  2957. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2958. {
  2959. TimeZero = TRUE;
  2960. }
  2961. else
  2962. {
  2963. strptime((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2964. }
  2965. }
  2966. else
  2967. {
  2968. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2969. {
  2970. TimeZero = TRUE;
  2971. }
  2972. else
  2973. {
  2974. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2975. }
  2976. }
  2977. DEBUG_INFO("ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule=%s\n",ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule);
  2978. #endif
  2979. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2980. {
  2981. TimeZero = TRUE;
  2982. }
  2983. else
  2984. {
  2985. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2986. }
  2987. if(TimeZero == FALSE)
  2988. {
  2989. tp.tm_isdst = -1;
  2990. time_t utc = mktime(&tp);
  2991. time_t t = time(NULL);
  2992. diff_f = difftime(t, utc);
  2993. diff_i = (int)diff_f;
  2994. diffSeconds = diff_i % 86400;//86400 seconds/day
  2995. }
  2996. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2997. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2998. #if 0 //remove temporally
  2999. 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}"
  3000. ,MESSAGE_TYPE_CALLRESULT
  3001. ,uuid
  3002. ,payload
  3003. ,connectorIdInt
  3004. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3005. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3006. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3007. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3008. #endif
  3009. if(nPeriod == 0)
  3010. {
  3011. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3012. ,MESSAGE_TYPE_CALLRESULT
  3013. ,uuid
  3014. ,payload
  3015. ,connectorIdInt
  3016. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3017. }
  3018. else
  3019. {
  3020. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3021. ,MESSAGE_TYPE_CALLRESULT
  3022. ,uuid
  3023. ,payload
  3024. ,connectorIdInt
  3025. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3026. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3027. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3028. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3029. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3030. #if 1 // remove temporally
  3031. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3032. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  3033. {
  3034. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3035. , 0
  3036. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3037. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3038. }
  3039. else
  3040. {
  3041. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3042. {
  3043. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) || (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  3044. {
  3045. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3046. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3047. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3048. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3049. }
  3050. else
  3051. {
  3052. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3053. , (((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  3054. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3055. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3056. }
  3057. }
  3058. }
  3059. #endif
  3060. sprintf(message + strlen(message), "]}}]");
  3061. }
  3062. LWS_Send(message);
  3063. result = TRUE;
  3064. return result;
  3065. }
  3066. int sendGetConfigurationConfirmation(char *uuid)
  3067. {
  3068. mtrace();
  3069. int result = FAIL;
  3070. int MaxKeySupported = 0;
  3071. int sentConfigurationNumber= 0;
  3072. int sentunConfigurationNumber= 0;
  3073. char message[4000]={0};
  3074. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3075. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3076. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3077. ,MESSAGE_TYPE_CALLRESULT
  3078. ,uuid );
  3079. //configuration key
  3080. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3081. {
  3082. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3083. {
  3084. if (sentConfigurationNumber == 0)
  3085. {
  3086. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3087. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3088. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3089. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3090. }
  3091. else
  3092. {
  3093. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3094. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3095. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3096. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3097. }
  3098. sentConfigurationNumber = sentConfigurationNumber + 1;
  3099. }
  3100. }
  3101. sprintf(message + strlen(message), "]");
  3102. if(UnknownKeynum != 0)
  3103. {
  3104. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3105. //unkown key
  3106. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3107. {
  3108. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3109. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3110. if(sentunConfigurationNumber == 0)
  3111. {
  3112. sprintf(message + strlen(message), "\"%s\""
  3113. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3114. }
  3115. else
  3116. {
  3117. sprintf(message + strlen(message), ",\"%s\""
  3118. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3119. }
  3120. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3121. }
  3122. sprintf(message + strlen(message), "]");
  3123. }
  3124. sprintf(message + strlen(message), "} ]");
  3125. LWS_Send(message);
  3126. #if 0
  3127. printf("error 1-0\n");
  3128. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3129. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3130. #endif
  3131. return result;
  3132. }
  3133. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3134. {
  3135. mtrace();
  3136. int result = FAIL;
  3137. char message[400]={0};
  3138. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3139. if(strcmp(payload,"")==0)
  3140. {
  3141. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3142. }
  3143. else
  3144. {
  3145. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3146. }
  3147. LWS_Send(message);
  3148. result = TRUE;
  3149. return result;
  3150. }
  3151. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3152. {
  3153. mtrace();
  3154. int result = FAIL;
  3155. char message[80]={0};
  3156. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3157. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3158. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3159. LWS_Send(message);
  3160. result = TRUE;
  3161. return result;
  3162. }
  3163. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3164. {
  3165. mtrace();
  3166. int result = FAIL;
  3167. char message[80]={0};
  3168. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3169. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3170. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3171. LWS_Send(message);
  3172. result = TRUE;
  3173. return result;
  3174. }
  3175. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3176. {
  3177. mtrace();
  3178. int result = FAIL;
  3179. char message[80]={0};
  3180. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3181. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3182. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3183. LWS_Send(message);
  3184. result = TRUE;
  3185. return result;
  3186. }
  3187. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3188. {
  3189. mtrace();
  3190. int result = FAIL;
  3191. char message[80]={0};
  3192. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3193. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3194. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3195. LWS_Send(message);
  3196. result = TRUE;
  3197. return result;
  3198. }
  3199. int sendResetConfirmation(char *uuid,char *payload)
  3200. {
  3201. mtrace();
  3202. int result = FAIL;
  3203. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3204. char message[80]={0};
  3205. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3206. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3207. LWS_Send(message);
  3208. result = TRUE;
  3209. return result;
  3210. }
  3211. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3212. {
  3213. mtrace();
  3214. int result = FAIL;
  3215. char message[500]={0};
  3216. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3217. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3218. LWS_Send(message);
  3219. result = TRUE;
  3220. return result;
  3221. }
  3222. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3223. {
  3224. mtrace();
  3225. int result = FAIL;
  3226. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3227. char message[80]={0};
  3228. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3229. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3230. LWS_Send(message);
  3231. result = TRUE;
  3232. return result;
  3233. }
  3234. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3235. {
  3236. mtrace();
  3237. int result = FAIL;
  3238. char message[80]={0};
  3239. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3240. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3241. LWS_Send(message);
  3242. result = TRUE;
  3243. return result;
  3244. }
  3245. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3246. {
  3247. mtrace();
  3248. int result = FAIL;
  3249. char message[80]={0};
  3250. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3251. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3252. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3253. LWS_Send(message);
  3254. result = TRUE;
  3255. return result;
  3256. }
  3257. int sendUpdateFirmwareConfirmation(char *uuid)
  3258. {
  3259. mtrace();
  3260. int result = FAIL;
  3261. char message[60]={0};
  3262. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3263. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3264. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3265. LWS_Send(message);
  3266. result = TRUE;
  3267. return result;
  3268. }
  3269. //==========================================
  3270. // send CallError routine
  3271. //==========================================
  3272. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3273. {
  3274. mtrace();
  3275. //int result = FAIL;
  3276. char message[220]={0};
  3277. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3278. #ifdef SystemLogMessage
  3279. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3280. uniqueId, action, errorCode, errorDescription);
  3281. #endif
  3282. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3283. LWS_Send(message);
  3284. //result = TRUE;
  3285. }
  3286. //==========================================
  3287. // Handle server request routine Start
  3288. //==========================================
  3289. #define GUN_NUM 1
  3290. int handleCancelReservationRequest(char *uuid, char *payload)
  3291. {
  3292. mtrace();
  3293. int result = FAIL;
  3294. int gunNO = 0;
  3295. int reservationIdInt =0;
  3296. char comfirmstr[20];
  3297. int c = 0;
  3298. char *loc;
  3299. char sstr[100]={0};
  3300. DEBUG_INFO("handle CancelReservationRequest\n");
  3301. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3302. c = 0;
  3303. loc = strstr(payload, "reservationId");
  3304. memset(sstr ,0, sizeof(sstr) );
  3305. while (loc[strlen("reservationId")+2+c] != '}')
  3306. {
  3307. sstr[c] = loc[strlen("reservationId")+2+c];
  3308. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3309. c++;
  3310. }
  3311. sstr[c] = '\0';
  3312. reservationIdInt = atoi(sstr);
  3313. memset(comfirmstr, 0, sizeof comfirmstr);
  3314. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3315. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3316. //check Transaction active
  3317. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3318. {
  3319. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3320. {
  3321. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3322. {
  3323. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3324. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3325. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3326. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3327. goto end;
  3328. }
  3329. }
  3330. for (int index = 0; index < CCS_QUANTITY; index++)
  3331. {
  3332. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3333. {
  3334. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3335. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3336. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3337. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3338. goto end;
  3339. }
  3340. }
  3341. for (int index = 0; index < GB_QUANTITY; index++)
  3342. {
  3343. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3344. {
  3345. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3346. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3347. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3348. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3349. goto end;
  3350. }
  3351. }
  3352. }
  3353. else
  3354. {
  3355. for (int index = 0; index < AC_QUANTITY; index++)
  3356. {
  3357. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3358. {
  3359. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3360. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3361. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3362. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3363. goto end;
  3364. }
  3365. }
  3366. }// END FOR AC ELSE
  3367. //The reservationId does NOT match the reservationId
  3368. sendCancelReservationConfirmation(uuid, comfirmstr);
  3369. end:
  3370. // Fill in ocpp packet uuid
  3371. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3372. return result;
  3373. }
  3374. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3375. {
  3376. mtrace();
  3377. int result = FAIL;
  3378. int gunIndex = 0;
  3379. char sstr[90]={0};
  3380. char typeStr[16]={0};
  3381. char comfirmstr[20];
  3382. int specificId = FALSE;
  3383. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3384. char *loc;
  3385. //int intervalInt = 0;
  3386. int c = 0;
  3387. /*** connectorId ****/
  3388. c = 0;
  3389. loc = strstr(payload, "connectorId");
  3390. memset(sstr ,0, sizeof(sstr) );
  3391. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3392. {
  3393. sstr[c] = loc[strlen("connectorId")+2+c];
  3394. c++;
  3395. }
  3396. sstr[c] = '\0';
  3397. gunIndex = atoi(sstr);
  3398. /***type ****/
  3399. loc = strstr(payload, "type");
  3400. memset(sstr ,0, sizeof(sstr) );
  3401. c = 0;
  3402. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3403. {
  3404. sstr[c] = loc[3+strlen("type")+c];
  3405. c++;
  3406. }
  3407. sstr[c] = '\0';
  3408. strcpy(typeStr, sstr);
  3409. if(gunIndex != 0)
  3410. {
  3411. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3412. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3413. }
  3414. else
  3415. {
  3416. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3417. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3418. }
  3419. memset(comfirmstr, 0, sizeof comfirmstr);
  3420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3421. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3422. {
  3423. specificId = TRUE;
  3424. }
  3425. if(specificId == FALSE)
  3426. goto end;
  3427. if(gunIndex != 0)
  3428. {
  3429. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3430. }
  3431. else
  3432. {
  3433. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3434. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3435. }
  3436. /*
  3437. enum _SYSTEM_STATUS
  3438. {
  3439. S_BOOTING = 0,
  3440. S_IDLE, = 1
  3441. S_AUTHORIZING, =2
  3442. S_REASSIGN_CHECK, =3
  3443. S_REASSIGN, =4
  3444. S_PRECHARGE, =5
  3445. S_PREPARING_FOR_EV, =6
  3446. S_PREPARING_FOR_EVSE, =7
  3447. S_CHARGING, =8
  3448. S_TERMINATING, =9
  3449. S_COMPLETE, =10
  3450. S_ALARM, =11
  3451. S_FAULT =12
  3452. }
  3453. */
  3454. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3455. {
  3456. //check Transaction active
  3457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3458. {
  3459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3460. {
  3461. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3462. {
  3463. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3464. {
  3465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3466. }
  3467. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3468. {
  3469. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3470. }
  3471. else
  3472. {
  3473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3474. }
  3475. goto end;
  3476. }
  3477. }//END FOR CHAdeMO_QUANTITY
  3478. for (int index = 0; index < CCS_QUANTITY; index++)
  3479. {
  3480. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3481. {
  3482. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3483. {
  3484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3485. }
  3486. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3487. {
  3488. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3489. }
  3490. else
  3491. {
  3492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3493. }
  3494. goto end;
  3495. }
  3496. }//END FOR CCS_QUANTITY
  3497. for (int index = 0; index < GB_QUANTITY; index++)
  3498. {
  3499. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3500. {
  3501. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3502. {
  3503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3504. }
  3505. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3506. {
  3507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3508. }
  3509. else
  3510. {
  3511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3512. }
  3513. goto end;
  3514. }
  3515. }// END FOR GB_QUANTITY
  3516. }
  3517. else
  3518. {
  3519. for (int index = 0; index < AC_QUANTITY; index++)
  3520. {
  3521. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3522. {
  3523. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3524. {
  3525. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3526. }
  3527. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3528. {
  3529. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3530. }
  3531. else
  3532. {
  3533. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3534. }
  3535. goto end;
  3536. }
  3537. }//END FOR AC_QUANTITY
  3538. }// END FOR AC ELSE
  3539. }//END FOR AvailabilityTypeStr[Inoperative]
  3540. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3541. {
  3542. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3543. //check Transaction active
  3544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3545. {
  3546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3547. {
  3548. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3549. {
  3550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3551. goto end;
  3552. }
  3553. }//END FOR CHAdeMO_QUANTITY
  3554. for (int index = 0; index < CCS_QUANTITY; index++)
  3555. {
  3556. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3557. {
  3558. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3559. goto end;
  3560. }
  3561. }//END FOR CCS_QUANTITY
  3562. for (int index = 0; index < GB_QUANTITY; index++)
  3563. {
  3564. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3565. {
  3566. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3567. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3568. goto end;
  3569. }
  3570. }// END FOR GB_QUANTITY
  3571. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3572. }
  3573. else
  3574. {
  3575. for (int index = 0; index < AC_QUANTITY; index++)
  3576. {
  3577. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3578. {
  3579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3580. goto end;
  3581. }
  3582. }//END FOR CHAdeMO_QUANTITY
  3583. }//END FOR AC ELSE
  3584. }//END FOR AvailabilityTypeStr[Operative]
  3585. end:
  3586. if(gunIndex != 0)
  3587. {
  3588. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3589. }
  3590. else
  3591. {
  3592. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3593. }
  3594. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3595. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3596. return result;
  3597. }
  3598. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3599. {
  3600. mtrace();
  3601. int result = FAIL;
  3602. char sstr[100]={0};
  3603. char keystr[40]={0};
  3604. char valuestr[16]={0};
  3605. char *loc;
  3606. int c = 0;
  3607. char comfirmstr[20];
  3608. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3609. /***key ****/
  3610. loc = strstr(payload, "key");
  3611. memset(sstr ,0, sizeof(sstr) );
  3612. c = 0;
  3613. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3614. {
  3615. sstr[c] = loc[3+strlen("key")+c];
  3616. c++;
  3617. }
  3618. sstr[c] = '\0';
  3619. strcpy(keystr, sstr);
  3620. /***value ****/
  3621. loc = strstr(payload, "value");
  3622. memset(sstr ,0, sizeof(sstr) );
  3623. c = 0;
  3624. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3625. {
  3626. sstr[c] = loc[3+strlen("value")+c];
  3627. c++;
  3628. }
  3629. sstr[c] = '\0';
  3630. strcpy(valuestr, sstr);
  3631. if((uuid==NULL) || (payload ==NULL) )
  3632. {
  3633. #ifdef Debug
  3634. DEBUG_INFO("payload is null\n");
  3635. #endif
  3636. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3637. }
  3638. else
  3639. {
  3640. int status = setKeyValue(keystr, valuestr);
  3641. switch(status)
  3642. {
  3643. case ConfigurationStatus_Accepted:
  3644. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3645. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3646. break;
  3647. case ConfigurationStatus_Rejected:
  3648. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3649. break;
  3650. case RebootRequired:
  3651. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3652. break;
  3653. case NotSupported:
  3654. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3655. break;
  3656. default:
  3657. break;
  3658. }
  3659. }
  3660. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3661. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3662. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3663. return result;
  3664. }
  3665. int handleClearCacheRequest(char *uuid, char *payload)
  3666. {
  3667. mtrace();
  3668. int result = FAIL;
  3669. char comfirmstr[20];
  3670. int fd;
  3671. char rmFileCmd[100]={0};
  3672. struct stat stats;
  3673. DEBUG_ERROR("handle ClearCacheRequest\n");
  3674. stat("../Storage/OCPP", &stats);
  3675. // Check for directory existence
  3676. if (S_ISDIR(stats.st_mode) == 1)
  3677. {
  3678. //DEBUG_ERROR("\n OCPP directory exist \n");
  3679. }
  3680. else
  3681. {
  3682. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3683. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3684. system(rmFileCmd);
  3685. }
  3686. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3687. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3688. {
  3689. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3690. }
  3691. else
  3692. {
  3693. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3694. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3695. if(log == NULL)
  3696. {
  3697. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3698. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3699. goto end;
  3700. }
  3701. else
  3702. {
  3703. fclose(log);
  3704. }
  3705. }
  3706. fd = open(AuthorizationCache_JSON,O_RDWR);
  3707. if(fd < 0)
  3708. {
  3709. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3710. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3711. }
  3712. else
  3713. {
  3714. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3715. //* 清空?�件 */
  3716. ftruncate(fd,0);
  3717. //* ?�新设置?�件?�移??*/
  3718. lseek(fd,0,SEEK_SET);
  3719. close(fd);
  3720. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3721. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3722. }
  3723. end:
  3724. sendClearCacheConfirmation(uuid, comfirmstr);
  3725. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3726. return result;
  3727. }
  3728. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3729. {
  3730. mtrace();
  3731. int result = FAIL;
  3732. int resultRename;
  3733. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3734. char chargingProfilePurposeStr[26]={0};
  3735. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3736. char tempchargingProfilePurposeStr[26]={0};
  3737. char sstr[160]={0};//sstr[200]={ 0 };
  3738. char str[100]={0};
  3739. int c = 0;
  3740. //int i = 0;
  3741. //char * pch;
  3742. char *loc;
  3743. char fname[200];
  3744. char comfirmstr[20]={0};
  3745. char word[1000]={0};
  3746. int clearflag = FALSE;
  3747. int chargingProfileIdIsNULL = FALSE;
  3748. int connectorIsNULL = FALSE;
  3749. int chargingProfilePurposeIsNULL = FALSE;
  3750. int stackLevelIsNULL = FALSE;
  3751. FILE *fptr1, *fptr2;
  3752. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3753. int n_chargingProfile=0;
  3754. char sLineWord[1060]={0};
  3755. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3756. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3757. //***id ****/
  3758. c = 0;
  3759. loc = strstr(payload, "id");
  3760. memset(sstr ,0, sizeof(sstr) );
  3761. if(loc == NULL)
  3762. {
  3763. chargingProfileIdIsNULL = TRUE;
  3764. }
  3765. else
  3766. {
  3767. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3768. {
  3769. sstr[c] = loc[strlen("id")+2+c];
  3770. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3771. c++;
  3772. }
  3773. sstr[c] = '\0';
  3774. chargingProfileIdInt = atoi(sstr);
  3775. }
  3776. //***connectorId ****/
  3777. c=0;
  3778. loc = strstr(payload, "connectorId");
  3779. memset(sstr ,0, sizeof(sstr) );
  3780. if(loc == NULL)
  3781. {
  3782. connectorIsNULL = TRUE;
  3783. }
  3784. else
  3785. {
  3786. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3787. {
  3788. sstr[c] = loc[strlen("connectorId")+2+c];
  3789. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3790. c++;
  3791. }
  3792. sstr[c] = '\0';
  3793. connectorIdInt = atoi(sstr);
  3794. }
  3795. //***chargingProfilePurpose ****/
  3796. loc = strstr(payload, "chargingProfilePurpose");
  3797. memset(sstr ,0, sizeof(sstr) );
  3798. c = 0;
  3799. if(loc == NULL)
  3800. {
  3801. chargingProfilePurposeIsNULL = TRUE;
  3802. }
  3803. else
  3804. {
  3805. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3806. {
  3807. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3808. c++;
  3809. }
  3810. sstr[c] = '\0';
  3811. strcpy(chargingProfilePurposeStr, sstr);
  3812. }
  3813. //***stackLevel ****/
  3814. c=0;
  3815. loc = strstr(payload, "stackLevel");
  3816. memset(sstr ,0, sizeof(sstr) );
  3817. if(loc == NULL)
  3818. {
  3819. stackLevelIsNULL = TRUE;
  3820. }
  3821. else
  3822. {
  3823. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3824. {
  3825. sstr[c] = loc[strlen("stackLevel")+2+c];
  3826. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3827. c++;
  3828. }
  3829. sstr[c] = '\0';
  3830. stackLevelInt = atoi(sstr);
  3831. }
  3832. if(connectorIsNULL == FALSE)
  3833. {
  3834. switch(connectorIdInt)
  3835. {
  3836. case 0:
  3837. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3838. {
  3839. strcpy(fname, ChargePointMaxProfile_JSON);
  3840. }
  3841. // else
  3842. // {
  3843. // strcpy(fname, TxDefaultProfile_0_JSON);
  3844. // }
  3845. break;
  3846. case 1:
  3847. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3848. {
  3849. strcpy(fname, TxDefaultProfile_1_JSON);
  3850. }
  3851. // else
  3852. // {
  3853. // strcpy(fname, TxProfile_1_JSON);
  3854. // }
  3855. break;
  3856. case 2:
  3857. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3858. {
  3859. strcpy(fname, TxDefaultProfile_2_JSON);
  3860. }
  3861. // else
  3862. // {
  3863. // strcpy(fname, TxProfile_2_JSON);
  3864. // }
  3865. break;
  3866. default:
  3867. strcpy(fname, ChargePointMaxProfile_JSON );
  3868. break;
  3869. }
  3870. }
  3871. else
  3872. {
  3873. strcpy(fname, ChargePointMaxProfile_JSON );
  3874. }
  3875. fptr1 = fopen(fname, "r");
  3876. if (!fptr1)
  3877. {
  3878. //file not exist
  3879. DEBUG_ERROR("Unable to open the input file!!\n");
  3880. fptr1 = fopen(fname, "w+");
  3881. }
  3882. fclose(fptr1);
  3883. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3884. {
  3885. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3886. goto end;
  3887. }
  3888. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3889. {
  3890. //clear the whole contents of a file in C
  3891. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3892. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3893. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3894. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3895. fclose(fopen(TxProfile_1_JSON, "w"));
  3896. fclose(fopen(TxProfile_2_JSON, "w"));
  3897. #if 0
  3898. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3899. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3900. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3901. #endif
  3902. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3903. }
  3904. else
  3905. {
  3906. fptr1 = fopen(fname, "r");
  3907. fptr2 = fopen(temp, "w+");
  3908. while(fscanf(fptr1, "%s", word) != EOF)
  3909. {
  3910. //DEBUG_INFO("word=%s\n",word);
  3911. if(strcmp(word, "chargingProfileId") == 0)
  3912. {
  3913. n_chargingProfile = n_chargingProfile + 1;
  3914. DEBUG_INFO("chargingProfileId Found\n");
  3915. }
  3916. }
  3917. rewind(fptr1);
  3918. //search Charging Profile Element
  3919. //int i= 0;
  3920. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3921. {
  3922. //*************************tempconnectorIdInt*********************************/
  3923. loc = strstr(sLineWord, "connectorId");
  3924. c = 0;
  3925. memset(sstr ,0, sizeof(sstr) );
  3926. while (loc[strlen("connectorId")+2+c] != ',')
  3927. {
  3928. sstr[c] = loc[strlen("connectorId")+2+c];
  3929. c++;
  3930. }
  3931. sstr[c] = '\0';
  3932. tempconnectorIdInt = atoi(sstr);
  3933. //chargingProfileId
  3934. c = 0;
  3935. loc = strstr(sLineWord, "chargingProfileId");
  3936. memset(sstr ,0, sizeof(sstr) );
  3937. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3938. {
  3939. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3940. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3941. c++;
  3942. }
  3943. sstr[c] = '\0';
  3944. tempchargingProfileIdInt = atoi(sstr);
  3945. //stackLevel
  3946. c = 0;
  3947. loc = strstr(sLineWord, "stackLevel");
  3948. memset(sstr ,0, sizeof(sstr) );
  3949. while (loc[strlen("stackLevel")+2+c] != ',')
  3950. {
  3951. sstr[c] = loc[strlen("stackLevel")+2+c];
  3952. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3953. c++;
  3954. }
  3955. sstr[c] = '\0';
  3956. tempstackLevelInt = atoi(sstr);
  3957. c = 0;
  3958. loc = strstr(sLineWord, "chargingProfilePurpose");
  3959. memset(sstr ,0, sizeof(sstr) );
  3960. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3961. {
  3962. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3963. c++;
  3964. }
  3965. sstr[c] = '\0';
  3966. strcpy(tempchargingProfilePurposeStr, sstr);
  3967. if(chargingProfileIdIsNULL == FALSE)
  3968. {
  3969. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3970. {
  3971. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3972. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3973. clearflag = TRUE;
  3974. continue;
  3975. }
  3976. else
  3977. {
  3978. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3979. //json_object_array_add(newHeatMap, jsonitem);
  3980. fprintf(fptr2, sLineWord);//writing data into file
  3981. }
  3982. }
  3983. else
  3984. {
  3985. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3986. {
  3987. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3988. {
  3989. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3990. clearflag = TRUE;
  3991. continue;
  3992. }
  3993. }
  3994. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3995. {
  3996. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3997. {
  3998. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3999. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  4000. {
  4001. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4002. clearflag = TRUE;
  4003. continue;
  4004. }
  4005. }
  4006. }
  4007. else
  4008. {
  4009. //json_object_array_add(newHeatMap, jsonitem);
  4010. fprintf(fptr2, sLineWord);//writing data into file
  4011. }
  4012. }
  4013. memset(sLineWord, 0, sizeof sLineWord);
  4014. }
  4015. if(clearflag == FALSE)
  4016. {
  4017. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4018. goto end;
  4019. }
  4020. fclose(fptr1);
  4021. fclose(fptr2);
  4022. sprintf(str,"rm -f %s",fname);
  4023. system(str);
  4024. resultRename = rename(temp, fname);
  4025. if(resultRename == 0)
  4026. {
  4027. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4028. }
  4029. else
  4030. {
  4031. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4032. }
  4033. }
  4034. end:
  4035. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4036. return result;
  4037. }
  4038. int handleDataTransferRequest(char *uuid, char *payload)
  4039. {
  4040. mtrace();
  4041. int result = FAIL;
  4042. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4043. char tempvendorId[255]={0};
  4044. char tempmessageId[50]={0};
  4045. char tempdata[50]={0};
  4046. char sstr[160]={0};//sstr[200]={ 0 };
  4047. char message[80]={0};
  4048. int c = 0;
  4049. char *loc;
  4050. DEBUG_INFO("handle DataTransferRequest\n");
  4051. if((uuid != NULL) && (payload != NULL))
  4052. {
  4053. //===============================
  4054. // vendorId
  4055. //===============================
  4056. c = 0;
  4057. loc = strstr(payload, "vendorId");
  4058. while (loc[strlen("vendorId")+3+c] != '\"')
  4059. {
  4060. sstr[c] = loc[strlen("vendorId")+3+c];
  4061. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4062. c++;
  4063. }
  4064. sstr[c] = '\0';
  4065. strcpy(tempvendorId,sstr);
  4066. //===============================
  4067. // messageId
  4068. //===============================
  4069. memset(sstr ,0, sizeof(sstr) );
  4070. c = 0;
  4071. loc = strstr(payload, "messageId");
  4072. while (loc[strlen("messageId")+3+c] != '\"')
  4073. {
  4074. sstr[c] = loc[strlen("messageId")+3+c];
  4075. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4076. c++;
  4077. }
  4078. sstr[c] = '\0';
  4079. strcpy(tempmessageId,sstr);
  4080. //===============================
  4081. // data
  4082. //===============================
  4083. memset(sstr ,0, sizeof(sstr) );
  4084. c = 0;
  4085. loc = strstr(payload, "data");
  4086. printf("loc=%s\n",loc);
  4087. while (loc[strlen("data")+3+c] != '\"')
  4088. {
  4089. sstr[c] = loc[strlen("data")+3+c];
  4090. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4091. c++;
  4092. }
  4093. sstr[c] = '\0';
  4094. strcpy(tempdata,sstr);
  4095. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4096. }
  4097. else
  4098. {
  4099. char guid[37]={0};
  4100. random_uuid(guid);
  4101. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4102. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4103. }
  4104. LWS_Send(message);
  4105. return result;
  4106. }
  4107. #if 0
  4108. long long diff_tm(struct tm *a, struct tm *b) {
  4109. return a->tm_sec - b->tm_sec
  4110. + 60LL * (a->tm_min - b->tm_min)
  4111. + 3600LL * (a->tm_hour - b->tm_hour)
  4112. + 86400LL * (a->tm_yday - b->tm_yday)
  4113. + (a->tm_year - 70) * 31536000LL
  4114. - (a->tm_year - 69) / 4 * 86400LL
  4115. + (a->tm_year - 1) / 100 * 86400LL
  4116. - (a->tm_year + 299) / 400 * 86400LL
  4117. - (b->tm_year - 70) * 31536000LL
  4118. + (b->tm_year - 69) / 4 * 86400LL
  4119. - (b->tm_year - 1) / 100 * 86400LL
  4120. + (b->tm_year + 299) /400 * 86400LL;
  4121. }
  4122. #endif
  4123. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4124. {
  4125. mtrace();
  4126. int result = FAIL;
  4127. int connectorIdInt, durationInt;
  4128. char chargingRateUnitStr[4]={0};
  4129. //int tempconnectorIdInt,
  4130. int tempdurationInt;
  4131. float tempminChargingRateFloat = 0.0;
  4132. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4133. int tempStartPeriodInt=0;
  4134. float tempLimitInt=0.0;//0.1;
  4135. int tempNumberPhasesInt=0;
  4136. char fname[200];
  4137. char comfirmstr[20];
  4138. //float totallimit =0.0;
  4139. float MinChargingRate =0.0;
  4140. double diff_t;
  4141. struct tm tp;
  4142. //int clearflag = FALSE;
  4143. FILE *fptr1;//, *fptr2;
  4144. //char temp[] = "../Storage/OCPP/temp.json";
  4145. int c = 0;
  4146. //int i = 0;
  4147. char * pch;
  4148. char *loc;
  4149. char sstr[200]={ 0 };
  4150. int n_chargingProfile = 0;
  4151. int n_SchedulePeriods = 0;
  4152. char SchedulePeriodList[10][200]={0};
  4153. char sLineWord[800]={0};
  4154. //int n_periods = 0;
  4155. char word[1000]={0};
  4156. int confirmPeriods = 0;
  4157. struct StructProfile ChargePointMaxProfile;
  4158. struct StructProfile TxDefaultProfile;
  4159. struct StructProfile TxProfile;
  4160. struct StructProfile TxDefaultProfiletemp[2]={0};
  4161. int TxDefaultProfileFileIsNull=FALSE;
  4162. int ChargePointMaxProfileIsNull=FALSE;
  4163. int TxProfileIsNull=FALSE;
  4164. int CompositeSceduleIndex = 0;
  4165. char ChargePointMaxProfileScheduleStr[30]={0};
  4166. char TxDefaultProfileScheduleStr[30]={0};
  4167. char TxProfileScheduleStr[30]={0};
  4168. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4169. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4170. memset(&TxProfile,0,sizeof(struct StructProfile));
  4171. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4172. c=0;
  4173. loc = strstr(payload, "connectorId");
  4174. memset(sstr ,0, sizeof(sstr) );
  4175. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4176. {
  4177. sstr[c] = loc[strlen("connectorId")+2+c];
  4178. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4179. c++;
  4180. }
  4181. sstr[c] = '\0';
  4182. connectorIdInt = atoi(sstr);
  4183. c=0;
  4184. loc = strstr(payload, "duration");
  4185. memset(sstr ,0, sizeof(sstr) );
  4186. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4187. {
  4188. sstr[c] = loc[strlen("duration")+2+c];
  4189. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4190. c++;
  4191. }
  4192. sstr[c] = '\0';
  4193. durationInt = atoi(sstr);
  4194. c = 0;
  4195. loc = strstr(payload, "chargingRateUnit");
  4196. memset(sstr ,0, sizeof(sstr) );
  4197. if(loc == NULL)
  4198. {
  4199. }
  4200. else
  4201. {
  4202. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4203. {
  4204. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4205. c++;
  4206. }
  4207. sstr[c] = '\0';
  4208. strcpy(chargingRateUnitStr, sstr);
  4209. }
  4210. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4211. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4212. if(connectorIdInt==0) // connectorId is 0
  4213. {
  4214. //******************************ChargePointMaxProfile*****************************************************/
  4215. strcpy(fname, ChargePointMaxProfile_JSON );
  4216. char word[30]={0};
  4217. char sLineWord[1060]={0};
  4218. int n_chargingProfile=0;
  4219. ChargePointMaxProfileIsNull=TRUE;
  4220. if((access(fname,F_OK))!=-1)
  4221. {
  4222. fptr1 = fopen(fname, "r");
  4223. int c;
  4224. c = fgetc(fptr1);
  4225. //DEBUG_INFO("c:%d\n",c);
  4226. rewind(fptr1);
  4227. if(c == EOF)
  4228. {
  4229. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4230. ChargePointMaxProfileIsNull=TRUE;
  4231. fclose(fptr1);
  4232. }
  4233. else
  4234. {
  4235. ChargePointMaxProfileIsNull=FALSE;
  4236. while(fscanf(fptr1, "%s", word) != EOF)
  4237. {
  4238. if(strcmp(word, "chargingProfileId") == 0)
  4239. {
  4240. n_chargingProfile = n_chargingProfile + 1;
  4241. printf("Found\n");
  4242. }
  4243. }
  4244. rewind(fptr1);
  4245. //search Charging Profile Element
  4246. int i= 0;
  4247. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4248. #if 0
  4249. /***********connectorId****************/
  4250. c = 0;
  4251. loc = strstr(sLineWord, "connectorId");
  4252. // printf("loc=%s\n",loc);
  4253. memset(sstr ,0, sizeof(sstr) );
  4254. while (loc[strlen("connectorId")+2+c] != ',')
  4255. {
  4256. sstr[c] = loc[strlen("connectorId")+2+c];
  4257. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4258. c++;
  4259. }
  4260. sstr[c] = '\0';
  4261. tempconnectorIdInt = atoi(sstr);
  4262. #endif
  4263. //***********validFrom**************/
  4264. c = 0;
  4265. loc = strstr(sLineWord, "validFrom");
  4266. //DEBUG_INFO("loc=%s\n",loc);
  4267. memset(sstr ,0, sizeof(sstr) );
  4268. if(loc != NULL)
  4269. {
  4270. while (loc[3+strlen("validFrom")+c] != '\"')
  4271. {
  4272. sstr[c] = loc[3+strlen("validFrom")+c];
  4273. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4274. c++;
  4275. }
  4276. sstr[c] = '\0';
  4277. DEBUG_INFO("validFrom=%s\n",sstr);
  4278. strcpy(tempvalidFromStr,sstr);
  4279. }
  4280. else
  4281. {
  4282. strcpy(tempvalidFromStr,"");
  4283. }
  4284. //**********startSchedule**********/
  4285. c = 0;
  4286. loc = strstr(sLineWord, "startSchedule");
  4287. //DEBUG_INFO("loc=%s\n",loc);
  4288. memset(sstr ,0, sizeof(sstr) );
  4289. while (loc[3+strlen("startSchedule")+c] != '\"')
  4290. {
  4291. sstr[c] = loc[3+strlen("startSchedule")+c];
  4292. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4293. c++;
  4294. }
  4295. sstr[c] = '\0';
  4296. strcpy(tempstartScheduleStr, sstr);
  4297. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4298. //**********chargingRateUnit**********/
  4299. c = 0;
  4300. loc = strstr(sLineWord, "chargingRateUnit");
  4301. memset(sstr ,0, sizeof(sstr) );
  4302. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4303. {
  4304. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4305. c++;
  4306. }
  4307. sstr[c] = '\0';
  4308. strcpy(tempchargingRateUnitStr, sstr);
  4309. //**********minChargingRate*******/
  4310. c = 0;
  4311. loc = strstr(sLineWord, "minChargingRate");
  4312. //printf("loc=%s\n",loc);
  4313. if(loc != NULL)
  4314. {
  4315. memset(sstr ,0, sizeof(sstr) );
  4316. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4317. {
  4318. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4319. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4320. c++;
  4321. }
  4322. sstr[c] = '\0';
  4323. tempminChargingRateFloat = atof(sstr);
  4324. }
  4325. else
  4326. {
  4327. tempminChargingRateFloat = 0.0;
  4328. }
  4329. //
  4330. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4331. tp.tm_isdst = -1;
  4332. time_t utc = mktime(&tp);
  4333. // current time
  4334. time_t t = time(NULL);
  4335. diff_t = difftime(t, utc);
  4336. //parsing strings to words
  4337. i = 0;
  4338. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4339. loc = loc+3+strlen("chargingSchedulePeriod");
  4340. pch = strtok(loc ,"{");
  4341. while (pch != NULL)
  4342. {
  4343. strcpy(SchedulePeriodList[i], pch);
  4344. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4345. //printf ("%s\n",pch);
  4346. pch = strtok (NULL, "{");
  4347. i = i + 1;
  4348. }
  4349. n_SchedulePeriods = i;
  4350. for(int i=0;i<n_SchedulePeriods;i++)
  4351. {
  4352. //*************startPeriod****************/
  4353. c = 0;
  4354. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4355. memset(sstr ,0, sizeof(sstr) );
  4356. while (loc[strlen("startPeriod")+2+c] != ',')
  4357. {
  4358. sstr[c] = loc[strlen("startPeriod")+2+c];
  4359. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4360. c++;
  4361. }
  4362. sstr[c] = '\0';
  4363. tempStartPeriodInt = atoi(sstr);
  4364. //*************limit****************/
  4365. c = 0;
  4366. loc = strstr(SchedulePeriodList[i], "limit");
  4367. memset(sstr ,0, sizeof(sstr) );
  4368. while (loc[strlen("limit")+2+c] != ',')
  4369. {
  4370. sstr[c] = loc[strlen("limit")+2+c];
  4371. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4372. c++;
  4373. }
  4374. sstr[c] = '\0';
  4375. tempLimitInt = atof(sstr);
  4376. //*************numberPhases****************/
  4377. c = 0;
  4378. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4379. memset(sstr ,0, sizeof(sstr) );
  4380. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4381. {
  4382. sstr[c] = loc[strlen("numberPhases")+2+c];
  4383. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4384. c++;
  4385. }
  4386. sstr[c] = '\0';
  4387. tempNumberPhasesInt = atoi(sstr);
  4388. ChargePointMaxProfile.Duration = durationInt;
  4389. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4390. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4391. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4392. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4393. }
  4394. if(MinChargingRate < tempminChargingRateFloat)
  4395. MinChargingRate = tempminChargingRateFloat;
  4396. }
  4397. }// End of file ChargingProfile
  4398. } //THE END OF ACCESS ChargePointMaxProfile
  4399. //******************************TxDefaultProfile***********************************************/
  4400. strcpy(fname, TxDefaultProfile_0_JSON);
  4401. memset(word, 0, 30);
  4402. memset(sLineWord, 0, 1060);
  4403. //char word[30]={0};
  4404. //char sLineWord[1060]={0};
  4405. n_chargingProfile=0;
  4406. TxDefaultProfileFileIsNull=TRUE;
  4407. if((access(fname,F_OK))!=-1)
  4408. {
  4409. fptr1 = fopen(fname, "r");
  4410. c = 0;
  4411. c = fgetc(fptr1);
  4412. //DEBUG_INFO("c:%d\n",c);
  4413. rewind(fptr1);
  4414. if(c == EOF)
  4415. {
  4416. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4417. TxDefaultProfileFileIsNull=TRUE;
  4418. fclose(fptr1);
  4419. }
  4420. else
  4421. {
  4422. TxDefaultProfileFileIsNull=FALSE;
  4423. while(fscanf(fptr1, "%s", word) != EOF)
  4424. {
  4425. if(strcmp(word, "chargingProfileId") == 0)
  4426. {
  4427. n_chargingProfile = n_chargingProfile + 1;
  4428. printf("Found\n");
  4429. }
  4430. }
  4431. rewind(fptr1);
  4432. //search Charging Profile Element
  4433. int i= 0;
  4434. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4435. #if 0
  4436. /***********connectorId****************/
  4437. c = 0;
  4438. loc = strstr(sLineWord, "connectorId");
  4439. // printf("loc=%s\n",loc);
  4440. memset(sstr ,0, sizeof(sstr) );
  4441. while (loc[strlen("connectorId")+2+c] != ',')
  4442. {
  4443. sstr[c] = loc[strlen("connectorId")+2+c];
  4444. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4445. c++;
  4446. }
  4447. sstr[c] = '\0';
  4448. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4449. tempconnectorIdInt = atoi(sstr);
  4450. #endif
  4451. //***********validFrom**************/
  4452. c = 0;
  4453. loc = strstr(sLineWord, "validFrom");
  4454. //DEBUG_INFO("loc=%s\n",loc);
  4455. memset(sstr ,0, sizeof(sstr) );
  4456. if(loc != NULL)
  4457. {
  4458. while (loc[3+strlen("validFrom")+c] != '\"')
  4459. {
  4460. sstr[c] = loc[3+strlen("validFrom")+c];
  4461. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4462. c++;
  4463. }
  4464. sstr[c] = '\0';
  4465. DEBUG_INFO("validFrom=%s\n",sstr);
  4466. strcpy(tempvalidFromStr,sstr);
  4467. }
  4468. else
  4469. {
  4470. strcpy(tempvalidFromStr,"");
  4471. }
  4472. //**********startSchedule**********/
  4473. c = 0;
  4474. loc = strstr(sLineWord, "startSchedule");
  4475. //DEBUG_INFO("loc=%s\n",loc);
  4476. memset(sstr ,0, sizeof(sstr) );
  4477. while (loc[3+strlen("startSchedule")+c] != '\"')
  4478. {
  4479. sstr[c] = loc[3+strlen("startSchedule")+c];
  4480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4481. c++;
  4482. }
  4483. sstr[c] = '\0';
  4484. strcpy(tempstartScheduleStr, sstr);
  4485. strcpy(TxDefaultProfileScheduleStr, sstr);
  4486. DEBUG_INFO(" debug 3-1\n");
  4487. //**********chargingRateUnit**********/
  4488. c = 0;
  4489. loc = strstr(sLineWord, "chargingRateUnit");
  4490. memset(sstr ,0, sizeof(sstr) );
  4491. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4492. {
  4493. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4494. c++;
  4495. }
  4496. sstr[c] = '\0';
  4497. strcpy(tempchargingRateUnitStr, sstr);
  4498. //**********minChargingRate*******/
  4499. c = 0;
  4500. loc = strstr(sLineWord, "minChargingRate");
  4501. //printf("loc=%s\n",loc);
  4502. if(loc != NULL)
  4503. {
  4504. memset(sstr ,0, sizeof(sstr) );
  4505. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4506. {
  4507. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4508. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4509. c++;
  4510. }
  4511. sstr[c] = '\0';
  4512. tempminChargingRateFloat = atof(sstr);
  4513. }
  4514. else
  4515. {
  4516. tempminChargingRateFloat = 0.0;
  4517. }
  4518. //
  4519. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4520. tp.tm_isdst = -1;
  4521. time_t utc = mktime(&tp);
  4522. // current time
  4523. time_t t = time(NULL);
  4524. diff_t = difftime(t, utc);
  4525. //parsing strings to words
  4526. i = 0;
  4527. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4528. loc = loc+3+strlen("chargingSchedulePeriod");
  4529. pch = strtok(loc ,"{");
  4530. while (pch != NULL)
  4531. {
  4532. strcpy(SchedulePeriodList[i], pch);
  4533. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4534. //printf ("%s\n",pch);
  4535. pch = strtok (NULL, "{");
  4536. i = i + 1;
  4537. }
  4538. n_SchedulePeriods = i;
  4539. for(int i=0;i<n_SchedulePeriods;i++)
  4540. {
  4541. //*************startPeriod****************/
  4542. c = 0;
  4543. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4544. memset(sstr ,0, sizeof(sstr) );
  4545. while (loc[strlen("startPeriod")+2+c] != ',')
  4546. {
  4547. sstr[c] = loc[strlen("startPeriod")+2+c];
  4548. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4549. c++;
  4550. }
  4551. sstr[c] = '\0';
  4552. tempStartPeriodInt = atoi(sstr);
  4553. //*************limit****************/
  4554. c = 0;
  4555. loc = strstr(SchedulePeriodList[i], "limit");
  4556. memset(sstr ,0, sizeof(sstr) );
  4557. while (loc[strlen("limit")+2+c] != ',')
  4558. {
  4559. sstr[c] = loc[strlen("limit")+2+c];
  4560. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4561. c++;
  4562. }
  4563. sstr[c] = '\0';
  4564. tempLimitInt = atof(sstr);
  4565. //*************numberPhases****************/
  4566. c = 0;
  4567. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4568. memset(sstr ,0, sizeof(sstr) );
  4569. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4570. {
  4571. sstr[c] = loc[strlen("numberPhases")+2+c];
  4572. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4573. c++;
  4574. }
  4575. sstr[c] = '\0';
  4576. tempNumberPhasesInt = atoi(sstr);
  4577. TxDefaultProfile.Duration = durationInt;
  4578. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4579. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4580. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4581. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4582. }
  4583. if(MinChargingRate < tempminChargingRateFloat)
  4584. MinChargingRate = tempminChargingRateFloat;
  4585. }
  4586. }
  4587. }// the end of ACCESS TxDefaultProfile
  4588. // Composite Schedule
  4589. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4590. {
  4591. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4592. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4593. {
  4594. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4595. {
  4596. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4597. }
  4598. else
  4599. {
  4600. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4601. }
  4602. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4603. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4604. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4605. }
  4606. }
  4607. //* Define temporary variables */
  4608. struct tm *gtime;
  4609. time_t now;
  4610. char buf[28];
  4611. /* Read the current system time */
  4612. time(&now);
  4613. /* Convert the system time to GMT (now UTC) */
  4614. gtime = gmtime(&now);
  4615. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4616. // make .conf
  4617. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4618. //MaxChargingProfilesInstalled is 10
  4619. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4620. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4621. //nPeriod = 1;
  4622. if(chargingRateUnitStr[0] != 0)
  4623. {
  4624. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4625. }
  4626. else
  4627. {
  4628. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4629. }
  4630. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4631. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4632. confirmPeriods = 1;
  4633. }
  4634. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4635. {
  4636. //*****************************ChargePointMaxProfile******************************************/
  4637. strcpy(fname, ChargePointMaxProfile_JSON);
  4638. ChargePointMaxProfileIsNull=TRUE;
  4639. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4640. {
  4641. fptr1 = fopen(fname, "r");
  4642. int c;
  4643. c = fgetc(fptr1);
  4644. //DEBUG_INFO("c:%d\n",c);
  4645. rewind(fptr1);
  4646. if(c == EOF)
  4647. {
  4648. DEBUG_INFO("\n End of file reached.");
  4649. ChargePointMaxProfileIsNull=TRUE;
  4650. fclose(fptr1);
  4651. }
  4652. else
  4653. {
  4654. ChargePointMaxProfileIsNull=FALSE;
  4655. while(fscanf(fptr1, "%s", word) != EOF)
  4656. {
  4657. if(strcmp(word, "chargingProfileId") == 0)
  4658. {
  4659. n_chargingProfile = n_chargingProfile + 1;
  4660. }
  4661. }
  4662. rewind(fptr1);
  4663. //search Charging Profile Element
  4664. int i = 0;
  4665. int j = 0;
  4666. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4667. #if 0
  4668. /***********connectorId****************/
  4669. c = 0;
  4670. loc = strstr(sLineWord, "connectorId");
  4671. memset(sstr ,0, sizeof(sstr) );
  4672. while (loc[strlen("connectorId")+2+c] != ',')
  4673. {
  4674. sstr[c] = loc[strlen("connectorId")+2+c];
  4675. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4676. c++;
  4677. }
  4678. sstr[c] = '\0';
  4679. tempconnectorIdInt = atoi(sstr);
  4680. #endif
  4681. //***********validFrom**************/
  4682. c = 0;
  4683. loc = strstr(sLineWord, "validFrom");
  4684. if(loc != NULL)
  4685. {
  4686. memset(sstr ,0, sizeof(sstr) );
  4687. while (loc[3+strlen("validFrom")+c] != '\"')
  4688. {
  4689. sstr[c] = loc[3+strlen("validFrom")+c];
  4690. c++;
  4691. }
  4692. sstr[c] = '\0';
  4693. strcpy(tempvalidFromStr,sstr);
  4694. }
  4695. else
  4696. {
  4697. strcpy(tempvalidFromStr,"");
  4698. }
  4699. //***********validFrom**************/
  4700. c = 0;
  4701. loc = strstr(sLineWord, "duration");
  4702. if(loc != NULL)
  4703. {
  4704. memset(sstr ,0, sizeof(sstr) );
  4705. while (loc[2+strlen("duration")+c] != ',')
  4706. {
  4707. sstr[c] = loc[2+strlen("duration")+c];
  4708. c++;
  4709. }
  4710. sstr[c] = '\0';
  4711. tempdurationInt = atoi(sstr);
  4712. }
  4713. else
  4714. {
  4715. tempdurationInt = 0;
  4716. }
  4717. //**********startSchedule**********/
  4718. c = 0;
  4719. loc = strstr(sLineWord, "startSchedule");
  4720. memset(sstr ,0, sizeof(sstr) );
  4721. while (loc[3+strlen("startSchedule")+c] != '\"')
  4722. {
  4723. sstr[c] = loc[3+strlen("startSchedule")+c];
  4724. c++;
  4725. }
  4726. sstr[c] = '\0';
  4727. strcpy(tempstartScheduleStr, sstr);
  4728. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4729. //**********chargingRateUnit**********/
  4730. c = 0;
  4731. loc = strstr(sLineWord, "chargingRateUnit");
  4732. memset(sstr ,0, sizeof(sstr) );
  4733. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4734. {
  4735. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4736. c++;
  4737. }
  4738. sstr[c] = '\0';
  4739. strcpy(tempchargingRateUnitStr, sstr);
  4740. //**********minChargingRate*******/
  4741. c = 0;
  4742. loc = strstr(sLineWord, "minChargingRate");
  4743. if(loc != NULL)
  4744. {
  4745. memset(sstr ,0, sizeof(sstr) );
  4746. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4747. {
  4748. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4749. c++;
  4750. }
  4751. sstr[c] = '\0';
  4752. tempminChargingRateFloat = atof(sstr);
  4753. }
  4754. else
  4755. {
  4756. tempminChargingRateFloat = 0.0;
  4757. }
  4758. //
  4759. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4760. tp.tm_isdst = -1;
  4761. time_t utc = mktime(&tp);
  4762. time_t t = time(NULL);
  4763. diff_t = difftime(t, utc);
  4764. DEBUG_INFO("diff_t=%f\n",diff_t);
  4765. DEBUG_INFO(" debug 5 -1\n");
  4766. //parsing strings to words
  4767. i = 0;
  4768. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4769. loc = loc+3+strlen("chargingSchedulePeriod");
  4770. pch = strtok(loc ,"{");
  4771. while (pch != NULL)
  4772. {
  4773. strcpy(SchedulePeriodList[i], pch);
  4774. pch = strtok (NULL, "{");
  4775. i = i + 1;
  4776. }
  4777. n_SchedulePeriods = i;
  4778. for(int i=0;i<n_SchedulePeriods;i++)
  4779. {
  4780. //*************startPeriod****************/
  4781. c = 0;
  4782. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4783. memset(sstr ,0, sizeof(sstr) );
  4784. while (loc[strlen("startPeriod")+2+c] != ',')
  4785. {
  4786. sstr[c] = loc[strlen("startPeriod")+2+c];
  4787. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4788. c++;
  4789. }
  4790. sstr[c] = '\0';
  4791. tempStartPeriodInt = atoi(sstr);
  4792. //*************limit****************/
  4793. c = 0;
  4794. loc = strstr(SchedulePeriodList[i], "limit");
  4795. memset(sstr ,0, sizeof(sstr) );
  4796. while (loc[strlen("limit")+2+c] != ',')
  4797. {
  4798. sstr[c] = loc[strlen("limit")+2+c];
  4799. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4800. c++;
  4801. }
  4802. sstr[c] = '\0';
  4803. tempLimitInt = atof(sstr);
  4804. //*************numberPhases****************/
  4805. c = 0;
  4806. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4807. memset(sstr ,0, sizeof(sstr) );
  4808. while (loc[strlen("numberPhases")+2+c] != '}')
  4809. {
  4810. sstr[c] = loc[strlen("numberPhases")+2+c];
  4811. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4812. c++;
  4813. }
  4814. sstr[c] = '\0';
  4815. tempNumberPhasesInt = atoi(sstr);
  4816. if(j == 0)
  4817. {
  4818. ChargePointMaxProfile.Duration = tempdurationInt;
  4819. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4820. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4821. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4822. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4823. }
  4824. }
  4825. if(MinChargingRate < tempminChargingRateFloat)
  4826. {
  4827. MinChargingRate = tempminChargingRateFloat;
  4828. }
  4829. if(confirmPeriods < n_SchedulePeriods)
  4830. {
  4831. confirmPeriods = n_SchedulePeriods;
  4832. }
  4833. j = j + 1;
  4834. }
  4835. fclose(fptr1);
  4836. }
  4837. }// the end of access file ChargePointMaxProfile
  4838. //****************************TxDefaultProfile************************************************/
  4839. switch(connectorIdInt)
  4840. {
  4841. case 0:
  4842. break;
  4843. case 1:
  4844. strcpy(fname, TxDefaultProfile_1_JSON );
  4845. break;
  4846. case 2:
  4847. strcpy(fname, TxDefaultProfile_2_JSON );
  4848. break;
  4849. default:
  4850. strcpy(fname, TxDefaultProfile_1_JSON );
  4851. break;
  4852. }
  4853. TxDefaultProfileFileIsNull=TRUE;
  4854. if((access(fname,F_OK))!=-1)
  4855. {
  4856. fptr1 = fopen(fname, "r");
  4857. c = 0;
  4858. c = fgetc(fptr1);
  4859. //DEBUG_INFO("c:%d\n",c);
  4860. rewind(fptr1);
  4861. if(c == EOF)
  4862. {
  4863. DEBUG_INFO("\n End of file reached.");
  4864. TxDefaultProfileFileIsNull=TRUE;
  4865. fclose(fptr1);
  4866. }
  4867. else
  4868. {
  4869. TxDefaultProfileFileIsNull=FALSE;
  4870. while(fscanf(fptr1, "%s", word) != EOF)
  4871. {
  4872. if(strcmp(word, "chargingProfileId") == 0)
  4873. {
  4874. n_chargingProfile = n_chargingProfile + 1;
  4875. }
  4876. }
  4877. rewind(fptr1);
  4878. //search Charging Profile Element
  4879. int i = 0;
  4880. int j = 0;
  4881. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4882. #if 0
  4883. /***********connectorId****************/
  4884. c = 0;
  4885. loc = strstr(sLineWord, "connectorId");
  4886. memset(sstr ,0, sizeof(sstr) );
  4887. while (loc[strlen("connectorId")+2+c] != ',')
  4888. {
  4889. sstr[c] = loc[strlen("connectorId")+2+c];
  4890. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4891. c++;
  4892. }
  4893. sstr[c] = '\0';
  4894. tempconnectorIdInt = atoi(sstr);
  4895. #endif
  4896. //***********validFrom**************/
  4897. c = 0;
  4898. loc = strstr(sLineWord, "validFrom");
  4899. if(loc != NULL)
  4900. {
  4901. memset(sstr ,0, sizeof(sstr) );
  4902. while (loc[3+strlen("validFrom")+c] != '\"')
  4903. {
  4904. sstr[c] = loc[3+strlen("validFrom")+c];
  4905. c++;
  4906. }
  4907. sstr[c] = '\0';
  4908. strcpy(tempvalidFromStr,sstr);
  4909. }
  4910. else
  4911. {
  4912. strcpy(tempvalidFromStr,"");
  4913. }
  4914. //***********validFrom**************/
  4915. c = 0;
  4916. loc = strstr(sLineWord, "duration");
  4917. if(loc != NULL)
  4918. {
  4919. memset(sstr ,0, sizeof(sstr) );
  4920. while (loc[2+strlen("duration")+c] != ',')
  4921. {
  4922. sstr[c] = loc[2+strlen("duration")+c];
  4923. c++;
  4924. }
  4925. sstr[c] = '\0';
  4926. tempdurationInt = atoi(sstr);
  4927. }
  4928. else
  4929. {
  4930. tempdurationInt = 0;
  4931. }
  4932. //**********startSchedule**********/
  4933. c = 0;
  4934. loc = strstr(sLineWord, "startSchedule");
  4935. memset(sstr ,0, sizeof(sstr) );
  4936. while (loc[3+strlen("startSchedule")+c] != '\"')
  4937. {
  4938. sstr[c] = loc[3+strlen("startSchedule")+c];
  4939. c++;
  4940. }
  4941. sstr[c] = '\0';
  4942. strcpy(tempstartScheduleStr, sstr);
  4943. strcpy(TxDefaultProfileScheduleStr, sstr);
  4944. //**********chargingRateUnit**********/
  4945. c = 0;
  4946. loc = strstr(sLineWord, "chargingRateUnit");
  4947. memset(sstr ,0, sizeof(sstr) );
  4948. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4949. {
  4950. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4951. c++;
  4952. }
  4953. sstr[c] = '\0';
  4954. strcpy(tempchargingRateUnitStr, sstr);
  4955. //**********minChargingRate*******/
  4956. c = 0;
  4957. loc = strstr(sLineWord, "minChargingRate");
  4958. if(loc != NULL)
  4959. {
  4960. memset(sstr ,0, sizeof(sstr) );
  4961. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4962. {
  4963. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4964. c++;
  4965. }
  4966. sstr[c] = '\0';
  4967. tempminChargingRateFloat = atof(sstr);
  4968. }
  4969. else
  4970. {
  4971. tempminChargingRateFloat = 0.0;
  4972. }
  4973. //
  4974. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4975. tp.tm_isdst = -1;
  4976. time_t utc = mktime(&tp);
  4977. time_t t = time(NULL);
  4978. diff_t = difftime(t, utc);
  4979. DEBUG_INFO("diff_t=%f\n",diff_t);
  4980. //parsing strings to words
  4981. i = 0;
  4982. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4983. loc = loc+3+strlen("chargingSchedulePeriod");
  4984. pch = strtok(loc ,"{");
  4985. while (pch != NULL)
  4986. {
  4987. strcpy(SchedulePeriodList[i], pch);
  4988. pch = strtok (NULL, "{");
  4989. i = i + 1;
  4990. }
  4991. n_SchedulePeriods = i;
  4992. for(int i=0;i<n_SchedulePeriods;i++)
  4993. {
  4994. //*************startPeriod****************/
  4995. c = 0;
  4996. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4997. memset(sstr ,0, sizeof(sstr) );
  4998. while (loc[strlen("startPeriod")+2+c] != ',')
  4999. {
  5000. sstr[c] = loc[strlen("startPeriod")+2+c];
  5001. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5002. c++;
  5003. }
  5004. sstr[c] = '\0';
  5005. tempStartPeriodInt = atoi(sstr);
  5006. //*************limit****************/
  5007. c = 0;
  5008. loc = strstr(SchedulePeriodList[i], "limit");
  5009. memset(sstr ,0, sizeof(sstr) );
  5010. while (loc[strlen("limit")+2+c] != ',')
  5011. {
  5012. sstr[c] = loc[strlen("limit")+2+c];
  5013. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5014. c++;
  5015. }
  5016. sstr[c] = '\0';
  5017. tempLimitInt = atof(sstr);
  5018. //*************numberPhases****************/
  5019. c = 0;
  5020. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5021. memset(sstr ,0, sizeof(sstr) );
  5022. while (loc[strlen("numberPhases")+2+c] != '}')
  5023. {
  5024. sstr[c] = loc[strlen("numberPhases")+2+c];
  5025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5026. c++;
  5027. }
  5028. sstr[c] = '\0';
  5029. tempNumberPhasesInt = atoi(sstr);
  5030. if(j == 0)
  5031. {
  5032. TxDefaultProfile.Duration = tempdurationInt;
  5033. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5034. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5035. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5036. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5037. }
  5038. else
  5039. {
  5040. //other stack level charging Profile
  5041. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5042. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5043. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5044. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5045. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5046. }
  5047. }
  5048. if(MinChargingRate < tempminChargingRateFloat)
  5049. MinChargingRate = tempminChargingRateFloat;
  5050. if(confirmPeriods < n_SchedulePeriods)
  5051. confirmPeriods = n_SchedulePeriods;
  5052. j = j + 1;
  5053. }
  5054. fclose(fptr1);
  5055. //Stacking Charging Profiles
  5056. for(int l=0; l <(j-1) ;l++)
  5057. {
  5058. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5059. {
  5060. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5061. {
  5062. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5063. {
  5064. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5065. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5066. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5067. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5068. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5069. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5070. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5071. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5072. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5073. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5074. }
  5075. else
  5076. {
  5077. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5078. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5079. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5080. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5081. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5082. }
  5083. }
  5084. }
  5085. }
  5086. //end of Stacking Charging Profiles
  5087. }
  5088. }// the end of ACCESS TxDefaultProfile
  5089. //****************************TxProfile************************************************/
  5090. switch(connectorIdInt)
  5091. {
  5092. case 0:
  5093. break;
  5094. case 1:
  5095. strcpy(fname, TxProfile_1_JSON );
  5096. break;
  5097. case 2:
  5098. strcpy(fname, TxProfile_2_JSON );
  5099. break;
  5100. default:
  5101. strcpy(fname, TxProfile_1_JSON );
  5102. break;
  5103. }
  5104. TxProfileIsNull=TRUE;
  5105. if((access(fname,F_OK))!=-1)
  5106. {
  5107. fptr1 = fopen(fname, "r");
  5108. c = 0;
  5109. c = fgetc(fptr1);
  5110. //DEBUG_INFO("c:%d\n",c);
  5111. rewind(fptr1);
  5112. if(c == EOF)
  5113. {
  5114. DEBUG_INFO("\n End of file reached.");
  5115. TxProfileIsNull=TRUE;
  5116. fclose(fptr1);
  5117. }
  5118. else
  5119. {
  5120. TxProfileIsNull=FALSE;
  5121. while(fscanf(fptr1, "%s", word) != EOF)
  5122. {
  5123. if(strcmp(word, "chargingProfileId") == 0)
  5124. {
  5125. n_chargingProfile = n_chargingProfile + 1;
  5126. }
  5127. }
  5128. rewind(fptr1);
  5129. //search Charging Profile Element
  5130. int i= 0;
  5131. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5132. #if 0
  5133. /***********connectorId****************/
  5134. c = 0;
  5135. loc = strstr(sLineWord, "connectorId");
  5136. memset(sstr ,0, sizeof(sstr) );
  5137. while (loc[strlen("connectorId")+2+c] != ',')
  5138. {
  5139. sstr[c] = loc[strlen("connectorId")+2+c];
  5140. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5141. c++;
  5142. }
  5143. sstr[c] = '\0';
  5144. tempconnectorIdInt = atoi(sstr);
  5145. #endif
  5146. //***********validFrom**************/
  5147. c = 0;
  5148. loc = strstr(sLineWord, "validFrom");
  5149. if(loc != NULL)
  5150. {
  5151. memset(sstr ,0, sizeof(sstr) );
  5152. while (loc[3+strlen("validFrom")+c] != '\"')
  5153. {
  5154. sstr[c] = loc[3+strlen("validFrom")+c];
  5155. c++;
  5156. }
  5157. sstr[c] = '\0';
  5158. strcpy(tempvalidFromStr,sstr);
  5159. }
  5160. else
  5161. {
  5162. strcpy(tempvalidFromStr,"");
  5163. }
  5164. //**********startSchedule**********/
  5165. c = 0;
  5166. loc = strstr(sLineWord, "startSchedule");
  5167. memset(sstr ,0, sizeof(sstr) );
  5168. while (loc[3+strlen("startSchedule")+c] != '\"')
  5169. {
  5170. sstr[c] = loc[3+strlen("startSchedule")+c];
  5171. c++;
  5172. }
  5173. sstr[c] = '\0';
  5174. strcpy(tempstartScheduleStr, sstr);
  5175. strcpy(TxProfileScheduleStr, sstr);
  5176. //**********chargingRateUnit**********/
  5177. c = 0;
  5178. loc = strstr(sLineWord, "chargingRateUnit");
  5179. memset(sstr ,0, sizeof(sstr) );
  5180. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5181. {
  5182. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5183. c++;
  5184. }
  5185. sstr[c] = '\0';
  5186. strcpy(tempchargingRateUnitStr, sstr);
  5187. //**********minChargingRate*******/
  5188. c = 0;
  5189. loc = strstr(sLineWord, "minChargingRate");
  5190. if(loc != NULL)
  5191. {
  5192. memset(sstr ,0, sizeof(sstr) );
  5193. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5194. {
  5195. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5196. c++;
  5197. }
  5198. sstr[c] = '\0';
  5199. tempminChargingRateFloat = atof(sstr);
  5200. }
  5201. else
  5202. {
  5203. tempminChargingRateFloat = 0.0;
  5204. }
  5205. //
  5206. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5207. tp.tm_isdst = -1;
  5208. time_t utc = mktime(&tp);
  5209. time_t t = time(NULL);
  5210. diff_t = difftime(t, utc);
  5211. DEBUG_INFO("diff_t=%f\n",diff_t);
  5212. //parsing strings to words
  5213. i = 0;
  5214. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5215. loc = loc+3+strlen("chargingSchedulePeriod");
  5216. pch = strtok(loc ,"{");
  5217. while (pch != NULL)
  5218. {
  5219. strcpy(SchedulePeriodList[i], pch);
  5220. pch = strtok (NULL, "{");
  5221. i = i + 1;
  5222. }
  5223. n_SchedulePeriods = i;
  5224. for(int i=0;i<n_SchedulePeriods;i++)
  5225. {
  5226. //*************startPeriod****************/
  5227. c = 0;
  5228. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5229. memset(sstr ,0, sizeof(sstr) );
  5230. while (loc[strlen("startPeriod")+2+c] != ',')
  5231. {
  5232. sstr[c] = loc[strlen("startPeriod")+2+c];
  5233. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5234. c++;
  5235. }
  5236. sstr[c] = '\0';
  5237. tempStartPeriodInt = atoi(sstr);
  5238. //*************limit****************/
  5239. c = 0;
  5240. loc = strstr(SchedulePeriodList[i], "limit");
  5241. memset(sstr ,0, sizeof(sstr) );
  5242. while (loc[strlen("limit")+2+c] != ',')
  5243. {
  5244. sstr[c] = loc[strlen("limit")+2+c];
  5245. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5246. c++;
  5247. }
  5248. sstr[c] = '\0';
  5249. tempLimitInt = atof(sstr);
  5250. //*************numberPhases****************/
  5251. c = 0;
  5252. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5253. memset(sstr ,0, sizeof(sstr) );
  5254. while (loc[strlen("numberPhases")+2+c] != '}')
  5255. {
  5256. sstr[c] = loc[strlen("numberPhases")+2+c];
  5257. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5258. c++;
  5259. }
  5260. sstr[c] = '\0';
  5261. tempNumberPhasesInt = atoi(sstr);
  5262. TxProfile.Duration = durationInt;
  5263. TxProfile.TotalPeriod = n_SchedulePeriods;
  5264. TxProfile.Period[i].Limit = tempLimitInt;
  5265. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5266. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5267. }
  5268. if(MinChargingRate < tempminChargingRateFloat)
  5269. MinChargingRate = tempminChargingRateFloat;
  5270. if(confirmPeriods < n_SchedulePeriods)
  5271. confirmPeriods = n_SchedulePeriods;
  5272. }
  5273. fclose(fptr1);
  5274. }
  5275. }// the end of ACCESS TxProfile
  5276. //CompositeSchedule
  5277. int period=0;
  5278. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5279. {
  5280. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5281. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5282. {
  5283. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5284. {
  5285. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5286. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5287. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5288. period = period + 1;
  5289. }
  5290. else
  5291. {
  5292. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5293. {
  5294. }
  5295. else
  5296. {
  5297. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5298. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5299. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5300. period = period + 1;
  5301. }
  5302. }
  5303. }
  5304. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5305. {
  5306. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5307. {
  5308. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5309. {
  5310. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5311. }
  5312. else
  5313. {
  5314. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5315. }
  5316. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5317. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5318. period = period + 1;
  5319. }
  5320. }
  5321. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5322. {
  5323. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5324. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5325. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5326. period = period + 1;
  5327. }
  5328. }
  5329. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5330. {
  5331. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5332. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5333. {
  5334. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5335. {
  5336. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5337. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5338. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5339. period = period + 1;
  5340. }
  5341. else
  5342. {
  5343. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5344. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5345. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5346. period = period + 1;
  5347. }
  5348. }
  5349. }
  5350. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5351. {
  5352. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5353. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5354. {
  5355. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5356. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5357. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5358. period = period + 1;
  5359. }
  5360. }
  5361. confirmPeriods = period;
  5362. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5363. //* Define temporary variables */
  5364. struct tm *gtime;
  5365. time_t now;
  5366. char buf[28];
  5367. //* Read the current system time */
  5368. time(&now);
  5369. //* Convert the system time to GMT (now UTC) */
  5370. gtime = gmtime(&now);
  5371. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5372. // make .conf
  5373. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5374. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5375. //DEBUG_INFO(" debug 11\n");
  5376. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5377. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5378. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5379. }
  5380. else
  5381. {
  5382. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5383. }
  5384. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5385. return result;
  5386. }
  5387. int handleGetConfigurationRequest(char *uuid, char *payload)
  5388. {
  5389. mtrace();
  5390. int result = FAIL;
  5391. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5392. //struct json_object *jsonitem;
  5393. int MaxKeySupported = 0;
  5394. int n_keys = 0;
  5395. char requestKey[43][50]={0};
  5396. char search[]="[";
  5397. char sstr[500]={ 0 };
  5398. //int pos;
  5399. int l, c = 0;
  5400. int i = 0;
  5401. char *delim = "\",\"";
  5402. char * pch;
  5403. char *loc = strstr(payload, search);
  5404. //********************* Parsing String ***********************************/
  5405. if(loc == NULL) {
  5406. DEBUG_INFO("no key match in Configuration \n");
  5407. }
  5408. else {
  5409. //pos = loc - payload;
  5410. l = strlen(loc)-4;
  5411. while (c < l)
  5412. {
  5413. sstr[c] = loc[c+2];
  5414. c++;
  5415. }
  5416. sstr[c] = '\0';
  5417. //parsing strings to words
  5418. pch = strtok(sstr,delim);
  5419. if(pch == NULL)
  5420. {
  5421. strcpy(requestKey[0], sstr);
  5422. }
  5423. else
  5424. {
  5425. while (pch != NULL)
  5426. {
  5427. strcpy(requestKey[i], pch);
  5428. pch = strtok (NULL, delim);
  5429. i = i + 1;
  5430. }
  5431. n_keys = i;
  5432. }
  5433. }
  5434. UnknownKeynum = 0;
  5435. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5436. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5437. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5438. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5439. if(n_keys != 0)
  5440. {
  5441. for(int i=0;i<n_keys;i++)
  5442. {
  5443. getKeyValue(requestKey[i]);
  5444. //json_object_put(jsonitem);
  5445. }
  5446. }
  5447. else
  5448. {
  5449. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5450. getKeyValue("");
  5451. }
  5452. processUnkownKey();
  5453. sendGetConfigurationConfirmation(uuid);
  5454. return result;
  5455. }
  5456. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5457. {
  5458. mtrace();
  5459. int result = FAIL;
  5460. //void *ret; //
  5461. char fnamePlusPath[50]="";
  5462. char fname[16]="";
  5463. pthread_t t; // pthread 變數
  5464. time_t rawtime;
  5465. struct tm * timeinfo;
  5466. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5467. system("exec /root/logPackTools 'log' 6");
  5468. //char buffer [128];
  5469. time (&rawtime);
  5470. //printf("%ld\n", rawtime);
  5471. timeinfo = localtime (&rawtime);
  5472. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5473. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5474. if((access(fnamePlusPath,F_OK))!=-1)
  5475. {
  5476. DEBUG_INFO("fnamePlusPath exist.\n");
  5477. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5478. }
  5479. else
  5480. {
  5481. DEBUG_INFO("fnamePlusPath not exist!\n");
  5482. }
  5483. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5484. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5485. pthread_join(t, NULL/*&ret*/);
  5486. return result;
  5487. }
  5488. void* GetDiagnosticsProcess(void* data)
  5489. {
  5490. mtrace();
  5491. int retriesInt=0, retryIntervalInt=0;
  5492. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5493. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5494. 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};
  5495. int port=0;
  5496. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5497. char fname[16]="";
  5498. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5499. int c = 0;
  5500. char *loc;
  5501. int isSuccess = FALSE;
  5502. char ftpbuf[200]={0};
  5503. //char temp[100]={0};
  5504. char * pch;
  5505. // [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"}]
  5506. char *str = (char*) data; // ?��?輸入資�?
  5507. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5508. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5509. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5510. //****************location*******************/
  5511. c = 0;
  5512. memset(sstr ,0, sizeof(sstr) );
  5513. loc = strstr(str, "location");
  5514. while (loc[3+strlen("location")+c] != '\"')
  5515. {
  5516. sstr[c] = loc[3+strlen("location")+c];
  5517. c++;
  5518. }
  5519. sstr[c] = '\0';
  5520. strcpy(locationstr,sstr);
  5521. if(strcmp(locationstr,"")==0)
  5522. {
  5523. DEBUG_INFO("location is <Empty>!\n");
  5524. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5525. goto end;
  5526. }
  5527. //****************retries*******************/
  5528. c = 0;
  5529. loc = strstr(str, "retries");
  5530. if(loc == NULL)
  5531. {
  5532. retriesIsNULL = TRUE;
  5533. }
  5534. else
  5535. {
  5536. while (loc[strlen("retries")+2+c] != ',')
  5537. {
  5538. sstr[c] = loc[strlen("retries")+2+c];
  5539. c++;
  5540. }
  5541. sstr[c] = '\0';
  5542. retriesInt = atoi(sstr);
  5543. }
  5544. if(retriesIsNULL == TRUE)
  5545. {
  5546. retriesInt = 0;
  5547. }
  5548. //****************retryInterval*******************/
  5549. c = 0;
  5550. loc = strstr(str, "retryInterval");
  5551. if(loc == NULL)
  5552. {
  5553. retryIntervalIsNULL = TRUE;
  5554. }
  5555. else
  5556. {
  5557. while (loc[strlen("retryInterval")+2+c] != ',')
  5558. {
  5559. sstr[c] = loc[strlen("retryInterval")+2+c];
  5560. c++;
  5561. }
  5562. sstr[c] = '\0';
  5563. retryIntervalInt = atoi(sstr);
  5564. }
  5565. //****************startTime*******************/
  5566. c = 0;
  5567. memset(sstr ,0, sizeof(sstr) );
  5568. loc = strstr(str, "startTime");
  5569. if(loc == NULL)
  5570. {
  5571. startTimeIsNULL = TRUE;
  5572. }
  5573. else
  5574. {
  5575. while (loc[3+strlen("startTime")+c] != '\"')
  5576. {
  5577. sstr[c] = loc[3+strlen("startTime")+c];
  5578. c++;
  5579. }
  5580. sstr[c] = '\0';
  5581. strcpy(startTimestr,sstr);
  5582. }
  5583. //****************stopTime*******************/
  5584. c = 0;
  5585. memset(sstr ,0, sizeof(sstr) );
  5586. loc = strstr(str, "stopTime");
  5587. if(loc == NULL)
  5588. {
  5589. stopTimeIsNULL = TRUE;
  5590. }
  5591. else
  5592. {
  5593. while (loc[3+strlen("stopTime")+c] != '\"')
  5594. {
  5595. sstr[c] = loc[3+strlen("stopTime")+c];
  5596. c++;
  5597. }
  5598. sstr[c] = '\0';
  5599. strcpy(stopTimestr,sstr);
  5600. }
  5601. memset(protocol, 0, sizeof(protocol));
  5602. memset(user, 0, sizeof(user) );
  5603. memset(password, 0, sizeof(password));
  5604. memset(host, 0, sizeof(host));
  5605. memset(path, 0, sizeof(path));
  5606. memset(ftppath, 0, sizeof(ftppath));
  5607. memset(host1, 0, sizeof(host1));
  5608. memset(path1, 0, sizeof(path1));
  5609. /*location: ftp://user:password@host:port/path*/
  5610. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5611. // protocol, user, password, host, &port, path);
  5612. #if 0 // remove for temporally
  5613. //zip files in /Storage
  5614. system("exec /root/logPackTools 'log' 6");
  5615. #endif
  5616. // system("exec /root/Module_WebService 'log' 6");
  5617. time_t rawtime;
  5618. struct tm * timeinfo;
  5619. //char buffer [128];
  5620. time (&rawtime);
  5621. //printf("%ld\n", rawtime);
  5622. timeinfo = localtime (&rawtime);
  5623. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5624. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5625. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5626. if((access(fnamePlusPath,F_OK))!=-1)
  5627. {
  5628. DEBUG_INFO("fnamePlusPath exist.\n");
  5629. }
  5630. else
  5631. {
  5632. DEBUG_INFO("fnamePlusPath not exist!\n");
  5633. goto end;
  5634. }
  5635. pch=strchr(locationstr,'@');
  5636. if(pch==NULL)
  5637. {
  5638. sscanf(locationstr,
  5639. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5640. protocol, host, &port, path);
  5641. strcpy(user,"anonymous");
  5642. strcpy(password,"");
  5643. }
  5644. else
  5645. {
  5646. DEBUG_INFO("pch=%s\n", pch);
  5647. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5648. protocol, user, password, host, &port, path);
  5649. }
  5650. if(strcmp(protocol,"ftp")!=0)
  5651. {
  5652. DEBUG_INFO("protocol is not ftp!\n");
  5653. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5654. goto end;
  5655. }
  5656. sscanf(host,"%[^/]%s",host1, path1);
  5657. sprintf(ftppath,"%s", path1);
  5658. DEBUG_INFO("protocol =%s\n",protocol);
  5659. DEBUG_INFO("user =%s\n",user);
  5660. DEBUG_INFO("password =%s\n",password);
  5661. DEBUG_INFO("host1 =%s\n",host1);
  5662. DEBUG_INFO("port =%d\n",port);
  5663. DEBUG_INFO("path1 =%s\n",path1);
  5664. DEBUG_INFO("ftppath=%s\n",ftppath);
  5665. int ftppathlen=strlen(ftppath);
  5666. int i=1;
  5667. char filenametemp[50];
  5668. while(i < ftppathlen)
  5669. {
  5670. int len=ftppathlen-i;
  5671. if(ftppath[len]== 47) // '/' ascll code: 47
  5672. {
  5673. DEBUG_INFO("find '/' all right\n");
  5674. break;
  5675. }
  5676. i=i+1;
  5677. }
  5678. memset(filenametemp, 0, sizeof(filenametemp));
  5679. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5680. filenametemp[i+1] = 0;
  5681. //httpDownLoadFile(host, ftppath, fname);
  5682. memset(ftpbuf, 0, sizeof(ftpbuf));
  5683. if(port == 0)
  5684. port = 21;
  5685. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5686. do{
  5687. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5688. sleep(retryIntervalInt);
  5689. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5690. if(!isSuccess)
  5691. {
  5692. //BulldogUtil.sleepMs(interval*1000);
  5693. DEBUG_INFO("Diagnostics fail.\n");
  5694. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5695. }
  5696. else
  5697. {
  5698. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5699. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5700. //isUpdateRequest = TRUE;
  5701. }
  5702. end:
  5703. // json_object_put(obj);
  5704. DiagnosticsStatusNotificationStatus = 0; //Idle
  5705. pthread_exit(NULL/*(void *) fname*/); // ?��?子執行�?
  5706. }
  5707. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5708. {
  5709. mtrace();
  5710. int result = FAIL;
  5711. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5712. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5713. {
  5714. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5715. localversion = -1;
  5716. }
  5717. else
  5718. {
  5719. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5720. OCPP_getListVerion();
  5721. }
  5722. //from db.OCPP_getListVerion
  5723. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5724. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5725. sendGetLocalListVersionConfirmation(uuid,"");
  5726. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5727. return result;
  5728. }
  5729. int handleRemoteStartRequest(char *uuid, char *payload)
  5730. {
  5731. mtrace();
  5732. int result = FAIL;
  5733. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5734. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5735. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5736. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5737. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5738. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5739. int chargingSchedulePeriodCount = 0;
  5740. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5741. int c = 0;
  5742. char *loc;
  5743. char comfirmstr[20]={0};
  5744. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5745. if(server_pending == TRUE)
  5746. {
  5747. return 0;
  5748. }
  5749. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5750. //**********connectorId****************/
  5751. c = 0;
  5752. memset(sstr ,0, sizeof(sstr) );
  5753. loc = strstr(payload, "connectorId");
  5754. if(loc == NULL)
  5755. {
  5756. connectorIdIsNULL = TRUE;
  5757. }
  5758. else
  5759. {
  5760. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5761. {
  5762. sstr[c] = loc[strlen("connectorId")+2+c];
  5763. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5764. c++;
  5765. }
  5766. sstr[c] = '\0';
  5767. connectorIdInt = atoi(sstr);
  5768. }
  5769. if(connectorIdIsNULL == TRUE) // need to discussion
  5770. {
  5771. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5772. goto end;
  5773. }
  5774. //****************idTag*******************/
  5775. c = 0;
  5776. memset(sstr ,0, sizeof(sstr) );
  5777. loc = strstr(payload, "idTag");
  5778. while (loc[3+strlen("idTag")+c] != '\"')
  5779. {
  5780. sstr[c] = loc[3+strlen("idTag")+c];
  5781. c++;
  5782. }
  5783. sstr[c] = '\0';
  5784. strcpy(idTagstr,sstr);
  5785. //****************chargingProfile*******************/
  5786. c = 0;
  5787. memset(sstr ,0, sizeof(sstr) );
  5788. loc = strstr(payload, "chargingProfile");
  5789. if(loc == NULL)
  5790. {
  5791. chargingProfileIsNULL = TRUE;
  5792. }
  5793. else
  5794. {
  5795. //****************chargingProfileId*******************/
  5796. c=0;
  5797. loc = strstr(payload, "chargingProfileId");
  5798. memset(sstr ,0, sizeof(sstr) );
  5799. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5800. {
  5801. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5802. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5803. c++;
  5804. }
  5805. sstr[c] = '\0';
  5806. chargingProfileIdInt = atoi(sstr);
  5807. //****************transactionId*******************/
  5808. loc = strstr(payload, "transactionId");
  5809. if(loc == NULL)
  5810. {
  5811. transactionIdIsNULL = TRUE;
  5812. }
  5813. else
  5814. {
  5815. c=0;
  5816. memset(sstr ,0, sizeof(sstr) );
  5817. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5818. {
  5819. sstr[c] = loc[strlen("transactionId")+2+c];
  5820. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5821. c++;
  5822. }
  5823. sstr[c] = '\0';
  5824. transactionIdInt = atoi(sstr);
  5825. }
  5826. //****************stackLevel*******************/
  5827. c=0;
  5828. loc = strstr(payload, "stackLevel");
  5829. memset(sstr ,0, sizeof(sstr) );
  5830. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5831. {
  5832. sstr[c] = loc[strlen("stackLevel")+2+c];
  5833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5834. c++;
  5835. }
  5836. sstr[c] = '\0';
  5837. stackLevelInt = atoi(sstr);
  5838. //****************chargingProfilePurpose*******************/
  5839. c = 0;
  5840. memset(sstr ,0, sizeof(sstr) );
  5841. loc = strstr(payload, "chargingProfilePurpose");
  5842. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5843. {
  5844. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5845. c++;
  5846. }
  5847. sstr[c] = '\0';
  5848. strcpy(chargingProfilePurposestr,sstr);
  5849. //****************chargingProfileKind*******************/
  5850. c = 0;
  5851. memset(sstr ,0, sizeof(sstr) );
  5852. loc = strstr(payload, "chargingProfileKind");
  5853. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5854. {
  5855. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5856. c++;
  5857. }
  5858. sstr[c] = '\0';
  5859. strcpy(chargingProfileKindstr,sstr);
  5860. //****************recurrencyKind*******************/
  5861. loc = strstr(payload, "recurrencyKind");
  5862. if(loc == NULL)
  5863. {
  5864. recurrencyKindIsNULL = TRUE;
  5865. }
  5866. else
  5867. {
  5868. c = 0;
  5869. memset(sstr ,0, sizeof(sstr) );
  5870. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5871. {
  5872. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5873. c++;
  5874. }
  5875. sstr[c] = '\0';
  5876. strcpy(recurrencyKindstr,sstr);
  5877. }
  5878. //****************validFrom*******************/
  5879. loc = strstr(payload, "validFrom");
  5880. if(loc == NULL)
  5881. {
  5882. validFromIsNULL = TRUE;
  5883. }
  5884. else
  5885. {
  5886. c = 0;
  5887. memset(sstr ,0, sizeof(sstr) );
  5888. while (loc[3+strlen("validFrom")+c] != '\"')
  5889. {
  5890. sstr[c] = loc[3+strlen("validFrom")+c];
  5891. c++;
  5892. }
  5893. sstr[c] = '\0';
  5894. strcpy(validFromstr,sstr);
  5895. }
  5896. //****************validTo*******************/
  5897. loc = strstr(payload, "validTo");
  5898. if(loc == NULL)
  5899. {
  5900. validToIsNULL = TRUE;
  5901. }
  5902. else
  5903. {
  5904. c = 0;
  5905. memset(sstr ,0, sizeof(sstr) );
  5906. while (loc[3+strlen("validTo")+c] != '\"')
  5907. {
  5908. sstr[c] = loc[3+strlen("validTo")+c];
  5909. c++;
  5910. }
  5911. sstr[c] = '\0';
  5912. strcpy(validTostr,sstr);
  5913. }
  5914. //****************chargingSchedule*******************/
  5915. loc = strstr(payload, "chargingSchedule");
  5916. if(loc != NULL)
  5917. {
  5918. //****************duration*******************/
  5919. loc = strstr(payload, "duration");
  5920. if(loc == NULL)
  5921. {
  5922. durationIsNULL = TRUE;
  5923. }
  5924. else
  5925. {
  5926. c=0;
  5927. memset(sstr ,0, sizeof(sstr) );
  5928. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5929. {
  5930. sstr[c] = loc[strlen("duration")+2+c];
  5931. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5932. c++;
  5933. }
  5934. sstr[c] = '\0';
  5935. durationInt = atoi(sstr);
  5936. }
  5937. //****************startSchedule******************/
  5938. loc = strstr(payload, "startSchedule");
  5939. if(loc == NULL)
  5940. {
  5941. startScheduleIsNULL = TRUE;
  5942. }
  5943. else
  5944. {
  5945. c = 0;
  5946. memset(sstr ,0, sizeof(sstr) );
  5947. while (loc[3+strlen("startSchedule")+c] != '\"')
  5948. {
  5949. sstr[c] = loc[3+strlen("startSchedule")+c];
  5950. c++;
  5951. }
  5952. sstr[c] = '\0';
  5953. strcpy(startSchedulestr,sstr);
  5954. }
  5955. //****************chargingRateUnit*******************/
  5956. c = 0;
  5957. memset(sstr ,0, sizeof(sstr) );
  5958. loc = strstr(payload, "chargingRateUnit");
  5959. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5960. {
  5961. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5962. c++;
  5963. }
  5964. sstr[c] = '\0';
  5965. strcpy(chargingRateUnitstr,sstr);
  5966. //****************minChargingRate*******************/
  5967. loc = strstr(payload, "minChargingRate");
  5968. if(loc == NULL)
  5969. {
  5970. minChargingRateIsNULL = TRUE;
  5971. }
  5972. else
  5973. {
  5974. c=0;
  5975. memset(sstr ,0, sizeof(sstr) );
  5976. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5977. {
  5978. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5979. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5980. c++;
  5981. }
  5982. sstr[c] = '\0';
  5983. minChargingRateflaot = atof(sstr);
  5984. }
  5985. //****************chargingSchedulePeriod count*******************/
  5986. int what_len = strlen("startPeriod");
  5987. char *where = payload;
  5988. while ((where = strstr(where, "startPeriod"))) {
  5989. where += what_len;
  5990. chargingSchedulePeriodCount++;
  5991. }
  5992. where = payload;
  5993. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5994. {
  5995. //****************startPeriod*******************/
  5996. c=0;
  5997. loc = strstr(where, "startPeriod");
  5998. memset(sstr ,0, sizeof(sstr) );
  5999. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6000. {
  6001. sstr[c] = loc[strlen("startPeriod")+2+c];
  6002. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6003. c++;
  6004. }
  6005. sstr[c] = '\0';
  6006. startPeriodInt[periodNums] = atoi(sstr);
  6007. //****************limit*******************/
  6008. c=0;
  6009. loc = strstr(where, "limit");
  6010. memset(sstr ,0, sizeof(sstr) );
  6011. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6012. {
  6013. sstr[c] = loc[strlen("limit")+2+c];
  6014. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6015. c++;
  6016. }
  6017. sstr[c] = '\0';
  6018. limitflaot[periodNums] = atof(sstr);
  6019. //****************numberPhases*******************/
  6020. loc = strstr(where, "numberPhases");
  6021. if(loc == NULL)
  6022. {
  6023. numberPhasesIsNULL = TRUE;
  6024. }
  6025. else
  6026. {
  6027. c=0;
  6028. memset(sstr ,0, sizeof(sstr) );
  6029. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6030. {
  6031. sstr[c] = loc[strlen("numberPhases")+2+c];
  6032. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6033. c++;
  6034. }
  6035. sstr[c] = '\0';
  6036. numberPhasesInt[periodNums] = atoi(sstr);
  6037. }
  6038. where = loc;
  6039. }
  6040. }
  6041. }
  6042. /*
  6043. enum _SYSTEM_STATUS
  6044. {
  6045. S_BOOTING = 0,
  6046. S_IDLE, = 1
  6047. S_AUTHORIZING, =2
  6048. S_REASSIGN_CHECK, =3
  6049. S_REASSIGN, =4
  6050. S_PRECHARGE, =5
  6051. S_PREPARING_FOR_EV, =6
  6052. S_PREPARING_FOR_EVSE, =7
  6053. S_CHARGING, =8
  6054. S_TERMINATING, =9
  6055. S_COMPLETE, =10
  6056. S_ALARM, =11
  6057. S_FAULT =12
  6058. }
  6059. */
  6060. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6061. {
  6062. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6063. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6064. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6065. //check Transaction active
  6066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6067. {
  6068. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6069. {
  6070. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6071. {
  6072. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6073. {
  6074. //Reserved
  6075. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6076. }
  6077. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6078. {
  6079. //Reserved
  6080. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6081. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6082. goto end;
  6083. }
  6084. else
  6085. {
  6086. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6087. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6088. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6089. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6090. {
  6091. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6092. goto end;
  6093. }
  6094. }//END FOR ELSE
  6095. }
  6096. }// END FOR CHAdeMO_QUANTITY
  6097. for (int index = 0; index < CCS_QUANTITY; index++)
  6098. {
  6099. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6100. {
  6101. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6102. {
  6103. //Reserved
  6104. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6105. }
  6106. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6107. {
  6108. //Reserved
  6109. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6110. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6111. goto end;
  6112. }
  6113. else
  6114. {
  6115. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6116. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6117. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6118. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6119. {
  6120. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6121. goto end;
  6122. }
  6123. }// END FOR ELSE
  6124. }
  6125. }// END FOR CCS_QUANTITY
  6126. for (int index = 0; index < GB_QUANTITY; index++)
  6127. {
  6128. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6129. {
  6130. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6131. {
  6132. //Reserved
  6133. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6134. }
  6135. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6136. {
  6137. //Reserved
  6138. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6139. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6140. goto end;
  6141. }
  6142. else
  6143. {
  6144. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6145. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6146. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6147. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6148. {
  6149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6150. goto end;
  6151. }
  6152. }// END FOR ELSE
  6153. }
  6154. } // END FOR GB_QUANTITY
  6155. }
  6156. else
  6157. {
  6158. for (int index = 0; index < AC_QUANTITY; index++)
  6159. {
  6160. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6161. {
  6162. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6163. {
  6164. //Reserved
  6165. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6166. }
  6167. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6168. {
  6169. //Reserved
  6170. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6171. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6172. goto end;
  6173. }
  6174. else
  6175. {
  6176. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6177. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6178. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6179. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6180. {
  6181. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6182. goto end;
  6183. }
  6184. }//END FOR ELSE
  6185. }
  6186. }// END FOR AC_QUANTITY
  6187. }
  6188. if(chargingProfileIsNULL == FALSE)
  6189. {
  6190. //ChargingProfile
  6191. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6192. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6193. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6194. if(recurrencyKindIsNULL == FALSE) //OPTION
  6195. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6196. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6197. if(transactionIdIsNULL == FALSE) // OPTION
  6198. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6199. if(validFromIsNULL == FALSE) // OPTION
  6200. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6201. if(validToIsNULL == FALSE) //OPTION
  6202. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6203. //ChargingSchedule
  6204. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6205. if(durationIsNULL == FALSE) //OPTION
  6206. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6207. if(minChargingRateIsNULL == FALSE) //OPTION
  6208. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6209. if(startScheduleIsNULL == FALSE) //OPTION
  6210. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6211. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6212. {
  6213. //ChargingSchedulePeriod
  6214. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6215. if(numberPhasesIsNULL == FALSE)
  6216. {
  6217. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6218. }
  6219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6220. }
  6221. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6222. {
  6223. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6224. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6225. //memset idTag
  6226. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6227. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6228. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6229. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6230. }
  6231. else
  6232. {
  6233. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6234. }
  6235. }
  6236. else
  6237. {
  6238. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6239. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6240. //memset idTag
  6241. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6242. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6243. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6244. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6245. }
  6246. }
  6247. else
  6248. {
  6249. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6250. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6251. }
  6252. end:
  6253. if(connectorIdIsNULL == FALSE)
  6254. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6255. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6256. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6257. //OCPP send RemoteStartConfirmation by first.
  6258. sendRemoteStartConfirmation(uuid, comfirmstr);
  6259. return result;
  6260. }
  6261. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6262. {
  6263. mtrace();
  6264. int result = FAIL;
  6265. int match = FALSE;
  6266. int GunNO = 0;
  6267. int transactionIdInt=0;
  6268. int transactionIdIsNULL= FALSE;
  6269. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6270. int c = 0;
  6271. char *loc;
  6272. char comfirmstr[20];
  6273. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6274. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6275. if(server_pending == TRUE)
  6276. {
  6277. return 0;
  6278. }
  6279. c=0;
  6280. loc = strstr(payload, "transactionId");
  6281. if(loc == NULL)
  6282. {
  6283. transactionIdIsNULL= TRUE;
  6284. }
  6285. else
  6286. {
  6287. memset(sstr ,0, sizeof(sstr) );
  6288. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6289. {
  6290. sstr[c] = loc[strlen("transactionId")+2+c];
  6291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6292. c++;
  6293. }
  6294. sstr[c] = '\0';
  6295. transactionIdInt = atoi(sstr);
  6296. }
  6297. if(transactionIdIsNULL == FALSE)
  6298. {
  6299. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6300. {
  6301. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6302. {
  6303. //check Transaction active
  6304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6305. {
  6306. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6307. {
  6308. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6309. {
  6310. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6311. {
  6312. match = TRUE;
  6313. GunNO = gun_index;
  6314. }
  6315. }
  6316. }// END FOR CHAdeMO_QUANTITY
  6317. for (int index = 0; index < CCS_QUANTITY; index++)
  6318. {
  6319. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6320. {
  6321. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6322. {
  6323. match = TRUE;
  6324. GunNO = gun_index;
  6325. }
  6326. }
  6327. }// END FOR CCS_QUANTITY
  6328. for (int index = 0; index < GB_QUANTITY; index++)
  6329. {
  6330. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6331. {
  6332. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6333. {
  6334. match = TRUE;
  6335. GunNO = gun_index;
  6336. }
  6337. }
  6338. }// END FOR GB_QUANTITY
  6339. }
  6340. else
  6341. {
  6342. for (int index = 0; index < AC_QUANTITY; index++)
  6343. {
  6344. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6345. {
  6346. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6347. {
  6348. match = TRUE;
  6349. GunNO = gun_index;
  6350. }
  6351. }
  6352. }// END FOR CHAdeMO_QUANTITY
  6353. }// END FOR AC ELSE
  6354. }// CHECK IF ResponseTransactionId == transactionIdInt
  6355. }//END FOR
  6356. if( match == TRUE)
  6357. {
  6358. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6359. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6360. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6361. }
  6362. else
  6363. {
  6364. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6365. }
  6366. }
  6367. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6368. return result;
  6369. }
  6370. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6371. {
  6372. mtrace();
  6373. int result = FAIL;
  6374. int connectorIdInt=0, reservationIdInt=0;
  6375. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6376. char comfirmstr[20]={0};
  6377. char sstr[180]={ 0 };
  6378. int c = 0;
  6379. char *loc;
  6380. //char *ptr;
  6381. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6382. //***(1)connectorId ****/
  6383. c=0;
  6384. loc = strstr(payload, "connectorId");
  6385. memset(sstr ,0, sizeof(sstr) );
  6386. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6387. {
  6388. sstr[c] = loc[strlen("connectorId")+2+c];
  6389. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6390. c++;
  6391. }
  6392. sstr[c] = '\0';
  6393. connectorIdInt = atoi(sstr);
  6394. //***(2)expiryDate ****/
  6395. loc = strstr(payload, "expiryDate");
  6396. memset(sstr ,0, sizeof(sstr) );
  6397. c = 0;
  6398. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6399. {
  6400. sstr[c] = loc[3+strlen("expiryDate")+c];
  6401. c++;
  6402. }
  6403. sstr[c] = '\0';
  6404. strcpy(expiryDatestr, sstr);
  6405. //***(3)idTag ****/
  6406. loc = strstr(payload, "idTag");
  6407. memset(sstr ,0, sizeof(sstr) );
  6408. c = 0;
  6409. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6410. {
  6411. sstr[c] = loc[3+strlen("idTag")+c];
  6412. c++;
  6413. }
  6414. sstr[c] = '\0';
  6415. strcpy(idTagstr, sstr);
  6416. //***(4)parentIdTag ****/
  6417. loc = strstr(payload, "parentIdTag");
  6418. memset(sstr ,0, sizeof(sstr) );
  6419. c = 0;
  6420. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6421. {
  6422. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6423. c++;
  6424. }
  6425. sstr[c] = '\0';
  6426. strcpy(parentIdTagstr, sstr);
  6427. //***(5)reservationId ****/
  6428. c=0;
  6429. loc = strstr(payload, "reservationId");
  6430. memset(sstr ,0, sizeof(sstr) );
  6431. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6432. {
  6433. sstr[c] = loc[strlen("reservationId")+2+c];
  6434. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6435. c++;
  6436. }
  6437. sstr[c] = '\0';
  6438. reservationIdInt = atoi(sstr);
  6439. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6440. /*
  6441. enum _SYSTEM_STATUS
  6442. {
  6443. S_BOOTING = 0,
  6444. S_IDLE, = 1
  6445. S_AUTHORIZING, =2
  6446. S_REASSIGN_CHECK, =3
  6447. S_REASSIGN, =4
  6448. S_PRECHARGE, =5
  6449. S_PREPARING_FOR_EV, =6
  6450. S_PREPARING_FOR_EVSE, =7
  6451. S_CHARGING, =8
  6452. S_TERMINATING, =9
  6453. S_COMPLETE, =10
  6454. S_ALARM, =11
  6455. S_FAULT =12
  6456. }
  6457. */
  6458. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6459. {
  6460. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6461. goto end;
  6462. }
  6463. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6464. {
  6465. //check Transaction active
  6466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6467. {
  6468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6469. {
  6470. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6471. {
  6472. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6473. {
  6474. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6475. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6476. {
  6477. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6478. {
  6479. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6481. }
  6482. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6483. {
  6484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6485. }
  6486. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6487. {
  6488. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6489. }
  6490. else
  6491. {
  6492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6493. }
  6494. }
  6495. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6496. {
  6497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6498. }
  6499. }
  6500. else
  6501. {
  6502. //replace reservation
  6503. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6504. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6505. }
  6506. }
  6507. } // END FOR CHAdeMO_QUANTITY
  6508. for (int index = 0; index < CCS_QUANTITY; index++)
  6509. {
  6510. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6511. {
  6512. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6513. {
  6514. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6515. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6516. {
  6517. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6518. {
  6519. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6521. }
  6522. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6523. {
  6524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6525. }
  6526. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6527. {
  6528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6529. }
  6530. else
  6531. {
  6532. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6533. }
  6534. }
  6535. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6536. {
  6537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6538. }
  6539. }
  6540. else
  6541. {
  6542. //replace reservation
  6543. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6544. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6545. }
  6546. }
  6547. } // END FOR CCS_QUANTITY
  6548. for (int index = 0; index < GB_QUANTITY; index++)
  6549. {
  6550. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6551. {
  6552. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6553. {
  6554. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6555. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6556. {
  6557. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6558. {
  6559. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6561. }
  6562. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6563. {
  6564. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6565. }
  6566. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6567. {
  6568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6569. }
  6570. else
  6571. {
  6572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6573. }
  6574. }
  6575. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6576. {
  6577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6578. }
  6579. }
  6580. else
  6581. {
  6582. //replace reservation
  6583. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6585. }
  6586. }
  6587. }// END FOR GB_QUANTITY
  6588. }
  6589. else
  6590. {
  6591. for (int index = 0; index < AC_QUANTITY; index++)
  6592. {
  6593. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6594. {
  6595. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6596. {
  6597. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6598. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6599. {
  6600. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6601. {
  6602. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6604. }
  6605. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6606. {
  6607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6608. }
  6609. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6610. {
  6611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6612. }
  6613. else
  6614. {
  6615. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6616. }
  6617. }
  6618. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6619. {
  6620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6621. }
  6622. }
  6623. else
  6624. {
  6625. //replace reservation
  6626. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6628. }
  6629. }
  6630. } // END FOR AC_QUANTITY
  6631. }//END FOR AC ELSE
  6632. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6633. }
  6634. else if(connectorIdInt == 0)
  6635. {
  6636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6637. {
  6638. //check Transaction active
  6639. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6640. {
  6641. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6642. {
  6643. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6644. {
  6645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6646. goto end;
  6647. }
  6648. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6649. {
  6650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6651. goto end;
  6652. }
  6653. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6654. {
  6655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6656. goto end;
  6657. }
  6658. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6659. {
  6660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6661. goto end;
  6662. }
  6663. }
  6664. }// END FOR CHAdeMO_QUANTITY
  6665. for (int index = 0; index < CCS_QUANTITY; index++)
  6666. {
  6667. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6668. {
  6669. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6670. {
  6671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6672. }
  6673. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6674. {
  6675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6676. }
  6677. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6678. {
  6679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6680. }
  6681. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6682. {
  6683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6684. }
  6685. }
  6686. } // END FOR CCS_QUANTITY
  6687. for (int index = 0; index < GB_QUANTITY; index++)
  6688. {
  6689. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6690. {
  6691. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6692. {
  6693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6694. }
  6695. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6696. {
  6697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6698. }
  6699. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6700. {
  6701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6702. }
  6703. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6704. {
  6705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6706. }
  6707. }
  6708. } // END FOR GB_QUANTITY
  6709. }
  6710. else
  6711. {
  6712. for (int index = 0; index < AC_QUANTITY; index++)
  6713. {
  6714. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6715. {
  6716. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6717. {
  6718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6719. goto end;
  6720. }
  6721. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6722. {
  6723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6724. goto end;
  6725. }
  6726. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6727. {
  6728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6729. goto end;
  6730. }
  6731. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6732. {
  6733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6734. goto end;
  6735. }
  6736. }
  6737. }// END FOR AC_QUANTITY
  6738. }
  6739. //The connectorId is 0
  6740. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6742. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6743. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6744. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6745. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6746. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6747. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6748. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6749. result = TRUE;
  6750. return result;
  6751. }
  6752. else
  6753. {
  6754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6755. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6756. }
  6757. if(strcmp(comfirmstr,"Accepted") == 0)
  6758. {
  6759. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6760. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6761. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6762. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6763. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6764. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6765. result = TRUE;
  6766. return result;
  6767. }
  6768. end:
  6769. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6770. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6771. return result;
  6772. }
  6773. int handleResetRequest(char *uuid, char *payload)
  6774. {
  6775. mtrace();
  6776. int result = FAIL;
  6777. char sstr[10]={0};
  6778. char typestr[10]={0};
  6779. char comfirmstr[20]={0};
  6780. int c = 0;
  6781. char *loc;
  6782. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6783. DEBUG_INFO("handleResetRequest ...\n");
  6784. loc = strstr(payload, "type");
  6785. memset(sstr ,0, sizeof(sstr) );
  6786. c = 0;
  6787. while (loc[3+strlen("type")+c] != '\"')
  6788. {
  6789. sstr[c] = loc[3+strlen("type")+c];
  6790. c++;
  6791. }
  6792. sstr[c] = '\0';
  6793. strcpy(typestr,sstr);
  6794. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6795. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6796. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6797. {
  6798. //check Transaction active
  6799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6800. {
  6801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6802. {
  6803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6804. {
  6805. //0: unplug, 1: Plug-in
  6806. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6807. }
  6808. }
  6809. for (int index = 0; index < CCS_QUANTITY; index++)
  6810. {
  6811. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6812. {
  6813. //0: unplug, 1: Plug-in
  6814. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6815. }
  6816. }
  6817. for (int index = 0; index < GB_QUANTITY; index++)
  6818. {
  6819. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6820. {
  6821. //0: unplug, 1: Plug-in
  6822. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6823. }
  6824. }
  6825. }
  6826. else
  6827. {
  6828. for (int index = 0; index < AC_QUANTITY; index++)
  6829. {
  6830. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6831. {
  6832. //0: unplug, 1: Plug-in
  6833. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6834. }
  6835. }
  6836. }// END FOR AC ELSE
  6837. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6838. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6839. result = TRUE;
  6840. return result;
  6841. }
  6842. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6843. {
  6844. //check Transaction active
  6845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6846. {
  6847. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6848. {
  6849. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6850. {
  6851. //0: unplug, 1: Plug-in
  6852. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6853. }
  6854. }
  6855. for (int index = 0; index < CCS_QUANTITY; index++)
  6856. {
  6857. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6858. {
  6859. //0: unplug, 1: Plug-in
  6860. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6861. }
  6862. }
  6863. for (int index = 0; index < GB_QUANTITY; index++)
  6864. {
  6865. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6866. {
  6867. //0: unplug, 1: Plug-in
  6868. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6869. }
  6870. }
  6871. }
  6872. else
  6873. {
  6874. for (int index = 0; index < AC_QUANTITY; index++)
  6875. {
  6876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6877. {
  6878. //0: unplug, 1: Plug-in
  6879. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6880. }
  6881. }
  6882. }// END FOR AC ELSE
  6883. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6884. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6885. result = TRUE;
  6886. return result;
  6887. }
  6888. else
  6889. {
  6890. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6891. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6892. goto errorend;
  6893. }
  6894. errorend:
  6895. sendResetConfirmation(uuid, comfirmstr);
  6896. return result;
  6897. }
  6898. int handleSendLocalListRequest(char *uuid, char *payload)
  6899. {
  6900. mtrace();
  6901. int result = FAIL;
  6902. int listVersionInt;
  6903. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6904. char listsearch[]="listVersion";
  6905. char updateTypesearch[]="updateType";
  6906. char localAuthorizationListsearch[]="localAuthorizationList";
  6907. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6908. char CardList[500][160]={0};
  6909. char updateTypestr[15]={0};
  6910. char idTagstr[20]={0};
  6911. char parentIdTag[20]={0};
  6912. char expiryDate[30]={0};
  6913. char idTagstatus[16]={0};
  6914. int c = 0;
  6915. int i = 0;
  6916. char *delim1 = "}";
  6917. char * pch;
  6918. char *loc;
  6919. //char *ptr;
  6920. char comfirmstr[20];
  6921. //int n_localAuthorizations = 0;
  6922. int checkState_Faulted = FALSE;
  6923. DEBUG_INFO("handleSendLocalListRequest\n");
  6924. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6925. {
  6926. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6927. goto end;
  6928. }
  6929. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6930. {
  6931. //check Charge Point state
  6932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6933. {
  6934. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6935. {
  6936. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6937. }
  6938. }
  6939. for (int index = 0; index < CCS_QUANTITY; index++)
  6940. {
  6941. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6942. {
  6943. checkState_Faulted = TRUE; //OCPP Status
  6944. }
  6945. }
  6946. for (int index = 0; index < GB_QUANTITY; index++)
  6947. {
  6948. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6949. {
  6950. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6951. }
  6952. }
  6953. }
  6954. else
  6955. {
  6956. //check Charge Point state
  6957. for (int index = 0; index < AC_QUANTITY; index++)
  6958. {
  6959. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6960. {
  6961. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6962. }
  6963. }
  6964. }// END FOR AC ELSE
  6965. if(checkState_Faulted == TRUE)
  6966. {
  6967. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6968. goto end;
  6969. }
  6970. //listVersion
  6971. c = 0;
  6972. loc = strstr(payload, listsearch);
  6973. while (loc[strlen("listVersion")+2+c] != ',')
  6974. {
  6975. sstr[c] = loc[strlen("listVersion")+2+c];
  6976. c++;
  6977. }
  6978. sstr[c] = '\0';
  6979. listVersionInt = atoi(sstr);
  6980. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6981. //updateType
  6982. loc = strstr(payload, updateTypesearch);
  6983. c = 0;
  6984. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6985. {
  6986. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6987. c++;
  6988. }
  6989. sstr[c] = '\0';
  6990. strcpy(updateTypestr, sstr);
  6991. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6992. //localAuthorizationList
  6993. memset(sstr ,0, sizeof(sstr) );
  6994. loc = strstr(payload, localAuthorizationListsearch);
  6995. if(loc != NULL) // localAuthorizationList is not NULL
  6996. {
  6997. //Check UpdateType
  6998. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6999. {
  7000. //Local list full update
  7001. printf("Local list full update.\n");
  7002. OCPP_cleanLocalList();
  7003. }
  7004. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7005. {
  7006. //Local list different update
  7007. printf("Local list different update.\n");
  7008. OCPP_getListVerion();
  7009. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7010. {
  7011. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7012. goto end;
  7013. }
  7014. }
  7015. else
  7016. {
  7017. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7018. goto end;
  7019. }
  7020. c = 0;
  7021. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7022. {
  7023. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7025. c++;
  7026. }
  7027. sstr[c] = '\0';
  7028. //parsing strings to words
  7029. i = 0;
  7030. pch = strtok(sstr,delim1);
  7031. while (pch != NULL)
  7032. {
  7033. strcpy(CardList[i], pch);
  7034. pch = strtok (NULL, delim1);
  7035. i = i + 1;
  7036. }
  7037. //local Authorizations List Numbers
  7038. //n_localAuthorizations = i;
  7039. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7040. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7041. c= 0;
  7042. while(c < i)
  7043. {
  7044. //Search "IdToken"
  7045. memset(sstr ,0, sizeof(sstr) );
  7046. loc = strstr(CardList[c], "idTag");
  7047. int j = 0;
  7048. while (loc[3+strlen("idTag")+j] != '\"')
  7049. {
  7050. sstr[j] = loc[3+strlen("idTag")+j];
  7051. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7052. j++;
  7053. }
  7054. sstr[j] = '\0';
  7055. strcpy(idTagstr, sstr);
  7056. //Search "expiryDate"
  7057. memset(sstr ,0, sizeof(sstr) );
  7058. loc = strstr(CardList[c], "expiryDate");
  7059. j = 0;
  7060. while (loc[3+strlen("expiryDate")+j] != '\"')
  7061. {
  7062. sstr[j] = loc[3+strlen("expiryDate")+j];
  7063. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7064. j++;
  7065. }
  7066. sstr[j] = '\0';
  7067. strcpy(expiryDate, sstr);
  7068. //Search "parentIdTag"
  7069. memset(sstr ,0, sizeof(sstr) );
  7070. loc = strstr(CardList[c], "parentIdTag");
  7071. j = 0;
  7072. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7073. {
  7074. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7075. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7076. j++;
  7077. }
  7078. sstr[j] = '\0';
  7079. strcpy(parentIdTag, sstr);
  7080. //Search "status"
  7081. memset(sstr ,0, sizeof(sstr) );
  7082. loc = strstr(CardList[c], "status");
  7083. j = 0;
  7084. while (loc[3+strlen("status")+j] != '\"')
  7085. {
  7086. sstr[j] = loc[3+strlen("status")+j];
  7087. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7088. j++;
  7089. }
  7090. sstr[j] = '\0';
  7091. strcpy(idTagstatus, sstr);
  7092. OCPP_getIdTag(idTagstr);
  7093. //OCPP_getIdTag("test"); For Test
  7094. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7095. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7096. {
  7097. //Local list full update
  7098. DEBUG_INFO("Local list full update.\n");
  7099. // update list
  7100. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7101. OCPP_get_TableAuthlocalAllData();
  7102. }
  7103. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7104. {
  7105. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7106. {
  7107. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7108. }
  7109. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7110. {
  7111. OCPP_deleteIdTag(idTagstr);
  7112. }
  7113. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7114. {
  7115. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7116. }
  7117. }
  7118. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7119. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7120. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7121. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7122. c++;
  7123. }
  7124. }
  7125. else
  7126. {
  7127. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7128. {
  7129. //Local list different update
  7130. DEBUG_INFO("Local list different update.\n");
  7131. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7132. goto end;
  7133. }
  7134. }
  7135. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7136. end:
  7137. sendSendLocalListConfirmation(uuid, comfirmstr);
  7138. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7139. #if 0
  7140. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7141. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7142. #endif
  7143. return result;
  7144. }
  7145. /*
  7146. enum _SYSTEM_STATUS
  7147. {
  7148. S_BOOTING = 0,
  7149. S_IDLE, =1
  7150. S_AUTHORIZING, =2
  7151. S_REASSIGN_CHECK, =3
  7152. S_REASSIGN, =4
  7153. S_PRECHARGE, =5
  7154. S_PREPARING_FOR_EV, =6
  7155. S_PREPARING_FOR_EVSE, =7
  7156. S_CHARGING, =8
  7157. S_TERMINATING, =9
  7158. S_COMPLETE, =10
  7159. S_ALARM, =11
  7160. S_FAULT =12
  7161. };
  7162. */
  7163. #define MAX 200
  7164. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7165. {
  7166. mtrace();
  7167. int result = FAIL;
  7168. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7169. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7170. char chargingProfilePurposeStr[30]={0};
  7171. char chargingProfileKindStr[16]={0};
  7172. char recurrencyKindStr[10]={0};
  7173. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7174. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7175. int chargingSchedulePeriodCount = 0;
  7176. //int updateflag = FALSE;
  7177. char comfirmstr[20]={0};
  7178. int meet= FALSE;
  7179. char sstr[10]={0};
  7180. int c = 0;
  7181. char *loc;
  7182. FILE *fptr1;//, *fptr2;
  7183. //int lno=0;//, linectr = 0;
  7184. //int modifyflag = FALSE;
  7185. char filename[MAX]={0};
  7186. char tempfile[] = "../Storage/OCPP/temp.json";
  7187. int resultRename=0;
  7188. char rmFileCmd[50]={0};
  7189. char tempchargingProfilePurposeStr[30]={0};
  7190. //[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}}}]
  7191. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7192. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7193. //*********************connectorId***************************/
  7194. loc = strstr(payload, "connectorId");
  7195. c = 0;
  7196. memset(sstr ,0, sizeof(sstr) );
  7197. while (loc[strlen("connectorId")+2+c] != ',')
  7198. {
  7199. sstr[c] = loc[strlen("connectorId")+2+c];
  7200. c++;
  7201. }
  7202. sstr[c] = '\0';
  7203. connectorIdInt = atoi(sstr);
  7204. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7205. {
  7206. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7207. }
  7208. else
  7209. {
  7210. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7211. }
  7212. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7213. //*********************chargingProfileId***************************/
  7214. loc = strstr(payload, "chargingProfileId");
  7215. c = 0;
  7216. memset(sstr ,0, sizeof(sstr) );
  7217. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7218. {
  7219. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7220. c++;
  7221. }
  7222. sstr[c] = '\0';
  7223. chargingProfileIdInt = atoi(sstr);
  7224. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7225. {
  7226. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7227. }
  7228. else
  7229. {
  7230. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7231. }
  7232. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7233. //*********************transactionId***************************/
  7234. loc = strstr(payload, "transactionId");
  7235. if(loc != NULL)
  7236. {
  7237. c = 0;
  7238. memset(sstr ,0, sizeof(sstr) );
  7239. while (loc[strlen("transactionId")+2+c] != ',')
  7240. {
  7241. sstr[c] = loc[strlen("transactionId")+2+c];
  7242. c++;
  7243. }
  7244. sstr[c] = '\0';
  7245. transactionIdInt = atoi(sstr);
  7246. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7247. {
  7248. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7249. }
  7250. else
  7251. {
  7252. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7253. }
  7254. }
  7255. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7256. //*********************stackLevel***************************/
  7257. loc = strstr(payload, "stackLevel");
  7258. c = 0;
  7259. memset(sstr ,0, sizeof(sstr) );
  7260. while (loc[strlen("stackLevel")+2+c] != ',')
  7261. {
  7262. sstr[c] = loc[strlen("stackLevel")+2+c];
  7263. c++;
  7264. }
  7265. sstr[c] = '\0';
  7266. stackLevelInt = atoi(sstr);
  7267. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7268. {
  7269. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7270. }
  7271. else
  7272. {
  7273. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7274. }
  7275. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7276. //*********************chargingProfilePurpose***************************/
  7277. loc = strstr(payload, "chargingProfilePurpose");
  7278. c = 0;
  7279. memset(sstr ,0, sizeof(sstr) );
  7280. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7281. {
  7282. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7284. c++;
  7285. }
  7286. sstr[c] = '\0';
  7287. strcpy(chargingProfilePurposeStr,sstr);
  7288. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7289. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7290. {
  7291. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7292. }
  7293. else
  7294. {
  7295. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7296. }
  7297. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7298. //*********************chargingProfileKind***************************/
  7299. loc = strstr(payload, "chargingProfileKind");
  7300. c = 0;
  7301. memset(sstr ,0, sizeof(sstr) );
  7302. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7303. {
  7304. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7306. c++;
  7307. }
  7308. sstr[c] = '\0';
  7309. strcpy(chargingProfileKindStr,sstr);
  7310. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7311. {
  7312. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7313. }
  7314. else
  7315. {
  7316. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7317. }
  7318. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7319. //*********************recurrencyKind***************************/
  7320. loc = strstr(payload, "recurrencyKind");
  7321. if(loc != NULL)
  7322. {
  7323. c = 0;
  7324. memset(sstr ,0, sizeof(sstr) );
  7325. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7326. {
  7327. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7328. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7329. c++;
  7330. }
  7331. sstr[c] = '\0';
  7332. strcpy(recurrencyKindStr,sstr);
  7333. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7334. {
  7335. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7336. }
  7337. else
  7338. {
  7339. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7340. }
  7341. }
  7342. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7343. //*********************validFrom***************************/
  7344. loc = strstr(payload, "validFrom");
  7345. if(loc != NULL)
  7346. {
  7347. c = 0;
  7348. memset(sstr ,0, sizeof(sstr) );
  7349. while (loc[3+strlen("validFrom")+c] != '\"')
  7350. {
  7351. sstr[c] = loc[3+strlen("validFrom")+c];
  7352. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7353. c++;
  7354. }
  7355. sstr[c] = '\0';
  7356. strcpy(validFromStr,sstr);
  7357. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7358. {
  7359. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7360. }
  7361. else
  7362. {
  7363. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7364. }
  7365. }
  7366. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7367. //*********************validTo***************************/
  7368. loc = strstr(payload, "validTo");
  7369. if(loc != NULL)
  7370. {
  7371. c = 0;
  7372. memset(sstr ,0, sizeof(sstr) );
  7373. while (loc[3+strlen("validTo")+c] != '\"')
  7374. {
  7375. sstr[c] = loc[3+strlen("validTo")+c];
  7376. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7377. c++;
  7378. }
  7379. sstr[c] = '\0';
  7380. strcpy(validToStr,sstr);
  7381. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7382. {
  7383. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7384. }
  7385. else
  7386. {
  7387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7388. }
  7389. }
  7390. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7391. //*********************duration***************************/
  7392. loc = strstr(payload, "duration");
  7393. if(loc != NULL)
  7394. {
  7395. c = 0;
  7396. memset(sstr ,0, sizeof(sstr) );
  7397. while (loc[strlen("duration")+2+c] != ',')
  7398. {
  7399. sstr[c] = loc[strlen("duration")+2+c];
  7400. c++;
  7401. }
  7402. sstr[c] = '\0';
  7403. durationInt = atoi(sstr);
  7404. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7405. {
  7406. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7407. }
  7408. else
  7409. {
  7410. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7411. }
  7412. }
  7413. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7414. //*********************startSchedule***************************/
  7415. loc = strstr(payload, "startSchedule");
  7416. if(loc != NULL)
  7417. {
  7418. c = 0;
  7419. memset(sstr ,0, sizeof(sstr) );
  7420. while (loc[3+strlen("startSchedule")+c] != '\"')
  7421. {
  7422. sstr[c] = loc[3+strlen("startSchedule")+c];
  7423. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7424. c++;
  7425. }
  7426. sstr[c] = '\0';
  7427. strcpy(startScheduleStr,sstr);
  7428. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7429. {
  7430. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7431. }
  7432. else
  7433. {
  7434. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7435. }
  7436. }
  7437. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7438. //*********************chargingRateUnit***************************/
  7439. loc = strstr(payload, "chargingRateUnit");
  7440. if(loc != NULL)
  7441. {
  7442. c = 0;
  7443. memset(sstr ,0, sizeof(sstr) );
  7444. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7445. {
  7446. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7447. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7448. c++;
  7449. }
  7450. sstr[c] = '\0';
  7451. strcpy(chargingRateUnitStr,sstr);
  7452. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7453. {
  7454. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7455. }
  7456. else
  7457. {
  7458. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7459. }
  7460. }
  7461. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7462. //****************chargingSchedulePeriod count start*******************/
  7463. int what_len = strlen("startPeriod");
  7464. char *where = payload;
  7465. if (what_len)
  7466. while ((where = strstr(where, "startPeriod"))) {
  7467. where += what_len;
  7468. chargingSchedulePeriodCount++;
  7469. }
  7470. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7471. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7472. where = payload;
  7473. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7474. {
  7475. //****************startPeriod*******************/
  7476. c=0;
  7477. loc = strstr(where, "startPeriod");
  7478. memset(sstr ,0, sizeof(sstr) );
  7479. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7480. {
  7481. sstr[c] = loc[strlen("startPeriod")+2+c];
  7482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7483. c++;
  7484. }
  7485. sstr[c] = '\0';
  7486. startPeriodInt[periodNums] = atoi(sstr);
  7487. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7488. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7489. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7490. {
  7491. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7492. }
  7493. else
  7494. {
  7495. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7496. }
  7497. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7498. //****************limit*******************/
  7499. c=0;
  7500. loc = strstr(where, "limit");
  7501. memset(sstr ,0, sizeof(sstr) );
  7502. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7503. {
  7504. sstr[c] = loc[strlen("limit")+2+c];
  7505. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7506. c++;
  7507. }
  7508. sstr[c] = '\0';
  7509. limitflaot[periodNums] = atof(sstr);
  7510. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7511. {
  7512. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7513. }
  7514. else
  7515. {
  7516. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7517. }
  7518. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7519. //****************numberPhases*******************/
  7520. loc = strstr(where, "numberPhases");
  7521. if(loc != NULL)
  7522. {
  7523. c=0;
  7524. memset(sstr ,0, sizeof(sstr) );
  7525. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7526. {
  7527. sstr[c] = loc[strlen("numberPhases")+2+c];
  7528. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7529. c++;
  7530. }
  7531. sstr[c] = '\0';
  7532. numberPhasesInt[periodNums] = atoi(sstr);
  7533. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7534. {
  7535. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7536. }
  7537. else
  7538. {
  7539. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7540. }
  7541. }
  7542. where = loc;
  7543. }
  7544. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7545. //****************chargingSchedulePeriod count end*******************/
  7546. //*********************minChargingRate***************************/
  7547. loc = strstr(payload, "minChargingRate");
  7548. if(loc != NULL)
  7549. {
  7550. c = 0;
  7551. memset(sstr ,0, sizeof(sstr) );
  7552. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7553. {
  7554. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7555. c++;
  7556. }
  7557. sstr[c] = '\0';
  7558. minChargingRateFloat = atof(sstr);
  7559. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7560. {
  7561. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7562. }
  7563. else
  7564. {
  7565. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7566. }
  7567. }
  7568. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7569. DEBUG_INFO("-------------------------------------------------------------\n");
  7570. DEBUG_INFO(" Input the file name to be opened : ");
  7571. //fgets(fname, MAX, stdin);
  7572. //fname[strlen(fname) - 1] = '\0';
  7573. #if 0
  7574. switch(connectorIdInt)
  7575. {
  7576. case 0:
  7577. strcpy(filename, ChargingProfile_0_JSON );
  7578. break;
  7579. case 1:
  7580. strcpy(filename, ChargingProfile_1_JSON );
  7581. break;
  7582. case 2:
  7583. strcpy(filename, ChargingProfile_2_JSON );
  7584. break;
  7585. default:
  7586. strcpy(filename, ChargingProfile_0_JSON );
  7587. break;
  7588. }
  7589. fptr1 = fopen(filename, "r");
  7590. if (!fptr1)
  7591. {
  7592. //file not exist
  7593. DEBUG_INFO("Unable to open the input file!!\n");
  7594. fptr1 = fopen(filename, "w+");
  7595. }
  7596. fclose(fptr1);
  7597. #endif
  7598. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7599. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7600. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7601. {
  7602. //printf("set chargingProfile 1-2\n");
  7603. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7604. if(connectorIdInt != 0)
  7605. {
  7606. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7607. goto end;
  7608. }
  7609. strcpy(filename, ChargePointMaxProfile_JSON );
  7610. fptr1 = fopen(filename, "r");
  7611. if (!fptr1)
  7612. {
  7613. //file not exist
  7614. DEBUG_INFO("Unable to open the input file!!\n");
  7615. fptr1 = fopen(filename, "w+");
  7616. }
  7617. fclose(fptr1);
  7618. }
  7619. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7620. {
  7621. //printf("set chargingProfile 1-3\n");
  7622. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7623. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7624. {
  7625. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7626. goto end;
  7627. }
  7628. switch(connectorIdInt)
  7629. {
  7630. case 0:
  7631. strcpy(filename, TxDefaultProfile_0_JSON );
  7632. break;
  7633. case 1:
  7634. strcpy(filename, TxDefaultProfile_1_JSON );
  7635. break;
  7636. case 2:
  7637. strcpy(filename, TxDefaultProfile_2_JSON );
  7638. break;
  7639. default:
  7640. strcpy(filename, TxDefaultProfile_0_JSON );
  7641. break;
  7642. }
  7643. fptr1 = fopen(filename, "r");
  7644. if (!fptr1)
  7645. {
  7646. //file not exist
  7647. DEBUG_INFO("Unable to open the input file!!\n");
  7648. fptr1 = fopen(filename, "w+");
  7649. }
  7650. fclose(fptr1);
  7651. }
  7652. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7653. {
  7654. //printf("set chargingProfile 1-4\n");
  7655. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7656. //check Transaction active
  7657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7658. {
  7659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7660. {
  7661. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7662. {
  7663. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7664. {
  7665. meet = TRUE;
  7666. break;
  7667. }
  7668. }
  7669. }
  7670. }
  7671. for (int index = 0; index < CCS_QUANTITY; index++)
  7672. {
  7673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7674. {
  7675. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7676. {
  7677. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7678. {
  7679. meet = TRUE;
  7680. break;
  7681. }
  7682. }
  7683. }
  7684. }
  7685. for (int index = 0; index < GB_QUANTITY; index++)
  7686. {
  7687. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7688. {
  7689. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7690. {
  7691. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7692. {
  7693. meet = TRUE;
  7694. break;
  7695. }
  7696. }
  7697. }
  7698. }
  7699. if(meet == FALSE)
  7700. {
  7701. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7702. goto end;
  7703. }
  7704. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7705. {
  7706. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7707. goto end;
  7708. }
  7709. switch(connectorIdInt)
  7710. {
  7711. case 0:
  7712. break;
  7713. case 1:
  7714. strcpy(filename, TxProfile_1_JSON);
  7715. break;
  7716. case 2:
  7717. strcpy(filename, TxProfile_2_JSON);
  7718. break;
  7719. default:
  7720. strcpy(filename, TxProfile_1_JSON);
  7721. break;
  7722. }
  7723. fptr1 = fopen(filename, "r");
  7724. if (!fptr1)
  7725. {
  7726. //file not exist
  7727. DEBUG_INFO("Unable to open the input file!!\n");
  7728. fptr1 = fopen(filename, "w+");
  7729. }
  7730. fclose(fptr1);
  7731. }
  7732. //**********************************Write to File********************************************************/
  7733. FILE *infile;
  7734. FILE *outfile;
  7735. // open file for writing
  7736. infile = fopen (filename, "r");
  7737. outfile = fopen (tempfile, "w");
  7738. int d =0;
  7739. d = fgetc(infile);
  7740. DEBUG_INFO("d:%d\n",d);
  7741. rewind(infile);
  7742. //*检测到文件结束标识返回1,否则返回0。*/
  7743. if(d == EOF)
  7744. {
  7745. DEBUG_INFO("ChargingProfile content is NULL\n");
  7746. fprintf(outfile,"[%s]\n",payload);
  7747. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7748. fclose(infile);
  7749. fclose(outfile);
  7750. sprintf(rmFileCmd,"rm -f %s",filename);
  7751. system(rmFileCmd);
  7752. resultRename = rename(tempfile, filename);
  7753. if(resultRename == 0)
  7754. {
  7755. DEBUG_INFO("File chargingProfile renamed successfully");
  7756. }
  7757. else
  7758. {
  7759. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7760. }
  7761. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7762. //system(rmFileCmd);
  7763. }
  7764. else
  7765. {
  7766. char buf[1000]={0};
  7767. while (fgets(buf, sizeof(buf), infile) != NULL)
  7768. {
  7769. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7770. //*************************tempconnectorIdInt*********************************/
  7771. loc = strstr(buf, "connectorId");
  7772. c = 0;
  7773. memset(sstr ,0, sizeof(sstr) );
  7774. while (loc[strlen("connectorId")+2+c] != ',')
  7775. {
  7776. sstr[c] = loc[strlen("connectorId")+2+c];
  7777. c++;
  7778. }
  7779. sstr[c] = '\0';
  7780. tempconnectorIdInt = atoi(sstr);
  7781. //*************************tempchargingProfileIdInt*********************************/
  7782. loc = strstr(buf, "chargingProfileId");
  7783. c = 0;
  7784. memset(sstr ,0, sizeof(sstr) );
  7785. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7786. {
  7787. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7788. c++;
  7789. }
  7790. sstr[c] = '\0';
  7791. tempchargingProfileIdInt = atoi(sstr);
  7792. //*************************tempstackLevelInt*********************************/
  7793. loc = strstr(buf, "stackLevel");
  7794. c = 0;
  7795. memset(sstr ,0, sizeof(sstr) );
  7796. while (loc[strlen("stackLevel")+2+c] != ',')
  7797. {
  7798. sstr[c] = loc[strlen("stackLevel")+2+c];
  7799. c++;
  7800. }
  7801. sstr[c] = '\0';
  7802. tempstackLevelInt = atoi(sstr);
  7803. //*************************tempchargingProfilePurposeStr*********************************/
  7804. loc = strstr(payload, "chargingProfilePurpose");
  7805. c = 0;
  7806. memset(sstr ,0, sizeof(sstr) );
  7807. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7808. {
  7809. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7810. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7811. c++;
  7812. }
  7813. sstr[c] = '\0';
  7814. strcpy(tempchargingProfilePurposeStr,sstr);
  7815. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7816. {
  7817. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7818. {
  7819. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7820. fprintf(outfile,"[%s]\n",payload);
  7821. }
  7822. else
  7823. {
  7824. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7825. if(tempstackLevelInt < stackLevelInt)
  7826. {
  7827. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7828. fprintf(outfile,"[%s]\n",payload);
  7829. fprintf(outfile,"[%s]\n",buf);
  7830. }
  7831. else
  7832. {
  7833. fprintf(outfile,"[%s]\n",buf);
  7834. fprintf(outfile,"[%s]\n",payload);
  7835. }
  7836. }
  7837. DEBUG_INFO("update set chargingProfile to file\n");
  7838. }
  7839. else
  7840. {
  7841. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7842. {
  7843. fprintf(outfile,"[%s]\n",payload);
  7844. fprintf(outfile,"[%s]\n",buf);
  7845. }
  7846. else if(tempstackLevelInt < stackLevelInt)
  7847. {
  7848. fprintf(outfile,"[%s]\n",payload);
  7849. fprintf(outfile,"[%s]\n",buf);
  7850. }
  7851. else
  7852. {
  7853. fprintf(outfile,"[%s]\n",buf);
  7854. fprintf(outfile,"[%s]\n",payload);
  7855. }
  7856. fprintf(outfile,"[%s]\n",buf);
  7857. DEBUG_INFO("add set chargingProfile to file\n");
  7858. }
  7859. } // end of while loop
  7860. fclose(infile);
  7861. fclose(outfile);
  7862. sprintf(rmFileCmd,"rm -f %s",filename);
  7863. system(rmFileCmd);
  7864. resultRename = rename(tempfile, filename);
  7865. if(resultRename == 0)
  7866. {
  7867. DEBUG_INFO("File chargingProfile renamed successfully");
  7868. }
  7869. else
  7870. {
  7871. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7872. }
  7873. result = TRUE;
  7874. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7875. }
  7876. end:
  7877. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7878. return result;
  7879. return result;
  7880. }
  7881. int handleTriggerMessageRequest(char *uuid, char *payload)
  7882. {
  7883. mtrace();
  7884. int result = FAIL;
  7885. int connectorIdIsNULL = FALSE;
  7886. int connectorIdInt =0;
  7887. char sstr[40]={0};
  7888. char requestedMessagestr[40]={0};
  7889. char comfirmstr[20]={0};
  7890. int c = 0;
  7891. char *loc;
  7892. DEBUG_INFO("handleTriggerMessageRequest\n");
  7893. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7894. c = 0;
  7895. loc = strstr(payload, "requestedMessage");
  7896. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7897. {
  7898. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7899. c++;
  7900. }
  7901. sstr[c] = '\0';
  7902. strcpy(requestedMessagestr, sstr);
  7903. c = 0;
  7904. loc = strstr(payload, "connectorId");
  7905. if(loc == NULL)
  7906. {
  7907. connectorIdIsNULL = TRUE;
  7908. }
  7909. else
  7910. {
  7911. memset(sstr ,0, sizeof(sstr) );
  7912. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7913. {
  7914. sstr[c] = loc[strlen("connectorId")+2+c];
  7915. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7916. c++;
  7917. }
  7918. sstr[c] = '\0';
  7919. connectorIdInt = atoi(sstr);
  7920. }
  7921. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7922. {
  7923. //connectorIdInt = json_object_get_int(connectorId);
  7924. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7925. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7926. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7927. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7928. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7929. }
  7930. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7931. {
  7932. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7933. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7934. return TRUE;
  7935. }
  7936. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7937. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7938. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7939. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7940. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7941. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7942. {
  7943. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7944. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7945. return TRUE;
  7946. }
  7947. else
  7948. {
  7949. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7950. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7951. }
  7952. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7953. {
  7954. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7955. {
  7956. FirmwareStatusNotificationStatus = 3;
  7957. }
  7958. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7959. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7960. }
  7961. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7962. {
  7963. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7964. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7965. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7966. }
  7967. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7968. {
  7969. sendBootNotificationRequest();
  7970. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7971. }
  7972. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7973. {
  7974. sendHeartbeatRequest(connectorIdInt);
  7975. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7976. }
  7977. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7978. {
  7979. if(connectorIdIsNULL == FALSE)
  7980. {
  7981. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7982. {
  7983. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7984. sendMeterValuesRequest(connectorIdInt -1);
  7985. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7986. }
  7987. }
  7988. else
  7989. {
  7990. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7991. {
  7992. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7993. sendMeterValuesRequest(idx);
  7994. }
  7995. }
  7996. }
  7997. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7998. {
  7999. if(connectorIdIsNULL == FALSE)
  8000. {
  8001. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8002. {
  8003. sendStatusNotificationRequest(connectorIdInt -1);
  8004. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8005. }
  8006. }
  8007. else
  8008. {
  8009. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8010. sendStatusNotificationRequest(idx);
  8011. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8012. }
  8013. }
  8014. return result;
  8015. }
  8016. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8017. {
  8018. mtrace();
  8019. int result = FAIL;
  8020. char sstr[6]={0};
  8021. int connectorIdInt =0;
  8022. char comfirmstr[20]={0};
  8023. int c = 0;
  8024. char *loc;
  8025. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8026. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8027. c = 0;
  8028. loc = strstr(payload, "connectorId");
  8029. memset(sstr ,0, sizeof(sstr) );
  8030. while (loc[strlen("connectorId")+2+c] != '}')
  8031. {
  8032. sstr[c] = loc[strlen("connectorId")+2+c];
  8033. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8034. c++;
  8035. }
  8036. sstr[c] = '\0';
  8037. connectorIdInt = atoi(sstr);
  8038. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8039. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8040. {
  8041. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8042. goto end;
  8043. }
  8044. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8045. {
  8046. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8047. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8048. goto end;
  8049. }
  8050. else
  8051. {
  8052. //check Transaction active
  8053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8054. {
  8055. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8056. {
  8057. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8058. {
  8059. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8060. }
  8061. }
  8062. for (int index = 0; index < CCS_QUANTITY; index++)
  8063. {
  8064. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8065. {
  8066. //stop Transaction
  8067. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8068. }
  8069. }
  8070. for (int index = 0; index < GB_QUANTITY; index++)
  8071. {
  8072. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8073. {
  8074. //stop Transaction
  8075. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8076. }
  8077. }
  8078. }
  8079. else
  8080. {
  8081. for (int index = 0; index < AC_QUANTITY; index++)
  8082. {
  8083. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8084. {
  8085. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8086. }
  8087. }
  8088. }// END FOR AC ELSE
  8089. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8090. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8091. result = TRUE;
  8092. return result;
  8093. }
  8094. end:
  8095. //json_object_put(obj); --- remove temporally
  8096. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8097. return result;
  8098. }
  8099. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8100. {
  8101. mtrace();
  8102. int result = FAIL;
  8103. pthread_t t;
  8104. sendUpdateFirmwareConfirmation(uuid);
  8105. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8106. ////pthread_join(t, NULL); //
  8107. pthread_detach(t);
  8108. //sendUpdateFirmwareConfirmation(uuid);
  8109. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8110. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8111. return result;
  8112. }
  8113. void *UpdateFirmwareProcess(void *data)
  8114. {
  8115. mtrace();
  8116. int retriesInt =0, retryIntervalInt=0;
  8117. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8118. int port=0;
  8119. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8120. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8121. //char comfirmstr[20];
  8122. int isSuccess = 0;
  8123. char ftpbuf[200];
  8124. char temp[100];
  8125. char * pch;
  8126. int retriesISNULL=FALSE;
  8127. int retryInterval=FALSE;
  8128. int c = 0;
  8129. //int i = 0;
  8130. char *loc;
  8131. char sstr[300]={ 0 };
  8132. char *str = (char*) data; // ?��?輸入資�?
  8133. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8134. //***************location **************/
  8135. loc = strstr(str, "location");
  8136. memset(sstr ,0, sizeof(sstr) );
  8137. c = 0;
  8138. while (loc[3+strlen("location")+c] != '\"')
  8139. {
  8140. sstr[c] = loc[3+strlen("location")+c];
  8141. c++;
  8142. }
  8143. sstr[c] = '\0';
  8144. strcpy(locationstr, sstr);
  8145. //***************retries**************/
  8146. c = 0;
  8147. loc = strstr(str, "retries");
  8148. if(loc == NULL)
  8149. {
  8150. retriesISNULL=TRUE;
  8151. }
  8152. else
  8153. {
  8154. memset(sstr ,0, sizeof(sstr) );
  8155. while (loc[strlen("retries")+2+c] != ',')
  8156. {
  8157. sstr[c] = loc[strlen("retries")+2+c];
  8158. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8159. c++;
  8160. }
  8161. sstr[c] = '\0';
  8162. }
  8163. if(retriesISNULL == FALSE)
  8164. {
  8165. retriesInt = atoi(sstr);
  8166. }
  8167. //***************retrieveDate **************/
  8168. loc = strstr(str, "retrieveDate");
  8169. memset(sstr ,0, sizeof(sstr) );
  8170. c = 0;
  8171. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8172. {
  8173. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8174. c++;
  8175. }
  8176. sstr[c] = '\0';
  8177. strcpy(retrieveDatestr, sstr);
  8178. //***************retryInterval **************/
  8179. c = 0;
  8180. loc = strstr(str, "retryInterval");
  8181. memset(sstr ,0, sizeof(sstr) );
  8182. if(loc == NULL)
  8183. {
  8184. retryInterval=TRUE;
  8185. }
  8186. else
  8187. {
  8188. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8189. {
  8190. sstr[c] = loc[strlen("retryInterval")+2+c];
  8191. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8192. c++;
  8193. }
  8194. sstr[c] = '\0';
  8195. }
  8196. if(retryInterval==FALSE)
  8197. {
  8198. retryIntervalInt = atoi(sstr);
  8199. }
  8200. memset(ftppath, 0, sizeof(ftppath));
  8201. memset(path, 0, sizeof(path));
  8202. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8203. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8204. if(strncmp(locationstr,"http", 4) == 0)
  8205. {
  8206. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8207. protocol, host, path);
  8208. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8209. // protocol, user, password, host, path);
  8210. sprintf(ftppath,"/%s", path);
  8211. DEBUG_INFO("protocol =%s\n",protocol);
  8212. DEBUG_INFO("host =%s\n",host);
  8213. DEBUG_INFO("path =%s\n",path);
  8214. DEBUG_INFO("ftppath=%s\n",ftppath);
  8215. int ftppathlen=strlen(ftppath);
  8216. int i=1;
  8217. char filenametemp[50];
  8218. while(i < ftppathlen)
  8219. {
  8220. int len=ftppathlen-i;
  8221. if(ftppath[len]== 47) // '/' ascll code: 47
  8222. {
  8223. DEBUG_INFO("compare '/' all right\n");
  8224. break;
  8225. }
  8226. i=i+1;
  8227. }
  8228. memset(filenametemp, 0, sizeof(filenametemp));
  8229. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8230. filenametemp[i+1] = 0;
  8231. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8232. do{
  8233. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8234. sleep(retryIntervalInt);
  8235. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8236. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8237. if(!isSuccess)
  8238. {
  8239. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8240. }
  8241. else
  8242. {
  8243. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8244. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8245. isUpdateRequest = TRUE;
  8246. }
  8247. }
  8248. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8249. {
  8250. memset(ftpbuf, 0, sizeof(ftpbuf));
  8251. memset(temp, 0, sizeof(temp));
  8252. DEBUG_INFO("locationstr=%s\n",locationstr);
  8253. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8254. int ftppathlen=strlen(ftpbuf);
  8255. int i=1;
  8256. char filenametemp[50];
  8257. while(i < ftppathlen)
  8258. {
  8259. int len=ftppathlen-i;
  8260. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8261. {
  8262. DEBUG_INFO(" compare '/' all right\n");
  8263. break;
  8264. }
  8265. i=i+1;
  8266. }
  8267. memset(filenametemp, 0, sizeof(filenametemp));
  8268. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8269. filenametemp[i+1] = 0;
  8270. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8271. pch=strchr(temp,'@');
  8272. if(pch==NULL)
  8273. {
  8274. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8275. protocol, host, &port, path);
  8276. strcpy(user,"anonymous");
  8277. strcpy(password,"");
  8278. }
  8279. else
  8280. {
  8281. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8282. protocol, user, password, host, &port, path);
  8283. }
  8284. sscanf(host,"%[^/]%s",host1, path1);
  8285. sprintf(ftppath,"%s", path1);
  8286. DEBUG_INFO("protocol =%s\n",protocol);
  8287. DEBUG_INFO("user =%s\n",user);
  8288. DEBUG_INFO("password =%s\n",password);
  8289. DEBUG_INFO("host1 =%s\n",host1);
  8290. DEBUG_INFO("port =%d\n",port);
  8291. DEBUG_INFO("path1 =%s\n",path1);
  8292. DEBUG_INFO("ftppath=%s\n",ftppath);
  8293. //ftpFile(host, user, password, port, ftppath, fname);
  8294. //download firmware pthred
  8295. if(port == 0)
  8296. {
  8297. port = 21;
  8298. }
  8299. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8300. do{
  8301. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8302. sleep(retryIntervalInt);
  8303. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8304. if(!isSuccess)
  8305. {
  8306. //BulldogUtil.sleepMs(interval*1000);
  8307. DEBUG_INFO("Update firmware request and download file fail.\n");
  8308. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8309. }
  8310. else
  8311. {
  8312. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8313. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8314. isUpdateRequest = TRUE;
  8315. }
  8316. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8317. }
  8318. else
  8319. {
  8320. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8321. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8322. }
  8323. pthread_exit(NULL);
  8324. }
  8325. //==========================================
  8326. // Handle server response routine
  8327. //==========================================
  8328. void handleAuthorizeResponse(char *payload, int gun_index)
  8329. {
  8330. mtrace();
  8331. char expiryDatestr[30]={0};
  8332. char parentIdTagstr[20]={0};
  8333. char statusstr[20]={0};
  8334. char expiryDatestrtemp[30]={0};
  8335. char parentIdTagstrtemp[20]={0};
  8336. char IdTagstrtemp[20]={0};
  8337. char statusstrtemp[20]={0};
  8338. int expiryDateISNULL=FALSE;
  8339. int parentIdTagISNULL=FALSE;
  8340. char sstr[160]={ 0 };
  8341. char* filename = AuthorizationCache_JSON;
  8342. char tempfile[] = "../Storage/OCPP/temp.json";
  8343. int c = 0;
  8344. char *loc;
  8345. int resultRename=0;
  8346. int responseIdTagInfoAsZero= 0;
  8347. char rmFileCmd[50]={0};
  8348. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8349. //***********expiryDate*************/
  8350. loc = strstr(payload, "expiryDate");
  8351. memset(sstr ,0, sizeof(sstr) );
  8352. c = 0;
  8353. if(loc == NULL)
  8354. {
  8355. expiryDateISNULL = TRUE;
  8356. }
  8357. else
  8358. {
  8359. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8360. {
  8361. sstr[c] = loc[3+strlen("expiryDate")+c];
  8362. c++;
  8363. }
  8364. sstr[c] = '\0';
  8365. strcpy(expiryDatestr, sstr);
  8366. }
  8367. //***********parentIdTag*************/
  8368. loc = strstr(payload, "parentIdTag");
  8369. memset(sstr ,0, sizeof(sstr) );
  8370. c = 0;
  8371. if(loc == NULL)
  8372. {
  8373. parentIdTagISNULL = TRUE;
  8374. }
  8375. else
  8376. {
  8377. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8378. {
  8379. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8380. c++;
  8381. }
  8382. sstr[c] = '\0';
  8383. strcpy(parentIdTagstr, sstr);
  8384. }
  8385. //***********status*************/
  8386. loc = strstr(payload, "status");
  8387. memset(sstr ,0, sizeof(sstr) );
  8388. c = 0;
  8389. while (loc[3+strlen("status")+c] != '\"')
  8390. {
  8391. sstr[c] = loc[3+strlen("status")+c];
  8392. c++;
  8393. }
  8394. sstr[c] = '\0';
  8395. strcpy(statusstr, sstr);
  8396. //#ifdef SystemLogMessage
  8397. // if(expiryDateISNULL == FALSE)
  8398. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8399. // if(parentIdTagISNULL == FALSE)
  8400. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8401. // DEBUG_INFO("status: %s\n", statusstr);
  8402. //#endif
  8403. if(expiryDateISNULL == FALSE)
  8404. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8405. if(parentIdTagISNULL == FALSE)
  8406. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8407. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8408. //Update idTag information to authorization cache if supproted
  8409. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8410. {
  8411. if((access(filename,F_OK))!=-1)
  8412. {
  8413. DEBUG_INFO("AuthorizationCache exist.\n");
  8414. }
  8415. else
  8416. {
  8417. DEBUG_INFO("AuthorizationCache not exist\n");
  8418. FILE *log = fopen(filename, "w+");
  8419. if(log == NULL)
  8420. {
  8421. DEBUG_INFO("log is NULL\n");
  8422. goto out;
  8423. }
  8424. else
  8425. {
  8426. fclose(log);
  8427. }
  8428. }
  8429. FILE *infile;
  8430. FILE *outfile;
  8431. // open file for writing
  8432. infile = fopen (filename, "r");
  8433. outfile = fopen (tempfile, "w");
  8434. //*检测到文件结束标识返回1,否则返回0。*/
  8435. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8436. int c;
  8437. c = fgetc(infile);
  8438. //DEBUG_INFO("c:%d\n",c);
  8439. rewind(infile);
  8440. if(c == EOF)
  8441. {
  8442. DEBUG_INFO("Orignal File is NULL\n");
  8443. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8444. {
  8445. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8446. }
  8447. else
  8448. {
  8449. strcpy(expiryDatestrtemp, "");
  8450. }
  8451. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8452. {
  8453. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8454. }
  8455. else
  8456. {
  8457. //write Authorize IdTag
  8458. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8459. }
  8460. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8461. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8462. fclose(infile);
  8463. fclose(outfile);
  8464. sprintf(rmFileCmd,"rm -f %s",filename);
  8465. system(rmFileCmd);
  8466. resultRename = rename(tempfile, filename);
  8467. if(resultRename == 0)
  8468. {
  8469. DEBUG_INFO("File renamed successfully");
  8470. }
  8471. else
  8472. {
  8473. DEBUG_INFO("Error: unable to rename the file");
  8474. }
  8475. }
  8476. else
  8477. {
  8478. char buf[160]={0};
  8479. //DEBUG_INFO("Orignal File is not NULL\n");
  8480. while (fgets(buf, sizeof(buf), infile) != NULL)
  8481. {
  8482. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8483. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8484. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8485. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8486. memset(statusstr, 0, sizeof(statusstrtemp));
  8487. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8488. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8489. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8490. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8491. //------------------IdTag-----------------------
  8492. loc = strstr(buf, "idTag");
  8493. memset(sstr ,0, sizeof(sstr) );
  8494. c = 0;
  8495. while (loc[3+strlen("idTag")+c] != '\"')
  8496. {
  8497. sstr[c] = loc[3+strlen("idTag")+c];
  8498. c++;
  8499. }
  8500. sstr[c] = '\0';
  8501. strcpy(IdTagstrtemp,sstr);
  8502. //*********************expiryDate***************/
  8503. loc = strstr(buf, "expiryDate");
  8504. memset(sstr ,0, sizeof(sstr) );
  8505. c = 0;
  8506. while (loc[3+strlen("expiryDate")+c] != '\"')
  8507. {
  8508. sstr[c] = loc[3+strlen("expiryDate")+c];
  8509. c++;
  8510. }
  8511. sstr[c] = '\0';
  8512. strcpy(expiryDatestr,sstr);
  8513. //*********************parentIdTag***************/
  8514. loc = strstr(buf, "parentIdTag");
  8515. memset(sstr ,0, sizeof(sstr) );
  8516. c = 0;
  8517. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8518. {
  8519. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8520. c++;
  8521. }
  8522. sstr[c] = '\0';
  8523. strcpy(parentIdTagstr,sstr);
  8524. //*********************status***************/
  8525. loc = strstr(buf, "status");
  8526. memset(sstr ,0, sizeof(sstr) );
  8527. c = 0;
  8528. while (loc[3+strlen("status")+c] != '\"')
  8529. {
  8530. sstr[c] = loc[3+strlen("status")+c];
  8531. c++;
  8532. }
  8533. sstr[c] = '\0';
  8534. strcpy(statusstr,sstr);
  8535. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8536. {
  8537. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8538. responseIdTagInfoAsZero = 1;
  8539. }
  8540. else
  8541. {
  8542. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8543. }
  8544. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8545. {
  8546. //modify item
  8547. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8548. {
  8549. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8550. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8551. }
  8552. else
  8553. {
  8554. strcpy(expiryDatestrtemp, "");
  8555. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8556. }
  8557. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8558. {
  8559. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8560. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8561. }
  8562. else
  8563. {
  8564. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8565. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8566. }
  8567. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8568. }
  8569. else
  8570. {
  8571. //wrie original item
  8572. strcpy(expiryDatestrtemp, expiryDatestr);
  8573. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8574. strcpy(statusstrtemp, statusstr);
  8575. }
  8576. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8577. }
  8578. fclose(infile);
  8579. fclose(outfile);
  8580. sprintf(rmFileCmd,"rm -f %s",filename);
  8581. system(rmFileCmd);
  8582. resultRename = rename(tempfile, filename);
  8583. if(resultRename == 0)
  8584. {
  8585. DEBUG_INFO("File renamed successfully");
  8586. }
  8587. else
  8588. {
  8589. DEBUG_INFO("Error: unable to rename the file");
  8590. }
  8591. }
  8592. }
  8593. out:
  8594. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8595. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8596. authorizeRetryTimes = 0;
  8597. }
  8598. void handleBootNotificationResponse(char *payload, int gun_index)
  8599. {
  8600. mtrace();
  8601. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8602. char statusStr[12]={0};
  8603. char currentTimeStr[30]={0};
  8604. char *loc;
  8605. int intervalInt = 0;
  8606. int c = 0;
  8607. //double diff_t;
  8608. struct tm tp;
  8609. char buf[28]={0};
  8610. char timebuf[50]={0};
  8611. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8612. //*** interval ****/
  8613. c = 0;
  8614. loc = strstr(payload, "interval");
  8615. //printf("loc=%s\n",loc);
  8616. memset(sstr ,0, sizeof(sstr) );
  8617. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8618. {
  8619. sstr[c] = loc[strlen("interval")+2+c];
  8620. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8621. c++;
  8622. }
  8623. sstr[c] = '\0';
  8624. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8625. intervalInt = atoi(sstr);
  8626. //***status ****/
  8627. loc = strstr(payload, "status");
  8628. memset(sstr ,0, sizeof(sstr) );
  8629. c = 0;
  8630. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8631. {
  8632. sstr[c] = loc[3+strlen("status")+c];
  8633. c++;
  8634. }
  8635. sstr[c] = '\0';
  8636. strcpy(statusStr, sstr);
  8637. //***currentTime ****/
  8638. loc = strstr(payload, "currentTime");
  8639. //printf("loc=%s\n",loc);
  8640. memset(sstr ,0, sizeof(sstr) );
  8641. c = 0;
  8642. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8643. {
  8644. sstr[c] = loc[3+strlen("currentTime")+c];
  8645. c++;
  8646. }
  8647. sstr[c] = '\0';
  8648. strcpy(currentTimeStr, sstr);
  8649. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8650. HeartBeatWaitTime = BootNotificationInterval;
  8651. //#ifdef SystemLogMessage
  8652. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8653. // DEBUG_INFO("interval: %d\n", intervalInt);
  8654. // DEBUG_INFO("status: %s\n", statusStr);
  8655. //#endif
  8656. //write back to ShmOCPP16Data->BootNotification
  8657. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8658. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8659. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8660. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8661. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8662. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8663. {
  8664. server_sign = TRUE;
  8665. server_pending =FALSE;
  8666. }
  8667. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8668. {
  8669. server_pending = TRUE;
  8670. }
  8671. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8672. tp.tm_isdst = -1;
  8673. //time_t utc = mktime(&tp);
  8674. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8675. memset(timebuf, 0, sizeof timebuf);
  8676. sprintf(timebuf,"date -s '%s'",buf);
  8677. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8678. system(timebuf);
  8679. //==============================================
  8680. // RTC sync
  8681. //==============================================
  8682. system("/sbin/hwclock -w --systohc");
  8683. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8684. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8685. }
  8686. void handleDataTransferResponse(char *payload, int gun_index)
  8687. {
  8688. char sstr[160]={0};//sstr[200]={ 0 };
  8689. int c = 0;
  8690. char *loc;
  8691. DEBUG_INFO("handleDataTransferResponse ...\n");
  8692. loc = strstr(payload, "status");
  8693. printf("loc=%s\n",loc);
  8694. c = 0;
  8695. while (loc[3+strlen("status")+c] != '\"')
  8696. {
  8697. sstr[c] = loc[3+strlen("status")+c];
  8698. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8699. c++;
  8700. }
  8701. sstr[c] = '\0';
  8702. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8703. //#ifdef SystemLogMessage
  8704. //DEBUG_INFO("data: %s\n", payload);
  8705. //#endif
  8706. }
  8707. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8708. {
  8709. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8710. //struct json_object *obj;
  8711. // obj = json_tokener_parse(payload);
  8712. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8713. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8714. //No fields are defined.
  8715. }
  8716. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8717. {
  8718. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8719. //struct json_object *obj;
  8720. // obj = json_tokener_parse(payload);
  8721. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8722. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8723. //No fields are defined.
  8724. }
  8725. void handleHeartbeatResponse(char *payload, int gun_index)
  8726. {
  8727. mtrace();
  8728. //double diff_t;
  8729. struct tm tp;
  8730. char buf[28]={0};
  8731. char timebuf[50]={0};
  8732. char sstr[30]={ 0 };
  8733. int c = 0;
  8734. char *loc;
  8735. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8736. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8737. c = 0;
  8738. loc = strstr(payload, "currentTime");
  8739. memset(sstr ,0, sizeof(sstr) );
  8740. while (loc[3+strlen("currentTime")+c] != '\"')
  8741. {
  8742. sstr[c] = loc[3+strlen("currentTime")+c];
  8743. c++;
  8744. }
  8745. sstr[c] = '\0';
  8746. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8747. // #ifdef SystemLogMessage
  8748. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8749. // #endif
  8750. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8751. tp.tm_isdst = -1;
  8752. //time_t utc = mktime(&tp);
  8753. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8754. memset(timebuf, 0, sizeof timebuf);
  8755. sprintf(timebuf,"date -s '%s'",buf);
  8756. system(timebuf);
  8757. //==============================================
  8758. // RTC sync
  8759. //==============================================
  8760. system("/sbin/hwclock -w --systohc");
  8761. if(FirstHeartBeat == 0)
  8762. {
  8763. FirstHeartBeat = 1;
  8764. }
  8765. HeartBeatWithNOResponse = 0;
  8766. }
  8767. void handleMeterValuesResponse(char *payload, int gun_index)
  8768. {
  8769. mtrace();
  8770. //struct json_object *obj;
  8771. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8772. //No fields are defined.
  8773. }
  8774. void handleStartTransactionResponse(char *payload, int gun_index)
  8775. {
  8776. mtrace();
  8777. char sstr[28]={ 0 };
  8778. int c = 0;
  8779. char *loc;
  8780. int transactionIdInt = 0;
  8781. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8782. DEBUG_INFO("handleStartTransactionResponse\n");
  8783. //****************expiryDate********************/
  8784. loc = strstr(payload, "expiryDate");
  8785. if(loc == NULL)
  8786. {
  8787. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8788. }
  8789. else
  8790. {
  8791. c = 0;
  8792. memset(sstr ,0, sizeof(sstr) );
  8793. while (loc[3+strlen("expiryDate")+c] != '\"')
  8794. {
  8795. sstr[c] = loc[3+strlen("expiryDate")+c];
  8796. c++;
  8797. }
  8798. sstr[c] = '\0';
  8799. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8800. }
  8801. //****************parentIdTag********************/
  8802. loc = strstr(payload, "parentIdTag");
  8803. if(loc == NULL)
  8804. {
  8805. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8806. }
  8807. else
  8808. {
  8809. c = 0;
  8810. memset(sstr ,0, sizeof(sstr) );
  8811. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8812. {
  8813. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8814. c++;
  8815. }
  8816. sstr[c] = '\0';
  8817. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8818. }
  8819. //****************status********************/
  8820. loc = strstr(payload, "status");
  8821. if(loc == NULL)
  8822. {
  8823. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8824. }
  8825. else
  8826. {
  8827. c = 0;
  8828. memset(sstr ,0, sizeof(sstr) );
  8829. while (loc[3+strlen("status")+c] != '\"')
  8830. {
  8831. sstr[c] = loc[3+strlen("status")+c];
  8832. c++;
  8833. }
  8834. sstr[c] = '\0';
  8835. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8836. }
  8837. //****************transactionId********************/
  8838. c=0;
  8839. loc = strstr(payload, "transactionId");
  8840. memset(sstr ,0, sizeof(sstr) );
  8841. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8842. {
  8843. sstr[c] = loc[strlen("transactionId")+2+c];
  8844. c++;
  8845. }
  8846. sstr[c] = '\0';
  8847. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8848. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8849. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8850. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8851. #ifdef SystemLogMessage
  8852. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8853. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8854. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8855. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8856. #endif
  8857. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8858. {
  8859. //add Charging Record
  8860. SettingChargingRecord(gun_index, transactionIdInt);
  8861. }
  8862. DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8863. }
  8864. void handleStatusNotificationResponse(char *payload, int gun_index)
  8865. {
  8866. mtrace();
  8867. printf("handleStatusNotificationResponse\n");
  8868. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8869. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8870. }
  8871. void handleStopTransactionnResponse(char *payload, int gun_index)
  8872. {
  8873. mtrace();
  8874. char sstr[30]={ 0 };
  8875. int c = 0;
  8876. char *loc;
  8877. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8878. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8879. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8880. loc = strstr(payload, "idTagInfo");
  8881. //***********************idTagInfo************************/
  8882. if(loc != NULL)
  8883. {
  8884. //***********************expiryDate************************/
  8885. loc = strstr(payload, "expiryDate");
  8886. if(loc != NULL)
  8887. {
  8888. memset(sstr ,0, sizeof(sstr) );
  8889. c = 0;
  8890. while (loc[3+strlen("expiryDate")+c] != '\"')
  8891. {
  8892. sstr[c] = loc[3+strlen("expiryDate")+c];
  8893. c++;
  8894. }
  8895. sstr[c] = '\0';
  8896. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8897. }
  8898. //***********************parentIdTag************************/
  8899. loc = strstr(payload, "parentIdTag");
  8900. if(loc != NULL)
  8901. {
  8902. memset(sstr ,0, sizeof(sstr) );
  8903. c = 0;
  8904. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8905. {
  8906. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8907. c++;
  8908. }
  8909. sstr[c] = '\0';
  8910. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8911. }
  8912. //***********************status************************/
  8913. loc = strstr(payload, "status");
  8914. memset(sstr ,0, sizeof(sstr) );
  8915. c = 0;
  8916. while (loc[3+strlen("status")+c] != '\"')
  8917. {
  8918. sstr[c] = loc[3+strlen("status")+c];
  8919. c++;
  8920. }
  8921. sstr[c] = '\0';
  8922. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8923. }
  8924. #ifdef SystemLogMessage
  8925. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8926. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8927. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8928. #endif
  8929. }
  8930. //==========================================
  8931. // Handle Error routine
  8932. //==========================================
  8933. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8934. {
  8935. mtrace();
  8936. #ifdef SystemLogMessage
  8937. DEBUG_INFO("errorCode: %s\n", errorCode);
  8938. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8939. DEBUG_INFO("errorDetails: %s\n", payload);
  8940. #endif
  8941. }
  8942. //===============================================
  8943. // Common routine
  8944. //===============================================
  8945. int initialConfigurationTable(void)
  8946. {
  8947. printf("initialConfigurationTable \n");
  8948. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8949. /*Core Profile*/
  8950. //AllowOfflineTxForUnknownId
  8951. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8952. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8955. //AuthorizationCacheEnabled
  8956. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8959. //AuthorizeRemoteTxRequests
  8960. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8963. //BlinkRepeat
  8964. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8967. //ClockAlignedDataInterval
  8968. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8971. //ConnectionTimeOut
  8972. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8975. //GetConfigurationMaxKeys
  8976. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8979. // HeartbeatInterval
  8980. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8983. // LightIntensity
  8984. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8987. // LocalAuthorizeOffline
  8988. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  8989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8991. // LocalPreAuthorize
  8992. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  8993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8995. // MaxEnergyOnInvalidId
  8996. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  8998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  8999. // MeterValuesAlignedData
  9000. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9003. // MeterValuesAlignedDataMaxLength
  9004. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9007. // MeterValuesSampledData
  9008. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9011. // MeterValuesSampledDataMaxLength
  9012. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9015. // MeterValueSampleInterval
  9016. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9019. // MinimumStatusDuration
  9020. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9023. // NumberOfConnectors
  9024. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  9027. // ResetRetries
  9028. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9031. // ConnectorPhaseRotation
  9032. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  9035. // ConnectorPhaseRotationMaxLength
  9036. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9039. // StopTransactionOnEVSideDisconnect
  9040. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9043. // StopTransactionOnInvalidId
  9044. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9047. // StopTxnAlignedData
  9048. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9051. // StopTxnAlignedDataMaxLength
  9052. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9055. // StopTxnSampledData
  9056. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9059. // StopTxnSampledDataMaxLength
  9060. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9063. // SupportedFeatureProfiles
  9064. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9067. // SupportedFeatureProfilesMaxLength
  9068. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9071. // TransactionMessageAttempts
  9072. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9075. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9076. // TransactionMessageRetryInterval
  9077. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9080. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9081. // UnlockConnectorOnEVSideDisconnect
  9082. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9085. // WebSocketPingInterval
  9086. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9089. //* Local Auth List Management Profile*/
  9090. #if 0
  9091. //For OCTT Test Case
  9092. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9095. #endif
  9096. #if 1
  9097. //LocalAuthListEnabled
  9098. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9101. #endif
  9102. //LocalAuthListMaxLength
  9103. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9106. //SendLocalListMaxLength
  9107. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9110. //ReserveConnectorZeroSupported
  9111. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9114. //* Smart Charging Profile */
  9115. //ChargeProfileMaxStackLevel
  9116. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9119. // ChargingScheduleAllowedChargingRateUnit
  9120. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9123. // ChargingScheduleMaxPeriods
  9124. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9127. // ConnectorSwitch3to1PhaseSupported
  9128. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9131. // MaxChargingProfilesInstalled
  9132. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9135. return 0;
  9136. }
  9137. void getKeyValue(char *keyReq)
  9138. {
  9139. int isEmpty = FALSE;
  9140. int isKnowKey = FALSE;
  9141. //int unKnowIndex = 0;
  9142. DEBUG_INFO("getKeyValue \n");
  9143. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9144. isEmpty = TRUE;
  9145. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9146. {
  9147. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9150. {
  9151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9152. }
  9153. else
  9154. {
  9155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9156. }
  9157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9158. isKnowKey = TRUE;
  9159. }
  9160. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9161. {
  9162. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9165. {
  9166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9167. }
  9168. else
  9169. {
  9170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9171. }
  9172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9173. isKnowKey = TRUE;
  9174. }
  9175. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9176. {
  9177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9180. {
  9181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9182. }
  9183. else
  9184. {
  9185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9186. }
  9187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9188. isKnowKey = TRUE;
  9189. }
  9190. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9191. {
  9192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9195. {
  9196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9197. }
  9198. else
  9199. {
  9200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9201. }
  9202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9203. isKnowKey = TRUE;
  9204. }
  9205. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9206. {
  9207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9210. {
  9211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9212. }
  9213. else
  9214. {
  9215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9216. }
  9217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9218. isKnowKey = TRUE;
  9219. }
  9220. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9221. {
  9222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9225. {
  9226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9227. }
  9228. else
  9229. {
  9230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9231. }
  9232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9233. isKnowKey = TRUE;
  9234. }
  9235. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9236. {
  9237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9240. {
  9241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9242. }
  9243. else
  9244. {
  9245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9246. }
  9247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9248. isKnowKey = TRUE;
  9249. }
  9250. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9251. {
  9252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9255. {
  9256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9257. }
  9258. else
  9259. {
  9260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9261. }
  9262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9263. isKnowKey = TRUE;
  9264. }
  9265. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9266. {
  9267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9270. {
  9271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9272. }
  9273. else
  9274. {
  9275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9276. }
  9277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9278. isKnowKey = TRUE;
  9279. }
  9280. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9281. {
  9282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9285. {
  9286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9287. }
  9288. else
  9289. {
  9290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9291. }
  9292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9293. isKnowKey = TRUE;
  9294. }
  9295. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9296. {
  9297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9300. {
  9301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9302. }
  9303. else
  9304. {
  9305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9306. }
  9307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9308. isKnowKey = TRUE;
  9309. }
  9310. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9311. {
  9312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9315. {
  9316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9317. }
  9318. else
  9319. {
  9320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9321. }
  9322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9323. isKnowKey = TRUE;
  9324. }
  9325. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9326. {
  9327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9330. {
  9331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9332. }
  9333. else
  9334. {
  9335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9336. }
  9337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9338. isKnowKey = TRUE;
  9339. }
  9340. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9341. {
  9342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9345. {
  9346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9347. }
  9348. else
  9349. {
  9350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9351. }
  9352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9353. isKnowKey = TRUE;
  9354. }
  9355. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9356. {
  9357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9360. {
  9361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9362. }
  9363. else
  9364. {
  9365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9366. }
  9367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9368. isKnowKey = TRUE;
  9369. }
  9370. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9371. {
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9375. {
  9376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9377. }
  9378. else
  9379. {
  9380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9381. }
  9382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9383. isKnowKey = TRUE;
  9384. }
  9385. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9386. {
  9387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9390. {
  9391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9392. }
  9393. else
  9394. {
  9395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9396. }
  9397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9398. isKnowKey = TRUE;
  9399. }
  9400. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9401. {
  9402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9405. {
  9406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9407. }
  9408. else
  9409. {
  9410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9411. }
  9412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9413. isKnowKey = TRUE;
  9414. }
  9415. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9420. {
  9421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9422. }
  9423. else
  9424. {
  9425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9426. }
  9427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9428. isKnowKey = TRUE;
  9429. }
  9430. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9435. {
  9436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9437. }
  9438. else
  9439. {
  9440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9441. }
  9442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9443. isKnowKey = TRUE;
  9444. }
  9445. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9446. {
  9447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9450. {
  9451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9452. }
  9453. else
  9454. {
  9455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9456. }
  9457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9458. isKnowKey = TRUE;
  9459. }
  9460. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9461. {
  9462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9465. {
  9466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9467. }
  9468. else
  9469. {
  9470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9471. }
  9472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9473. isKnowKey = TRUE;
  9474. }
  9475. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9476. {
  9477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9480. {
  9481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9482. }
  9483. else
  9484. {
  9485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9486. }
  9487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9488. isKnowKey = TRUE;
  9489. }
  9490. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9491. {
  9492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9495. {
  9496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9497. }
  9498. else
  9499. {
  9500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9501. }
  9502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9503. isKnowKey = TRUE;
  9504. }
  9505. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9506. {
  9507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9510. {
  9511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9512. }
  9513. else
  9514. {
  9515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9516. }
  9517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9518. isKnowKey = TRUE;
  9519. }
  9520. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9521. {
  9522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9525. {
  9526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9527. }
  9528. else
  9529. {
  9530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9531. }
  9532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9533. isKnowKey = TRUE;
  9534. }
  9535. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9536. {
  9537. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9540. {
  9541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9542. }
  9543. else
  9544. {
  9545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9546. }
  9547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9548. isKnowKey = TRUE;
  9549. }
  9550. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9551. {
  9552. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9555. {
  9556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9557. }
  9558. else
  9559. {
  9560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9561. }
  9562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9563. isKnowKey = TRUE;
  9564. }
  9565. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9566. {
  9567. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9570. {
  9571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9572. }
  9573. else
  9574. {
  9575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9576. }
  9577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9578. isKnowKey = TRUE;
  9579. }
  9580. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9581. {
  9582. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9585. {
  9586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9587. }
  9588. else
  9589. {
  9590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9591. }
  9592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9593. isKnowKey = TRUE;
  9594. }
  9595. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9596. {
  9597. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9599. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9600. {
  9601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9602. }
  9603. else
  9604. {
  9605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9606. }
  9607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9608. isKnowKey = TRUE;
  9609. }
  9610. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9611. {
  9612. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9614. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9615. {
  9616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9617. }
  9618. else
  9619. {
  9620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9621. }
  9622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9623. isKnowKey = TRUE;
  9624. }
  9625. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9626. {
  9627. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9630. {
  9631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9632. }
  9633. else
  9634. {
  9635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9636. }
  9637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9638. isKnowKey = TRUE;
  9639. }
  9640. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9641. {
  9642. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9644. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9645. {
  9646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9647. }
  9648. else
  9649. {
  9650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9651. }
  9652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9653. isKnowKey = TRUE;
  9654. }
  9655. #if 0
  9656. //For OCTT Test Case
  9657. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9658. {
  9659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9661. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9662. {
  9663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9664. }
  9665. else
  9666. {
  9667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9668. }
  9669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9670. isKnowKey = TRUE;
  9671. }
  9672. #endif
  9673. #if 1
  9674. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9675. {
  9676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9678. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9679. {
  9680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9681. }
  9682. else
  9683. {
  9684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9685. }
  9686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9687. isKnowKey = TRUE;
  9688. }
  9689. #endif
  9690. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9691. {
  9692. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9694. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9695. {
  9696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9697. }
  9698. else
  9699. {
  9700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9701. }
  9702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9703. isKnowKey = TRUE;
  9704. }
  9705. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9706. {
  9707. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9709. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9710. {
  9711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9712. }
  9713. else
  9714. {
  9715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9716. }
  9717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9718. isKnowKey = TRUE;
  9719. }
  9720. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9721. {
  9722. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9724. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9725. {
  9726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9727. }
  9728. else
  9729. {
  9730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9731. }
  9732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9733. isKnowKey = TRUE;
  9734. }
  9735. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9736. {
  9737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9739. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9740. {
  9741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9742. }
  9743. else
  9744. {
  9745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9746. }
  9747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9748. isKnowKey = TRUE;
  9749. }
  9750. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9751. {
  9752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9754. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9755. {
  9756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9757. }
  9758. else
  9759. {
  9760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9761. }
  9762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9763. isKnowKey = TRUE;
  9764. }
  9765. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9766. {
  9767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9769. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9770. {
  9771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9772. }
  9773. else
  9774. {
  9775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9776. }
  9777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9778. isKnowKey = TRUE;
  9779. }
  9780. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9781. {
  9782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9784. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9785. {
  9786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9787. }
  9788. else
  9789. {
  9790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9791. }
  9792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9793. isKnowKey = TRUE;
  9794. }
  9795. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9796. {
  9797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9799. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9800. {
  9801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9802. }
  9803. else
  9804. {
  9805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9806. }
  9807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9808. isKnowKey = TRUE;
  9809. }
  9810. //=========================================================
  9811. if(!isEmpty && !isKnowKey)
  9812. {
  9813. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9814. strcpy(unknownkey[UnknownKeynum], keyReq);
  9815. UnknownKeynum = UnknownKeynum + 1;
  9816. }
  9817. }
  9818. void processUnkownKey(void)
  9819. {
  9820. DEBUG_INFO("processUnkownKey\n");
  9821. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9822. for(int index=0; index < UnknownKeynum; index++)
  9823. {
  9824. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9825. {
  9826. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9827. }
  9828. }
  9829. }
  9830. int setKeyValue(char *key, char *value)
  9831. {
  9832. int isSuccess = NotSupported;
  9833. int check_ascii=0;
  9834. #ifdef Debug
  9835. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9836. #endif
  9837. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9838. {
  9839. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9841. {
  9842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9843. isSuccess = ConfigurationStatus_Accepted;
  9844. }
  9845. else
  9846. {
  9847. isSuccess = ConfigurationStatus_Rejected;
  9848. }
  9849. }
  9850. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9851. {
  9852. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9854. {
  9855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9856. isSuccess = ConfigurationStatus_Accepted;
  9857. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9858. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9859. }
  9860. else
  9861. {
  9862. isSuccess = ConfigurationStatus_Rejected;
  9863. }
  9864. }
  9865. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9866. {
  9867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9868. {
  9869. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9871. isSuccess = ConfigurationStatus_Accepted;
  9872. }
  9873. else
  9874. {
  9875. isSuccess = ConfigurationStatus_Rejected;
  9876. }
  9877. }
  9878. if(strcmp(key, "BlinkRepeat") == 0)
  9879. {
  9880. //Charger.BlinkRepeat = Integer.parseInt(value);
  9881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9882. {
  9883. check_ascii = value[0];
  9884. if( (check_ascii < 48) || (check_ascii > 57) )
  9885. {
  9886. isSuccess = ConfigurationStatus_Rejected;
  9887. }
  9888. else
  9889. {
  9890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9891. isSuccess = ConfigurationStatus_Accepted;
  9892. }
  9893. }
  9894. else
  9895. {
  9896. isSuccess = ConfigurationStatus_Rejected;
  9897. }
  9898. }
  9899. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9900. {
  9901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9902. {
  9903. check_ascii = value[0];
  9904. if( (check_ascii < 48) || (check_ascii > 57) )
  9905. {
  9906. isSuccess = ConfigurationStatus_Rejected;
  9907. }
  9908. else
  9909. {
  9910. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9912. isSuccess = ConfigurationStatus_Accepted;
  9913. }
  9914. }
  9915. else
  9916. {
  9917. isSuccess = ConfigurationStatus_Rejected;
  9918. }
  9919. }
  9920. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9921. {
  9922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9923. {
  9924. check_ascii = value[0];
  9925. if( (check_ascii < 48) || (check_ascii > 57) )
  9926. {
  9927. isSuccess = ConfigurationStatus_Rejected;
  9928. }
  9929. else
  9930. {
  9931. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9933. isSuccess = ConfigurationStatus_Accepted;
  9934. }
  9935. }
  9936. else
  9937. {
  9938. isSuccess = ConfigurationStatus_Rejected;
  9939. }
  9940. }
  9941. if(strcmp(key, "HeartbeatInterval") == 0)
  9942. {
  9943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9944. {
  9945. check_ascii = value[0];
  9946. if( (check_ascii < 48) || (check_ascii > 57) )
  9947. {
  9948. isSuccess = ConfigurationStatus_Rejected;
  9949. }
  9950. else
  9951. {
  9952. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9954. HeartBeatWaitTime = atoi(value);
  9955. isSuccess = ConfigurationStatus_Accepted;
  9956. }
  9957. }
  9958. else
  9959. {
  9960. isSuccess = ConfigurationStatus_Rejected;
  9961. }
  9962. }
  9963. if(strcmp(key, "LightIntensity") == 0)
  9964. {
  9965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9966. {
  9967. check_ascii = value[0];
  9968. if( (check_ascii < 48) || (check_ascii > 57) )
  9969. {
  9970. isSuccess = ConfigurationStatus_Rejected;
  9971. }
  9972. else
  9973. {
  9974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9975. isSuccess = ConfigurationStatus_Accepted;
  9976. }
  9977. }
  9978. else
  9979. {
  9980. isSuccess = ConfigurationStatus_Rejected;
  9981. }
  9982. }
  9983. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9984. {
  9985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9986. {
  9987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9988. isSuccess = ConfigurationStatus_Accepted;
  9989. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9990. }
  9991. else
  9992. {
  9993. isSuccess = ConfigurationStatus_Rejected;
  9994. }
  9995. }
  9996. if(strcmp(key, "LocalPreAuthorize") == 0)
  9997. {
  9998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9999. {
  10000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10001. isSuccess = ConfigurationStatus_Accepted;
  10002. }
  10003. else
  10004. {
  10005. isSuccess = ConfigurationStatus_Rejected;
  10006. }
  10007. }
  10008. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10009. {
  10010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10011. {
  10012. check_ascii = value[0];
  10013. if( (check_ascii < 48) || (check_ascii > 57) )
  10014. {
  10015. isSuccess = ConfigurationStatus_Rejected;
  10016. }
  10017. else
  10018. {
  10019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10020. isSuccess = ConfigurationStatus_Accepted;
  10021. }
  10022. }
  10023. else
  10024. {
  10025. isSuccess = ConfigurationStatus_Rejected;
  10026. }
  10027. }
  10028. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10029. {
  10030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10031. {
  10032. //int valueLength = strlen(value);
  10033. for(int i = 0; value[i]; i++){
  10034. value[i] = tolower(value[i]);
  10035. }
  10036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10037. isSuccess = ConfigurationStatus_Accepted;
  10038. }
  10039. else
  10040. {
  10041. isSuccess = ConfigurationStatus_Rejected;
  10042. }
  10043. }
  10044. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10045. {
  10046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10047. {
  10048. //int valueLength = strlen(value);
  10049. for(int i = 0; value[i]; i++){
  10050. value[i] = tolower(value[i]);
  10051. }
  10052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10053. isSuccess = ConfigurationStatus_Accepted;
  10054. }
  10055. else
  10056. {
  10057. isSuccess = ConfigurationStatus_Rejected;
  10058. }
  10059. }
  10060. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10061. {
  10062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10063. {
  10064. check_ascii = value[0];
  10065. if( (check_ascii < 48) || (check_ascii > 57) )
  10066. {
  10067. isSuccess = ConfigurationStatus_Rejected;
  10068. }
  10069. else
  10070. {
  10071. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10073. isSuccess = ConfigurationStatus_Accepted;
  10074. }
  10075. #ifdef Debug
  10076. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10077. #endif
  10078. }
  10079. else
  10080. {
  10081. isSuccess = ConfigurationStatus_Rejected;
  10082. #ifdef Debug
  10083. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10084. #endif
  10085. }
  10086. }
  10087. if(strcmp(key, "MinimumStatusDuration") == 0)
  10088. {
  10089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10090. {
  10091. check_ascii = value[0];
  10092. if( (check_ascii < 48) || (check_ascii > 57) )
  10093. {
  10094. isSuccess = ConfigurationStatus_Rejected;
  10095. }
  10096. else
  10097. {
  10098. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10100. isSuccess = ConfigurationStatus_Accepted;
  10101. }
  10102. }
  10103. else
  10104. {
  10105. isSuccess = ConfigurationStatus_Rejected;
  10106. }
  10107. }
  10108. if(strcmp(key, "ResetRetries") == 0)
  10109. {
  10110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10111. {
  10112. check_ascii = value[0];
  10113. if( (check_ascii < 48) || (check_ascii > 57) )
  10114. {
  10115. isSuccess = ConfigurationStatus_Rejected;
  10116. }
  10117. else
  10118. {
  10119. //Charger.ResetRetries = Integer.parseInt(value);
  10120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10121. isSuccess = ConfigurationStatus_Accepted;
  10122. }
  10123. }
  10124. else
  10125. {
  10126. isSuccess = ConfigurationStatus_Rejected;
  10127. }
  10128. }
  10129. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10130. {
  10131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10132. {
  10133. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10134. //int valueLength = strlen(value);
  10135. for(int i = 0; value[i]; i++){
  10136. value[i] = tolower(value[i]);
  10137. }
  10138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10139. isSuccess = ConfigurationStatus_Accepted;
  10140. }
  10141. else
  10142. {
  10143. isSuccess = ConfigurationStatus_Rejected;
  10144. }
  10145. }
  10146. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10147. {
  10148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10149. {
  10150. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10152. isSuccess = ConfigurationStatus_Accepted;
  10153. }
  10154. else
  10155. {
  10156. isSuccess = ConfigurationStatus_Rejected;
  10157. }
  10158. }
  10159. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10160. {
  10161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10162. {
  10163. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10165. isSuccess = ConfigurationStatus_Accepted;
  10166. }
  10167. else
  10168. {
  10169. isSuccess = ConfigurationStatus_Rejected;
  10170. }
  10171. }
  10172. if(strcmp(key, "StopTxnAlignedData") == 0)
  10173. {
  10174. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10175. {
  10176. //Charger.StopTxnAlignedData = value.toLowerCase();
  10177. //int valueLength = strlen(value);
  10178. for(int i = 0; value[i]; i++){
  10179. value[i] = tolower(value[i]);
  10180. }
  10181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10182. isSuccess = ConfigurationStatus_Accepted;
  10183. }
  10184. else
  10185. {
  10186. isSuccess = ConfigurationStatus_Rejected;
  10187. }
  10188. }
  10189. if(strcmp(key, "StopTxnSampledData") == 0)
  10190. {
  10191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10192. {
  10193. //Charger.StopTxnSampledData = value.toLowerCase();
  10194. //int valueLength = strlen(value);
  10195. for(int i = 0; value[i]; i++){
  10196. value[i] = tolower(value[i]);
  10197. }
  10198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10199. isSuccess = ConfigurationStatus_Accepted;
  10200. }
  10201. else
  10202. {
  10203. isSuccess = ConfigurationStatus_Rejected;
  10204. }
  10205. }
  10206. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10207. {
  10208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10209. {
  10210. check_ascii = value[0];
  10211. if( (check_ascii < 48) || (check_ascii > 57) )
  10212. {
  10213. isSuccess = ConfigurationStatus_Rejected;
  10214. }
  10215. else
  10216. {
  10217. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10219. TransactionMessageAttemptsValue = atoi(value);
  10220. isSuccess = ConfigurationStatus_Accepted;
  10221. }
  10222. }
  10223. else
  10224. {
  10225. isSuccess = ConfigurationStatus_Rejected;
  10226. }
  10227. }
  10228. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10229. {
  10230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10231. {
  10232. check_ascii = value[0];
  10233. if( (check_ascii < 48) || (check_ascii > 57) )
  10234. {
  10235. isSuccess = ConfigurationStatus_Rejected;
  10236. }
  10237. else
  10238. {
  10239. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10241. TransactionMessageRetryIntervalValue = atoi(value);
  10242. isSuccess = ConfigurationStatus_Accepted;
  10243. }
  10244. }
  10245. else
  10246. {
  10247. isSuccess = ConfigurationStatus_Rejected;
  10248. }
  10249. }
  10250. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10251. {
  10252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10253. {
  10254. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10256. isSuccess = ConfigurationStatus_Accepted;
  10257. }
  10258. else
  10259. {
  10260. isSuccess = ConfigurationStatus_Rejected;
  10261. }
  10262. }
  10263. if(strcmp(key, "WebSocketPingInterval") == 0)
  10264. {
  10265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10266. {
  10267. check_ascii = value[0];
  10268. if( (check_ascii < 48) || (check_ascii > 57) )
  10269. {
  10270. isSuccess = ConfigurationStatus_Rejected;
  10271. }
  10272. else
  10273. {
  10274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10275. isSuccess = ConfigurationStatus_Accepted;
  10276. }
  10277. }
  10278. else
  10279. {
  10280. isSuccess = ConfigurationStatus_Rejected;
  10281. }
  10282. }
  10283. #if 0
  10284. //For OCPP Test Case
  10285. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10286. {
  10287. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10288. {
  10289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10290. isSuccess = ConfigurationStatus_Accepted;
  10291. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10292. }
  10293. else
  10294. {
  10295. isSuccess = ConfigurationStatus_Rejected;
  10296. }
  10297. }
  10298. #endif
  10299. #if 1
  10300. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10301. {
  10302. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10303. {
  10304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10305. isSuccess = ConfigurationStatus_Accepted;
  10306. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10307. }
  10308. else
  10309. {
  10310. isSuccess = ConfigurationStatus_Rejected;
  10311. }
  10312. }
  10313. #endif
  10314. return isSuccess;
  10315. }
  10316. int updateSetting(char *key, char *value)
  10317. {
  10318. mtrace();
  10319. int isSuccess = FALSE;
  10320. char string[1000]={0}, buffer[1000]={0};
  10321. char strtemp[50]={0};
  10322. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10323. int pos, c = 0;
  10324. char *loc;
  10325. int pos1=0;
  10326. FILE *f = fopen("/var/www/settings1", "r");
  10327. if(f == NULL)
  10328. {
  10329. #ifdef Debug
  10330. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10331. #endif
  10332. return isSuccess;
  10333. }
  10334. fseek(f, 0, SEEK_END);
  10335. long fsize = ftell(f);
  10336. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10337. fread(string, 1, fsize, f);
  10338. fclose(f);
  10339. string[fsize] = 0;
  10340. loc = strstr(string, key);
  10341. if(loc != NULL)
  10342. {
  10343. DEBUG_INFO("key exist!\n");
  10344. pos = loc - string-1;
  10345. f = fopen("/var/www/settings1", "w");
  10346. strncpy(buffer, string, pos);
  10347. fprintf(f, "%s", buffer);
  10348. memset(sstr ,0, sizeof(sstr) );
  10349. c = 0;
  10350. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10351. {
  10352. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10353. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10354. c++;
  10355. }
  10356. sstr[c] = '\0';
  10357. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10358. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10359. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10360. memset(buffer ,0, sizeof(buffer) );
  10361. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10362. //printf("buffer=%s",buffer);
  10363. fprintf(f, "%s", buffer);
  10364. fclose(f);
  10365. }
  10366. else
  10367. {
  10368. printf("key not exist!\n");
  10369. f = fopen("/var/www/settings1", "w+");
  10370. fputs(string, f);
  10371. fseek(f, -1, SEEK_CUR);
  10372. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10373. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10374. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10375. fclose(f);
  10376. }
  10377. isSuccess = TRUE;
  10378. return isSuccess;
  10379. }
  10380. int TransactionMessageAttemptsGet(void)
  10381. {
  10382. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10383. }
  10384. int FirstHeartBeatResponse(void)
  10385. {
  10386. return FirstHeartBeat;
  10387. }
  10388. int TransactionMessageRetryIntervalGet(void)
  10389. {
  10390. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10391. }
  10392. #define SA struct sockaddr
  10393. #define MAXBUF 1024
  10394. //static int m_socket_data;
  10395. //static int sockfd;
  10396. int ReadHttpStatus(int sock){
  10397. //char c;
  10398. char buff[1024]="",*ptr=buff+1;
  10399. int bytes_received, status;
  10400. DEBUG_INFO("Begin Response ..\n");
  10401. while((bytes_received = recv(sock, ptr, 1, 0))){
  10402. if(bytes_received==-1){
  10403. perror("ReadHttpStatus");
  10404. exit(1);
  10405. }
  10406. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10407. ptr++;
  10408. }
  10409. *ptr=0;
  10410. ptr=buff+1;
  10411. sscanf(ptr,"%*s %d ", &status);
  10412. DEBUG_INFO("%s\n",ptr);
  10413. DEBUG_INFO("status=%d\n",status);
  10414. DEBUG_INFO("End Response ..\n");
  10415. return (bytes_received>0)?status:0;
  10416. }
  10417. //the only filed that it parsed is 'Content-Length'
  10418. int ParseHeader(int sock){
  10419. //char c;
  10420. char buff[1024]="",*ptr=buff+4;
  10421. int bytes_received;
  10422. DEBUG_INFO("Begin HEADER ..\n");
  10423. while((bytes_received = recv(sock, ptr, 1, 0))){
  10424. if(bytes_received==-1){
  10425. perror("Parse Header");
  10426. exit(1);
  10427. }
  10428. if(
  10429. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10430. (ptr[-1]=='\r') && (*ptr=='\n' )
  10431. ) break;
  10432. ptr++;
  10433. }
  10434. *ptr=0;
  10435. ptr=buff+4;
  10436. //printf("%s",ptr);
  10437. if(bytes_received){
  10438. ptr=strstr(ptr,"Content-Length:");
  10439. if(ptr){
  10440. sscanf(ptr,"%*s %d",&bytes_received);
  10441. }else
  10442. bytes_received=-1; //unknown size
  10443. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10444. }
  10445. DEBUG_INFO("End HEADER ..\n");
  10446. return bytes_received ;
  10447. }
  10448. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10449. {
  10450. char rmFileCmd[100]={0};
  10451. char FilePath[100]={0};
  10452. char ftpbuf[200];
  10453. int systemresult;
  10454. DEBUG_INFO("filename=%s\n",filename);
  10455. DEBUG_INFO("url=%s\n",url);
  10456. sprintf(FilePath,"../mnt/%s",filename);
  10457. if((access(FilePath,F_OK))!=-1)
  10458. {
  10459. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10460. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10461. system(rmFileCmd);
  10462. }
  10463. memset(ftpbuf, 0, sizeof(ftpbuf));
  10464. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10465. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10466. systemresult = system(ftpbuf);
  10467. DEBUG_INFO("systemresult=%d\n",systemresult);
  10468. if(systemresult != 0)
  10469. {
  10470. DEBUG_INFO("http DownLoad error!\n");
  10471. return FALSE;
  10472. }
  10473. return TRUE;
  10474. }
  10475. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10476. {
  10477. char rmFileCmd[100]={0};
  10478. char FilePath[100]={0};
  10479. char ftpbuf[200];
  10480. int systemresult;
  10481. //char temp[100];
  10482. #if 0
  10483. struct hostent* server;
  10484. char *IPbuffer;
  10485. server = gethostbyname(location);
  10486. // To convert an Internet network
  10487. // address into ASCII string
  10488. IPbuffer = inet_ntoa(*((struct in_addr*)
  10489. server->h_addr_list[0]));
  10490. #endif
  10491. sprintf(FilePath,"../mnt/%s",filename);
  10492. if((access(FilePath,F_OK))!=-1)
  10493. {
  10494. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10495. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10496. system(rmFileCmd);
  10497. }
  10498. memset(ftpbuf, 0, sizeof(ftpbuf));
  10499. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10500. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10501. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10502. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10503. systemresult = system(ftpbuf);
  10504. DEBUG_INFO("systemresult=%d\n",systemresult);
  10505. if(systemresult != 0)
  10506. {
  10507. printf("ftpget error!\n");
  10508. return FALSE;
  10509. }
  10510. return TRUE;
  10511. }
  10512. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10513. {
  10514. struct hostent* server;
  10515. char *IPbuffer;
  10516. char ftpbuf[200];
  10517. int systemresult;
  10518. // To retrieve host information
  10519. server = gethostbyname(location);
  10520. // To convert an Internet network
  10521. // address into ASCII string
  10522. IPbuffer = inet_ntoa(*((struct in_addr*)
  10523. server->h_addr_list[0]));
  10524. memset(ftpbuf, 0, sizeof(ftpbuf));
  10525. /* format : ftpput -u username -p passwd IP target source*/
  10526. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10527. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10528. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10529. systemresult = system(ftpbuf);
  10530. DEBUG_INFO("systemresult=%d\n",systemresult);
  10531. if(systemresult != 0)
  10532. {
  10533. DEBUG_INFO("ftpput error!\n");
  10534. return FALSE;
  10535. }
  10536. return TRUE;
  10537. }
  10538. int SettingChargingRecord(int target, int transactionId)
  10539. {
  10540. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10541. {
  10542. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10543. {
  10544. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10545. {
  10546. addBuff(target, transactionId, 0);
  10547. return TRUE;
  10548. }
  10549. }
  10550. for (int index = 0; index < CCS_QUANTITY; index++)
  10551. {
  10552. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10553. {
  10554. addBuff(target, transactionId, 0);
  10555. return TRUE;
  10556. }
  10557. }
  10558. for (int index = 0; index < GB_QUANTITY; index++)
  10559. {
  10560. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10561. {
  10562. addBuff(target, transactionId, 0);
  10563. return TRUE;
  10564. }
  10565. }
  10566. }
  10567. else
  10568. {
  10569. for (int index = 0; index < AC_QUANTITY; index++)
  10570. {
  10571. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10572. {
  10573. addBuff(target, transactionId, 0);
  10574. return TRUE;
  10575. }
  10576. }
  10577. }
  10578. return FALSE;
  10579. }
  10580. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10581. {
  10582. int isSuccess = FALSE;
  10583. //char *query = NULL;
  10584. sqlite3_stmt *stmt;
  10585. int rc; // return code
  10586. char str[20];
  10587. sprintf(str,"%d",user_id);
  10588. 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 */
  10589. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10590. rc = sqlite3_step(stmt); /* 3 */
  10591. if (rc != SQLITE_DONE) {
  10592. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10593. goto out;
  10594. }
  10595. sqlite3_finalize(stmt);
  10596. // free(query);
  10597. out:
  10598. //----------------------
  10599. // close SQLite database
  10600. //----------------------
  10601. sqlite3_close(db);
  10602. printf("database closed.\n");
  10603. return isSuccess;
  10604. }
  10605. /**
  10606. * Place the contents of the specified file into a memory buffer
  10607. *
  10608. * @param[in] filename The path and name of the file to read
  10609. * @param[out] filebuffer A pointer to the contents in memory
  10610. * @return status 0 success, 1 on failure
  10611. */
  10612. int get_file_contents(const char* filename, char** outbuffer) {
  10613. FILE* file = NULL;
  10614. long filesize;
  10615. const int blocksize = 1;
  10616. size_t readsize;
  10617. char* filebuffer;
  10618. // Open the file
  10619. file = fopen(filename, "r");
  10620. if (NULL == file)
  10621. {
  10622. printf("'%s' not opened\n", filename);
  10623. exit(EXIT_FAILURE);
  10624. }
  10625. // Determine the file size
  10626. fseek(file, 0, SEEK_END);
  10627. filesize = ftell(file);
  10628. rewind (file);
  10629. // Allocate memory for the file contents
  10630. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10631. *outbuffer = filebuffer;
  10632. if (filebuffer == NULL)
  10633. {
  10634. fputs ("malloc out-of-memory", stderr);
  10635. exit(EXIT_FAILURE);
  10636. }
  10637. // Read in the file
  10638. readsize = fread(filebuffer, blocksize, filesize, file);
  10639. if (readsize != filesize)
  10640. {
  10641. fputs ("didn't read file completely",stderr);
  10642. exit(EXIT_FAILURE);
  10643. }
  10644. // Clean exit
  10645. fclose(file);
  10646. return EXIT_SUCCESS;
  10647. }
  10648. static int selectSqlCount = 0;
  10649. static int callback(void *data, int argc, char **argv, char **azColName){
  10650. int i;
  10651. printf("%s: ", (const char*)data);
  10652. selectSqlCount = argc;
  10653. for(i = 0; i<argc; i++){
  10654. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10655. }
  10656. printf("\n");
  10657. return 0;
  10658. }
  10659. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10660. //int i;
  10661. //printf("%s:\n", (const char*)data);
  10662. localversion = argv[5] ? atoi(argv[5]) : 0;
  10663. printf("localversion=%d\n", localversion);
  10664. return 0;
  10665. }
  10666. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10667. //int i;
  10668. //printf("%s:\n", (const char*)data);
  10669. //idTag
  10670. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10671. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10672. //parentIdTag
  10673. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10674. //expir_date
  10675. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10676. //status
  10677. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10678. //version
  10679. idTagQuery.listVersionInt = atoi(argv[5]);
  10680. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10681. return 0;
  10682. }
  10683. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10684. int i;
  10685. //printf("%s:\n", (const char*)data);
  10686. #if 1
  10687. for(i=0; i<argc; i++){
  10688. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10689. }
  10690. //printf("");
  10691. #endif
  10692. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10693. // printf("localversion=%d\n", localversion);
  10694. return 0;
  10695. }
  10696. /** sqlite3_exec的回调。
  10697. *
  10698. * 向控制台打印查询的结果。
  10699. *
  10700. * @param in data 传递给回调函数的数据。
  10701. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10702. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10703. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10704. * @return 状态码。
  10705. */
  10706. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10707. {
  10708. for (int i = 0; i < n_columns; i++)
  10709. {
  10710. DEBUG_INFO("%s/t", col_values[i]);
  10711. }
  10712. DEBUG_INFO("/n");
  10713. return 0;
  10714. }
  10715. void OCPP_getListVerion()
  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. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10724. /* Execute SQL statement */
  10725. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10726. DEBUG_INFO("rc=%d\n",rc);
  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. }
  10734. void OCPP_getIdTag(char *idTag)
  10735. {
  10736. int rc = 0;
  10737. // const char* data = "Callback function called";
  10738. char sql[100];
  10739. char zErrMsg[100];
  10740. memset(sql, 0, 100);
  10741. memset(zErrMsg, 0, 100);
  10742. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10743. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10744. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10745. /* Execute SQL statement */
  10746. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10747. if( rc != SQLITE_OK ){
  10748. DEBUG_INFO("SQL error: %s", zErrMsg);
  10749. //sqlite3_free(zErrMsg);
  10750. }else{
  10751. printf("Operation done successfully");
  10752. }
  10753. //return ver;
  10754. }
  10755. void OCPP_get_TableAuthlocalAllData(void)
  10756. {
  10757. int rc = 0;
  10758. // const char* data = "Callback function called";
  10759. char sql[100];
  10760. char zErrMsg[100];
  10761. memset(sql, 0, 100);
  10762. memset(zErrMsg, 0, 100);
  10763. sprintf(sql,"select * from ocpp_auth_local ");
  10764. /* Execute SQL statement */
  10765. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10766. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10767. if( rc != SQLITE_OK ){
  10768. DEBUG_INFO("SQL error: %s", zErrMsg);
  10769. //sqlite3_free(zErrMsg);
  10770. }else{
  10771. DEBUG_INFO("Operation done successfully");
  10772. }
  10773. //return ver;
  10774. }
  10775. int OCPP_cleanLocalList()
  10776. {
  10777. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10778. char *errMsg = 0;
  10779. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10780. if (SQLITE_OK != rc)
  10781. {
  10782. DEBUG_INFO("%s\n",errMsg);
  10783. return FALSE;
  10784. }
  10785. else
  10786. {
  10787. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10788. }
  10789. return TRUE;
  10790. }
  10791. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10792. {
  10793. int isSuccess = FALSE;
  10794. int ret = 0;
  10795. //const char* data = "Callback function called";
  10796. char sql[200];
  10797. char zErrMsg[100];
  10798. memset(sql, 0, 200);
  10799. memset(zErrMsg, 0, 100);
  10800. 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);
  10801. //* Execute SQL statement */
  10802. //zErrMsg = 0;
  10803. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10804. if( ret != SQLITE_OK ){
  10805. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10806. // free(zErrMsg);
  10807. // free(sql);
  10808. return isSuccess;
  10809. }
  10810. DEBUG_INFO("successfully Insert records created\n");
  10811. isSuccess = TRUE;
  10812. return isSuccess;
  10813. }
  10814. void OCPP_deleteIdTag(char *idTag)
  10815. {
  10816. //int ver = 0;
  10817. //int isSuccess = FALSE;
  10818. int rc = 0;
  10819. char sql[100];
  10820. char zErrMsg[100];
  10821. memset(sql, 0, 100);
  10822. memset(zErrMsg, 0, 100);
  10823. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10824. //* Execute SQL statement */
  10825. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10826. if( rc != SQLITE_OK ){
  10827. DEBUG_INFO("SQL error: %s", zErrMsg);
  10828. //sqlite3_free(zErrMsg);
  10829. }else{
  10830. DEBUG_INFO("Operation done successfully");
  10831. }
  10832. }
  10833. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10834. {
  10835. int isSuccess = FALSE;
  10836. int ret = 0;
  10837. const char* data = "Callback function called";
  10838. char sql[200];
  10839. char zErrMsg[100];
  10840. memset(sql, 0, 200);
  10841. memset(zErrMsg, 0, 100);
  10842. //* selectFromTable */
  10843. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10844. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10845. //* Execute SQL statement */
  10846. selectSqlCount = 0;
  10847. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10848. if( ret != SQLITE_OK ){
  10849. printf("Error SQL: %s\n", zErrMsg);
  10850. }
  10851. printf("successfully select operation done\n");
  10852. memset(sql, 0, 200);
  10853. memset(zErrMsg, 0, 100);
  10854. if(selectSqlCount == 0)
  10855. {
  10856. //Insert
  10857. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  10858. 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);
  10859. DEBUG_INFO("sql:%s\n", sql);
  10860. //* Execute SQL statement */
  10861. //zErrMsg = 0;
  10862. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10863. if( ret != SQLITE_OK ){
  10864. printf("SQL error: %s\n", zErrMsg);
  10865. return isSuccess;
  10866. }
  10867. DEBUG_INFO("successfully Insert records created\n");
  10868. isSuccess = TRUE;
  10869. }
  10870. else
  10871. {
  10872. //Update
  10873. //* Create merged SQL statement */
  10874. 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);
  10875. /* Execute SQL statement */
  10876. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10877. if( ret != SQLITE_OK ){
  10878. printf("SQL error: %s\n", zErrMsg);
  10879. //sqlite3_free(zErrMsg);
  10880. //sqlite3_free(sql);
  10881. return isSuccess;
  10882. }
  10883. DEBUG_INFO("Successfully operation done \n");
  10884. isSuccess = TRUE;
  10885. }
  10886. return isSuccess;
  10887. }
  10888. char *GetOcppServerURL()
  10889. {
  10890. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10891. memset(OcppHost, 0, sizeof(OcppHost));
  10892. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10893. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10894. {
  10895. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10896. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10897. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10898. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10899. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10900. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10901. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10902. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10903. goto End;
  10904. }
  10905. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10906. {
  10907. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10908. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10909. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10910. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10911. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10912. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10913. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10914. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10915. goto End;
  10916. }
  10917. else
  10918. {
  10919. strcpy(OcppHost,"");
  10920. }
  10921. End:
  10922. return OcppHost;
  10923. }
  10924. char *GetOcppPath()
  10925. {
  10926. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10927. {
  10928. if(OcppTempPath == NULL)
  10929. {
  10930. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10931. }
  10932. else
  10933. {
  10934. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10935. }
  10936. goto End;
  10937. }
  10938. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10939. {
  10940. if(OcppTempPath == NULL)
  10941. {
  10942. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10943. }
  10944. else
  10945. {
  10946. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10947. }
  10948. goto End;
  10949. }
  10950. else
  10951. {
  10952. strcpy(OcppHost,"");
  10953. }
  10954. End:
  10955. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10956. return OcppPath;
  10957. }
  10958. int GetOcppPort()
  10959. {
  10960. return OcppPort;
  10961. }
  10962. int GetOcppConnStatus(void)
  10963. {
  10964. return ShmOCPP16Data->OcppConnStatus;
  10965. }
  10966. void SetOcppConnStatus(uint8_t status)
  10967. {
  10968. ShmOCPP16Data->OcppConnStatus = status;
  10969. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  10970. if(status == FALSE)
  10971. {
  10972. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10973. {
  10974. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  10975. }
  10976. else
  10977. {
  10978. SystemInitial = AC_QUANTITY;
  10979. }
  10980. }
  10981. }
  10982. int GetHeartBeatWithNOResponse(void)
  10983. {
  10984. return HeartBeatWithNOResponse;
  10985. }
  10986. void SetHeartBeatWithNOResponse(void)
  10987. {
  10988. HeartBeatWithNOResponse = 0;
  10989. }
  10990. int InternetDisconnect(void)
  10991. {
  10992. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  10993. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  10994. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  10995. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  10996. }
  10997. #if 0
  10998. void Send(struct json_object *message)
  10999. {
  11000. printf("Send -1 \n");
  11001. printf("message=%s\n",json_object_to_json_string(message));
  11002. LWS_Send(json_object_to_json_string(message));
  11003. }
  11004. #endif
  11005. void LWS_Send(char * str)
  11006. {
  11007. #if 1
  11008. //=====================================================
  11009. // Check InternetConn 0: disconnected, 1: connected
  11010. //====================================================
  11011. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  11012. {
  11013. DEBUG_INFO("\n offline now !!!\n");
  11014. return;
  11015. }
  11016. #endif
  11017. pthread_mutex_lock(&lock);
  11018. memset(SendBuffer,0,SendBufLen);
  11019. sprintf((char *)SendBuffer, "%s", str);
  11020. pthread_mutex_unlock(&lock);
  11021. lws_callback_on_writable(wsi_client);
  11022. lws_service(context, 10000);//timeout_ms
  11023. //usleep(10000); // 等�??��?微�?
  11024. //DEBUG_INFO("Send message end\n");
  11025. }