MessageHandler.c 455 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "SystemLogMessage.h"
  24. #include "define.h"
  25. #include "ShareMemory.h"
  26. #include "SystemLogMessage.h"
  27. //#include "config.h"
  28. #include <sys/socket.h>
  29. #include <netinet/in.h>
  30. #include <stdlib.h>
  31. /*for sendfile()*/
  32. #include <sys/sendfile.h>
  33. /*for O_RDONLY*/
  34. #include <fcntl.h>
  35. #include "sqlite3.h"
  36. #include <arpa/inet.h>
  37. //#define _GNU_SOURCE
  38. #include <time.h>
  39. #include "MessageHandler.h"
  40. #include <assert.h>
  41. #include <pthread.h>
  42. #include <mcheck.h>
  43. #define PASS 1
  44. #define FAIL -1
  45. #define FALSE 0
  46. #define TRUE 1 // Option 1
  47. //ChargePointMaxProfile
  48. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  49. //TxDefaultProfile
  50. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  51. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  52. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  53. //TxProfile
  54. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  55. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  56. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  57. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  58. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  59. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  60. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  61. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  62. struct StatusCodeData *ShmStatusCodeData;
  63. struct PsuData *ShmPsuData ;
  64. struct OCPP16Data *ShmOCPP16Data;
  65. // define Macro
  66. #define SystemLogMessage
  67. // OCPP Message Type
  68. #define MESSAGE_TYPE_CALL 2
  69. #define MESSAGE_TYPE_CALLRESULT 3
  70. #define MESSAGE_TYPE_CALLERROR 4
  71. //
  72. #define server_cycle_Status 120
  73. #define MACROSTR(k) #k
  74. //ConfigurationMaxKeys
  75. #define GetConfigurationMaxKeysNUM 43
  76. //char guid[37];
  77. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  78. char queuedata[2000]={0};
  79. //===============================
  80. // Configuration: unknownkey
  81. //===============================
  82. static char unknownkey[10][20]={0};
  83. static int UnknownKeynum = 0;
  84. //===============================
  85. // Gun Total Numbers
  86. //===============================
  87. //#define gunTotalNumber (strstr(ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL) ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  88. static int gunTotalNumber=0;
  89. //===============================
  90. // Local List Version
  91. //===============================
  92. static int localversion=0;
  93. static char idTagAuthorization[32]={0};
  94. //===============================
  95. // OCPP Path
  96. //===============================
  97. char OcppPath[160]={};
  98. char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP other variables
  115. //===============================
  116. int isUpdateRequest = FALSE;
  117. static int HeartBeatWaitTime = 10;
  118. static int FirstHeartBeat = 0;
  119. static int FirmwareStatusNotificationStatus = 3; // Idle
  120. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  121. //========================================
  122. // OCPP status/previous related variables
  123. //========================================
  124. static int GunStatusInterval = 10;
  125. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY] = {FALSE};
  126. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  127. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  128. static int GbPreviousSystemStatus[GB_QUANTITY];
  129. static int AcPreviousSystemStatus[AC_QUANTITY];
  130. int TransactionMessageAttemptsValue = 0;
  131. int TransactionMessageRetryIntervalValue = 0;
  132. static struct OCPPAuthLocalElemet
  133. {
  134. int listVersionInt;
  135. char idTagstr[20];
  136. char parentIdTag[20];
  137. char expiryDate[30];
  138. char idTagstatus[16];
  139. }idTagQuery;
  140. extern struct lws *wsi_client;
  141. extern struct lws_context *context;
  142. #if 0
  143. extern unsigned char *SendBuffer;
  144. #endif
  145. extern unsigned char SendBuffer[4096];
  146. extern int SendBufLen;
  147. //extern map_t hashMap;
  148. //extern data_struct_t* mapItem; --- remove for temporally
  149. //extern data_struct_t mapItem[0];
  150. extern char *random_uuid( char buf[37] );
  151. extern void split(char **arr, char *str, const char *del);
  152. extern pthread_mutex_t mutex1;
  153. extern struct Charger_Info Charger;
  154. extern sqlite3 *db;
  155. int TransactionMessageAttemptsGet(void);
  156. int TransactionMessageRetryIntervalGet(void);
  157. int GetOcppConnStatus(void);
  158. void SetOcppConnStatus(uint8_t status);
  159. int updateSetting(char *key, char *value);
  160. int setKeyValue(char *key, char *value);
  161. void OCPP_get_TableAuthlocalAllData(void);
  162. void processUnkownKey(void);
  163. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  164. struct StructOCPPMeterValue
  165. {
  166. unsigned char TimeStamp[28];
  167. struct StructSampledValue SampledValue[10];
  168. };
  169. struct ClientTime
  170. {
  171. unsigned int Heartbeat;
  172. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  173. unsigned int StartTransaction;
  174. unsigned int StopTransaction;
  175. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  176. }clientTime;
  177. typedef union
  178. {
  179. //Operations Initiated by Central System
  180. unsigned char CsMsgValue[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  181. struct
  182. {
  183. //CsMsgValue[0]
  184. unsigned char StatusNotificationReq :1; //bit 0,
  185. unsigned char StatusNotificationConf :1; //bit 0,
  186. unsigned char :6; //bit 2~7
  187. }bits[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  188. }CpinitiateMsg;
  189. CpinitiateMsg cpinitateMsg;
  190. //==========================================
  191. // Init all Enumeration & Mapping String
  192. //==========================================
  193. /*ChargePointErrorCode*/
  194. typedef enum {
  195. ConnectorLockFailure,
  196. EVCommunicationError,
  197. GroundFailure,
  198. HighTemperature,
  199. InternalError,
  200. LocalListConflict,
  201. NoError,
  202. OtherError,
  203. OverCurrentFailure,
  204. OverVoltage,
  205. PowerMeterFailure,
  206. PowerSwitchFailure,
  207. ReaderFailure,
  208. ResetFailure,
  209. UnderVoltage,
  210. WeakSignal
  211. } ChargePointErrorCode;
  212. #if 0
  213. static char *ChargePointErrorCodeStr[] = {
  214. MACROSTR(ConnectorLockFailure),
  215. MACROSTR(EVCommunicationError),
  216. MACROSTR(GroundFailure),
  217. MACROSTR(HighTemperature),
  218. MACROSTR(InternalError),
  219. MACROSTR(LocalListConflict),
  220. MACROSTR(NoError),
  221. MACROSTR(OtherError),
  222. MACROSTR(OverCurrentFailure),
  223. MACROSTR(OverVoltage),
  224. MACROSTR(PowerMeterFailure),
  225. MACROSTR(PowerSwitchFailure),
  226. MACROSTR(ReaderFailure),
  227. MACROSTR(ResetFailure),
  228. MACROSTR(UnderVoltage),
  229. MACROSTR(WeakSignal)
  230. };
  231. #endif
  232. /*ChargePointStatus*/
  233. typedef enum {
  234. Available =0,
  235. Preparing,
  236. Charging,
  237. SuspendedEVSE,
  238. SuspendedEV,
  239. Finishing,
  240. Reserved,
  241. Unavailable,
  242. Faulted
  243. } ChargePointStatus;
  244. static char * ChargePointStatusStr[] = {
  245. MACROSTR(Available),
  246. MACROSTR(Preparing),
  247. MACROSTR(Charging),
  248. MACROSTR(SuspendedEVSE),
  249. MACROSTR(SuspendedEV),
  250. MACROSTR(Finishing),
  251. MACROSTR(Reserved),
  252. MACROSTR(Unavailable),
  253. MACROSTR(Faulted)
  254. };
  255. /*AvailabilityType*/
  256. typedef enum {
  257. RegistrationStatus_Accepted,
  258. RegistrationStatus_Pending,
  259. RegistrationStatus_Rejected
  260. } RegistrationStatus;
  261. static char *RegistrationStatusStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Pending),
  264. MACROSTR(Rejected)
  265. };
  266. /*AvailabilityType*/
  267. typedef enum {
  268. Inoperative,
  269. Operative
  270. } AvailabilityType;
  271. static char *AvailabilityTypeStr[] = {
  272. MACROSTR(Inoperative),
  273. MACROSTR(Operative)
  274. };
  275. /*AvailabilityStatus*/
  276. typedef enum {
  277. Accepted,
  278. Rejected,
  279. Scheduled
  280. } AvailabilityStatus;
  281. static char *AvailabilityStatusStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Rejected),
  284. MACROSTR(Scheduled)
  285. };
  286. /*ConfigurationStatus*/
  287. typedef enum {
  288. ConfigurationStatus_Accepted,
  289. ConfigurationStatus_Rejected,
  290. RebootRequired,
  291. NotSupported
  292. } ConfigurationStatus;
  293. static char *ConfigurationStatusStr[] = {
  294. MACROSTR(Accepted),
  295. MACROSTR(Rejected),
  296. MACROSTR(RebootRequired),
  297. MACROSTR(NotSupported)
  298. };
  299. /*ClearCacheStatus*/
  300. typedef enum {
  301. ClearCacheStatus_Accepted,
  302. ClearCacheStatus_Rejected
  303. } ClearCacheStatus;
  304. static char *ClearCacheStatusStr[] = {
  305. MACROSTR(Accepted),
  306. MACROSTR(Rejected)
  307. };
  308. /*ChargingProfilePurposeType*/
  309. typedef enum {
  310. ChargePointMaxProfile,
  311. TxDefaultProfile,
  312. TxProfile
  313. } ChargingProfilePurposeType;
  314. static char *ChargingProfilePurposeTypeStr[] = {
  315. MACROSTR(ChargePointMaxProfile),
  316. MACROSTR(TxDefaultProfile),
  317. MACROSTR(TxProfile)
  318. };
  319. /*ChargingProfileStatus*/
  320. typedef enum {
  321. ChargingProfileStatus_Accepted,
  322. ChargingProfileStatus_Rejected,
  323. ChargingProfileStatus_NotSupported
  324. } ChargingProfileStatus;
  325. static char *ChargingProfileStatusStr[] = {
  326. MACROSTR(Accepted),
  327. MACROSTR(Rejected),
  328. MACROSTR(NotSupported)
  329. };
  330. /*ClearChargingProfileStatus*/
  331. typedef enum {
  332. ClearChargingProfileStatus_Accepted,
  333. ClearChargingProfileStatus_Unknown
  334. } ClearChargingProfileStatus;
  335. static char *ClearChargingProfileStatusStr[] = {
  336. MACROSTR(Accepted),
  337. MACROSTR(Unknown)
  338. };
  339. /*GetCompositeScheduleStatus*/
  340. typedef enum {
  341. GetCompositeScheduleStatus_Accepted,
  342. GetCompositeScheduleStatus_Rejected
  343. } GetCompositeScheduleStatus;
  344. static char *GetCompositeScheduleStatusStr[] = {
  345. MACROSTR(Accepted),
  346. MACROSTR(Rejected)
  347. };
  348. /*ChargingRateUnitType*/
  349. typedef enum {
  350. ChargingRateUnitType_W,
  351. ChargingRateUnitType_A
  352. } ChargingRateUnitType;
  353. /*AuthorizationStatus*/
  354. typedef enum {
  355. AuthorizationStatus_Accepted ,
  356. AuthorizationStatus_Blocked ,
  357. AuthorizationStatus_Expired ,
  358. AuthorizationStatus_Invalid ,
  359. AuthorizationStatus_ConcurrentTx
  360. } AuthorizationStatus;
  361. /*UpdateType*/
  362. typedef enum {
  363. Differential ,
  364. Full
  365. } UpdateType;
  366. static char *UpdateTypeStr[] = {
  367. MACROSTR(Differential),
  368. MACROSTR(Full)
  369. };
  370. /*UpdateStatus*/
  371. typedef enum {
  372. UpdateStatus_Accepted ,
  373. UpdateStatus_Failed ,
  374. UpdateStatus_NotSupported ,
  375. UpdateStatus_VersionMismatch
  376. } UpdateStatus;
  377. static char *UpdateStatusStr[] = {
  378. MACROSTR(Accepted),
  379. MACROSTR(Failed),
  380. MACROSTR(NotSupported),
  381. MACROSTR(VersionMismatch)
  382. };
  383. /*RemoteStartStopStatus*/
  384. typedef enum {
  385. RemoteStartStopStatus_Accepted,
  386. RemoteStartStopStatus_Rejected
  387. } RemoteStartStopStatus;
  388. static char *RemoteStartStopStatusStr[] = {
  389. MACROSTR(Accepted),
  390. MACROSTR(Rejected)
  391. };
  392. /*ReservationStatus*/
  393. typedef enum {
  394. ReservationStatus_Accepted,
  395. ReservationStatus_Faulted,
  396. ReservationStatus_Occupied,
  397. ReservationStatus_Rejected,
  398. ReservationStatus_Unavailable
  399. } ReservationStatus;
  400. static char *ReservationStatusStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Faulted),
  403. MACROSTR(Occupied),
  404. MACROSTR(Rejected),
  405. MACROSTR(Unavailable)
  406. };
  407. /*ResetType*/
  408. typedef enum {
  409. Hard,
  410. Soft
  411. } ResetType;
  412. static char *ResetTypeStr[] = {
  413. MACROSTR(Hard),
  414. MACROSTR(Soft)
  415. };
  416. /*ResetStatus*/
  417. typedef enum {
  418. ResetStatus_Accepted,
  419. ResetStatus_Rejected
  420. } ResetStatus;
  421. static char *ResetStatusStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Rejected)
  424. };
  425. /*DiagnosticsStatus*/
  426. typedef enum {
  427. DiagnosticsStatus_Idle,
  428. DiagnosticsStatus_Uploaded,
  429. DiagnosticsStatus_UploadFailed,
  430. DiagnosticsStatus_Uploading
  431. } DiagnosticsStatus;
  432. static char * DiagnosticsStatusStr[] = {
  433. MACROSTR(Idle),
  434. MACROSTR(Uploaded),
  435. MACROSTR(UploadFailed),
  436. MACROSTR(Uploading)
  437. };
  438. /*FirmwareStatus*/
  439. typedef enum {
  440. FirmwareStatus_Downloaded,
  441. FirmwareStatus_DownloadFailed,
  442. FirmwareStatus_Downloading,
  443. FirmwareStatus_Idle,
  444. FirmwareStatus_InstallationFailed,
  445. FirmwareStatus_Installing,
  446. FirmwareStatus_Installed
  447. } FirmwareStatus;
  448. static char * FirmwareStatusStr[] = {
  449. MACROSTR(Downloaded),
  450. MACROSTR(DownloadFailed),
  451. MACROSTR(Downloading),
  452. MACROSTR(Idle),
  453. MACROSTR(InstallationFailed),
  454. MACROSTR(Installing),
  455. MACROSTR(Installed)
  456. };
  457. /*MessageTrigger*/
  458. typedef enum {
  459. BootNotification,
  460. DiagnosticsStatusNotification,
  461. FirmwareStatusNotification,
  462. Heartbeat,
  463. MeterValues,
  464. StatusNotification
  465. } MessageTrigger;
  466. static char * MessageTriggerStr[] = {
  467. MACROSTR(BootNotification),
  468. MACROSTR(DiagnosticsStatusNotification),
  469. MACROSTR(FirmwareStatusNotification),
  470. MACROSTR(Heartbeat),
  471. MACROSTR(MeterValues),
  472. MACROSTR(StatusNotification)
  473. };
  474. /*TriggerMessageStatus*/
  475. typedef enum {
  476. TriggerMessageStatus_Accepted ,
  477. TriggerMessageStatus_Rejected ,
  478. TriggerMessageStatus_NotImplemented
  479. } TriggerMessageStatus;
  480. static char * TriggerMessageStatusStr[] = {
  481. MACROSTR(Accepted),
  482. MACROSTR(Rejected),
  483. MACROSTR(NotImplemented)
  484. };
  485. /*UnlockStatus*/
  486. typedef enum {
  487. Unlocked,
  488. UnlockFailed,
  489. UnlockStatus_NotSupported
  490. } UnlockStatus;
  491. static char * UnlockStatusStr[] = {
  492. MACROSTR(Unlocked),
  493. MACROSTR(UnlockFailed),
  494. MACROSTR(NotSupported)
  495. };
  496. /*StopTransactionReason*/
  497. typedef enum {
  498. EmergencyStop,
  499. EVDisconnected,
  500. HardReset,
  501. Local,
  502. Other,
  503. PowerLoss,
  504. Reboot,
  505. Remote,
  506. SoftReset,
  507. UnlockCommand,
  508. DeAuthorized
  509. } StopTransactionReason;
  510. static char * StopTransactionReasonStr[] = {
  511. MACROSTR(EmergencyStop),
  512. MACROSTR(EVDisconnected),
  513. MACROSTR(HardReset),
  514. MACROSTR(Local),
  515. MACROSTR(Other),
  516. MACROSTR(PowerLoss),
  517. MACROSTR(Reboot),
  518. MACROSTR(Remote),
  519. MACROSTR(SoftReset),
  520. MACROSTR(UnlockCommand),
  521. MACROSTR(DeAuthorized)
  522. };
  523. /*CancelReservationStatus*/
  524. typedef enum {
  525. CancelReservationStatus_Accepted,
  526. CancelReservationStatus_Rejected
  527. } CancelReservationStatus;
  528. static char * CancelReservationStatusStr[] = {
  529. MACROSTR(Accepted),
  530. MACROSTR(Rejected)
  531. };
  532. /*ReadingContext*/
  533. typedef enum {
  534. ReadingContext_Interruption_Begin,
  535. ReadingContext_Interruption_End,
  536. ReadingContext_Other,
  537. ReadingContext_Sample_Clock,
  538. ReadingContext_Sample_Periodic ,
  539. ReadingContext_Transaction_Begin ,
  540. ReadingContext_Transaction_End,
  541. ReadingContext_Trigger
  542. } ReadingContext;
  543. static char * ReadingContextStr[] = {
  544. MACROSTR(Interruption.Begin),
  545. MACROSTR(Interruption.End),
  546. MACROSTR(Other),
  547. MACROSTR(Sample.Clock),
  548. MACROSTR(Sample.Periodic),
  549. MACROSTR(Transaction.Begin),
  550. MACROSTR(Transaction.End),
  551. MACROSTR(Trigger)
  552. };
  553. /*ValueFormat*/
  554. typedef enum {
  555. Raw,
  556. SignedData
  557. } ValueFormat;
  558. static char * ValueFormatStr[] = {
  559. MACROSTR(Raw),
  560. MACROSTR(SignedData)
  561. };
  562. /*Measurand*/
  563. typedef enum {
  564. Current_Export ,
  565. Current_Import,
  566. Current_Offered,
  567. Energy_Active_Export_Register,
  568. Energy_Active_Import_Register,
  569. Energy_Reactive_Export_Register,
  570. Energy_Reactive_Import_Register,
  571. Energy_Active_Export_Interval,
  572. Energy_Active_Import_Interval,
  573. Energy_Reactive_Export_Interval,
  574. Energy_Reactive_Import_Interval,
  575. Frequency,
  576. Power_Active_Export ,
  577. Power_Active_Import,
  578. Power_Factor,
  579. Power_Offered,
  580. Power_Reactive_Export,
  581. Power_Reactive_Import,
  582. RPM,
  583. SoC,
  584. Temperature ,
  585. Voltage
  586. } Measurand;
  587. static char * MeasurandStr[] = {
  588. MACROSTR(Current.Export),
  589. MACROSTR(Current.Import),
  590. MACROSTR(Current.Offered),
  591. MACROSTR(Energy.Active.Export.Register),
  592. MACROSTR(Energy.Active.Import.Register),
  593. MACROSTR(Energy.Reactive.Export.Register),
  594. MACROSTR(Energy.Reactive.Import.Register),
  595. MACROSTR(Energy.Active.Export.Interval),
  596. MACROSTR(Energy.Active.Import.Interval),
  597. MACROSTR(Energy.Reactive.Export.Interval),
  598. MACROSTR(Energy.Reactive.Import.Interval),
  599. MACROSTR(Frequency),
  600. MACROSTR(Power.Active.Export),
  601. MACROSTR(Power.Active.Import),
  602. MACROSTR(Power.Factor),
  603. MACROSTR(Power.Offered),
  604. MACROSTR(Power.Reactive.ExportMACROSTR),
  605. MACROSTR(Power.Reactive.Import),
  606. MACROSTR(RPM),
  607. MACROSTR(SoC),
  608. MACROSTR(Temperature),
  609. MACROSTR(Voltage)
  610. };
  611. /*Location*/
  612. typedef enum {
  613. Location_Body,
  614. Location_Cable,
  615. Location_EV,
  616. Location_Inlet ,
  617. Location_Outlet
  618. } Location;
  619. static char * LocationStr[] = {
  620. MACROSTR(Body),
  621. MACROSTR(Cable),
  622. MACROSTR(EV),
  623. MACROSTR(Inlet),
  624. MACROSTR(Outlet)
  625. };
  626. /*Phase*/
  627. typedef enum {
  628. L1,
  629. L2,
  630. L3,
  631. N,
  632. L1_N,
  633. L2_N,
  634. L3_N,
  635. L1_L2,
  636. L2_L3,
  637. L3_L1
  638. } Phase;
  639. static char * PhaseStr[] = {
  640. MACROSTR(L1),
  641. MACROSTR(L2),
  642. MACROSTR(L3),
  643. MACROSTR(N),
  644. MACROSTR(L1-N),
  645. MACROSTR(L2-N),
  646. MACROSTR(L3-N),
  647. MACROSTR(L1-L2),
  648. MACROSTR(L2-L3),
  649. MACROSTR(L3-L1)
  650. };
  651. /*UnitOfMeasure*/
  652. typedef enum {
  653. UnitOfMeasure_Wh,
  654. UnitOfMeasure_kWh ,
  655. UnitOfMeasure_varh ,
  656. UnitOfMeasure_kvarh ,
  657. UnitOfMeasure_W ,
  658. UnitOfMeasure_kW ,
  659. UnitOfMeasure_VA ,
  660. UnitOfMeasure_kVA ,
  661. UnitOfMeasure_var ,
  662. UnitOfMeasure_kvar ,
  663. UnitOfMeasure_A ,
  664. UnitOfMeasure_V ,
  665. UnitOfMeasure_Celsius ,
  666. UnitOfMeasure_Fahrenheit ,
  667. UnitOfMeasure_K ,
  668. UnitOfMeasure_Percent
  669. } UnitOfMeasure;
  670. static char * UnitOfMeasureStr[] = {
  671. MACROSTR(Wh),
  672. MACROSTR(kWh),
  673. MACROSTR(varh),
  674. MACROSTR(kvarh),
  675. MACROSTR(W),
  676. MACROSTR(kW),
  677. MACROSTR(VA),
  678. MACROSTR(kVA),
  679. MACROSTR(var),
  680. MACROSTR(kvar),
  681. MACROSTR(A),
  682. MACROSTR(V),
  683. MACROSTR(Celsius),
  684. MACROSTR(Fahrenheit),
  685. MACROSTR(K),
  686. MACROSTR(Percent)
  687. };
  688. /*Configuration enum*/
  689. enum CoreProfile {
  690. AllowOfflineTxForUnknownId=0,
  691. AuthorizationCacheEnabled,
  692. AuthorizeRemoteTxRequests,
  693. BlinkRepeat,
  694. ClockAlignedDataInterval,
  695. ConnectionTimeOut,
  696. GetConfigurationMaxKeys,
  697. HeartbeatInterval,
  698. LightIntensity,
  699. LocalAuthorizeOffline,
  700. LocalPreAuthorize,
  701. MaxEnergyOnInvalidId,
  702. MeterValuesAlignedData,
  703. MeterValuesAlignedDataMaxLength,
  704. MeterValuesSampledData,
  705. MeterValuesSampledDataMaxLength,
  706. MeterValueSampleInterval,
  707. MinimumStatusDuration,
  708. NumberOfConnectors,
  709. ResetRetries,
  710. ConnectorPhaseRotation,
  711. ConnectorPhaseRotationMaxLength,
  712. StopTransactionOnEVSideDisconnect,
  713. StopTransactionOnInvalidId,
  714. StopTxnAlignedData,
  715. StopTxnAlignedDataMaxLength,
  716. StopTxnSampledData,
  717. StopTxnSampledDataMaxLength,
  718. SupportedFeatureProfiles,
  719. SupportedFeatureProfilesMaxLength,
  720. TransactionMessageAttempts,
  721. TransactionMessageRetryInterval,
  722. UnlockConnectorOnEVSideDisconnect,
  723. WebSocketPingInterval,
  724. _CoreProfile_CNT
  725. };
  726. enum LocalAuthListManagementProfile{
  727. LocalAuthListEnabled=0,
  728. LocalAuthListMaxLength,
  729. SendLocalListMaxLength,
  730. _LocalAuthListManagementProfile_CNT
  731. };
  732. enum ReservationProfile{
  733. ReserveConnectorZeroSupported
  734. };
  735. enum SmartChargingProfile{
  736. ChargeProfileMaxStackLevel,
  737. ChargingScheduleAllowedChargingRateUnit,
  738. ChargingScheduleMaxPeriods,
  739. ConnectorSwitch3to1PhaseSupported,
  740. MaxChargingProfilesInstalled
  741. };
  742. enum ChargerSystemStatus{
  743. ChargerSystemStatus_Booting,
  744. ChargerSystemStatus_Idle,
  745. ChargerSystemStatus_Authorizing,
  746. ChargerSystemStatus_Preparing,
  747. ChargerSystemStatus_Charging,
  748. ChargerSystemStatus_Terminating,
  749. ChargerSystemStatus_Alarm,
  750. ChargerSystemStatus_Fault
  751. };
  752. enum GetConfigurationKey {
  753. GetConfiguration_AllowOfflineTxForUnknownId=0,
  754. GetConfiguration_AuthorizationCacheEnabled,
  755. GetConfiguration_AuthorizeRemoteTxRequests,
  756. GetConfiguration_BlinkRepeat,
  757. GetConfiguration_ClockAlignedDataInterval,
  758. GetConfiguration_ConnectionTimeOut,
  759. GetConfiguration_GetConfigurationMaxKeys,
  760. GetConfiguration_HeartbeatInterval,
  761. GetConfiguration_LightIntensity,
  762. GetConfiguration_LocalAuthorizeOffline,
  763. GetConfiguration_LocalPreAuthorize,
  764. GetConfiguration_MaxEnergyOnInvalidId,
  765. GetConfiguration_MeterValuesAlignedData,
  766. GetConfiguration_MeterValuesAlignedDataMaxLength,
  767. GetConfiguration_MeterValuesSampledData,
  768. GetConfiguration_MeterValuesSampledDataMaxLength,
  769. GetConfiguration_MeterValueSampleInterval,
  770. GetConfiguration_MinimumStatusDuration,
  771. GetConfiguration_NumberOfConnectors,
  772. GetConfiguration_ResetRetries,
  773. GetConfiguration_ConnectorPhaseRotation,
  774. GetConfiguration_ConnectorPhaseRotationMaxLength,
  775. GetConfiguration_StopTransactionOnEVSideDisconnect,
  776. GetConfiguration_StopTransactionOnInvalidId,
  777. GetConfiguration_StopTxnAlignedData,
  778. GetConfiguration_StopTxnAlignedDataMaxLength,
  779. GetConfiguration_StopTxnSampledData,
  780. GetConfiguration_StopTxnSampledDataMaxLength,
  781. GetConfiguration_SupportedFeatureProfiles,
  782. GetConfiguration_SupportedFeatureProfilesMaxLength,
  783. GetConfiguration_TransactionMessageAttempts,
  784. GetConfiguration_TransactionMessageRetryInterval,
  785. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  786. GetConfiguration_WebSocketPingInterval,
  787. GetConfiguration_LocalAuthListEnabled,
  788. GetConfiguration_LocalAuthListMaxLength,
  789. GetConfiguration_SendLocalListMaxLength,
  790. GetConfiguration_ReserveConnectorZeroSupported,
  791. GetConfiguration_ChargeProfileMaxStackLevel,
  792. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  793. GetConfiguration_ChargingScheduleMaxPeriods,
  794. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  795. GetConfiguration_MaxChargingProfilesInstalled,
  796. };
  797. //GetConfiguration Array
  798. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  799. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  800. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  801. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  802. struct StructChargingSchedulePeriod staticCHAdeMOChargingSchedulePeriod[10]={0};
  803. struct StructChargingSchedulePeriod staticCCSChargingSchedulePeriod[10]={0};
  804. struct StructChargingSchedulePeriod staticGBChargingSchedulePeriod[10]={0};
  805. struct StructChargingSchedulePeriod staticACChargingSchedulePeriod[10]={0};
  806. struct StructChargingSchedulePeriod staticCHAdeMOCompositeChargingSchedulePeriod[10]={0};
  807. struct StructChargingSchedulePeriod staticCCSCompositeChargingSchedulePeriod[10]={0};
  808. struct StructChargingSchedulePeriod staticGBCompositeChargingSchedulePeriod[10]={0};
  809. struct StructChargingSchedulePeriod staticACCompositeChargingSchedulePeriod[10]={0};
  810. struct StructChargingSchedulePeriod staticCHAdeMORemoteStartTransactionChargingSchedulePeriod[10]={0};
  811. struct StructChargingSchedulePeriod staticCCSRemoteStartTransactionChargingSchedulePeriod[10]={0};
  812. struct StructChargingSchedulePeriod staticGBRemoteStartTransactionChargingSchedulePeriod[10]={0};
  813. struct StructChargingSchedulePeriod staticACRemoteStartTransactionChargingSchedulePeriod[10]={0};
  814. struct StructOCPPMeterValue staticCHAdeMOTransactionDataForMeterValueRequest={0};
  815. struct StructOCPPMeterValue staticCCSTransactionDataForMeterValueRequest={0};
  816. struct StructOCPPMeterValue staticGBTransactionDataForMeterValueRequest={0};
  817. struct StructOCPPMeterValue staticACTransactionDataForMeterValueRequest={0};
  818. struct StructOCPPMeterValue staticCHAdeMOTransactionDataForStopTransactionRequest[0];
  819. struct StructOCPPMeterValue staticCCSTransactionDataForStopTransactionRequest[0];
  820. struct StructOCPPMeterValue staticGBTransactionDataForStopTransactionRequest[0];
  821. struct StructOCPPMeterValue staticACTransactionDataForStopTransactionRequest[0];
  822. //==========================================
  823. // Init all share memory
  824. //==========================================
  825. int InitShareMemory()
  826. {
  827. int result = PASS;
  828. int MeterSMId;
  829. //printf("1\n");
  830. //creat ShmSysConfigAndInfo
  831. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  832. {
  833. #ifdef SystemLogMessage
  834. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  835. #endif
  836. result = FAIL;
  837. }
  838. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  839. {
  840. #ifdef SystemLogMessage
  841. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  842. #endif
  843. result = FAIL;
  844. }
  845. else
  846. {}
  847. //printf("2\n");
  848. //creat ShmStatusCodeData
  849. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  850. {
  851. #ifdef SystemLogMessage
  852. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  853. #endif
  854. result = FAIL;
  855. }
  856. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  857. {
  858. #ifdef SystemLogMessage
  859. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  860. #endif
  861. result = FAIL;
  862. }
  863. else
  864. {}
  865. //printf("3\n");
  866. //creat ShmPsuData
  867. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  868. {
  869. #ifdef SystemLogMessage
  870. DEBUG_ERROR("shmget ShmPsuData NG\n");
  871. #endif
  872. result = FAIL;
  873. }
  874. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  875. {
  876. #ifdef SystemLogMessage
  877. DEBUG_ERROR("shmat ShmPsuData NG\n");
  878. #endif
  879. result = FAIL;
  880. }
  881. else
  882. {}
  883. //creat ShmOCPP16Data
  884. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  885. {
  886. #ifdef SystemLogMessage
  887. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  888. #endif
  889. result = FAIL;
  890. }
  891. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  892. {
  893. #ifdef SystemLogMessage
  894. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  895. #endif
  896. result = FAIL;
  897. }
  898. else
  899. {}
  900. /****************************** For TEST ************************************************/
  901. //inital settings
  902. gunTotalNumber = (strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL) ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  903. memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/);
  904. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  905. {
  906. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  907. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  908. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  909. }
  910. // Charger PRE_SYS_MODE
  911. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  912. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  913. clientTime.Heartbeat=time((time_t*)NULL);
  914. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  915. {
  916. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  917. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  918. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  919. }
  920. //HeartBeatWaitTime = 10;
  921. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  923. // allocate Configuration memory address
  924. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  925. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  926. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  927. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  928. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  929. {
  930. if(CHAdeMO_QUANTITY != 0)
  931. {
  932. int index = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].Index;
  933. ShmOCPP16Data->SetChargingProfile[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCHAdeMOChargingSchedulePeriod;
  934. ShmOCPP16Data->GetCompositeSchedule[index].ResponseChargingSchedule.ChargingSchedulePeriod = staticCHAdeMOCompositeChargingSchedulePeriod;
  935. ShmOCPP16Data->RemoteStartTransaction[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCHAdeMORemoteStartTransactionChargingSchedulePeriod;
  936. //ShmOCPP16Data->StopTransaction[index].TransactionData = (struct StructMeterValue *)&staticCHAdeMOTransactionDataForStopTransactionRequest;
  937. //ShmOCPP16Data->StopTransaction[index].TransactionData[0].SampledValue = staticCHAdeMOTransactionDataForStopTransactionRequest[0].SampledValue;
  938. }
  939. if(CCS_QUANTITY != 0)
  940. {
  941. int index = ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].Index;
  942. ShmOCPP16Data->SetChargingProfile[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCCSChargingSchedulePeriod;
  943. ShmOCPP16Data->GetCompositeSchedule[index].ResponseChargingSchedule.ChargingSchedulePeriod = staticCCSCompositeChargingSchedulePeriod;
  944. ShmOCPP16Data->RemoteStartTransaction[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCCSRemoteStartTransactionChargingSchedulePeriod;
  945. //ShmOCPP16Data->StopTransaction[index].TransactionData = (struct StructMeterValue *)&staticCCSTransactionDataForStopTransactionRequest;
  946. //ShmOCPP16Data->StopTransaction[index].TransactionData[0].SampledValue = staticCCSTransactionDataForStopTransactionRequest[0].SampledValue;
  947. }
  948. if(GB_QUANTITY != 0)
  949. {
  950. int index = ShmSysConfigAndInfo->SysInfo.GbChargingData[0].Index;
  951. ShmOCPP16Data->SetChargingProfile[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticGBChargingSchedulePeriod;
  952. ShmOCPP16Data->GetCompositeSchedule[index].ResponseChargingSchedule.ChargingSchedulePeriod = staticGBCompositeChargingSchedulePeriod;
  953. ShmOCPP16Data->RemoteStartTransaction[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticGBRemoteStartTransactionChargingSchedulePeriod;
  954. //ShmOCPP16Data->StopTransaction[index].TransactionData = (struct StructMeterValue *)&staticGBTransactionDataForStopTransactionRequest;
  955. //ShmOCPP16Data->StopTransaction[index].TransactionData[0].SampledValue = staticGBTransactionDataForStopTransactionRequest[0].SampledValue;
  956. }
  957. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  958. DEBUG_INFO("DC ...\n");
  959. }
  960. else
  961. {
  962. if(AC_QUANTITY)
  963. {
  964. int index = ShmSysConfigAndInfo->SysInfo.AcChargingData[0].Index;
  965. ShmOCPP16Data->SetChargingProfile[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticACChargingSchedulePeriod;
  966. ShmOCPP16Data->GetCompositeSchedule[index].ResponseChargingSchedule.ChargingSchedulePeriod = staticACCompositeChargingSchedulePeriod;
  967. ShmOCPP16Data->RemoteStartTransaction[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticACRemoteStartTransactionChargingSchedulePeriod;
  968. //ShmOCPP16Data->StopTransaction[index].TransactionData = (struct StructMeterValue *)&staticACTransactionDataForStopTransactionRequest;
  969. //ShmOCPP16Data->StopTransaction[index].TransactionData[0].SampledValue = staticACTransactionDataForStopTransactionRequest[0].SampledValue;
  970. }
  971. SystemInitial = AC_QUANTITY;
  972. DEBUG_INFO("AC ...\n");
  973. DEBUG_INFO("gunTotalNumber=%d\n",gunTotalNumber);
  974. }
  975. //Status Setting
  976. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  977. {
  978. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  979. }
  980. for (int index = 0; index < CCS_QUANTITY; index++)
  981. {
  982. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  983. }
  984. for (int index = 0; index < GB_QUANTITY; index++)
  985. {
  986. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  987. }
  988. for (int index = 0; index < AC_QUANTITY; index++)
  989. {
  990. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  991. }
  992. //memset(unknownkey, 0, 10);
  993. return result;
  994. }
  995. int ProcessShareMemory()
  996. {
  997. if(InitShareMemory() == FAIL)
  998. {
  999. #ifdef SystemLogMessage
  1000. DEBUG_ERROR("InitShareMemory NG\n");
  1001. #endif
  1002. if(ShmStatusCodeData!=NULL)
  1003. {
  1004. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1005. }
  1006. sleep(5);
  1007. return FAIL;
  1008. }
  1009. return PASS;
  1010. }
  1011. //---------------------------------------------
  1012. // new:
  1013. // enum SYSTEM_STATUS
  1014. // {
  1015. // SYS_MODE_BOOTING = 0,
  1016. // SYS_MODE_IDLE = 1,
  1017. // SYS_MODE_AUTHORIZING = 2,
  1018. // SYS_MODE_PREPARING = 3,
  1019. // SYS_MODE_CHARGING = 4,
  1020. // SYS_MODE_TERMINATING = 5,
  1021. // SYS_MODE_ALARM = 6,
  1022. // SYS_MODE_FAULT = 7,
  1023. // SYS_MODE_RESERVATION = 8,
  1024. // SYS_MODE_BOOKING = 9,
  1025. // SYS_MODE_MAINTAIN = 10,
  1026. // SYS_MODE_DEBUG = 11,
  1027. // SYS_MODE_REASSIGN_CHECK = 12,
  1028. // SYS_MODE_REASSIGN = 13,
  1029. // SYS_MODE_PRECHARGE = 14,
  1030. // SYS_MODE_PREPARING_EV = 15,
  1031. // SYS_MODE_PREPARING_EVSE = 16,
  1032. // SYS_MODE_COMPLETE = 17
  1033. // };
  1034. //
  1035. // old:
  1036. // enum _SYSTEM_STATUS
  1037. // {
  1038. // S_BOOTING = 0,
  1039. // S_IDLE, =1
  1040. // S_AUTHORIZING, =2
  1041. // S_REASSIGN_CHECK, =3
  1042. // S_REASSIGN, =4
  1043. // S_PRECHARGE, =5
  1044. // S_PREPARING_FOR_EV, =6
  1045. // S_PREPARING_FOR_EVSE, =7
  1046. // S_CHARGING, =8
  1047. // S_TERMINATING, =9
  1048. // S_COMPLETE, =10
  1049. // S_ALARM, =11
  1050. // S_FAULT =12
  1051. // };
  1052. //
  1053. //-----------------------------------------
  1054. void CheckSystemValue(void)
  1055. {
  1056. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]={0};
  1057. int IdleModeCnt = 0;
  1058. char filenmae[100]={0};
  1059. char str[100]={0};
  1060. //===============================
  1061. // send Heartbeat
  1062. //===============================
  1063. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1064. {
  1065. //parameter for test
  1066. sendHeartbeatRequest(0);
  1067. //==============================================
  1068. // Reset Waiting Time
  1069. //==============================================
  1070. clientTime.Heartbeat=time((time_t*)NULL);
  1071. }
  1072. //==============================================
  1073. // Update firmware request
  1074. //==============================================
  1075. if(isUpdateRequest == TRUE )
  1076. {
  1077. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1078. {
  1079. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1080. {
  1081. //check SystemStatus
  1082. /*************************DC*******************************/
  1083. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1084. {
  1085. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1086. {
  1087. IdleModeCnt = IdleModeCnt + 1;
  1088. }
  1089. }
  1090. for (int index = 0; index < CCS_QUANTITY; index++)
  1091. {
  1092. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1093. {
  1094. IdleModeCnt = IdleModeCnt + 1;
  1095. }
  1096. }
  1097. for (int index = 0; index < GB_QUANTITY; index++)
  1098. {
  1099. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1100. {
  1101. IdleModeCnt = IdleModeCnt + 1;
  1102. }
  1103. }
  1104. }
  1105. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1106. {
  1107. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1108. isUpdateRequest = FALSE;
  1109. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1110. }
  1111. }
  1112. else
  1113. {
  1114. /*************************AC*******************************/
  1115. for (int index = 0; index < AC_QUANTITY; index++)
  1116. {
  1117. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1118. {
  1119. IdleModeCnt = IdleModeCnt + 1;
  1120. }
  1121. }
  1122. if(IdleModeCnt == AC_QUANTITY)
  1123. {
  1124. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1125. isUpdateRequest = FALSE;
  1126. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1127. }
  1128. }
  1129. }
  1130. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1131. for(int gun_index=0;gun_index < gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY )*/ ;gun_index++)
  1132. {
  1133. //===============================
  1134. // CSU Trigger Reset Conf
  1135. //===============================
  1136. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1137. {
  1138. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1139. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1140. {
  1141. server_sign = FALSE;
  1142. }
  1143. }
  1144. //===============================
  1145. // CSU Trigger Authorize Request
  1146. //===============================
  1147. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1148. {
  1149. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1150. {
  1151. sendAuthorizeRequest(0);
  1152. authorizeRetryTimes = authorizeRetryTimes + 1;
  1153. // authenrequest = TRUE
  1154. if(authorizeRetryTimes < 3)
  1155. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1156. }
  1157. }
  1158. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1159. {
  1160. authorizeRetryTimes = 0;
  1161. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1162. server_sign = FALSE;
  1163. }
  1164. //==============================================
  1165. // Charger start transaction
  1166. //==============================================
  1167. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1168. {
  1169. sendStartTransactionRequest(gun_index);
  1170. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1171. clientTime.StartTransaction = time((time_t*)NULL);
  1172. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1173. }
  1174. //==============================================
  1175. // Charger stop transaction
  1176. //==============================================
  1177. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1178. {
  1179. sendStopTransactionRequest(gun_index);
  1180. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1181. clientTime.StopTransaction = time((time_t*)NULL);
  1182. }
  1183. //==============================================
  1184. // Charger status report
  1185. //==============================================
  1186. /* Check Mode Change */
  1187. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1188. {
  1189. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1190. {
  1191. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1192. {
  1193. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1194. {
  1195. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1196. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1197. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1198. statusModeChage[gun_index] = TRUE;
  1199. }
  1200. }
  1201. }
  1202. for (int index = 0; index < CCS_QUANTITY; index++)
  1203. {
  1204. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1205. {
  1206. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1207. {
  1208. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1209. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1210. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1211. statusModeChage[gun_index] = TRUE;
  1212. }
  1213. }
  1214. }
  1215. for (int index = 0; index < GB_QUANTITY; index++)
  1216. {
  1217. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1218. {
  1219. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1220. {
  1221. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1222. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1223. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1224. statusModeChage[gun_index] = TRUE;
  1225. }
  1226. }
  1227. }
  1228. }
  1229. else //AC
  1230. {
  1231. for (int index = 0; index < AC_QUANTITY; index++)
  1232. {
  1233. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1234. {
  1235. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1236. {
  1237. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1238. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1239. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1240. statusModeChage[gun_index] = TRUE;
  1241. }
  1242. }
  1243. }// END OF FOR
  1244. }// END OF ELSE
  1245. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1246. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1247. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1248. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1249. {
  1250. if(SystemInitial != 0)
  1251. SystemInitial = SystemInitial -1;
  1252. //GunStatusInterval= GunStatusInterval* gun_index;
  1253. sendStatusNotificationRequest(gun_index);
  1254. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1255. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1256. statusModeChage[gun_index] = FALSE;
  1257. //sleep(30); // sleep for 30 seconds
  1258. }
  1259. //==============================================
  1260. // Meter report
  1261. //==============================================
  1262. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1263. {
  1264. //check Transaction active
  1265. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1266. {
  1267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1268. {
  1269. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1270. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1271. {
  1272. meterValueSend[gun_index] =1;
  1273. }
  1274. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1275. {
  1276. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1277. if((access(filenmae,F_OK))!=-1)
  1278. {
  1279. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1280. sprintf(str,"rm -f %s",filenmae);
  1281. system(str);
  1282. }
  1283. }
  1284. }// End for CHAdeMO
  1285. for (int index = 0; index < CCS_QUANTITY; index++)
  1286. {
  1287. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1288. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1289. {
  1290. meterValueSend[gun_index] =1;
  1291. }
  1292. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1293. {
  1294. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1295. if((access(filenmae,F_OK))!=-1)
  1296. {
  1297. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1298. sprintf(str,"rm -f %s",filenmae);
  1299. system(str);
  1300. }
  1301. }
  1302. } // End for CCS
  1303. for (int index = 0; index < GB_QUANTITY; index++)
  1304. {
  1305. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1306. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1307. {
  1308. meterValueSend[gun_index] =1;
  1309. }
  1310. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1311. {
  1312. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1313. if((access(filenmae,F_OK))!=-1)
  1314. {
  1315. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1316. sprintf(str,"rm -f %s",filenmae);
  1317. system(str);
  1318. }
  1319. }
  1320. }// End for GB
  1321. }
  1322. else
  1323. {
  1324. for (int index = 0; index < AC_QUANTITY; index++)
  1325. {
  1326. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1327. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1328. {
  1329. meterValueSend[gun_index] =1;
  1330. }
  1331. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1332. {
  1333. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1334. if((access(filenmae,F_OK))!=-1)
  1335. {
  1336. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1337. sprintf(str,"rm -f %s",filenmae);
  1338. system(str);
  1339. }
  1340. }
  1341. }//End for AC
  1342. }//END OF ELSE
  1343. // sleep(1);
  1344. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1345. if(meterValueSend[gun_index] == 1)
  1346. sendMeterValuesRequest(gun_index);
  1347. }
  1348. //==============================================
  1349. // Check Connector reserved
  1350. //==============================================
  1351. //===============================
  1352. // Check if Reserve is expired
  1353. //===============================
  1354. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1355. {
  1356. double diff_t;
  1357. struct tm tp;
  1358. // current time
  1359. time_t t = time(NULL);
  1360. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1361. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1362. tp.tm_isdst = -1;
  1363. time_t utc = mktime(&tp);
  1364. diff_t = difftime(utc, t);
  1365. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1366. if(diff_t <= 0)
  1367. {
  1368. DEBUG_INFO("reserve expired !!! \n");
  1369. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1370. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1371. }
  1372. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1373. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1374. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1375. {
  1376. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1377. }
  1378. else
  1379. {
  1380. //check Transaction active
  1381. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1382. {
  1383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1384. {
  1385. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1386. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1387. {
  1388. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1389. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1390. {
  1391. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1392. }
  1393. }
  1394. }
  1395. for (int index = 0; index < CCS_QUANTITY; index++)
  1396. {
  1397. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1398. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1399. {
  1400. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1401. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1402. {
  1403. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1404. }
  1405. }
  1406. }
  1407. for (int index = 0; index < GB_QUANTITY; index++)
  1408. {
  1409. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1410. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1411. {
  1412. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1413. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1414. {
  1415. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1416. }
  1417. }
  1418. }
  1419. }
  1420. else //AC
  1421. {
  1422. for (int index = 0; index < AC_QUANTITY; index++)
  1423. {
  1424. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1425. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1426. {
  1427. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1428. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1429. {
  1430. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1431. }
  1432. }
  1433. }
  1434. }// END OF ELSE
  1435. }// END OF check Transaction active
  1436. }//END OF Check if Reserve is expired
  1437. //==========================================
  1438. // csu trigger FirmwareStatusNotificationReq
  1439. //==========================================
  1440. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1441. {
  1442. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1443. }
  1444. //==========================================
  1445. // csu trigger CancelReservationConf
  1446. //==========================================
  1447. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1448. {
  1449. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1450. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1451. }
  1452. //==========================================
  1453. // csu trigger ChangeAvailabilityConf
  1454. //==========================================
  1455. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1456. {
  1457. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1458. }
  1459. //==========================================
  1460. // csu trigger UnlockConnectorConf
  1461. //==========================================
  1462. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1463. {
  1464. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1465. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1466. }
  1467. //==========================================
  1468. // csu trigger ReserveNowConf
  1469. //==========================================
  1470. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1471. {
  1472. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1473. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1474. }
  1475. //==========================================
  1476. // csu trigger DataTransferReq
  1477. //==========================================
  1478. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1479. {
  1480. sendDataTransferRequest(gun_index);
  1481. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1482. }
  1483. }
  1484. }
  1485. //==========================================
  1486. // send request routine
  1487. //==========================================
  1488. int sendAuthorizeRequest(int gun_index)
  1489. {
  1490. mtrace();
  1491. int result = FAIL;
  1492. char message[100]={0};
  1493. char guid[37];
  1494. char tempdata[65]={0};
  1495. DEBUG_INFO("sendAuthorizeRequest \n");
  1496. //Local Authorize
  1497. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1498. {
  1499. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1500. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1501. {
  1502. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1503. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1504. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1505. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1506. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1507. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1508. authorizeRetryTimes = 0;
  1509. return result;
  1510. }
  1511. else
  1512. {
  1513. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1514. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1515. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1516. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1517. result = PASS;
  1518. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1519. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1520. authorizeRetryTimes = 0;
  1521. return result;
  1522. }
  1523. }
  1524. //initailize struct Authorize
  1525. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1526. //get data from shared memory
  1527. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1528. random_uuid(guid);
  1529. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1530. LWS_Send(message);
  1531. sprintf(tempdata, "Authorize,%d", gun_index);
  1532. if(hashmap_operation(0, guid, tempdata) == 1)
  1533. {
  1534. result = PASS;
  1535. DEBUG_ERROR("Authorize mapItem pass\n");
  1536. }
  1537. //#ifdef SystemLogMessage
  1538. //DEBUG_INFO(">>>>>Authorize request\n");
  1539. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1540. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1541. //#endif
  1542. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1543. return result;
  1544. }
  1545. int sendBootNotificationRequest(void)
  1546. {
  1547. mtrace();
  1548. int result = FAIL;
  1549. char message[500]={0}, payload[700]={0};
  1550. char guid[37]={0};
  1551. char tempdata[65]={0};
  1552. int IsGunCharging = FALSE;
  1553. //check Transaction active
  1554. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1555. {
  1556. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1557. {
  1558. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1559. {
  1560. IsGunCharging = TRUE;
  1561. }
  1562. }
  1563. for (int index = 0; index < CCS_QUANTITY; index++)
  1564. {
  1565. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1566. {
  1567. IsGunCharging = TRUE;
  1568. }
  1569. }
  1570. for (int index = 0; index < GB_QUANTITY; index++)
  1571. {
  1572. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1573. {
  1574. IsGunCharging = TRUE;
  1575. }
  1576. }
  1577. }
  1578. else
  1579. {
  1580. for (int index = 0; index < AC_QUANTITY; index++)
  1581. {
  1582. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1583. {
  1584. IsGunCharging = TRUE;
  1585. }
  1586. }
  1587. }
  1588. if(IsGunCharging == TRUE)
  1589. {
  1590. server_sign = TRUE;
  1591. return result;
  1592. }
  1593. // Fill BootNotification fields
  1594. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1595. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1596. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1597. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1598. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1599. ShmOCPP16Data->ChargeBoxId
  1600. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1601. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1602. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1603. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1604. ,ShmOCPP16Data->BootNotification.CpIccid
  1605. ,ShmOCPP16Data->BootNotification.CpImsi
  1606. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1607. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1608. random_uuid(guid);
  1609. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1610. LWS_Send(message);
  1611. sprintf(tempdata, "BootNotification,0");
  1612. 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*/)
  1613. {
  1614. result = PASS;
  1615. }
  1616. memset(queuedata, 0, sizeof(queuedata));
  1617. strcpy(queuedata,message);
  1618. //#ifdef SystemLogMessage
  1619. //DEBUG_INFO(">>>>>BootNotification request\n");
  1620. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1621. //#endif
  1622. return result;
  1623. }
  1624. int sendDataTransferRequest(int gun_index)
  1625. {
  1626. mtrace();
  1627. char message[1000]={0};
  1628. char guid[37]={0};
  1629. char tempdata[65]={0};
  1630. int result = FAIL;
  1631. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1632. random_uuid(guid);
  1633. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1634. MESSAGE_TYPE_CALL,
  1635. guid,
  1636. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1637. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1638. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1639. LWS_Send(message);
  1640. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1641. 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*/)
  1642. {
  1643. result = PASS;
  1644. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1645. }
  1646. //#ifdef SystemLogMessage
  1647. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1648. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1649. //#endif
  1650. return result;
  1651. }
  1652. int sendDiagnosticsStatusNotificationRequest(char *status)
  1653. {
  1654. mtrace();
  1655. int result = FAIL;
  1656. char message[110]={0};
  1657. char guid[37]={0};
  1658. char tempdata[65]={0};
  1659. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1660. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1661. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1662. random_uuid(guid);
  1663. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1664. LWS_Send(message);
  1665. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1666. if(hashmap_operation(0, guid, tempdata) == 1)
  1667. {
  1668. result = PASS;
  1669. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1670. }
  1671. //#ifdef SystemLogMessage
  1672. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1673. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1674. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1675. //#endif
  1676. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1677. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1678. //record status
  1679. if(strcmp(status,"Idle")==0)
  1680. {
  1681. DiagnosticsStatusNotificationStatus = 0;
  1682. }
  1683. else if(strcmp(status,"Uploaded")==0)
  1684. {
  1685. DiagnosticsStatusNotificationStatus = 1;
  1686. }
  1687. else if(strcmp(status,"UploadFailed")==0)
  1688. {
  1689. DiagnosticsStatusNotificationStatus = 2;
  1690. }
  1691. else if(strcmp(status,"Uploading")==0)
  1692. {
  1693. DiagnosticsStatusNotificationStatus = 3;
  1694. }
  1695. return result;
  1696. }
  1697. int sendFirmwareStatusNotificationRequest(char *status)
  1698. {
  1699. mtrace();
  1700. int result = FAIL;
  1701. char message[110]={0};
  1702. char guid[37]={0};
  1703. char tempdata[65]={0};
  1704. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1705. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1706. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1707. random_uuid(guid);
  1708. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1709. LWS_Send(message);
  1710. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1711. 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*/)
  1712. {
  1713. result = PASS;
  1714. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1715. }
  1716. //#ifdef SystemLogMessage
  1717. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1718. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1719. //#endif
  1720. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1721. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1722. //record status
  1723. if(strcmp(status,"Downloaded")==0)
  1724. {
  1725. FirmwareStatusNotificationStatus = 0;
  1726. }
  1727. else if(strcmp(status,"DownloadFailed")==0)
  1728. {
  1729. FirmwareStatusNotificationStatus = 1;
  1730. }
  1731. else if(strcmp(status,"Downloading")==0)
  1732. {
  1733. FirmwareStatusNotificationStatus = 2;
  1734. }
  1735. else if(strcmp(status,"Idle")==0)
  1736. {
  1737. FirmwareStatusNotificationStatus = 3;
  1738. }
  1739. else if(strcmp(status,"InstallationFailed")==0)
  1740. {
  1741. FirmwareStatusNotificationStatus = 4;
  1742. }
  1743. else if(strcmp(status,"Installing")==0)
  1744. {
  1745. FirmwareStatusNotificationStatus = 5;
  1746. }
  1747. else if(strcmp(status,"Installed")==0)
  1748. {
  1749. FirmwareStatusNotificationStatus = 6;
  1750. }
  1751. return result;
  1752. }
  1753. int sendHeartbeatRequest(int gun_index)
  1754. {
  1755. mtrace();
  1756. int result = FAIL;
  1757. char message[80]={0};
  1758. char guid[37]={0};
  1759. char tempdata[65]={0};
  1760. random_uuid(guid);
  1761. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1762. , MESSAGE_TYPE_CALL
  1763. , guid );
  1764. LWS_Send(message);
  1765. sprintf(tempdata, "Heartbeat,%d", 0);
  1766. 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*/)
  1767. {
  1768. result = PASS;
  1769. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1770. }
  1771. //#ifdef SystemLogMessage
  1772. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1773. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1774. //#endif
  1775. return result;
  1776. }
  1777. int sendStartTransactionRequest(int gun_index)
  1778. {
  1779. mtrace();
  1780. int result = FAIL;
  1781. char message[250]={0};
  1782. char guid[37]={0};
  1783. struct timeval tmnow;
  1784. struct tm *tm;
  1785. char buf[30];//, usec_buf[6];
  1786. char tempdata[65]={0};
  1787. DEBUG_INFO("sendStartTransactionRequest...");
  1788. gettimeofday(&tmnow, NULL);
  1789. time_t t;
  1790. t = time(NULL);
  1791. /*UTC time and date*/
  1792. tm = gmtime(&t);
  1793. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1794. #if 0 // remove temporally
  1795. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1796. strcat(buf,".");
  1797. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1798. strcat(buf,usec_buf);
  1799. #endif
  1800. //printf("Start Charging Time :%s",buf);
  1801. // set value
  1802. if(ShmOCPP16Data->OcppConnStatus == 1 )
  1803. {
  1804. memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1805. }
  1806. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1807. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1808. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1809. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1810. {
  1811. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1812. {
  1813. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1814. {
  1815. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1816. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1817. }
  1818. }
  1819. for (int index = 0; index < CCS_QUANTITY; index++)
  1820. {
  1821. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1822. {
  1823. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1824. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1825. }
  1826. }
  1827. for (int index = 0; index < GB_QUANTITY; index++)
  1828. {
  1829. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1830. {
  1831. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1832. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1833. }
  1834. }
  1835. }
  1836. else
  1837. {
  1838. for (int index = 0; index < AC_QUANTITY; index++)
  1839. {
  1840. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1841. {
  1842. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1843. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1844. }
  1845. }
  1846. }//END OF ELSE
  1847. random_uuid(guid);
  1848. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1849. , MESSAGE_TYPE_CALL
  1850. , guid
  1851. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1852. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1853. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1854. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1855. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1856. LWS_Send(message);
  1857. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1858. 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*/)
  1859. {
  1860. result = PASS;
  1861. }
  1862. strcpy(queuedata, message);
  1863. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1864. //#ifdef SystemLogMessage
  1865. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1866. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1867. //#endif
  1868. return result;
  1869. }
  1870. int sendStatusNotificationRequest(int gun_index)
  1871. {
  1872. mtrace();
  1873. int result = FAIL;
  1874. char message[600]={0};
  1875. char guid[37];
  1876. int currentStatus = 0;
  1877. struct timeval tmnow;
  1878. struct tm *tm;
  1879. char buf[30];//, usec_buf[6];
  1880. char tempdata[65]={0};
  1881. gettimeofday(&tmnow, NULL);
  1882. time_t t;
  1883. t = time(NULL);
  1884. /*UTC time and date*/
  1885. tm = gmtime(&t);
  1886. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1887. #if 0 // remove temporally
  1888. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1889. strcat(buf,".");
  1890. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1891. strcat(buf,usec_buf);
  1892. #endif
  1893. printf("%s",buf);
  1894. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1895. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1896. // it's option
  1897. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1898. /*
  1899. enum _SYSTEM_STATUS
  1900. {
  1901. S_BOOTING = 0,
  1902. S_IDLE, = 1
  1903. S_AUTHORIZING, =2
  1904. S_REASSIGN_CHECK, =3
  1905. S_REASSIGN, =4
  1906. S_PRECHARGE, =5
  1907. S_PREPARING_FOR_EV, =6
  1908. S_PREPARING_FOR_EVSE, =7
  1909. S_CHARGING, =8
  1910. S_TERMINATING, =9
  1911. S_COMPLETE, =10
  1912. S_ALARM, =11
  1913. S_FAULT =12
  1914. }
  1915. */
  1916. //check Transaction active
  1917. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1918. {
  1919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1920. {
  1921. //printf("gun_index=%d\n",gun_index);
  1922. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1923. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1924. {
  1925. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1926. currentStatus = 0; //OCPP Status
  1927. }
  1928. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1929. {
  1930. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1931. currentStatus = 1; //OCPP Status
  1932. }
  1933. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1934. {
  1935. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1936. currentStatus = 2; //OCPP Status
  1937. }
  1938. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1939. {
  1940. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1941. currentStatus = 5; //OCPP Status
  1942. }
  1943. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1944. {
  1945. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1946. currentStatus = 4; //OCPP Status
  1947. }
  1948. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  1949. {
  1950. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1951. currentStatus = 7; //OCPP Status: Unavailable
  1952. }
  1953. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1954. {
  1955. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1956. currentStatus = 8; //OCPP Status: Faulted
  1957. }
  1958. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1959. {
  1960. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1961. currentStatus = 6; //OCPP Status: Reserved
  1962. }
  1963. }//end of for CHAdeMO_QUANTITY
  1964. for (int index = 0; index < CCS_QUANTITY; index++)
  1965. {
  1966. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1967. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1968. {
  1969. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1970. currentStatus = 0; //OCPP Status
  1971. }
  1972. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1973. {
  1974. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1975. currentStatus = 1; //OCPP Status
  1976. }
  1977. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1978. {
  1979. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1980. currentStatus = 2; //OCPP Status
  1981. }
  1982. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1983. {
  1984. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1985. currentStatus = 5; //OCPP Status
  1986. }
  1987. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1988. {
  1989. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1990. currentStatus = 4; //OCPP Status
  1991. }
  1992. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  1993. {
  1994. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1995. currentStatus = 7; //OCPP Status
  1996. }
  1997. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1998. {
  1999. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2000. currentStatus = 8; //OCPP Status
  2001. }
  2002. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2003. {
  2004. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2005. currentStatus = 6; //OCPP Status
  2006. }
  2007. }
  2008. for (int index = 0; index < GB_QUANTITY; index++)
  2009. {
  2010. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  2011. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2012. {
  2013. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2014. currentStatus = 0; //OCPP Status
  2015. }
  2016. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2017. {
  2018. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2019. currentStatus = 1; //OCPP Status
  2020. }
  2021. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2022. {
  2023. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2024. currentStatus = 2; //OCPP Status
  2025. }
  2026. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2027. {
  2028. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2029. currentStatus = 5; //OCPP Status
  2030. }
  2031. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2032. {
  2033. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2034. currentStatus = 4; //OCPP Status
  2035. }
  2036. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  2037. {
  2038. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2039. currentStatus = 7; //OCPP Status: Unavailable
  2040. }
  2041. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2042. {
  2043. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2044. currentStatus = 8; //OCPP Status: Faulted
  2045. }
  2046. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2047. {
  2048. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2049. currentStatus = 6; //OCPP Status: Faulted
  2050. }
  2051. }
  2052. }
  2053. else
  2054. {
  2055. for (int index = 0; index < AC_QUANTITY; index++)
  2056. {
  2057. //printf("gun_index=%d\n",gun_index);
  2058. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2059. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2060. {
  2061. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2062. currentStatus = 0; //OCPP Status
  2063. }
  2064. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2065. {
  2066. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2067. currentStatus = 1; //OCPP Status
  2068. }
  2069. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2070. {
  2071. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2072. currentStatus = 2; //OCPP Status
  2073. }
  2074. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2075. {
  2076. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2077. currentStatus = 5; //OCPP Status
  2078. }
  2079. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2080. {
  2081. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2082. currentStatus = 4; //OCPP Status
  2083. }
  2084. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  2085. {
  2086. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2087. currentStatus = 7; //OCPP Status: Unavailable
  2088. }
  2089. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2090. {
  2091. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2092. currentStatus = 8; //OCPP Status: Faulted
  2093. }
  2094. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2095. {
  2096. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2097. currentStatus = 6; //OCPP Status: Reserved
  2098. }
  2099. }//end of for AC_QUANTITY
  2100. }//END OF ELSE
  2101. //it's option
  2102. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2103. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2104. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2105. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2106. random_uuid(guid);
  2107. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2108. , MESSAGE_TYPE_CALL
  2109. , guid
  2110. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2111. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2112. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2113. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2114. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2115. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2116. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2117. LWS_Send(message);
  2118. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2119. 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*/)
  2120. {
  2121. DEBUG_ERROR("statusNotification mapitem pass");
  2122. result = PASS;
  2123. }
  2124. //#ifdef SystemLogMessage
  2125. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2126. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2127. //#endif
  2128. return result;
  2129. }
  2130. int sendStopTransactionRequest(int gun_index)
  2131. {
  2132. mtrace();
  2133. int result = FAIL;
  2134. char message[1500]={0};
  2135. char guid[37]={0};
  2136. char tempdata[65]={0};
  2137. int idx_sample=0;
  2138. DEBUG_ERROR("sendStopTransactionRequest \n");
  2139. //memset(&(ShmOCPP16Data->StopTransaction[gun_index].TransactionData), 0, sizeof(struct StructMeterValue));
  2140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId/*ShmOCPP16Data->Authorize.IdTag*/);
  2141. //ENERGY_ACTIVE_IMPORT_REGISTER
  2142. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2143. {
  2144. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2145. {
  2146. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2147. {
  2148. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2149. //Check Status
  2150. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2151. {
  2152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2153. }
  2154. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2155. }
  2156. }// END OF CHAdeMO_QUANTITY
  2157. for (int index = 0; index < CCS_QUANTITY; index++)
  2158. {
  2159. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2160. {
  2161. //for test
  2162. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2163. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2164. //Check Status
  2165. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2166. {
  2167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2168. }
  2169. else
  2170. {
  2171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2172. }
  2173. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2174. }
  2175. }// END OF CCS_QUANTITY
  2176. for (int index = 0; index < GB_QUANTITY; index++)
  2177. {
  2178. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2179. {
  2180. // for test
  2181. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2182. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2183. //Check Status
  2184. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2185. {
  2186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2187. }
  2188. else
  2189. {
  2190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2191. }
  2192. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2193. }
  2194. }// END OF GB_QUANTITY
  2195. }
  2196. else
  2197. {
  2198. for (int index = 0; index < AC_QUANTITY; index++)
  2199. {
  2200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2201. {
  2202. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2203. //Check Status
  2204. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2205. {
  2206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2207. }
  2208. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2209. }
  2210. }// END OF AC_QUANTITY
  2211. }//END OF ELSE
  2212. //Stop Transaction Time
  2213. struct timeval tmnow;
  2214. struct tm *tm;
  2215. char buf[30];//, usec_buf[6];
  2216. gettimeofday(&tmnow, NULL);
  2217. time_t t;
  2218. t = time(NULL);
  2219. /*UTC time and date*/
  2220. tm = gmtime(&t);
  2221. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2222. #if 0 // remove temporally
  2223. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2224. strcat(buf,".");
  2225. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2226. strcat(buf,usec_buf);
  2227. #endif
  2228. printf("StopTransaction Time %s\n",buf);
  2229. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2231. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2232. random_uuid(guid);
  2233. sprintf(message,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":"
  2234. ,MESSAGE_TYPE_CALL
  2235. ,guid
  2236. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2237. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2238. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2239. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2240. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
  2241. /***********************************transactionData******************************************************/
  2242. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2243. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2244. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2245. {
  2246. //transactionData = json_object_new_object();
  2247. //json_object_object_add(transactionData, "timestamp", json_object_new_string("2019-05-04T18:15:33Z"));
  2248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp, buf/*"2019-05-04T18:15:33Z"*/);
  2249. sprintf(message + strlen(message), "[{\"timestamp\":\"%s\",\"sampledValue\":[", (const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp);
  2250. //=================================
  2251. // Transaction_Begin
  2252. //=================================
  2253. // Energy.Active.Export.Interval
  2254. idx_sample=0;
  2255. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2262. sprintf(message + strlen(message), "{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2263. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2264. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2265. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2266. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2267. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2268. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2269. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2270. );
  2271. //=================================
  2272. // Transaction_End
  2273. //=================================
  2274. //Current.Export
  2275. idx_sample=1;
  2276. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2277. {
  2278. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2279. {
  2280. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2281. {
  2282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2283. }
  2284. }
  2285. for (int index = 0; index < CCS_QUANTITY; index++)
  2286. {
  2287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2288. {
  2289. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2290. }
  2291. }
  2292. for (int index = 0; index < GB_QUANTITY; index++)
  2293. {
  2294. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2295. {
  2296. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2297. }
  2298. }
  2299. }
  2300. else
  2301. {
  2302. for (int index = 0; index < AC_QUANTITY; index++)
  2303. {
  2304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2305. {
  2306. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2307. }
  2308. }
  2309. }// END FOR AC ELSE
  2310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Current_Export/*Energy_Reactive_Export_Register*/]);
  2313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A/*UnitOfMeasure_kWh*/]);
  2316. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2317. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2318. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2319. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2320. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2321. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2322. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2323. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2324. );
  2325. //Energy.Active.Export.Interval
  2326. idx_sample=2;
  2327. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2328. {
  2329. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2330. {
  2331. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2332. {
  2333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2334. }
  2335. }
  2336. for (int index = 0; index < CCS_QUANTITY; index++)
  2337. {
  2338. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2339. {
  2340. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2341. }
  2342. }
  2343. for (int index = 0; index < GB_QUANTITY; index++)
  2344. {
  2345. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2346. {
  2347. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2348. }
  2349. }
  2350. }
  2351. else
  2352. {
  2353. for (int index = 0; index < AC_QUANTITY; index++)
  2354. {
  2355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2356. {
  2357. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2358. }
  2359. }
  2360. }// END FOR AC ELSE
  2361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2367. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2368. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2369. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2370. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2371. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2372. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2373. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2374. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2375. );
  2376. //Power.Active.Export
  2377. idx_sample=3;
  2378. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2379. {
  2380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2381. {
  2382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2383. {
  2384. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2385. }
  2386. }
  2387. for (int index = 0; index < CCS_QUANTITY; index++)
  2388. {
  2389. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2390. {
  2391. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2392. }
  2393. }
  2394. for (int index = 0; index < GB_QUANTITY; index++)
  2395. {
  2396. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2397. {
  2398. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2399. }
  2400. }
  2401. }
  2402. else
  2403. {
  2404. for (int index = 0; index < AC_QUANTITY; index++)
  2405. {
  2406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2407. {
  2408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2409. }
  2410. }
  2411. }// END FOR AC ELSE
  2412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2418. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2419. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2420. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2421. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2422. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2423. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2424. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2425. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2426. );
  2427. //Voltage
  2428. idx_sample=4;
  2429. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2430. {
  2431. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2432. {
  2433. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2434. {
  2435. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2436. }
  2437. }
  2438. for (int index = 0; index < CCS_QUANTITY; index++)
  2439. {
  2440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2441. {
  2442. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2443. }
  2444. }
  2445. for (int index = 0; index < GB_QUANTITY; index++)
  2446. {
  2447. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2448. {
  2449. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2450. }
  2451. }
  2452. }
  2453. else
  2454. {
  2455. for (int index = 0; index < AC_QUANTITY; index++)
  2456. {
  2457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2458. {
  2459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2460. }
  2461. }
  2462. }// END FOR AC ELSE
  2463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2469. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2470. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2471. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2472. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2473. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2474. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2475. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2476. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2477. );
  2478. //SoC
  2479. idx_sample=5;
  2480. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2481. {
  2482. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2483. {
  2484. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2485. {
  2486. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2487. }
  2488. }
  2489. for (int index = 0; index < CCS_QUANTITY; index++)
  2490. {
  2491. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2492. {
  2493. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2494. }
  2495. }
  2496. for (int index = 0; index < GB_QUANTITY; index++)
  2497. {
  2498. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2499. {
  2500. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2501. }
  2502. }
  2503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2509. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2510. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2511. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2512. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2513. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2514. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2515. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2516. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2517. );
  2518. } // END FOR DC CASE
  2519. sprintf(message + strlen(message)," ] } ] } ]");
  2520. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue);
  2521. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);
  2522. }
  2523. LWS_Send(message);
  2524. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2525. if(hashmap_operation(0, guid, tempdata) == 1)
  2526. {
  2527. result = PASS;
  2528. DEBUG_INFO("StopTransaction mapitem pass\n");
  2529. }
  2530. strcpy(queuedata, message);
  2531. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2532. //#ifdef SystemLogMessage
  2533. //DEBUG_INFO(">>>>>StopTransaction request\n");
  2534. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2535. //#endif
  2536. //for test
  2537. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2538. return result;
  2539. }
  2540. int sendMeterValuesRequest(int gun_index)
  2541. {
  2542. mtrace();
  2543. int result = FAIL;
  2544. char message[1500]={0};
  2545. char guid[37]={0};
  2546. int idx_sample=0;
  2547. //int length = 0;
  2548. char tempdata[65]={0};
  2549. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2550. DEBUG_ERROR("gun_index =%d\n",gun_index);
  2551. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2552. {
  2553. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2554. DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2555. DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2556. return result;
  2557. }
  2558. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2559. {
  2560. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2561. }
  2562. //set value
  2563. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2564. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2565. random_uuid(guid);
  2566. sprintf(message,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":"
  2567. ,MESSAGE_TYPE_CALL
  2568. ,guid
  2569. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2570. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId);
  2571. //,comfirmpayload);
  2572. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2573. {
  2574. //allocate memory space
  2575. //ShmOCPP16Data->MeterValues[gun_index].MeterValue = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2576. //UTC Date time
  2577. struct timeval tmnow;
  2578. struct tm *tm;
  2579. char buf[30];//, usec_buf[6];
  2580. gettimeofday(&tmnow, NULL);
  2581. time_t t;
  2582. t = time(NULL);
  2583. /*UTC time and date*/
  2584. tm = gmtime(&t);
  2585. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2586. #if 0 // remove temporally
  2587. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2588. strcat(buf,".");
  2589. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2590. strcat(buf,usec_buf);
  2591. #endif
  2592. // printf("%s",buf);
  2593. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp, buf);
  2594. //allocate memory space
  2595. //ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*6);
  2596. sprintf(message + strlen(message),"[{\"timestamp\":\"%s\",\"sampledValue\":[",(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp);
  2597. idx_sample=0;
  2598. //********************************(1)Current.Export************************************************/
  2599. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2600. {
  2601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2602. {
  2603. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2604. {
  2605. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2606. }
  2607. }
  2608. for (int index = 0; index < CCS_QUANTITY; index++)
  2609. {
  2610. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2611. {
  2612. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2613. }
  2614. }
  2615. for (int index = 0; index < GB_QUANTITY; index++)
  2616. {
  2617. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2618. {
  2619. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2620. }
  2621. }
  2622. }
  2623. else
  2624. {
  2625. for (int index = 0; index < AC_QUANTITY; index++)
  2626. {
  2627. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2628. {
  2629. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2630. }
  2631. }
  2632. }// END FOR AC ELSE
  2633. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2634. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Current_Export]);
  2636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2639. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2640. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2641. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2642. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2643. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2644. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2645. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2646. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2647. );
  2648. #if 0
  2649. idx_sample=1;
  2650. //****************************************************(2)Energy.Active.Export.Register*********************************************/
  2651. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2652. {
  2653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2654. {
  2655. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2656. {
  2657. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2658. }
  2659. }
  2660. for (int index = 0; index < CCS_QUANTITY; index++)
  2661. {
  2662. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2663. {
  2664. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2665. }
  2666. }
  2667. for (int index = 0; index < GB_QUANTITY; index++)
  2668. {
  2669. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2670. {
  2671. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2673. }
  2674. }
  2675. }
  2676. else
  2677. {
  2678. for (int index = 0; index < AC_QUANTITY; index++)
  2679. {
  2680. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2681. {
  2682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2683. }
  2684. }
  2685. }// END FOR AC ELSE
  2686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2687. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2688. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Register]);
  2689. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2691. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2692. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2693. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2694. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2695. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2696. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2697. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2698. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2699. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2700. );
  2701. #endif
  2702. idx_sample=1;
  2703. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2704. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2705. {
  2706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2707. {
  2708. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2709. {
  2710. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2711. }
  2712. }
  2713. for (int index = 0; index < CCS_QUANTITY; index++)
  2714. {
  2715. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2717. {
  2718. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2719. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2720. }
  2721. }
  2722. for (int index = 0; index < GB_QUANTITY; index++)
  2723. {
  2724. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2725. {
  2726. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2727. }
  2728. }
  2729. }
  2730. else
  2731. {
  2732. for (int index = 0; index < AC_QUANTITY; index++)
  2733. {
  2734. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2735. {
  2736. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2737. }
  2738. }
  2739. }//END FOR AC ELSE
  2740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2743. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2746. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2747. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2748. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2749. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2750. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2751. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2752. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2753. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2754. );
  2755. idx_sample=2;
  2756. //********************************(4)Power.Active.Export************************************************/
  2757. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2758. {
  2759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2760. {
  2761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2762. {
  2763. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2764. }
  2765. }
  2766. for (int index = 0; index < CCS_QUANTITY; index++)
  2767. {
  2768. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2769. {
  2770. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2771. }
  2772. }
  2773. for (int index = 0; index < GB_QUANTITY; index++)
  2774. {
  2775. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2776. {
  2777. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2778. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2779. }
  2780. }
  2781. }
  2782. else
  2783. {
  2784. for (int index = 0; index < AC_QUANTITY; index++)
  2785. {
  2786. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2787. {
  2788. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2789. }
  2790. }
  2791. }// END FOR AC ELSE
  2792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Power_Active_Export]);
  2795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2796. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2797. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2798. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2799. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2800. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2801. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2802. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2803. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2804. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2805. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2806. );
  2807. idx_sample=3;
  2808. //***********************************************(5)VOLTAGE******************************************************/
  2809. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2810. {
  2811. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2812. {
  2813. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2814. {
  2815. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2816. }
  2817. }
  2818. for (int index = 0; index < CCS_QUANTITY; index++)
  2819. {
  2820. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2821. {
  2822. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2823. }
  2824. }
  2825. for (int index = 0; index < GB_QUANTITY; index++)
  2826. {
  2827. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2828. {
  2829. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2830. }
  2831. }
  2832. }
  2833. else
  2834. {
  2835. for (int index = 0; index < AC_QUANTITY; index++)
  2836. {
  2837. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2838. {
  2839. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2840. }
  2841. }
  2842. }//END FOR AC ELSE
  2843. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2844. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Voltage]);
  2846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2847. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2849. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2850. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2851. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2852. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2853. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2854. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2855. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2856. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2857. );
  2858. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2859. {
  2860. idx_sample=4;
  2861. //sampledValue = NULL;
  2862. //***********************************************(6)SOC******************************************************/
  2863. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2864. {
  2865. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2866. {
  2867. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2868. {
  2869. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2870. }
  2871. }
  2872. for (int index = 0; index < CCS_QUANTITY; index++)
  2873. {
  2874. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2875. {
  2876. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2877. }
  2878. }
  2879. for (int index = 0; index < GB_QUANTITY; index++)
  2880. {
  2881. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2882. {
  2883. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2884. }
  2885. }
  2886. }
  2887. else
  2888. {
  2889. for (int index = 0; index < AC_QUANTITY; index++)
  2890. {
  2891. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2892. {
  2893. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2894. }
  2895. }
  2896. }//END FOR AC ELSE
  2897. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[SoC]);
  2900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2903. sprintf(message + strlen(message),",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2904. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2905. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2906. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2907. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2908. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2909. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2910. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2911. );
  2912. }
  2913. //}
  2914. sprintf(message + strlen(message)," ] } ] } ]");
  2915. //free(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue);
  2916. }
  2917. LWS_Send(message);
  2918. //memset(mapItem, 0, sizeof(data_struct_t));
  2919. // Put request guid to hash map
  2920. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2921. 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*/)
  2922. {
  2923. result = PASS;
  2924. DEBUG_INFO("MeterValues mapitem pass\n");
  2925. }
  2926. strcpy(queuedata, message);
  2927. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2928. //#ifdef SystemLogMessage
  2929. //DEBUG_INFO(">>>>>MeerValues request\n");
  2930. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2931. //#endif
  2932. return result;
  2933. }
  2934. //==========================================
  2935. // send confirm routine
  2936. //==========================================
  2937. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2938. {
  2939. mtrace();
  2940. int result = FAIL;
  2941. char message[100]={0};
  2942. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2943. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2944. LWS_Send(message);
  2945. result = TRUE;
  2946. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2947. return result;
  2948. }
  2949. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2950. {
  2951. mtrace();
  2952. int result = FAIL;
  2953. char message[100]={0};
  2954. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2955. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2956. LWS_Send(message);
  2957. result = TRUE;
  2958. return result;
  2959. }
  2960. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2961. {
  2962. mtrace();
  2963. int result = FAIL;
  2964. char message[100]={0};
  2965. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2966. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2967. LWS_Send(message);
  2968. result = TRUE;
  2969. return result;
  2970. }
  2971. int sendClearCacheConfirmation(char *uuid,char *payload)
  2972. {
  2973. mtrace();
  2974. int result = FAIL;
  2975. char message[500]={0};
  2976. // int count = 0;
  2977. // int gun_index = 0;
  2978. // char guid[37];
  2979. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2980. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2981. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2982. LWS_Send(message);
  2983. return result;
  2984. }
  2985. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2986. {
  2987. mtrace();
  2988. int result = FAIL;
  2989. char message[500]={0};
  2990. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2991. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2992. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2993. LWS_Send(message);
  2994. return result;
  2995. }
  2996. int sendDataTransferConfirmation(char *uuid,char *payload)
  2997. {
  2998. mtrace();
  2999. char statusStr[20]={0};
  3000. char dataStr[10]={0};
  3001. char sstr[20]={0};
  3002. int c = 0;
  3003. char *loc;
  3004. int result = FAIL;
  3005. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  3006. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  3007. /**********************status**************************/
  3008. loc = strstr(payload, "status");
  3009. memset(sstr ,0, sizeof(sstr) );
  3010. c = 0;
  3011. while (loc[3+strlen("status")+c] != '\"')
  3012. {
  3013. sstr[c] = loc[3+strlen("status")+c];
  3014. c++;
  3015. }
  3016. sstr[c] = '\0';
  3017. strcpy(statusStr, sstr);
  3018. /**********************data**************************/
  3019. loc = strstr(payload, "data");
  3020. memset(sstr ,0, sizeof(sstr) );
  3021. c = 0;
  3022. while (loc[3+strlen("data")+c] != '\"')
  3023. {
  3024. sstr[c] = loc[3+strlen("data")+c];
  3025. c++;
  3026. }
  3027. sstr[c] = '\0';
  3028. strcpy(dataStr, sstr);
  3029. return result;
  3030. }
  3031. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  3032. {
  3033. mtrace();
  3034. int result = FAIL;
  3035. char message[1000]={0};
  3036. double diff_f = 0.0;
  3037. int diff_i = 0;
  3038. struct tm tp;
  3039. DEBUG_ERROR("handle sendGetCompositeScheduleConfirmation ...\n");
  3040. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  3041. tp.tm_isdst = -1;
  3042. time_t utc = mktime(&tp);
  3043. time_t t = time(NULL);
  3044. diff_f = difftime(t, utc);
  3045. diff_i = (int)diff_f;
  3046. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3047. #if 0 //remove temporally
  3048. 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}"
  3049. ,MESSAGE_TYPE_CALLRESULT
  3050. ,uuid
  3051. ,payload
  3052. ,connectorIdInt
  3053. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3054. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3055. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3056. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3057. #endif
  3058. if(nPeriod == 0)
  3059. {
  3060. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3061. ,MESSAGE_TYPE_CALLRESULT
  3062. ,uuid
  3063. ,payload
  3064. ,connectorIdInt
  3065. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule);
  3066. }
  3067. else
  3068. {
  3069. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3070. ,MESSAGE_TYPE_CALLRESULT
  3071. ,uuid
  3072. ,payload
  3073. ,connectorIdInt
  3074. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3075. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3076. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3077. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3078. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3079. #if 1 // remove temporally
  3080. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3081. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3082. {
  3083. if (idx_sample == 0)
  3084. {
  3085. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3086. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  3087. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3088. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3089. }
  3090. else
  3091. {
  3092. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3093. , (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diff_i /*-1*/)
  3094. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3095. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3096. }
  3097. }
  3098. #endif
  3099. sprintf(message + strlen(message), "]}}]");
  3100. }
  3101. LWS_Send(message);
  3102. result = TRUE;
  3103. return result;
  3104. }
  3105. int sendGetConfigurationConfirmation(char *uuid)
  3106. {
  3107. mtrace();
  3108. int result = FAIL;
  3109. int MaxKeySupported = 0;
  3110. int sentConfigurationNumber= 0;
  3111. int sentunConfigurationNumber= 0;
  3112. char message[4000]={0};
  3113. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3114. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3115. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3116. ,MESSAGE_TYPE_CALLRESULT
  3117. ,uuid );
  3118. //configuration key
  3119. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3120. {
  3121. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3122. {
  3123. if (sentConfigurationNumber == 0)
  3124. {
  3125. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3126. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3127. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3128. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3129. }
  3130. else
  3131. {
  3132. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3133. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3134. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3135. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3136. }
  3137. sentConfigurationNumber = sentConfigurationNumber + 1;
  3138. }
  3139. }
  3140. sprintf(message + strlen(message), "]");
  3141. if(UnknownKeynum != 0)
  3142. {
  3143. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3144. //unkown key
  3145. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3146. {
  3147. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3148. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3149. if(sentunConfigurationNumber == 0)
  3150. {
  3151. sprintf(message + strlen(message), "\"%s\""
  3152. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3153. }
  3154. else
  3155. {
  3156. sprintf(message + strlen(message), ",\"%s\""
  3157. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3158. }
  3159. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3160. }
  3161. sprintf(message + strlen(message), "]");
  3162. }
  3163. sprintf(message + strlen(message), "} ]");
  3164. LWS_Send(message);
  3165. #if 0
  3166. printf("error 1-0\n");
  3167. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3168. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3169. #endif
  3170. return result;
  3171. }
  3172. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3173. {
  3174. mtrace();
  3175. int result = FAIL;
  3176. char message[400]={0};
  3177. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3178. if(strcmp(payload,"")==0)
  3179. {
  3180. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3181. }
  3182. else
  3183. {
  3184. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3185. }
  3186. LWS_Send(message);
  3187. result = TRUE;
  3188. return result;
  3189. }
  3190. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3191. {
  3192. mtrace();
  3193. int result = FAIL;
  3194. char message[80]={0};
  3195. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3196. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3197. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3198. LWS_Send(message);
  3199. result = TRUE;
  3200. return result;
  3201. }
  3202. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3203. {
  3204. mtrace();
  3205. int result = FAIL;
  3206. char message[80]={0};
  3207. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3208. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3209. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3210. LWS_Send(message);
  3211. result = TRUE;
  3212. return result;
  3213. }
  3214. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3215. {
  3216. mtrace();
  3217. int result = FAIL;
  3218. char message[80]={0};
  3219. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3220. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3221. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3222. LWS_Send(message);
  3223. result = TRUE;
  3224. return result;
  3225. }
  3226. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3227. {
  3228. mtrace();
  3229. int result = FAIL;
  3230. char message[80]={0};
  3231. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3232. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3233. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3234. LWS_Send(message);
  3235. result = TRUE;
  3236. return result;
  3237. }
  3238. int sendResetConfirmation(char *uuid,char *payload)
  3239. {
  3240. mtrace();
  3241. int result = FAIL;
  3242. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3243. char message[80]={0};
  3244. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3245. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3246. LWS_Send(message);
  3247. result = TRUE;
  3248. return result;
  3249. }
  3250. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3251. {
  3252. mtrace();
  3253. int result = FAIL;
  3254. char message[500]={0};
  3255. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3256. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3257. LWS_Send(message);
  3258. result = TRUE;
  3259. return result;
  3260. }
  3261. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3262. {
  3263. mtrace();
  3264. int result = FAIL;
  3265. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3266. char message[80]={0};
  3267. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3268. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3269. LWS_Send(message);
  3270. result = TRUE;
  3271. return result;
  3272. }
  3273. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3274. {
  3275. mtrace();
  3276. int result = FAIL;
  3277. char message[80]={0};
  3278. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3279. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3280. LWS_Send(message);
  3281. result = TRUE;
  3282. return result;
  3283. }
  3284. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3285. {
  3286. mtrace();
  3287. int result = FAIL;
  3288. char message[80]={0};
  3289. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3290. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3291. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3292. LWS_Send(message);
  3293. result = TRUE;
  3294. return result;
  3295. }
  3296. int sendUpdateFirmwareConfirmation(char *uuid)
  3297. {
  3298. mtrace();
  3299. int result = FAIL;
  3300. char message[60]={0};
  3301. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3302. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3303. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3304. LWS_Send(message);
  3305. result = TRUE;
  3306. return result;
  3307. }
  3308. //==========================================
  3309. // send CallError routine
  3310. //==========================================
  3311. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3312. {
  3313. mtrace();
  3314. //int result = FAIL;
  3315. char message[220]={0};
  3316. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3317. #ifdef SystemLogMessage
  3318. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3319. uniqueId, action, errorCode, errorDescription);
  3320. #endif
  3321. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3322. LWS_Send(message);
  3323. //result = TRUE;
  3324. }
  3325. //==========================================
  3326. // Handle server request routine Start
  3327. //==========================================
  3328. #define GUN_NUM 1
  3329. int handleCancelReservationRequest(char *uuid, char *payload)
  3330. {
  3331. mtrace();
  3332. int result = FAIL;
  3333. int gunNO = 0;
  3334. int reservationIdInt =0;
  3335. char comfirmstr[20];
  3336. int c = 0;
  3337. char *loc;
  3338. char sstr[100]={0};
  3339. DEBUG_INFO("handle CancelReservationRequest\n");
  3340. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3341. c = 0;
  3342. loc = strstr(payload, "reservationId");
  3343. memset(sstr ,0, sizeof(sstr) );
  3344. while (loc[strlen("reservationId")+2+c] != '}')
  3345. {
  3346. sstr[c] = loc[strlen("reservationId")+2+c];
  3347. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3348. c++;
  3349. }
  3350. sstr[c] = '\0';
  3351. reservationIdInt = atoi(sstr);
  3352. memset(comfirmstr, 0, sizeof comfirmstr);
  3353. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3354. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3355. //check Transaction active
  3356. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3357. {
  3358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3359. {
  3360. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3361. {
  3362. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3363. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3364. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3365. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3366. goto end;
  3367. }
  3368. }
  3369. for (int index = 0; index < CCS_QUANTITY; index++)
  3370. {
  3371. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3372. {
  3373. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3374. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3375. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3376. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3377. goto end;
  3378. }
  3379. }
  3380. for (int index = 0; index < GB_QUANTITY; index++)
  3381. {
  3382. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3383. {
  3384. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3385. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3386. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3387. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3388. goto end;
  3389. }
  3390. }
  3391. }
  3392. else
  3393. {
  3394. for (int index = 0; index < AC_QUANTITY; index++)
  3395. {
  3396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3397. {
  3398. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3399. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3400. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3401. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3402. goto end;
  3403. }
  3404. }
  3405. }// END FOR AC ELSE
  3406. //The reservationId does NOT match the reservationId
  3407. sendCancelReservationConfirmation(uuid, comfirmstr);
  3408. end:
  3409. // Fill in ocpp packet uuid
  3410. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3411. return result;
  3412. }
  3413. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3414. {
  3415. mtrace();
  3416. int result = FAIL;
  3417. int gunIndex = 0;
  3418. char sstr[90]={0};
  3419. char typeStr[16]={0};
  3420. char comfirmstr[20];
  3421. int specificId = FALSE;
  3422. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3423. char *loc;
  3424. //int intervalInt = 0;
  3425. int c = 0;
  3426. /*** connectorId ****/
  3427. c = 0;
  3428. loc = strstr(payload, "connectorId");
  3429. memset(sstr ,0, sizeof(sstr) );
  3430. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3431. {
  3432. sstr[c] = loc[strlen("connectorId")+2+c];
  3433. c++;
  3434. }
  3435. sstr[c] = '\0';
  3436. gunIndex = atoi(sstr);
  3437. /***type ****/
  3438. loc = strstr(payload, "type");
  3439. memset(sstr ,0, sizeof(sstr) );
  3440. c = 0;
  3441. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3442. {
  3443. sstr[c] = loc[3+strlen("type")+c];
  3444. c++;
  3445. }
  3446. sstr[c] = '\0';
  3447. strcpy(typeStr, sstr);
  3448. if(gunIndex != 0)
  3449. {
  3450. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3451. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3452. }
  3453. else
  3454. {
  3455. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3456. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3457. }
  3458. memset(comfirmstr, 0, sizeof comfirmstr);
  3459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3460. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3461. {
  3462. specificId = TRUE;
  3463. }
  3464. if(specificId == FALSE)
  3465. goto end;
  3466. if(gunIndex != 0)
  3467. {
  3468. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3469. }
  3470. else
  3471. {
  3472. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3473. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3474. }
  3475. /*
  3476. enum _SYSTEM_STATUS
  3477. {
  3478. S_BOOTING = 0,
  3479. S_IDLE, = 1
  3480. S_AUTHORIZING, =2
  3481. S_REASSIGN_CHECK, =3
  3482. S_REASSIGN, =4
  3483. S_PRECHARGE, =5
  3484. S_PREPARING_FOR_EV, =6
  3485. S_PREPARING_FOR_EVSE, =7
  3486. S_CHARGING, =8
  3487. S_TERMINATING, =9
  3488. S_COMPLETE, =10
  3489. S_ALARM, =11
  3490. S_FAULT =12
  3491. }
  3492. */
  3493. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3494. {
  3495. //check Transaction active
  3496. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3497. {
  3498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3499. {
  3500. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3501. {
  3502. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3503. {
  3504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3505. }
  3506. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3507. {
  3508. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3509. }
  3510. else
  3511. {
  3512. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3513. }
  3514. goto end;
  3515. }
  3516. }//END FOR CHAdeMO_QUANTITY
  3517. for (int index = 0; index < CCS_QUANTITY; index++)
  3518. {
  3519. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3520. {
  3521. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3522. {
  3523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3524. }
  3525. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3526. {
  3527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3528. }
  3529. else
  3530. {
  3531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3532. }
  3533. goto end;
  3534. }
  3535. }//END FOR CCS_QUANTITY
  3536. for (int index = 0; index < GB_QUANTITY; index++)
  3537. {
  3538. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3539. {
  3540. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3541. {
  3542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3543. }
  3544. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3545. {
  3546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3547. }
  3548. else
  3549. {
  3550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3551. }
  3552. goto end;
  3553. }
  3554. }// END FOR GB_QUANTITY
  3555. }
  3556. else
  3557. {
  3558. for (int index = 0; index < AC_QUANTITY; index++)
  3559. {
  3560. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3561. {
  3562. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3563. {
  3564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3565. }
  3566. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3567. {
  3568. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3569. }
  3570. else
  3571. {
  3572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3573. }
  3574. goto end;
  3575. }
  3576. }//END FOR AC_QUANTITY
  3577. }// END FOR AC ELSE
  3578. }//END FOR AvailabilityTypeStr[Inoperative]
  3579. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3580. {
  3581. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3582. //check Transaction active
  3583. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3584. {
  3585. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3586. {
  3587. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3588. {
  3589. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3590. goto end;
  3591. }
  3592. }//END FOR CHAdeMO_QUANTITY
  3593. for (int index = 0; index < CCS_QUANTITY; index++)
  3594. {
  3595. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3596. {
  3597. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3598. goto end;
  3599. }
  3600. }//END FOR CCS_QUANTITY
  3601. for (int index = 0; index < GB_QUANTITY; index++)
  3602. {
  3603. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3604. {
  3605. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3606. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3607. goto end;
  3608. }
  3609. }// END FOR GB_QUANTITY
  3610. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3611. }
  3612. else
  3613. {
  3614. for (int index = 0; index < AC_QUANTITY; index++)
  3615. {
  3616. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3617. {
  3618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3619. goto end;
  3620. }
  3621. }//END FOR CHAdeMO_QUANTITY
  3622. }//END FOR AC ELSE
  3623. }//END FOR AvailabilityTypeStr[Operative]
  3624. end:
  3625. if(gunIndex != 0)
  3626. {
  3627. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3628. }
  3629. else
  3630. {
  3631. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3632. }
  3633. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3634. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3635. return result;
  3636. }
  3637. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3638. {
  3639. mtrace();
  3640. int result = FAIL;
  3641. char sstr[100]={0};
  3642. char keystr[40]={0};
  3643. char valuestr[16]={0};
  3644. char *loc;
  3645. int c = 0;
  3646. char comfirmstr[20];
  3647. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3648. /***key ****/
  3649. loc = strstr(payload, "key");
  3650. memset(sstr ,0, sizeof(sstr) );
  3651. c = 0;
  3652. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3653. {
  3654. sstr[c] = loc[3+strlen("key")+c];
  3655. c++;
  3656. }
  3657. sstr[c] = '\0';
  3658. strcpy(keystr, sstr);
  3659. /***value ****/
  3660. loc = strstr(payload, "value");
  3661. memset(sstr ,0, sizeof(sstr) );
  3662. c = 0;
  3663. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3664. {
  3665. sstr[c] = loc[3+strlen("value")+c];
  3666. c++;
  3667. }
  3668. sstr[c] = '\0';
  3669. strcpy(valuestr, sstr);
  3670. if((uuid==NULL) || (payload ==NULL) )
  3671. {
  3672. #ifdef Debug
  3673. DEBUG_INFO("payload is null\n");
  3674. #endif
  3675. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3676. }
  3677. else
  3678. {
  3679. int status = setKeyValue(keystr, valuestr);
  3680. switch(status)
  3681. {
  3682. case ConfigurationStatus_Accepted:
  3683. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3684. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3685. break;
  3686. case ConfigurationStatus_Rejected:
  3687. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3688. break;
  3689. case RebootRequired:
  3690. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3691. break;
  3692. case NotSupported:
  3693. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3694. break;
  3695. default:
  3696. break;
  3697. }
  3698. }
  3699. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3700. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3701. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3702. return result;
  3703. }
  3704. int handleClearCacheRequest(char *uuid, char *payload)
  3705. {
  3706. mtrace();
  3707. int result = FAIL;
  3708. char comfirmstr[20];
  3709. int fd;
  3710. char rmFileCmd[100]={0};
  3711. struct stat stats;
  3712. DEBUG_ERROR("handle ClearCacheRequest\n");
  3713. stat("../Storage/OCPP", &stats);
  3714. // Check for directory existence
  3715. if (S_ISDIR(stats.st_mode) == 1)
  3716. {
  3717. //DEBUG_ERROR("\n OCPP directory exist \n");
  3718. }
  3719. else
  3720. {
  3721. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3722. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3723. system(rmFileCmd);
  3724. }
  3725. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  3726. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3727. {
  3728. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3729. }
  3730. else
  3731. {
  3732. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3733. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3734. if(log == NULL)
  3735. {
  3736. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3737. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3738. goto end;
  3739. }
  3740. else
  3741. {
  3742. fclose(log);
  3743. }
  3744. }
  3745. fd = open(AuthorizationCache_JSON,O_RDWR);
  3746. if(fd < 0)
  3747. {
  3748. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3749. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3750. }
  3751. else
  3752. {
  3753. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3754. //* 清空?�件 */
  3755. ftruncate(fd,0);
  3756. //* ?�新设置?�件?�移??*/
  3757. lseek(fd,0,SEEK_SET);
  3758. close(fd);
  3759. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3760. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3761. }
  3762. end:
  3763. sendClearCacheConfirmation(uuid, comfirmstr);
  3764. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3765. return result;
  3766. }
  3767. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3768. {
  3769. mtrace();
  3770. int result = FAIL;
  3771. int resultRename;
  3772. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3773. char chargingProfilePurposeStr[26]={0};
  3774. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3775. char tempchargingProfilePurposeStr[26]={0};
  3776. char sstr[160]={0};//sstr[200]={ 0 };
  3777. char str[100]={0};
  3778. int c = 0;
  3779. //int i = 0;
  3780. //char * pch;
  3781. char *loc;
  3782. char fname[200];
  3783. char comfirmstr[20]={0};
  3784. char word[1000]={0};
  3785. int clearflag = FALSE;
  3786. int chargingProfileIdIsNULL = FALSE;
  3787. int connectorIsNULL = FALSE;
  3788. FILE *fptr1, *fptr2;
  3789. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3790. int n_chargingProfile=0;
  3791. char sLineWord[1060]={0};
  3792. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3793. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3794. //***id ****/
  3795. c = 0;
  3796. loc = strstr(payload, "id");
  3797. memset(sstr ,0, sizeof(sstr) );
  3798. if(loc == NULL)
  3799. {
  3800. chargingProfileIdIsNULL = TRUE;
  3801. }
  3802. while ((loc != NULL) &&(loc[strlen("id")+2+c] != ',') )
  3803. {
  3804. sstr[c] = loc[strlen("id")+2+c];
  3805. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3806. c++;
  3807. }
  3808. sstr[c] = '\0';
  3809. chargingProfileIdInt = atoi(sstr);
  3810. //***connectorId ****/
  3811. c=0;
  3812. loc = strstr(payload, "connectorId");
  3813. memset(sstr ,0, sizeof(sstr) );
  3814. if(loc == NULL)
  3815. {
  3816. connectorIsNULL = TRUE;
  3817. }
  3818. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  3819. {
  3820. sstr[c] = loc[strlen("connectorId")+2+c];
  3821. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3822. c++;
  3823. }
  3824. sstr[c] = '\0';
  3825. connectorIdInt = atoi(sstr);
  3826. //***chargingProfilePurpose ****/
  3827. loc = strstr(payload, "chargingProfilePurpose");
  3828. memset(sstr ,0, sizeof(sstr) );
  3829. c = 0;
  3830. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3831. {
  3832. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3833. c++;
  3834. }
  3835. sstr[c] = '\0';
  3836. strcpy(chargingProfilePurposeStr, sstr);
  3837. //***stackLevel ****/
  3838. c=0;
  3839. loc = strstr(payload, "stackLevel");
  3840. memset(sstr ,0, sizeof(sstr) );
  3841. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3842. {
  3843. sstr[c] = loc[strlen("stackLevel")+2+c];
  3844. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3845. c++;
  3846. }
  3847. sstr[c] = '\0';
  3848. stackLevelInt = atoi(sstr);
  3849. if(connectorIsNULL == FALSE)
  3850. {
  3851. switch(connectorIdInt)
  3852. {
  3853. case 0:
  3854. if(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)
  3855. {
  3856. strcpy(fname, ChargePointMaxProfile_JSON);
  3857. }
  3858. else
  3859. {
  3860. strcpy(fname, TxDefaultProfile_0_JSON);
  3861. }
  3862. break;
  3863. case 1:
  3864. if(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)
  3865. {
  3866. strcpy(fname, TxDefaultProfile_1_JSON);
  3867. }
  3868. else
  3869. {
  3870. strcpy(fname, TxProfile_1_JSON);
  3871. }
  3872. break;
  3873. case 2:
  3874. if(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)
  3875. {
  3876. strcpy(fname, TxDefaultProfile_2_JSON);
  3877. }
  3878. else
  3879. {
  3880. strcpy(fname, TxProfile_2_JSON);
  3881. }
  3882. break;
  3883. default:
  3884. strcpy(fname, ChargePointMaxProfile_JSON );
  3885. break;
  3886. }
  3887. }
  3888. else
  3889. {
  3890. strcpy(fname, ChargePointMaxProfile_JSON );
  3891. }
  3892. fptr1 = fopen(fname, "r");
  3893. if (!fptr1)
  3894. {
  3895. //file not exist
  3896. DEBUG_ERROR("Unable to open the input file!!\n");
  3897. fptr1 = fopen(fname, "w+");
  3898. }
  3899. fclose(fptr1);
  3900. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3901. {
  3902. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3903. goto end;
  3904. }
  3905. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3906. {
  3907. //clear the whole contents of a file in C
  3908. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3909. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3910. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3911. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3912. fclose(fopen(TxProfile_1_JSON, "w"));
  3913. fclose(fopen(TxProfile_2_JSON, "w"));
  3914. #if 0
  3915. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3916. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3917. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3918. #endif
  3919. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3920. }
  3921. else
  3922. {
  3923. fptr1 = fopen(fname, "r");
  3924. fptr2 = fopen(temp, "w+");
  3925. while(fscanf(fptr1, "%s", word) != EOF)
  3926. {
  3927. DEBUG_INFO("word=%s\n",word);
  3928. if(strcmp(word, "chargingProfileId") == 0)
  3929. {
  3930. n_chargingProfile = n_chargingProfile + 1;
  3931. printf("Found\n");
  3932. }
  3933. }
  3934. rewind(fptr1);
  3935. //search Charging Profile Element
  3936. //int i= 0;
  3937. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3938. {
  3939. //*************************tempconnectorIdInt*********************************/
  3940. loc = strstr(sLineWord, "connectorId");
  3941. c = 0;
  3942. memset(sstr ,0, sizeof(sstr) );
  3943. while (loc[strlen("connectorId")+2+c] != ',')
  3944. {
  3945. sstr[c] = loc[strlen("connectorId")+2+c];
  3946. c++;
  3947. }
  3948. sstr[c] = '\0';
  3949. tempconnectorIdInt = atoi(sstr);
  3950. //chargingProfileId
  3951. c = 0;
  3952. loc = strstr(sLineWord, "chargingProfileId");
  3953. memset(sstr ,0, sizeof(sstr) );
  3954. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3955. {
  3956. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3957. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3958. c++;
  3959. }
  3960. sstr[c] = '\0';
  3961. tempchargingProfileIdInt = atoi(sstr);
  3962. //stackLevel
  3963. c = 0;
  3964. loc = strstr(sLineWord, "stackLevel");
  3965. memset(sstr ,0, sizeof(sstr) );
  3966. while (loc[strlen("stackLevel")+2+c] != ',')
  3967. {
  3968. sstr[c] = loc[strlen("stackLevel")+2+c];
  3969. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3970. c++;
  3971. }
  3972. sstr[c] = '\0';
  3973. tempstackLevelInt = atoi(sstr);
  3974. c = 0;
  3975. loc = strstr(sLineWord, "chargingProfilePurpose");
  3976. memset(sstr ,0, sizeof(sstr) );
  3977. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3978. {
  3979. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3980. c++;
  3981. }
  3982. sstr[c] = '\0';
  3983. strcpy(tempchargingProfilePurposeStr, sstr);
  3984. if(chargingProfileIdIsNULL == FALSE)
  3985. {
  3986. DEBUG_INFO("\n OCPP clear 0 !!!\n");
  3987. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3988. {
  3989. DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3990. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3991. clearflag = TRUE;
  3992. break;//continue;
  3993. }
  3994. else
  3995. {
  3996. DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3997. //json_object_array_add(newHeatMap, jsonitem);
  3998. fprintf(fptr2, sLineWord);//writing data into file
  3999. }
  4000. }
  4001. else
  4002. {
  4003. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt) && (tempstackLevelInt == stackLevelInt))
  4004. {
  4005. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4006. clearflag = TRUE;
  4007. break;//continue;
  4008. }
  4009. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4010. {
  4011. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4012. clearflag = TRUE;
  4013. break;//continue;
  4014. }
  4015. else
  4016. {
  4017. //json_object_array_add(newHeatMap, jsonitem);
  4018. fprintf(fptr2, sLineWord);//writing data into file
  4019. }
  4020. }
  4021. memset(sLineWord, 0, sizeof sLineWord);
  4022. }
  4023. if(clearflag == FALSE)
  4024. {
  4025. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4026. goto end;
  4027. }
  4028. fclose(fptr1);
  4029. fclose(fptr2);
  4030. sprintf(str,"rm -f %s",fname);
  4031. system(str);
  4032. resultRename = rename(temp, fname);
  4033. if(resultRename == 0)
  4034. {
  4035. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4036. }
  4037. else
  4038. {
  4039. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4040. }
  4041. }
  4042. end:
  4043. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4044. return result;
  4045. }
  4046. int handleDataTransferRequest(char *uuid, char *payload)
  4047. {
  4048. mtrace();
  4049. int result = FAIL;
  4050. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4051. char tempvendorId[255]={0};
  4052. char tempmessageId[50]={0};
  4053. char tempdata[50]={0};
  4054. char sstr[160]={0};//sstr[200]={ 0 };
  4055. char message[80]={0};
  4056. int c = 0;
  4057. char *loc;
  4058. DEBUG_INFO("handle DataTransferRequest\n");
  4059. if((uuid != NULL) && (payload != NULL))
  4060. {
  4061. //===============================
  4062. // vendorId
  4063. //===============================
  4064. c = 0;
  4065. loc = strstr(payload, "vendorId");
  4066. while (loc[strlen("vendorId")+3+c] != '\"')
  4067. {
  4068. sstr[c] = loc[strlen("vendorId")+3+c];
  4069. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4070. c++;
  4071. }
  4072. sstr[c] = '\0';
  4073. strcpy(tempvendorId,sstr);
  4074. //===============================
  4075. // messageId
  4076. //===============================
  4077. memset(sstr ,0, sizeof(sstr) );
  4078. c = 0;
  4079. loc = strstr(payload, "messageId");
  4080. while (loc[strlen("messageId")+3+c] != '\"')
  4081. {
  4082. sstr[c] = loc[strlen("messageId")+3+c];
  4083. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4084. c++;
  4085. }
  4086. sstr[c] = '\0';
  4087. strcpy(tempmessageId,sstr);
  4088. //===============================
  4089. // data
  4090. //===============================
  4091. memset(sstr ,0, sizeof(sstr) );
  4092. c = 0;
  4093. loc = strstr(payload, "data");
  4094. printf("loc=%s\n",loc);
  4095. while (loc[strlen("data")+3+c] != '\"')
  4096. {
  4097. sstr[c] = loc[strlen("data")+3+c];
  4098. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4099. c++;
  4100. }
  4101. sstr[c] = '\0';
  4102. strcpy(tempdata,sstr);
  4103. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4104. }
  4105. else
  4106. {
  4107. char guid[37]={0};
  4108. random_uuid(guid);
  4109. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4110. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4111. }
  4112. LWS_Send(message);
  4113. return result;
  4114. }
  4115. #if 0
  4116. long long diff_tm(struct tm *a, struct tm *b) {
  4117. return a->tm_sec - b->tm_sec
  4118. + 60LL * (a->tm_min - b->tm_min)
  4119. + 3600LL * (a->tm_hour - b->tm_hour)
  4120. + 86400LL * (a->tm_yday - b->tm_yday)
  4121. + (a->tm_year - 70) * 31536000LL
  4122. - (a->tm_year - 69) / 4 * 86400LL
  4123. + (a->tm_year - 1) / 100 * 86400LL
  4124. - (a->tm_year + 299) / 400 * 86400LL
  4125. - (b->tm_year - 70) * 31536000LL
  4126. + (b->tm_year - 69) / 4 * 86400LL
  4127. - (b->tm_year - 1) / 100 * 86400LL
  4128. + (b->tm_year + 299) /400 * 86400LL;
  4129. }
  4130. #endif
  4131. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4132. {
  4133. mtrace();
  4134. int result = FAIL;
  4135. int connectorIdInt, durationInt;
  4136. char chargingRateUnitStr[4]={0};
  4137. //int tempconnectorIdInt,
  4138. int tempdurationInt;
  4139. float tempminChargingRateFloat = 0.0;
  4140. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4141. int tempStartPeriodInt=0;
  4142. float tempLimitInt=0.0;//0.1;
  4143. int tempNumberPhasesInt=0;
  4144. char fname[200];
  4145. char comfirmstr[20];
  4146. //float totallimit =0.0;
  4147. float MinChargingRate =0.0;
  4148. double diff_t;
  4149. struct tm tp;
  4150. //int clearflag = FALSE;
  4151. FILE *fptr1;//, *fptr2;
  4152. //char temp[] = "../Storage/OCPP/temp.json";
  4153. int c = 0;
  4154. //int i = 0;
  4155. char * pch;
  4156. char *loc;
  4157. char sstr[200]={ 0 };
  4158. int n_chargingProfile = 0;
  4159. int n_SchedulePeriods = 0;
  4160. char SchedulePeriodList[10][200]={0};
  4161. char sLineWord[800]={0};
  4162. //int n_periods = 0;
  4163. char word[1000]={0};
  4164. int confirmPeriods = 0;
  4165. struct StructProfile ChargePointMaxProfile;
  4166. struct StructProfile TxDefaultProfile;
  4167. struct StructProfile TxProfile;
  4168. struct StructProfile TxDefaultProfiletemp[2]={0};
  4169. int TxDefaultProfileFileIsNull=FALSE;
  4170. int ChargePointMaxProfileIsNull=FALSE;
  4171. int TxProfileIsNull=FALSE;
  4172. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4173. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4174. memset(&TxProfile,0,sizeof(struct StructProfile));
  4175. c=0;
  4176. loc = strstr(payload, "connectorId");
  4177. memset(sstr ,0, sizeof(sstr) );
  4178. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4179. {
  4180. sstr[c] = loc[strlen("connectorId")+2+c];
  4181. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4182. c++;
  4183. }
  4184. sstr[c] = '\0';
  4185. connectorIdInt = atoi(sstr);
  4186. c=0;
  4187. loc = strstr(payload, "duration");
  4188. memset(sstr ,0, sizeof(sstr) );
  4189. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4190. {
  4191. sstr[c] = loc[strlen("duration")+2+c];
  4192. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4193. c++;
  4194. }
  4195. sstr[c] = '\0';
  4196. durationInt = atoi(sstr);
  4197. c = 0;
  4198. loc = strstr(payload, "chargingRateUnit");
  4199. memset(sstr ,0, sizeof(sstr) );
  4200. if(loc == NULL)
  4201. {
  4202. }
  4203. else
  4204. {
  4205. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4206. {
  4207. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4208. c++;
  4209. }
  4210. sstr[c] = '\0';
  4211. strcpy(chargingRateUnitStr, sstr);
  4212. }
  4213. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4214. if(connectorIdInt==0) // connectorId is 0
  4215. {
  4216. //******************************ChargePointMaxProfile*****************************************************/
  4217. strcpy(fname, ChargePointMaxProfile_JSON );
  4218. char word[30]={0};
  4219. char sLineWord[1060]={0};
  4220. int n_chargingProfile=0;
  4221. ChargePointMaxProfileIsNull=TRUE;
  4222. if((access(fname,F_OK))!=-1)
  4223. {
  4224. fptr1 = fopen(fname, "r");
  4225. int c;
  4226. c = fgetc(fptr1);
  4227. //DEBUG_INFO("c:%d\n",c);
  4228. rewind(fptr1);
  4229. if(c == EOF)
  4230. {
  4231. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4232. ChargePointMaxProfileIsNull=TRUE;
  4233. fclose(fptr1);
  4234. }
  4235. else
  4236. {
  4237. ChargePointMaxProfileIsNull=FALSE;
  4238. while(fscanf(fptr1, "%s", word) != EOF)
  4239. {
  4240. if(strcmp(word, "chargingProfileId") == 0)
  4241. {
  4242. n_chargingProfile = n_chargingProfile + 1;
  4243. printf("Found\n");
  4244. }
  4245. }
  4246. rewind(fptr1);
  4247. //search Charging Profile Element
  4248. int i= 0;
  4249. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4250. #if 0
  4251. /***********connectorId****************/
  4252. c = 0;
  4253. loc = strstr(sLineWord, "connectorId");
  4254. // printf("loc=%s\n",loc);
  4255. memset(sstr ,0, sizeof(sstr) );
  4256. while (loc[strlen("connectorId")+2+c] != ',')
  4257. {
  4258. sstr[c] = loc[strlen("connectorId")+2+c];
  4259. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4260. c++;
  4261. }
  4262. sstr[c] = '\0';
  4263. tempconnectorIdInt = atoi(sstr);
  4264. #endif
  4265. //***********validFrom**************/
  4266. c = 0;
  4267. loc = strstr(sLineWord, "validFrom");
  4268. //DEBUG_INFO("loc=%s\n",loc);
  4269. memset(sstr ,0, sizeof(sstr) );
  4270. if(loc != NULL)
  4271. {
  4272. while (loc[3+strlen("validFrom")+c] != '\"')
  4273. {
  4274. sstr[c] = loc[3+strlen("validFrom")+c];
  4275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4276. c++;
  4277. }
  4278. sstr[c] = '\0';
  4279. DEBUG_INFO("validFrom=%s\n",sstr);
  4280. strcpy(tempvalidFromStr,sstr);
  4281. }
  4282. else
  4283. {
  4284. strcpy(tempvalidFromStr,"");
  4285. }
  4286. //**********startSchedule**********/
  4287. c = 0;
  4288. loc = strstr(sLineWord, "startSchedule");
  4289. //DEBUG_INFO("loc=%s\n",loc);
  4290. memset(sstr ,0, sizeof(sstr) );
  4291. while (loc[3+strlen("startSchedule")+c] != '\"')
  4292. {
  4293. sstr[c] = loc[3+strlen("startSchedule")+c];
  4294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4295. c++;
  4296. }
  4297. sstr[c] = '\0';
  4298. strcpy(tempstartScheduleStr, sstr);
  4299. //**********startSchedule**********/
  4300. c = 0;
  4301. loc = strstr(sLineWord, "chargingRateUnit");
  4302. memset(sstr ,0, sizeof(sstr) );
  4303. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4304. {
  4305. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4306. c++;
  4307. }
  4308. sstr[c] = '\0';
  4309. strcpy(tempchargingRateUnitStr, sstr);
  4310. //**********minChargingRate*******/
  4311. c = 0;
  4312. loc = strstr(sLineWord, "minChargingRate");
  4313. //printf("loc=%s\n",loc);
  4314. if(loc != NULL)
  4315. {
  4316. memset(sstr ,0, sizeof(sstr) );
  4317. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4318. {
  4319. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4320. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4321. c++;
  4322. }
  4323. sstr[c] = '\0';
  4324. tempminChargingRateFloat = atof(sstr);
  4325. }
  4326. else
  4327. {
  4328. tempminChargingRateFloat = 0.0;
  4329. }
  4330. //
  4331. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4332. tp.tm_isdst = -1;
  4333. time_t utc = mktime(&tp);
  4334. // current time
  4335. time_t t = time(NULL);
  4336. diff_t = difftime(t, utc);
  4337. //parsing strings to words
  4338. i = 0;
  4339. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4340. loc = loc+3+strlen("chargingSchedulePeriod");
  4341. pch = strtok(loc ,"{");
  4342. while (pch != NULL)
  4343. {
  4344. strcpy(SchedulePeriodList[i], pch);
  4345. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4346. //printf ("%s\n",pch);
  4347. pch = strtok (NULL, "{");
  4348. i = i + 1;
  4349. }
  4350. n_SchedulePeriods = i;
  4351. for(int i=0;i<n_SchedulePeriods;i++)
  4352. {
  4353. //*************startPeriod****************/
  4354. c = 0;
  4355. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4356. memset(sstr ,0, sizeof(sstr) );
  4357. while (loc[strlen("startPeriod")+2+c] != ',')
  4358. {
  4359. sstr[c] = loc[strlen("startPeriod")+2+c];
  4360. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4361. c++;
  4362. }
  4363. sstr[c] = '\0';
  4364. tempStartPeriodInt = atoi(sstr);
  4365. //*************limit****************/
  4366. c = 0;
  4367. loc = strstr(SchedulePeriodList[i], "limit");
  4368. memset(sstr ,0, sizeof(sstr) );
  4369. while (loc[strlen("limit")+2+c] != ',')
  4370. {
  4371. sstr[c] = loc[strlen("limit")+2+c];
  4372. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4373. c++;
  4374. }
  4375. sstr[c] = '\0';
  4376. tempLimitInt = atof(sstr);
  4377. //*************numberPhases****************/
  4378. c = 0;
  4379. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4380. memset(sstr ,0, sizeof(sstr) );
  4381. while (loc[strlen("numberPhases")+2+c] != ',')
  4382. {
  4383. sstr[c] = loc[strlen("numberPhases")+2+c];
  4384. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4385. c++;
  4386. }
  4387. sstr[c] = '\0';
  4388. tempNumberPhasesInt = atoi(sstr);
  4389. ChargePointMaxProfile.Duration = durationInt;
  4390. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4391. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4392. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4393. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4394. }
  4395. if(MinChargingRate < tempminChargingRateFloat)
  4396. MinChargingRate = tempminChargingRateFloat;
  4397. }
  4398. }// End of file ChargingProfile
  4399. } //THE END OF ACCESS ChargePointMaxProfile
  4400. //******************************TxDefaultProfile***********************************************/
  4401. strcpy(fname, TxDefaultProfile_0_JSON);
  4402. memset(word, 0, 30);
  4403. memset(sLineWord, 0, 1060);
  4404. //char word[30]={0};
  4405. //char sLineWord[1060]={0};
  4406. n_chargingProfile=0;
  4407. TxDefaultProfileFileIsNull=TRUE;
  4408. if((access(fname,F_OK))!=-1)
  4409. {
  4410. fptr1 = fopen(fname, "r");
  4411. c = 0;
  4412. c = fgetc(fptr1);
  4413. //DEBUG_INFO("c:%d\n",c);
  4414. rewind(fptr1);
  4415. if(c == EOF)
  4416. {
  4417. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4418. TxDefaultProfileFileIsNull=TRUE;
  4419. fclose(fptr1);
  4420. }
  4421. else
  4422. {
  4423. TxDefaultProfileFileIsNull=FALSE;
  4424. while(fscanf(fptr1, "%s", word) != EOF)
  4425. {
  4426. if(strcmp(word, "chargingProfileId") == 0)
  4427. {
  4428. n_chargingProfile = n_chargingProfile + 1;
  4429. printf("Found\n");
  4430. }
  4431. }
  4432. rewind(fptr1);
  4433. //search Charging Profile Element
  4434. int i= 0;
  4435. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4436. #if 0
  4437. /***********connectorId****************/
  4438. c = 0;
  4439. loc = strstr(sLineWord, "connectorId");
  4440. // printf("loc=%s\n",loc);
  4441. memset(sstr ,0, sizeof(sstr) );
  4442. while (loc[strlen("connectorId")+2+c] != ',')
  4443. {
  4444. sstr[c] = loc[strlen("connectorId")+2+c];
  4445. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4446. c++;
  4447. }
  4448. sstr[c] = '\0';
  4449. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4450. tempconnectorIdInt = atoi(sstr);
  4451. #endif
  4452. //***********validFrom**************/
  4453. c = 0;
  4454. loc = strstr(sLineWord, "validFrom");
  4455. //DEBUG_INFO("loc=%s\n",loc);
  4456. memset(sstr ,0, sizeof(sstr) );
  4457. if(loc != NULL)
  4458. {
  4459. while (loc[3+strlen("validFrom")+c] != '\"')
  4460. {
  4461. sstr[c] = loc[3+strlen("validFrom")+c];
  4462. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4463. c++;
  4464. }
  4465. sstr[c] = '\0';
  4466. DEBUG_INFO("validFrom=%s\n",sstr);
  4467. strcpy(tempvalidFromStr,sstr);
  4468. }
  4469. else
  4470. {
  4471. strcpy(tempvalidFromStr,"");
  4472. }
  4473. //**********startSchedule**********/
  4474. c = 0;
  4475. loc = strstr(sLineWord, "startSchedule");
  4476. //DEBUG_INFO("loc=%s\n",loc);
  4477. memset(sstr ,0, sizeof(sstr) );
  4478. while (loc[3+strlen("startSchedule")+c] != '\"')
  4479. {
  4480. sstr[c] = loc[3+strlen("startSchedule")+c];
  4481. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4482. c++;
  4483. }
  4484. sstr[c] = '\0';
  4485. strcpy(tempstartScheduleStr, sstr);
  4486. DEBUG_INFO(" debug 3-1\n");
  4487. //**********startSchedule**********/
  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[3+strlen("minChargingRate")+c] != '\"')
  4506. {
  4507. sstr[c] = loc[3+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] != ',')
  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. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4592. {
  4593. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4594. {
  4595. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4596. }
  4597. else
  4598. {
  4599. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4600. }
  4601. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4602. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4603. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4604. }
  4605. }
  4606. //* Define temporary variables */
  4607. struct tm *gtime;
  4608. time_t now;
  4609. char buf[28];
  4610. /* Read the current system time */
  4611. time(&now);
  4612. /* Convert the system time to GMT (now UTC) */
  4613. gtime = gmtime(&now);
  4614. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4615. // make .conf
  4616. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  4617. //MaxChargingProfilesInstalled is 10
  4618. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4619. memset(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4620. //nPeriod = 1;
  4621. if(chargingRateUnitStr[0] != 0)
  4622. {
  4623. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4624. }
  4625. else
  4626. {
  4627. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  4628. }
  4629. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4630. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4631. confirmPeriods = 1;
  4632. }
  4633. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4634. {
  4635. //*****************************ChargePointMaxProfile******************************************/
  4636. strcpy(fname, ChargePointMaxProfile_JSON);
  4637. ChargePointMaxProfileIsNull=TRUE;
  4638. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4639. {
  4640. fptr1 = fopen(fname, "r");
  4641. int c;
  4642. c = fgetc(fptr1);
  4643. //DEBUG_INFO("c:%d\n",c);
  4644. rewind(fptr1);
  4645. if(c == EOF)
  4646. {
  4647. DEBUG_INFO("\n End of file reached.");
  4648. ChargePointMaxProfileIsNull=TRUE;
  4649. fclose(fptr1);
  4650. }
  4651. else
  4652. {
  4653. ChargePointMaxProfileIsNull=FALSE;
  4654. while(fscanf(fptr1, "%s", word) != EOF)
  4655. {
  4656. if(strcmp(word, "chargingProfileId") == 0)
  4657. {
  4658. n_chargingProfile = n_chargingProfile + 1;
  4659. }
  4660. }
  4661. rewind(fptr1);
  4662. //search Charging Profile Element
  4663. int i = 0;
  4664. int j = 0;
  4665. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4666. #if 0
  4667. /***********connectorId****************/
  4668. c = 0;
  4669. loc = strstr(sLineWord, "connectorId");
  4670. memset(sstr ,0, sizeof(sstr) );
  4671. while (loc[strlen("connectorId")+2+c] != ',')
  4672. {
  4673. sstr[c] = loc[strlen("connectorId")+2+c];
  4674. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4675. c++;
  4676. }
  4677. sstr[c] = '\0';
  4678. tempconnectorIdInt = atoi(sstr);
  4679. #endif
  4680. //***********validFrom**************/
  4681. c = 0;
  4682. loc = strstr(sLineWord, "validFrom");
  4683. if(loc != NULL)
  4684. {
  4685. memset(sstr ,0, sizeof(sstr) );
  4686. while (loc[3+strlen("validFrom")+c] != '\"')
  4687. {
  4688. sstr[c] = loc[3+strlen("validFrom")+c];
  4689. c++;
  4690. }
  4691. sstr[c] = '\0';
  4692. strcpy(tempvalidFromStr,sstr);
  4693. }
  4694. else
  4695. {
  4696. strcpy(tempvalidFromStr,"");
  4697. }
  4698. //***********validFrom**************/
  4699. c = 0;
  4700. loc = strstr(sLineWord, "duration");
  4701. if(loc != NULL)
  4702. {
  4703. memset(sstr ,0, sizeof(sstr) );
  4704. while (loc[2+strlen("duration")+c] != ',')
  4705. {
  4706. sstr[c] = loc[2+strlen("duration")+c];
  4707. c++;
  4708. }
  4709. sstr[c] = '\0';
  4710. tempdurationInt = atoi(sstr);
  4711. }
  4712. else
  4713. {
  4714. tempdurationInt = 0;
  4715. }
  4716. //**********startSchedule**********/
  4717. c = 0;
  4718. loc = strstr(sLineWord, "startSchedule");
  4719. memset(sstr ,0, sizeof(sstr) );
  4720. while (loc[3+strlen("startSchedule")+c] != '\"')
  4721. {
  4722. sstr[c] = loc[3+strlen("startSchedule")+c];
  4723. c++;
  4724. }
  4725. sstr[c] = '\0';
  4726. strcpy(tempstartScheduleStr, sstr);
  4727. //**********startSchedule**********/
  4728. c = 0;
  4729. loc = strstr(sLineWord, "chargingRateUnit");
  4730. memset(sstr ,0, sizeof(sstr) );
  4731. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4732. {
  4733. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4734. c++;
  4735. }
  4736. sstr[c] = '\0';
  4737. strcpy(tempchargingRateUnitStr, sstr);
  4738. //**********minChargingRate*******/
  4739. c = 0;
  4740. loc = strstr(sLineWord, "minChargingRate");
  4741. if(loc != NULL)
  4742. {
  4743. memset(sstr ,0, sizeof(sstr) );
  4744. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4745. {
  4746. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4747. c++;
  4748. }
  4749. sstr[c] = '\0';
  4750. tempminChargingRateFloat = atof(sstr);
  4751. }
  4752. else
  4753. {
  4754. tempminChargingRateFloat = 0.0;
  4755. }
  4756. //
  4757. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4758. tp.tm_isdst = -1;
  4759. time_t utc = mktime(&tp);
  4760. time_t t = time(NULL);
  4761. diff_t = difftime(t, utc);
  4762. DEBUG_INFO("diff_t=%f\n",diff_t);
  4763. DEBUG_INFO(" debug 5 -1\n");
  4764. //parsing strings to words
  4765. i = 0;
  4766. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4767. loc = loc+3+strlen("chargingSchedulePeriod");
  4768. pch = strtok(loc ,"{");
  4769. while (pch != NULL)
  4770. {
  4771. strcpy(SchedulePeriodList[i], pch);
  4772. pch = strtok (NULL, "{");
  4773. i = i + 1;
  4774. }
  4775. n_SchedulePeriods = i;
  4776. for(int i=0;i<n_SchedulePeriods;i++)
  4777. {
  4778. //*************startPeriod****************/
  4779. c = 0;
  4780. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4781. memset(sstr ,0, sizeof(sstr) );
  4782. while (loc[strlen("startPeriod")+2+c] != ',')
  4783. {
  4784. sstr[c] = loc[strlen("startPeriod")+2+c];
  4785. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4786. c++;
  4787. }
  4788. sstr[c] = '\0';
  4789. tempStartPeriodInt = atoi(sstr);
  4790. //*************limit****************/
  4791. c = 0;
  4792. loc = strstr(SchedulePeriodList[i], "limit");
  4793. memset(sstr ,0, sizeof(sstr) );
  4794. while (loc[strlen("limit")+2+c] != ',')
  4795. {
  4796. sstr[c] = loc[strlen("limit")+2+c];
  4797. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4798. c++;
  4799. }
  4800. sstr[c] = '\0';
  4801. tempLimitInt = atof(sstr);
  4802. //*************numberPhases****************/
  4803. c = 0;
  4804. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4805. memset(sstr ,0, sizeof(sstr) );
  4806. while (loc[strlen("numberPhases")+2+c] != '}')
  4807. {
  4808. sstr[c] = loc[strlen("numberPhases")+2+c];
  4809. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4810. c++;
  4811. }
  4812. sstr[c] = '\0';
  4813. tempNumberPhasesInt = atoi(sstr);
  4814. if(j == 0)
  4815. {
  4816. ChargePointMaxProfile.Duration = tempdurationInt;
  4817. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4818. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4819. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4820. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4821. }
  4822. }
  4823. if(MinChargingRate < tempminChargingRateFloat)
  4824. {
  4825. MinChargingRate = tempminChargingRateFloat;
  4826. }
  4827. if(confirmPeriods < n_SchedulePeriods)
  4828. {
  4829. confirmPeriods = n_SchedulePeriods;
  4830. }
  4831. j = j + 1;
  4832. }
  4833. fclose(fptr1);
  4834. }
  4835. }// the end of access file ChargePointMaxProfile
  4836. //****************************TxDefaultProfile************************************************/
  4837. switch(connectorIdInt)
  4838. {
  4839. case 0:
  4840. break;
  4841. case 1:
  4842. strcpy(fname, TxDefaultProfile_1_JSON );
  4843. break;
  4844. case 2:
  4845. strcpy(fname, TxDefaultProfile_2_JSON );
  4846. break;
  4847. default:
  4848. strcpy(fname, TxDefaultProfile_1_JSON );
  4849. break;
  4850. }
  4851. TxDefaultProfileFileIsNull=TRUE;
  4852. if((access(fname,F_OK))!=-1)
  4853. {
  4854. fptr1 = fopen(fname, "r");
  4855. c = 0;
  4856. c = fgetc(fptr1);
  4857. //DEBUG_INFO("c:%d\n",c);
  4858. rewind(fptr1);
  4859. if(c == EOF)
  4860. {
  4861. DEBUG_INFO("\n End of file reached.");
  4862. TxDefaultProfileFileIsNull=TRUE;
  4863. fclose(fptr1);
  4864. }
  4865. else
  4866. {
  4867. TxDefaultProfileFileIsNull=FALSE;
  4868. while(fscanf(fptr1, "%s", word) != EOF)
  4869. {
  4870. if(strcmp(word, "chargingProfileId") == 0)
  4871. {
  4872. n_chargingProfile = n_chargingProfile + 1;
  4873. }
  4874. }
  4875. rewind(fptr1);
  4876. //search Charging Profile Element
  4877. int i = 0;
  4878. int j = 0;
  4879. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4880. #if 0
  4881. /***********connectorId****************/
  4882. c = 0;
  4883. loc = strstr(sLineWord, "connectorId");
  4884. memset(sstr ,0, sizeof(sstr) );
  4885. while (loc[strlen("connectorId")+2+c] != ',')
  4886. {
  4887. sstr[c] = loc[strlen("connectorId")+2+c];
  4888. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4889. c++;
  4890. }
  4891. sstr[c] = '\0';
  4892. tempconnectorIdInt = atoi(sstr);
  4893. #endif
  4894. //***********validFrom**************/
  4895. c = 0;
  4896. loc = strstr(sLineWord, "validFrom");
  4897. if(loc != NULL)
  4898. {
  4899. memset(sstr ,0, sizeof(sstr) );
  4900. while (loc[3+strlen("validFrom")+c] != '\"')
  4901. {
  4902. sstr[c] = loc[3+strlen("validFrom")+c];
  4903. c++;
  4904. }
  4905. sstr[c] = '\0';
  4906. strcpy(tempvalidFromStr,sstr);
  4907. }
  4908. else
  4909. {
  4910. strcpy(tempvalidFromStr,"");
  4911. }
  4912. //***********validFrom**************/
  4913. c = 0;
  4914. loc = strstr(sLineWord, "duration");
  4915. if(loc != NULL)
  4916. {
  4917. memset(sstr ,0, sizeof(sstr) );
  4918. while (loc[2+strlen("duration")+c] != ',')
  4919. {
  4920. sstr[c] = loc[2+strlen("duration")+c];
  4921. c++;
  4922. }
  4923. sstr[c] = '\0';
  4924. tempdurationInt = atoi(sstr);
  4925. }
  4926. else
  4927. {
  4928. tempdurationInt = 0;
  4929. }
  4930. //**********startSchedule**********/
  4931. c = 0;
  4932. loc = strstr(sLineWord, "startSchedule");
  4933. memset(sstr ,0, sizeof(sstr) );
  4934. while (loc[3+strlen("startSchedule")+c] != '\"')
  4935. {
  4936. sstr[c] = loc[3+strlen("startSchedule")+c];
  4937. c++;
  4938. }
  4939. sstr[c] = '\0';
  4940. strcpy(tempstartScheduleStr, sstr);
  4941. //**********startSchedule**********/
  4942. c = 0;
  4943. loc = strstr(sLineWord, "chargingRateUnit");
  4944. memset(sstr ,0, sizeof(sstr) );
  4945. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4946. {
  4947. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4948. c++;
  4949. }
  4950. sstr[c] = '\0';
  4951. strcpy(tempchargingRateUnitStr, sstr);
  4952. //**********minChargingRate*******/
  4953. c = 0;
  4954. loc = strstr(sLineWord, "minChargingRate");
  4955. if(loc != NULL)
  4956. {
  4957. memset(sstr ,0, sizeof(sstr) );
  4958. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4959. {
  4960. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4961. c++;
  4962. }
  4963. sstr[c] = '\0';
  4964. tempminChargingRateFloat = atof(sstr);
  4965. }
  4966. else
  4967. {
  4968. tempminChargingRateFloat = 0.0;
  4969. }
  4970. //
  4971. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4972. tp.tm_isdst = -1;
  4973. time_t utc = mktime(&tp);
  4974. time_t t = time(NULL);
  4975. diff_t = difftime(t, utc);
  4976. DEBUG_INFO("diff_t=%f\n",diff_t);
  4977. DEBUG_INFO(" debug 5 -1\n");
  4978. //parsing strings to words
  4979. i = 0;
  4980. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4981. loc = loc+3+strlen("chargingSchedulePeriod");
  4982. pch = strtok(loc ,"{");
  4983. while (pch != NULL)
  4984. {
  4985. strcpy(SchedulePeriodList[i], pch);
  4986. pch = strtok (NULL, "{");
  4987. i = i + 1;
  4988. }
  4989. n_SchedulePeriods = i;
  4990. for(int i=0;i<n_SchedulePeriods;i++)
  4991. {
  4992. //*************startPeriod****************/
  4993. c = 0;
  4994. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4995. memset(sstr ,0, sizeof(sstr) );
  4996. while (loc[strlen("startPeriod")+2+c] != ',')
  4997. {
  4998. sstr[c] = loc[strlen("startPeriod")+2+c];
  4999. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5000. c++;
  5001. }
  5002. sstr[c] = '\0';
  5003. tempStartPeriodInt = atoi(sstr);
  5004. //*************limit****************/
  5005. c = 0;
  5006. loc = strstr(SchedulePeriodList[i], "limit");
  5007. memset(sstr ,0, sizeof(sstr) );
  5008. while (loc[strlen("limit")+2+c] != ',')
  5009. {
  5010. sstr[c] = loc[strlen("limit")+2+c];
  5011. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5012. c++;
  5013. }
  5014. sstr[c] = '\0';
  5015. tempLimitInt = atof(sstr);
  5016. //*************numberPhases****************/
  5017. c = 0;
  5018. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5019. memset(sstr ,0, sizeof(sstr) );
  5020. while (loc[strlen("numberPhases")+2+c] != '}')
  5021. {
  5022. sstr[c] = loc[strlen("numberPhases")+2+c];
  5023. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5024. c++;
  5025. }
  5026. sstr[c] = '\0';
  5027. tempNumberPhasesInt = atoi(sstr);
  5028. if(j == 0)
  5029. {
  5030. TxDefaultProfile.Duration = tempdurationInt;
  5031. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5032. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5033. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5034. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5035. }
  5036. else
  5037. {
  5038. //other stack level charging Profile
  5039. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5040. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5041. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5042. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5043. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5044. }
  5045. }
  5046. if(MinChargingRate < tempminChargingRateFloat)
  5047. MinChargingRate = tempminChargingRateFloat;
  5048. if(confirmPeriods < n_SchedulePeriods)
  5049. confirmPeriods = n_SchedulePeriods;
  5050. j = j + 1;
  5051. }
  5052. fclose(fptr1);
  5053. //Stacking Charging Profiles
  5054. for(int l=0; l <(j-1) ;l++)
  5055. {
  5056. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5057. {
  5058. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5059. {
  5060. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5061. {
  5062. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5063. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5064. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5065. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5066. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5067. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5068. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5069. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5070. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5071. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5072. }
  5073. else
  5074. {
  5075. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5076. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5077. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5078. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5079. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5080. }
  5081. }
  5082. }
  5083. }
  5084. //end of Stacking Charging Profiles
  5085. }
  5086. }// the end of ACCESS TxDefaultProfile
  5087. //****************************TxProfile************************************************/
  5088. switch(connectorIdInt)
  5089. {
  5090. case 0:
  5091. break;
  5092. case 1:
  5093. strcpy(fname, TxProfile_1_JSON );
  5094. break;
  5095. case 2:
  5096. strcpy(fname, TxProfile_2_JSON );
  5097. break;
  5098. default:
  5099. strcpy(fname, TxProfile_1_JSON );
  5100. break;
  5101. }
  5102. TxProfileIsNull=TRUE;
  5103. if((access(fname,F_OK))!=-1)
  5104. {
  5105. fptr1 = fopen(fname, "r");
  5106. c = 0;
  5107. c = fgetc(fptr1);
  5108. //DEBUG_INFO("c:%d\n",c);
  5109. rewind(fptr1);
  5110. if(c == EOF)
  5111. {
  5112. DEBUG_INFO("\n End of file reached.");
  5113. TxProfileIsNull=TRUE;
  5114. fclose(fptr1);
  5115. }
  5116. else
  5117. {
  5118. TxProfileIsNull=FALSE;
  5119. while(fscanf(fptr1, "%s", word) != EOF)
  5120. {
  5121. if(strcmp(word, "chargingProfileId") == 0)
  5122. {
  5123. n_chargingProfile = n_chargingProfile + 1;
  5124. }
  5125. }
  5126. rewind(fptr1);
  5127. //search Charging Profile Element
  5128. int i= 0;
  5129. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5130. #if 0
  5131. /***********connectorId****************/
  5132. c = 0;
  5133. loc = strstr(sLineWord, "connectorId");
  5134. memset(sstr ,0, sizeof(sstr) );
  5135. while (loc[strlen("connectorId")+2+c] != ',')
  5136. {
  5137. sstr[c] = loc[strlen("connectorId")+2+c];
  5138. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5139. c++;
  5140. }
  5141. sstr[c] = '\0';
  5142. tempconnectorIdInt = atoi(sstr);
  5143. #endif
  5144. //***********validFrom**************/
  5145. c = 0;
  5146. loc = strstr(sLineWord, "validFrom");
  5147. if(loc != NULL)
  5148. {
  5149. memset(sstr ,0, sizeof(sstr) );
  5150. while (loc[3+strlen("validFrom")+c] != '\"')
  5151. {
  5152. sstr[c] = loc[3+strlen("validFrom")+c];
  5153. c++;
  5154. }
  5155. sstr[c] = '\0';
  5156. strcpy(tempvalidFromStr,sstr);
  5157. }
  5158. else
  5159. {
  5160. strcpy(tempvalidFromStr,"");
  5161. }
  5162. //**********startSchedule**********/
  5163. c = 0;
  5164. loc = strstr(sLineWord, "startSchedule");
  5165. memset(sstr ,0, sizeof(sstr) );
  5166. while (loc[3+strlen("startSchedule")+c] != '\"')
  5167. {
  5168. sstr[c] = loc[3+strlen("startSchedule")+c];
  5169. c++;
  5170. }
  5171. sstr[c] = '\0';
  5172. strcpy(tempstartScheduleStr, sstr);
  5173. //**********startSchedule**********/
  5174. c = 0;
  5175. loc = strstr(sLineWord, "chargingRateUnit");
  5176. memset(sstr ,0, sizeof(sstr) );
  5177. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5178. {
  5179. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5180. c++;
  5181. }
  5182. sstr[c] = '\0';
  5183. strcpy(tempchargingRateUnitStr, sstr);
  5184. //**********minChargingRate*******/
  5185. c = 0;
  5186. loc = strstr(sLineWord, "minChargingRate");
  5187. if(loc != NULL)
  5188. {
  5189. memset(sstr ,0, sizeof(sstr) );
  5190. while (loc[3+strlen("minChargingRate")+c] != '\"')
  5191. {
  5192. sstr[c] = loc[3+strlen("minChargingRate")+c];
  5193. c++;
  5194. }
  5195. sstr[c] = '\0';
  5196. tempminChargingRateFloat = atof(sstr);
  5197. }
  5198. else
  5199. {
  5200. tempminChargingRateFloat = 0.0;
  5201. }
  5202. //
  5203. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5204. tp.tm_isdst = -1;
  5205. time_t utc = mktime(&tp);
  5206. time_t t = time(NULL);
  5207. diff_t = difftime(t, utc);
  5208. DEBUG_INFO("diff_t=%f\n",diff_t);
  5209. //parsing strings to words
  5210. i = 0;
  5211. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5212. loc = loc+3+strlen("chargingSchedulePeriod");
  5213. pch = strtok(loc ,"{");
  5214. while (pch != NULL)
  5215. {
  5216. strcpy(SchedulePeriodList[i], pch);
  5217. pch = strtok (NULL, "{");
  5218. i = i + 1;
  5219. }
  5220. n_SchedulePeriods = i;
  5221. for(int i=0;i<n_SchedulePeriods;i++)
  5222. {
  5223. //*************startPeriod****************/
  5224. c = 0;
  5225. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5226. memset(sstr ,0, sizeof(sstr) );
  5227. while (loc[strlen("startPeriod")+2+c] != ',')
  5228. {
  5229. sstr[c] = loc[strlen("startPeriod")+2+c];
  5230. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5231. c++;
  5232. }
  5233. sstr[c] = '\0';
  5234. tempStartPeriodInt = atoi(sstr);
  5235. //*************limit****************/
  5236. c = 0;
  5237. loc = strstr(SchedulePeriodList[i], "limit");
  5238. memset(sstr ,0, sizeof(sstr) );
  5239. while (loc[strlen("limit")+2+c] != ',')
  5240. {
  5241. sstr[c] = loc[strlen("limit")+2+c];
  5242. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5243. c++;
  5244. }
  5245. sstr[c] = '\0';
  5246. tempLimitInt = atof(sstr);
  5247. //*************numberPhases****************/
  5248. c = 0;
  5249. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5250. memset(sstr ,0, sizeof(sstr) );
  5251. while (loc[strlen("numberPhases")+2+c] != '}')
  5252. {
  5253. sstr[c] = loc[strlen("numberPhases")+2+c];
  5254. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5255. c++;
  5256. }
  5257. sstr[c] = '\0';
  5258. tempNumberPhasesInt = atoi(sstr);
  5259. TxProfile.Duration = durationInt;
  5260. TxProfile.TotalPeriod = n_SchedulePeriods;
  5261. TxProfile.Period[i].Limit = tempLimitInt;
  5262. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5263. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5264. }
  5265. if(MinChargingRate < tempminChargingRateFloat)
  5266. MinChargingRate = tempminChargingRateFloat;
  5267. if(confirmPeriods < n_SchedulePeriods)
  5268. confirmPeriods = n_SchedulePeriods;
  5269. }
  5270. fclose(fptr1);
  5271. }
  5272. }// the end of ACCESS TxProfile
  5273. //CompositeSchedule
  5274. int period=0;
  5275. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5276. {
  5277. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5278. {
  5279. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5280. {
  5281. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5282. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5283. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5284. period = period + 1;
  5285. }
  5286. else
  5287. {
  5288. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5289. {
  5290. }
  5291. else
  5292. {
  5293. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5294. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5295. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5296. period = period + 1;
  5297. }
  5298. }
  5299. }
  5300. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5301. {
  5302. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5303. {
  5304. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5305. {
  5306. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5307. }
  5308. else
  5309. {
  5310. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5311. }
  5312. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5313. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5314. period = period + 1;
  5315. }
  5316. }
  5317. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5318. {
  5319. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5320. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5321. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5322. period = period + 1;
  5323. }
  5324. }
  5325. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5326. {
  5327. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5328. {
  5329. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5330. {
  5331. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5332. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5333. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5334. period = period + 1;
  5335. }
  5336. else
  5337. {
  5338. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5339. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5340. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5341. period = period + 1;
  5342. }
  5343. }
  5344. }
  5345. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5346. {
  5347. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5348. {
  5349. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5350. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5351. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5352. period = period + 1;
  5353. }
  5354. }
  5355. confirmPeriods = period;
  5356. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5357. //* Define temporary variables */
  5358. struct tm *gtime;
  5359. time_t now;
  5360. char buf[28];
  5361. //* Read the current system time */
  5362. time(&now);
  5363. //* Convert the system time to GMT (now UTC) */
  5364. gtime = gmtime(&now);
  5365. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5366. // make .conf
  5367. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  5368. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  5369. //DEBUG_INFO(" debug 11\n");
  5370. // if(chargingRateUnitStr[0] != 0)
  5371. // {
  5372. // strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  5373. // }
  5374. // else
  5375. {
  5376. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5377. }
  5378. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5379. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5380. }
  5381. else
  5382. {
  5383. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5384. }
  5385. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5386. return result;
  5387. }
  5388. int handleGetConfigurationRequest(char *uuid, char *payload)
  5389. {
  5390. mtrace();
  5391. int result = FAIL;
  5392. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5393. //struct json_object *jsonitem;
  5394. int MaxKeySupported = 0;
  5395. int n_keys = 0;
  5396. char requestKey[43][50]={0};
  5397. char search[]="[";
  5398. char sstr[500]={ 0 };
  5399. //int pos;
  5400. int l, c = 0;
  5401. int i = 0;
  5402. char *delim = "\",\"";
  5403. char * pch;
  5404. char *loc = strstr(payload, search);
  5405. //********************* Parsing String ***********************************/
  5406. if(loc == NULL) {
  5407. DEBUG_INFO("no key match in Configuration \n");
  5408. }
  5409. else {
  5410. //pos = loc - payload;
  5411. l = strlen(loc)-4;
  5412. while (c < l)
  5413. {
  5414. sstr[c] = loc[c+2];
  5415. c++;
  5416. }
  5417. sstr[c] = '\0';
  5418. //parsing strings to words
  5419. pch = strtok(sstr,delim);
  5420. if(pch == NULL)
  5421. {
  5422. strcpy(requestKey[0], sstr);
  5423. }
  5424. else
  5425. {
  5426. while (pch != NULL)
  5427. {
  5428. strcpy(requestKey[i], pch);
  5429. pch = strtok (NULL, delim);
  5430. i = i + 1;
  5431. }
  5432. n_keys = i;
  5433. }
  5434. }
  5435. UnknownKeynum = 0;
  5436. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5437. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5438. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5439. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5440. if(n_keys != 0)
  5441. {
  5442. for(int i=0;i<n_keys;i++)
  5443. {
  5444. getKeyValue(requestKey[i]);
  5445. //json_object_put(jsonitem);
  5446. }
  5447. }
  5448. else
  5449. {
  5450. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5451. getKeyValue("");
  5452. }
  5453. processUnkownKey();
  5454. sendGetConfigurationConfirmation(uuid);
  5455. return result;
  5456. }
  5457. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5458. {
  5459. mtrace();
  5460. int result = FAIL;
  5461. //void *ret; //
  5462. char fnamePlusPath[50]="";
  5463. char fname[16]="";
  5464. pthread_t t; // pthread 變數
  5465. time_t rawtime;
  5466. struct tm * timeinfo;
  5467. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5468. system("exec /root/logPackTools 'log' 6");
  5469. //char buffer [128];
  5470. time (&rawtime);
  5471. //printf("%ld\n", rawtime);
  5472. timeinfo = localtime (&rawtime);
  5473. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5474. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5475. if((access(fnamePlusPath,F_OK))!=-1)
  5476. {
  5477. DEBUG_INFO("fnamePlusPath exist.\n");
  5478. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5479. }
  5480. else
  5481. {
  5482. DEBUG_INFO("fnamePlusPath not exist!\n");
  5483. }
  5484. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5485. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5486. pthread_join(t, NULL/*&ret*/);
  5487. return result;
  5488. }
  5489. void* GetDiagnosticsProcess(void* data)
  5490. {
  5491. mtrace();
  5492. int retriesInt=0, retryIntervalInt=0;
  5493. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5494. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5495. 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};
  5496. int port=0;
  5497. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5498. char fname[16]="";
  5499. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5500. int c = 0;
  5501. char *loc;
  5502. int isSuccess = FALSE;
  5503. char ftpbuf[200]={0};
  5504. //char temp[100]={0};
  5505. char * pch;
  5506. // [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"}]
  5507. char *str = (char*) data; // ?��?輸入資�?
  5508. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5509. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5510. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5511. //****************location*******************/
  5512. c = 0;
  5513. memset(sstr ,0, sizeof(sstr) );
  5514. loc = strstr(str, "location");
  5515. while (loc[3+strlen("location")+c] != '\"')
  5516. {
  5517. sstr[c] = loc[3+strlen("location")+c];
  5518. c++;
  5519. }
  5520. sstr[c] = '\0';
  5521. strcpy(locationstr,sstr);
  5522. if(strcmp(locationstr,"")==0)
  5523. {
  5524. DEBUG_INFO("location is <Empty>!\n");
  5525. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5526. goto end;
  5527. }
  5528. //****************retries*******************/
  5529. c = 0;
  5530. loc = strstr(str, "retries");
  5531. if(loc == NULL)
  5532. {
  5533. retriesIsNULL = TRUE;
  5534. }
  5535. else
  5536. {
  5537. while (loc[strlen("retries")+2+c] != ',')
  5538. {
  5539. sstr[c] = loc[strlen("retries")+2+c];
  5540. c++;
  5541. }
  5542. sstr[c] = '\0';
  5543. retriesInt = atoi(sstr);
  5544. }
  5545. if(retriesIsNULL == TRUE)
  5546. {
  5547. retriesInt = 0;
  5548. }
  5549. //****************retryInterval*******************/
  5550. c = 0;
  5551. loc = strstr(str, "retryInterval");
  5552. if(loc == NULL)
  5553. {
  5554. retryIntervalIsNULL = TRUE;
  5555. }
  5556. else
  5557. {
  5558. while (loc[strlen("retryInterval")+2+c] != ',')
  5559. {
  5560. sstr[c] = loc[strlen("retryInterval")+2+c];
  5561. c++;
  5562. }
  5563. sstr[c] = '\0';
  5564. retryIntervalInt = atoi(sstr);
  5565. }
  5566. //****************startTime*******************/
  5567. c = 0;
  5568. memset(sstr ,0, sizeof(sstr) );
  5569. loc = strstr(str, "startTime");
  5570. if(loc == NULL)
  5571. {
  5572. startTimeIsNULL = TRUE;
  5573. }
  5574. else
  5575. {
  5576. while (loc[3+strlen("startTime")+c] != '\"')
  5577. {
  5578. sstr[c] = loc[3+strlen("startTime")+c];
  5579. c++;
  5580. }
  5581. sstr[c] = '\0';
  5582. strcpy(startTimestr,sstr);
  5583. }
  5584. //****************stopTime*******************/
  5585. c = 0;
  5586. memset(sstr ,0, sizeof(sstr) );
  5587. loc = strstr(str, "stopTime");
  5588. if(loc == NULL)
  5589. {
  5590. stopTimeIsNULL = TRUE;
  5591. }
  5592. else
  5593. {
  5594. while (loc[3+strlen("stopTime")+c] != '\"')
  5595. {
  5596. sstr[c] = loc[3+strlen("stopTime")+c];
  5597. c++;
  5598. }
  5599. sstr[c] = '\0';
  5600. strcpy(stopTimestr,sstr);
  5601. }
  5602. memset(protocol, 0, sizeof(protocol));
  5603. memset(user, 0, sizeof(user) );
  5604. memset(password, 0, sizeof(password));
  5605. memset(host, 0, sizeof(host));
  5606. memset(path, 0, sizeof(path));
  5607. memset(ftppath, 0, sizeof(ftppath));
  5608. memset(host1, 0, sizeof(host1));
  5609. memset(path1, 0, sizeof(path1));
  5610. /*location: ftp://user:password@host:port/path*/
  5611. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5612. // protocol, user, password, host, &port, path);
  5613. #if 0 // remove for temporally
  5614. //zip files in /Storage
  5615. system("exec /root/logPackTools 'log' 6");
  5616. #endif
  5617. // system("exec /root/Module_WebService 'log' 6");
  5618. time_t rawtime;
  5619. struct tm * timeinfo;
  5620. //char buffer [128];
  5621. time (&rawtime);
  5622. //printf("%ld\n", rawtime);
  5623. timeinfo = localtime (&rawtime);
  5624. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5625. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5626. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5627. if((access(fnamePlusPath,F_OK))!=-1)
  5628. {
  5629. DEBUG_INFO("fnamePlusPath exist.\n");
  5630. }
  5631. else
  5632. {
  5633. DEBUG_INFO("fnamePlusPath not exist!\n");
  5634. goto end;
  5635. }
  5636. pch=strchr(locationstr,'@');
  5637. if(pch==NULL)
  5638. {
  5639. sscanf(locationstr,
  5640. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5641. protocol, host, &port, path);
  5642. strcpy(user,"anonymous");
  5643. strcpy(password,"");
  5644. }
  5645. else
  5646. {
  5647. DEBUG_INFO("pch=%s\n", pch);
  5648. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5649. protocol, user, password, host, &port, path);
  5650. }
  5651. if(strcmp(protocol,"ftp")!=0)
  5652. {
  5653. DEBUG_INFO("protocol is not ftp!\n");
  5654. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5655. goto end;
  5656. }
  5657. sscanf(host,"%[^/]%s",host1, path1);
  5658. sprintf(ftppath,"%s", path1);
  5659. DEBUG_INFO("protocol =%s\n",protocol);
  5660. DEBUG_INFO("user =%s\n",user);
  5661. DEBUG_INFO("password =%s\n",password);
  5662. DEBUG_INFO("host1 =%s\n",host1);
  5663. DEBUG_INFO("port =%d\n",port);
  5664. DEBUG_INFO("path1 =%s\n",path1);
  5665. DEBUG_INFO("ftppath=%s\n",ftppath);
  5666. int ftppathlen=strlen(ftppath);
  5667. int i=1;
  5668. char filenametemp[50];
  5669. while(i < ftppathlen)
  5670. {
  5671. int len=ftppathlen-i;
  5672. if(ftppath[len]== 47) // '/' ascll code: 47
  5673. {
  5674. DEBUG_INFO("find '/' all right\n");
  5675. break;
  5676. }
  5677. i=i+1;
  5678. }
  5679. memset(filenametemp, 0, sizeof(filenametemp));
  5680. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5681. filenametemp[i+1] = 0;
  5682. //httpDownLoadFile(host, ftppath, fname);
  5683. memset(ftpbuf, 0, sizeof(ftpbuf));
  5684. if(port == 0)
  5685. port = 21;
  5686. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5687. do{
  5688. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5689. sleep(retryIntervalInt);
  5690. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5691. if(!isSuccess)
  5692. {
  5693. //BulldogUtil.sleepMs(interval*1000);
  5694. DEBUG_INFO("Diagnostics fail.\n");
  5695. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5696. }
  5697. else
  5698. {
  5699. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5700. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5701. //isUpdateRequest = TRUE;
  5702. }
  5703. end:
  5704. // json_object_put(obj);
  5705. DiagnosticsStatusNotificationStatus = 0; //Idle
  5706. pthread_exit(NULL/*(void *) fname*/); // ?��?�執行�?
  5707. }
  5708. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5709. {
  5710. mtrace();
  5711. int result = FAIL;
  5712. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5713. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5714. {
  5715. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5716. localversion = -1;
  5717. }
  5718. else
  5719. {
  5720. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5721. OCPP_getListVerion();
  5722. }
  5723. //from db.OCPP_getListVerion
  5724. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5725. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5726. sendGetLocalListVersionConfirmation(uuid,"");
  5727. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5728. return result;
  5729. }
  5730. int handleRemoteStartRequest(char *uuid, char *payload)
  5731. {
  5732. mtrace();
  5733. int result = FAIL;
  5734. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5735. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5736. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5737. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5738. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5739. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5740. int chargingSchedulePeriodCount = 0;
  5741. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5742. int c = 0;
  5743. char *loc;
  5744. char comfirmstr[20]={0};
  5745. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5746. if(server_pending == TRUE)
  5747. {
  5748. return 0;
  5749. }
  5750. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5751. //**********connectorId****************/
  5752. c = 0;
  5753. memset(sstr ,0, sizeof(sstr) );
  5754. loc = strstr(payload, "connectorId");
  5755. if(loc == NULL)
  5756. {
  5757. connectorIdIsNULL = TRUE;
  5758. }
  5759. else
  5760. {
  5761. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5762. {
  5763. sstr[c] = loc[strlen("connectorId")+2+c];
  5764. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5765. c++;
  5766. }
  5767. sstr[c] = '\0';
  5768. connectorIdInt = atoi(sstr);
  5769. }
  5770. if(connectorIdIsNULL == TRUE) // need to discussion
  5771. {
  5772. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5773. goto end;
  5774. }
  5775. //****************idTag*******************/
  5776. c = 0;
  5777. memset(sstr ,0, sizeof(sstr) );
  5778. loc = strstr(payload, "idTag");
  5779. while (loc[3+strlen("idTag")+c] != '\"')
  5780. {
  5781. sstr[c] = loc[3+strlen("idTag")+c];
  5782. c++;
  5783. }
  5784. sstr[c] = '\0';
  5785. strcpy(idTagstr,sstr);
  5786. //****************chargingProfile*******************/
  5787. c = 0;
  5788. memset(sstr ,0, sizeof(sstr) );
  5789. loc = strstr(payload, "chargingProfile");
  5790. if(loc == NULL)
  5791. {
  5792. chargingProfileIsNULL = TRUE;
  5793. }
  5794. else
  5795. {
  5796. //****************chargingProfileId*******************/
  5797. c=0;
  5798. loc = strstr(payload, "chargingProfileId");
  5799. memset(sstr ,0, sizeof(sstr) );
  5800. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5801. {
  5802. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5803. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5804. c++;
  5805. }
  5806. sstr[c] = '\0';
  5807. chargingProfileIdInt = atoi(sstr);
  5808. //****************transactionId*******************/
  5809. loc = strstr(payload, "transactionId");
  5810. if(loc == NULL)
  5811. {
  5812. transactionIdIsNULL = TRUE;
  5813. }
  5814. else
  5815. {
  5816. c=0;
  5817. memset(sstr ,0, sizeof(sstr) );
  5818. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5819. {
  5820. sstr[c] = loc[strlen("transactionId")+2+c];
  5821. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5822. c++;
  5823. }
  5824. sstr[c] = '\0';
  5825. transactionIdInt = atoi(sstr);
  5826. }
  5827. //****************stackLevel*******************/
  5828. c=0;
  5829. loc = strstr(payload, "stackLevel");
  5830. memset(sstr ,0, sizeof(sstr) );
  5831. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5832. {
  5833. sstr[c] = loc[strlen("stackLevel")+2+c];
  5834. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5835. c++;
  5836. }
  5837. sstr[c] = '\0';
  5838. stackLevelInt = atoi(sstr);
  5839. //****************chargingProfilePurpose*******************/
  5840. c = 0;
  5841. memset(sstr ,0, sizeof(sstr) );
  5842. loc = strstr(payload, "chargingProfilePurpose");
  5843. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5844. {
  5845. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5846. c++;
  5847. }
  5848. sstr[c] = '\0';
  5849. strcpy(chargingProfilePurposestr,sstr);
  5850. //****************chargingProfileKind*******************/
  5851. c = 0;
  5852. memset(sstr ,0, sizeof(sstr) );
  5853. loc = strstr(payload, "chargingProfileKind");
  5854. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5855. {
  5856. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5857. c++;
  5858. }
  5859. sstr[c] = '\0';
  5860. strcpy(chargingProfileKindstr,sstr);
  5861. //****************recurrencyKind*******************/
  5862. loc = strstr(payload, "recurrencyKind");
  5863. if(loc == NULL)
  5864. {
  5865. recurrencyKindIsNULL = TRUE;
  5866. }
  5867. else
  5868. {
  5869. c = 0;
  5870. memset(sstr ,0, sizeof(sstr) );
  5871. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5872. {
  5873. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5874. c++;
  5875. }
  5876. sstr[c] = '\0';
  5877. strcpy(recurrencyKindstr,sstr);
  5878. }
  5879. //****************validFrom*******************/
  5880. loc = strstr(payload, "validFrom");
  5881. if(loc == NULL)
  5882. {
  5883. validFromIsNULL = TRUE;
  5884. }
  5885. else
  5886. {
  5887. c = 0;
  5888. memset(sstr ,0, sizeof(sstr) );
  5889. while (loc[3+strlen("validFrom")+c] != '\"')
  5890. {
  5891. sstr[c] = loc[3+strlen("validFrom")+c];
  5892. c++;
  5893. }
  5894. sstr[c] = '\0';
  5895. strcpy(validFromstr,sstr);
  5896. }
  5897. //****************validTo*******************/
  5898. loc = strstr(payload, "validTo");
  5899. if(loc == NULL)
  5900. {
  5901. validToIsNULL = TRUE;
  5902. }
  5903. else
  5904. {
  5905. c = 0;
  5906. memset(sstr ,0, sizeof(sstr) );
  5907. while (loc[3+strlen("validTo")+c] != '\"')
  5908. {
  5909. sstr[c] = loc[3+strlen("validTo")+c];
  5910. c++;
  5911. }
  5912. sstr[c] = '\0';
  5913. strcpy(validTostr,sstr);
  5914. }
  5915. //****************chargingSchedule*******************/
  5916. loc = strstr(payload, "chargingSchedule");
  5917. if(loc != NULL)
  5918. {
  5919. //****************duration*******************/
  5920. loc = strstr(payload, "duration");
  5921. if(loc == NULL)
  5922. {
  5923. durationIsNULL = TRUE;
  5924. }
  5925. else
  5926. {
  5927. c=0;
  5928. memset(sstr ,0, sizeof(sstr) );
  5929. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5930. {
  5931. sstr[c] = loc[strlen("duration")+2+c];
  5932. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5933. c++;
  5934. }
  5935. sstr[c] = '\0';
  5936. durationInt = atoi(sstr);
  5937. }
  5938. //****************startSchedule******************/
  5939. loc = strstr(payload, "startSchedule");
  5940. if(loc == NULL)
  5941. {
  5942. startScheduleIsNULL = TRUE;
  5943. }
  5944. else
  5945. {
  5946. c = 0;
  5947. memset(sstr ,0, sizeof(sstr) );
  5948. while (loc[3+strlen("startSchedule")+c] != '\"')
  5949. {
  5950. sstr[c] = loc[3+strlen("startSchedule")+c];
  5951. c++;
  5952. }
  5953. sstr[c] = '\0';
  5954. strcpy(startSchedulestr,sstr);
  5955. }
  5956. //****************chargingRateUnit*******************/
  5957. c = 0;
  5958. memset(sstr ,0, sizeof(sstr) );
  5959. loc = strstr(payload, "chargingRateUnit");
  5960. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5961. {
  5962. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5963. c++;
  5964. }
  5965. sstr[c] = '\0';
  5966. strcpy(chargingRateUnitstr,sstr);
  5967. //****************minChargingRate*******************/
  5968. loc = strstr(payload, "minChargingRate");
  5969. if(loc == NULL)
  5970. {
  5971. minChargingRateIsNULL = TRUE;
  5972. }
  5973. else
  5974. {
  5975. c=0;
  5976. memset(sstr ,0, sizeof(sstr) );
  5977. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5978. {
  5979. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5980. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5981. c++;
  5982. }
  5983. sstr[c] = '\0';
  5984. minChargingRateflaot = atof(sstr);
  5985. }
  5986. //****************chargingSchedulePeriod count*******************/
  5987. int what_len = strlen("startPeriod");
  5988. char *where = payload;
  5989. while ((where = strstr(where, "startPeriod"))) {
  5990. where += what_len;
  5991. chargingSchedulePeriodCount++;
  5992. }
  5993. where = payload;
  5994. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5995. {
  5996. //****************startPeriod*******************/
  5997. c=0;
  5998. loc = strstr(where, "startPeriod");
  5999. memset(sstr ,0, sizeof(sstr) );
  6000. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6001. {
  6002. sstr[c] = loc[strlen("startPeriod")+2+c];
  6003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6004. c++;
  6005. }
  6006. sstr[c] = '\0';
  6007. startPeriodInt[periodNums] = atoi(sstr);
  6008. //****************limit*******************/
  6009. c=0;
  6010. loc = strstr(where, "limit");
  6011. memset(sstr ,0, sizeof(sstr) );
  6012. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6013. {
  6014. sstr[c] = loc[strlen("limit")+2+c];
  6015. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6016. c++;
  6017. }
  6018. sstr[c] = '\0';
  6019. limitflaot[periodNums] = atof(sstr);
  6020. //****************numberPhases*******************/
  6021. loc = strstr(where, "numberPhases");
  6022. if(loc == NULL)
  6023. {
  6024. numberPhasesIsNULL = TRUE;
  6025. }
  6026. else
  6027. {
  6028. c=0;
  6029. memset(sstr ,0, sizeof(sstr) );
  6030. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6031. {
  6032. sstr[c] = loc[strlen("numberPhases")+2+c];
  6033. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6034. c++;
  6035. }
  6036. sstr[c] = '\0';
  6037. numberPhasesInt[periodNums] = atoi(sstr);
  6038. }
  6039. where = loc;
  6040. }
  6041. }
  6042. }
  6043. /*
  6044. enum _SYSTEM_STATUS
  6045. {
  6046. S_BOOTING = 0,
  6047. S_IDLE, = 1
  6048. S_AUTHORIZING, =2
  6049. S_REASSIGN_CHECK, =3
  6050. S_REASSIGN, =4
  6051. S_PRECHARGE, =5
  6052. S_PREPARING_FOR_EV, =6
  6053. S_PREPARING_FOR_EVSE, =7
  6054. S_CHARGING, =8
  6055. S_TERMINATING, =9
  6056. S_COMPLETE, =10
  6057. S_ALARM, =11
  6058. S_FAULT =12
  6059. }
  6060. */
  6061. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6062. {
  6063. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6064. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6065. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6066. //check Transaction active
  6067. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6068. {
  6069. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6070. {
  6071. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6072. {
  6073. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6074. {
  6075. //Reserved
  6076. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6077. }
  6078. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6079. {
  6080. //Reserved
  6081. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6082. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6083. goto end;
  6084. }
  6085. else
  6086. {
  6087. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6088. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6089. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6090. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6091. {
  6092. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6093. goto end;
  6094. }
  6095. }//END FOR ELSE
  6096. }
  6097. }// END FOR CHAdeMO_QUANTITY
  6098. for (int index = 0; index < CCS_QUANTITY; index++)
  6099. {
  6100. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6101. {
  6102. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6103. {
  6104. //Reserved
  6105. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6106. }
  6107. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6108. {
  6109. //Reserved
  6110. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6111. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6112. goto end;
  6113. }
  6114. else
  6115. {
  6116. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6117. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6118. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6119. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6120. {
  6121. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6122. goto end;
  6123. }
  6124. }// END FOR ELSE
  6125. }
  6126. }// END FOR CCS_QUANTITY
  6127. for (int index = 0; index < GB_QUANTITY; index++)
  6128. {
  6129. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6130. {
  6131. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6132. {
  6133. //Reserved
  6134. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6135. }
  6136. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6137. {
  6138. //Reserved
  6139. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6140. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6141. goto end;
  6142. }
  6143. else
  6144. {
  6145. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6146. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6147. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6148. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6149. {
  6150. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6151. goto end;
  6152. }
  6153. }// END FOR ELSE
  6154. }
  6155. } // END FOR GB_QUANTITY
  6156. }
  6157. else
  6158. {
  6159. for (int index = 0; index < AC_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6162. {
  6163. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6164. {
  6165. //Reserved
  6166. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6167. }
  6168. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6169. {
  6170. //Reserved
  6171. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6172. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6173. goto end;
  6174. }
  6175. else
  6176. {
  6177. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6178. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6179. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6180. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6181. {
  6182. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6183. goto end;
  6184. }
  6185. }//END FOR ELSE
  6186. }
  6187. }// END FOR AC_QUANTITY
  6188. }
  6189. if(chargingProfileIsNULL == FALSE)
  6190. {
  6191. //ChargingProfile
  6192. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6193. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6194. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6195. if(recurrencyKindIsNULL == FALSE) //OPTION
  6196. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6197. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6198. if(transactionIdIsNULL == FALSE) // OPTION
  6199. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6200. if(validFromIsNULL == FALSE) // OPTION
  6201. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6202. if(validToIsNULL == FALSE) //OPTION
  6203. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6204. //ChargingSchedule
  6205. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6206. if(durationIsNULL == FALSE) //OPTION
  6207. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6208. if(minChargingRateIsNULL == FALSE) //OPTION
  6209. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6210. if(startScheduleIsNULL == FALSE) //OPTION
  6211. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6212. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6213. {
  6214. //ChargingSchedulePeriod
  6215. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6216. if(numberPhasesIsNULL == FALSE)
  6217. {
  6218. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6219. }
  6220. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6221. }
  6222. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6223. {
  6224. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6225. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6226. }
  6227. else
  6228. {
  6229. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6230. }
  6231. }
  6232. else
  6233. {
  6234. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6235. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6236. }
  6237. }
  6238. else
  6239. {
  6240. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6241. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6242. }
  6243. end:
  6244. if(connectorIdIsNULL == FALSE)
  6245. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6246. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6247. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6248. //OCPP send RemoteStartConfirmation by first.
  6249. sendRemoteStartConfirmation(uuid, comfirmstr);
  6250. return result;
  6251. }
  6252. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6253. {
  6254. mtrace();
  6255. int result = FAIL;
  6256. int match = FALSE;
  6257. int GunNO = 0;
  6258. int transactionIdInt=0;
  6259. int transactionIdIsNULL= FALSE;
  6260. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6261. int c = 0;
  6262. char *loc;
  6263. char comfirmstr[20];
  6264. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6265. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6266. if(server_pending == TRUE)
  6267. {
  6268. return 0;
  6269. }
  6270. c=0;
  6271. loc = strstr(payload, "transactionId");
  6272. if(loc == NULL)
  6273. {
  6274. transactionIdIsNULL= TRUE;
  6275. }
  6276. else
  6277. {
  6278. memset(sstr ,0, sizeof(sstr) );
  6279. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6280. {
  6281. sstr[c] = loc[strlen("transactionId")+2+c];
  6282. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6283. c++;
  6284. }
  6285. sstr[c] = '\0';
  6286. transactionIdInt = atoi(sstr);
  6287. }
  6288. if(transactionIdIsNULL == FALSE)
  6289. {
  6290. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6291. {
  6292. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6293. {
  6294. //check Transaction active
  6295. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6296. {
  6297. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6298. {
  6299. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6300. {
  6301. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6302. {
  6303. match = TRUE;
  6304. GunNO = gun_index;
  6305. }
  6306. }
  6307. }// END FOR CHAdeMO_QUANTITY
  6308. for (int index = 0; index < CCS_QUANTITY; index++)
  6309. {
  6310. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6311. {
  6312. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6313. {
  6314. match = TRUE;
  6315. GunNO = gun_index;
  6316. }
  6317. }
  6318. }// END FOR CCS_QUANTITY
  6319. for (int index = 0; index < GB_QUANTITY; index++)
  6320. {
  6321. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6322. {
  6323. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6324. {
  6325. match = TRUE;
  6326. GunNO = gun_index;
  6327. }
  6328. }
  6329. }// END FOR GB_QUANTITY
  6330. }
  6331. else
  6332. {
  6333. for (int index = 0; index < AC_QUANTITY; index++)
  6334. {
  6335. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6336. {
  6337. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6338. {
  6339. match = TRUE;
  6340. GunNO = gun_index;
  6341. }
  6342. }
  6343. }// END FOR CHAdeMO_QUANTITY
  6344. }// END FOR AC ELSE
  6345. }// CHECK IF ResponseTransactionId == transactionIdInt
  6346. }//END FOR
  6347. if( match == TRUE)
  6348. {
  6349. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6350. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6351. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6352. }
  6353. else
  6354. {
  6355. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6356. }
  6357. }
  6358. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6359. return result;
  6360. }
  6361. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6362. {
  6363. mtrace();
  6364. int result = FAIL;
  6365. int connectorIdInt=0, reservationIdInt=0;
  6366. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6367. char comfirmstr[20]={0};
  6368. char sstr[180]={ 0 };
  6369. int c = 0;
  6370. char *loc;
  6371. //char *ptr;
  6372. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6373. //***(1)connectorId ****/
  6374. c=0;
  6375. loc = strstr(payload, "connectorId");
  6376. memset(sstr ,0, sizeof(sstr) );
  6377. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6378. {
  6379. sstr[c] = loc[strlen("connectorId")+2+c];
  6380. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6381. c++;
  6382. }
  6383. sstr[c] = '\0';
  6384. connectorIdInt = atoi(sstr);
  6385. //***(2)expiryDate ****/
  6386. loc = strstr(payload, "expiryDate");
  6387. memset(sstr ,0, sizeof(sstr) );
  6388. c = 0;
  6389. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6390. {
  6391. sstr[c] = loc[3+strlen("expiryDate")+c];
  6392. c++;
  6393. }
  6394. sstr[c] = '\0';
  6395. strcpy(expiryDatestr, sstr);
  6396. //***(3)idTag ****/
  6397. loc = strstr(payload, "idTag");
  6398. memset(sstr ,0, sizeof(sstr) );
  6399. c = 0;
  6400. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6401. {
  6402. sstr[c] = loc[3+strlen("idTag")+c];
  6403. c++;
  6404. }
  6405. sstr[c] = '\0';
  6406. strcpy(idTagstr, sstr);
  6407. //***(4)parentIdTag ****/
  6408. loc = strstr(payload, "parentIdTag");
  6409. memset(sstr ,0, sizeof(sstr) );
  6410. c = 0;
  6411. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6412. {
  6413. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6414. c++;
  6415. }
  6416. sstr[c] = '\0';
  6417. strcpy(parentIdTagstr, sstr);
  6418. //***(5)reservationId ****/
  6419. c=0;
  6420. loc = strstr(payload, "reservationId");
  6421. memset(sstr ,0, sizeof(sstr) );
  6422. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6423. {
  6424. sstr[c] = loc[strlen("reservationId")+2+c];
  6425. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6426. c++;
  6427. }
  6428. sstr[c] = '\0';
  6429. reservationIdInt = atoi(sstr);
  6430. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6431. /*
  6432. enum _SYSTEM_STATUS
  6433. {
  6434. S_BOOTING = 0,
  6435. S_IDLE, = 1
  6436. S_AUTHORIZING, =2
  6437. S_REASSIGN_CHECK, =3
  6438. S_REASSIGN, =4
  6439. S_PRECHARGE, =5
  6440. S_PREPARING_FOR_EV, =6
  6441. S_PREPARING_FOR_EVSE, =7
  6442. S_CHARGING, =8
  6443. S_TERMINATING, =9
  6444. S_COMPLETE, =10
  6445. S_ALARM, =11
  6446. S_FAULT =12
  6447. }
  6448. */
  6449. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6450. {
  6451. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6452. goto end;
  6453. }
  6454. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6455. {
  6456. //check Transaction active
  6457. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6458. {
  6459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6460. {
  6461. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6462. {
  6463. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6464. {
  6465. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6466. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6467. {
  6468. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6469. {
  6470. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6472. }
  6473. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6474. {
  6475. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6476. }
  6477. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6478. {
  6479. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6480. }
  6481. else
  6482. {
  6483. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6484. }
  6485. }
  6486. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6487. {
  6488. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6489. }
  6490. }
  6491. else
  6492. {
  6493. //replace reservation
  6494. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6496. }
  6497. }
  6498. } // END FOR CHAdeMO_QUANTITY
  6499. for (int index = 0; index < CCS_QUANTITY; index++)
  6500. {
  6501. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6502. {
  6503. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6504. {
  6505. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6506. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6507. {
  6508. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6509. {
  6510. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6511. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6512. }
  6513. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6514. {
  6515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6516. }
  6517. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6518. {
  6519. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6520. }
  6521. else
  6522. {
  6523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6524. }
  6525. }
  6526. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6527. {
  6528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6529. }
  6530. }
  6531. else
  6532. {
  6533. //replace reservation
  6534. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6536. }
  6537. }
  6538. } // END FOR CCS_QUANTITY
  6539. for (int index = 0; index < GB_QUANTITY; index++)
  6540. {
  6541. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6542. {
  6543. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6544. {
  6545. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6546. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6547. {
  6548. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6549. {
  6550. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6552. }
  6553. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6554. {
  6555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6556. }
  6557. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6558. {
  6559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6560. }
  6561. else
  6562. {
  6563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6564. }
  6565. }
  6566. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6567. {
  6568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6569. }
  6570. }
  6571. else
  6572. {
  6573. //replace reservation
  6574. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6576. }
  6577. }
  6578. }// END FOR GB_QUANTITY
  6579. }
  6580. else
  6581. {
  6582. for (int index = 0; index < AC_QUANTITY; index++)
  6583. {
  6584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6585. {
  6586. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6587. {
  6588. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6589. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6590. {
  6591. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6592. {
  6593. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6595. }
  6596. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6597. {
  6598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6599. }
  6600. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6601. {
  6602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6603. }
  6604. else
  6605. {
  6606. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6607. }
  6608. }
  6609. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6610. {
  6611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6612. }
  6613. }
  6614. else
  6615. {
  6616. //replace reservation
  6617. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6619. }
  6620. }
  6621. } // END FOR AC_QUANTITY
  6622. }//END FOR AC ELSE
  6623. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6624. }
  6625. else if(connectorIdInt == 0)
  6626. {
  6627. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6628. {
  6629. //check Transaction active
  6630. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6631. {
  6632. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6633. {
  6634. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6635. {
  6636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6637. goto end;
  6638. }
  6639. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6640. {
  6641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6642. goto end;
  6643. }
  6644. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6645. {
  6646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6647. goto end;
  6648. }
  6649. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6650. {
  6651. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6652. goto end;
  6653. }
  6654. }
  6655. }// END FOR CHAdeMO_QUANTITY
  6656. for (int index = 0; index < CCS_QUANTITY; index++)
  6657. {
  6658. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6659. {
  6660. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6661. {
  6662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6663. }
  6664. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6665. {
  6666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6667. }
  6668. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6669. {
  6670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6671. }
  6672. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6673. {
  6674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6675. }
  6676. }
  6677. } // END FOR CCS_QUANTITY
  6678. for (int index = 0; index < GB_QUANTITY; index++)
  6679. {
  6680. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6681. {
  6682. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6683. {
  6684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6685. }
  6686. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6687. {
  6688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6689. }
  6690. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6691. {
  6692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6693. }
  6694. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6695. {
  6696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6697. }
  6698. }
  6699. } // END FOR GB_QUANTITY
  6700. }
  6701. else
  6702. {
  6703. for (int index = 0; index < AC_QUANTITY; index++)
  6704. {
  6705. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6706. {
  6707. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6708. {
  6709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6710. goto end;
  6711. }
  6712. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6713. {
  6714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6715. goto end;
  6716. }
  6717. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6718. {
  6719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6720. goto end;
  6721. }
  6722. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6723. {
  6724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6725. goto end;
  6726. }
  6727. }
  6728. }// END FOR AC_QUANTITY
  6729. }
  6730. //The connectorId is 0
  6731. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6733. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6734. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6735. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6736. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6737. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6738. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6739. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6740. result = TRUE;
  6741. return result;
  6742. }
  6743. else
  6744. {
  6745. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6746. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6747. }
  6748. if(strcmp(comfirmstr,"Accepted") == 0)
  6749. {
  6750. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6751. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6752. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6753. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6754. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6755. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6756. result = TRUE;
  6757. return result;
  6758. }
  6759. end:
  6760. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6761. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6762. return result;
  6763. }
  6764. int handleResetRequest(char *uuid, char *payload)
  6765. {
  6766. mtrace();
  6767. int result = FAIL;
  6768. char sstr[10]={0};
  6769. char typestr[10]={0};
  6770. char comfirmstr[20]={0};
  6771. int c = 0;
  6772. char *loc;
  6773. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6774. DEBUG_INFO("handleResetRequest ...\n");
  6775. loc = strstr(payload, "type");
  6776. memset(sstr ,0, sizeof(sstr) );
  6777. c = 0;
  6778. while (loc[3+strlen("type")+c] != '\"')
  6779. {
  6780. sstr[c] = loc[3+strlen("type")+c];
  6781. c++;
  6782. }
  6783. sstr[c] = '\0';
  6784. strcpy(typestr,sstr);
  6785. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6786. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6787. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6788. {
  6789. //check Transaction active
  6790. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6791. {
  6792. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6793. {
  6794. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6795. {
  6796. //0: unplug, 1: Plug-in
  6797. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6798. }
  6799. }
  6800. for (int index = 0; index < CCS_QUANTITY; index++)
  6801. {
  6802. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6803. {
  6804. //0: unplug, 1: Plug-in
  6805. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6806. }
  6807. }
  6808. for (int index = 0; index < GB_QUANTITY; index++)
  6809. {
  6810. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6811. {
  6812. //0: unplug, 1: Plug-in
  6813. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6814. }
  6815. }
  6816. }
  6817. else
  6818. {
  6819. for (int index = 0; index < AC_QUANTITY; index++)
  6820. {
  6821. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6822. {
  6823. //0: unplug, 1: Plug-in
  6824. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6825. }
  6826. }
  6827. }// END FOR AC ELSE
  6828. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6829. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6830. result = TRUE;
  6831. return result;
  6832. }
  6833. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6834. {
  6835. //check Transaction active
  6836. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6837. {
  6838. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6839. {
  6840. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6841. {
  6842. //0: unplug, 1: Plug-in
  6843. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6844. }
  6845. }
  6846. for (int index = 0; index < CCS_QUANTITY; index++)
  6847. {
  6848. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6849. {
  6850. //0: unplug, 1: Plug-in
  6851. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6852. }
  6853. }
  6854. for (int index = 0; index < GB_QUANTITY; index++)
  6855. {
  6856. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6857. {
  6858. //0: unplug, 1: Plug-in
  6859. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6860. }
  6861. }
  6862. }
  6863. else
  6864. {
  6865. for (int index = 0; index < AC_QUANTITY; index++)
  6866. {
  6867. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6868. {
  6869. //0: unplug, 1: Plug-in
  6870. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6871. }
  6872. }
  6873. }// END FOR AC ELSE
  6874. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6875. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6876. result = TRUE;
  6877. return result;
  6878. }
  6879. else
  6880. {
  6881. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6882. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6883. goto errorend;
  6884. }
  6885. errorend:
  6886. sendResetConfirmation(uuid, comfirmstr);
  6887. return result;
  6888. }
  6889. int handleSendLocalListRequest(char *uuid, char *payload)
  6890. {
  6891. mtrace();
  6892. int result = FAIL;
  6893. int listVersionInt;
  6894. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6895. char listsearch[]="listVersion";
  6896. char updateTypesearch[]="updateType";
  6897. char localAuthorizationListsearch[]="localAuthorizationList";
  6898. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6899. char CardList[500][160]={0};
  6900. char updateTypestr[15]={0};
  6901. char idTagstr[20]={0};
  6902. char parentIdTag[20]={0};
  6903. char expiryDate[30]={0};
  6904. char idTagstatus[16]={0};
  6905. int c = 0;
  6906. int i = 0;
  6907. char *delim1 = "}";
  6908. char * pch;
  6909. char *loc;
  6910. //char *ptr;
  6911. char comfirmstr[20];
  6912. //int n_localAuthorizations = 0;
  6913. int checkState_Faulted = FALSE;
  6914. DEBUG_INFO("handleSendLocalListRequest\n");
  6915. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6916. {
  6917. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6918. goto end;
  6919. }
  6920. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6921. {
  6922. //check Charge Point state
  6923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6924. {
  6925. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6926. {
  6927. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6928. }
  6929. }
  6930. for (int index = 0; index < CCS_QUANTITY; index++)
  6931. {
  6932. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6933. {
  6934. checkState_Faulted = TRUE; //OCPP Status
  6935. }
  6936. }
  6937. for (int index = 0; index < GB_QUANTITY; index++)
  6938. {
  6939. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6940. {
  6941. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6942. }
  6943. }
  6944. }
  6945. else
  6946. {
  6947. //check Charge Point state
  6948. for (int index = 0; index < AC_QUANTITY; index++)
  6949. {
  6950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6951. {
  6952. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6953. }
  6954. }
  6955. }// END FOR AC ELSE
  6956. if(checkState_Faulted == TRUE)
  6957. {
  6958. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6959. goto end;
  6960. }
  6961. //listVersion
  6962. c = 0;
  6963. loc = strstr(payload, listsearch);
  6964. while (loc[strlen("listVersion")+2+c] != ',')
  6965. {
  6966. sstr[c] = loc[strlen("listVersion")+2+c];
  6967. c++;
  6968. }
  6969. sstr[c] = '\0';
  6970. listVersionInt = atoi(sstr);
  6971. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6972. //updateType
  6973. loc = strstr(payload, updateTypesearch);
  6974. c = 0;
  6975. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6976. {
  6977. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6978. c++;
  6979. }
  6980. sstr[c] = '\0';
  6981. strcpy(updateTypestr, sstr);
  6982. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6983. //localAuthorizationList
  6984. memset(sstr ,0, sizeof(sstr) );
  6985. loc = strstr(payload, localAuthorizationListsearch);
  6986. if(loc != NULL) // localAuthorizationList is not NULL
  6987. {
  6988. //Check UpdateType
  6989. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6990. {
  6991. //Local list full update
  6992. printf("Local list full update.\n");
  6993. OCPP_cleanLocalList();
  6994. }
  6995. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6996. {
  6997. //Local list different update
  6998. printf("Local list different update.\n");
  6999. OCPP_getListVerion();
  7000. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7001. {
  7002. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7003. goto end;
  7004. }
  7005. }
  7006. else
  7007. {
  7008. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7009. goto end;
  7010. }
  7011. c = 0;
  7012. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7013. {
  7014. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7015. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7016. c++;
  7017. }
  7018. sstr[c] = '\0';
  7019. //parsing strings to words
  7020. i = 0;
  7021. pch = strtok(sstr,delim1);
  7022. while (pch != NULL)
  7023. {
  7024. strcpy(CardList[i], pch);
  7025. pch = strtok (NULL, delim1);
  7026. i = i + 1;
  7027. }
  7028. //local Authorizations List Numbers
  7029. //n_localAuthorizations = i;
  7030. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7031. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7032. c= 0;
  7033. while(c < i)
  7034. {
  7035. //Search "IdToken"
  7036. memset(sstr ,0, sizeof(sstr) );
  7037. loc = strstr(CardList[c], "idTag");
  7038. int j = 0;
  7039. while (loc[3+strlen("idTag")+j] != '\"')
  7040. {
  7041. sstr[j] = loc[3+strlen("idTag")+j];
  7042. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7043. j++;
  7044. }
  7045. sstr[j] = '\0';
  7046. strcpy(idTagstr, sstr);
  7047. //Search "expiryDate"
  7048. memset(sstr ,0, sizeof(sstr) );
  7049. loc = strstr(CardList[c], "expiryDate");
  7050. j = 0;
  7051. while (loc[3+strlen("expiryDate")+j] != '\"')
  7052. {
  7053. sstr[j] = loc[3+strlen("expiryDate")+j];
  7054. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7055. j++;
  7056. }
  7057. sstr[j] = '\0';
  7058. strcpy(expiryDate, sstr);
  7059. //Search "parentIdTag"
  7060. memset(sstr ,0, sizeof(sstr) );
  7061. loc = strstr(CardList[c], "parentIdTag");
  7062. j = 0;
  7063. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7064. {
  7065. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7066. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7067. j++;
  7068. }
  7069. sstr[j] = '\0';
  7070. strcpy(parentIdTag, sstr);
  7071. //Search "status"
  7072. memset(sstr ,0, sizeof(sstr) );
  7073. loc = strstr(CardList[c], "status");
  7074. j = 0;
  7075. while (loc[3+strlen("status")+j] != '\"')
  7076. {
  7077. sstr[j] = loc[3+strlen("status")+j];
  7078. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7079. j++;
  7080. }
  7081. sstr[j] = '\0';
  7082. strcpy(idTagstatus, sstr);
  7083. OCPP_getIdTag(idTagstr);
  7084. //OCPP_getIdTag("test"); For Test
  7085. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7086. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7087. {
  7088. //Local list full update
  7089. DEBUG_INFO("Local list full update.\n");
  7090. // update list
  7091. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7092. OCPP_get_TableAuthlocalAllData();
  7093. }
  7094. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7095. {
  7096. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7097. {
  7098. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7099. }
  7100. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7101. {
  7102. OCPP_deleteIdTag(idTagstr);
  7103. }
  7104. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7105. {
  7106. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7107. }
  7108. }
  7109. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7110. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7111. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7112. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7113. c++;
  7114. }
  7115. }
  7116. else
  7117. {
  7118. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7119. {
  7120. //Local list different update
  7121. DEBUG_INFO("Local list different update.\n");
  7122. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7123. goto end;
  7124. }
  7125. }
  7126. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7127. end:
  7128. sendSendLocalListConfirmation(uuid, comfirmstr);
  7129. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7130. #if 0
  7131. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7132. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7133. #endif
  7134. return result;
  7135. }
  7136. /*
  7137. enum _SYSTEM_STATUS
  7138. {
  7139. S_BOOTING = 0,
  7140. S_IDLE, =1
  7141. S_AUTHORIZING, =2
  7142. S_REASSIGN_CHECK, =3
  7143. S_REASSIGN, =4
  7144. S_PRECHARGE, =5
  7145. S_PREPARING_FOR_EV, =6
  7146. S_PREPARING_FOR_EVSE, =7
  7147. S_CHARGING, =8
  7148. S_TERMINATING, =9
  7149. S_COMPLETE, =10
  7150. S_ALARM, =11
  7151. S_FAULT =12
  7152. };
  7153. */
  7154. #define MAX 200
  7155. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7156. {
  7157. mtrace();
  7158. int result = FAIL;
  7159. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7160. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7161. char chargingProfilePurposeStr[30]={0};
  7162. char chargingProfileKindStr[16]={0};
  7163. char recurrencyKindStr[10]={0};
  7164. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7165. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7166. int chargingSchedulePeriodCount = 0;
  7167. //int updateflag = FALSE;
  7168. char comfirmstr[20]={0};
  7169. int meet= FALSE;
  7170. char sstr[10]={0};
  7171. int c = 0;
  7172. char *loc;
  7173. FILE *fptr1;//, *fptr2;
  7174. //int lno=0;//, linectr = 0;
  7175. //int modifyflag = FALSE;
  7176. char filename[MAX]={0};
  7177. char tempfile[] = "../Storage/OCPP/temp.json";
  7178. int resultRename=0;
  7179. char rmFileCmd[50]={0};
  7180. char tempchargingProfilePurposeStr[30]={0};
  7181. //[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}}}]
  7182. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7183. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7184. //*********************connectorId***************************/
  7185. loc = strstr(payload, "connectorId");
  7186. c = 0;
  7187. memset(sstr ,0, sizeof(sstr) );
  7188. while (loc[strlen("connectorId")+2+c] != ',')
  7189. {
  7190. sstr[c] = loc[strlen("connectorId")+2+c];
  7191. c++;
  7192. }
  7193. sstr[c] = '\0';
  7194. connectorIdInt = atoi(sstr);
  7195. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7196. {
  7197. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7198. }
  7199. else
  7200. {
  7201. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7202. }
  7203. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7204. //*********************chargingProfileId***************************/
  7205. loc = strstr(payload, "chargingProfileId");
  7206. c = 0;
  7207. memset(sstr ,0, sizeof(sstr) );
  7208. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7209. {
  7210. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7211. c++;
  7212. }
  7213. sstr[c] = '\0';
  7214. chargingProfileIdInt = atoi(sstr);
  7215. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7216. {
  7217. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7218. }
  7219. else
  7220. {
  7221. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7222. }
  7223. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7224. //*********************transactionId***************************/
  7225. loc = strstr(payload, "transactionId");
  7226. if(loc != NULL)
  7227. {
  7228. c = 0;
  7229. memset(sstr ,0, sizeof(sstr) );
  7230. while (loc[strlen("transactionId")+2+c] != ',')
  7231. {
  7232. sstr[c] = loc[strlen("transactionId")+2+c];
  7233. c++;
  7234. }
  7235. sstr[c] = '\0';
  7236. transactionIdInt = atoi(sstr);
  7237. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7238. {
  7239. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7240. }
  7241. else
  7242. {
  7243. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7244. }
  7245. }
  7246. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7247. //*********************stackLevel***************************/
  7248. loc = strstr(payload, "stackLevel");
  7249. c = 0;
  7250. memset(sstr ,0, sizeof(sstr) );
  7251. while (loc[strlen("stackLevel")+2+c] != ',')
  7252. {
  7253. sstr[c] = loc[strlen("stackLevel")+2+c];
  7254. c++;
  7255. }
  7256. sstr[c] = '\0';
  7257. stackLevelInt = atoi(sstr);
  7258. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7259. {
  7260. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7261. }
  7262. else
  7263. {
  7264. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7265. }
  7266. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7267. //*********************chargingProfilePurpose***************************/
  7268. loc = strstr(payload, "chargingProfilePurpose");
  7269. c = 0;
  7270. memset(sstr ,0, sizeof(sstr) );
  7271. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7272. {
  7273. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7274. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7275. c++;
  7276. }
  7277. sstr[c] = '\0';
  7278. strcpy(chargingProfilePurposeStr,sstr);
  7279. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7280. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7281. {
  7282. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7283. }
  7284. else
  7285. {
  7286. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7287. }
  7288. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7289. //*********************chargingProfileKind***************************/
  7290. loc = strstr(payload, "chargingProfileKind");
  7291. c = 0;
  7292. memset(sstr ,0, sizeof(sstr) );
  7293. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7294. {
  7295. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7296. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7297. c++;
  7298. }
  7299. sstr[c] = '\0';
  7300. strcpy(chargingProfileKindStr,sstr);
  7301. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7302. {
  7303. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7304. }
  7305. else
  7306. {
  7307. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7308. }
  7309. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7310. //*********************recurrencyKind***************************/
  7311. loc = strstr(payload, "recurrencyKind");
  7312. if(loc != NULL)
  7313. {
  7314. c = 0;
  7315. memset(sstr ,0, sizeof(sstr) );
  7316. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7317. {
  7318. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7319. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7320. c++;
  7321. }
  7322. sstr[c] = '\0';
  7323. strcpy(recurrencyKindStr,sstr);
  7324. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7325. {
  7326. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7327. }
  7328. else
  7329. {
  7330. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7331. }
  7332. }
  7333. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7334. //*********************validFrom***************************/
  7335. loc = strstr(payload, "validFrom");
  7336. if(loc != NULL)
  7337. {
  7338. c = 0;
  7339. memset(sstr ,0, sizeof(sstr) );
  7340. while (loc[3+strlen("validFrom")+c] != '\"')
  7341. {
  7342. sstr[c] = loc[3+strlen("validFrom")+c];
  7343. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7344. c++;
  7345. }
  7346. sstr[c] = '\0';
  7347. strcpy(validFromStr,sstr);
  7348. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7349. {
  7350. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7351. }
  7352. else
  7353. {
  7354. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7355. }
  7356. }
  7357. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7358. //*********************validTo***************************/
  7359. loc = strstr(payload, "validTo");
  7360. if(loc != NULL)
  7361. {
  7362. c = 0;
  7363. memset(sstr ,0, sizeof(sstr) );
  7364. while (loc[3+strlen("validTo")+c] != '\"')
  7365. {
  7366. sstr[c] = loc[3+strlen("validTo")+c];
  7367. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7368. c++;
  7369. }
  7370. sstr[c] = '\0';
  7371. strcpy(validToStr,sstr);
  7372. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7373. {
  7374. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7375. }
  7376. else
  7377. {
  7378. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7379. }
  7380. }
  7381. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7382. //*********************duration***************************/
  7383. loc = strstr(payload, "duration");
  7384. if(loc != NULL)
  7385. {
  7386. c = 0;
  7387. memset(sstr ,0, sizeof(sstr) );
  7388. while (loc[strlen("duration")+2+c] != ',')
  7389. {
  7390. sstr[c] = loc[strlen("duration")+2+c];
  7391. c++;
  7392. }
  7393. sstr[c] = '\0';
  7394. durationInt = atoi(sstr);
  7395. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7396. {
  7397. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7398. }
  7399. else
  7400. {
  7401. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7402. }
  7403. }
  7404. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7405. //*********************startSchedule***************************/
  7406. loc = strstr(payload, "startSchedule");
  7407. if(loc != NULL)
  7408. {
  7409. c = 0;
  7410. memset(sstr ,0, sizeof(sstr) );
  7411. while (loc[3+strlen("startSchedule")+c] != '\"')
  7412. {
  7413. sstr[c] = loc[3+strlen("startSchedule")+c];
  7414. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7415. c++;
  7416. }
  7417. sstr[c] = '\0';
  7418. strcpy(startScheduleStr,sstr);
  7419. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7420. {
  7421. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7422. }
  7423. else
  7424. {
  7425. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7426. }
  7427. }
  7428. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7429. //*********************chargingRateUnit***************************/
  7430. loc = strstr(payload, "chargingRateUnit");
  7431. if(loc != NULL)
  7432. {
  7433. c = 0;
  7434. memset(sstr ,0, sizeof(sstr) );
  7435. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7436. {
  7437. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7438. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7439. c++;
  7440. }
  7441. sstr[c] = '\0';
  7442. strcpy(chargingRateUnitStr,sstr);
  7443. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7444. {
  7445. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7446. }
  7447. else
  7448. {
  7449. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7450. }
  7451. }
  7452. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7453. //****************chargingSchedulePeriod count start*******************/
  7454. int what_len = strlen("startPeriod");
  7455. char *where = payload;
  7456. if (what_len)
  7457. while ((where = strstr(where, "startPeriod"))) {
  7458. where += what_len;
  7459. chargingSchedulePeriodCount++;
  7460. }
  7461. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7462. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7463. where = payload;
  7464. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7465. {
  7466. //****************startPeriod*******************/
  7467. c=0;
  7468. loc = strstr(where, "startPeriod");
  7469. memset(sstr ,0, sizeof(sstr) );
  7470. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7471. {
  7472. sstr[c] = loc[strlen("startPeriod")+2+c];
  7473. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7474. c++;
  7475. }
  7476. sstr[c] = '\0';
  7477. startPeriodInt[periodNums] = atoi(sstr);
  7478. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7479. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7480. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7481. {
  7482. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7483. }
  7484. else
  7485. {
  7486. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7487. }
  7488. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7489. //****************limit*******************/
  7490. c=0;
  7491. loc = strstr(where, "limit");
  7492. memset(sstr ,0, sizeof(sstr) );
  7493. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7494. {
  7495. sstr[c] = loc[strlen("limit")+2+c];
  7496. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7497. c++;
  7498. }
  7499. sstr[c] = '\0';
  7500. limitflaot[periodNums] = atof(sstr);
  7501. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7502. {
  7503. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7504. }
  7505. else
  7506. {
  7507. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7508. }
  7509. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7510. //****************numberPhases*******************/
  7511. loc = strstr(where, "numberPhases");
  7512. if(loc != NULL)
  7513. {
  7514. c=0;
  7515. memset(sstr ,0, sizeof(sstr) );
  7516. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7517. {
  7518. sstr[c] = loc[strlen("numberPhases")+2+c];
  7519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7520. c++;
  7521. }
  7522. sstr[c] = '\0';
  7523. numberPhasesInt[periodNums] = atoi(sstr);
  7524. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7525. {
  7526. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7527. }
  7528. else
  7529. {
  7530. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7531. }
  7532. }
  7533. where = loc;
  7534. }
  7535. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7536. //****************chargingSchedulePeriod count end*******************/
  7537. //*********************minChargingRate***************************/
  7538. loc = strstr(payload, "minChargingRate");
  7539. if(loc != NULL)
  7540. {
  7541. c = 0;
  7542. memset(sstr ,0, sizeof(sstr) );
  7543. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7544. {
  7545. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7546. c++;
  7547. }
  7548. sstr[c] = '\0';
  7549. minChargingRateFloat = atof(sstr);
  7550. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7551. {
  7552. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7553. }
  7554. else
  7555. {
  7556. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7557. }
  7558. }
  7559. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7560. DEBUG_INFO("-------------------------------------------------------------\n");
  7561. DEBUG_INFO(" Input the file name to be opened : ");
  7562. //fgets(fname, MAX, stdin);
  7563. //fname[strlen(fname) - 1] = '\0';
  7564. #if 0
  7565. switch(connectorIdInt)
  7566. {
  7567. case 0:
  7568. strcpy(filename, ChargingProfile_0_JSON );
  7569. break;
  7570. case 1:
  7571. strcpy(filename, ChargingProfile_1_JSON );
  7572. break;
  7573. case 2:
  7574. strcpy(filename, ChargingProfile_2_JSON );
  7575. break;
  7576. default:
  7577. strcpy(filename, ChargingProfile_0_JSON );
  7578. break;
  7579. }
  7580. fptr1 = fopen(filename, "r");
  7581. if (!fptr1)
  7582. {
  7583. //file not exist
  7584. DEBUG_INFO("Unable to open the input file!!\n");
  7585. fptr1 = fopen(filename, "w+");
  7586. }
  7587. fclose(fptr1);
  7588. #endif
  7589. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7590. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7591. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7592. {
  7593. //printf("set chargingProfile 1-2\n");
  7594. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7595. if(connectorIdInt != 0)
  7596. {
  7597. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7598. goto end;
  7599. }
  7600. strcpy(filename, ChargePointMaxProfile_JSON );
  7601. fptr1 = fopen(filename, "r");
  7602. if (!fptr1)
  7603. {
  7604. //file not exist
  7605. DEBUG_INFO("Unable to open the input file!!\n");
  7606. fptr1 = fopen(filename, "w+");
  7607. }
  7608. fclose(fptr1);
  7609. }
  7610. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7611. {
  7612. //printf("set chargingProfile 1-3\n");
  7613. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7614. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7615. {
  7616. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7617. goto end;
  7618. }
  7619. switch(connectorIdInt)
  7620. {
  7621. case 0:
  7622. strcpy(filename, TxDefaultProfile_0_JSON );
  7623. break;
  7624. case 1:
  7625. strcpy(filename, TxDefaultProfile_1_JSON );
  7626. break;
  7627. case 2:
  7628. strcpy(filename, TxDefaultProfile_2_JSON );
  7629. break;
  7630. default:
  7631. strcpy(filename, TxDefaultProfile_0_JSON );
  7632. break;
  7633. }
  7634. fptr1 = fopen(filename, "r");
  7635. if (!fptr1)
  7636. {
  7637. //file not exist
  7638. DEBUG_INFO("Unable to open the input file!!\n");
  7639. fptr1 = fopen(filename, "w+");
  7640. }
  7641. fclose(fptr1);
  7642. }
  7643. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7644. {
  7645. //printf("set chargingProfile 1-4\n");
  7646. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7647. //check Transaction active
  7648. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7649. {
  7650. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7651. {
  7652. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7653. {
  7654. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7655. {
  7656. meet = TRUE;
  7657. break;
  7658. }
  7659. }
  7660. }
  7661. }
  7662. for (int index = 0; index < CCS_QUANTITY; index++)
  7663. {
  7664. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7665. {
  7666. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7667. {
  7668. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7669. {
  7670. meet = TRUE;
  7671. break;
  7672. }
  7673. }
  7674. }
  7675. }
  7676. for (int index = 0; index < GB_QUANTITY; index++)
  7677. {
  7678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7679. {
  7680. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7681. {
  7682. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7683. {
  7684. meet = TRUE;
  7685. break;
  7686. }
  7687. }
  7688. }
  7689. }
  7690. if(meet == FALSE)
  7691. {
  7692. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7693. goto end;
  7694. }
  7695. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7696. {
  7697. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7698. goto end;
  7699. }
  7700. switch(connectorIdInt)
  7701. {
  7702. case 0:
  7703. break;
  7704. case 1:
  7705. strcpy(filename, TxProfile_1_JSON);
  7706. break;
  7707. case 2:
  7708. strcpy(filename, TxProfile_2_JSON);
  7709. break;
  7710. default:
  7711. strcpy(filename, TxProfile_1_JSON);
  7712. break;
  7713. }
  7714. fptr1 = fopen(filename, "r");
  7715. if (!fptr1)
  7716. {
  7717. //file not exist
  7718. DEBUG_INFO("Unable to open the input file!!\n");
  7719. fptr1 = fopen(filename, "w+");
  7720. }
  7721. fclose(fptr1);
  7722. }
  7723. //**********************************Write to File********************************************************/
  7724. FILE *infile;
  7725. FILE *outfile;
  7726. // open file for writing
  7727. infile = fopen (filename, "r");
  7728. outfile = fopen (tempfile, "w");
  7729. int d =0;
  7730. d = fgetc(infile);
  7731. DEBUG_INFO("d:%d\n",d);
  7732. rewind(infile);
  7733. if(d == EOF)
  7734. {
  7735. DEBUG_INFO("ChargingProfile content is NULL\n");
  7736. fprintf(outfile,"[%s]\n",payload);
  7737. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7738. fclose(infile);
  7739. fclose(outfile);
  7740. sprintf(rmFileCmd,"rm -f %s",filename);
  7741. system(rmFileCmd);
  7742. resultRename = rename(tempfile, filename);
  7743. if(resultRename == 0)
  7744. {
  7745. DEBUG_INFO("File chargingProfile renamed successfully");
  7746. }
  7747. else
  7748. {
  7749. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7750. }
  7751. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7752. //system(rmFileCmd);
  7753. }
  7754. else
  7755. {
  7756. char buf[1000]={0};
  7757. while (fgets(buf, sizeof(buf), infile) != NULL)
  7758. {
  7759. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7760. //*************************tempconnectorIdInt*********************************/
  7761. loc = strstr(buf, "connectorId");
  7762. c = 0;
  7763. memset(sstr ,0, sizeof(sstr) );
  7764. while (loc[strlen("connectorId")+2+c] != ',')
  7765. {
  7766. sstr[c] = loc[strlen("connectorId")+2+c];
  7767. c++;
  7768. }
  7769. sstr[c] = '\0';
  7770. tempconnectorIdInt = atoi(sstr);
  7771. //*************************tempchargingProfileIdInt*********************************/
  7772. loc = strstr(buf, "chargingProfileId");
  7773. c = 0;
  7774. memset(sstr ,0, sizeof(sstr) );
  7775. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7776. {
  7777. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7778. c++;
  7779. }
  7780. sstr[c] = '\0';
  7781. tempchargingProfileIdInt = atoi(sstr);
  7782. //*************************tempstackLevelInt*********************************/
  7783. loc = strstr(buf, "stackLevel");
  7784. c = 0;
  7785. memset(sstr ,0, sizeof(sstr) );
  7786. while (loc[strlen("stackLevel")+2+c] != ',')
  7787. {
  7788. sstr[c] = loc[strlen("stackLevel")+2+c];
  7789. c++;
  7790. }
  7791. sstr[c] = '\0';
  7792. tempstackLevelInt = atoi(sstr);
  7793. //*************************tempchargingProfilePurposeStr*********************************/
  7794. loc = strstr(payload, "chargingProfilePurpose");
  7795. c = 0;
  7796. memset(sstr ,0, sizeof(sstr) );
  7797. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7798. {
  7799. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7800. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7801. c++;
  7802. }
  7803. sstr[c] = '\0';
  7804. strcpy(tempchargingProfilePurposeStr,sstr);
  7805. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7806. {
  7807. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7808. {
  7809. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7810. fprintf(outfile,"[%s]\n",payload);
  7811. }
  7812. else
  7813. {
  7814. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7815. if(tempstackLevelInt < stackLevelInt)
  7816. {
  7817. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7818. fprintf(outfile,"[%s]\n",payload);
  7819. fprintf(outfile,"[%s]\n",buf);
  7820. }
  7821. else
  7822. {
  7823. fprintf(outfile,"[%s]\n",buf);
  7824. fprintf(outfile,"[%s]\n",payload);
  7825. }
  7826. }
  7827. DEBUG_INFO("update set chargingProfile to file\n");
  7828. }
  7829. else
  7830. {
  7831. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7832. {
  7833. fprintf(outfile,"[%s]\n",payload);
  7834. fprintf(outfile,"[%s]\n",buf);
  7835. }
  7836. else if(tempstackLevelInt < stackLevelInt)
  7837. {
  7838. fprintf(outfile,"[%s]\n",payload);
  7839. fprintf(outfile,"[%s]\n",buf);
  7840. }
  7841. else
  7842. {
  7843. fprintf(outfile,"[%s]\n",buf);
  7844. fprintf(outfile,"[%s]\n",payload);
  7845. }
  7846. fprintf(outfile,"[%s]\n",buf);
  7847. DEBUG_INFO("add set chargingProfile to file\n");
  7848. }
  7849. } // end of while loop
  7850. fclose(infile);
  7851. fclose(outfile);
  7852. sprintf(rmFileCmd,"rm -f %s",filename);
  7853. system(rmFileCmd);
  7854. resultRename = rename(tempfile, filename);
  7855. if(resultRename == 0)
  7856. {
  7857. DEBUG_INFO("File chargingProfile renamed successfully");
  7858. }
  7859. else
  7860. {
  7861. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7862. }
  7863. result = TRUE;
  7864. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7865. }
  7866. end:
  7867. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7868. return result;
  7869. return result;
  7870. }
  7871. int handleTriggerMessageRequest(char *uuid, char *payload)
  7872. {
  7873. mtrace();
  7874. int result = FAIL;
  7875. int connectorIdIsNULL = FALSE;
  7876. int connectorIdInt =0;
  7877. char sstr[40]={0};
  7878. char requestedMessagestr[40]={0};
  7879. char comfirmstr[20]={0};
  7880. int c = 0;
  7881. char *loc;
  7882. DEBUG_INFO("handleTriggerMessageRequest\n");
  7883. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7884. c = 0;
  7885. loc = strstr(payload, "requestedMessage");
  7886. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7887. {
  7888. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7889. c++;
  7890. }
  7891. sstr[c] = '\0';
  7892. strcpy(requestedMessagestr, sstr);
  7893. c = 0;
  7894. loc = strstr(payload, "connectorId");
  7895. if(loc == NULL)
  7896. {
  7897. connectorIdIsNULL = TRUE;
  7898. }
  7899. else
  7900. {
  7901. memset(sstr ,0, sizeof(sstr) );
  7902. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7903. {
  7904. sstr[c] = loc[strlen("connectorId")+2+c];
  7905. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7906. c++;
  7907. }
  7908. sstr[c] = '\0';
  7909. connectorIdInt = atoi(sstr);
  7910. }
  7911. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7912. {
  7913. //connectorIdInt = json_object_get_int(connectorId);
  7914. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7915. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7916. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7917. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7918. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7919. }
  7920. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7921. {
  7922. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7923. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7924. return TRUE;
  7925. }
  7926. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7927. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7928. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7929. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7930. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7931. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7932. {
  7933. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7934. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7935. return TRUE;
  7936. }
  7937. else
  7938. {
  7939. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7940. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7941. }
  7942. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7943. {
  7944. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7945. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7946. }
  7947. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7948. {
  7949. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7950. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7951. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7952. }
  7953. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7954. {
  7955. sendBootNotificationRequest();
  7956. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7957. }
  7958. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7959. {
  7960. sendHeartbeatRequest(connectorIdInt);
  7961. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7962. }
  7963. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7964. {
  7965. if(connectorIdIsNULL == FALSE)
  7966. {
  7967. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7968. {
  7969. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7970. sendMeterValuesRequest(connectorIdInt -1);
  7971. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7972. }
  7973. }
  7974. else
  7975. {
  7976. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7977. {
  7978. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7979. sendMeterValuesRequest(idx);
  7980. }
  7981. }
  7982. }
  7983. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7984. {
  7985. if(connectorIdIsNULL == FALSE)
  7986. {
  7987. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7988. {
  7989. sendStatusNotificationRequest(connectorIdInt -1);
  7990. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7991. }
  7992. }
  7993. else
  7994. {
  7995. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7996. sendStatusNotificationRequest(idx);
  7997. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7998. }
  7999. }
  8000. return result;
  8001. }
  8002. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8003. {
  8004. mtrace();
  8005. int result = FAIL;
  8006. char sstr[6]={0};
  8007. int connectorIdInt =0;
  8008. char comfirmstr[20]={0};
  8009. int c = 0;
  8010. char *loc;
  8011. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8012. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8013. c = 0;
  8014. loc = strstr(payload, "connectorId");
  8015. memset(sstr ,0, sizeof(sstr) );
  8016. while (loc[strlen("connectorId")+2+c] != '}')
  8017. {
  8018. sstr[c] = loc[strlen("connectorId")+2+c];
  8019. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8020. c++;
  8021. }
  8022. sstr[c] = '\0';
  8023. connectorIdInt = atoi(sstr);
  8024. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8025. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8026. {
  8027. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8028. goto end;
  8029. }
  8030. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8031. {
  8032. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8033. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8034. goto end;
  8035. }
  8036. else
  8037. {
  8038. //check Transaction active
  8039. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  8040. {
  8041. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8042. {
  8043. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8044. {
  8045. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8046. }
  8047. }
  8048. for (int index = 0; index < CCS_QUANTITY; index++)
  8049. {
  8050. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8051. {
  8052. //stop Transaction
  8053. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8054. }
  8055. }
  8056. for (int index = 0; index < GB_QUANTITY; index++)
  8057. {
  8058. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8059. {
  8060. //stop Transaction
  8061. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8062. }
  8063. }
  8064. }
  8065. else
  8066. {
  8067. for (int index = 0; index < AC_QUANTITY; index++)
  8068. {
  8069. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8070. {
  8071. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8072. }
  8073. }
  8074. }// END FOR AC ELSE
  8075. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8076. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8077. result = TRUE;
  8078. return result;
  8079. }
  8080. end:
  8081. //json_object_put(obj); --- remove temporally
  8082. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8083. return result;
  8084. }
  8085. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8086. {
  8087. mtrace();
  8088. int result = FAIL;
  8089. pthread_t t;
  8090. sendUpdateFirmwareConfirmation(uuid);
  8091. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8092. pthread_join(t, NULL); // 等�?�執行�??��?完�?
  8093. //sendUpdateFirmwareConfirmation(uuid);
  8094. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8095. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8096. return result;
  8097. }
  8098. void *UpdateFirmwareProcess(void *data)
  8099. {
  8100. mtrace();
  8101. int retriesInt =0, retryIntervalInt=0;
  8102. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8103. int port=0;
  8104. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8105. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8106. //char comfirmstr[20];
  8107. int isSuccess = 0;
  8108. char ftpbuf[200];
  8109. char temp[100];
  8110. char * pch;
  8111. int retriesISNULL=FALSE;
  8112. int retryInterval=FALSE;
  8113. int c = 0;
  8114. //int i = 0;
  8115. char *loc;
  8116. char sstr[300]={ 0 };
  8117. char *str = (char*) data; // ?��?輸入資�?
  8118. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8119. //***************location **************/
  8120. loc = strstr(str, "location");
  8121. memset(sstr ,0, sizeof(sstr) );
  8122. c = 0;
  8123. while (loc[3+strlen("location")+c] != '\"')
  8124. {
  8125. sstr[c] = loc[3+strlen("location")+c];
  8126. c++;
  8127. }
  8128. sstr[c] = '\0';
  8129. strcpy(locationstr, sstr);
  8130. //***************retries**************/
  8131. c = 0;
  8132. loc = strstr(str, "retries");
  8133. if(loc == NULL)
  8134. {
  8135. retriesISNULL=TRUE;
  8136. }
  8137. else
  8138. {
  8139. memset(sstr ,0, sizeof(sstr) );
  8140. while (loc[strlen("retries")+2+c] != ',')
  8141. {
  8142. sstr[c] = loc[strlen("retries")+2+c];
  8143. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8144. c++;
  8145. }
  8146. sstr[c] = '\0';
  8147. }
  8148. if(retriesISNULL == FALSE)
  8149. {
  8150. retriesInt = atoi(sstr);
  8151. }
  8152. //***************retrieveDate **************/
  8153. loc = strstr(str, "retrieveDate");
  8154. memset(sstr ,0, sizeof(sstr) );
  8155. c = 0;
  8156. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8157. {
  8158. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8159. c++;
  8160. }
  8161. sstr[c] = '\0';
  8162. strcpy(retrieveDatestr, sstr);
  8163. //***************retryInterval **************/
  8164. c = 0;
  8165. loc = strstr(str, "retryInterval");
  8166. memset(sstr ,0, sizeof(sstr) );
  8167. if(loc == NULL)
  8168. {
  8169. retryInterval=TRUE;
  8170. }
  8171. else
  8172. {
  8173. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8174. {
  8175. sstr[c] = loc[strlen("retryInterval")+2+c];
  8176. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8177. c++;
  8178. }
  8179. sstr[c] = '\0';
  8180. }
  8181. if(retryInterval==FALSE)
  8182. {
  8183. retryIntervalInt = atoi(sstr);
  8184. }
  8185. memset(ftppath, 0, sizeof(ftppath));
  8186. memset(path, 0, sizeof(path));
  8187. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8188. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8189. if(strncmp(locationstr,"http", 4) == 0)
  8190. {
  8191. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8192. protocol, host, path);
  8193. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8194. // protocol, user, password, host, path);
  8195. sprintf(ftppath,"/%s", path);
  8196. DEBUG_INFO("protocol =%s\n",protocol);
  8197. DEBUG_INFO("host =%s\n",host);
  8198. DEBUG_INFO("path =%s\n",path);
  8199. DEBUG_INFO("ftppath=%s\n",ftppath);
  8200. int ftppathlen=strlen(ftppath);
  8201. int i=1;
  8202. char filenametemp[50];
  8203. while(i < ftppathlen)
  8204. {
  8205. int len=ftppathlen-i;
  8206. if(ftppath[len]== 47) // '/' ascll code: 47
  8207. {
  8208. DEBUG_INFO("compare '/' all right\n");
  8209. break;
  8210. }
  8211. i=i+1;
  8212. }
  8213. memset(filenametemp, 0, sizeof(filenametemp));
  8214. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8215. filenametemp[i+1] = 0;
  8216. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8217. do{
  8218. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8219. sleep(retryIntervalInt);
  8220. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8221. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8222. if(!isSuccess)
  8223. {
  8224. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8225. }
  8226. else
  8227. {
  8228. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8229. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8230. isUpdateRequest = TRUE;
  8231. }
  8232. }
  8233. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8234. {
  8235. memset(ftpbuf, 0, sizeof(ftpbuf));
  8236. memset(temp, 0, sizeof(temp));
  8237. DEBUG_INFO("locationstr=%s\n",locationstr);
  8238. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8239. int ftppathlen=strlen(ftpbuf);
  8240. int i=1;
  8241. char filenametemp[50];
  8242. while(i < ftppathlen)
  8243. {
  8244. int len=ftppathlen-i;
  8245. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8246. {
  8247. DEBUG_INFO(" compare '/' all right\n");
  8248. break;
  8249. }
  8250. i=i+1;
  8251. }
  8252. memset(filenametemp, 0, sizeof(filenametemp));
  8253. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8254. filenametemp[i+1] = 0;
  8255. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8256. pch=strchr(temp,'@');
  8257. if(pch==NULL)
  8258. {
  8259. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8260. protocol, host, &port, path);
  8261. strcpy(user,"anonymous");
  8262. strcpy(password,"");
  8263. }
  8264. else
  8265. {
  8266. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8267. protocol, user, password, host, &port, path);
  8268. }
  8269. sscanf(host,"%[^/]%s",host1, path1);
  8270. sprintf(ftppath,"%s", path1);
  8271. DEBUG_INFO("protocol =%s\n",protocol);
  8272. DEBUG_INFO("user =%s\n",user);
  8273. DEBUG_INFO("password =%s\n",password);
  8274. DEBUG_INFO("host1 =%s\n",host1);
  8275. DEBUG_INFO("port =%d\n",port);
  8276. DEBUG_INFO("path1 =%s\n",path1);
  8277. DEBUG_INFO("ftppath=%s\n",ftppath);
  8278. //ftpFile(host, user, password, port, ftppath, fname);
  8279. //download firmware pthred
  8280. if(port == 0)
  8281. {
  8282. port = 21;
  8283. }
  8284. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8285. do{
  8286. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8287. sleep(retryIntervalInt);
  8288. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8289. if(!isSuccess)
  8290. {
  8291. //BulldogUtil.sleepMs(interval*1000);
  8292. DEBUG_INFO("Update firmware request and download file fail.\n");
  8293. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8294. }
  8295. else
  8296. {
  8297. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8298. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8299. isUpdateRequest = TRUE;
  8300. }
  8301. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8302. }
  8303. else
  8304. {
  8305. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8306. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8307. }
  8308. pthread_exit(NULL);
  8309. }
  8310. //==========================================
  8311. // Handle server response routine
  8312. //==========================================
  8313. void handleAuthorizeResponse(char *payload, int gun_index)
  8314. {
  8315. mtrace();
  8316. char expiryDatestr[30]={0};
  8317. char parentIdTagstr[20]={0};
  8318. char statusstr[20]={0};
  8319. char expiryDatestrtemp[30]={0};
  8320. char parentIdTagstrtemp[20]={0};
  8321. char IdTagstrtemp[20]={0};
  8322. char statusstrtemp[20]={0};
  8323. int expiryDateISNULL=FALSE;
  8324. int parentIdTagISNULL=FALSE;
  8325. char sstr[160]={ 0 };
  8326. char* filename = AuthorizationCache_JSON;
  8327. char tempfile[] = "../Storage/OCPP/temp.json";
  8328. int c = 0;
  8329. char *loc;
  8330. int resultRename=0;
  8331. int responseIdTagInfoAsZero= 0;
  8332. char rmFileCmd[50]={0};
  8333. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8334. //***********expiryDate*************/
  8335. loc = strstr(payload, "expiryDate");
  8336. memset(sstr ,0, sizeof(sstr) );
  8337. c = 0;
  8338. if(loc == NULL)
  8339. {
  8340. expiryDateISNULL = TRUE;
  8341. }
  8342. else
  8343. {
  8344. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8345. {
  8346. sstr[c] = loc[3+strlen("expiryDate")+c];
  8347. c++;
  8348. }
  8349. sstr[c] = '\0';
  8350. strcpy(expiryDatestr, sstr);
  8351. }
  8352. //***********parentIdTag*************/
  8353. loc = strstr(payload, "parentIdTag");
  8354. memset(sstr ,0, sizeof(sstr) );
  8355. c = 0;
  8356. if(loc == NULL)
  8357. {
  8358. parentIdTagISNULL = TRUE;
  8359. }
  8360. else
  8361. {
  8362. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8363. {
  8364. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8365. c++;
  8366. }
  8367. sstr[c] = '\0';
  8368. strcpy(parentIdTagstr, sstr);
  8369. }
  8370. //***********status*************/
  8371. loc = strstr(payload, "status");
  8372. memset(sstr ,0, sizeof(sstr) );
  8373. c = 0;
  8374. while (loc[3+strlen("status")+c] != '\"')
  8375. {
  8376. sstr[c] = loc[3+strlen("status")+c];
  8377. c++;
  8378. }
  8379. sstr[c] = '\0';
  8380. strcpy(statusstr, sstr);
  8381. //#ifdef SystemLogMessage
  8382. // if(expiryDateISNULL == FALSE)
  8383. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8384. // if(parentIdTagISNULL == FALSE)
  8385. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8386. // DEBUG_INFO("status: %s\n", statusstr);
  8387. //#endif
  8388. if(expiryDateISNULL == FALSE)
  8389. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8390. if(parentIdTagISNULL == FALSE)
  8391. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8392. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8393. //Update idTag information to authorization cache if supproted
  8394. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8395. {
  8396. if((access(filename,F_OK))!=-1)
  8397. {
  8398. DEBUG_INFO("AuthorizationCache exist.\n");
  8399. }
  8400. else
  8401. {
  8402. DEBUG_INFO("AuthorizationCache not exist\n");
  8403. FILE *log = fopen(filename, "w+");
  8404. if(log == NULL)
  8405. {
  8406. DEBUG_INFO("log is NULL\n");
  8407. goto out;
  8408. }
  8409. else
  8410. {
  8411. fclose(log);
  8412. }
  8413. }
  8414. FILE *infile;
  8415. FILE *outfile;
  8416. // open file for writing
  8417. infile = fopen (filename, "r");
  8418. outfile = fopen (tempfile, "w");
  8419. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8420. int c;
  8421. c = fgetc(infile);
  8422. //DEBUG_INFO("c:%d\n",c);
  8423. rewind(infile);
  8424. if(c == EOF)
  8425. {
  8426. DEBUG_INFO("Orignal File is NULL\n");
  8427. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8428. {
  8429. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8430. }
  8431. else
  8432. {
  8433. strcpy(expiryDatestrtemp, "");
  8434. }
  8435. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8436. {
  8437. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8438. }
  8439. else
  8440. {
  8441. //write Authorize IdTag
  8442. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8443. }
  8444. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8445. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8446. fclose(infile);
  8447. fclose(outfile);
  8448. sprintf(rmFileCmd,"rm -f %s",filename);
  8449. system(rmFileCmd);
  8450. resultRename = rename(tempfile, filename);
  8451. if(resultRename == 0)
  8452. {
  8453. DEBUG_INFO("File renamed successfully");
  8454. }
  8455. else
  8456. {
  8457. DEBUG_INFO("Error: unable to rename the file");
  8458. }
  8459. }
  8460. else
  8461. {
  8462. char buf[160]={0};
  8463. //DEBUG_INFO("Orignal File is not NULL\n");
  8464. while (fgets(buf, sizeof(buf), infile) != NULL)
  8465. {
  8466. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8467. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8468. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8469. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8470. memset(statusstr, 0, sizeof(statusstrtemp));
  8471. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8472. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8473. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8474. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8475. //------------------IdTag-----------------------
  8476. loc = strstr(buf, "idTag");
  8477. memset(sstr ,0, sizeof(sstr) );
  8478. c = 0;
  8479. while (loc[3+strlen("idTag")+c] != '\"')
  8480. {
  8481. sstr[c] = loc[3+strlen("idTag")+c];
  8482. c++;
  8483. }
  8484. sstr[c] = '\0';
  8485. strcpy(IdTagstrtemp,sstr);
  8486. //*********************expiryDate***************/
  8487. loc = strstr(buf, "expiryDate");
  8488. memset(sstr ,0, sizeof(sstr) );
  8489. c = 0;
  8490. while (loc[3+strlen("expiryDate")+c] != '\"')
  8491. {
  8492. sstr[c] = loc[3+strlen("expiryDate")+c];
  8493. c++;
  8494. }
  8495. sstr[c] = '\0';
  8496. strcpy(expiryDatestr,sstr);
  8497. //*********************parentIdTag***************/
  8498. loc = strstr(buf, "parentIdTag");
  8499. memset(sstr ,0, sizeof(sstr) );
  8500. c = 0;
  8501. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8502. {
  8503. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8504. c++;
  8505. }
  8506. sstr[c] = '\0';
  8507. strcpy(parentIdTagstr,sstr);
  8508. //*********************status***************/
  8509. loc = strstr(buf, "status");
  8510. memset(sstr ,0, sizeof(sstr) );
  8511. c = 0;
  8512. while (loc[3+strlen("status")+c] != '\"')
  8513. {
  8514. sstr[c] = loc[3+strlen("status")+c];
  8515. c++;
  8516. }
  8517. sstr[c] = '\0';
  8518. strcpy(statusstr,sstr);
  8519. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8520. {
  8521. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8522. responseIdTagInfoAsZero = 1;
  8523. }
  8524. else
  8525. {
  8526. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8527. }
  8528. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8529. {
  8530. //modify item
  8531. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8532. {
  8533. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8534. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8535. }
  8536. else
  8537. {
  8538. strcpy(expiryDatestrtemp, "");
  8539. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8540. }
  8541. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8542. {
  8543. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8544. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8545. }
  8546. else
  8547. {
  8548. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8549. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8550. }
  8551. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8552. }
  8553. else
  8554. {
  8555. //wrie original item
  8556. strcpy(expiryDatestrtemp, expiryDatestr);
  8557. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8558. strcpy(statusstrtemp, statusstr);
  8559. }
  8560. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8561. }
  8562. fclose(infile);
  8563. fclose(outfile);
  8564. sprintf(rmFileCmd,"rm -f %s",filename);
  8565. system(rmFileCmd);
  8566. resultRename = rename(tempfile, filename);
  8567. if(resultRename == 0)
  8568. {
  8569. DEBUG_INFO("File renamed successfully");
  8570. }
  8571. else
  8572. {
  8573. DEBUG_INFO("Error: unable to rename the file");
  8574. }
  8575. }
  8576. }
  8577. out:
  8578. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8579. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8580. authorizeRetryTimes = 0;
  8581. }
  8582. void handleBootNotificationResponse(char *payload, int gun_index)
  8583. {
  8584. mtrace();
  8585. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8586. char statusStr[12]={0};
  8587. char currentTimeStr[30]={0};
  8588. char *loc;
  8589. int intervalInt = 0;
  8590. int c = 0;
  8591. //double diff_t;
  8592. struct tm tp;
  8593. char buf[28]={0};
  8594. char timebuf[50]={0};
  8595. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8596. //*** interval ****/
  8597. c = 0;
  8598. loc = strstr(payload, "interval");
  8599. //printf("loc=%s\n",loc);
  8600. memset(sstr ,0, sizeof(sstr) );
  8601. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8602. {
  8603. sstr[c] = loc[strlen("interval")+2+c];
  8604. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8605. c++;
  8606. }
  8607. sstr[c] = '\0';
  8608. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8609. intervalInt = atoi(sstr);
  8610. //***status ****/
  8611. loc = strstr(payload, "status");
  8612. memset(sstr ,0, sizeof(sstr) );
  8613. c = 0;
  8614. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8615. {
  8616. sstr[c] = loc[3+strlen("status")+c];
  8617. c++;
  8618. }
  8619. sstr[c] = '\0';
  8620. strcpy(statusStr, sstr);
  8621. //***currentTime ****/
  8622. loc = strstr(payload, "currentTime");
  8623. //printf("loc=%s\n",loc);
  8624. memset(sstr ,0, sizeof(sstr) );
  8625. c = 0;
  8626. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8627. {
  8628. sstr[c] = loc[3+strlen("currentTime")+c];
  8629. c++;
  8630. }
  8631. sstr[c] = '\0';
  8632. strcpy(currentTimeStr, sstr);
  8633. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8634. HeartBeatWaitTime = BootNotificationInterval;
  8635. //#ifdef SystemLogMessage
  8636. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8637. // DEBUG_INFO("interval: %d\n", intervalInt);
  8638. // DEBUG_INFO("status: %s\n", statusStr);
  8639. //#endif
  8640. //write back to ShmOCPP16Data->BootNotification
  8641. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8642. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8643. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8644. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8645. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8646. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8647. {
  8648. server_sign = TRUE;
  8649. server_pending =FALSE;
  8650. }
  8651. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8652. {
  8653. server_pending = TRUE;
  8654. }
  8655. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8656. tp.tm_isdst = -1;
  8657. //time_t utc = mktime(&tp);
  8658. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8659. memset(timebuf, 0, sizeof timebuf);
  8660. sprintf(timebuf,"date -s '%s'",buf);
  8661. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8662. system(timebuf);
  8663. //==============================================
  8664. // RTC sync
  8665. //==============================================
  8666. system("/sbin/hwclock -w --systohc");
  8667. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8668. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8669. }
  8670. void handleDataTransferResponse(char *payload, int gun_index)
  8671. {
  8672. char sstr[160]={0};//sstr[200]={ 0 };
  8673. int c = 0;
  8674. char *loc;
  8675. DEBUG_INFO("handleDataTransferResponse ...\n");
  8676. loc = strstr(payload, "status");
  8677. printf("loc=%s\n",loc);
  8678. c = 0;
  8679. while (loc[3+strlen("status")+c] != '\"')
  8680. {
  8681. sstr[c] = loc[3+strlen("status")+c];
  8682. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8683. c++;
  8684. }
  8685. sstr[c] = '\0';
  8686. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8687. //#ifdef SystemLogMessage
  8688. //DEBUG_INFO("data: %s\n", payload);
  8689. //#endif
  8690. }
  8691. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8692. {
  8693. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8694. //struct json_object *obj;
  8695. // obj = json_tokener_parse(payload);
  8696. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8697. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8698. //No fields are defined.
  8699. }
  8700. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8701. {
  8702. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8703. //struct json_object *obj;
  8704. // obj = json_tokener_parse(payload);
  8705. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8706. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8707. //No fields are defined.
  8708. }
  8709. void handleHeartbeatResponse(char *payload, int gun_index)
  8710. {
  8711. mtrace();
  8712. //double diff_t;
  8713. struct tm tp;
  8714. char buf[28]={0};
  8715. char timebuf[50]={0};
  8716. char sstr[30]={ 0 };
  8717. int c = 0;
  8718. char *loc;
  8719. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8720. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8721. c = 0;
  8722. loc = strstr(payload, "currentTime");
  8723. memset(sstr ,0, sizeof(sstr) );
  8724. while (loc[3+strlen("currentTime")+c] != '\"')
  8725. {
  8726. sstr[c] = loc[3+strlen("currentTime")+c];
  8727. c++;
  8728. }
  8729. sstr[c] = '\0';
  8730. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8731. #ifdef SystemLogMessage
  8732. DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8733. #endif
  8734. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8735. tp.tm_isdst = -1;
  8736. //time_t utc = mktime(&tp);
  8737. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8738. memset(timebuf, 0, sizeof timebuf);
  8739. sprintf(timebuf,"date -s '%s'",buf);
  8740. system(timebuf);
  8741. //==============================================
  8742. // RTC sync
  8743. //==============================================
  8744. system("/sbin/hwclock -w --systohc");
  8745. if(FirstHeartBeat == 0)
  8746. {
  8747. FirstHeartBeat = 1;
  8748. }
  8749. }
  8750. void handleMeterValuesResponse(char *payload, int gun_index)
  8751. {
  8752. mtrace();
  8753. //struct json_object *obj;
  8754. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8755. //No fields are defined.
  8756. }
  8757. void handleStartTransactionResponse(char *payload, int gun_index)
  8758. {
  8759. mtrace();
  8760. char sstr[30]={ 0 };
  8761. int c = 0;
  8762. char *loc;
  8763. int transactionIdInt = 0;
  8764. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8765. DEBUG_INFO("handleStartTransactionResponse\n");
  8766. //****************expiryDate********************/
  8767. loc = strstr(payload, "expiryDate");
  8768. if(loc == NULL)
  8769. {
  8770. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8771. }
  8772. else
  8773. {
  8774. c = 0;
  8775. memset(sstr ,0, sizeof(sstr) );
  8776. while (loc[3+strlen("expiryDate")+c] != '\"')
  8777. {
  8778. sstr[c] = loc[3+strlen("expiryDate")+c];
  8779. c++;
  8780. }
  8781. sstr[c] = '\0';
  8782. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8783. }
  8784. //****************parentIdTag********************/
  8785. loc = strstr(payload, "parentIdTag");
  8786. if(loc == NULL)
  8787. {
  8788. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8789. }
  8790. else
  8791. {
  8792. c = 0;
  8793. memset(sstr ,0, sizeof(sstr) );
  8794. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8795. {
  8796. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8797. c++;
  8798. }
  8799. sstr[c] = '\0';
  8800. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8801. }
  8802. //****************status********************/
  8803. loc = strstr(payload, "status");
  8804. if(loc == NULL)
  8805. {
  8806. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8807. }
  8808. else
  8809. {
  8810. c = 0;
  8811. memset(sstr ,0, sizeof(sstr) );
  8812. while (loc[3+strlen("status")+c] != '\"')
  8813. {
  8814. sstr[c] = loc[3+strlen("status")+c];
  8815. c++;
  8816. }
  8817. sstr[c] = '\0';
  8818. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8819. }
  8820. //****************transactionId********************/
  8821. c=0;
  8822. loc = strstr(payload, "transactionId");
  8823. memset(sstr ,0, sizeof(sstr) );
  8824. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8825. {
  8826. sstr[c] = loc[strlen("transactionId")+2+c];
  8827. c++;
  8828. }
  8829. sstr[c] = '\0';
  8830. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8831. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8832. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8833. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8834. #ifdef SystemLogMessage
  8835. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8836. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8837. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8838. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8839. #endif
  8840. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8841. {
  8842. //add Charging Record
  8843. SettingChargingRecord(gun_index, transactionIdInt);
  8844. }
  8845. }
  8846. void handleStatusNotificationResponse(char *payload, int gun_index)
  8847. {
  8848. mtrace();
  8849. printf("handleStatusNotificationResponse\n");
  8850. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8851. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8852. }
  8853. void handleStopTransactionnResponse(char *payload, int gun_index)
  8854. {
  8855. mtrace();
  8856. char sstr[30]={ 0 };
  8857. int c = 0;
  8858. char *loc;
  8859. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8860. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8861. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8862. loc = strstr(payload, "idTagInfo");
  8863. //***********************idTagInfo************************/
  8864. if(loc != NULL)
  8865. {
  8866. //***********************expiryDate************************/
  8867. loc = strstr(payload, "expiryDate");
  8868. if(loc != NULL)
  8869. {
  8870. memset(sstr ,0, sizeof(sstr) );
  8871. c = 0;
  8872. while (loc[3+strlen("expiryDate")+c] != '\"')
  8873. {
  8874. sstr[c] = loc[3+strlen("expiryDate")+c];
  8875. c++;
  8876. }
  8877. sstr[c] = '\0';
  8878. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8879. }
  8880. //***********************parentIdTag************************/
  8881. loc = strstr(payload, "parentIdTag");
  8882. if(loc != NULL)
  8883. {
  8884. memset(sstr ,0, sizeof(sstr) );
  8885. c = 0;
  8886. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8887. {
  8888. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8889. c++;
  8890. }
  8891. sstr[c] = '\0';
  8892. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8893. }
  8894. //***********************status************************/
  8895. loc = strstr(payload, "status");
  8896. memset(sstr ,0, sizeof(sstr) );
  8897. c = 0;
  8898. while (loc[3+strlen("status")+c] != '\"')
  8899. {
  8900. sstr[c] = loc[3+strlen("status")+c];
  8901. c++;
  8902. }
  8903. sstr[c] = '\0';
  8904. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8905. }
  8906. #ifdef SystemLogMessage
  8907. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8908. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8909. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8910. #endif
  8911. }
  8912. //==========================================
  8913. // Handle Error routine
  8914. //==========================================
  8915. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8916. {
  8917. mtrace();
  8918. #ifdef SystemLogMessage
  8919. DEBUG_INFO("errorCode: %s\n", errorCode);
  8920. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8921. DEBUG_INFO("errorDetails: %s\n", payload);
  8922. #endif
  8923. }
  8924. //===============================================
  8925. // Common routine
  8926. //===============================================
  8927. int initialConfigurationTable(void)
  8928. {
  8929. printf("initialConfigurationTable \n");
  8930. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8931. /*Core Profile*/
  8932. //AllowOfflineTxForUnknownId
  8933. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8934. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8937. //AuthorizationCacheEnabled
  8938. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8941. //AuthorizeRemoteTxRequests
  8942. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8945. //BlinkRepeat
  8946. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8949. //ClockAlignedDataInterval
  8950. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8953. //ConnectionTimeOut
  8954. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8957. //GetConfigurationMaxKeys
  8958. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8961. // HeartbeatInterval
  8962. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8965. // LightIntensity
  8966. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8969. // LocalAuthorizeOffline
  8970. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  8971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8973. // LocalPreAuthorize
  8974. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  8975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8977. // MaxEnergyOnInvalidId
  8978. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  8980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  8981. // MeterValuesAlignedData
  8982. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  8983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  8984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  8985. // MeterValuesAlignedDataMaxLength
  8986. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  8987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  8988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  8989. // MeterValuesSampledData
  8990. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  8991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  8992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  8993. // MeterValuesSampledDataMaxLength
  8994. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  8995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  8996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  8997. // MeterValueSampleInterval
  8998. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  8999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9001. // MinimumStatusDuration
  9002. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9005. // NumberOfConnectors
  9006. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  9009. // ResetRetries
  9010. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9013. // ConnectorPhaseRotation
  9014. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  9017. // ConnectorPhaseRotationMaxLength
  9018. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9021. // StopTransactionOnEVSideDisconnect
  9022. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9025. // StopTransactionOnInvalidId
  9026. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9029. // StopTxnAlignedData
  9030. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9033. // StopTxnAlignedDataMaxLength
  9034. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9037. // StopTxnSampledData
  9038. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9041. // StopTxnSampledDataMaxLength
  9042. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9045. // SupportedFeatureProfiles
  9046. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9049. // SupportedFeatureProfilesMaxLength
  9050. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9053. // TransactionMessageAttempts
  9054. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9057. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9058. // TransactionMessageRetryInterval
  9059. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9062. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9063. // UnlockConnectorOnEVSideDisconnect
  9064. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9067. // WebSocketPingInterval
  9068. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9071. //* Local Auth List Management Profile*/
  9072. #if 0
  9073. //For OCTT Test Case
  9074. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9077. #endif
  9078. #if 1
  9079. //LocalAuthListEnabled
  9080. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9083. #endif
  9084. //LocalAuthListMaxLength
  9085. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9088. //SendLocalListMaxLength
  9089. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9092. //ReserveConnectorZeroSupported
  9093. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9096. //* Smart Charging Profile */
  9097. //ChargeProfileMaxStackLevel
  9098. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9101. // ChargingScheduleAllowedChargingRateUnit
  9102. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9105. // ChargingScheduleMaxPeriods
  9106. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9109. // ConnectorSwitch3to1PhaseSupported
  9110. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9113. // MaxChargingProfilesInstalled
  9114. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9117. return 0;
  9118. }
  9119. void getKeyValue(char *keyReq)
  9120. {
  9121. int isEmpty = FALSE;
  9122. int isKnowKey = FALSE;
  9123. //int unKnowIndex = 0;
  9124. DEBUG_INFO("getKeyValue \n");
  9125. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9126. isEmpty = TRUE;
  9127. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9128. {
  9129. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9132. {
  9133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9134. }
  9135. else
  9136. {
  9137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9138. }
  9139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9140. isKnowKey = TRUE;
  9141. }
  9142. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9143. {
  9144. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9146. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9147. {
  9148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9149. }
  9150. else
  9151. {
  9152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9153. }
  9154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9155. isKnowKey = TRUE;
  9156. }
  9157. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9158. {
  9159. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9162. {
  9163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9164. }
  9165. else
  9166. {
  9167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9168. }
  9169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9170. isKnowKey = TRUE;
  9171. }
  9172. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9173. {
  9174. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9177. {
  9178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9179. }
  9180. else
  9181. {
  9182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9183. }
  9184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9185. isKnowKey = TRUE;
  9186. }
  9187. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9188. {
  9189. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9192. {
  9193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9194. }
  9195. else
  9196. {
  9197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9198. }
  9199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9200. isKnowKey = TRUE;
  9201. }
  9202. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9203. {
  9204. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9206. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9207. {
  9208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9209. }
  9210. else
  9211. {
  9212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9213. }
  9214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9215. isKnowKey = TRUE;
  9216. }
  9217. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9218. {
  9219. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9221. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9222. {
  9223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9224. }
  9225. else
  9226. {
  9227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9228. }
  9229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9230. isKnowKey = TRUE;
  9231. }
  9232. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9233. {
  9234. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9236. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9237. {
  9238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9239. }
  9240. else
  9241. {
  9242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9243. }
  9244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9245. isKnowKey = TRUE;
  9246. }
  9247. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9248. {
  9249. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9252. {
  9253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9254. }
  9255. else
  9256. {
  9257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9258. }
  9259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9260. isKnowKey = TRUE;
  9261. }
  9262. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9263. {
  9264. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9266. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9267. {
  9268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9269. }
  9270. else
  9271. {
  9272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9273. }
  9274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9275. isKnowKey = TRUE;
  9276. }
  9277. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9278. {
  9279. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9282. {
  9283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9284. }
  9285. else
  9286. {
  9287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9288. }
  9289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9290. isKnowKey = TRUE;
  9291. }
  9292. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9293. {
  9294. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9296. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9297. {
  9298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9299. }
  9300. else
  9301. {
  9302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9303. }
  9304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9305. isKnowKey = TRUE;
  9306. }
  9307. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9308. {
  9309. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9312. {
  9313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9314. }
  9315. else
  9316. {
  9317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9318. }
  9319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9320. isKnowKey = TRUE;
  9321. }
  9322. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9323. {
  9324. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9327. {
  9328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9329. }
  9330. else
  9331. {
  9332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9333. }
  9334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9335. isKnowKey = TRUE;
  9336. }
  9337. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9338. {
  9339. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9342. {
  9343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9344. }
  9345. else
  9346. {
  9347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9348. }
  9349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9350. isKnowKey = TRUE;
  9351. }
  9352. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9353. {
  9354. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9357. {
  9358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9359. }
  9360. else
  9361. {
  9362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9363. }
  9364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9365. isKnowKey = TRUE;
  9366. }
  9367. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9368. {
  9369. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9372. {
  9373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9374. }
  9375. else
  9376. {
  9377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9378. }
  9379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9380. isKnowKey = TRUE;
  9381. }
  9382. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9383. {
  9384. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9387. {
  9388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9389. }
  9390. else
  9391. {
  9392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9393. }
  9394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9395. isKnowKey = TRUE;
  9396. }
  9397. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9398. {
  9399. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9402. {
  9403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9404. }
  9405. else
  9406. {
  9407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9408. }
  9409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9410. isKnowKey = TRUE;
  9411. }
  9412. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9413. {
  9414. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9417. {
  9418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9419. }
  9420. else
  9421. {
  9422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9423. }
  9424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9425. isKnowKey = TRUE;
  9426. }
  9427. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9428. {
  9429. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9432. {
  9433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9434. }
  9435. else
  9436. {
  9437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9438. }
  9439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9440. isKnowKey = TRUE;
  9441. }
  9442. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9443. {
  9444. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9447. {
  9448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9449. }
  9450. else
  9451. {
  9452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9453. }
  9454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9455. isKnowKey = TRUE;
  9456. }
  9457. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9458. {
  9459. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9462. {
  9463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9464. }
  9465. else
  9466. {
  9467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9468. }
  9469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9470. isKnowKey = TRUE;
  9471. }
  9472. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9473. {
  9474. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9477. {
  9478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9479. }
  9480. else
  9481. {
  9482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9483. }
  9484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9485. isKnowKey = TRUE;
  9486. }
  9487. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9488. {
  9489. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9492. {
  9493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9494. }
  9495. else
  9496. {
  9497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9498. }
  9499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9500. isKnowKey = TRUE;
  9501. }
  9502. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9503. {
  9504. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9507. {
  9508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9509. }
  9510. else
  9511. {
  9512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9513. }
  9514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9515. isKnowKey = TRUE;
  9516. }
  9517. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9518. {
  9519. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9522. {
  9523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9524. }
  9525. else
  9526. {
  9527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9528. }
  9529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9530. isKnowKey = TRUE;
  9531. }
  9532. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9533. {
  9534. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9537. {
  9538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9539. }
  9540. else
  9541. {
  9542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9543. }
  9544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9545. isKnowKey = TRUE;
  9546. }
  9547. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9548. {
  9549. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9552. {
  9553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9554. }
  9555. else
  9556. {
  9557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9558. }
  9559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9560. isKnowKey = TRUE;
  9561. }
  9562. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9563. {
  9564. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9566. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9567. {
  9568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9569. }
  9570. else
  9571. {
  9572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9573. }
  9574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9575. isKnowKey = TRUE;
  9576. }
  9577. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9578. {
  9579. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9582. {
  9583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9584. }
  9585. else
  9586. {
  9587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9588. }
  9589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9590. isKnowKey = TRUE;
  9591. }
  9592. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9593. {
  9594. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9597. {
  9598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9599. }
  9600. else
  9601. {
  9602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9603. }
  9604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9605. isKnowKey = TRUE;
  9606. }
  9607. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9608. {
  9609. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9612. {
  9613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9614. }
  9615. else
  9616. {
  9617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9618. }
  9619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9620. isKnowKey = TRUE;
  9621. }
  9622. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9623. {
  9624. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9627. {
  9628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9629. }
  9630. else
  9631. {
  9632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9633. }
  9634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9635. isKnowKey = TRUE;
  9636. }
  9637. #if 0
  9638. //For OCTT Test Case
  9639. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9640. {
  9641. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9643. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9644. {
  9645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9646. }
  9647. else
  9648. {
  9649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9650. }
  9651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9652. isKnowKey = TRUE;
  9653. }
  9654. #endif
  9655. #if 1
  9656. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9657. {
  9658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9660. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9661. {
  9662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9663. }
  9664. else
  9665. {
  9666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9667. }
  9668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9669. isKnowKey = TRUE;
  9670. }
  9671. #endif
  9672. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9673. {
  9674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9676. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9677. {
  9678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9679. }
  9680. else
  9681. {
  9682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9683. }
  9684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9685. isKnowKey = TRUE;
  9686. }
  9687. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9688. {
  9689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9691. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9692. {
  9693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9694. }
  9695. else
  9696. {
  9697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9698. }
  9699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9700. isKnowKey = TRUE;
  9701. }
  9702. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9703. {
  9704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9706. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9707. {
  9708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9709. }
  9710. else
  9711. {
  9712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9713. }
  9714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9715. isKnowKey = TRUE;
  9716. }
  9717. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9718. {
  9719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9721. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9722. {
  9723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9724. }
  9725. else
  9726. {
  9727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9728. }
  9729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9730. isKnowKey = TRUE;
  9731. }
  9732. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9733. {
  9734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9736. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9737. {
  9738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9739. }
  9740. else
  9741. {
  9742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9743. }
  9744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9745. isKnowKey = TRUE;
  9746. }
  9747. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9748. {
  9749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9751. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9752. {
  9753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9754. }
  9755. else
  9756. {
  9757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9758. }
  9759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9760. isKnowKey = TRUE;
  9761. }
  9762. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9763. {
  9764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9766. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9767. {
  9768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9769. }
  9770. else
  9771. {
  9772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9773. }
  9774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9775. isKnowKey = TRUE;
  9776. }
  9777. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9778. {
  9779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9781. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9782. {
  9783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9784. }
  9785. else
  9786. {
  9787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9788. }
  9789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9790. isKnowKey = TRUE;
  9791. }
  9792. //=========================================================
  9793. if(!isEmpty && !isKnowKey)
  9794. {
  9795. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9796. strcpy(unknownkey[UnknownKeynum], keyReq);
  9797. UnknownKeynum = UnknownKeynum + 1;
  9798. }
  9799. }
  9800. void processUnkownKey(void)
  9801. {
  9802. DEBUG_INFO("processUnkownKey\n");
  9803. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9804. for(int index=0; index < UnknownKeynum; index++)
  9805. {
  9806. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9807. {
  9808. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9809. }
  9810. }
  9811. }
  9812. int setKeyValue(char *key, char *value)
  9813. {
  9814. int isSuccess = NotSupported;
  9815. int check_ascii=0;
  9816. #ifdef Debug
  9817. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9818. #endif
  9819. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9820. {
  9821. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9823. {
  9824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9825. isSuccess = ConfigurationStatus_Accepted;
  9826. }
  9827. else
  9828. {
  9829. isSuccess = ConfigurationStatus_Rejected;
  9830. }
  9831. }
  9832. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9833. {
  9834. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9835. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9836. {
  9837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9838. isSuccess = ConfigurationStatus_Accepted;
  9839. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9840. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9841. }
  9842. else
  9843. {
  9844. isSuccess = ConfigurationStatus_Rejected;
  9845. }
  9846. }
  9847. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9848. {
  9849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9850. {
  9851. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9853. isSuccess = ConfigurationStatus_Accepted;
  9854. }
  9855. else
  9856. {
  9857. isSuccess = ConfigurationStatus_Rejected;
  9858. }
  9859. }
  9860. if(strcmp(key, "BlinkRepeat") == 0)
  9861. {
  9862. //Charger.BlinkRepeat = Integer.parseInt(value);
  9863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9864. {
  9865. check_ascii = value[0];
  9866. if( (check_ascii < 48) || (check_ascii > 57) )
  9867. {
  9868. isSuccess = ConfigurationStatus_Rejected;
  9869. }
  9870. else
  9871. {
  9872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9873. isSuccess = ConfigurationStatus_Accepted;
  9874. }
  9875. }
  9876. else
  9877. {
  9878. isSuccess = ConfigurationStatus_Rejected;
  9879. }
  9880. }
  9881. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9882. {
  9883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9884. {
  9885. check_ascii = value[0];
  9886. if( (check_ascii < 48) || (check_ascii > 57) )
  9887. {
  9888. isSuccess = ConfigurationStatus_Rejected;
  9889. }
  9890. else
  9891. {
  9892. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9894. isSuccess = ConfigurationStatus_Accepted;
  9895. }
  9896. }
  9897. else
  9898. {
  9899. isSuccess = ConfigurationStatus_Rejected;
  9900. }
  9901. }
  9902. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9903. {
  9904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9905. {
  9906. check_ascii = value[0];
  9907. if( (check_ascii < 48) || (check_ascii > 57) )
  9908. {
  9909. isSuccess = ConfigurationStatus_Rejected;
  9910. }
  9911. else
  9912. {
  9913. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9915. isSuccess = ConfigurationStatus_Accepted;
  9916. }
  9917. }
  9918. else
  9919. {
  9920. isSuccess = ConfigurationStatus_Rejected;
  9921. }
  9922. }
  9923. if(strcmp(key, "HeartbeatInterval") == 0)
  9924. {
  9925. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9926. {
  9927. check_ascii = value[0];
  9928. if( (check_ascii < 48) || (check_ascii > 57) )
  9929. {
  9930. isSuccess = ConfigurationStatus_Rejected;
  9931. }
  9932. else
  9933. {
  9934. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9936. HeartBeatWaitTime = atoi(value);
  9937. isSuccess = ConfigurationStatus_Accepted;
  9938. }
  9939. }
  9940. else
  9941. {
  9942. isSuccess = ConfigurationStatus_Rejected;
  9943. }
  9944. }
  9945. if(strcmp(key, "LightIntensity") == 0)
  9946. {
  9947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9948. {
  9949. check_ascii = value[0];
  9950. if( (check_ascii < 48) || (check_ascii > 57) )
  9951. {
  9952. isSuccess = ConfigurationStatus_Rejected;
  9953. }
  9954. else
  9955. {
  9956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9957. isSuccess = ConfigurationStatus_Accepted;
  9958. }
  9959. }
  9960. else
  9961. {
  9962. isSuccess = ConfigurationStatus_Rejected;
  9963. }
  9964. }
  9965. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9966. {
  9967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9968. {
  9969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9970. isSuccess = ConfigurationStatus_Accepted;
  9971. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9972. }
  9973. else
  9974. {
  9975. isSuccess = ConfigurationStatus_Rejected;
  9976. }
  9977. }
  9978. if(strcmp(key, "LocalPreAuthorize") == 0)
  9979. {
  9980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9981. {
  9982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9983. isSuccess = ConfigurationStatus_Accepted;
  9984. }
  9985. else
  9986. {
  9987. isSuccess = ConfigurationStatus_Rejected;
  9988. }
  9989. }
  9990. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  9991. {
  9992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9993. {
  9994. check_ascii = value[0];
  9995. if( (check_ascii < 48) || (check_ascii > 57) )
  9996. {
  9997. isSuccess = ConfigurationStatus_Rejected;
  9998. }
  9999. else
  10000. {
  10001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10002. isSuccess = ConfigurationStatus_Accepted;
  10003. }
  10004. }
  10005. else
  10006. {
  10007. isSuccess = ConfigurationStatus_Rejected;
  10008. }
  10009. }
  10010. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10011. {
  10012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10013. {
  10014. //int valueLength = strlen(value);
  10015. for(int i = 0; value[i]; i++){
  10016. value[i] = tolower(value[i]);
  10017. }
  10018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10019. isSuccess = ConfigurationStatus_Accepted;
  10020. }
  10021. else
  10022. {
  10023. isSuccess = ConfigurationStatus_Rejected;
  10024. }
  10025. }
  10026. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10027. {
  10028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10029. {
  10030. //int valueLength = strlen(value);
  10031. for(int i = 0; value[i]; i++){
  10032. value[i] = tolower(value[i]);
  10033. }
  10034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10035. isSuccess = ConfigurationStatus_Accepted;
  10036. }
  10037. else
  10038. {
  10039. isSuccess = ConfigurationStatus_Rejected;
  10040. }
  10041. }
  10042. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10043. {
  10044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10045. {
  10046. check_ascii = value[0];
  10047. if( (check_ascii < 48) || (check_ascii > 57) )
  10048. {
  10049. isSuccess = ConfigurationStatus_Rejected;
  10050. }
  10051. else
  10052. {
  10053. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10055. isSuccess = ConfigurationStatus_Accepted;
  10056. }
  10057. #ifdef Debug
  10058. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10059. #endif
  10060. }
  10061. else
  10062. {
  10063. isSuccess = ConfigurationStatus_Rejected;
  10064. #ifdef Debug
  10065. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10066. #endif
  10067. }
  10068. }
  10069. if(strcmp(key, "MinimumStatusDuration") == 0)
  10070. {
  10071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10072. {
  10073. check_ascii = value[0];
  10074. if( (check_ascii < 48) || (check_ascii > 57) )
  10075. {
  10076. isSuccess = ConfigurationStatus_Rejected;
  10077. }
  10078. else
  10079. {
  10080. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10082. isSuccess = ConfigurationStatus_Accepted;
  10083. }
  10084. }
  10085. else
  10086. {
  10087. isSuccess = ConfigurationStatus_Rejected;
  10088. }
  10089. }
  10090. if(strcmp(key, "ResetRetries") == 0)
  10091. {
  10092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10093. {
  10094. check_ascii = value[0];
  10095. if( (check_ascii < 48) || (check_ascii > 57) )
  10096. {
  10097. isSuccess = ConfigurationStatus_Rejected;
  10098. }
  10099. else
  10100. {
  10101. //Charger.ResetRetries = Integer.parseInt(value);
  10102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10103. isSuccess = ConfigurationStatus_Accepted;
  10104. }
  10105. }
  10106. else
  10107. {
  10108. isSuccess = ConfigurationStatus_Rejected;
  10109. }
  10110. }
  10111. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10112. {
  10113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10114. {
  10115. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10116. //int valueLength = strlen(value);
  10117. for(int i = 0; value[i]; i++){
  10118. value[i] = tolower(value[i]);
  10119. }
  10120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10121. isSuccess = ConfigurationStatus_Accepted;
  10122. }
  10123. else
  10124. {
  10125. isSuccess = ConfigurationStatus_Rejected;
  10126. }
  10127. }
  10128. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10129. {
  10130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10131. {
  10132. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10134. isSuccess = ConfigurationStatus_Accepted;
  10135. }
  10136. else
  10137. {
  10138. isSuccess = ConfigurationStatus_Rejected;
  10139. }
  10140. }
  10141. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10142. {
  10143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10144. {
  10145. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10147. isSuccess = ConfigurationStatus_Accepted;
  10148. }
  10149. else
  10150. {
  10151. isSuccess = ConfigurationStatus_Rejected;
  10152. }
  10153. }
  10154. if(strcmp(key, "StopTxnAlignedData") == 0)
  10155. {
  10156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10157. {
  10158. //Charger.StopTxnAlignedData = value.toLowerCase();
  10159. //int valueLength = strlen(value);
  10160. for(int i = 0; value[i]; i++){
  10161. value[i] = tolower(value[i]);
  10162. }
  10163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10164. isSuccess = ConfigurationStatus_Accepted;
  10165. }
  10166. else
  10167. {
  10168. isSuccess = ConfigurationStatus_Rejected;
  10169. }
  10170. }
  10171. if(strcmp(key, "StopTxnSampledData") == 0)
  10172. {
  10173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10174. {
  10175. //Charger.StopTxnSampledData = value.toLowerCase();
  10176. //int valueLength = strlen(value);
  10177. for(int i = 0; value[i]; i++){
  10178. value[i] = tolower(value[i]);
  10179. }
  10180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10181. isSuccess = ConfigurationStatus_Accepted;
  10182. }
  10183. else
  10184. {
  10185. isSuccess = ConfigurationStatus_Rejected;
  10186. }
  10187. }
  10188. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10189. {
  10190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10191. {
  10192. check_ascii = value[0];
  10193. if( (check_ascii < 48) || (check_ascii > 57) )
  10194. {
  10195. isSuccess = ConfigurationStatus_Rejected;
  10196. }
  10197. else
  10198. {
  10199. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10201. TransactionMessageAttemptsValue = atoi(value);
  10202. isSuccess = ConfigurationStatus_Accepted;
  10203. }
  10204. }
  10205. else
  10206. {
  10207. isSuccess = ConfigurationStatus_Rejected;
  10208. }
  10209. }
  10210. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10211. {
  10212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10213. {
  10214. check_ascii = value[0];
  10215. if( (check_ascii < 48) || (check_ascii > 57) )
  10216. {
  10217. isSuccess = ConfigurationStatus_Rejected;
  10218. }
  10219. else
  10220. {
  10221. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10223. TransactionMessageRetryIntervalValue = atoi(value);
  10224. isSuccess = ConfigurationStatus_Accepted;
  10225. }
  10226. }
  10227. else
  10228. {
  10229. isSuccess = ConfigurationStatus_Rejected;
  10230. }
  10231. }
  10232. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10233. {
  10234. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10235. {
  10236. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10238. isSuccess = ConfigurationStatus_Accepted;
  10239. }
  10240. else
  10241. {
  10242. isSuccess = ConfigurationStatus_Rejected;
  10243. }
  10244. }
  10245. if(strcmp(key, "WebSocketPingInterval") == 0)
  10246. {
  10247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10248. {
  10249. check_ascii = value[0];
  10250. if( (check_ascii < 48) || (check_ascii > 57) )
  10251. {
  10252. isSuccess = ConfigurationStatus_Rejected;
  10253. }
  10254. else
  10255. {
  10256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10257. isSuccess = ConfigurationStatus_Accepted;
  10258. }
  10259. }
  10260. else
  10261. {
  10262. isSuccess = ConfigurationStatus_Rejected;
  10263. }
  10264. }
  10265. #if 0
  10266. //For OCPP Test Case
  10267. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10268. {
  10269. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10270. {
  10271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10272. isSuccess = ConfigurationStatus_Accepted;
  10273. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10274. }
  10275. else
  10276. {
  10277. isSuccess = ConfigurationStatus_Rejected;
  10278. }
  10279. }
  10280. #endif
  10281. #if 1
  10282. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10283. {
  10284. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10285. {
  10286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10287. isSuccess = ConfigurationStatus_Accepted;
  10288. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10289. }
  10290. else
  10291. {
  10292. isSuccess = ConfigurationStatus_Rejected;
  10293. }
  10294. }
  10295. #endif
  10296. return isSuccess;
  10297. }
  10298. int updateSetting(char *key, char *value)
  10299. {
  10300. mtrace();
  10301. int isSuccess = FALSE;
  10302. char string[1000]={0}, buffer[1000]={0};
  10303. char strtemp[50]={0};
  10304. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10305. int pos, c = 0;
  10306. char *loc;
  10307. int pos1=0;
  10308. FILE *f = fopen("/var/www/settings1", "r");
  10309. if(f == NULL)
  10310. {
  10311. #ifdef Debug
  10312. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10313. #endif
  10314. return isSuccess;
  10315. }
  10316. fseek(f, 0, SEEK_END);
  10317. long fsize = ftell(f);
  10318. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10319. fread(string, 1, fsize, f);
  10320. fclose(f);
  10321. string[fsize] = 0;
  10322. loc = strstr(string, key);
  10323. if(loc != NULL)
  10324. {
  10325. DEBUG_INFO("key exist!\n");
  10326. pos = loc - string-1;
  10327. f = fopen("/var/www/settings1", "w");
  10328. strncpy(buffer, string, pos);
  10329. fprintf(f, "%s", buffer);
  10330. memset(sstr ,0, sizeof(sstr) );
  10331. c = 0;
  10332. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10333. {
  10334. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10336. c++;
  10337. }
  10338. sstr[c] = '\0';
  10339. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10340. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10341. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10342. memset(buffer ,0, sizeof(buffer) );
  10343. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10344. //printf("buffer=%s",buffer);
  10345. fprintf(f, "%s", buffer);
  10346. fclose(f);
  10347. }
  10348. else
  10349. {
  10350. printf("key not exist!\n");
  10351. f = fopen("/var/www/settings1", "w+");
  10352. fputs(string, f);
  10353. fseek(f, -1, SEEK_CUR);
  10354. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10355. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10356. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10357. fclose(f);
  10358. }
  10359. isSuccess = TRUE;
  10360. return isSuccess;
  10361. }
  10362. int TransactionMessageAttemptsGet(void)
  10363. {
  10364. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10365. }
  10366. int FirstHeartBeatResponse(void)
  10367. {
  10368. return FirstHeartBeat;
  10369. }
  10370. int TransactionMessageRetryIntervalGet(void)
  10371. {
  10372. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10373. }
  10374. #define SA struct sockaddr
  10375. #define MAXBUF 1024
  10376. //static int m_socket_data;
  10377. //static int sockfd;
  10378. int ReadHttpStatus(int sock){
  10379. //char c;
  10380. char buff[1024]="",*ptr=buff+1;
  10381. int bytes_received, status;
  10382. DEBUG_INFO("Begin Response ..\n");
  10383. while((bytes_received = recv(sock, ptr, 1, 0))){
  10384. if(bytes_received==-1){
  10385. perror("ReadHttpStatus");
  10386. exit(1);
  10387. }
  10388. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10389. ptr++;
  10390. }
  10391. *ptr=0;
  10392. ptr=buff+1;
  10393. sscanf(ptr,"%*s %d ", &status);
  10394. DEBUG_INFO("%s\n",ptr);
  10395. DEBUG_INFO("status=%d\n",status);
  10396. DEBUG_INFO("End Response ..\n");
  10397. return (bytes_received>0)?status:0;
  10398. }
  10399. //the only filed that it parsed is 'Content-Length'
  10400. int ParseHeader(int sock){
  10401. //char c;
  10402. char buff[1024]="",*ptr=buff+4;
  10403. int bytes_received;
  10404. DEBUG_INFO("Begin HEADER ..\n");
  10405. while((bytes_received = recv(sock, ptr, 1, 0))){
  10406. if(bytes_received==-1){
  10407. perror("Parse Header");
  10408. exit(1);
  10409. }
  10410. if(
  10411. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10412. (ptr[-1]=='\r') && (*ptr=='\n' )
  10413. ) break;
  10414. ptr++;
  10415. }
  10416. *ptr=0;
  10417. ptr=buff+4;
  10418. //printf("%s",ptr);
  10419. if(bytes_received){
  10420. ptr=strstr(ptr,"Content-Length:");
  10421. if(ptr){
  10422. sscanf(ptr,"%*s %d",&bytes_received);
  10423. }else
  10424. bytes_received=-1; //unknown size
  10425. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10426. }
  10427. DEBUG_INFO("End HEADER ..\n");
  10428. return bytes_received ;
  10429. }
  10430. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10431. {
  10432. char rmFileCmd[100]={0};
  10433. char ftpbuf[200];
  10434. int systemresult;
  10435. DEBUG_INFO("filename=%s\n",filename);
  10436. DEBUG_INFO("url=%s\n",url);
  10437. if((access(filename,F_OK))!=-1)
  10438. {
  10439. DEBUG_INFO("filename=%s exist.\n",filename);
  10440. sprintf(rmFileCmd,"rm -f %s",filename);
  10441. system(rmFileCmd);
  10442. }
  10443. memset(ftpbuf, 0, sizeof(ftpbuf));
  10444. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10445. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10446. systemresult = system(ftpbuf);
  10447. DEBUG_INFO("systemresult=%d\n",systemresult);
  10448. if(systemresult != 0)
  10449. {
  10450. DEBUG_INFO("http DownLoad error!\n");
  10451. return FALSE;
  10452. }
  10453. return TRUE;
  10454. }
  10455. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10456. {
  10457. char rmFileCmd[100]={0};
  10458. char ftpbuf[200];
  10459. int systemresult;
  10460. //char temp[100];
  10461. #if 0
  10462. struct hostent* server;
  10463. char *IPbuffer;
  10464. server = gethostbyname(location);
  10465. // To convert an Internet network
  10466. // address into ASCII string
  10467. IPbuffer = inet_ntoa(*((struct in_addr*)
  10468. server->h_addr_list[0]));
  10469. #endif
  10470. if((access(filename,F_OK))!=-1)
  10471. {
  10472. DEBUG_INFO("filename=%s exist.\n",filename);
  10473. sprintf(rmFileCmd,"rm -f %s",filename);
  10474. system(rmFileCmd);
  10475. }
  10476. memset(ftpbuf, 0, sizeof(ftpbuf));
  10477. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10478. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10479. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10480. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10481. systemresult = system(ftpbuf);
  10482. DEBUG_INFO("systemresult=%d\n",systemresult);
  10483. if(systemresult != 0)
  10484. {
  10485. printf("ftpget error!\n");
  10486. return FALSE;
  10487. }
  10488. return TRUE;
  10489. }
  10490. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10491. {
  10492. struct hostent* server;
  10493. char *IPbuffer;
  10494. char ftpbuf[200];
  10495. int systemresult;
  10496. // To retrieve host information
  10497. server = gethostbyname(location);
  10498. // To convert an Internet network
  10499. // address into ASCII string
  10500. IPbuffer = inet_ntoa(*((struct in_addr*)
  10501. server->h_addr_list[0]));
  10502. memset(ftpbuf, 0, sizeof(ftpbuf));
  10503. /* format : ftpput -u username -p passwd IP target source*/
  10504. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10505. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10506. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10507. systemresult = system(ftpbuf);
  10508. DEBUG_INFO("systemresult=%d\n",systemresult);
  10509. if(systemresult != 0)
  10510. {
  10511. DEBUG_INFO("ftpput error!\n");
  10512. return FALSE;
  10513. }
  10514. return TRUE;
  10515. }
  10516. int SettingChargingRecord(int target, int transactionId)
  10517. {
  10518. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  10519. {
  10520. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10521. {
  10522. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10523. {
  10524. addBuff(target, transactionId, 0);
  10525. return TRUE;
  10526. }
  10527. }
  10528. for (int index = 0; index < CCS_QUANTITY; index++)
  10529. {
  10530. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10531. {
  10532. addBuff(target, transactionId, 0);
  10533. return TRUE;
  10534. }
  10535. }
  10536. for (int index = 0; index < GB_QUANTITY; index++)
  10537. {
  10538. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10539. {
  10540. addBuff(target, transactionId, 0);
  10541. return TRUE;
  10542. }
  10543. }
  10544. }
  10545. else
  10546. {
  10547. for (int index = 0; index < AC_QUANTITY; index++)
  10548. {
  10549. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10550. {
  10551. addBuff(target, transactionId, 0);
  10552. return TRUE;
  10553. }
  10554. }
  10555. }
  10556. return FALSE;
  10557. }
  10558. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10559. {
  10560. int isSuccess = FALSE;
  10561. //char *query = NULL;
  10562. sqlite3_stmt *stmt;
  10563. int rc; // return code
  10564. char str[20];
  10565. sprintf(str,"%d",user_id);
  10566. 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 */
  10567. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10568. rc = sqlite3_step(stmt); /* 3 */
  10569. if (rc != SQLITE_DONE) {
  10570. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10571. goto out;
  10572. }
  10573. sqlite3_finalize(stmt);
  10574. // free(query);
  10575. out:
  10576. //----------------------
  10577. // close SQLite database
  10578. //----------------------
  10579. sqlite3_close(db);
  10580. printf("database closed.\n");
  10581. return isSuccess;
  10582. }
  10583. /**
  10584. * Place the contents of the specified file into a memory buffer
  10585. *
  10586. * @param[in] filename The path and name of the file to read
  10587. * @param[out] filebuffer A pointer to the contents in memory
  10588. * @return status 0 success, 1 on failure
  10589. */
  10590. int get_file_contents(const char* filename, char** outbuffer) {
  10591. FILE* file = NULL;
  10592. long filesize;
  10593. const int blocksize = 1;
  10594. size_t readsize;
  10595. char* filebuffer;
  10596. // Open the file
  10597. file = fopen(filename, "r");
  10598. if (NULL == file)
  10599. {
  10600. printf("'%s' not opened\n", filename);
  10601. exit(EXIT_FAILURE);
  10602. }
  10603. // Determine the file size
  10604. fseek(file, 0, SEEK_END);
  10605. filesize = ftell(file);
  10606. rewind (file);
  10607. // Allocate memory for the file contents
  10608. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10609. *outbuffer = filebuffer;
  10610. if (filebuffer == NULL)
  10611. {
  10612. fputs ("malloc out-of-memory", stderr);
  10613. exit(EXIT_FAILURE);
  10614. }
  10615. // Read in the file
  10616. readsize = fread(filebuffer, blocksize, filesize, file);
  10617. if (readsize != filesize)
  10618. {
  10619. fputs ("didn't read file completely",stderr);
  10620. exit(EXIT_FAILURE);
  10621. }
  10622. // Clean exit
  10623. fclose(file);
  10624. return EXIT_SUCCESS;
  10625. }
  10626. static int selectSqlCount = 0;
  10627. static int callback(void *data, int argc, char **argv, char **azColName){
  10628. int i;
  10629. printf("%s: ", (const char*)data);
  10630. selectSqlCount = argc;
  10631. for(i = 0; i<argc; i++){
  10632. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10633. }
  10634. printf("\n");
  10635. return 0;
  10636. }
  10637. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10638. //int i;
  10639. //printf("%s:\n", (const char*)data);
  10640. localversion = argv[5] ? atoi(argv[5]) : 0;
  10641. printf("localversion=%d\n", localversion);
  10642. return 0;
  10643. }
  10644. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10645. //int i;
  10646. //printf("%s:\n", (const char*)data);
  10647. //idTag
  10648. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10649. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10650. //parentIdTag
  10651. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10652. //expir_date
  10653. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10654. //status
  10655. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10656. //version
  10657. idTagQuery.listVersionInt = atoi(argv[5]);
  10658. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10659. return 0;
  10660. }
  10661. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10662. int i;
  10663. //printf("%s:\n", (const char*)data);
  10664. #if 1
  10665. for(i=0; i<argc; i++){
  10666. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10667. }
  10668. //printf("");
  10669. #endif
  10670. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10671. // printf("localversion=%d\n", localversion);
  10672. return 0;
  10673. }
  10674. /** sqlite3_exec?„å?è°ƒã€?
  10675. *
  10676. * ?‘控?¶å�°?“å�°?¥è¯¢?„ç??œã€?
  10677. *
  10678. * @param in data 传递ç??žè??½æ•°?„æ•°?®ã€?
  10679. * @param in n_columns sqlite3_exec?§è?结æ??†ä¸­?—ç??°é???
  10680. * @param in col_values sqlite3_exec?§è?结æ??†ä¸­æ¯�ä??—ç??°æ�®??
  10681. * @param in col_names sqlite3_exec?§è?结æ??†ä¸­æ¯�ä??—ç??�ç§°??
  10682. * @return ?¶æ€�ç???
  10683. */
  10684. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10685. {
  10686. for (int i = 0; i < n_columns; i++)
  10687. {
  10688. DEBUG_INFO("%s/t", col_values[i]);
  10689. }
  10690. DEBUG_INFO("/n");
  10691. return 0;
  10692. }
  10693. void OCPP_getListVerion()
  10694. {
  10695. int rc = 0;
  10696. // const char* data = "Callback function called";
  10697. char sql[100];
  10698. char zErrMsg[100];
  10699. memset(sql, 0, 100);
  10700. memset(zErrMsg, 0, 100);
  10701. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10702. /* Execute SQL statement */
  10703. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10704. DEBUG_INFO("rc=%d\n",rc);
  10705. if( rc != SQLITE_OK ){
  10706. DEBUG_INFO("SQL error: %s", zErrMsg);
  10707. //sqlite3_free(zErrMsg);
  10708. }else{
  10709. DEBUG_INFO("Operation done successfully");
  10710. }
  10711. }
  10712. void OCPP_getIdTag(char *idTag)
  10713. {
  10714. int rc = 0;
  10715. // const char* data = "Callback function called";
  10716. char sql[100];
  10717. char zErrMsg[100];
  10718. memset(sql, 0, 100);
  10719. memset(zErrMsg, 0, 100);
  10720. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10721. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10722. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10723. /* Execute SQL statement */
  10724. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10725. if( rc != SQLITE_OK ){
  10726. DEBUG_INFO("SQL error: %s", zErrMsg);
  10727. //sqlite3_free(zErrMsg);
  10728. }else{
  10729. printf("Operation done successfully");
  10730. }
  10731. //return ver;
  10732. }
  10733. void OCPP_get_TableAuthlocalAllData(void)
  10734. {
  10735. int rc = 0;
  10736. // const char* data = "Callback function called";
  10737. char sql[100];
  10738. char zErrMsg[100];
  10739. memset(sql, 0, 100);
  10740. memset(zErrMsg, 0, 100);
  10741. sprintf(sql,"select * from ocpp_auth_local ");
  10742. /* Execute SQL statement */
  10743. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10744. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10745. if( rc != SQLITE_OK ){
  10746. DEBUG_INFO("SQL error: %s", zErrMsg);
  10747. //sqlite3_free(zErrMsg);
  10748. }else{
  10749. DEBUG_INFO("Operation done successfully");
  10750. }
  10751. //return ver;
  10752. }
  10753. int OCPP_cleanLocalList()
  10754. {
  10755. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10756. char *errMsg = 0;
  10757. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10758. if (SQLITE_OK != rc)
  10759. {
  10760. DEBUG_INFO("%s\n",errMsg);
  10761. return FALSE;
  10762. }
  10763. else
  10764. {
  10765. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10766. }
  10767. return TRUE;
  10768. }
  10769. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10770. {
  10771. int isSuccess = FALSE;
  10772. int ret = 0;
  10773. //const char* data = "Callback function called";
  10774. char sql[200];
  10775. char zErrMsg[100];
  10776. memset(sql, 0, 200);
  10777. memset(zErrMsg, 0, 100);
  10778. 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);
  10779. //* Execute SQL statement */
  10780. //zErrMsg = 0;
  10781. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10782. if( ret != SQLITE_OK ){
  10783. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10784. // free(zErrMsg);
  10785. // free(sql);
  10786. return isSuccess;
  10787. }
  10788. DEBUG_INFO("successfully Insert records created\n");
  10789. isSuccess = TRUE;
  10790. return isSuccess;
  10791. }
  10792. void OCPP_deleteIdTag(char *idTag)
  10793. {
  10794. //int ver = 0;
  10795. //int isSuccess = FALSE;
  10796. int rc = 0;
  10797. char sql[100];
  10798. char zErrMsg[100];
  10799. memset(sql, 0, 100);
  10800. memset(zErrMsg, 0, 100);
  10801. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10802. //* Execute SQL statement */
  10803. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10804. if( rc != SQLITE_OK ){
  10805. DEBUG_INFO("SQL error: %s", zErrMsg);
  10806. //sqlite3_free(zErrMsg);
  10807. }else{
  10808. DEBUG_INFO("Operation done successfully");
  10809. }
  10810. }
  10811. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10812. {
  10813. int isSuccess = FALSE;
  10814. int ret = 0;
  10815. const char* data = "Callback function called";
  10816. char sql[200];
  10817. char zErrMsg[100];
  10818. memset(sql, 0, 200);
  10819. memset(zErrMsg, 0, 100);
  10820. //* selectFromTable */
  10821. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10822. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10823. //* Execute SQL statement */
  10824. selectSqlCount = 0;
  10825. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10826. if( ret != SQLITE_OK ){
  10827. printf("Error SQL: %s\n", zErrMsg);
  10828. }
  10829. printf("successfully select operation done\n");
  10830. memset(sql, 0, 200);
  10831. memset(zErrMsg, 0, 100);
  10832. if(selectSqlCount == 0)
  10833. {
  10834. //Insert
  10835. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  10836. 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);
  10837. DEBUG_INFO("sql:%s\n", sql);
  10838. //* Execute SQL statement */
  10839. //zErrMsg = 0;
  10840. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10841. if( ret != SQLITE_OK ){
  10842. printf("SQL error: %s\n", zErrMsg);
  10843. return isSuccess;
  10844. }
  10845. DEBUG_INFO("successfully Insert records created\n");
  10846. isSuccess = TRUE;
  10847. }
  10848. else
  10849. {
  10850. //Update
  10851. //* Create merged SQL statement */
  10852. 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);
  10853. /* Execute SQL statement */
  10854. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10855. if( ret != SQLITE_OK ){
  10856. printf("SQL error: %s\n", zErrMsg);
  10857. //sqlite3_free(zErrMsg);
  10858. //sqlite3_free(sql);
  10859. return isSuccess;
  10860. }
  10861. DEBUG_INFO("Successfully operation done \n");
  10862. isSuccess = TRUE;
  10863. }
  10864. return isSuccess;
  10865. }
  10866. char *GetOcppServerURL()
  10867. {
  10868. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10869. memset(OcppHost, 0, sizeof(OcppHost));
  10870. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10871. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10872. {
  10873. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10874. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10875. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10876. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10877. DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10878. DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10879. DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10880. DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10881. goto End;
  10882. }
  10883. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10884. {
  10885. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10886. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10887. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10888. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10889. DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10890. DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10891. DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10892. DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10893. goto End;
  10894. }
  10895. else
  10896. {
  10897. strcpy(OcppHost,"");
  10898. }
  10899. End:
  10900. return OcppHost;
  10901. }
  10902. char *GetOcppPath()
  10903. {
  10904. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10905. {
  10906. if(OcppTempPath == NULL)
  10907. {
  10908. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10909. }
  10910. else
  10911. {
  10912. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10913. }
  10914. goto End;
  10915. }
  10916. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10917. {
  10918. if(OcppTempPath == NULL)
  10919. {
  10920. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10921. }
  10922. else
  10923. {
  10924. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10925. }
  10926. goto End;
  10927. }
  10928. else
  10929. {
  10930. strcpy(OcppHost,"");
  10931. }
  10932. End:
  10933. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10934. return OcppPath;
  10935. }
  10936. int GetOcppPort()
  10937. {
  10938. return OcppPort;
  10939. }
  10940. int GetOcppConnStatus(void)
  10941. {
  10942. return ShmOCPP16Data->OcppConnStatus;
  10943. }
  10944. void SetOcppConnStatus(uint8_t status)
  10945. {
  10946. ShmOCPP16Data->OcppConnStatus = status;
  10947. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  10948. if(status == FALSE)
  10949. {
  10950. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  10951. {
  10952. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  10953. }
  10954. else
  10955. {
  10956. SystemInitial = AC_QUANTITY;
  10957. }
  10958. }
  10959. }
  10960. #if 0
  10961. void Send(struct json_object *message)
  10962. {
  10963. printf("Send -1 \n");
  10964. printf("message=%s\n",json_object_to_json_string(message));
  10965. LWS_Send(json_object_to_json_string(message));
  10966. }
  10967. #endif
  10968. void LWS_Send(char * str)
  10969. {
  10970. #if 1
  10971. //=====================================================
  10972. // Check InternetConn 0: disconnected, 1: connected
  10973. //====================================================
  10974. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  10975. {
  10976. DEBUG_INFO("\n offline now !!!\n");
  10977. return;
  10978. }
  10979. #endif
  10980. pthread_mutex_lock(&lock);
  10981. memset(SendBuffer,0,SendBufLen);
  10982. sprintf((char *)SendBuffer, "%s", str);
  10983. pthread_mutex_unlock(&lock);
  10984. lws_callback_on_writable(wsi_client);
  10985. lws_service(context, 10000);//timeout_ms
  10986. //usleep(10000); // 等�??��?微�?
  10987. //DEBUG_INFO("Send message end\n");
  10988. }