12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213 |
- /*
- * main.c
- *
- * Created on: 2020年9月10日
- * Author: Wendell
- */
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <stdint.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include "../../define.h"
- #include "Config.h"
- #include <stdbool.h>
- #include <dirent.h>
- #include "timeout.h"
- #include "Module_EvComm.h"
- #include "Module_CabinetParallel.h"
- #include "Common.h"
- #define BTN_RELEASE 0
- #define BTN_PRESS 1
- #define MAX_BUF 64
- #define MtdBlockSize 0x300000
- #define SYSFS_GPIO_DIR "/sys/class/gpio"
- #define UPGRADE_FAN 0x02
- #define UPGRADE_RB 0x03
- #define UPGRADE_PRI 0x04
- #define UPGRADE_AC 0x05
- #define UPGRADE_LED 0x06
- #define UPGRADE_DORC1 0x07
- #define UPGRADE_DORC2 0x08
- #define UPGRADE_DDRB 0x09
- #define SYSTEM_MIN_VOL 150
- #define MIN_OUTPUT_CUR 0
- #define AC_OUTPUT_VOL 220
- #define NO_DEFINE 255
- #define DEFAULT_AC_INDEX 2
- #define PSU_MIN_CUR 100
- #define MAIN_PRIORITY_INTERVAL 5
- #define CABINET_ROLE_TIMEOUT 3 // unit: 1s
- #define GUN_PREPARE_TIMEOUT 30
- #define GUN_EV_WAIT_TIMEOUT (120 + 10)
- #define GUN_EVSE_WAIT_TIMEOUT (60 + 10)
- #define GUN_COMP_WAIT_TIMEOUT 10
- #define GUN_PRECHARGING_TIMEOUT 60
- #define REBOOT_TIMEOUT 10
- #define RESET_TIMEOUT 10
- #define OCPP_COST_REQ_INTERVAL 1
- #define DISPENSER_RECONNECTE_TIME 30
- #define DISPENSER_AUTH_COMP_TIME 3
- #define FORCE_BALANCE_TIME 5
- #define DISPENSER_UPGRADE_TIME 600
- #define AC_CONTACTOR_REOPEN_TIME 60
- #define PSU_FAILURE_RESUME_TIME 180
- #define MAX_AC_CONTACTOR_COUNT 3
- #define STANDBY_TIME 600
- #define FAST_STANDBY_TIME 10
- #define E4U_STANDBY_TIME 1800
- #define WIRING_INFO_DELAY 30
- #define WAIT_REASSIGN_TIME 40 // unit: second
- #define MAX_REQUEST_CHARGING_TIME 15 // unit: second
- #define MIN_WAIT_PREPARNING_TIME 1 // unit: second
- #define FORCE_CHARGING_CMD_DELAY 3 // unit: second
- #define FORCE_CHARGING_WAIT_EVSE 10 // unit: second
- #define TRY_RESET_4G_WIFI_TIME 300 // unit: second
- #define FAST_RESET_4G_WIFI_TIME 60 // unit: second
- #define ENERAGY_INTERVAL 1 // unit: second
- #define FAULT_RELEASE_TIME 2 // unit: second
- #define MAINTAIN_RECOVERY_TIME 1 // unit: second
- #define PARALLEL_WAIT_TIME 3 // unit: second
- #define START_UPGRADE_TIME 60 // unit: second
- #define PCABINET_UPGRADE_TIME 300 // unit: second
- #define MCABINET_UPGRADE_TIME 60 // unit: second
- #define CONNECTION_TIME_OFFSET 5 // unit: second
- #define PLUG_IN_HOLD_TIME 1 // unit: second
- #define FINAL_COST_TIMEOUT 3 // unit: second
- #define FINAL_COST_UPDATE_TIME 10 // unit: second
- #define MAX_FINAL_COST_MISC_COUNT 3
- #define PARKING_STATUS_TIMEOUT 3 // unit: second
- #define OCCUPANCY_FEE_TIMEOUT 10 // unit: second
- #define MIN_AVAILABLE_MEMORY 200 // unit: MB
- #define AUTO_START_CHARGING "AutoStartCharging"
- #define CONTACTOR_AUTO_ON_OFF 0
- #define CONTACTOR_AUTO_ON_TIME 60
- #define CONTACTOR_AUTO_OFF_TIME 300
- #define WAIT_DISPENSER_STOP_TIMEOUT 3 // unit: second
- #define STARTTRANSATION_TIME 1
- #define STOP_TARTTRANSATION_DELAY 2
- #define WAIT_DIAGNOSTICS_CONFIRM 10 // unit: second
- #define WAIT_DIAGNOSTICS_TIMEOUT 120 // unit: second
- char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
- unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
- int whileLoopTime = 10000; // 10 ms
- int wtdFd = -1;
- byte _authorizeIndex = NO_DEFINE;
- BOOL _UpgradeNeedReboot = FALSE;
- bool _isBridgeModeConfig = false;
- #define GUN_DERATING_COUNT 2
- const int GunDeratingTemp[GUN_DERATING_COUNT] = {80, 85};
- const byte Group_to_Location_2_Gun[GENERAL_GUN_QUANTITY] = {0, 1, 0, 0};
- const byte Location_to_Group_2_Gun[GENERAL_GUN_QUANTITY] = {0, 1, 0, 0};
- const byte GroupParallelRelay_2_Gun[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- {
- {0, 1, 0, 0},
- {1, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0}
- };
- //Location: 1 2 3 4
- // Gun: 1 3 4 2
- //Parallel: 1 2 3
- //const byte Group_to_Location_4_Gun[GENERAL_GUN_QUANTITY] = {0, 3, 1, 2};
- //const byte Location_to_Group_4_Gun[GENERAL_GUN_QUANTITY] = {0, 2, 3, 1};
- //const byte GroupParallelRelay_4_Gun[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- //{
- // {0, 3, 1, 2}, // group 0
- // {1, 0, 2, 3}, // group 1
- // {1, 3, 0, 2}, // group 2
- // {1, 3, 2, 0} // group 3
- //};
- //Location: 1 2 3 4
- // Gun: 1 4 3 2
- //Parallel: 1 2 3
- const byte Group_to_Location_4_Gun[GENERAL_GUN_QUANTITY] = {0, 3, 2, 1};
- const byte Location_to_Group_4_Gun[GENERAL_GUN_QUANTITY] = {0, 3, 2, 1};
- const byte GroupParallelRelay_4_Gun[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- {
- {0, 3, 2, 1}, // group 0
- {1, 0, 3, 2}, // group 1
- {1, 3, 0, 2}, // group 2
- {1, 3, 2, 0} // group 3
- };
- const byte GroupParallelRelay_4_Gun_6Parallel[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- {
- {0, 4, 6, 1}, // group 0
- {4, 0, 3, 5}, // group 1
- {6, 3, 0, 2}, // group 2
- {1, 5, 2, 0} // group 3
- };
- long long DiffTimebWithNow(struct timeb ST);
- unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
- void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
- void ChargingTerminalProcess(byte gunIndex);
- void ChkPrimaryStatus();
- void ChargingAlarmProcess(byte gunIndex);
- void InformOcppErrOccur(byte codeType);
- void SetOcppErrorCode(unsigned char _index, char *errCode);
- void SetOcppVendorErrorCode(unsigned char _index, char *vendorCode);
- void ReleaseAlarmCode(byte gunIndex);
- int DB_Open(sqlite3 *db);
- int DB_Insert_Record(sqlite3 *db, int gun_index);
- int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
- int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
- void DB_Update_LocalConsumption(sqlite3 *db, uint8_t gun_index, float value);
- void DB_Update_GunConsumption(sqlite3 *db, uint8_t gun_index, float value);
- float DB_Get_LocalConsumption(sqlite3 *db, uint8_t gun_index);
- float DB_Get_GunConsumption(sqlite3 *db, uint8_t gun_index);
- float Get_PowerConsumption(uint8_t gun_index);
- void Update_PowerConsumption(uint8_t gun_index);
- int DB_Insert_FinalCost(sqlite3 *db, uint8_t gun_index, int txId, char *description);
- int DB_Update_FinalCost_Status(sqlite3 *db, int txId, int status);
- int DB_Get_Undisposed_FinalCost(sqlite3 *db, int gunIndex, char *costString);
- int DB_Reboot_Record(sqlite3 *db);
- int DB_Insert_Ocmf(sqlite3 *db, int gun_index, char *txId, char *ocmfKey, char *ocmfInfo);
- int DB_Update_Ocmf_Status(sqlite3 *db, char *txId, int status);
- int DB_Get_Undisposed_Ocmf(sqlite3 *db, int *gunIndex, char *txId, char *ocmfKey, char *ocmfInfo);
- void InitialDHCP();
- void InitialDispenserDhcpServerConfig(void);
- void StartDispenserDhcpServer(void);
- int GetStartScheduleTime(unsigned char *time);
- void CheckConnectionTimeout(void);
- bool IsParallelCabinetIdle(void);
- bool IsStandbyEnable(void);
- bool IsGunIdle(int gunIndex, int idleType);
- bool IsDispenserIdle(int dispenserIndex);
- bool IsConnectorWholeIdle(void);
- void SetAcContactor(unsigned char OnOff);
- void UpdateErrorCodeToOcpp(byte index);
- bool CheckConnectorTypeStatus(void);
- void CreateWatchdog(void);
- void TryCloseWatchdog(void);
- void TryFeedWatchdog(void);
- bool IsReadyParalleling(void);
- void SetParallelingStart(void);
- void SetParallelingDone(void);
- void SetPCabinetOutputRelay(unsigned char index, unsigned char OnOff);
- void SetParallelCabinetAcContactor(unsigned char OnOff);
- unsigned short GetTotalParallelCabinetPower(void);
- void MCabinetParallelingProcess(void);
- void SCabinetControllProcess(void);
- bool Is_WebServer_Alive(void);
- void Run_WebServer_Service(void);
- bool Get_Ocpp_ConnectionStatus(void);
- void Run_Ocpp_Service(void);
- bool Is_Ocpp_Task_Alive(void);
- void Kill_Ocpp_Service(void);
- void Run_MaintainOcpp_Service(void);
- bool Is_MaintainOcpp_Task_Alive(void);
- void Kill_MaintainOcpp_Service(void);
- long int Get_Ocpp_procDogTime(void);
- void Clean_Ocpp_procDogTime(void);
- bool Is_Ocpp_BootNotification(void);
- void Clean_Ocpp_BootNotification(void);
- bool Is_Ocpp_ResetReq(void);
- bool Chk_Ocpp_Reset_Type(char *type);
- void Clean_Ocpp_ResetReq(void);
- void Set_Ocpp_AuthorizeReq(void);
- bool Is_Ocpp_AuthorizeConf(void);
- bool Is_Ocpp_Authorize_Status(char *status);
- bool Is_Ocpp_UpdateFirmwareReq(void);
- void Clean_Ocpp_UpdateFirmwareReq(void);
- bool Is_Ocpp_UpdateFirmwareStatus(char *status);
- void Set_Ocpp_UpdateFirmwareStatus(char *status);
- void Clean_Ocpp_UpdateFirmwareStatus(char *status);
- void Set_Ocpp_FirmwareStatusNotificationReq(void);
- bool Is_Ocpp_StopOnInvalidId_Enable(void);
- bool Is_Ocpp_AuthorizeRemoteTxRequests(void);
- int Get_Ocpp_ConnectionTimeOut(void);
- void Get_Ocpp_DefaultPrice(char *defaultPrice);
- void Get_Ocpp_UserPrice(char * userId, char *userPrice);
- void Clean_Ocpp_UserPrice(void);
- void Get_Ocpp_RunningCost(int gun_index, char *cost);
- void Clean_Ocpp_RunningCost(int gun_index);
- void Get_Ocpp_FinalCost(int gun_index, char *cost);
- void Clean_Ocpp_FinalCost(int gun_index);
- int Get_Ocpp_FinalCostTxId(int gun_index);
- void Get_Ocpp_TimeOffset(char *timeOffset);
- void Get_Ocpp_PreAuthAmount(char *amount);
- void Get_Ocpp_PowerSharingServerIP(char *ip);
- void Get_Ocpp_Refunding(char *Refunding);
- void Clean_Ocpp_Refunding(void);
- bool Is_Ocpp_LcdOverideReq(int *gun, int *page);
- void Clean_Ocpp_LcdOverideReq(void);
- void Get_Ocpp_ChargerStationInfo(int *station_id, char *name);
- bool Is_Ocpp_ChargerStationReq(void);
- void Clean_Ocpp_ChargerStationReq(void);
- void Get_Ocpp_WeatherInfo(int *weatherID, float *temperature);
- bool Is_Ocpp_WeatherReq(void);
- void Clean_Ocpp_WeatherReq(void);
- void Set_Ocpp_DeductTransaction(int transaction);
- void Set_Ocpp_DeductCreditNo(char *userId);
- void Set_Ocpp_DeductVemData(char *vemData);
- void Set_Ocpp_DeductAmount(double value);
- void Set_Ocpp_DeductResult(unsigned char result);
- void Set_Ocpp_DonateInvoice(unsigned char donate);
- bool Is_Ocpp_ReportCreditDeductReq(void);
- void Set_Ocpp_ReportCreditDeductReq(void);
- void Clean_Ocpp_TcciSerialNo(int gun_index);
- bool Set_Ocpp_TcciReaderStatus(int gun_index, DeductResultInfoData *ReaderStatus);
- void Clean_Ocpp_TcciCreditInfo(int gun_index);
- void Set_Ocpp_TcciReaderStatusReq(int gun_index);
- bool Is_Ocpp_TcciReaderStatusReq(int gun_index);
- void Set_Ocpp_StartTransactionIdTag(int gun_index, char *id);
- void Set_Ocpp_StartTransactionReq(int gun_index);
- bool Is_Ocpp_StartTransactionConf(int gun_index);
- void Clean_Ocpp_StartTransactionConf(int gun_index);
- bool Is_Ocpp_StartTransaction_Status(int gun_index, char *status);
- bool Is_Ocpp_StartTransaction_Accepted(int gun_index);
- void Get_Ocpp_StartTransaction_Status(int gun_index, char *status);
- void Get_Ocpp_TransactionId(int gun_index, char *transactionId);
- bool Is_Invalid_StartTransactionId(int gun_index);
- void Set_Ocpp_StopTransactionId(int gun_index, char *id);
- void Set_Ocpp_StopTransactionReq(int gun_index);
- void Chk_Ocpp_Backup_ErrorCode(int gun_index);
- bool Is_Ocpp_ReserveNowReq(int gun_index);
- void Clean_Ocpp_ReserveNowReq(int gun_index);
- int Get_Ocpp_ReserveNowId(int gun_index);
- void Set_Ocpp_ReserveNowConf(int gun_index);
- void Get_Ocpp_ReserveNowExpiryDate(int gun_index, char *date);
- bool Is_Ocpp_ReserveNowExpired(int gun_index);
- void Get_Ocpp_ReserveNowIdTag(int gun_index, char *idTag);
- bool Is_Ocpp_ReserveNowIdTag(uint8_t gun_index, char *authIdTag);
- bool Is_Ocpp_CancelReservationReq(int gun_index);
- void Clean_Ocpp_CancelReservationReq(int gun_index);
- void Set_Ocpp_CancelReservationConf(int gun_index);
- bool Is_Ocpp_ChangeAvailabilityReq(int gun_index);
- void Clean_Ocpp_ChangeAvailabilityReq(int gun_index);
- bool Chk_Ocpp_Availability_Type(int gun_index, char *type);
- bool Is_Ocpp_UnlockConnectorReq(int gun_index);
- void Clean_Ocpp_UnlockConnectorReq(int gun_index);
- void Set_Ocpp_UnlockConnectorConf(int gun_index);
- bool Is_Ocpp_RemoteStartReq(int gun_index);
- void Clean_Ocpp_RemoteStartReq(int gun_index);
- void Get_Ocpp_RemoteStartIdTag(int gun_index, char *idTag);
- bool Is_Ocpp_RemoteStopReq(int gun_index);
- void Clean_Ocpp_RemoteStopReq(int gun_index);
- void Set_Ocpp_StopReason(int gun_index, char *reason);
- void Get_Ocpp_StopReason(int gun_index, char *reason);
- void Clean_Ocpp_StopReason(int gun_index);
- void Set_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode);
- bool Is_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode);
- void Set_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode);
- bool Is_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode);
- bool Is_Ocpp_ChargingProfileConf(int gun_index);
- void Clean_Ocpp_ChargingProfileConf(int gun_index);
- bool Is_Ocpp_ChargingProfileReq(int gun_index);
- void Set_Ocpp_ChargingProfileReq(int gun_index);
- bool Is_Ocpp_ChargingProfileKind(int gun_index, char *kind);
- bool Is_Ocpp_ChargingProfileId(int gun_index);
- int Get_Ocpp_ChargingProfileStartTime(int gun_index);
- int Get_Ocpp_ChargingProfileScheduleCount(int gun_index);
- int Get_Ocpp_ChargingProfileScheduleTime(int gun_index, int schedule_index);
- float Get_Ocpp_ChargingProfileScheduleLimit(int gun_index, int schedule_index);
- int Get_Ocpp_ChargingProfileScheduleNumberPhases(int gun_index, int schedule_index);
- int Get_Ocpp_ChargingProfileStartIndex(int gun_index);
- bool Is_Ocpp_MaxChargingProfileKind(char *kind);
- bool Is_Ocpp_MaxChargingProfileId(void);
- int Get_Ocpp_MaxProfileStartTime(void);
- int Get_Ocpp_MaxProfileScheduleCount(void);
- int Get_Ocpp_MaxProfileScheduleTime(int schedule_index);
- float Get_Ocpp_MaxProfileScheduleLimit(int schedule_index);
- int Get_Ocpp_MaxProfileScheduleNumberPhases(int schedule_index);
- int Get_Ocpp_MaxProfileStartIndex(void);
- int Is_Ocpp_RemoteStartWaitReq(void);
- void Get_Ocpp_SessionTarget(int gunIndex, struct StructSessionTarget *sessionTarget);
- int Get_Ocpp_OffLineMaxChargingPower(void);
- bool Is_Ocpp_SendOcmfDataReq(int gunIndex);
- void Set_Ocpp_SendOcmfDataReq(int gunIndex);
- void Clean_Ocpp_SendOcmfDataReq(int gunIndex);
- void Set_Ocpp_OcmfData(int gunIndex, char *key, char *ocmfInfo);
- void Set_Deduct_UserId(int gunIndex, char *userId);
- void Set_Deduct_TransactionId(int gunIndex, int transaction);
- void Clean_DeductInfo(int gunIndex);
- bool Is_DeductResultReq(int gunIndex);
- bool Is_ReaderStatusReq(int gunIndex);
- void Clean_ReaderStatusInfo(int gunIndex);
- void Set_UserTransactionId(int gunIndex, int transaction);
- void Set_UserPrice(int gunIndex, float price);
- void Set_UserTotalCost(int gunIndex, float cost);
- void Set_UserAccountBalance(int gunIndex, float balance);
- void Set_UserDiscount(int gunIndex, float discount);
- void Clean_UserTransaction(int gunIndex);
- bool Is_OccupancyDeductReq(int gunIndex);
- void Clean_OccupancyDeductReq(int gunIndex);
- bool Is_OccupancyKeepCountingReq(int gunIndex);
- void Set_OccupancyKeepCountingReq(int gunIndex);
- void Clean_OccupancyKeepCountingReq(int gunIndex);
- bool Is_OccupancyFeeForceCancelReq(int gunIndex);
- void Set_OccupancyFeeForceCancelReq(int gunIndex);
- void Clean_OccupancyFeeForceCancelReq(int gunIndex);
- bool Is_Ocpp_GetDiagnosticsReq(void);
- void Clean_Ocpp_GetDiagnosticsReq(void);
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct PsuData *ShmPsuData;
- struct CHAdeMOData *ShmCHAdeMOData;
- struct GBTData *ShmGBTData;
- struct CcsData *ShmCcsData;
- struct PrimaryMcuData *ShmPrimaryMcuData;
- struct FanModuleData *ShmFanModuleData;
- struct RelayModuleData *ShmRelayModuleData[2];
- struct LedModuleData *ShmLedModuleData;
- struct OCPP16Data *ShmOCPP16Data;
- struct OCPP20Data *ShmOCPP20Data;
- struct OCPP16Data *ShmOCPP16DataPH;
- struct MeterInformation *ShmCsuMeterData;
- ChargerInfoData *ShmChargerInfo;
- PsuPositionInfoData *ShmPsuPosition;
- PsuGroupingInfoData *ShmPsuGrouping;
- struct ChargingInfoData *chargingInfo[CONNECTOR_QUANTITY];
- struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
- struct timespec _cmdMainPriority_time;
- struct timespec _cmdSubPriority_time;
- struct timespec _ConnectorAuthorizing_Time[CONNECTOR_QUANTITY];
- struct timespec _ConnectorAuthorizeFail_Time[CONNECTOR_QUANTITY];
- struct timespec _DispenserAuthorizing_Time[CONNECTOR_QUANTITY];
- struct timespec _DispenserUpgrade_time;
- struct timespec _Standby_time;
- struct timespec _SystemStatus_Time[CONNECTOR_QUANTITY];
- struct timespec _ChargedEnergy_Time[CONNECTOR_QUANTITY];
- struct timespec _Parallel_Time;
- struct timespec _RemoteStartNoId_Time;
- float gunOutputVol[CONNECTOR_QUANTITY];
- unsigned char _ocppProfileChkFlag[CONNECTOR_QUANTITY];
- float _lastProfilePower[CONNECTOR_QUANTITY];
- float _lastProfileCurrent[CONNECTOR_QUANTITY];
- float _lastMaxProfilePower;
- float _lsatGunMeterValue[CONNECTOR_QUANTITY];
- struct StructStatusNotification _BackupStatusNotification[CONNECTOR_QUANTITY];
- bool _useGunMeterValue[MAX_GUN_QUANTITY];
- bool _triggerTransaction[MAX_GUN_QUANTITY];
- bool _plugInHold[MAX_GUN_QUANTITY];
- struct timespec _PlugInHold_Time[MAX_GUN_QUANTITY];
- struct timespec _DispenserBill_Time[MAX_DISPENSER_QUANTITY];
- struct timespec _ConnectorBill_Time[MAX_GUN_QUANTITY];
- struct timespec _ParkingStatus_Time[MAX_GUN_QUANTITY];
- struct timespec _GetOccupancyFee_Time[MAX_GUN_QUANTITY];
- struct timespec _Diagnostics_Time;
- bool _canUpdateFinalCost[MAX_DISPENSER_QUANTITY];
- bool _isUndisposedFinalCost[MAX_DISPENSER_QUANTITY];
- int _notifyOccupancyFeeAct[MAX_GUN_QUANTITY];
- bool _NeedReset4gWifi;
- struct timespec _4gWifiReset_time;
- int _psuLostQuantity = 0;
- bool _isStandbyEnable = true;
- bool isModelNameMatch = true;
- bool _NeedDiagnostics = false;
- //int rfidFd = -1;
- //char* rfidPortName = "/dev/ttyS2";
- #if ENABLE_PCBA_TEST == 0
- char* fwVersion = "V2.05.00.0000.00";
- char* subVersion = "03";
- #else
- char* fwVersion = "PCBA.00.04";
- char* subVersion = "00";
- #endif
- sqlite3 *localDb;
- bool isDb_ready;
- sqlite3 *networkDb;
- //================================================
- // initial can-bus
- //================================================
- int InitCanBus()
- {
- int s0,nbytes;
- struct timeval tv;
- struct ifreq ifr0;
- struct sockaddr_can addr0;
- system("/sbin/ip link set can0 down");
- system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
- system("/sbin/ip link set can0 up");
- s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
- tv.tv_sec = 0;
- tv.tv_usec = 10000;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("Set SO_RCVTIMEO NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("Set SO_RCVBUF NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("Set SO_SNDBUF NG");
- #endif
- }
- strcpy(ifr0.ifr_name, "can0" );
- ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
- addr0.can_family = AF_CAN;
- addr0.can_ifindex = ifr0.ifr_ifindex;
- bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
- return s0;
- }
- //================================================
- // initial uart port
- //================================================
- char *_priPortName = "/dev/ttyS1";
- char *_485PortName = "/dev/ttyS5";
- int InitComPort(byte target)
- {
- int fd;
- struct termios tios;
- if(target == UPGRADE_PRI)
- fd = open(_priPortName, O_RDWR);
- else if (target == UPGRADE_FAN || target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED)
- fd = open(_485PortName, O_RDWR);
- if(fd<=0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("open 407 Communication port NG");
- #endif
- return -1;
- }
- ioctl (fd, TCGETS, &tios);
- tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN]=0;
- tios.c_cc[VTIME]=(unsigned char)1;
- tios.c_lflag=0;
- tcflush(fd, TCIFLUSH);
- ioctl (fd, TCSETS, &tios);
- return fd;
- }
- //=================================
- // Common routine
- //=================================
- void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
- {
- strncpy(dest, src + start, cnt);
- dest[cnt] = 0;
- }
- int InitWatchDog()
- {
- int fd;
- int timeout = 180;
- system("/usr/bin/fuser -k /dev/watchdog");
- sleep(1);
- system("echo V > /dev/watchdog");
- sleep(1);
- fd=open("/dev/watchdog", O_RDWR);
- if(fd<=0)
- {
- LOG_ERROR("System watch dog initial fail.\r\n");
- }
- ioctl(fd, _IOWR('W', 6, int), &timeout);
- return fd;
- }
- void setChargerMode(byte gun_index, byte mode)
- {
- chargingInfo[gun_index]->SystemStatus = mode;
- }
- long long DiffTimebWithNow(struct timeb ST)
- {
- //return milli-second
- struct timeb ET;
- long long StartTime,StopTime;
- ftime(&ET);
- StartTime=(long long)ST.time;
- StopTime=(long long)ET.time;
- return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
- }
- //=================================
- // Create all share memory
- //=================================
- int CreateShareMemory()
- {
- int MeterSMId;
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG");
- #endif
- return 0;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG");
- #endif
- return 0;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmStatusCodeData NG");
- #endif
- return 0;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmStatusCodeData NG");
- #endif
- return 0;
- }
- memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
- //creat ShmPsuData
- if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmPsuData NG");
- #endif
- return 0;
- }
- else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmPsuData NG");
- #endif
- return 0;
- }
- memset(ShmPsuData, 0, sizeof(struct PsuData));
- /*
- if(CHAdeMO_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmCHAdeMOData NG");
- #endif
- return 0;
- }
- else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmCHAdeMOData NG");
- #endif
- return 0;
- }
- memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
- }
- if(GB_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmGBTData NG");
- #endif
- return 0;
- }
- else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmGBTData NG");
- #endif
- return 0;
- }
- memset(ShmGBTData, 0, sizeof(struct GBTData));
- }
- //creat ShmCcsData
- if(CCS_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmCcsData NG");
- #endif
- return 0;
- }
- else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmCcsData NG");
- #endif
- return 0;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
- }
- */
- //creat ShmPrimaryMcuData
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmPrimaryMcuData NGn");
- #endif
- return 0;
- }
- else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG");
- #endif
- return 0;
- }
- memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
- //creat ShmFanModuleData
- if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmFanModuleData NG");
- #endif
- return 0;
- }
- else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmFanModuleData NG");
- #endif
- return 0;
- }
- memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
- //creat ShmRelayModuleData
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmRelayModuleData[0] NG");
- #endif
- return 0;
- }
- else if ((ShmRelayModuleData[0] = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmRelayModuleData[0] NG");
- #endif
- return 0;
- }
- memset(ShmRelayModuleData[0], 0, sizeof(struct RelayModuleData));
- // DO360 RC2
- if ((MeterSMId = shmget(ShmRelay2BdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmRelayModuleData[1] NG");
- #endif
- return 0;
- }
- else if ((ShmRelayModuleData[1] = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmRelayModuleData[1] NG");
- #endif
- return 0;
- }
- memset(ShmRelayModuleData[1], 0, sizeof(struct RelayModuleData));
- if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmLedModuleData NG");
- #endif
- return 0;
- }
- else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmLedModuleData NG");
- #endif
- return 0;
- }
- memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
- //creat ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmOCPP16Data NG");
- #endif
- return 0;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmOCPP16Data NG");
- #endif
- return 0;
- }
- memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
- if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0)
- {
- LOG_ERROR("[main]CreatShareMemory:shmget OCPP20Data NG");
- return 0;
- }
- else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- LOG_ERROR("[main]CreatShareMemory:shmat OCPP20Data NG");
- return 0;
- }
- memset(ShmOCPP20Data,0,sizeof(struct OCPP20Data));
- //creat ShmOCPP16DataPH
- if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
- {
- LOG_ERROR("shmget ShmOCPP16DataPH NG");
- return 0;
- }
- else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- LOG_ERROR("shmat ShmOCPP16DataPH NG");
- return 0;
- }
- memset(ShmOCPP16DataPH,0,sizeof(struct OCPP16Data));
- if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ChargerInfoData NG");
- #endif
- return 0;
- }
- else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ChargerInfoData NG");
- #endif
- return 0;
- }
- memset(ShmChargerInfo, 0, sizeof(ChargerInfoData));
- ShmPsuPosition = &ShmChargerInfo->PsuPosition;
- ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
- return 1;
- }
- //======================================================
- // Peripheral initial
- //======================================================
- void InitGPIO()
- {
- /*****************0~3, 4 bank, bank x 32+ num*********************/
- /***************************************************************/
- /*************** GPIO 0 ***************************************/
- /***************************************************************/
- /* GPMC_AD8 => GPIO0_22 *//*ID BD1_1*/ // no use
- system("echo 22 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio22/direction");
- /* GPMC_AD9 => GPIO0_23 *//*ID BD1_2*/ // no use
- system("echo 23 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio23/direction");
- /* GPMC_AD10 => GPIO0_26 *//*IO BD1_1*/ // no use
- system("echo 26 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio26/direction");
- system("echo 1 > /sys/class/gpio/gpio26/value");
- /* GPMC_AD11 => GPIO0_27 *//*IO BD1_2*/ // no use
- system("echo 27 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio27/direction");
- /* RMII1_REF_CLK => GPIO0_29 *//*USB 0 OCP detection*/
- system("echo 29 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio29/direction");
- /*XDMA_EVENT_INTR0 => GPIO0_19 *//*AM_RFID_RST*/ // no use
- system("echo 19 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio19/direction");
- system("echo 1 > /sys/class/gpio/gpio19/value");
- /*XDMA_EVENT_INTR1 => GPIO0_20 *//*AM_RFID_ICC*/ // no use
- system("echo 20 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio20/direction");
- /***************************************************************/
- /*************** GPIO 1 ***************************************/
- /***************************************************************/
- /* GPMC_AD12 => GPIO1_12 *//*ID BD2_1*/ // no use
- system("echo 44 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio44/direction");
- /* GPMC_AD13 => GPIO1_13 *//*ID BD2_2*/ // no use
- system("echo 45 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio45/direction");
- /* GPMC_AD14 => GPIO1_14 *//*IO BD2_1*/ // no use
- system("echo 46 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio46/direction");
- system("echo 0 > /sys/class/gpio/gpio46/value");
- /* GPMC_AD15 => GPIO1_15 *//*IO BD2_2*/ // no use
- system("echo 47 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio47/direction");
- /***************************************************************/
- /*************** GPIO 2 ***************************************/
- /***************************************************************/
- /*LCD_AC_BIAS_EN => GPIO2_25*//*RS-485 for module DE control*/
- system("echo 89 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio89/direction");
- system("echo 1 > /sys/class/gpio/gpio89/value");
- /*LCD_HSYNC => GPIO2_23*//*RS-485 for module RE control*/
- system("echo 87 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio87/direction");
- system("echo 0 > /sys/class/gpio/gpio87/value");
- /*LCD_PCLK => GPIO2_24*//*CCS communication board 1 proximity*/ // no use
- system("echo 88 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio88/direction");
- /*LCD_VSYNC => GPIO2_22*//*CCS communication board 2 proximity*/ // no use
- system("echo 86 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio86/direction");
- /***************************************************************/
- /*************** GPIO 3 ***************************************/
- /***************************************************************/
- /*MCASP0_FSX => GPIO3_15*//*Emergency Stop button detect*/
- system("echo 111 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio111/direction");
- /*MCASP0_ACLKR => GPIO3_18*//*USB1 OCP detect*/
- system("echo 114 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio114/direction");
- /*MCASP0_AHCLKR => GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
- system("echo 113 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio113/direction");
- /*MCASP0_ACLKX => GPIO3_14*//*Ethernet PHY reset*/
- system("echo 110 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio110/direction");
- system("echo 0 > /sys/class/gpio/gpio110/value");
- /* MCASP0_FSR => GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/ // no use
- system("echo 115 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio115/direction");
- system("echo 0 > /sys/class/gpio/gpio115/value");
- /* MCASP0_AXR0 => GPIO3_16 *//*CSU board function OK indicator.*/
- system("echo 112 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio112/direction");
- system("echo 1 > /sys/class/gpio/gpio112/value");
- /* MCASP0_AXR1 => GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/ // no use
- system("echo 116 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio116/direction");
- system("echo 0 > /sys/class/gpio/gpio116/value");
- /* (C14) EMU0.gpio3[7] */ /*CP open/short feature enable/disable, pull low for default enable*/
- system("echo 103 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio103/direction");
- system("echo 0 > /sys/class/gpio/gpio103/value");
- /* (B14) EMU1.gpio3[8] */ /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
- system("echo 104 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio104/direction");
- system("echo 0 > /sys/class/gpio/gpio104/value");
- LOG_INFO("[main]InitGPIO: Initial GPIO OK");
- }
- int LoadSysConfigAndInfo(struct SysConfigData *ptr)
- {
- int fd, wrd;
- unsigned char *buf;
- unsigned int ChkSum, ChkSumOrg;
- if((buf = malloc(MtdBlockSize)) == NULL)
- {
- LOG_ERROR("malloc buffer NG, rebooting..\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- //================================================
- // Load configuration from mtdblock10
- //================================================
- system("nanddump /dev/mtd10 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- LOG_ERROR("open mtdblock10 NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- free(buf);
- LOG_ERROR("read SysConfigData data NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for(wrd = ARRAY_SIZE(ptr->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++)
- {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
- memcpy(&ptr->ModelName, buf + (ARRAY_SIZE(ptr->CsuBootLoadFwRev)), ARRAY_SIZE(ptr->ModelName));
- memcpy(&ptr->SerialNumber, buf + (ARRAY_SIZE(ptr->CsuBootLoadFwRev) + ARRAY_SIZE(ptr->ModelName) + ARRAY_SIZE(ptr->AcModelName)), ARRAY_SIZE(ptr->SerialNumber));
- //================================================
- // Load configuration from mtdblock11
- //================================================
- if(ChkSum != ChkSumOrg)
- {
- LOG_ERROR("Primary SysConfigData checksum NG, read backup\n");
- system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- LOG_ERROR("open mtdblock11 (backup) NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- free(buf);
- LOG_ERROR("read backup SysConfigData data NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for(wrd = ARRAY_SIZE(ptr->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++)
- {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
- //================================================
- // Load configuration from mtdblock12 (Factory default)
- //================================================
- if(ChkSum != ChkSumOrg)
- {
- LOG_ERROR("backup SysConfigData checksum NG, read Factory default\n");
- system("nanddump /dev/mtd12 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- LOG_ERROR("open mtdblock12 (Factory default) NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- free(buf);
- LOG_ERROR("read factory default SysConfigData data NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for(wrd = ARRAY_SIZE(ptr->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++)
- {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
- memcpy(buf + (ARRAY_SIZE(ptr->CsuBootLoadFwRev)), &ptr->ModelName, ARRAY_SIZE(ptr->ModelName));
- memcpy(buf + (ARRAY_SIZE(ptr->CsuBootLoadFwRev) + ARRAY_SIZE(ptr->ModelName) + ARRAY_SIZE(ptr->AcModelName)), &ptr->SerialNumber, ARRAY_SIZE(ptr->SerialNumber));
- if(ChkSum != ChkSumOrg)
- {
- LOG_ERROR("factory default SysConfigData checksum NG, restore factory default\n");
- free(buf);
- system("cd /root;./FactoryConfig -m");
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- return FAIL;
- }
- }
- }
- //load OK
- memcpy((struct SysConfigData *)ptr, buf, sizeof(struct SysConfigData));
- free(buf);
- system("rm -f /mnt/EvseConfig.bin");
- // SysConfig in flash is empty (0xffffffff)
- if((strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName)) ||
- (strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber)) ||
- (strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId)) ||
- (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff))
- {
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName))
- {
- LOG_INFO("Model name over length.");
- memset(ShmSysConfigAndInfo->SysConfig.ModelName, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
- }
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber))
- {
- LOG_INFO("Model serial number over length.");
- memset(ShmSysConfigAndInfo->SysConfig.SerialNumber, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
- }
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId))
- {
- LOG_INFO("System id over length.");
- memset(ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId));
- }
- if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff)
- {
- LOG_INFO("Ethernet dhcp config is null.");
- }
- system("cd /root;./Module_FactoryConfig -m");
- sleep(3);
- system("/usr/bin/run_evse_restart.sh");
- }
- LOG_INFO("Load SysConfigData OK");
- return PASS;
- }
- int isEthernetCablePlugIn(int ethernet)
- {
- int fd, PlugInStatus = 0;
- char ch[2];
- char buffer[64];
- snprintf(buffer, sizeof(buffer), "/sys/class/net/eth%d/carrier", ethernet);
- fd = open(buffer, O_RDONLY);
- if(fd < 0)
- {
- return -1;
- }
- if(read(fd, ch, 1) < 0)
- {
- return -1;
- }
- PlugInStatus = atoi(ch);
- close(fd);
- return PlugInStatus;
- }
- int isRouteFail()
- {
- int result = YES;
- FILE *fp;
- char buf[512];
- fp = popen("route -n", "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, "eth0") != NULL)
- result = NO;
- }
- }
- pclose(fp);
- return result;
- }
- int isReachableInternet()
- {
- int result = FAIL;
- FILE *fp;
- char cmd[256];
- char buf[512];
- char tmp[512];
- // if (ShmOCPP16Data->OcppConnStatus == PASS)
- // {
- // result = PASS;
- // }
- // else
- {
- strcpy(cmd, "ifconfig eth0");
- fp = popen(cmd, "r");
- if (fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if (strstr(buf, "inet addr:") > 0)
- {
- sscanf(buf, "%*s%s", tmp);
- substr(tmp, tmp, strspn(tmp, "addr:"), strlen(tmp)-strspn(tmp, "addr:"));
- if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != EQUAL)
- {
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
- }
- }
- }
- }
- pclose(fp);
- memset(buf, 0x00, sizeof(buf));
- for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
- {
- sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, "transmitted") > 0)
- {
- //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
- if(strstr(buf,"100%") != NULL)
- {
- }
- else
- {
- result = PASS;
- }
- //DEBUG_INFO("%s",buf);
- //DEBUG_INFO("%s\n",tmp);
- }
- }
- }
- pclose(fp);
- }
- }
- return result;
- }
- int isUap0up(void)
- {
- int result = FAIL;
- FILE *fp;
- char cmd[256];
- char buf[512];
- strcpy(cmd, "ifconfig uap0");;
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, "uap0") > 0)
- {
- result = PASS;
- }
- }
- }
- pclose(fp);
- return result;
- }
- void InitialApModeDhcpServerConfig(void)
- {
- system("echo 'start 192.168.10.100' > /etc/udhcpd.conf");
- system("echo 'end 192.168.10.150' >> /etc/udhcpd.conf");
- system("echo 'interface uap0' >> /etc/udhcpd.conf");
- system("echo 'lease_file /var/log/udhcpd.leases'>> /etc/udhcpd.conf");
- system("echo 'opt dns 8.8.8.8' >> /etc/udhcpd.conf");
- system("echo 'option subnet 255.255.255.0' >> /etc/udhcpd.conf");
- system("echo 'opt router 192.168.10.10' >> /etc/udhcpd.conf");
- system("echo 'option domain local' >> /etc/udhcpd.conf");
- system("echo 'option lease 86400' >> /etc/udhcpd.conf");
- usleep(1000);
- }
- void InitialBridgeModeDhcpServerConfig(void)
- {
- system("echo 'start 192.168.10.100' > /etc/udhcpd.conf");
- system("echo 'end 192.168.10.150' >> /etc/udhcpd.conf");
- system("echo 'interface br0' >> /etc/udhcpd.conf");
- system("echo 'lease_file /var/log/udhcpd.leases'>> /etc/udhcpd.conf");
- system("echo 'opt dns 8.8.8.8' >> /etc/udhcpd.conf");
- system("echo 'option subnet 255.255.255.0' >> /etc/udhcpd.conf");
- system("echo 'opt router 192.168.10.10' >> /etc/udhcpd.conf");
- system("echo 'option domain local' >> /etc/udhcpd.conf");
- system("echo 'option lease 86400' >> /etc/udhcpd.conf");
- usleep(1000);
- }
- bool Is_Dispenser_MiscCommand(int dispenser, int misc_cmd)
- {
- return (ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue & misc_cmd) > 0 ? true : false;
- }
- void Set_Dispenser_MiscCommand(int dispenser, int misc_cmd)
- {
- ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue |= misc_cmd;
- }
- void Clean_Dispenser_MiscCommand(int dispenser, int misc_cmd)
- {
- ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue &= ~misc_cmd;
- }
- bool Is_Connector_MiscCommand(int connector, int misc_cmd)
- {
- return (ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue & misc_cmd) > 0 ? true : false;
- }
- void Set_Connector_MiscCommand(int connector, int misc_cmd)
- {
- ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue |= misc_cmd;
- }
- void Clean_Connector_MiscCommand(int connector, int misc_cmd)
- {
- ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue &= ~misc_cmd;
- }
- void AnnounceEthernetStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_ETHERNET_STATUS);
- }
- }
- }
- void AnnounceWiFiStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_WIFI_STATUS);
- }
- }
- }
- void AnnounceTelcomModemStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_TELCOM_MODEM_STATUS);
- }
- }
- }
- void AnnounceBackendStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_BACKEND_STATUS);
- }
- }
- }
- void AnnounceBillingStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_BILLING_STATUS);
- }
- }
- }
- void AnnounceStopChargingButtonStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_STOP_BUTTON_STATUS);
- }
- }
- }
- void AnnounceAuthModeConfig(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_AUTH_MODE_CONFIG);
- }
- }
- }
- void AnnounceEVCCIDConfig(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_EVCCID_CONFIG);
- }
- }
- }
- void AnnounceLEDIntensity(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_LED_INTENSITY);
- }
- }
- }
- void AnnounceCurrency(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_CURRENCY);
- }
- }
- }
- void AnnounceRfidEndian(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_RFID_CARD_ENDIAN);
- }
- }
- }
- void AnnounceRfidReader(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_RFID_ENABLE);
- }
- }
- }
- void AnnounceRemoteStartNoID(void)
- {
- for(int index = 0; index < CONNECTOR_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorID[i] - 1;
- if(chargingInfo[gun]->SystemStatus == S_IDLE)
- {
- ShmChargerInfo->ConnectorPageReq[gun].bits.RemoteStartNoID = true;
- break;
- }
- }
- }
- }
- }
- void AnnounceLineStatusCode(int gun, int status)
- {
- int dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].ParentDispensetIndex;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
- {
- ShmChargerInfo->LineApi.StatusCode[gun] = status;
- Set_Connector_MiscCommand(gun, MISC_CONN_LINE_STATUS);
- }
- }
- void AnnounceStationInfo(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_STATION_INFO);
- }
- }
- }
- void AnnounceOccupancyPrice(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_PARKING_PRICE);
- }
- }
- }
- void UpdateConfigAndIcon(void)
- {
- unsigned char status = _Connnection_Disable;
- // update ethernet connection status
- status = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet == YES ? _Connnection_Disconnected : _Connnection_Connected;
- if(ShmChargerInfo->CabinetMiscValue.EthernetStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.EthernetStatus = status;
- AnnounceEthernetStatus();
- }
- // update wifi connection status
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- status = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? _Connnection_Disconnected : _Connnection_Connected;
- }
- else
- {
- status = _Connnection_Disable;
- }
- if(ShmChargerInfo->CabinetMiscValue.WiFiStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.WiFiStatus = status;
- AnnounceWiFiStatus();
- }
- // update 4g connection status
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- status = (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == NO &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES) ? _Connnection_Connected : _Connnection_Disconnected;
- }
- else
- {
- status = _Connnection_Disable;
- }
- if(ShmChargerInfo->CabinetMiscValue.TelcomModemStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.TelcomModemStatus = status;
- AnnounceTelcomModemStatus();
- }
- // update backend connection status
- status = ShmStatusCodeData->InfoCode.InfoEvents.bits.BackendDisconnectedViaEthernet == YES ? _Connnection_Disconnected : _Connnection_Connected;
- if(ShmChargerInfo->CabinetMiscValue.BackendStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.BackendStatus = status;
- AnnounceBackendStatus();
- }
- // update billing status
- status = ShmSysConfigAndInfo->SysConfig.BillingData.isBilling;
- if(ShmChargerInfo->CabinetMiscValue.BillingStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.BillingStatus = status;
- AnnounceBillingStatus();
- }
- // update stop charging button
- status = ShmSysConfigAndInfo->SysConfig.StopChargingByButton;
- if(ShmChargerInfo->CabinetMiscValue.StopChargingButton != status)
- {
- ShmChargerInfo->CabinetMiscValue.StopChargingButton = status;
- AnnounceStopChargingButtonStatus();
- }
- // update AuthMode config
- status = ShmSysConfigAndInfo->SysConfig.AuthorisationMode;
- if(ShmChargerInfo->CabinetMiscValue.AuthModeConfig != status)
- {
- ShmChargerInfo->CabinetMiscValue.AuthModeConfig = status;
- AnnounceAuthModeConfig();
- AnnounceEVCCIDConfig();
- }
- // update EVCCID config
- status = ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID;
- if(ShmChargerInfo->CabinetMiscValue.EVCCIDConfig != status)
- {
- ShmChargerInfo->CabinetMiscValue.EVCCIDConfig = status;
- AnnounceEVCCIDConfig();
- }
- // update LED Intensity
- status = ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity;
- if(ShmChargerInfo->CabinetMiscValue.LEDIntensity != status)
- {
- ShmChargerInfo->CabinetMiscValue.LEDIntensity = status;
- AnnounceLEDIntensity();
- }
- // update currency
- status = ShmSysConfigAndInfo->SysConfig.BillingData.Currency;
- if(ShmChargerInfo->CabinetMiscValue.Currency != status)
- {
- ShmChargerInfo->CabinetMiscValue.Currency = status;
- AnnounceCurrency();
- }
- // update RfidCardNumEndian
- status = ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian;
- if(ShmChargerInfo->CabinetMiscValue.RfidEndian != status)
- {
- ShmChargerInfo->CabinetMiscValue.RfidEndian = status;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Phihong ||
- ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- AnnounceRfidEndian();
- }
- }
- // update AuthMode config
- status = ShmSysConfigAndInfo->SysConfig.isRFID;
- if(ShmChargerInfo->AuthInfo.AuthMode.bits.RFIDEnable != status)
- {
- ShmChargerInfo->AuthInfo.AuthMode.bits.RFIDEnable = status;
- ShmChargerInfo->CabinetMiscValue.RfidReaderEnable = status;
- AnnounceRfidReader();
- }
- }
- void Check4gWifiReset(void)
- {
- int timeDelay = 0;
- if(ShmChargerInfo->Control.SysCtrl.bits.BackendEnable)
- {
- if((!ShmSysConfigAndInfo->SysInfo.InternetConn && !ShmSysConfigAndInfo->SysInfo.OcppConnStatus &&
- (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE ||
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)) ||
- ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken == YES)
- {
- if(!_NeedReset4gWifi)
- {
- GetClockTime(&_4gWifiReset_time);
- LOG_INFO("Backend Enable But Internet Not Available!");
- }
- _NeedReset4gWifi = true;
- }
- else
- {
- _NeedReset4gWifi = false;
- }
- if(_NeedReset4gWifi)
- {
- timeDelay = ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken == YES ?
- FAST_RESET_4G_WIFI_TIME : TRY_RESET_4G_WIFI_TIME;
- if(GetTimeoutValue(_4gWifiReset_time) / uSEC_VAL >= timeDelay)
- {
- ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable = true;
- usleep(100000);
- // before reset 4g io, kill Module_4g & Module_Wifi task
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- system("killall Module_4g &");
- }
- usleep(100000);
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- system("killall Module_Wifi &");
- }
- LOG_INFO("Reset 4g_Wifi Module");
- system("echo 1 > /sys/class/gpio/gpio104/value");
- sleep(1);
- system("echo 0 > /sys/class/gpio/gpio104/value");
- _NeedReset4gWifi = false;
- ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable = false;
- }
- }
- }
- else
- {
- _NeedReset4gWifi = false;
- }
- }
- void MasterCabinetDhcpClientConfig(void)
- {
- char tmpbuf[256];
- //Run DHCP client if enabled
- system("killall udhcpc");
- system("rm -rf /etc/resolv.conf");
- system("echo nameserver 8.8.8.8 > /etc/resolv.conf"); //Google DNS server
- system("echo nameserver 180.76.76.76 >> /etc/resolv.conf"); //Baidu DNS server
- //system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
- {
- sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- //Upgrade system id to /etc/hostname
- sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- void InitMasterCabinetEthernet(void)
- {
- char tmpbuf[256];
- //Init Eth0 for internet
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- system(tmpbuf);
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"route add default gw %s eth0 ",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- system(tmpbuf);
- //system("ifconfig lo up");
- // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
- //Init Eth1 for administrator tool
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up", "192.168.100.1", "255.255.255.0");
- system(tmpbuf);
- }
- void InitSlaveCabinetEthernet(void)
- {
- char tmpbuf[256];
- system("/sbin/ifconfig eth0 down");
- system("/sbin/ifconfig eth1 down");
- system("killall udhcpc");
- system("rm -rf /etc/resolv.conf");
- system("pgrep -f \"udhcpd /etc/udhcpd_eth1.conf\" | xargs kill");
- //Init Eth0 for internet
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 192.168.100.3%d netmask %s up",
- (ShmChargerInfo->Control.CabinetSwitch - 1),
- "255.255.255.0");
- system(tmpbuf);
- system("/sbin/route add default gw 192.168.100.1 eth0");
- //Init Eth1 for internet
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up", SLAVE_ETH1_IP, SLAVE_ETH1_SUBMASK);
- system(tmpbuf);
- }
- void InitEthernet(void)
- {
- system("ifconfig eth0 down");
- system("ifconfig eth1 down");
- sleep(2);
- char tmpbuf[256];
- // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
- system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
- sleep(2);
- InitMasterCabinetEthernet();
- MasterCabinetDhcpClientConfig();
- // DO360 DHCP Server
- InitialDispenserDhcpServerConfig();
- StartDispenserDhcpServer();
- pid_t pid = fork();
- uint8_t cnt_pingDNS_Fail;
- if(pid == 0)
- {
- ShmChargerInfo->CabinetMiscValue.BackendStatus = _Connnection_Disconnected;
- ShmChargerInfo->CabinetMiscValue.EthernetStatus = _Connnection_Disconnected;
- ShmChargerInfo->CabinetMiscValue.WiFiStatus = _Connnection_Disable;
- ShmChargerInfo->CabinetMiscValue.TelcomModemStatus = _Connnection_Disable;
- LOG_INFO("Internet Fork PID = %d", getpid());
- for(;;)
- {
- if(isEthernetCablePlugIn(0) == YES)
- {
- if(isRouteFail())
- {
- LOG_INFO("eth0 not in route, restart eht0.");
- system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
- {
- InitialDHCP();
- }
- else
- {
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up &",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- system(tmpbuf);
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"route add default gw %s eth0 &",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- system(tmpbuf);
- }
- }
- }
- if(isReachableInternet() == PASS)
- {
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet != NO)
- {
- LOG_INFO("Internet is Reachable");
- }
- ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = NO;
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = YES;
- cnt_pingDNS_Fail = 0;
- }
- else
- {
- if(++cnt_pingDNS_Fail > 3)
- {
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet != YES)
- {
- LOG_INFO("Internet is Disconnect Via Ethernet");
- }
- ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = YES;
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = NO;
- }
- }
- bool ethResult = ShmSysConfigAndInfo->SysInfo.ethInternetConn;
- if(ethResult == YES)
- {
- system("/sbin/ifmetric eth0 0");
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric mlan0 1");
- }
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric ppp0 2");
- }
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
- if (ethResult)
- {
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- system("/sbin/ifmetric eth0 1");
- system("/sbin/ifmetric mlan0 0");
- }
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric ppp0 2");
- }
- }
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- ethResult = (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == NO &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES) ? YES : NO;
- if (ethResult)
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric mlan0 2");
- }
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- system("/sbin/ifmetric eth0 1");
- system("/sbin/ifmetric ppp0 0");
- }
- }
- }
- // Bridge ethernet to uap0 to get dynamic ip address
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > _SYS_POWER_SHARING_MODE_DISABLE &&
- (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP))
- {
- if((isUap0up() == PASS) && access("/sys/class/net/br0/address", F_OK) == -1)
- {
- system("/usr/sbin/brctl addbr br0");
- system("/usr/sbin/brctl addif br0 eth0");
- system("/usr/sbin/brctl addif br0 uap0");
- system("/sbin/ifconfig br0 192.168.10.200 up");
- InitialBridgeModeDhcpServerConfig();
- //system("/bin/sed -i '/interface/d' /etc/udhcpd.conf");
- //system("/bin/echo 'interface br0' >> /etc/udhcpd.conf");
- system("pgrep -f \"udhcpd /etc/udhcpd.conf\" | xargs kill");
- system("/usr/sbin/udhcpd /etc/udhcpd.conf");
- LOG_INFO("Bridge uap0 & eth0 for local power sharing by ethernet.");
- _isBridgeModeConfig = true;
- }
- }
- else
- {
- if(access("/sys/class/net/br0/address", F_OK) != -1)
- {
- system("/sbin/ifconfig br0 down");
- system("/usr/sbin/brctl delbr br0");
- LOG_INFO("Disable uap0 & eth0 Bridge.");
- }
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP && _isBridgeModeConfig)
- {
- InitialApModeDhcpServerConfig();
- system("pgrep -f \"udhcpd /etc/udhcpd.conf\" | xargs kill");
- system("/usr/sbin/udhcpd /etc/udhcpd.conf");
- LOG_INFO("Restart uap0 udhcpd.");
- _isBridgeModeConfig = false;
- }
- }
- // Change uap0 to low priority
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > _SYS_POWER_SHARING_MODE_DISABLE &&
- (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP) &&
- (isUap0up() == PASS))
- {
- system("/sbin/ifmetric uap0 1");
- }
- //==============================================
- // Check Local Power Sharing Communication
- //==============================================
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing == _SYS_POWER_SHARING_MODE_SLAVE)
- {
- if(ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LocalPowerSharingCommunicationError == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LocalPowerSharingCommunicationError = OFF;
- }
- }
- else
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LocalPowerSharingCommunicationError == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LocalPowerSharingCommunicationError = ON;
- }
- }
- }
- else
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LocalPowerSharingCommunicationError = OFF;
- }
- if(!Is_Ocpp_Task_Alive())
- {
- ShmSysConfigAndInfo->SysInfo.OcppConnStatus = false;
- }
- ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.WiFiDisable = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_DISABLE ? true : false;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.Telocom4GModuleDisable = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == false ? true : false;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.BackendDisconnectedViaEthernet = ShmSysConfigAndInfo->SysInfo.OcppConnStatus == false ? true : false;
- UpdateConfigAndIcon();
- Check4gWifiReset();
- sleep(5);
- }
- }
- #ifdef SystemLogMessage
- LOG_INFO("[main]InitEthernet: Initial Ethernet OK.");
- #endif
- }
- void GetMacAddress()
- {
- for (byte index = 0; index < 2; index++)
- {
- int fd;
- struct ifreq ifr;
- char tarEth[5];
- char Mac[18];
- sprintf(tarEth,"eth%d",index);
- fd = socket(AF_INET, SOCK_DGRAM, 0);
- ifr.ifr_addr.sa_family = AF_INET;
- strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
- ioctl(fd, SIOCGIFHWADDR, &ifr);
- close(fd);
- sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
- ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
- ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
- if (index == 0)
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
- else
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
- }
- }
- void GetFirmwareVersion()
- {
- // Get CSU root file system version
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
- sprintf(ShmChargerInfo->SysMisc.MainVersion, fwVersion);
- sprintf(ShmChargerInfo->SysMisc.SubVersion, subVersion);
- #if ENABLE_PCBA_TEST == 0
- byte count = 0, chademo = 0, ccs = 0, gb = 0;
- for(uint8_t idx=0;idx<3;idx++)
- {
- if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'J')
- {
- chademo++;
- count++;
- }
- else if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'G')
- {
- gb++;
- count++;
- }
- else if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'U' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'E')
- {
- ccs++;
- count++;
- }
- }
- if (count == 1)
- {
- if (chademo > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
- else if (ccs > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
- else if (gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
- }
- else
- {
- if (chademo > 0 && ccs > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
- else if (chademo > 0 && gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
- else if (ccs > 0 && gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
- }
- // Get network option from model name
- switch(ShmSysConfigAndInfo->SysConfig.ModelName[10])
- {
- case 'B':
- case 'U':
- //Blue tooth
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
- break;
- case 'W':
- // WIFI
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
- break;
- case 'T':
- // 3G/4G
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
- break;
- case 'D':
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '5';
- break;
- default:
- // LAN
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
- break;
- }
- // Get rating power from model name
- memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
- // Get IEC or UL
- char _buf[3] = {0};
- memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 2);
- if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
- else if (strcmp(_buf, "WU") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
- #endif
- }
- void InitialShareMemoryInfo()
- {
- FILE *fp;
- char cmd[512];
- char buf[512];
- _UpgradeNeedReboot = FALSE;
- _psuLostQuantity = 0;
- //sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
- //sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
- //sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
- ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
- ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
- ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
- sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
- memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
- sprintf(cmd, "/bin/uname -r");
- fp = popen(cmd, "r");
- if(fp == NULL)
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
- else
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
- }
- }
- // 雙槍 CCS + Chademo
- GetFirmwareVersion();
- //sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Relay2ModuleHwRev, " "); //DO360 RC2
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, " "); //DO360 RC2
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Connector1FwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Connector2FwRev, " ");
- ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
- ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
- ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
- ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
- ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
- ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
- memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
- memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
- memset(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev)); //DO360 RC2
- ShmPrimaryMcuData->SelfTest_Comp = NO;
- ShmRelayModuleData[0]->SelfTest_Comp = NO;
- ShmRelayModuleData[1]->SelfTest_Comp = NO;
- ShmFanModuleData->SelfTest_Comp = NO;
- ShmLedModuleData->SelfTest_Comp = NO;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- ShmFanModuleData->TestFanSpeed = 0;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
- ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
- LOG_INFO("DispenserSequence = %d, MaxConnectorQuantity = %d",
- ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
- ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
- {
- LOG_INFO("Dispenser[%d] <=> %d", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- memset((char *)&_BackupStatusNotification[i], 0, sizeof(struct StructStatusNotification));
- _useGunMeterValue[i] = false;
- _notifyOccupancyFeeAct[i] = _Notify_None;
- }
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- _canUpdateFinalCost[i] = false;
- _isUndisposedFinalCost[i] = true;
- }
- }
- int Initialization(void)
- {
- // int pinOut[2] = { 116, 115 };
- for (byte count = 0; count < CONNECTOR_QUANTITY; count++)
- {
- chargingInfo[count]->RemoteStartFlag = NO;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[count].Parameter.bits.RemoteStartConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[count].Parameter.bits.RemoteStopConfirm = false;
- SetOcppErrorCode(count, "NoError");
- }
- LOG_INFO("Initialization OK");
- return PASS;
- }
- void InitialPsuGroupingAndLocation(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
- {
- memcpy(ShmPsuGrouping->Location, Group_to_Location_4_Gun, sizeof(ShmPsuGrouping->Location));
- memcpy(ShmPsuGrouping->Layout, Location_to_Group_4_Gun, sizeof(ShmPsuGrouping->Layout));
- }
- else
- {
- memcpy(ShmPsuGrouping->Location, Group_to_Location_2_Gun, sizeof(ShmPsuGrouping->Location));
- memcpy(ShmPsuGrouping->Layout, Location_to_Group_2_Gun, sizeof(ShmPsuGrouping->Layout));
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- ShmPsuGrouping->GroupCollection[i].Index = i;
- ShmPsuGrouping->GroupCollection[i].Location = ShmPsuGrouping->Location[i];
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay == 0)
- {
- memcpy(&ShmPsuGrouping->GroupCollection[i].ParallelConfig[0], &GroupParallelRelay_4_Gun[i][0], GENERAL_GUN_QUANTITY);
- }
- else
- {
- memcpy(&ShmPsuGrouping->GroupCollection[i].ParallelConfig[0], &GroupParallelRelay_4_Gun_6Parallel[i][0], GENERAL_GUN_QUANTITY);
- }
- }
- else
- {
- memcpy(&ShmPsuGrouping->GroupCollection[i].ParallelConfig[0], &GroupParallelRelay_2_Gun[i][0], GENERAL_GUN_QUANTITY);
- }
- ShmChargerInfo->Control.GunAvailable[i] = NO;
- }
- }
- void InitialCustomerCode(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'A' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'D')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_Audi;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'E' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == '4')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_E4U;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'U' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'U')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_UCar;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'T' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'C')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_TCC;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'O' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'L')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_Shell;
- }
- else
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_Phihong;
- }
- }
- void InitialCustomizedSetting(void)
- {
- ShmChargerInfo->Control.CustomizedInfo.StandbyTime = STANDBY_TIME;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
- {
- ShmChargerInfo->Control.CustomizedInfo.Flag.bits.StandbyTimeDisableForTcc = true;
- }
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_E4U)
- {
- ShmChargerInfo->Control.CustomizedInfo.Flag.bits.CustomizedStandbyTime = true;
- ShmChargerInfo->Control.CustomizedInfo.StandbyTime = E4U_STANDBY_TIME;
- }
- }
- void InitialMaxDispenserConnectorQuantity(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable == false)
- {
- ShmChargerInfo->Control.MaxDispenser = 2;
- ShmChargerInfo->Control.MaxConnector = 2;
- }
- else
- {
- ShmChargerInfo->Control.MaxDispenser = GENERAL_GUN_QUANTITY;
- ShmChargerInfo->Control.MaxConnector = GENERAL_GUN_QUANTITY;
- }
- }
- void InitialAuthMode(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'K')
- {
- }
- }
- void InitialQRCodeMode(void)
- {
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi ||
- ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
- {
- ShmChargerInfo->AuthInfo.QRCodeMode = _QR_MODE_ChargeBoxId;
- }
- else
- {
- // customized
- if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode)
- {
- ShmChargerInfo->AuthInfo.QRCodeMode = _QR_MODE_Customized;
- }
- else
- {
- ShmChargerInfo->AuthInfo.QRCodeMode = _QR_MODE_Default;
- }
- }
- }
- void InitialPowerCabinetSetting(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'A' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'D')
- {
- ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = true;
- }
- ShmChargerInfo->CabinetMiscValue.BillingStatus = ShmSysConfigAndInfo->SysConfig.BillingData.isBilling;
- ShmChargerInfo->CabinetMiscValue.StopChargingButton = ShmSysConfigAndInfo->SysConfig.StopChargingByButton;
- ShmChargerInfo->CabinetMiscValue.AuthModeConfig = ShmSysConfigAndInfo->SysConfig.AuthorisationMode;
- ShmChargerInfo->CabinetMiscValue.EVCCIDConfig = ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID;
- }
- void Initial6ParallelSetting(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[11] == '3')
- {
- ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay = 1;
- }
- }
- void PowerModuleLibSelection(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'L')
- {
- ShmChargerInfo->Control.LibCtrl.bits.PhPwrLib = true;
- }
- else
- {
- ShmChargerInfo->Control.LibCtrl.bits.InfyPwrLib = true;
- }
- }
- bool InitialChargerSetting(void)
- {
- bool result = true;
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'O' || ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'L'))
- {
- ShmChargerInfo->Control.PrimaryCtrl.bits.AcContactorReverse = false;
- ShmChargerInfo->Control.PrimaryCtrl.bits.DoorSensorReverse = false;
- ShmChargerInfo->Control.SysCtrl.bits.LedBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable = true;
- ShmChargerInfo->Control.SysCtrl.bits.DOLedIndication = true;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'K')
- {
- if(!(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'P' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'K'))
- {
- ShmChargerInfo->Control.SysCtrl.bits.FanBoardDisable = true;
- }
- ShmChargerInfo->Control.SysCtrl.bits.LedBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.DKLedIndication = true;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'B')
- {
- //ShmChargerInfo->Control.SysCtrl.bits.FanBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.LedBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.DOLedIndication = true;
- //ShmChargerInfo->Control.SysCtrl.bits.DKLedIndication = true;
- ShmChargerInfo->Control.RelayCtrl.bits.AcInputDisable = true;
- ShmChargerInfo->Control.RelayCtrl.bits.DcInputEnable = true;
- }
- else
- {
- result = false;
- }
- LOG_INFO("door sensor reverse = %d", ShmChargerInfo->Control.PrimaryCtrl.bits.DoorSensorReverse);
- LOG_INFO("ac contactor reverse = %d",ShmChargerInfo->Control.PrimaryCtrl.bits.AcContactorReverse);
- InitialCustomerCode();
- InitialCustomizedSetting();
- InitialMaxDispenserConnectorQuantity();
- InitialAuthMode();
- InitialQRCodeMode();
- Initial6ParallelSetting();
- InitialPsuGroupingAndLocation();
- InitialPowerCabinetSetting();
- PowerModuleLibSelection();
- if(!CheckConnectorTypeStatus())
- {
- result = false;
- }
- return result;
- }
- bool InitialSystemDefaultConfig()
- {
- bool result = true;
- LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
- InitGPIO();
- InitEthernet();
- GetMacAddress();
- return result;
- }
- void SelfTestRun(void)
- {
- LOG_INFO("Self test.");
- system("/root/Module_ChargerSelfTest &");
- }
- void SpawnPowerModuleTask(void)
- {
- if(ShmChargerInfo->Control.LibCtrl.bits.PhPwrLib)
- {
- system("/root/Module_PsuComm_PH &");
- }
- else
- {
- system("/root/Module_PsuComm &");
- }
- }
- void KillPowerModuleTask(void)
- {
- if(ShmChargerInfo->Control.LibCtrl.bits.PhPwrLib)
- {
- system("killall Module_PsuComm_PH");
- }
- else
- {
- system("killall Module_PsuComm");
- }
- }
- void SpawnNormalService(void)
- {
- system("/root/Module_EventLogging &");
- system("/root/Module_PrimaryComm &");
- system("/root/Module_EvComm &");
- //system("/root/Module_LcmControl &");
- system("/root/Module_InternalComm &");
- SpawnPowerModuleTask();
- system("/root/Module_ProduceUtils &");
- system("/root/Module_CabinetParallel &");
- system("/root/Module_LedIndication &");
- system("/root/Module_Authorize &");
- }
- void SpawnOcppService(void)
- {
- if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
- Run_Ocpp_Service();
- }
- }
- void SpawnMaintainOcppService(void)
- {
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- Run_MaintainOcpp_Service();
- }
- }
- void SpawnInternetService(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
- {
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- system("/root/Module_4g &");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- system("/root/Module_Wifi &");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- system("/root/Module_4g &");
- }
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- system("/root/Module_Wifi &");
- }
- }
- }
- int SpawnTask(void)
- {
- sleep(2);
- SpawnNormalService();
- SpawnInternetService();
- return PASS;
- }
- int runFlashShellCmd(const char *cmd)
- {
- int result = FAIL;
- char buf[256];
- FILE *fp;
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- LOG_INFO("%s\n", buf);
- }
- result = PASS;
- }
- pclose(fp);
- return result;
- }
- int StoreUsrConfigData(struct SysConfigData *UsrData)
- {
- int result = PASS;
- int fd, wrd;
- unsigned int i, Chk;
- unsigned char *ptr, *BufTmp;
- Chk = 0;
- ptr = (unsigned char *)UsrData;
- if((BufTmp = malloc(MtdBlockSize)) != NULL)
- {
- memset(BufTmp, 0, MtdBlockSize);
- memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
- for(i = ARRAY_SIZE(UsrData->CsuBootLoadFwRev); i < MtdBlockSize - 4; i++)
- {
- Chk += *(BufTmp+i);
- }
- memcpy(BufTmp + MtdBlockSize - 4, &Chk, 4);
- // Output configuration to file.
- fd = open("/mnt/EvseTempConfig.bin", O_RDWR | O_CREAT | O_TRUNC);
- if(fd < 0)
- {
- LOG_ERROR("open /mnt/EvseTempConfig.bin NG");
- free(BufTmp);
- return 0;
- }
- wrd = write(fd, BufTmp, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- LOG_ERROR("write /mnt/EvseTempConfig.bin NG");
- free(BufTmp);
- return 0;
- }
- LOG_INFO("EvseTempConfig write to file in /mnt OK.");
- LOG_INFO("Erase /dev/mtd10.");
- runFlashShellCmd("flash_erase /dev/mtd10 0 0");
- LOG_INFO("Write /dev/mtd10.");
- runFlashShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseTempConfig.bin");
- LOG_INFO("Erase /dev/mtd11.");
- runFlashShellCmd("flash_erase /dev/mtd11 0 0");
- LOG_INFO("Write /dev/mtd11.");
- runFlashShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseTempConfig.bin");
- system("rm -f /mnt/EvseTempConfig.bin");
- LOG_INFO("EvseTempConfig write to flash OK");
- }
- else
- {
- LOG_ERROR("alloc BlockSize NG");
- result = FAIL;
- }
- if(BufTmp != NULL)
- {
- free(BufTmp);
- }
- return result;
- }
- //===============================================
- // Common Detect Chk - Stop Charging ?
- //===============================================
- bool isEvBoardStopChargeFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->ChargingStopFlag.bits.AlarmStop;
- }
- bool isNormalStopChargeFlag(byte gunIndex)
- {
- return (chargingInfo[gunIndex]->ChargingStopFlag.bits.NormalStop || chargingInfo[gunIndex]->ChargingStopFlag.bits.ManualStop);
- }
- bool isResetStopChargeFlag(byte gunIndex)
- {
- return (chargingInfo[gunIndex]->ChargingStopFlag.bits.HardResetStop || chargingInfo[gunIndex]->ChargingStopFlag.bits.SoftResetStop);
- }
- bool isInvalidIdStopFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->ChargingStopFlag.bits.InvalidIdStop;
- }
- bool isSessionTargetStopFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->ChargingStopFlag.bits.SessionTargetStop;
- }
- bool isBackendStopFlag(byte gunIndex)
- {
- return (chargingInfo[gunIndex]->ChargingStopFlag.bits.BackendStop || chargingInfo[gunIndex]->ChargingStopFlag.bits.RemoteStop || chargingInfo[gunIndex]->ChargingStopFlag.bits.UnlockStop);
- }
- void ReleaseAlarmCode(byte gunIndex)
- {
- if(!Is_Ocpp_StatusNotificationErrorCode(gunIndex, "NoError"))
- {
- SetOcppErrorCode(gunIndex, "NoError");
- }
- if(!Is_Ocpp_StatusNotificationVendorCode(gunIndex, ""))
- {
- SetOcppVendorErrorCode(gunIndex, "");
- }
- if (strcmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "") != EQUAL)
- {
- strcpy((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "");
- }
- if (strcmp((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "") != EQUAL)
- {
- strcpy((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "");
- }
- if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemotenAlarmCode, "") != EQUAL)
- {
- strcpy((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemotenAlarmCode, "");
- }
- if (strcmp((char *)ShmChargerInfo->GunError[gunIndex].GunAlarmCode, "") != EQUAL)
- {
- strcpy((char *)ShmChargerInfo->GunError[gunIndex].GunAlarmCode, "");
- }
- }
- //===============================================
- // EmergencyStop and Charging Stop
- //===============================================
- void ChargingTerminalProcess(byte gunIndex)
- {
- setChargerMode(gunIndex, MODE_TERMINATING);
- }
- void ChargingAlarmProcess(byte gunIndex)
- {
- UpdateErrorCodeToOcpp(gunIndex);
- setChargerMode(gunIndex, MODE_ALARM);
- }
- void AcChargingTerminalProcess()
- {
- ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
- }
- void StopChargingProcessByString(byte level)
- {
- if (level > ShmSysConfigAndInfo->SysWarningInfo.Level)
- {
- ShmSysConfigAndInfo->SysWarningInfo.Level = level;
- }
- }
- void ReleaseChargingProcessByString(byte level)
- {
- if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level)
- ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
- }
- // 一般錯誤停止充電處理函式
- void BoardErrOccurByString(byte index, char *code)
- {
- byte level = 1;
- if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
- (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (strncmp(code, "023730", 6) == EQUAL && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
- }
- ChargingTerminalProcess(index);
- }
- StopChargingProcessByString(level);
- }
- // 急停狀況的停止充電處理函式
- void EmcOccureByString(char *code)
- {
- byte level = 2;
- if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
- {
- return;
- }
- // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
- // 其錯誤等級為 2
- if (strncmp(code, "042251", 6) == EQUAL || strncmp(code, "042252", 6) == EQUAL ||
- strncmp(code, "042238", 6) == EQUAL || strncmp(code, "042267", 6) == EQUAL ||
- strncmp(code, "042328", 6) == EQUAL)
- {
- for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++)
- {
- if ((chargingInfo[gun]->SystemStatus > S_IDLE && chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
- (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (strncmp((char *)chargingInfo[gun]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun]->ConnectorAlarmCode, code, 6);
- }
- InformOcppErrOccur(4);
- ChargingAlarmProcess(gun);
- }
- }
- StopChargingProcessByString(level);
- }
- }
- void ReleaseEmsOccureByString(byte index, char *code)
- {
- bool isTrigger = false;
- byte level = 2;
- if (strncmp(code, "042251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
- }
- else if (strncmp(code, "042252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
- }
- else if (strncmp(code, "042237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- }
- else if (strncmp(code, "042238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- else if (strncmp(code, "042267", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = NO;
- }
- if (isTrigger)
- {
- ReleaseChargingProcessByString(level);
- }
- }
- //===============================================
- // 確認硬體 (按鈕) 狀態
- //===============================================
- void ChkPrimaryStatus()
- {
- if(ShmChargerInfo->Control.TestCtrl.bits.ChargingSimulation)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = NO;
- return;
- }
- if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = YES;
- EmcOccureByString("042251");
- }
- else
- {
- ReleaseEmsOccureByString(0, "042251");
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = NO;
- }
- if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
- //EmcOccureByString("042238");
- }
- else
- {
- //ReleaseEmsOccureByString(0, "042238");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
- }
- else
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- }
- if(ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL &&
- (ShmChargerInfo->Control.CustomizedInfo.TiltSensorStep == _TILT_SENSOR_NONE ||
- ShmChargerInfo->Control.CustomizedInfo.TiltSensorStep == _TILT_SENSOR_FINISH))
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
- EmcOccureByString("042252");
- }
- else
- {
- ReleaseEmsOccureByString(0, "042252");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
- {
- EmcOccureByString("042328");
- SetAcContactor(OFF);
- }
- if(ShmChargerInfo->Control.CustomizedInfo.TiltSensorFail)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.TiltSensorStestFail = YES;
- }
- else
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.TiltSensorStestFail = NO;
- }
- }
- struct timespec _AcContactReOpen_Time;
- void ChkPsuStatus(void)
- {
- if(!ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- {
- if(IsConnectorWholeIdle())
- {
- for(int psuGroup = 0; psuGroup < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; psuGroup++)
- {
- //if(ShmPsuData->PsuGroup[psuGroup].GroupErrorFlag.PsuGroupErrorValue != 0)
- //{
- // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
- //}
- if(ShmChargerInfo->PsuGrouping.GroupPsuStatus_OR[psuGroup].StatusVal & PSU_STATUS_FLAG_FAULT)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
- }
- }
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- {
- EmcOccureByString("042267");
- }
- }
- else
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor &&
- ShmChargerInfo->Control.PsuCtrl.bits.FailureResume == NO)
- {
- bool allFaultStatus = true;
- for(int gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
- {
- if(chargingInfo[gunIndex]->SystemStatus != S_FAULT && chargingInfo[gunIndex]->SystemStatus != S_MAINTAIN)
- {
- allFaultStatus = false;
- }
- }
- if(allFaultStatus)
- {
- LOG_INFO("PSU Failure, Need Resume");
- ShmChargerInfo->Control.PsuCtrl.bits.FailureResume = YES;
- }
- }
- }
- }
- int AcContactorReOpenCount = 0;
- void PsuFailureResume(void)
- {
- if(ShmChargerInfo->Control.PsuCtrl.bits.FailureResume)
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu == NO)
- {
- LOG_INFO("Ac Contactor Off By Psu Failure");
- // update _AcContactReOpen_Time
- GetClockTime(&_AcContactReOpen_Time);
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = YES;
- AcContactorReOpenCount++;
- }
- else
- {
- if(AcContactorReOpenCount < MAX_AC_CONTACTOR_COUNT)
- {
- if(GetTimeoutValue(_AcContactReOpen_Time) / uSEC_VAL >= AC_CONTACTOR_REOPEN_TIME)
- {
- ReleaseEmsOccureByString(0, "042267");
- // update _AcContactReOpen_Time
- GetClockTime(&_AcContactReOpen_Time);
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = NO;
- ShmChargerInfo->Control.PsuCtrl.bits.FailureResume = NO;
- LOG_INFO("Psu Failure Resume");
- }
- }
- }
- }
- else
- {
- if(AcContactorReOpenCount > 0)
- {
- if(GetTimeoutValue(_AcContactReOpen_Time) / uSEC_VAL >= PSU_FAILURE_RESUME_TIME)
- {
- AcContactorReOpenCount = 0;
- }
- }
- }
- }
- void SetAcContactor(unsigned char OnOff)
- {
- OnOff = OnOff ? ON : OFF;
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor != OnOff)
- {
- if(OnOff)
- {
- ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown = NO;
- }
- LOG_INFO("Set Ac Contactor %s", OnOff == ON ? "On" : "Off");
- }
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = OnOff == ON ? ON : OFF;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER && ShmChargerInfo->ParallelCabinet.ParallelStatus == _Parallel_None)
- {
- SetParallelCabinetAcContactor(OnOff);
- }
- }
- int GetStandbyTime(void)
- {
- int time = STANDBY_TIME;
- if(ShmChargerInfo->Control.TestCtrl.bits.FastStandbyTime)
- {
- time = FAST_STANDBY_TIME;
- }
- if(ShmChargerInfo->Control.CustomizedInfo.Flag.bits.CustomizedStandbyTime)
- {
- time = ShmChargerInfo->Control.CustomizedInfo.StandbyTime;
- }
- if(ShmChargerInfo->Control.CustomizedInfo.Flag.bits.StandbyImmediately)
- {
- time = FAST_STANDBY_TIME;
- }
- return time;
- }
- void StandbyCheck(void)
- {
- bool enable = IsStandbyEnable();
- if(IsConnectorWholeIdle() && IsParallelCabinetIdle())
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown)
- {
- int time = GetStandbyTime();
- #if CONTACTOR_AUTO_ON_OFF == 1
- time = CONTACTOR_AUTO_ON_TIME;
- #endif
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor)
- {
- if(GetSecTimeoutValue(_Standby_time) >= time && enable)
- {
- SetAcContactor(OFF);
- }
- }
- #if CONTACTOR_AUTO_ON_OFF == 1
- time = CONTACTOR_AUTO_ON_TIME + CONTACTOR_AUTO_OFF_TIME;
- if((GetTimeoutValue(_Standby_time) / uSEC_VAL) >= time)
- {
- SetAcContactor(ON);
- }
- #endif
- }
- else
- {
- ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown = YES;
- GetClockTime(&_Standby_time);
- }
- }
- else
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown)
- {
- ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown = NO;
- }
- }
- }
- void CheckDisconnectionStatusRecovery(void)
- {
- bool recovery = true;
- // check all connector
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.Disconnection)
- {
- recovery = false;
- }
- }
- if(recovery)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = false;
- }
- }
- //===============================================
- // 確認各小板偵測的錯誤狀況
- //===============================================
- void CheckErrorOccurStatus(byte index)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.NormalStopRequest)
- {
- chargingInfo[index]->ChargingStopFlag.bits.NormalStop = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AlarmStopRequest)
- {
- if(strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].RemotenAlarmCode, 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d Error Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- if(ShmChargerInfo->GunError[index].ErrFlag.ErrorValue != 0)
- {
- if(strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, ShmChargerInfo->GunError[index].GunAlarmCode, 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d GunError Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.TimeoutStopRequest)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.TimeoutStopRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.Disconnection = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = true;
- if(chargingInfo[index]->SystemStatus == S_AUTHORIZING ||
- chargingInfo[index]->SystemStatus == S_PREPARNING ||
- chargingInfo[index]->SystemStatus == S_PREPARING_FOR_EV ||
- chargingInfo[index]->SystemStatus == S_PREPARING_FOR_EVSE ||
- chargingInfo[index]->SystemStatus == S_CHARGING)
- {
- if(strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042304", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d Disconnect Alarm Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else if(chargingInfo[index]->SystemStatus == S_REASSIGN_CHECK ||
- chargingInfo[index]->SystemStatus == S_REASSIGN)
- {
- setChargerMode(index, MODE_IDLE);
- }
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo)
- {
- CheckDisconnectionStatusRecovery();
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_PRIMARY;
- StopChargingProcessByString(2);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042251", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042252", 6);
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_PRIMARY)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- // RB
- if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
- StopChargingProcessByString(2);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042203", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042204", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042205", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d RC Board Input UVP Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcInputDisable == NO)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
- StopChargingProcessByString(2);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042200", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042201", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042202", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d RC Board Input OVP Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- }
- else
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
- StopChargingProcessByString(2);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042327", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042328", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Gun %d DC Input OVP/UVP Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- }
- }
- int DiffTimebWithNowSec(struct timeb ST)
- {
- //return milli-second
- struct timeb ET;
- unsigned int StartTime,StopTime;
- ftime(&ET);
- StartTime=(unsigned int)ST.time;
- StopTime=(unsigned int)ET.time;
- return (StopTime-StartTime);
- }
- int CheckTimeOut(char *start)
- {
- int result = YES;
- struct ParsingResult
- {
- int result;
- int scanedElement;
- int year;
- int month;
- int mday;
- int hour;
- int min;
- int sec;
- int tz_hour;
- int tz_min;
- float minSec;
- }parsingResult;
- struct tm tmStart;
- struct timeb tbStart;
- memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
- if(strstr((char*)start, ".") != NULL)
- {
- // Original data with mini second
- if(strstr((char*)start, "Z") != NULL)
- {
- // Original data with Z
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec,
- &parsingResult.minSec);
- }
- else
- {
- // Original data without Z
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec,
- &parsingResult.minSec,
- &parsingResult.tz_hour,
- &parsingResult.tz_min);
- }
- }
- else
- {
- // Original data without mini second
- if(strstr((char*)start, "Z") != NULL)
- {
- // Original data with Z
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec);
- }
- else
- {
- // Original data without Z
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec,
- &parsingResult.tz_hour,
- &parsingResult.tz_min);
- }
- }
- if(parsingResult.scanedElement >= 6)
- {
- tmStart.tm_year = parsingResult.year - 1900;
- tmStart.tm_mon = parsingResult.month - 1;
- tmStart.tm_mday = parsingResult.mday;
- tmStart.tm_hour = parsingResult.hour;
- tmStart.tm_min = parsingResult.min;
- tmStart.tm_sec = parsingResult.sec;
- tmStart.tm_gmtoff = 0;
- tbStart.time = mktime(&tmStart);
- tbStart.timezone = 0;
- tbStart.millitm = 0;
- tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
- if(DiffTimebWithNowSec(tbStart) <= 0)
- result = NO;
- else
- result = YES;
- }
- else
- {
- LOG_INFO("Start date parsing error");
- }
- return result;
- }
- bool Is_WebServer_Alive(void)
- {
- if(system("pidof -s lighttpd > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- void Run_WebServer_Service(void)
- {
- system("/root/web.sh");
- }
- bool Is_LocalPowerSharing_Alive(void)
- {
- if(system("pidof -s Module_PowerSharing > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- void Run_LocalPowerSharing_Service(void)
- {
- system ("/root/Module_PowerSharing &");
- }
- //===============================================
- // Ocpp_Service
- //===============================================
- void Run_Ocpp_Service(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- system("/root/OcppBackend &");
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- system("/root/OcppBackend20 &");
- return;
- }
- }
- bool Is_Ocpp_Task_Alive(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(system("pidof -s OcppBackend > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(system("pidof -s OcppBackend20 > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- return false;
- }
- void Kill_Ocpp_Service(void)
- {
- system("killall OcppBackend");
- system("killall OcppBackend20");
- }
- //===============================================
- // Maintain Ocpp_Service
- //===============================================
- void Run_MaintainOcpp_Service(void)
- {
- system("/root/OcppBackendPH &");
- }
- bool Is_MaintainOcpp_Task_Alive(void)
- {
- if(system("pidof -s OcppBackendPH > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- void Kill_MaintainOcpp_Service(void)
- {
- system("killall OcppBackendPH");
- }
- //===============================================
- // Ocpp OcppConnStatus
- //===============================================
- bool Get_Ocpp_ConnectionStatus(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->OcppConnStatus > 0 ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->OcppConnStatus > 0 ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp procDogTime
- //===============================================
- long int Get_Ocpp_procDogTime(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->procDogTime;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->procDogTime;
- }
- return 0;
- }
- void Clean_Ocpp_procDogTime(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->procDogTime = time((time_t*)NULL);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->procDogTime = time((time_t*)NULL);
- return;
- }
- }
- //===============================================
- // Ocpp Boot Notification
- //===============================================
- bool Is_Ocpp_BootNotification(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SpMsg.bits.BootNotificationConf == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_BootNotification(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->SpMsg.bits.BootNotificationConf = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->SpMsg.bits.BootNotificationConf = false;
- return;
- }
- }
- //===============================================
- // Ocpp Rest
- //===============================================
- bool Is_Ocpp_ResetReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.ResetReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MsMsg.bits.ResetReq == YES ? true : false;
- }
- return false;
- }
- bool Chk_Ocpp_Reset_Type(char *type)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->Reset.Type, type) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->Reset.type, type) == EQUAL ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ResetReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
- ShmOCPP16Data->MsMsg.bits.ResetReq = false;
- ShmOCPP16Data->MsMsg.bits.ResetConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- sprintf ( (char*) ShmOCPP20Data->Reset.Response_status, "Accepted" );
- ShmOCPP20Data->MsMsg.bits.ResetReq = false;
- ShmOCPP20Data->MsMsg.bits.ResetConf = true;
- return;
- }
- }
- //===============================================
- // Ocpp AuthorizeReq
- //===============================================
- void Set_Ocpp_AuthorizeReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->SpMsg.bits.AuthorizeConf = false;
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->SpMsg.bits.AuthorizeConf = false;
- ShmOCPP20Data->SpMsg.bits.AuthorizeReq = true;
- return;
- }
- }
- bool Is_Ocpp_AuthorizeConf(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SpMsg.bits.AuthorizeConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SpMsg.bits.AuthorizeConf == YES ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_Authorize_Status(char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, status) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp UpdateFirmwareReq
- //===============================================
- bool Is_Ocpp_UpdateFirmwareReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_UpdateFirmwareReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = false;
- return;
- }
- }
- bool Is_Ocpp_UpdateFirmwareStatus(char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, status) == EQUAL ? true : false;
- }
- return false;
- }
- void Set_Ocpp_UpdateFirmwareStatus(char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, status);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, status);
- return;
- }
- }
- void Clean_Ocpp_UpdateFirmwareStatus(char *status)
- {
- Set_Ocpp_UpdateFirmwareStatus("");
- }
- void Set_Ocpp_FirmwareStatusNotificationReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- return;
- }
- }
- //===============================================
- // Ocpp StopTransactionOnInvalidId
- //===============================================
- bool Is_Ocpp_StopOnInvalidId_Enable(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE") > 0 ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strstr((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE") > 0 ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp AuthorizeRemoteTxRequests
- //===============================================
- bool Is_Ocpp_AuthorizeRemoteTxRequests(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") > 0 ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strstr((char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "TRUE") > 0 ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp ConnectionTimeOut
- //===============================================
- int Get_Ocpp_ConnectionTimeOut(void)
- {
- int timeout = 0;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0)
- {
- timeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "" ) != 0)
- {
- timeout = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
- }
- }
- return timeout > 0 ? timeout : 0;
- }
- //===============================================
- // Ocpp DefaultPrice
- //===============================================
- void Get_Ocpp_DefaultPrice(char *defaultPrice)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(defaultPrice, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(defaultPrice, "");
- return;
- }
- strcpy(defaultPrice, "");
- }
- //===============================================
- // Ocpp UserPrice
- //===============================================
- void Get_Ocpp_UserPrice(char *userId, char *userPrice)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(userId, (char *)ShmOCPP16Data->Cost.SetUserPrice.idToken);
- strcpy(userPrice, (char *)ShmOCPP16Data->Cost.SetUserPrice.price);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(userId, "");
- strcpy(userPrice, "");
- return;
- }
- strcpy(userId, "");
- strcpy(userPrice, "");
- }
- void Clean_Ocpp_UserPrice(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- //===============================================
- // Ocpp RunningCost
- //===============================================
- void Get_Ocpp_RunningCost(int gun_index, char *cost)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(cost, (char *)ShmOCPP16Data->Cost.RunningCost[gun_index].description);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(cost, (char *)"");
- return;
- }
- }
- void Clean_Ocpp_RunningCost(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->Cost.RunningCost[gun_index], 0x00, sizeof(struct StrcutRunningCost));
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- //===============================================
- // Ocpp FinalCost
- //===============================================
- void Get_Ocpp_FinalCost(int gun_index, char *cost)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(cost, (char *)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(cost, (char *)"");
- return;
- }
- }
- void Clean_Ocpp_FinalCost(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->Cost.FinalCost[gun_index], 0x00, sizeof(struct StrcutFinalCost));
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- int Get_Ocpp_FinalCostTxId(int gun_index)
- {
- int txId = 0;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- txId = ShmOCPP16Data->Cost.FinalCost[gun_index].txId;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return txId;
- }
- //===============================================
- // Ocpp TimeOffset
- //===============================================
- void Get_Ocpp_TimeOffset(char *timeOffset)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(timeOffset, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(timeOffset, "");
- return;
- }
- strcpy(timeOffset, "");
- }
- //===============================================
- // Ocpp PreAuthAmount
- //===============================================
- void Get_Ocpp_PreAuthAmount(char *amount)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(amount, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(amount, "");
- return;
- }
- strcpy(amount, "");
- }
- //===============================================
- // Ocpp PowerSharingServerIP
- //===============================================
- void Get_Ocpp_PowerSharingServerIP(char *ip)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(ip, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(ip, "");
- return;
- }
- strcpy(ip, "");
- }
- //===============================================
- // Ocpp Refunding
- //===============================================
- void Get_Ocpp_Refunding(char *Refunding)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- void Clean_Ocpp_Refunding(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- //===============================================
- // Ocpp LcdOveride
- //===============================================
- bool Is_Ocpp_LcdOverideReq(int *gun, int *page)
- {
- *gun = ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId;
- *page = ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index;
- return ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq ? true : false;
- }
- void Clean_Ocpp_LcdOverideReq(void)
- {
- ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = false;
- }
- //===============================================
- // Ocpp StationInfo
- //===============================================
- void Get_Ocpp_ChargerStationInfo(int *station_id, char *name)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(name, (char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_ChargerStationReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ChargerInfoReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Clean_Ocpp_ChargerStationReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ChargerInfoReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp WeatherInfo
- //===============================================
- void Get_Ocpp_WeatherInfo(int *weatherID, float *temperature)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- *weatherID = ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId;
- *temperature = ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_WeatherReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.WeatherInfoReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Clean_Ocpp_WeatherReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.WeatherInfoReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp DeductInfo
- //===============================================
- void Set_Ocpp_DeductTransaction(int transaction)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.txId = transaction;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductCreditNo(char *userId)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, userId, strlen(userId));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductVemData(char *vemData)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.vemData, vemData);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductAmount(double value)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.amount = value;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductResult(unsigned char result)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult = result;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DonateInvoice(unsigned char donate)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice = donate ? YES : NO;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Set_Ocpp_DeductInfo(DeductResultInfoData *deductInfo)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.txId = deductInfo->TransactionId;
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, (char *)deductInfo->creditNo, sizeof(deductInfo->creditNo));
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.vemData, deductInfo->VemData, sizeof(deductInfo->VemData));
- ShmOCPP16Data->TcciCustomData.DeductInfo.amount = ((double)deductInfo->DeductAmount / 100);
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo, deductInfo->ApprovalNumber, sizeof(deductInfo->ApprovalNumber));
- ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult = deductInfo->DeductResult;
- ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice = deductInfo->IsDonateInvoice ? YES : NO;
- return true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- bool Is_Ocpp_ReportCreditDeductReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Set_Ocpp_ReportCreditDeductReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = YES;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Tcci SerialNo
- //===============================================
- void Clean_Ocpp_TcciSerialNo(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset((char *)&ShmOCPP16Data->TcciCustomData.SerialNo[gun_index], 0x00, sizeof(37));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Tcci ReaderStatus
- //===============================================
- bool Set_Ocpp_TcciReaderStatus(int gun_index, DeductResultInfoData *ReaderStatus)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(ReaderStatus->DeductResult == _Deduct_PreAuth_Cancel || ReaderStatus->DeductResult == _Deduct_PreAuth || ReaderStatus->DeductResult == _Deduct_PreAuth_Pass)
- {
- switch(ReaderStatus->DeductResult)
- {
- case _Deduct_PreAuth_Pass:
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus = 1;
- break;
- case _Deduct_PreAuth_Cancel:
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus = 2;
- break;
- case _Deduct_PreAuth:
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus = 0;
- break;
- }
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo, ReaderStatus->creditNo, sizeof(ReaderStatus->creditNo));
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.VEMData[gun_index], ReaderStatus->VemData, sizeof(ReaderStatus->VemData));
- return true;
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- void Clean_Ocpp_TcciCreditInfo(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset((char *)&ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo, 0x00, sizeof(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
- memset((char *)&ShmOCPP16Data->TcciCustomData.VEMData[gun_index], 0x00, sizeof(ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_TcciReaderStatusReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_TcciReaderStatusReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- //===============================================
- // Ocpp Tcci OccupancyFeeDisplay
- //===============================================
- bool Is_Ocpp_TcciOccupancyDisplayReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Clean_Ocpp_TcciOccupancyDisplayReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- // input: gun_index, sn_len
- // output: sn
- // return: action
- int Get_Ocpp_TcciOccupancyAction(int gun_index, int sn_len, char *sn)
- {
- int action = 0;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- action = ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId;
- if(action == _ParkingAction_DisplayButton)
- {
- memcpy(sn, ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, sn_len);
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return action;
- }
- void Clean_Ocpp_TcciOccupancyActionAndSn(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = 0;
- memset(ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, 0x00, sizeof(ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Tcci SetOccupancyPrice
- //===============================================
- bool Is_Ocpp_TcciSetOccupancyPriceReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Clean_Ocpp_TcciSetOccupancyPriceReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- float Get_Ocpp_TcciOccupancyPrice(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return 0;
- }
- //===============================================
- // Ocpp Tcci GetOccupancyFee
- //===============================================
- bool Is_Ocpp_TcciOccupancyFeeActReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Set_Ocpp_TcciOccupancyFeeAct(int gun_index, OccupancyBillInfo *bill, int action)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN, 0x00, sizeof(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN));
- memcpy(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN, bill->Sn, sizeof(bill->Sn));
- ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].action = action;
- ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Clean_Ocpp_TcciNotifyOccupancyFeeActReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].action = _Notify_None;
- ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Get_Ocpp_TcciGetOccupancyFeeResponse(int gun_index, OccupancyBillInfo *bill)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- bill->Duration = ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].response_duration;
- bill->Fee = ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].response_occupancyFee;
- memcpy(bill->StartTime, ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].response_startTime, sizeof(bill->StartTime));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_TcciOccupancyFeeActStatus(int gun_index, char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].response_status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- //===============================================
- // Ocpp Tcci ReportOccupancyDeductReq
- //===============================================
- bool Is_Ocpp_TcciReportOccupancyDeductReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Set_Ocpp_TcciReportOccupancyDeductReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Tcci OccupancyDeductResult
- //===============================================
- bool Set_Ocpp_OccupancyDeductResult(OccupancyDeductInfo *deduct, bool pass_fail)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->TcciCustomData.OccupancyDeductResult, 0x00, sizeof(struct StructOccupancyDeductResult));
- ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult = pass_fail;
- ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount = deduct->Fee;
- memcpy(&ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN[0], &deduct->Sn[0], sizeof(deduct->Sn));
- memcpy(&ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo[0], &deduct->creditNo[0], sizeof(deduct->creditNo));
- memcpy(&ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo[0], &deduct->ApprovalNumber[0], sizeof(deduct->ApprovalNumber));
- return true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- //===============================================
- // Ocpp Start Transaction
- //===============================================
- void Set_Ocpp_StartTransactionIdTag(int gun_index, char *id)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, id);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent [gun_index].idToken.idToken, id);
- }
- // MaintainServer
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, id);
- }
- }
- void Set_Ocpp_StartTransactionReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CpMsg.bits [gun_index].TransactionEventReq = true;
- }
- // MaintainServer
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = true;
- }
- }
- bool Is_Ocpp_StartTransactionConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf == YES)
- {
- if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "Started") != NULL)
- {
- return true;
- }
- else
- {
- ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = false;
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- return false;
- }
- void Clean_Ocpp_StartTransactionConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = false;
- }
- // MaintainServer
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = false;
- }
- }
- bool Is_Ocpp_StartTransaction_Status(int gun_index, char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, status) == EQUAL ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_StartTransaction_Accepted(int gun_index)
- {
- return Is_Ocpp_StartTransaction_Status(gun_index, "Accepted");
- }
- void Get_Ocpp_StartTransaction_Status(int gun_index, char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(status, (char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(status, (char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status);
- }
- }
- void Get_Ocpp_TransactionId(int gun_index, char *transactionId)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- sprintf(transactionId, "%d", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(transactionId, (char *)&ShmOCPP20Data->TransactionEvent [gun_index].transactionInfo.transactionId[0]);
- return;
- }
- sprintf(transactionId, "%d", 0);
- }
- bool Is_Invalid_StartTransactionId(int gun_index)
- {
- if(Is_Ocpp_StartTransaction_Status(gun_index, "Blocked") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "Expired") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "Invalid") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NoCredit") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NotAllowedTypeEVSE") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NotAtThisLocation") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NotAtThisTime") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "Unknown"))
- {
- return true;
- }
- return false;
- }
- //===============================================
- // Ocpp Stop Transaction
- //===============================================
- void Set_Ocpp_StopTransactionId(int gun_index, char *id)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, id);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent [gun_index].idToken.idToken, id);
- return;
- }
- }
- void Set_Ocpp_StopTransactionReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CpMsg.bits [gun_index].TransactionEventReq = true;
- }
- // MaintainServer
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = true;
- }
- }
- //===============================================
- // Ocpp Check Backup Error Code
- //===============================================
- void Chk_Ocpp_Backup_ErrorCode(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "") == EQUAL)
- {
- if(strcmp((char *)_BackupStatusNotification[gun_index].ErrorCode, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, (char *)_BackupStatusNotification[gun_index].ErrorCode);
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, (char *)_BackupStatusNotification[gun_index].VendorErrorCode);
- }
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Reserve Now
- //===============================================
- bool Is_Ocpp_ReserveNowReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ReserveNowReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowReq = false;
- return;
- }
- }
- int Get_Ocpp_ReserveNowId(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->ReserveNow[gun_index].ReservationId;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->ReserveNow[gun_index].id;
- }
- return 0;
- }
- void Set_Ocpp_ReserveNowConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits [gun_index].ReserveNowConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits [gun_index].ReserveNowConf = true;
- return;
- }
- }
- void Get_Ocpp_ReserveNowExpiryDate(int gun_index, char *date)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(date, (char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(date, (char *)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime);
- return;
- }
- strcpy(date, "");
- return;
- }
- bool Is_Ocpp_ReserveNowExpired(int gun_index)
- {
- bool _expired = true;
- char _expiryDate[128];
- Get_Ocpp_ReserveNowExpiryDate(gun_index, _expiryDate);
- _expired = CheckTimeOut(_expiryDate);
- return _expired;
- }
- void Get_Ocpp_ReserveNowIdTag(int gun_index, char *idTag)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(idTag, (char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(idTag, (char *)ShmOCPP20Data->ReserveNow[gun_index].idToken.idToken);
- return;
- }
- strcpy(idTag, "");
- return;
- }
- bool Is_Ocpp_ReserveNowIdTag(uint8_t gun_index, char *authIdTag)
- {
- char ReserveIdTag[32];
- Get_Ocpp_ReserveNowIdTag(gun_index, ReserveIdTag);
- return strcmp(ReserveIdTag, authIdTag) == EQUAL ? true : false;
- }
- //===============================================
- // Ocpp Cancel Reservation
- //===============================================
- bool Is_Ocpp_CancelReservationReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_CancelReservationReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationReq = false;
- return;
- }
- }
- void Set_Ocpp_CancelReservationConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits [gun_index].CancelReservationConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits [gun_index].CancelReservationConf = true;
- return;
- }
- }
- //===============================================
- // Ocpp Change Availability
- //===============================================
- bool Is_Ocpp_ChangeAvailabilityReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ChangeAvailabilityReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = false;
- return;
- }
- }
- bool Chk_Ocpp_Availability_Type(int gun_index, char *type)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->ChangeAvailability[gun_index].Type, type) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->ChangeAvailability[gun_index].operationalStatus, type) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp Unlock Connector
- //===============================================
- bool Is_Ocpp_UnlockConnectorReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_UnlockConnectorReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorReq = false;
- return;
- }
- }
- void Set_Ocpp_UnlockConnectorConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus, "Unlocked");
- ShmOCPP16Data->CsMsg.bits [gun_index].UnlockConnectorConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->UnlockConnector[gun_index].Response_status, "Unlocked");
- ShmOCPP20Data->CsMsg.bits [gun_index].UnlockConnectorConf = true;
- return;
- }
- }
- //===============================================
- // Ocpp Remote Start
- //===============================================
- bool Is_Ocpp_RemoteStartReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_RemoteStartReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq = false;
- return;
- }
- }
- void Get_Ocpp_RemoteStartIdTag(int gun_index, char *idTag)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(idTag, (char *)&ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag[0]);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(idTag, (char *)&ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken[0]);
- return;
- }
- strcpy(idTag, "");
- }
- //===============================================
- // Ocpp Remote Stop
- //===============================================
- bool Is_Ocpp_RemoteStopReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_RemoteStopReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq = false;
- return;
- }
- }
- //===============================================
- // Ocpp StopReason
- //===============================================
- void Set_Ocpp_StopReason(int gun_index, char *reason)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, reason);
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "" ) == EQUAL)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, reason);
- }
- }
- // Maintain server
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- memcpy(ShmOCPP16DataPH->StopTransaction[gun_index].StopReason, ShmOCPP16Data->StopTransaction[gun_index].StopReason, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].StopReason));
- }
- }
- void Get_Ocpp_StopReason(int gun_index, char *reason)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(reason, (char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(reason, (char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason);
- return;
- }
- strcpy(reason, "");
- }
- void Clean_Ocpp_StopReason(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "");
- }
- // Maintain server
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason, "");
- }
- }
- //===============================================
- // Ocpp StatusNotification ErrorCode
- //===============================================
- void Set_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, errCode);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- bool Is_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, errCode) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)_BackupStatusNotification[gun_index].ErrorCode, errCode) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp StatusNotification VendorErrorCode
- //===============================================
- void Set_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, vendorCode);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- bool Is_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, vendorCode) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)_BackupStatusNotification[gun_index].VendorErrorCode, vendorCode) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp ChargingProfileConf
- //===============================================
- bool Is_Ocpp_ChargingProfileConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileConf == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ChargingProfileConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = NO;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileConf = NO;
- return;
- }
- }
- //===============================================
- // Ocpp ChargingProfileReq
- //===============================================
- bool Is_Ocpp_ChargingProfileReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == YES ? true : false;
- }
- return false;
- }
- void Set_Ocpp_ChargingProfileReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = YES;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = YES;
- return;
- }
- }
- //===============================================
- // Ocpp SmartChargingProfile ChargingProfileKind
- //===============================================
- bool Is_Ocpp_ChargingProfileKind(int gun_index, char *kind)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileKind, kind) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->SmartChargingProfile [gun_index].chargingProfileKind, kind) == EQUAL ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_ChargingProfileId(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].id == YES ? true : false;
- }
- return false;
- }
- int Get_Ocpp_ChargingProfileStartTime(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.StartSchedule);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].startSchedule);
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileScheduleCount(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod);
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileScheduleTime(int gun_index, int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[schedule_index].StartPeriod;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[schedule_index].startPeriod;
- }
- return 0;
- }
- float Get_Ocpp_ChargingProfileScheduleLimit(int gun_index, int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[schedule_index].Limit;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[schedule_index].limit;
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileScheduleNumberPhases(int gun_index, int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[schedule_index].NumberPhases;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[schedule_index].numberPhases;
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileStartIndex(int gun_index)
- {
- int _time = 0, _scheduleTime = 0;
- int _maxCount = 0;
- float _limit = 0;
- int _startCount = NO_DEFINE;
- _time = Get_Ocpp_ChargingProfileStartTime(gun_index);
- _maxCount = Get_Ocpp_ChargingProfileScheduleCount(gun_index);
- for(int i = 0; i < _maxCount; i++)
- {
- _scheduleTime = Get_Ocpp_ChargingProfileScheduleTime(gun_index, i);
- if(_time >= _scheduleTime)
- {
- _limit = Get_Ocpp_ChargingProfileScheduleLimit(gun_index, i);
- if((i == 0 && _limit >= MIN_OUTPUT_CUR) || _limit > MIN_OUTPUT_CUR)
- {
- _startCount = i;
- }
- }
- }
- return _startCount;
- }
- //===============================================
- // Ocpp MaxChargingProfile ChargingProfileKind
- //===============================================
- bool Is_Ocpp_MaxChargingProfileKind(char *kind)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->MaxChargingProfile.ChargingProfileKind, kind) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->MaxChargingProfile.chargingProfileKind, kind) == EQUAL ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_MaxChargingProfileId(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingProfileId == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.id == YES ? true : false;
- }
- return false;
- }
- int Get_Ocpp_MaxProfileStartTime(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return GetStartScheduleTime(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.StartSchedule);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return GetStartScheduleTime(ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].startSchedule);
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileScheduleCount(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ARRAY_SIZE(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ARRAY_SIZE(ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod);
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileScheduleTime(int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[schedule_index].StartPeriod;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[schedule_index].startPeriod;
- }
- return 0;
- }
- float Get_Ocpp_MaxProfileScheduleLimit(int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[schedule_index].Limit;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[schedule_index].limit;
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileScheduleNumberPhases(int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[schedule_index].NumberPhases;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[schedule_index].limit;
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileStartIndex(void)
- {
- int _time = 0, _scheduleTime = 0;
- int _maxCount = 0;
- float _limit = 0;
- int _startCount = NO_DEFINE;
- _time = Get_Ocpp_MaxProfileStartTime();
- _maxCount = Get_Ocpp_MaxProfileScheduleCount();
- for(int i = 0; i < _maxCount; i++)
- {
- _scheduleTime = Get_Ocpp_MaxProfileScheduleTime(i);
- if(_time >= _scheduleTime)
- {
- _limit = Get_Ocpp_MaxProfileScheduleLimit(i);
- if((i == 0 && _limit >= MIN_OUTPUT_CUR) || _limit > MIN_OUTPUT_CUR)
- {
- _startCount = i;
- }
- }
- }
- return _startCount;
- }
- //===============================================
- // Ocpp isRemoteStartWaitReq
- //===============================================
- int Is_Ocpp_RemoteStartWaitReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq;
- }
- return 0;
- }
- //===============================================
- // Ocpp SessionTarget
- //===============================================
- void Get_Ocpp_SessionTarget(int gunIndex, struct StructSessionTarget *sessionTarget)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memcpy(sessionTarget, &ShmOCPP16Data->SessionTarget[gunIndex], sizeof(struct StructSessionTarget));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- memcpy(sessionTarget, &ShmOCPP20Data->SessionTarget[gunIndex], sizeof(struct StructSessionTarget));
- }
- }
- //===============================================
- // Ocpp OffLineMaxChargingPower
- //===============================================
- int Get_Ocpp_OffLineMaxChargingPower(void)
- {
- // unit: W
- int maxChargingPower = 0;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- maxChargingPower = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- maxChargingPower = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OffLineMaxChargingPower].variableAttribute[0].value);
- }
- return maxChargingPower > 0 ? maxChargingPower : 0;
- }
- //===============================================
- // Ocpp OcmfData
- //===============================================
- bool Is_Ocpp_SendOcmfDataReq(int gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->OcmfData[gunIndex].SendOcmfDataReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- void Set_Ocpp_SendOcmfDataReq(int gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->OcmfData[gunIndex].SendOcmfDataReq = YES;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Clean_Ocpp_SendOcmfDataReq(int gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->OcmfData[gunIndex].SendOcmfDataReq = NO;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_OcmfData(int gunIndex, char *key, char *ocmfInfo)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strncpy((char *)ShmOCPP16Data->OcmfData[gunIndex].PublicKey, key, sizeof(ShmOCPP16Data->OcmfData[gunIndex].PublicKey));
- strncpy((char *)ShmOCPP16Data->OcmfData[gunIndex].DataString, ocmfInfo, sizeof(ShmOCPP16Data->OcmfData[gunIndex].DataString));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Set_StartIdType
- //===============================================
- void Set_StartIdType(int gunIndex, int type)
- {
- chargingInfo[gunIndex]->StartIdType = type;
- }
- //===============================================
- // DeductResult
- //===============================================
- void Set_Deduct_UserId(int gunIndex, char *userId)
- {
- memcpy((char *)&ShmChargerInfo->DeductResultReq[gunIndex].creditNo, userId, strlen(userId));
- }
- void Set_Deduct_TransactionId(int gunIndex, int transaction)
- {
- ShmChargerInfo->DeductResultReq[gunIndex].TransactionId = transaction;
- }
- void Clean_DeductInfo(int gunIndex)
- {
- memset(&ShmChargerInfo->DeductResultReq[gunIndex], 0x00, sizeof(DeductResultInfoData));
- }
- bool Is_DeductResultReq(int gunIndex)
- {
- return ShmChargerInfo->DeductResultReq[gunIndex].DeductReq ? true : false;
- }
- //===============================================
- // ReaderStatus
- //===============================================
- bool Is_ReaderStatusReq(int gunIndex)
- {
- return ShmChargerInfo->ReaderStatus[gunIndex].ReaderStatusReq ? true : false;
- }
- void Clean_ReaderStatusInfo(int gunIndex)
- {
- memset(&ShmChargerInfo->ReaderStatus[gunIndex], 0x00, sizeof(DeductResultInfoData));
- }
- //===============================================
- // TransactionInfoData
- //===============================================
- void Set_UserTransactionId(int gunIndex, int transaction)
- {
- ShmChargerInfo->UserTransaction[gunIndex].TransactionId = transaction;
- }
- void Set_UserPrice(int gunIndex, float price)
- {
- ShmChargerInfo->UserTransaction[gunIndex].UserPrice = price;
- }
- void Set_UserTotalCost(int gunIndex, float cost)
- {
- ShmChargerInfo->UserTransaction[gunIndex].TotalCost = cost;
- }
- void Set_UserAccountBalance(int gunIndex, float balance)
- {
- ShmChargerInfo->UserTransaction[gunIndex].AccountBalance = balance;
- }
- void Set_UserDiscount(int gunIndex, float discount)
- {
- ShmChargerInfo->UserTransaction[gunIndex].CostDiscount = discount;
- }
- void Clean_UserTransaction(int gunIndex)
- {
- memset(&ShmChargerInfo->UserTransaction[gunIndex], 0x00, sizeof(TransactionInfoData));
- ShmChargerInfo->UserTransaction[gunIndex].AccountBalance = -65535;
- }
- void Clean_UserPriceAndReceipt(int gunIndex)
- {
- memset((char *)&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gunIndex][0], 0x00, sizeof(ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gunIndex]));
- memset((char *)&ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gunIndex][0], 0x00, sizeof(ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gunIndex]));
- }
- //===============================================
- // OccupancyDeductReq
- //===============================================
- bool Is_OccupancyDeductReq(int gunIndex)
- {
- return ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.DeductReq ? true : false;
- }
- void Clean_OccupancyDeductReq(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.DeductReq = false;
- }
- bool Is_OccupancyKeepCountingReq(int gunIndex)
- {
- return ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.KeepCounting ? true : false;
- }
- void Set_OccupancyKeepCountingReq(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.KeepCounting = true;
- }
- void Clean_OccupancyKeepCountingReq(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.KeepCounting = false;
- }
- bool Is_OccupancyFeeForceCancelReq(int gunIndex)
- {
- return ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.ForceCancel ? true : false;
- }
- void Set_OccupancyFeeForceCancelReq(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.ForceCancel = true;
- }
- void Clean_OccupancyFeeForceCancelReq(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.ForceCancel = false;
- }
- //===============================================
- // Ocpp GetDiagnosticsReq
- //===============================================
- bool Is_Ocpp_GetDiagnosticsReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- void Clean_Ocpp_GetDiagnosticsReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Main process
- //===============================================
- // 檢查 Byte 中某個 Bit 的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
- {
- return ( _byte & mask_table[_bit] ) != 0x00;
- }
- // 設定 Byte 中某個 Bit的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- // value : 修改的值為 0 or 1
- void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
- {
- if(value == 1)
- *_byte |= (1 << _bit);
- else if (value == 0)
- *_byte ^= (1 << _bit);
- }
- void UserScanFunction()
- {
- }
- unsigned char isModeChange(unsigned char gun_index)
- {
- unsigned char result = NO;
- if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
- {
- result = YES;
- chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
- }
- return result;
- }
- void AnnounceAccountBalance(unsigned char index, float balance)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance = true;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AccountBalance = balance;
- if(!ShmChargerInfo->Control.TestCtrl.bits.DisableBalance)
- {
- Set_Connector_MiscCommand(index, MISC_CONN_ACCOUNT_BALANCE);
- }
- LOG_INFO("%sAnnounce Account Balance %4.2f To Connector %d",
- ShmChargerInfo->Control.TestCtrl.bits.DisableBalance ? "Do Not " : "", balance, index + 1);
- }
- void FouceAnnounceAccountBalance(unsigned char index)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance)
- {
- AnnounceAccountBalance(index, 0);
- }
- }
- void CleanConnectorUserIdAndPrice(unsigned char index)
- {
- if(chargingInfo[index]->SystemStatus == S_IDLE)
- {
- LOG_INFO("*********** Connector %d Clean UserId & UserPrice ***********", index + 1);
- memset(chargingInfo[index]->StartUserId, 0x00, 32);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].UserPrice = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AccountBalance = -65535;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance = false;
- }
- }
- void DispenserAuthInitial(unsigned char dispenser)
- {
- LOG_INFO("*********** Dispenser %d Authorizing Initial ***********", dispenser + 1);
- memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- // clean dispenser price
- memset((char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[dispenser][0], 0x00, sizeof(ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[dispenser]));
- }
- void GunAuthInitial(unsigned char connector)
- {
- LOG_INFO("*********** Gun %d Authorizing Initial ***********", connector + 1);
- memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- }
- unsigned char _preGunAuthResult[GENERAL_GUN_QUANTITY];
- unsigned char _preDispenserAuthResult[GENERAL_GUN_QUANTITY];
- struct timespec _GunAuth_Time[GENERAL_GUN_QUANTITY];
- struct timespec _DispenserAuth_Time[GENERAL_GUN_QUANTITY];
- void AuthorizeTimeoutProcess(void)
- {
- int CompletedTime = 0;
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult != _AuthResult_None)
- {
- if(_preGunAuthResult[index] != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult)
- {
- GetClockTime(&_GunAuth_Time[index]);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult == _AuthResult_Invalid)
- {
- FouceAnnounceAccountBalance(index);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult == _AuthResult_Invalid)
- {
- if(GetTimeoutValue(_GunAuth_Time[index]) / uSEC_VAL >= AUTHORIZE_COMPLETED_TIME)
- {
- LOG_INFO("*********** Gun %d Authorizing Initial ***********", index + 1);
- memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- CleanConnectorUserIdAndPrice(index);
- }
- }
- }
- _preGunAuthResult[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult;
- }
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult != _AuthResult_None)
- {
- if(_preDispenserAuthResult[index] != ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult)
- {
- GetClockTime(&_DispenserAuth_Time[index]);
- }
- CompletedTime = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult == _AuthResult_Valid ?
- (ShmChargerInfo->CabinetMiscValue.ConnectionTimeout + AUTHORIZE_COMPLETED_TIME) : AUTHORIZE_COMPLETED_TIME;
- if(GetTimeoutValue(_DispenserAuth_Time[index]) / uSEC_VAL >= CompletedTime)
- {
- DispenserAuthInitial(index);
- }
- }
- _preDispenserAuthResult[index] = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult;
- }
- }
- BOOL IsConnectorAuthorizeSuccess(unsigned char connector)
- {
- BOOL success = false;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].AuthInfo.AuthResult == _AuthResult_Valid)
- {
- success = true;
- }
- return success;
- }
- BOOL IsAutoGunSelectionAuthorizeSuccess(unsigned char connector)
- {
- BOOL success = false;
- unsigned char dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].ParentDispensetIndex;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].AuthInfo.AuthResult == _AuthResult_Valid)
- {
- success = true;
- }
- return success;
- }
- bool CheckConnectorTypeStatus(void)
- {
- bool result = true;
- if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 14)
- {
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = ShmChargerInfo->Control.MaxConnector;
- ShmChargerInfo->Control.ChargerRatingPower = ParsingRatingPower((char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- ShmChargerInfo->Control.PsuQuantityByModel = ShmChargerInfo->Control.ChargerRatingPower / (INFY_SINGLE_PSU_POWER / 100);
- LOG_INFO("DC Gun Count = %d, RatingPower = %d.%d kW",
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
- (ShmChargerInfo->Control.ChargerRatingPower / 10),
- (ShmChargerInfo->Control.ChargerRatingPower % 10));
- if(ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0)
- {
- result = false;
- }
- //DO360 charging info default setting
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- chargingInfo[i] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData;
- chargingInfo[i]->Index = (i < ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity || i == 0) ? i : 0xFF;
- chargingInfo[i]->Evboard_id = 0x00;
- chargingInfo[i]->ReservationId = -1;
- chargingInfo[i]->slotsIndex = 0;
- chargingInfo[i]->SystemStatus = S_BOOTING;
- chargingInfo[i]->Type = _Type_Unknown;
- chargingInfo[i]->type_index = 0;
- chargingInfo[i]->IsAvailable = YES;
- }
- }
- else
- {
- // Module Name 不正確 - 告警
- result = false;
- }
- return result;
- }
- void KillTaskExceptPrimary()
- {
- system("killall Module_Authorize");
- system("killall Module_CabinetParallel");
- system("killall Module_ChargerSelfTest");
- system("killall Module_LedIndication");
- system("killall Module_EvComm");
- system("killall Module_InternalComm");
- KillPowerModuleTask();
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- }
- void KillNtpd(void)
- {
- system("killall ntpd");
- }
- void KillAllTask()
- {
- system("killall Module_Authorize");
- system("killall Module_CabinetParallel");
- system("killall Module_ChargerSelfTest");
- system("killall Module_LedIndication");
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_LcmControl");
- system("killall Module_InternalComm");
- KillPowerModuleTask();
- Kill_Ocpp_Service();
- Kill_MaintainOcpp_Service();
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- }
- int TransferImageViaFTP(char *IpAddress, char *SourcePath)
- {
- int isPass = PASS;
- unsigned char ftpcmdbuf[256];
- //Using ftpput command to transfer upgrade image,
- //User name : root
- //User password : y42j/4cj84
- //Destination : as same as source path
- sprintf((char*)ftpcmdbuf,"ftpput -u root -p y42j/4cj84 %s \"%s\" \"%s\"", IpAddress, SourcePath, SourcePath);
- if(system((char*)ftpcmdbuf) != 0)
- {
- isPass = FAIL;
- }
- return isPass;
- }
- void TriggerDispenserUpgrade(unsigned char index, char *FileName)
- {
- memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].FwFileName, 0x00, 128);
- memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].FwFileName, FileName, strlen(FileName));
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].Setting.bits.FirmwareUpdateRequest = true;
- LOG_INFO("Trigger dispenser %d to update image [%s]", index + 1, FileName);
- }
- BOOL PutImageToAllDispenser(char *SourcePath, char *FileName, char *model_name)
- {
- int isPass = FAIL;
- int isImageOK[GENERAL_GUN_QUANTITY];
- int dispenser_index = 0;
- BOOL transferred = FALSE;
- memset(isImageOK, 0x00, sizeof(isImageOK));
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- isPass = FAIL;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
- {
- dispenser_index = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex;
- if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser_index].ModelName, (char *)model_name) != EQUAL)
- {
- LOG_INFO("Dispenser %d model name [%s] update ignore",
- dispenser_index + 1,
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser_index].ModelName);
- continue;
- }
- char DispenserIpAddress[16];
- memset((char*)DispenserIpAddress, 0x00, 16);
- sprintf((char*)DispenserIpAddress, "%d.%d.%d.%d",
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 0) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 8) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) & 0xFF));
- LOG_INFO("Transfer Image(%s) to Dispenser %d (IP: %s)", SourcePath, dispenser_index + 1, DispenserIpAddress);
- isPass = TransferImageViaFTP(DispenserIpAddress, SourcePath);
- isImageOK[dispenser_index] = isPass;
- LOG_INFO("Dispenser %d Put Image %s", dispenser_index + 1, isPass == PASS ? "OK" : "Fail");
- }
- }
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- if(isImageOK[i] > 0)
- {
- TriggerDispenserUpgrade(i, FileName);
- transferred = true;
- }
- }
- return transferred;
- }
- BOOL WaitAllDispenserUpgradeCompleted(void)
- {
- BOOL completed = TRUE;
- GetClockTime(&_DispenserUpgrade_time);
- do
- {
- completed = TRUE;
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateRequest ||
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateConfirm)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateCompleted)
- {
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateRequest = false;
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateConfirm = false;
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateCompleted = false;
- LOG_INFO("Dispenser %d Upgrade Success", i + 1);
- }
- else
- {
- completed = FALSE;
- }
- }
- }
- if(GetTimeoutValue(_DispenserUpgrade_time) / uSEC_VAL >= DISPENSER_UPGRADE_TIME)
- {
- LOG_INFO("Wait Upgrade Timeout");
- completed = FALSE;
- break;
- }
- if(completed == FALSE)
- {
- sleep(1);
- }
- }while(!completed);
- return completed;
- }
- void UpgradePrepare(void)
- {
- int count = 0;
- SetAcContactor(OFF);
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- count++;
- }
- }
- }
- if(count > 0)
- {
- sleep(3);
- }
- else
- {
- sleep(1);
- }
- }
- void TriggerPCabinetUpgrade(unsigned char index, char *FileName)
- {
- memset(ShmChargerInfo->ParallelCabinet.PCabinet[index].FwFileName, 0x00, 128);
- memcpy(ShmChargerInfo->ParallelCabinet.PCabinet[index].FwFileName, FileName, strlen(FileName));
- ShmChargerInfo->ParallelCabinet.PCabinet[index].UpdateRequest = YES;
- LOG_INFO("Trigger PCabinet %d to update image [%s]", index + 1, FileName);
- }
- BOOL PutImageToAllParallelCabinet(char *SourcePath, char *FileName)
- {
- int isPass = FAIL;
- BOOL transferred = FALSE;
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- int channel = ShmChargerInfo->ParallelCabinet.PCabinet[i].SocketChannel;
- if(ShmChargerInfo->CabinetConnInfo[channel].Status == _SCONN_MATCHED &&
- ShmChargerInfo->ParallelCabinet.PCUpdateState[i] == Not_Update)
- {
- char PCabinetIpAddress[16];
- memset((char*)PCabinetIpAddress, 0x00, 16);
- sprintf((char*)PCabinetIpAddress, "%d.%d.%d.%d",
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 0) & 0xFF),
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 8) & 0xFF),
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 16) & 0xFF),
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 24) & 0xFF));
- isPass = TransferImageViaFTP(PCabinetIpAddress, SourcePath);
- if(isPass == PASS)
- {
- TriggerPCabinetUpgrade(i, FileName);
- }
- transferred = true;
- }
- }
- }
- return transferred;
- }
- BOOL WaitAllPCabinetStartUpgrade(void)
- {
- BOOL isStart = true;
- int count = 0;
- struct timespec _waitStart;
- GetClockTime(&_waitStart);
- do
- {
- isStart = true;
- count = 0;
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- count++;
- if(ShmChargerInfo->ParallelCabinet.PCUpdateState[i] != Updating)
- {
- isStart = false;
- }
- }
- }
- if((GetTimeoutValue(_waitStart) / uSEC_VAL) >= START_UPGRADE_TIME)
- {
- isStart = false;
- break;
- }
- usleep(10000);
- }while(!isStart);
- if(isStart && count > 0)
- {
- LOG_INFO("Total %d PCabinet upgrade start...", count);
- }
- else
- {
- if(count > 0)
- {
- LOG_INFO("Wait PCabinet upgrade timeout");
- }
- else
- {
- LOG_INFO("No PCabinet need to upgrade");
- }
- }
- return isStart;
- }
- BOOL WaitAllPCabinetUpgradeCompleted(void)
- {
- BOOL completed = true;
- int count = 0;
- struct timespec _waitCompleted;
- GetClockTime(&_waitCompleted);
- do
- {
- completed = true;
- count = 0;
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- count++;
- if(ShmChargerInfo->ParallelCabinet.PCUpdateState[i] != Updated)
- {
- completed = false;
- }
- }
- }
- if((GetTimeoutValue(_waitCompleted) / uSEC_VAL) >= PCABINET_UPGRADE_TIME)
- {
- completed = false;
- break;
- }
- usleep(10000);
- }while(!completed);
- if(completed && count > 0)
- {
- LOG_INFO("Total %d PCabinet upgrade completed!", count);
- }
- else
- {
- if(count > 0)
- {
- LOG_INFO("Wait PCabinet upgrade completed timeout");
- }
- else
- {
- LOG_INFO("Need not to wait PCabinet completed");
- }
- }
- return completed;
- }
- BOOL WaitMCabinetUpgradeCompleted(void)
- {
- BOOL completed = true;
- struct timespec _waitCompleted;
- GetClockTime(&_waitCompleted);
- do
- {
- completed = false;
- if(ShmChargerInfo->SCabinetControl.NeedUpgrade == _R_NoUpgrade)
- {
- completed = true;
- }
- if(ShmChargerInfo->SCabinetControl.SCabinetStatus != _DeviceStatus_Idle &&
- ShmChargerInfo->SCabinetControl.SCabinetStatus != _DeviceStatus_Alarm &&
- ShmChargerInfo->SCabinetControl.SCabinetStatus != _DeviceStatus_Charging)
- {
- completed = false;
- break;
- }
- if((GetTimeoutValue(_waitCompleted) / uSEC_VAL) >= MCABINET_UPGRADE_TIME)
- {
- completed = false;
- break;
- }
- usleep(10000);
- }while(!completed);
- if(completed)
- {
- LOG_INFO("MCabinet upgrade completed!");
- }
- else
- {
- LOG_INFO("Wait MCabinet upgrade timeout or disconnected...");
- }
- return completed;
- }
- bool IsModelNameMatch(char *model)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == model[0] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[1] == model[1] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[7] == model[7] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[8] == model[8] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[9] == model[9] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[11] == model[11] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[12] == model[12] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[13] == model[13])
- {
- return true;
- }
- return false;
- }
- unsigned long long getAvailableMemory(void)
- {
- long pages = sysconf(_SC_AVPHYS_PAGES);
- long page_size = sysconf(_SC_PAGE_SIZE);
- return pages * page_size;
- }
- void ImageTypeParsing(unsigned int type, char *type_str)
- {
- switch(type)
- {
- case 0x10000001:
- sprintf(type_str, "Image_uboot");
- break;
- case 0x10000002:
- sprintf(type_str, "Image_dtb");
- break;
- case 0x10000003:
- sprintf(type_str, "Image_zImage");
- break;
- case 0x10000004:
- sprintf(type_str, "Image_ramdisk");
- break;
- case 0x10000005:
- sprintf(type_str, "Image_Factory");
- break;
- case 0x10000006:
- sprintf(type_str, "Image_Primary");
- break;
- case 0x10000007:
- sprintf(type_str, "Image_CCS_uboot");
- break;
- case 0x10000008:
- sprintf(type_str, "Image_CCS_dtb");
- break;
- case 0x10000009:
- sprintf(type_str, "Image_CCS_zImage");
- break;
- case 0x1000000A:
- sprintf(type_str, "Image_CCS_ramdisk");
- break;
- case 0x1000000B:
- sprintf(type_str, "Image_CAHdeMO");
- break;
- case 0x1000000C:
- sprintf(type_str, "Image_GBT");
- break;
- case 0x1000000D:
- sprintf(type_str, "Image_Relay");
- break;
- case 0x1000000E:
- sprintf(type_str, "Image_Fan");
- break;
- case 0x1000000F:
- sprintf(type_str, "Image_LCM");
- break;
- case 0x10000010:
- sprintf(type_str, "Image_Infy_PFC");
- break;
- case 0x10000011:
- sprintf(type_str, "Image_Infy_DD");
- break;
- case 0x10000014:
- sprintf(type_str, "Image_LED");
- break;
- case 0x10000015:
- sprintf(type_str, "Image_LCM_APK");
- break;
- default:
- sprintf(type_str, "Image_Unknown");
- break;
- }
- }
- char CheckUpdateProcess()
- {
- char _model[32];
- char _type[32];
- bool support = false;
- bool OneImageOnly = false;
- int isPass = true;
- uint8_t retSucc = 0;
- uint8_t retFail = 0;
- byte target = 0;
- char *new_str = NULL;
- unsigned char *ptr = NULL;
- int fd = 0;
- int uartFd = 0;
- unsigned int Type = 0;
- long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
- DIR *d;
- struct dirent *dir;
- char cmdBuf[128];
- int availableMem = 0;
- memset(_model, 0x00, sizeof(_model));
- memset(_type, 0x00, sizeof(_type));
- availableMem = getAvailableMemory() / (1024 * 1024);
- LOG_INFO("AvailableMemory: %d MBytes", availableMem);
- // If available memory too small, free memory cache first
- if(availableMem < MIN_AVAILABLE_MEMORY)
- {
- LOG_INFO("Available memory less than %d MBytes, free cache & kill ntpd.", MIN_AVAILABLE_MEMORY);
- system("echo 3 > /proc/sys/vm/drop_caches");
- KillNtpd();
- availableMem = getAvailableMemory() / (1024 * 1024);
- LOG_INFO("AvailableMemory: %d MBytes", availableMem);
- }
- d = opendir("/mnt/");
- if(d)
- {
- while((dir = readdir(d)) != NULL && !OneImageOnly)
- {
- if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
- continue;
- }
- new_str = calloc(strlen("/mnt/") + strlen(dir->d_name) + 1, sizeof(char));
- strcat(new_str, "/mnt/");
- strcat(new_str, dir->d_name);
- fd = open(new_str, O_RDONLY);
- if(fd < 0)
- {
- close(fd);
- free(new_str);
- continue;
- }
- LOG_INFO("%s\n", new_str);
- ptr = calloc(MaxLen, sizeof(char)); //-48 is take out the header
- memset(ptr, 0xFF, MaxLen); //-48 is take out the header
- //get the image length
- ImageLen = read(fd, ptr, MaxLen);
- if(ImageLen > 20)
- {
- memcpy(_model, ptr, 16);
- Type = (((unsigned int)ptr[16]) << 24 | ((unsigned int)ptr[17]) << 16 | ((unsigned int)ptr[18]) << 8 | ((unsigned int)ptr[19]));
- ImageTypeParsing(Type, _type);
- LOG_INFO("Model: %s, Type: %s", _model, _type);
- }
- free(ptr);
- if (ImageLen > 20)
- {
- support = false;
- availableMem = getAvailableMemory() / (1024 * 1024);
- LOG_INFO("AvailableMemory: %dMByte", availableMem);
- //if(strcmp(model, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == EQUAL)
- if(IsModelNameMatch(_model))
- {
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- PutImageToAllParallelCabinet(new_str, dir->d_name);
- WaitAllPCabinetStartUpgrade();
- }
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE && ShmChargerInfo->SCabinetControl.NeedUpgrade)
- {
- ShmChargerInfo->SCabinetControl.UpgradeState = Updating;
- sleep(1);
- }
- switch (Type)
- {
- case 0x10000001:
- case 0x10000002:
- case 0x10000003:
- case 0x10000004:
- case 0x10000005:
- support = true;
- _UpgradeNeedReboot = TRUE;
- LOG_INFO("Upgrade Flash Start...", Type);
- isPass = Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- LOG_INFO("Upgrade Flash End, %s", isPass ? "Pass" : "Fail");
- break;
- case 0x10000006: // primary mcu
- case 0x1000000D: // relay board
- case 0x1000000E: // fan board
- case 0x10000014: // led board
- support = true;
- target = 0x00;
- if (Type == 0x10000006)
- {
- target = UPGRADE_PRI;
- }
- else if (Type == 0x1000000D)
- {
- target = UPGRADE_RB;
- }
- else if (Type == 0x1000000E)
- {
- target = UPGRADE_FAN;
- }
- else if (Type == 0x10000014)
- {
- target = UPGRADE_LED;
- }
- uartFd = InitComPort(target);
- if(target == UPGRADE_RB)
- {
- isPass = Upgrade_UART(uartFd, Type, UPGRADE_DORC1, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- if(isPass == PASS)
- {
- retSucc++;
- }
- else
- {
- retFail++;
- }
- LOG_INFO("Upgrade %s", isPass == PASS ? "Success" : "Fail");
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
- {
- sleep(3);
- isPass = Upgrade_UART(uartFd, Type, UPGRADE_DORC2, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- }
- }
- else
- {
- isPass = Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- }
- close(uartFd);
- break;
- }
- if(support)
- {
- if(isPass == PASS)
- {
- retSucc++;
- }
- else
- {
- retFail++;
- }
- LOG_INFO("Upgrade %s", isPass == PASS ? "Success" : "Fail");
- }
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- LOG_INFO("MCabinet upgrade completed");
- WaitAllPCabinetUpgradeCompleted();
- }
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE && ShmChargerInfo->SCabinetControl.UpgradeState == Updating)
- {
- ShmChargerInfo->SCabinetControl.UpgradeState = Updated;
- LOG_INFO("SCabinet upgrade completed");
- WaitMCabinetUpgradeCompleted();
- }
- }
- else
- {
- if(_model[0] == 'D' && (_model[1] == 'D' || _model[1] == 'X'))
- {
- OneImageOnly = true;
- _UpgradeNeedReboot = TRUE;
- LOG_INFO("Start Put Image To Dispenser");
- PutImageToAllDispenser(new_str, dir->d_name, _model);
- WaitAllDispenserUpgradeCompleted();
- LOG_INFO("All Dispenser Upgrade Completed");
- }
- else
- {
- retFail++;
- LOG_INFO("Model Name Is Not Match: %s", _model);
- }
- }
- }
- else
- {
- retFail++;
- LOG_INFO("Image length is illegal");
- }
- sprintf(cmdBuf, "rm -f %s", new_str);
- system(cmdBuf);
- close(fd);
- free(new_str);
- }
- }
- closedir(d);
- if(retFail != 0)
- {
- return FAIL;
- }
- return PASS;
- }
- void TriggerDispenserConnectionTimeoutSetting(void)
- {
- BOOL trigger = FALSE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0 &&
- !Is_Dispenser_MiscCommand(i, MISC_DISP_CONNECTION_TIMEOUT))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_CONNECTION_TIMEOUT);
- }
- }
- if(trigger)
- {
- LOG_INFO("********** Trigger Dispenser Connector Timeout Value: %d **********", ShmChargerInfo->CabinetMiscValue.ConnectionTimeout);
- }
- }
- void CheckConnectionTimeout(void)
- {
- if(!Is_Ocpp_Task_Alive())
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- else
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _connectionTimeout = Get_Ocpp_ConnectionTimeOut();
- if(_connectionTimeout <= 0)
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- else
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- if(_connectionTimeout != ShmChargerInfo->CabinetMiscValue.ConnectionTimeout)
- {
- ShmChargerInfo->CabinetMiscValue.ConnectionTimeout = _connectionTimeout;
- TriggerDispenserConnectionTimeoutSetting();
- }
- }
- void CreateTimeoutFork()
- {
- pid_t timeoutPid;
- timeoutPid = fork();
- if (timeoutPid == 0)
- {
- GetClockTime(&_cmdSubPriority_time);
- CheckConnectionTimeout();
- LOG_INFO("Timeout Fork PID = %d", getpid());
- while(true)
- {
- if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000)
- {
- CheckConnectionTimeout();
- GetClockTime(&_cmdSubPriority_time);
- }
- sleep(1);
- }
- }
- }
- void CheckFactoryConfigFunction(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
- {
- char Buf[256];
- sprintf(Buf, "cd /root;./FactoryConfig -m");
- system(Buf);
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- }
- void CheckFwUpdateFunction(void)
- {
- char UpdateResult = PASS;
- if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedSelfTest = false;
- UpgradePrepare();
- ShmChargerInfo->Control.PrimaryCtrl.bits.Paused = true;
- ShmChargerInfo->Control.RelayCtrl.bits.Paused = true;
- ShmChargerInfo->Control.FanCtrl.bits.Paused = true;
- LOG_INFO("ftp : update start.");
- TryCloseWatchdog();
- //KillTask();
- system("killall Module_PrimaryComm");
- system("killall Module_InternalComm");
- UpdateResult = CheckUpdateProcess();
- if (UpdateResult == PASS)
- {
- LOG_INFO("ftp : update complete.");
- }
- else
- {
- LOG_INFO("ftp : update fail.");
- }
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
- sleep(10);
- if(_UpgradeNeedReboot)
- {
- system("reboot -f");
- }
- else
- {
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- else if(Is_Ocpp_UpdateFirmwareReq())
- {
- Clean_Ocpp_UpdateFirmwareReq();
- ShmChargerInfo->Control.SysCtrl.bits.NeedSelfTest = false;
- UpgradePrepare();
- ShmChargerInfo->Control.PrimaryCtrl.bits.Paused = true;
- ShmChargerInfo->Control.RelayCtrl.bits.Paused = true;
- ShmChargerInfo->Control.FanCtrl.bits.Paused = true;
- if(Is_Ocpp_UpdateFirmwareStatus("Downloaded"))
- {
- LOG_INFO("Backend : update start.");
- TryCloseWatchdog();
- Set_Ocpp_UpdateFirmwareStatus("Installing");
- Set_Ocpp_FirmwareStatusNotificationReq();
- //KillTask();
- system("killall Module_PrimaryComm");
- system("killall Module_InternalComm");
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- setChargerMode(_index, MODE_UPDATE);
- }
- UpdateResult = CheckUpdateProcess();
- if (UpdateResult == PASS)
- {
- LOG_INFO("Backend : update complete.");
- Set_Ocpp_UpdateFirmwareStatus("Installed");
- }
- else
- {
- LOG_INFO("Backend : update fail.");
- Set_Ocpp_UpdateFirmwareStatus("InstallationFailed");
- }
- Set_Ocpp_FirmwareStatusNotificationReq();
- sleep(10);
- if(_UpgradeNeedReboot)
- {
- system("reboot -f");
- }
- else
- {
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- }
- void ExecuteWriteFlash(void)
- {
- struct SysConfigData config;
- memcpy(&config, &ShmSysConfigAndInfo->SysConfig, sizeof(struct SysConfigData));
- config.SwitchDebugFlag = NO;
- strcpy((char *) config.UserId, "");
- int result = StoreUsrConfigData(&config);
- if(result != 1)
- {
- LOG_INFO("Store User Config NG");
- }
- else
- {
- LOG_INFO("Store User Config OK");
- }
- }
- struct timespec _WiringInfo_time;
- int CheckFlashUpdate(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.FlashConfigChanged)
- {
- ShmChargerInfo->Control.SysCtrl.bits.FlashConfigChanged = false;
- LOG_INFO("Flash Config Changed");
- GetClockTime(&_WiringInfo_time);
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
- }
- if(ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable)
- {
- // wait for 30s to write flash or write flash immediately
- if((GetTimeoutValue(_WiringInfo_time) / uSEC_VAL) >= WIRING_INFO_DELAY ||
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately)
- {
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = false;
- LOG_INFO("Start Writing Flash");
- pid_t writePid = fork();
- if(writePid == 0)
- {
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashBusy = true;
- ExecuteWriteFlash();
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashBusy = false;
- if(ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset)
- {
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset = false;
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
- LOG_INFO("Write Flash OK And Need Soft Reset");
- }
- return NO;
- }
- LOG_INFO("Write Flash Conpleted");
- }
- }
- return YES;
- }
- void CheckSoftHardReset(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset)
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = false;
- LOG_INFO("********** Need Soft Reset **********");
- sleep(5);
- Kill_Ocpp_Service();
- KillAllTask();
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- }
- if(ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset)
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = false;
- LOG_INFO("********** Need Hard Reset **********");
- sleep(5);
- system("reboot -f");
- }
- }
- struct timespec _Reboot_time;
- void TriggerDispenserHardwareReboot(void)
- {
- BOOL trigger = FALSE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.HardwareRebootConfirm == 0 &&
- !Is_Dispenser_MiscCommand(i, MISC_DISP_SOFTWARE_RESET))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_HARDWARE_REBOOT);
- }
- }
- }
- if(trigger)
- {
- GetClockTime(&_Reboot_time);
- LOG_INFO("********** Trigger Dispenser Hardware Reboot **********");
- }
- }
- BOOL IsDispenserHardwareRebootResponsed(void)
- {
- BOOL response_ok = TRUE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.HardwareRebootConfirm)
- {
- response_ok = FALSE;
- // 10s for reboot request timeout
- if((GetTimeoutValue(_Reboot_time) / uSEC_VAL) >= REBOOT_TIMEOUT)
- {
- response_ok = TRUE;
- LOG_INFO("Reboot request timeout");
- }
- }
- }
- }
- return response_ok;
- }
- struct timespec _Reset_time;
- void TriggerDispenserSoftwareReset(void)
- {
- BOOL trigger = FALSE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.SoftwareResetConfirm == 0 &&
- !Is_Dispenser_MiscCommand(i, MISC_DISP_SOFTWARE_RESET))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_SOFTWARE_RESET);
- }
- }
- }
- if(trigger)
- {
- GetClockTime(&_Reset_time);
- LOG_INFO("********** Trigger Dispenser Software Reset **********");
- }
- }
- BOOL IsDispenserSoftwareResetResponsed(void)
- {
- BOOL response_ok = TRUE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.SoftwareResetConfirm)
- {
- response_ok = FALSE;
- // 10s for reset request timeout
- if((GetTimeoutValue(_Reset_time) / uSEC_VAL) >= RESET_TIMEOUT)
- {
- response_ok = TRUE;
- LOG_INFO("Reset request timeout");
- }
- }
- }
- }
- return response_ok;
- }
- // return time offset
- int TimeOffsetKeyParsing(char *StringItem)
- {
- int offset = 0;
- int hour = 0, minute = 0, sign = 1;
- char *ptrSave, *ptrToken;
- char strSource[501];
- memset(strSource, 0x00, sizeof(strSource));
- strcpy(strSource, StringItem);
- if(strSource[0] != '+' && strSource[0] != '-')
- {
- return offset;
- }
- sign = strSource[0] == '+' ? (1) : (-1);
- ptrToken = strtok_r(&strSource[1], ":", &ptrSave);
- if(ptrToken != NULL)
- {
- hour = atoi(ptrToken);
- ptrToken = strtok_r(NULL, ":", &ptrSave);
- if(ptrToken != NULL)
- {
- minute = atoi(ptrToken);
- offset = ((hour * 60) + minute) * sign;
- }
- }
- return offset;
- }
- char MyDefaultPriceString[501];
- void DefaultPriceHandler(void)
- {
- char price[501];
- char defaultPrice[512];
- memset(defaultPrice, 0x00, sizeof(defaultPrice));
- Get_Ocpp_DefaultPrice((char *)price);
- if(strcmp(MyDefaultPriceString, (char *)price) != EQUAL)
- {
- float ConnectionFee = 0, OccupancyFee = 0;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- ConnectionFee = PriceParsing(price, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
- ShmChargerInfo->PriceAndReceiptInfo.CurrentRate = PriceParsing(price, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
- OccupancyFee = PriceParsing(price, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
- LOG_INFO("******** Customer Audi Default Price *******");
- LOG_INFO("********** Connection Fee: %4.2f **********", ConnectionFee);
- LOG_INFO("********** Current Rate: %4.2f **********", ShmChargerInfo->PriceAndReceiptInfo.CurrentRate);
- LOG_INFO("********** Occupancy Fee: %4.2f **********", OccupancyFee);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- ShmChargerInfo->PriceAndReceiptInfo.CurrentRate = DefaultPriceParsing(price);
- ShellPriceParsing(price, defaultPrice);
- LOG_INFO("******* Customer Shell Default Price *******");
- LOG_INFO("*** Default Price: [%s]", defaultPrice);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
- {
- ShmChargerInfo->PriceAndReceiptInfo.CurrentRate = TccDefaultPriceParsing(price, &ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[0]);
- LOG_INFO("******* Customer Tcc Default Price *******");
- LOG_INFO("*** TimeOfDayPricing: %4.2f", ShmChargerInfo->PriceAndReceiptInfo.CurrentRate);
- }
- else
- {
- ShmChargerInfo->PriceAndReceiptInfo.CurrentRate = DefaultPriceParsing(price);
- strcpy(defaultPrice, price);
- LOG_INFO("********** Standard Default Price **********");
- LOG_INFO("********** Current Rate: %4.2f **********", ShmChargerInfo->PriceAndReceiptInfo.CurrentRate);
- LOG_INFO("*** Default Price: [%s]", defaultPrice);
- }
- strcpy(MyDefaultPriceString, price);
- }
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
- {
- ShmChargerInfo->PriceAndReceiptInfo.CurrentRate = GetNowTimePricing(&ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[0]);
- }
- if(ShmChargerInfo->CabinetMiscValue.DefaultPrice != ShmChargerInfo->PriceAndReceiptInfo.CurrentRate)
- {
- ShmChargerInfo->CabinetMiscValue.DefaultPrice = ShmChargerInfo->PriceAndReceiptInfo.CurrentRate;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_DEFAULT_PRICE))
- {
- Set_Dispenser_MiscCommand(i, MISC_DISP_DEFAULT_PRICE);
- }
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_CURRENCY))
- {
- Set_Dispenser_MiscCommand(i, MISC_DISP_CURRENCY);
- }
- }
- }
- LOG_INFO("********** Trigger Dispenser Default Price Value **********");
- }
- if(strlen(defaultPrice) > 0)
- {
- strcpy(ShmChargerInfo->PriceAndReceiptInfo.DefaultPriceString, defaultPrice);
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_DEFAULT_PRICE_STRING))
- {
- Set_Dispenser_MiscCommand(i, MISC_DISP_DEFAULT_PRICE_STRING);
- }
- }
- }
- LOG_INFO("********** Trigger Dispenser Default Price Value String **********");
- }
- }
- void UserPriceHandler(void)
- {
- char UserId[32];
- char price[500];
- char userPrice[512];
- memset(userPrice, 0x00, sizeof(userPrice));
- Get_Ocpp_UserPrice(UserId, price);
- if(strlen((char *)UserId) > 0 && strlen((char *)price) > 0)
- {
- float ConnectionFee = 0, CurrentRate = 0, OccupancyFee = 0;
- float AccountBalance = 0;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- ConnectionFee = PriceParsing((char *)price, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
- CurrentRate = PriceParsing((char *)price, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
- OccupancyFee = PriceParsing((char *)price, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
- AccountBalance = PriceParsing((char *)price, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
- LOG_INFO("********* Customer Audi User Price *********");
- LOG_INFO("********* User Id: [%s]", UserId);
- LOG_INFO("********* Connection Fee: [%7.2f]", ConnectionFee);
- LOG_INFO("********* Current Rate: [%7.2f]", CurrentRate);
- LOG_INFO("********* Occupancy Fee: [%7.2f]", OccupancyFee);
- LOG_INFO("********* Account Balance: [%7.2f]", AccountBalance);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- ShellPriceParsing(price, userPrice);
- LOG_INFO("******** Customer Shell User Price *********");
- LOG_INFO("******** User Id: [%s]", UserId);
- LOG_INFO("******** User Price: [%s]", userPrice);
- }
- else
- {
- CurrentRate = PriceParsing((char *)price, "chargineFee", _PHIHONG_PRICE_SPLIT_KEY);
- OccupancyFee = PriceParsing((char *)price, "parkingFee", _PHIHONG_PRICE_SPLIT_KEY);
- strcpy(userPrice, price);
- LOG_INFO("*********** Standard User Price ************");
- LOG_INFO("*********** User Id: [%s]", UserId);
- LOG_INFO("*********** Current Rate: [%7.2f]", CurrentRate);
- LOG_INFO("*********** Occupancy Fee: [%7.2f]", OccupancyFee);
- LOG_INFO("*********** User Price: [%s]", userPrice);
- }
- #if 0
- LOG_INFO("********** User Id: %s **********", UserId);
- LOG_INFO("********** User Price: %s", price);
- LOG_INFO("********** Connection Fee: %7.2f **********", ConnectionFee);
- LOG_INFO("********** Current Rate: %7.2f **********", CurrentRate);
- LOG_INFO("********** Occupancy Fee: %7.2f **********", OccupancyFee);
- LOG_INFO("********** Account Balance: %7.2f **********", AccountBalance);
- #endif
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.StartUserId, UserId) == EQUAL)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].UserPrice != CurrentRate ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance != AccountBalance)
- {
- LOG_INFO("********** Connector Id %d User Price %4.2f, Account Balance %7.2f **********",
- (i + 1), CurrentRate, AccountBalance);
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].UserPrice = CurrentRate;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance = AccountBalance;
- if(strlen(userPrice) > 0)
- {
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[i][0], userPrice);
- Set_Connector_MiscCommand(i, MISC_CONN_USER_PRICE_STRING);
- }
- if(chargingInfo[i]->SystemStatus == S_AUTHORIZING)
- {
- AnnounceAccountBalance(i, AccountBalance);
- }
- }
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].AuthInfo.AuthResult == _AuthResult_Valid)
- {
- if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].AuthInfo.AuthId, UserId) == EQUAL)
- {
- if(strlen(userPrice) > 0)
- {
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[i][0], userPrice);
- }
- }
- }
- }
- Clean_Ocpp_UserPrice();
- }
- }
- void RunningCostParsing(int gunIndex, char *strCost)
- {
- float ConnectionFee = 0, SessionFee = 0, OccupancyFee = -1, TotalCost = 0, EnergyCost = -1;
- float AccountBalance = 0;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- ConnectionFee = PriceParsing((char *)strCost, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
- SessionFee = PriceParsing((char *)strCost, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
- OccupancyFee = PriceParsing((char *)strCost, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
- TotalCost = PriceParsing((char *)strCost, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
- AccountBalance = PriceParsing((char *)strCost, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
- LOG_INFO("******** Customer Audi Gun %d Running Cost ********", (gunIndex + 1));
- LOG_INFO("******** Connection Fee: [%7.2f]", ConnectionFee);
- LOG_INFO("******** Session Fee: [%7.2f]", SessionFee);
- LOG_INFO("******** Occupancy Fee: [%7.2f]", OccupancyFee);
- LOG_INFO("******** Total Cost: [%7.2f]", TotalCost);
- LOG_INFO("******** Account Balance: [%7.2f]", AccountBalance);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- TotalCost = ShellRunningCostParsing(strCost);
- LOG_INFO("******** Customer Shell Gun %d Running Cost *******", (gunIndex + 1));
- LOG_INFO("******** Gun %d Running Cost", (gunIndex + 1));
- LOG_INFO("******** Total Cost: [%7.2f]", TotalCost);
- }
- else
- {
- EnergyCost = PriceParsing((char *)strCost, "chargingFee", _PHIHONG_PRICE_SPLIT_KEY);
- TotalCost = EnergyCost;
- OccupancyFee = PriceParsing((char *)strCost, "parkingFee", _PHIHONG_PRICE_SPLIT_KEY);
- LOG_INFO("********** Standard Gun %d Running Cost ***********", (gunIndex + 1));
- LOG_INFO("********** Energy Cost: [%7.2f]", EnergyCost);
- LOG_INFO("********** Occupancy Fee: [%7.2f]", OccupancyFee);
- LOG_INFO("********** Total Cost: [%7.2f]", TotalCost);
- }
- #if 0
- LOG_INFO("********** Connector Id: %d Running Cost **********", (gunIndex + 1));
- LOG_INFO("********** Connection Fee: %7.2f **********", ConnectionFee);
- LOG_INFO("********** Session Fee: %7.2f **********", SessionFee);
- LOG_INFO("********** Occupancy Fee: %7.2f **********", OccupancyFee);
- LOG_INFO("********** Total Cost: %7.2f **********", TotalCost);
- LOG_INFO("********** Account Balance: %7.2f **********", AccountBalance);
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].TotalCost != TotalCost ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].AccountBalance != AccountBalance)
- {
- LOG_INFO("********** Connector Id %d Total Cost %.2f, Account Balance %7.2f **********",
- (gunIndex + 1), TotalCost, AccountBalance);
- }
- #endif
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].TotalCost = TotalCost;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].AccountBalance = AccountBalance;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].EnergyCost = EnergyCost;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].ParkingFee = OccupancyFee;
- }
- void RunningCostHandler(void)
- {
- char strCost[256];
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- Get_Ocpp_RunningCost(i, strCost);
- if(strlen((char *)strCost) > 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.SystemStatus >= S_REASSIGN_CHECK &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.SystemStatus <= S_CHARGING)
- {
- RunningCostParsing(i, strCost);
- }
- Clean_Ocpp_RunningCost(i);
- }
- }
- }
- void EnableConnectorBillRequest(int gunIndex, ChargingBillInfoData *bill)
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_MiscReq;
- ShmChargerInfo->AllBill.GunBill[gunIndex].TryCnt = 0;
- ShmChargerInfo->AllBill.GunBill[gunIndex].TxId = bill->TxId;
- memcpy(&ShmChargerInfo->AllBill.GunBill[gunIndex].FeeInfo, &bill->FeeInfo, sizeof(FeeInfoData));
- }
- void DisableConnectorBill(int gunIndex)
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_Idle;
- ShmChargerInfo->AllBill.GunBill[gunIndex].TryCnt = 0;
- ShmChargerInfo->AllBill.GunBill[gunIndex].TxId = 0;
- memset(&ShmChargerInfo->AllBill.GunBill[gunIndex].FeeInfo, 0x00, sizeof(FeeInfoData));
- }
- void FinalCostParsing(int txId, char *strCost, ChargingBillInfoData *_bill)
- {
- memset(_bill, 0x00, sizeof(ChargingBillInfoData));
- _bill->TxId = txId;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- _bill->FeeInfo.ConnectionFee = PriceParsing(strCost, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
- _bill->FeeInfo.SessionFee = PriceParsing(strCost, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
- _bill->FeeInfo.ParkingFee = PriceParsing(strCost, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
- _bill->FeeInfo.TotalCost = PriceParsing(strCost, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
- _bill->FeeInfo.AccountBalance = PriceParsing(strCost, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- _bill->FeeInfo.TotalCost = ShellFinalCostParsing(strCost);
- GetShellReceiptInfo(strCost, (char *)_bill->Receipt);
- }
- else
- {
- _bill->FeeInfo.TotalCost = PriceParsing(strCost, "chargingFee", _PHIHONG_PRICE_SPLIT_KEY);
- _bill->FeeInfo.ParkingFee = PriceParsing(strCost, "parkingFee", _PHIHONG_PRICE_SPLIT_KEY);
- _bill->FeeInfo.AccountBalance = PriceParsing(strCost, "accountBalance", _PHIHONG_PRICE_SPLIT_KEY);
- _bill->FeeInfo.CostDiscount = PriceParsing(strCost, "couponPoint", _PHIHONG_PRICE_SPLIT_KEY);
- _bill->FeeInfo.RemainAmount = PriceParsing(strCost, "farewellMessage", _PHIHONG_PRICE_SPLIT_KEY);
- if(strlen((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL) > 0)
- {
- sprintf(_bill->Receipt, "%s%d",
- (char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL[0],
- txId);
- }
- }
- }
- void UpdateCurrentFinalCost(int gunIndex, ChargingBillInfoData *_bill)
- {
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- LOG_INFO("********* Customer Audi Gun %d Final Cost *********", (gunIndex + 1));
- LOG_INFO("********* Connection Fee: [%7.2f]", _bill->FeeInfo.ConnectionFee);
- LOG_INFO("********* Session Fee: [%7.2f]", _bill->FeeInfo.SessionFee);
- LOG_INFO("********* Occupancy Fee: [%7.2f]", _bill->FeeInfo.ParkingFee);
- LOG_INFO("********* Total Cost: [%7.2f]", _bill->FeeInfo.TotalCost);
- LOG_INFO("********* Account Balance: [%7.2f]", _bill->FeeInfo.AccountBalance);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- LOG_INFO("********* Customer Shell Gun %d Final Cost ********", (gunIndex + 1));
- LOG_INFO("********* Total Cost: [%7.2f]", _bill->FeeInfo.TotalCost);
- LOG_INFO("********* Receipt: [%s]", _bill->Receipt);
- }
- else
- {
- LOG_INFO("*********** Standard Gun %d Final Cost ************", (gunIndex + 1));
- LOG_INFO("*********** Occupancy Fee: [%7.2f]", _bill->FeeInfo.ParkingFee);
- LOG_INFO("*********** Total Cost: [%7.2f]", _bill->FeeInfo.TotalCost);
- LOG_INFO("*********** Account Balance: [%7.2f]", _bill->FeeInfo.AccountBalance);
- LOG_INFO("*********** Coupon Point: [%7.2f]", _bill->FeeInfo.CostDiscount);
- LOG_INFO("*********** Remain Amount: [%7.2f]", _bill->FeeInfo.RemainAmount);
- LOG_INFO("*********** Receipt: [%s]", _bill->Receipt);
- }
- #if 0
- LOG_INFO("********** Connector Id: %d Final Cost **********", (gunIndex + 1));
- LOG_INFO("********** Connection Fee: %7.2f **********", ConnectionFee);
- LOG_INFO("********** Session Fee: %7.2f **********", SessionFee);
- LOG_INFO("********** Occupancy Fee: %7.2f **********", OccupancyFee);
- LOG_INFO("********** Total Cost: %7.2f **********", TotalCost);
- LOG_INFO("********** Account Balance: %7.2f **********", AccountBalance);
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].TotalCost != TotalCost ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].AccountBalance != AccountBalance ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].CostDiscount != CostDiscount)
- {
- LOG_INFO("********** Connector Id %d Total Cost %.2f, Account Balance: %7.2f, Discount: %d.%02d **********",
- (gunIndex + 1), TotalCost, AccountBalance, (CostDiscount / 100), (CostDiscount % 100));
- }
- #endif
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].TotalCost = _bill->FeeInfo.TotalCost;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].AccountBalance = _bill->FeeInfo.AccountBalance;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].CostDiscount = _bill->FeeInfo.CostDiscount;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].EnergyCost = _bill->FeeInfo.EnergyCost;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].ParkingFee = _bill->FeeInfo.ParkingFee;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemainAmount = _bill->FeeInfo.RemainAmount;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_FINAL_COST);
- if(strlen(_bill->Receipt) > 0)
- {
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gunIndex][0], _bill->Receipt);
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_RECEIPT);
- }
- DB_Update_FinalCost_Status(localDb, _bill->TxId, BILL_SATAUS_Bypass_OK);
- }
- bool IsBillStatusChanged(int gunIndex)
- {
- return ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus == ShmChargerInfo->AllBill.GunBill[gunIndex].PreStatus ?
- false : true;
- }
- void SyncBillStatus(int gunIndex)
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].PreStatus = ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus;
- }
- void EnableUndisposedBill(int dispenserIndex)
- {
- LOG_INFO("Enable Dispenser %d Undisposed ChargingBill", dispenserIndex + 1);
- _isUndisposedFinalCost[dispenserIndex] = true;
- }
- void FindUndisposedAndTrigger(int dispenserIndex)
- {
- int txId = 0;
- char strCost[256];
- ChargingBillInfoData _bill;
- bool find = false;
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
- txId = DB_Get_Undisposed_FinalCost(localDb, gun, strCost);
- if(txId >= 0)
- {
- LOG_INFO("Find Gun %d Undisposed ChargingBill, txId: [%d]", gun + 1, txId);
- FinalCostParsing(txId, (char *)strCost, &_bill);
- EnableConnectorBillRequest(gun, &_bill);
- find = true;
- break;
- }
- }
- if(!find)
- {
- //LOG_INFO("Dispenser %d Undisposed ChargingBill Not Found", dispenserIndex + 1);
- _isUndisposedFinalCost[dispenserIndex] = false;
- }
- }
- bool IsDispenserBillStatusBusy(int dispenserIndex)
- {
- bool busy = false;
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
- if(ShmChargerInfo->AllBill.GunBill[gun].BillStatus != _BillStatus_Idle)
- {
- busy = true;
- break;
- }
- }
- return busy;
- }
- void DispenserBillRequestProcess(int dispenserIndex)
- {
- if(IsDispenserIdle(dispenserIndex) && !IsDispenserBillStatusBusy(dispenserIndex))
- {
- if(!_canUpdateFinalCost[dispenserIndex])
- {
- _canUpdateFinalCost[dispenserIndex] = true;
- GetClockTime(&_DispenserBill_Time[dispenserIndex]);
- }
- if(_canUpdateFinalCost[dispenserIndex] && _isUndisposedFinalCost[dispenserIndex])
- {
- if(GetSecTimeoutValue(_DispenserBill_Time[dispenserIndex]) >= FINAL_COST_UPDATE_TIME)
- {
- //LOG_INFO("Try Find Dispenser %d Undisposed ChargingBill", dispenserIndex + 1);
- FindUndisposedAndTrigger(dispenserIndex);
- GetClockTime(&_DispenserBill_Time[dispenserIndex]);
- }
- }
- }
- else
- {
- _canUpdateFinalCost[dispenserIndex] = false;
- }
- }
- void GunBillRequestProcess(int gunIndex)
- {
- unsigned char _status = ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus;
- switch(_status)
- {
- case _BillStatus_Idle:
- if(IsBillStatusChanged(gunIndex))
- {
- SyncBillStatus(gunIndex);
- }
- break;
- case _BillStatus_MiscReq:
- if(IsBillStatusChanged(gunIndex))
- {
- Database_INFO("Gun %d ChargingBill MiscRequest", gunIndex + 1);
- SyncBillStatus(gunIndex);
- }
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_WaitMiscClean;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_CHARGING_BILL);
- break;
- case _BillStatus_WaitMiscClean:
- if(IsBillStatusChanged(gunIndex))
- {
- SyncBillStatus(gunIndex);
- GetClockTime(&_ConnectorBill_Time[gunIndex]);
- }
- if((GetTimeoutValue(_ConnectorBill_Time[gunIndex]) / uSEC_VAL) >= FINAL_COST_TIMEOUT)
- {
- Database_INFO("Gun %d ChargingBill WaitMisc Timeout", gunIndex + 1);
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_Fail;
- }
- break;
- case _BillStatus_MiscClean:
- if(IsBillStatusChanged(gunIndex))
- {
- Database_INFO("Gun %d ChargingBill MiscClean", gunIndex + 1);
- SyncBillStatus(gunIndex);
- GetClockTime(&_ConnectorBill_Time[gunIndex]);
- }
- if((GetTimeoutValue(_ConnectorBill_Time[gunIndex]) / uSEC_VAL) >= FINAL_COST_TIMEOUT)
- {
- Database_INFO("Gun %d ChargingBill Wait Dispenser Timeout", gunIndex + 1);
- ShmChargerInfo->AllBill.GunBill[gunIndex].TryCnt++;
- if(ShmChargerInfo->AllBill.GunBill[gunIndex].TryCnt >= MAX_FINAL_COST_MISC_COUNT)
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_Fail;
- }
- else
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_MiscReq;
- }
- }
- break;
- case _BillStatus_UpdateDone:
- if(IsBillStatusChanged(gunIndex))
- {
- Database_INFO("Gun %d ChargingBill UpdateDone", gunIndex + 1);
- SyncBillStatus(gunIndex);
- }
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_Completed;
- break;
- case _BillStatus_Completed:
- if(IsBillStatusChanged(gunIndex))
- {
- SyncBillStatus(gunIndex);
- GetClockTime(&_ConnectorBill_Time[gunIndex]);
- }
- if((GetTimeoutValue(_ConnectorBill_Time[gunIndex]) / uSEC_VAL) >= FINAL_COST_TIMEOUT)
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_End;
- }
- break;
- case _BillStatus_Fail:
- if(IsBillStatusChanged(gunIndex))
- {
- SyncBillStatus(gunIndex);
- DB_Update_FinalCost_Status(localDb, ShmChargerInfo->AllBill.GunBill[gunIndex].TxId, BILL_SATAUS_UPDATED_FAIL);
- }
- DisableConnectorBill(gunIndex);
- break;
- case _BillStatus_End:
- if(IsBillStatusChanged(gunIndex))
- {
- SyncBillStatus(gunIndex);
- DB_Update_FinalCost_Status(localDb, ShmChargerInfo->AllBill.GunBill[gunIndex].TxId, BILL_SATAUS_UPDATED_OK);
- }
- DisableConnectorBill(gunIndex);
- break;
- default:
- DisableConnectorBill(gunIndex);
- break;
- }
- }
- void FinalCostHandler(void)
- {
- int txId = 0;
- char strCost[256];
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- txId = Get_Ocpp_FinalCostTxId(i);
- Get_Ocpp_FinalCost(i, strCost);
- if(strlen((char *)strCost) > 0)
- {
- DB_Insert_FinalCost(localDb, i, txId, strCost);
- Database_INFO("Insert FinalCost: Gun %d TxId[%d]", i + 1, txId);
- if(ShmChargerInfo->UserTransaction[i].TransactionId == txId)
- {
- ChargingBillInfoData _bill;
- FinalCostParsing(txId, (char *)strCost, &_bill);
- UpdateCurrentFinalCost(i, &_bill);
- }
- else
- {
- EnableUndisposedBill(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].ParentDispensetIndex);
- }
- Clean_Ocpp_FinalCost(i);
- }
- }
- if(ShmChargerInfo->Control.TestCtrl.bits.TryUndisposedBill)
- {
- ShmChargerInfo->Control.TestCtrl.bits.TryUndisposedBill = false;
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- _isUndisposedFinalCost[i] = true;
- }
- }
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
- {
- DispenserBillRequestProcess(i);
- }
- else
- {
- _canUpdateFinalCost[i] = false;
- }
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- GunBillRequestProcess(i);
- }
- }
- char MyTimeOffsetString[501];
- void TimeOffsetHandler(void)
- {
- char timeOffset[501];
- Get_Ocpp_TimeOffset((char *)timeOffset);
- if(strcmp(MyTimeOffsetString, (char *)timeOffset) != EQUAL)
- {
- BOOL trigger = FALSE;
- int offset = 0;
- offset = TimeOffsetKeyParsing(timeOffset);
- LOG_INFO("********** Time Offset String [%s] -> Value [%d] -> Time [%s%02d:%02d]",
- timeOffset, offset, offset >= 0 ? "+" : "-", (abs(offset) / 60), (abs(offset) % 60));
- ShmChargerInfo->CabinetMiscValue.TimeOffset = offset;
- #if 0
- time_t timep;
- struct tm *tm;
- time(&timep);
- tm = localtime(&timep);
- LOG_INFO(" NowTime: %d/%02d/%02d %02d:%02d:%02d",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
- timep += (offset * 60);
- tm = localtime(&timep);
- LOG_INFO("OffsetTime: %d/%02d/%02d %02d:%02d:%02d",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
- #endif
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_TIME_OFFSET))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_TIME_OFFSET);
- }
- }
- }
- if(trigger)
- {
- LOG_INFO("********** Trigger Dispenser Time Offset **********");
- }
- strcpy(MyTimeOffsetString, timeOffset);
- }
- }
- struct timespec _Cost_Price_time;
- void CheckOcppCostAndPrice(void)
- {
- // 5s for reboot request timeout
- if((GetTimeoutValue(_Cost_Price_time) / uSEC_VAL) >= OCPP_COST_REQ_INTERVAL)
- {
- GetClockTime(&_Cost_Price_time);
- DefaultPriceHandler();
- UserPriceHandler();
- RunningCostHandler();
- TimeOffsetHandler();
- }
- FinalCostHandler();
- }
- void CheckRemoteStartNoIdRequest(void)
- {
- if(Is_Ocpp_RemoteStartWaitReq())
- {
- if(!ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId)
- {
- LOG_INFO("Ocpp remote start without connector id is trigger");
- ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId = true;
- AnnounceRemoteStartNoID();
- GetClockTime(&_RemoteStartNoId_Time);
- }
- if(ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId)
- {
- // to avoid keep RemoteStartNoId state when ocpp is disconnected
- if((GetTimeoutValue(_RemoteStartNoId_Time) / uSEC_VAL) >= (ShmChargerInfo->CabinetMiscValue.ConnectionTimeout + CONNECTION_TIME_OFFSET))
- {
- ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId = false;
- }
- }
- }
- else
- {
- if(ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId)
- {
- LOG_INFO("Ocpp remote start without connector id is expired");
- }
- ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId = false;
- }
- }
- void CheckOcppPageChangeRequest(void)
- {
- int gunId = 0, pageIndex = 0;
- if(Is_Ocpp_LcdOverideReq(&gunId, &pageIndex))
- {
- Clean_Ocpp_LcdOverideReq();
- LOG_INFO("Gun %d Ocpp Line Status [%d] is trigger", gunId, pageIndex);
- AnnounceLineStatusCode(gunId - 1, pageIndex);
- }
- }
- void CheckLcmPageChangeRequest(void)
- {
- bool isTrigger = false;
- CheckRemoteStartNoIdRequest();
- CheckOcppPageChangeRequest();
- for(int index = 0; index < CONNECTOR_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- isTrigger = false;
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorID[i] - 1;
- if(ShmChargerInfo->ConnectorPageReq[gun].CtrlValue != 0)
- {
- isTrigger = true;
- break;
- }
- }
- if(isTrigger)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_CHANGE_LCM_INFO);
- }
- else
- {
- Clean_Dispenser_MiscCommand(index, MISC_DISP_CHANGE_LCM_INFO);
- }
- }
- }
- }
- void CheckStationInfo(void)
- {
- int station_id = 0;
- char station_name[64];
- if(Is_Ocpp_ChargerStationReq())
- {
- memset(station_name, 0x00, sizeof(station_name));
- Get_Ocpp_ChargerStationInfo(&station_id, station_name);
- if(strcmp(station_name, ShmChargerInfo->StationInfo.StationName) != EQUAL ||
- ShmChargerInfo->StationInfo.StationID != station_id)
- {
- strcpy(ShmChargerInfo->StationInfo.StationName, station_name);
- ShmChargerInfo->StationInfo.StationID = station_id;
- LOG_INFO("Station ID: %d, Name: %s", ShmChargerInfo->StationInfo.StationID, ShmChargerInfo->StationInfo.StationName);
- AnnounceStationInfo();
- }
- Clean_Ocpp_ChargerStationReq();
- }
- }
- void CheckWeatherInfo(void)
- {
- int weatherID = 0;
- float temperature = 0;
- char strWeather[16];
- char *str_weather_type[] = {STR_WEATHER_NONE, STR_WEATHER_SUNNY, STR_WEATHER_CLOUDY, STR_WEATHER_RAIN, STR_WEATHER_THUNDERSTORM, STR_WEATHER_SNOW, STR_WEATHER_MIST};
- if(Is_Ocpp_WeatherReq())
- {
- Get_Ocpp_WeatherInfo(&weatherID, &temperature);
- if(weatherID != ShmChargerInfo->StationInfo.WeatherID ||
- temperature != ShmChargerInfo->StationInfo.Temperature)
- {
- ShmChargerInfo->StationInfo.WeatherID = weatherID;
- ShmChargerInfo->StationInfo.Temperature = temperature;
- if(ShmChargerInfo->StationInfo.WeatherID <= _WEATHER_Mist)
- {
- strcpy(strWeather, str_weather_type[ShmChargerInfo->StationInfo.WeatherID]);
- }
- else
- {
- sprintf(strWeather, "%d", ShmChargerInfo->StationInfo.WeatherID);
- }
- LOG_INFO("Weather: [%s][%d], Temperature: %4.1f", strWeather, ShmChargerInfo->StationInfo.WeatherID, ShmChargerInfo->StationInfo.Temperature);
- AnnounceStationInfo();
- }
- Clean_Ocpp_WeatherReq();
- }
- }
- bool _WriteDeductBusy[CONNECTOR_QUANTITY] = {0};
- void CheckDeductResultRequest(void)
- {
- char *str_ReaderStatus[] = {STR_DEDUCT_FAIL, STR_DEDUCT_PASS, STR_DEDUCT_CANCEL, STR_DEDUCT_PREAUTH};
- char cardNo[21];
- char appNo[10];
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(Is_DeductResultReq(i))
- {
- if(!_WriteDeductBusy[i])
- {
- if(!Is_Ocpp_ReportCreditDeductReq() && ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _WriteDeductBusy[i] = true;
- //Set_Ocpp_DeductTransaction(_BackupDeductResult[i].TransactionId);
- //Set_Ocpp_DeductCreditNo((char *)&_BackupDeductResult[i].creditNo);
- //Set_Ocpp_DeductVemData("");
- //Set_Ocpp_DeductAmount(((double)_BackupDeductResult[i].DeductAmount / 100));
- //Set_Ocpp_DeductResult(_BackupDeductResult[i].DeductResult);
- //Set_Ocpp_DonateInvoice(_BackupDeductResult[i].IsDonateInvoice);
- if(Set_Ocpp_DeductInfo(&ShmChargerInfo->DeductResultReq[i]))
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memcpy(cardNo, (char *)&ShmChargerInfo->DeductResultReq[i].creditNo[0], sizeof(ShmChargerInfo->DeductResultReq[i].creditNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(appNo, (char *)&ShmChargerInfo->DeductResultReq[i].ApprovalNumber[0], sizeof(ShmChargerInfo->DeductResultReq[i].ApprovalNumber));
- Set_Ocpp_ReportCreditDeductReq();
- LOG_INFO("DeductReport Gun %d TxId: %d, UserId: %s, ApprovalNo: [%s], Amount: %d.%02d, [%s], Donate: %s",
- i + 1,
- ShmChargerInfo->DeductResultReq[i].TransactionId,
- cardNo,
- appNo,
- (ShmChargerInfo->DeductResultReq[i].DeductAmount / 100),
- (ShmChargerInfo->DeductResultReq[i].DeductAmount % 100),
- str_ReaderStatus[ShmChargerInfo->DeductResultReq[i].DeductResult],
- ShmChargerInfo->DeductResultReq[i].IsDonateInvoice ? "Yes" : "No");
- if(ShmChargerInfo->DeductResultReq[i].DeductResult == _Deduct_PreAuth_Pass)
- {
- memcpy(&ShmChargerInfo->ReaderStatus[i], &ShmChargerInfo->DeductResultReq[i], sizeof(DeductResultInfoData));
- ShmChargerInfo->ReaderStatus[i].ReaderStatusReq = YES;
- }
- }
- }
- }
- else
- {
- if(!Is_Ocpp_ReportCreditDeductReq())
- {
- Clean_DeductInfo(i);
- _WriteDeductBusy[i] = false;
- }
- }
- }
- else
- {
- _WriteDeductBusy[i] = false;
- }
- }
- }
- bool _WriteReDeductBusy = false;
- void CheckReDeductRequest(void)
- {
- char *str_ReaderStatus[] = {STR_DEDUCT_FAIL, STR_DEDUCT_PASS, STR_DEDUCT_CANCEL, STR_DEDUCT_PREAUTH};
- char cardNo[21];
- char appNo[10];
- if(ShmChargerInfo->ReDeductReq.DeductReq)
- {
- if(!_WriteReDeductBusy)
- {
- if(!Is_Ocpp_ReportCreditDeductReq() && ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _WriteReDeductBusy = true;
- if(Set_Ocpp_DeductInfo(&ShmChargerInfo->ReDeductReq))
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memcpy(cardNo, (char *)&ShmChargerInfo->ReDeductReq.creditNo[0], sizeof(ShmChargerInfo->ReDeductReq.creditNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(appNo, (char *)&ShmChargerInfo->ReDeductReq.ApprovalNumber[0], sizeof(ShmChargerInfo->ReDeductReq.ApprovalNumber));
- Set_Ocpp_ReportCreditDeductReq();
- LOG_INFO("ReDeductReport TxId: %d, UserId: %s, ApprovalNo: [%s], Amount: %d.%02d, [%s], Donate: %s",
- ShmChargerInfo->ReDeductReq.TransactionId,
- cardNo,
- appNo,
- (ShmChargerInfo->ReDeductReq.DeductAmount / 100),
- (ShmChargerInfo->ReDeductReq.DeductAmount % 100),
- str_ReaderStatus[ShmChargerInfo->ReDeductReq.DeductResult],
- ShmChargerInfo->ReDeductReq.IsDonateInvoice ? "Yes" : "No");
- if(ShmChargerInfo->ReDeductReq.DeductResult == _Deduct_PreAuth_Pass && ShmChargerInfo->ReDeductReq.ConnectorId != 0xFF)
- {
- int gunIndex = ShmChargerInfo->ReDeductReq.ConnectorId - 1;
- memcpy(&ShmChargerInfo->ReaderStatus[gunIndex], &ShmChargerInfo->ReDeductReq, sizeof(DeductResultInfoData));
- ShmChargerInfo->ReaderStatus[gunIndex].ReaderStatusReq = YES;
- }
- }
- }
- }
- else
- {
- if(!Is_Ocpp_ReportCreditDeductReq())
- {
- memset(&ShmChargerInfo->ReDeductReq, 0x00, sizeof(DeductResultInfoData));
- _WriteReDeductBusy = false;
- }
- }
- }
- else
- {
- _WriteReDeductBusy = false;
- }
- }
- bool _WriteReaderStatusBusy[CONNECTOR_QUANTITY] = {0};
- void CheckReaderStatusRequest(void)
- {
- char *str_ReaderStatus[] = {STR_DEDUCT_FAIL, STR_DEDUCT_PASS, STR_DEDUCT_CANCEL, STR_DEDUCT_PREAUTH};
- char cardNo[21];
- char appNo[10];
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(Is_ReaderStatusReq(i))
- {
- if(!_WriteReaderStatusBusy[i])
- {
- if(!Is_Ocpp_TcciReaderStatusReq(i) && ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _WriteReaderStatusBusy[i] = true;
- if(Set_Ocpp_TcciReaderStatus(i, &ShmChargerInfo->ReaderStatus[i]))
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memcpy(cardNo, (char *)&ShmChargerInfo->ReaderStatus[i].creditNo[0], sizeof(ShmChargerInfo->ReaderStatus[i].creditNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(appNo, (char *)&ShmChargerInfo->ReaderStatus[i].ApprovalNumber[0], sizeof(ShmChargerInfo->ReaderStatus[i].ApprovalNumber));
- Set_Ocpp_TcciReaderStatusReq(i);
- LOG_INFO("StatusReport Gun %d: [%s], CreditNo: [%s], ApprovalNo: [%s]",
- i + 1, str_ReaderStatus[ShmChargerInfo->ReaderStatus[i].DeductResult], cardNo, appNo);
- }
- }
- }
- else
- {
- if(!Is_Ocpp_TcciReaderStatusReq(i))
- {
- Clean_ReaderStatusInfo(i);
- _WriteReaderStatusBusy[i] = false;
- }
- }
- }
- else
- {
- _WriteReaderStatusBusy[i] = false;
- }
- }
- }
- void CheckOccupancyPrice(void)
- {
- float _price = 0;
- if(Is_Ocpp_TcciSetOccupancyPriceReq())
- {
- _price = Get_Ocpp_TcciOccupancyPrice();
- if(ShmChargerInfo->CabinetMiscValue.ParkingPrice != _price)
- {
- ShmChargerInfo->CabinetMiscValue.ParkingPrice = _price;
- LOG_INFO("Set OccupancyPrice: [%6.2f]", ShmChargerInfo->CabinetMiscValue.ParkingPrice);
- AnnounceOccupancyPrice();
- }
- Clean_Ocpp_TcciSetOccupancyPriceReq();
- }
- }
- bool IsParkingButtonStatusChanged(int gunIndex)
- {
- return ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus == ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.PreStatus ?
- false : true;
- }
- void SyncParkingButtonStatus(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.PreStatus = ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus;
- }
- int OccupancyButtonSync(int gunIndex)
- {
- int _pass = FAIL;
- unsigned char _status = ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus;
- switch(_status)
- {
- case _BillStatus_Idle:
- if(IsParkingButtonStatusChanged(gunIndex))
- {
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus, 0x00, sizeof(MiscRequestStatus));
- SyncParkingButtonStatus(gunIndex);
- }
- break;
- case _BillStatus_MiscReq:
- if(IsParkingButtonStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyButton [MiscRequest]", gunIndex + 1);
- SyncParkingButtonStatus(gunIndex);
- }
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_WaitMiscClean;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_PARKING_STATUS);
- break;
- case _BillStatus_WaitMiscClean:
- if(IsParkingButtonStatusChanged(gunIndex))
- {
- SyncParkingButtonStatus(gunIndex);
- GetClockTime(&_ParkingStatus_Time[gunIndex]);
- }
- if((GetTimeoutValue(_ParkingStatus_Time[gunIndex]) / uSEC_VAL) >= PARKING_STATUS_TIMEOUT)
- {
- Occupancy_INFO("Gun %d OccupancyButton [WaitMisc Timeout]", gunIndex + 1);
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_MiscReq;
- }
- break;
- case _BillStatus_MiscClean:
- if(IsParkingButtonStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyButton [MiscClean]", gunIndex + 1);
- SyncParkingButtonStatus(gunIndex);
- GetClockTime(&_ParkingStatus_Time[gunIndex]);
- }
- if((GetTimeoutValue(_ParkingStatus_Time[gunIndex]) / uSEC_VAL) >= PARKING_STATUS_TIMEOUT)
- {
- LOG_INFO("Gun %d OccupancyButton [Wait Timeout]", gunIndex + 1);
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_MiscReq;
- }
- break;
- case _BillStatus_UpdateDone:
- if(IsParkingButtonStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyButton [UpdateDone]", gunIndex + 1);
- SyncParkingButtonStatus(gunIndex);
- }
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_Idle;
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus, 0x00, sizeof(MiscRequestStatus));
- _pass = PASS;
- break;
- default:
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus, 0x00, sizeof(MiscRequestStatus));
- break;
- }
- return _pass;
- }
- int NotifyOccupancyFeeActRequest(int gunIndex, int action)
- {
- char *str_notify_occupancy_act[] = {STR_NOTIFY_NONE, STR_GET_OCCUPANCY_FEE, STR_CANCEL_OCCUPANCY_DEDUCT, STR_CANCEL_OCCUPANCY_FEE};
- if(_notifyOccupancyFeeAct[gunIndex] == _Notify_None)
- {
- if(!Is_Ocpp_TcciOccupancyFeeActReq(gunIndex))
- {
- GetClockTime(&_GetOccupancyFee_Time[gunIndex]);
- Set_Ocpp_TcciOccupancyFeeAct(gunIndex, &ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill, action);
- _notifyOccupancyFeeAct[gunIndex] = action;
- LOG_INFO("Gun %d Set OccupancyFee Action [%s] Request", gunIndex + 1, str_notify_occupancy_act[action]);
- }
- }
- else
- {
- if(!Is_Ocpp_TcciOccupancyFeeActReq(gunIndex))
- {
- if(Is_Ocpp_TcciOccupancyFeeActStatus(gunIndex, "Accepted"))
- {
- if(_notifyOccupancyFeeAct[gunIndex] == _Notify_GetOccupancyFee)
- {
- Get_Ocpp_TcciGetOccupancyFeeResponse(gunIndex, &ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill);
- LOG_INFO("Gun %d Get Occupancy Fee: [%.2f], Duration: [%d], StartTime: [%s]",
- gunIndex + 1,
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.Fee,
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.Duration,
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.StartTime);
- }
- if(_notifyOccupancyFeeAct[gunIndex] == _Notify_CancelLocalDeduction)
- {
- LOG_INFO("Gun %d Occupancy Deduction Stopped", gunIndex + 1);
- }
- if(_notifyOccupancyFeeAct[gunIndex] == _Notify_CancelOccupancyFee)
- {
- LOG_INFO("Gun %d Occupancy Fee Force Clean", gunIndex + 1);
- }
- _notifyOccupancyFeeAct[gunIndex] = _Notify_None;
- return PASS;
- }
- else
- {
- LOG_INFO("Gun %d OccupancyFee Action [%s] Rejected", gunIndex + 1, str_notify_occupancy_act[action]);
- return FAIL;
- }
- }
- if((GetTimeoutValue(_GetOccupancyFee_Time[gunIndex]) / uSEC_VAL) >= OCCUPANCY_FEE_TIMEOUT)
- {
- // shall not reach here
- Clean_Ocpp_TcciNotifyOccupancyFeeActReq(gunIndex);
- _notifyOccupancyFeeAct[gunIndex] = _Notify_None;
- LOG_INFO("Gun %d OccupancyFee Action [%s] Request Timeout", gunIndex + 1, str_notify_occupancy_act[action]);
- return FAIL;
- }
- }
- return WAIT;
- }
- bool IsParkingStatusChanged(int gunIndex)
- {
- return ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status == ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].PreStatus ?
- false : true;
- }
- void SyncParkingStatus(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].PreStatus = ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status;
- }
- bool Is_Occupancy_Cancel(int gunIndex)
- {
- unsigned char dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].ParentDispensetIndex;
- if((!ShmSysConfigAndInfo->SysInfo.OcppConnStatus && !ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.SelfReq) ||
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus == _DS_None ||
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus == _DS_Timeout)
- {
- return true;
- }
- return false;
- }
- void OccupancyRequest(int gunIndex)
- {
- int _action = 0;
- bool feeRequest = false;
- bool keepCounting = false;
- int res = FAIL;
- char _sn[37];
- unsigned char _status = 0;
- char *str_action[] = {STR_OCCUPANCY_ACT_NONE, STR_OCCUPANCY_ACT_DISPLAY, STR_OCCUPANCY_ACT_CANCEL, STR_OCCUPANCY_ACT_PAID_OK, STR_OCCUPANCY_ACT_PAID_NG};
- _status = ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status;
- if(Is_Ocpp_TcciOccupancyDisplayReq(gunIndex))
- {
- memset(_sn, 0x00, sizeof(_sn));
- _action = Get_Ocpp_TcciOccupancyAction(gunIndex, sizeof(_sn) - 1, _sn);
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ActionId = _action;
- LOG_INFO("Gun %d OccupancyAction is [%s]", gunIndex + 1, str_action[_action]);
- Clean_Ocpp_TcciOccupancyDisplayReq(gunIndex);
- }
- if(ShmChargerInfo->ConnectorActReq[gunIndex].Flag.bits.ParkingFeeRequest)
- {
- feeRequest = true;
- ShmChargerInfo->ConnectorActReq[gunIndex].Flag.bits.ParkingFeeRequest =false;
- }
- if(Is_OccupancyKeepCountingReq(gunIndex))
- {
- if(_status == _Parking_WaitToPay)
- {
- keepCounting = true;
- }
- else
- {
- Clean_OccupancyKeepCountingReq(gunIndex);
- }
- }
- if(_status != _Parking_NoOccupancy && chargingInfo[gunIndex]->SystemStatus == S_CHARGING)
- {
- if(!Is_OccupancyFeeForceCancelReq(gunIndex))
- {
- Set_OccupancyFeeForceCancelReq(gunIndex);
- Occupancy_INFO("Gun %d Need Force Cancel OccupancyStatus", gunIndex + 1);
- }
- }
- if(Is_OccupancyFeeForceCancelReq(gunIndex))
- {
- res = NotifyOccupancyFeeActRequest(gunIndex, _Notify_CancelOccupancyFee);
- if(res == PASS || res == FAIL)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- Clean_OccupancyFeeForceCancelReq(gunIndex);
- return;
- }
- else
- {
- // wait response
- }
- }
- switch(_status)
- {
- case _Parking_NoOccupancy:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [Clean]", gunIndex + 1);
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex], 0x00, sizeof(OccupancyInfoData));
- SyncParkingStatus(gunIndex);
- }
- if(_action == _ParkingAction_DisplayButton)
- {
- memcpy(ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.Sn, _sn, sizeof(_sn));
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_SyncOccupancy;
- }
- break;
- case _Parking_SyncOccupancy:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [Sync]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus, 0x00, sizeof(MiscRequestStatus));
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_MiscReq;
- }
- if(_action == _ParkingAction_DisplayButton)
- {
- memcpy(ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.Sn, _sn, sizeof(_sn));
- }
- else if(_action == _ParkingAction_CancelOccupancy ||
- Is_Occupancy_Cancel(gunIndex))
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- else if(_action == _ParkingAction_PaidOnlineOK)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineOK;
- }
- else
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteStatus != _CRS_Preparing &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteStatus != _CRS_Charging)
- {
- if(OccupancyButtonSync(gunIndex) == PASS)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_Occupied;
- }
- }
- }
- break;
- case _Parking_Occupied:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [Start]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus, 0x00, sizeof(MiscRequestStatus));
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_MiscReq;
- }
- if(_action == _ParkingAction_DisplayButton)
- {
- memcpy(ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.Sn, _sn, sizeof(_sn));
- }
- else if(_action == _ParkingAction_CancelOccupancy ||
- Is_Occupancy_Cancel(gunIndex))
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- else if(_action == _ParkingAction_PaidOnlineOK)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineOK;
- }
- else if(_action == _ParkingAction_PaidOnlineFail)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineFail;
- }
- else
- {
- if(feeRequest)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_RequestFee;
- }
- }
- break;
- case _Parking_RequestFee:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [RequestFee]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- _notifyOccupancyFeeAct[gunIndex] = _Notify_None;
- GetClockTime(&_GetOccupancyFee_Time[gunIndex]);
- }
- if(_action == _ParkingAction_CancelOccupancy ||
- Is_Occupancy_Cancel(gunIndex))
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- else if(_action == _ParkingAction_PaidOnlineOK)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineOK;
- }
- else if(_action == _ParkingAction_PaidOnlineFail)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineFail;
- }
- else
- {
- if(ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.SelfReq)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_WaitToPay;
- }
- else
- {
- res = NotifyOccupancyFeeActRequest(gunIndex, _Notify_GetOccupancyFee);
- if(res == PASS)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_WaitToPay;
- }
- else if(res == FAIL)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- else
- {
- // wait response
- }
- }
- }
- break;
- case _Parking_WaitToPay:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [WaitToPay]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].BillReqStatus, 0x00, sizeof(MiscRequestStatus));
- _notifyOccupancyFeeAct[gunIndex] = _Notify_None;
- }
- if(_action == _ParkingAction_CancelOccupancy ||
- Is_Occupancy_Cancel(gunIndex))
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- else if(_action == _ParkingAction_PaidOnlineOK)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineOK;
- }
- else if(_action == _ParkingAction_PaidOnlineFail)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineFail;
- }
- else if(keepCounting)
- {
- res = NotifyOccupancyFeeActRequest(gunIndex, _Notify_CancelLocalDeduction);
- if(res == PASS)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_Occupied;
- Clean_OccupancyKeepCountingReq(gunIndex);
- }
- else if(res == FAIL)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- Clean_OccupancyKeepCountingReq(gunIndex);
- }
- else
- {
- // wait response
- }
- }
- break;
- case _Parking_PaidOnlineOK:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [PaidOnlineOK]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- GetClockTime(&_GetOccupancyFee_Time[gunIndex]);
- }
- if((GetTimeoutValue(_GetOccupancyFee_Time[gunIndex]) / uSEC_VAL) >= OCCUPANCY_FEE_TIMEOUT)
- {
- LOG_INFO("Gun %d Reset OccupancyStatus via PaidOnlineOK", gunIndex + 1);
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- break;
- case _Parking_PaidOnlineFail:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [PaidOnlineFail]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- GetClockTime(&_GetOccupancyFee_Time[gunIndex]);
- }
- if((GetTimeoutValue(_GetOccupancyFee_Time[gunIndex]) / uSEC_VAL) >= OCCUPANCY_FEE_TIMEOUT)
- {
- LOG_INFO("Gun %d Return to Occupied via PaidOnlineFail", gunIndex + 1);
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_Occupied;
- }
- break;
- default:
- DisableConnectorBill(gunIndex);
- break;
- }
- }
- void CheckOccupancyFee(void)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- OccupancyRequest(i);
- }
- }
- #define OCCUPANCY_DEDUCT_IDLE 0
- #define OCCUPANCY_DEDUCT_REQUEST 1
- unsigned char _OccupancyDeductStatus = OCCUPANCY_DEDUCT_IDLE;
- int _OccupancyReportGunId = 0;
- void CheckOccupancyDeduct(void)
- {
- char cardNo[21];
- char appNo[10];
- if(_OccupancyDeductStatus == OCCUPANCY_DEDUCT_IDLE)
- {
- if(!Is_Ocpp_TcciReportOccupancyDeductReq())
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(Is_OccupancyDeductReq(i))
- {
- if(ShmChargerInfo->AllBill.OccupancyInfo[i].OccupancyReq.bits.SelfReq &&
- ShmChargerInfo->AllBill.OccupancyInfo[i].Status == _Parking_WaitToPay)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[i].Status = _Parking_NoOccupancy;
- LOG_INFO("Gun %d Occupancy Concluded!", i + 1);
- break;
- }
- Set_Ocpp_OccupancyDeductResult(&ShmChargerInfo->AllBill.OccupancyInfo[i].OccupancyDeduct, YES);
- Set_Ocpp_TcciReportOccupancyDeductReq();
- _OccupancyDeductStatus = OCCUPANCY_DEDUCT_REQUEST;
- _OccupancyReportGunId = i + 1;
- Clean_OccupancyDeductReq(i);
- break;
- }
- }
- if(_OccupancyDeductStatus != OCCUPANCY_DEDUCT_IDLE)
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(cardNo, ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.creditNo, sizeof(ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.creditNo));
- memcpy(appNo, ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.ApprovalNumber, sizeof(ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.ApprovalNumber));
- LOG_INFO("Gun %d Occupancy Deduct [Request] Sn: [%s], Fee: [%.2f], CreditNo: [%s], ApprovalNo: [%s]",
- _OccupancyReportGunId,
- ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.Sn,
- ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.Fee,
- cardNo,
- appNo);
- }
- }
- }
- else
- {
- if(!Is_Ocpp_TcciReportOccupancyDeductReq())
- {
- if(ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].Status == _Parking_WaitToPay)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].Status = _Parking_NoOccupancy;
- LOG_INFO("Gun %d OccupancyDeduct Request Completed!", _OccupancyReportGunId);
- }
- _OccupancyDeductStatus = OCCUPANCY_DEDUCT_IDLE;
- }
- }
- }
- void CheckDiagnosticsReq(void)
- {
- bool _DiagnosticsCompleted = true;
- int _DispenserId = 0;
- char _IpAddress[32];
- char cmdBuf[256] = {0};
- if(Is_Ocpp_GetDiagnosticsReq() || ShmChargerInfo->Control.Diagnostics.DiagnosticsType != DIAGNOSTICS_TYPE_NONE)
- {
- // check dispenser status and set diagnostics request
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
- {
- _DispenserId = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex + 1;
- if(!ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[_DispenserId - 1].bits.Request)
- {
- ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[_DispenserId - 1].CtrlValue = 0;
- sprintf((char*)_IpAddress, "%d.%d.%d.%d",
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 0) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 8) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) & 0xFF));
- sprintf(cmdBuf, "/root/Module_Diagnostics %d %s &", _DispenserId, _IpAddress);
- system(cmdBuf);
- ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[_DispenserId - 1].bits.Request = true;
- }
- if(!_NeedDiagnostics)
- {
- GetClockTime(&_Diagnostics_Time);
- LOG_INFO("Dispenser Need Diagnostics!");
- }
- _NeedDiagnostics = true;
- }
- }
- if(_NeedDiagnostics)
- {
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
- {
- if(!ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].bits.Stop)
- {
- if(!ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].bits.Confirm)
- {
- if(GetSecTimeoutValue(_Diagnostics_Time) >= WAIT_DIAGNOSTICS_CONFIRM)
- {
- ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].bits.Stop = true;
- LOG_INFO("Wait Dispenser %d diagnostics confirm timeout!", i + 1);
- }
- _DiagnosticsCompleted = false;
- }
- else if(!ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].bits.Completed)
- {
- if(GetSecTimeoutValue(_Diagnostics_Time) >= WAIT_DIAGNOSTICS_TIMEOUT)
- {
- ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].bits.Stop = true;
- LOG_INFO("Wait Dispenser %d diagnostics completed timeout!", i + 1);
- }
- _DiagnosticsCompleted = false;
- }
- }
- }
- }
- }
- if(_DiagnosticsCompleted)
- {
- // diagnostics completed, clean ocpp GetDiagnosticsReq
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].CtrlValue = 0;
- }
- if(Is_Ocpp_GetDiagnosticsReq())
- {
- Clean_Ocpp_GetDiagnosticsReq();
- }
- if(ShmChargerInfo->Control.Diagnostics.DiagnosticsType != DIAGNOSTICS_TYPE_NONE)
- {
- ShmChargerInfo->Control.Diagnostics.DiagnosticsType = DIAGNOSTICS_TYPE_NONE;
- }
- LOG_INFO("Dispenser Diagnostics Completed!");
- }
- }
- else
- {
- _NeedDiagnostics = false;
- }
- }
- //===============================================
- // OCPP
- //===============================================
- void CheckOcppStatus()
- {
- if (Is_Ocpp_BootNotification())
- {
- Clean_Ocpp_BootNotification();
- LOG_INFO("*********************OCPP Boot Notification****************************");
- }
- if (Is_Ocpp_ResetReq())
- {
- bool canReset = true;
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
- {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus != S_IDLE &&
- chargingInfo[_index]->SystemStatus != S_RESERVATION &&
- chargingInfo[_index]->SystemStatus != S_MAINTAIN)
- {
- canReset = false;
- //if (chargingInfo[_index]->SystemStatus >= S_REASSIGN && chargingInfo[_index]->SystemStatus < S_TERMINATING)
- //{
- // ChargingTerminalProcess(_index);
- //}
- if(Chk_Ocpp_Reset_Type("Hard") || Chk_Ocpp_Reset_Type("Immediate"))
- {
- chargingInfo[_index]->ChargingStopFlag.bits.HardResetStop = true;
- }
- if(Chk_Ocpp_Reset_Type("Soft") || Chk_Ocpp_Reset_Type("OnIdle"))
- {
- chargingInfo[_index]->ChargingStopFlag.bits.SoftResetStop = true;
- }
- }
- }
- }
- if(canReset)
- {
- if(Chk_Ocpp_Reset_Type("Hard") || Chk_Ocpp_Reset_Type("Immediate"))
- {
- //trigger dispenser to hardware reboot
- TriggerDispenserHardwareReboot();
- if(IsDispenserHardwareRebootResponsed())
- {
- Clean_Ocpp_ResetReq();
- LOG_INFO("****** Hard Reboot ******");
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- setChargerMode(i, MODE_MAINTAIN);
- }
- sleep(3);
- system("reboot -f");
- }
- }
- if(Chk_Ocpp_Reset_Type("Soft") || Chk_Ocpp_Reset_Type("OnIdle"))
- {
- //trigger dispenser to software reset
- TriggerDispenserSoftwareReset();
- if(IsDispenserSoftwareResetResponsed())
- {
- Clean_Ocpp_ResetReq();
- LOG_INFO("****** Soft Reboot ******");
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- setChargerMode(i, MODE_MAINTAIN);
- }
- sleep(3);
- Kill_Ocpp_Service();
- KillAllTask();
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- }
- CheckOcppCostAndPrice();
- CheckLcmPageChangeRequest();
- CheckStationInfo();
- CheckWeatherInfo();
- CheckDeductResultRequest();
- CheckReDeductRequest();
- CheckReaderStatusRequest();
- CheckOccupancyPrice();
- CheckOccupancyFee();
- CheckOccupancyDeduct();
- CheckDiagnosticsReq();
- }
- void CheckoutStartChargingSoc(byte gunIndex, bool force)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Parameter.bits.GetStartChargingSoc)
- {
- if(chargingInfo[gunIndex]->EvBatterySoc > 0 || force)
- {
- chargingInfo[gunIndex]->EvBatteryStartSoc = chargingInfo[gunIndex]->EvBatterySoc;
- LOG_INFO("Gun %d StartSoc = %d", chargingInfo[gunIndex]->Index + 1, chargingInfo[gunIndex]->EvBatteryStartSoc);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Parameter.bits.GetStartChargingSoc = true;
- }
- }
- }
- void UpdateChargingTimestamp(char *timestamp)
- {
- struct timeb SeqEndTime;
- struct tm *tm;
- ftime(&SeqEndTime);
- SeqEndTime.time = time(NULL);
- tm = localtime(&SeqEndTime.time);
- sprintf(timestamp, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
- }
- void OcppStartTransaction(byte gunIndex)
- {
- if(_triggerTransaction[gunIndex])
- {
- return;
- }
- // clean deduct info
- Clean_DeductInfo(gunIndex);
- // set deduct user id
- //Set_Deduct_UserId(gunIndex, (char *)&chargingInfo[gunIndex]->StartUserId);
- // initial start & stop datetime
- strcpy((char *)chargingInfo[gunIndex]->StartDateTime, "00:00:00");
- strcpy((char *)chargingInfo[gunIndex]->StopDateTime, "00:00:00");
- Update_PowerConsumption(gunIndex);
- _lsatGunMeterValue[gunIndex] = chargingInfo[gunIndex]->PowerConsumption;
- Set_Ocpp_StartTransactionIdTag(gunIndex, (char *)chargingInfo[gunIndex]->StartUserId);
- LOG_INFO("Gun %d Start Transaction IdTag = %s, MeterValue: %.4f",
- chargingInfo[gunIndex]->Index + 1, chargingInfo[gunIndex]->StartUserId, chargingInfo[gunIndex]->PowerConsumption);
- Clean_Ocpp_StartTransactionConf(gunIndex);
- UpdateChargingTimestamp(ShmChargerInfo->Timestamp[gunIndex].StartCharging);
- Set_Ocpp_StartTransactionReq(gunIndex);
- // set _triggerTransaction
- _triggerTransaction[gunIndex] = true;
- }
- void OcppStopTransaction(byte gunIndex)
- {
- if(!_triggerTransaction[gunIndex])
- {
- return;
- }
- Update_PowerConsumption(gunIndex);
- _lsatGunMeterValue[gunIndex] = chargingInfo[gunIndex]->PowerConsumption;
- Set_Ocpp_StopTransactionId(gunIndex, (char *)chargingInfo[gunIndex]->StartUserId);
- LOG_INFO("Gun %d Stop Transaction IdTag = %s, StopSoc = %d, MeterValue: %.4f",
- chargingInfo[gunIndex]->Index + 1,
- chargingInfo[gunIndex]->StartUserId,
- chargingInfo[gunIndex]->EvBatterySoc,
- chargingInfo[gunIndex]->PowerConsumption);
- UpdateChargingTimestamp(ShmChargerInfo->Timestamp[gunIndex].StopCharging);
- Set_Ocpp_StopTransactionReq(gunIndex);
- // clean _triggerTransaction
- _triggerTransaction[gunIndex] = false;
- }
- bool Is_DispenserStop(byte gunIndex)
- {
- bool _isStop = false;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteStatus != _CRS_Preparing &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteStatus != _CRS_Charging)
- {
- _isStop = true;
- }
- return _isStop;
- }
- void ChkOcppStatus(byte gunIndex)
- {
- Chk_Ocpp_Backup_ErrorCode(gunIndex);
- if(Is_Ocpp_ReserveNowReq(gunIndex))
- {
- Clean_Ocpp_ReserveNowReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_IDLE && !Is_Ocpp_ReserveNowExpired(gunIndex))
- {
- LOG_INFO("***************ChkOcppStatus: Gun %d OcppReservedStatus********************", gunIndex + 1);
- chargingInfo[gunIndex]->ReservationId = Get_Ocpp_ReserveNowId(gunIndex);
- setChargerMode(gunIndex, MODE_RESERVATION);
- }
- Set_Ocpp_ReserveNowConf(gunIndex);
- }
- if(Is_Ocpp_CancelReservationReq(gunIndex))
- {
- Clean_Ocpp_CancelReservationReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_RESERVATION)
- {
- LOG_INFO("***************ChkOcppStatus: Gun %d Cancel OcppReservedStatus********************", gunIndex + 1);
- chargingInfo[gunIndex]->ReservationId = -1;
- setChargerMode(gunIndex, MODE_IDLE);
- }
- Set_Ocpp_CancelReservationConf(gunIndex);
- }
- if (Is_Ocpp_ChangeAvailabilityReq(gunIndex) == YES)
- {
- LOG_INFO("***************ChkOcppStatus: Gun %d OcppChangeAvailability********************", gunIndex + 1);
- Clean_Ocpp_ChangeAvailabilityReq(gunIndex);
- if(Chk_Ocpp_Availability_Type(gunIndex, "Operative"))
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, true);
- chargingInfo[gunIndex]->IsAvailable = YES;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_AVAILABILITY);
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
- {
- setChargerMode(gunIndex, MODE_IDLE);
- }
- }
- else if(Chk_Ocpp_Availability_Type(gunIndex, "Inoperative"))
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, false);
- chargingInfo[gunIndex]->IsAvailable = NO;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_AVAILABILITY);
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
- {
- setChargerMode(gunIndex, MODE_MAINTAIN);
- }
- }
- }
- if (Is_Ocpp_UnlockConnectorReq(gunIndex))
- {
- Clean_Ocpp_UnlockConnectorReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_PREPARNING ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EV ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EVSE ||
- chargingInfo[gunIndex]->SystemStatus == S_CHARGING)
- {
- // 充電中,需停止充電
- Set_Ocpp_StopReason(gunIndex, "UnlockCommand");
- //Set_Connector_MiscCommand(gunIndex, MISC_CONN_UNLOCK);
- chargingInfo[gunIndex]->ChargingStopFlag.bits.UnlockStop = true;
- LOG_INFO("********** OcppUnlockStop Gun %d **********", gunIndex + 1);
- }
- Set_Ocpp_UnlockConnectorConf(gunIndex);
- }
- if (Is_Ocpp_RemoteStopReq(gunIndex))
- {
- Clean_Ocpp_RemoteStopReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_PREPARNING ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EV ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EVSE ||
- chargingInfo[gunIndex]->SystemStatus == S_CHARGING)
- {
- Set_Ocpp_StopReason(gunIndex, "Remote");
- //Set_Connector_MiscCommand(gunIndex, MISC_CONN_REMOTE_STOP);
- chargingInfo[gunIndex]->ChargingStopFlag.bits.RemoteStop = true;
- LOG_INFO("********** OcppRemoteStop Gun %d **********", gunIndex + 1);
- }
- }
- if(Is_Ocpp_StartTransactionConf(gunIndex))
- {
- char acceptId[128] = {0};
- char status[32] = {0};
- Get_Ocpp_StartTransaction_Status(gunIndex, status);
- Get_Ocpp_TransactionId(gunIndex, acceptId);
- Set_Deduct_TransactionId(gunIndex, atoi(acceptId));
- Set_UserTransactionId(gunIndex, atoi(acceptId));
- LOG_INFO("Gun %d OCPP Start Transaction %s, TransactionId [%s]", gunIndex + 1, status, acceptId);
- if(!Is_Ocpp_StartTransaction_Accepted(gunIndex))
- {
- if(Is_Ocpp_StopOnInvalidId_Enable())
- {
- if(Is_Invalid_StartTransactionId(gunIndex))
- {
- chargingInfo[gunIndex]->ChargingStopFlag.bits.InvalidIdStop = true;
- LOG_INFO("Gun %d OCPP StopOnInvalidId", gunIndex + 1);
- }
- }
- LOG_INFO("Gun %d Transaction [%s] Not Accepted, %s",
- gunIndex + 1, acceptId,
- chargingInfo[gunIndex]->ChargingStopFlag.bits.InvalidIdStop > 0 ? "And Stop Charging" : "But StopOnInvalidId is Disable");
- }
- Clean_Ocpp_StartTransactionConf(gunIndex);
- }
- }
- bool CheckBackendChargingTimeout(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60))
- result = true;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- // 隨插即充電的要看 offline
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60))
- result = true;
- }
- }
- return result;
- }
- bool CheckBackendChargingEnergy(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy >= ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)
- result = true;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- // 隨插即充電的要看 offline
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy))
- result = true;
- }
- }
- return result;
- }
- bool IsReachConfigMaxChargingSoc(byte gunIndex)
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysConfig.MaxChargingSoc > 0)
- {
- if(chargingInfo[gunIndex]->EvBatterySoc >= ShmSysConfigAndInfo->SysConfig.MaxChargingSoc)
- {
- LOG_INFO("Gun %d MaxChargingSoc: [%d%%] Stop", gunIndex + 1, ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
- result = true;
- }
- }
- return result;
- }
- bool CheckSessionTargetStop(byte gunIndex)
- {
- bool stop = false;
- struct StructSessionTarget target;
- Get_Ocpp_SessionTarget(gunIndex, &target);
- if(target.targetDuration > 0)
- {
- if(chargingInfo[gunIndex]->PresentChargedDuration >= (target.targetDuration * 60))
- {
- LOG_INFO("Gun %d SessionTarget(Duration) Stop, Present: %d (sec), Target: %d (min)",
- gunIndex + 1,
- chargingInfo[gunIndex]->PresentChargedDuration,
- target.targetDuration);
- stop = true;
- }
- }
- if(target.targetSoc > 0)
- {
- if(chargingInfo[gunIndex]->EvBatterySoc >= target.targetSoc)
- {
- LOG_INFO("Gun %d SessionTarget(SOC) Stop, Present: %d (%%), Target: %d (%%)",
- gunIndex + 1,
- chargingInfo[gunIndex]->EvBatterySoc,
- target.targetSoc);
- stop = true;
- }
- }
- if(target.targetEnergy > 0)
- {
- if(chargingInfo[gunIndex]->PresentChargedEnergy >= target.targetEnergy)
- {
- LOG_INFO("Gun %d SessionTarget(Energy) Stop, Present: %8.3f (kWh), Target: %4d (kWh)",
- gunIndex + 1,
- chargingInfo[gunIndex]->PresentChargedEnergy,
- target.targetEnergy);
- stop = true;
- }
- }
- if(stop)
- {
- chargingInfo[gunIndex]->ChargingStopFlag.bits.SessionTargetStop = true;
- }
- return stop;
- }
- void InformOcppErrOccur(byte codeType)
- {
- char _error[25];
- switch(codeType)
- {
- case 4: strcpy(_error, "InternalError"); break;
- case 6: strcpy(_error, "NoError"); break;
- case 7: strcpy(_error, "OtherError"); break;
- case 13: strcpy(_error, "UnderVoltage"); break;
- case 14: strcpy(_error, "OverVoltage"); break;
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- SetOcppErrorCode(gun_index, _error);
- }
- }
- void SetOcppErrorCode(unsigned char _index, char *errCode)
- {
- Set_Ocpp_StatusNotificationErrorCode(_index, errCode);
- strcpy((char *)_BackupStatusNotification[_index].ErrorCode, errCode);
- }
- void SetOcppVendorErrorCode(unsigned char _index, char *vendorCode)
- {
- Set_Ocpp_StatusNotificationVendorCode(_index, vendorCode);
- strcpy((char *)_BackupStatusNotification[_index].VendorErrorCode, vendorCode);
- }
- //===============================================
- // SQLite3 related routine
- //===============================================
- int NetworkDB_Open(sqlite3 *db)
- {
- int result = PASS;
- char* errMsg = NULL;
- char* createNerRecordSql="CREATE TABLE IF NOT EXISTS network_record("
- "idx integer primary key AUTOINCREMENT, "
- "occurDatetime text NOT NULL, "
- "isInternet text NOT NULL, "
- "isOcppConnected text NOT NULL, "
- "isEth0Internet text NOT NULL, "
- "isMlan0Internet text NOT NULL, "
- "isPpp0Internet text NOT NULL, "
- "rssiMlan0 text NOT NULL, "
- "rssiPpp0 text NOT NULL"
- ");";
- //sqlite3_config(SQLITE_CONFIG_URI, 1);
- if(sqlite3_open(NETWORK_DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database (Net) : %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO("Local network status record database open successfully.");
- if (sqlite3_exec(db, createNerRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Create local network status record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("Opened local network status record table successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Open(sqlite3 *db)
- {
- int result = PASS;
- char* errMsg = NULL;
- char* createRecordSql="CREATE TABLE IF NOT EXISTS charging_record("
- "idx integer primary key AUTOINCREMENT, "
- "reservationId text, "
- "transactionId text, "
- "startMethod text, "
- "userId text, "
- "dateTimeStart text, "
- "dateTimeStop text,"
- "socStart text, "
- "socStop text, "
- "chargeEnergy text, "
- "stopReason text, "
- "connector INTEGER"
- ");";
- char* createCfgSql="CREATE TABLE IF NOT EXISTS `config` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`IsAvailable` TEXT NOT NULL, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(IsAvailable,connector) on conflict replace);";
- char* creatererrecordSql="CREATE TABLE IF NOT EXISTS `event_record` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`occurDatetime` TEXT NOT NULL, "
- "`statusCode` TEXT NOT NULL, unique(occurDatetime,statusCode) on conflict replace);";
- char* createrebootSql="CREATE TABLE IF NOT EXISTS `reboot_record` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`rebootDatetime` TEXT NOT NULL, "
- "`model_name` TEXT, "
- "`serial_number` TEXT, unique(rebootDatetime) on conflict replace);";
- char * createconsumptionSql = "CREATE TABLE IF NOT EXISTS `power_consumption` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(connector) on conflict replace);";
- char *createGunConsumptionSql = "CREATE TABLE IF NOT EXISTS `gun_consumption` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(connector) on conflict replace);";
- char *createFinalCostSql = "CREATE TABLE IF NOT EXISTS `final_cost` ( "
- "idx integer primary key AUTOINCREMENT, "
- "gun text, "
- "transactionId text, "
- "occurDatetime text, "
- "updateDatetime text, "
- "description text, "
- "updateStatus integer"
- ");";
- char *createOcmfRecordSql = "CREATE TABLE IF NOT EXISTS `ocmf_record` ( "
- "idx integer primary key AUTOINCREMENT, "
- "gun text, "
- "transactionId text, "
- "publicKey text, "
- "ocmfInfo text, "
- "updateStatus integer, "
- "occurDatetime text, "
- "updateDatetime text"
- ");";
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR( "Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO( "Local charging record database open successfully.");
- if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create local charging record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened local charging record table successfully");
- }
- if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create local config table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened local config table successfully");
- }
- if (sqlite3_exec(db, creatererrecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create local record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened local record table successfully");
- }
- if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create reboot record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened reboot record table successfully");
- }
- if (sqlite3_exec(db, createconsumptionSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create power consumption record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened power consumption record table successfully");
- }
- if (sqlite3_exec(db, createGunConsumptionSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create gun consumption record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened gun consumption record table successfully");
- }
- if (sqlite3_exec(db, createFinalCostSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create final cost table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened final cost table successfully");
- }
- if(sqlite3_exec(db, createOcmfRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Create OCMF record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("Opened OCMF record table successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Insert_Record(sqlite3 *db, int gun_index)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[1024];
- char transactionId[128];
- char reason[32];
- Get_Ocpp_TransactionId(gun_index, transactionId);
- Get_Ocpp_StopReason(gun_index, reason);
- sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, connector) "
- "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', %d);",
- chargingInfo[gun_index]->ReservationId,
- transactionId,
- chargingInfo[gun_index]->StartMethod,
- chargingInfo[gun_index]->StartUserId,
- chargingInfo[gun_index]->StartDateTime,
- chargingInfo[gun_index]->StopDateTime,
- chargingInfo[gun_index]->EvBatteryStartSoc,
- chargingInfo[gun_index]->EvBatterySoc,
- chargingInfo[gun_index]->PresentChargedEnergy,
- reason,
- gun_index + 1);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO( "Local charging record database open successfully.");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Insert local charging record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("Insert local charging record successfully");
- }
- sprintf(insertSql, "delete from charging_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("delete local charging error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("delete local charging record successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable)
- {
- uint8_t result = false;
- char* errMsg = NULL;
- char sqlStr[1024];
- srand(time(NULL));
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR( "Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO( "Local charging record database open successfully (%d).", IsAvailable);
- sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
- LOG_INFO("sqlStr= %s", sqlStr);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_INFO( "update config error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("update connector-%d config item isOperactive to %d", gun_index, IsAvailable);
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
- {
- uint8_t result = true;
- char* errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gun_index);
- //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR( "Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO( "Local config query database open successfully.");
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if(rows>0)
- {
- for(int idxRow=1;idxRow<=rows;idxRow++)
- {
- if(strcmp(rs[(idxRow*cols)+3], "0") == 0)
- {
- result = false;
- }
- LOG_INFO("Query connector-%d isOperactive: %s", gun_index, rs[(idxRow*cols)+3]);
- }
- }
- else
- {
- LOG_INFO("Query connector-%d fail, set default value to operactive.", gun_index);
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- void DB_Update_LocalConsumption(sqlite3 *db, uint8_t gun_index, float value)
- {
- char* errMsg = NULL;
- char sqlStr[1024];
- srand(time(NULL));
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sprintf(sqlStr, "insert or replace into power_consumption (connector, val) values(%d, %f);", gun_index, value);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- LOG_ERROR("update power_consumption error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("update connector-%d power_consumption item consumption to %f \r\n", gun_index, value);
- }
- sqlite3_close(db);
- }
- }
- void DB_Update_GunConsumption(sqlite3 *db, uint8_t gun_index, float value)
- {
- char* errMsg = NULL;
- char sqlStr[1024];
- srand(time(NULL));
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sprintf(sqlStr, "insert or replace into gun_consumption (connector, val) values(%d, %f);", gun_index, value);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- LOG_ERROR("update gun_consumption error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("update connector-%d power_consumption item consumption to %f \r\n", gun_index, value);
- }
- sqlite3_close(db);
- }
- }
- float DB_Get_LocalConsumption(sqlite3 *db, uint8_t gun_index)
- {
- float result = 0;
- char* errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- sprintf(sqlStr, "select * from power_consumption where connector=%d;", gun_index);
- if (sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO("Local config query database open successfully.");
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if (rows > 0)
- {
- for (int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atof(rs[(idxRow * cols) + 2]);
- }
- }
- else
- {
- LOG_INFO("Query connector-%d fail, set default value to consumption.", gun_index);
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- float DB_Get_GunConsumption(sqlite3 *db, uint8_t gun_index)
- {
- float result = 0;
- char* errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- sprintf(sqlStr, "select * from gun_consumption where connector=%d;", gun_index);
- if (sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO("Local config query database open successfully.");
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if (rows > 0)
- {
- for (int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atof(rs[(idxRow * cols) + 2]);
- }
- }
- else
- {
- LOG_INFO("Query gun %d fail, set -1 to gun consumption.", gun_index + 1);
- result = -1;
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- float Get_PowerConsumption(uint8_t gun_index)
- {
- float value = 0;
- //value = ShmChargerInfo->MeterValue[gun_index].GunConsumption >= 0 ?
- // ShmChargerInfo->MeterValue[gun_index].GunConsumption : ShmChargerInfo->MeterValue[gun_index].LocalConsumption;
- if(ShmChargerInfo->MeterValue[gun_index].GunConsumption >= 0)
- {
- if(!_useGunMeterValue[gun_index])
- {
- LOG_INFO("***** Gun %d Use GunMeterValue *****", gun_index + 1);
- }
- _useGunMeterValue[gun_index] = true;
- value = ShmChargerInfo->MeterValue[gun_index].GunConsumption;
- }
- else
- {
- value = ShmChargerInfo->MeterValue[gun_index].LocalConsumption;
- }
- return value;
- }
- void Update_PowerConsumption(uint8_t gun_index)
- {
- chargingInfo[gun_index]->PowerConsumption = Get_PowerConsumption(gun_index);
- }
- int DB_Insert_FinalCost(sqlite3 *db, uint8_t gun_index, int txId, char *description)
- {
- char timeBuf[32];
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[1024];
- getNowDatetime((unsigned char *)timeBuf);
- sprintf(insertSql, "insert into final_cost(gun, transactionId, occurDatetime, updateDatetime, description, updateStatus) "
- "values('%d', '%d', '%s', '%s', '%s', '%d');",
- gun_index + 1,
- txId,
- timeBuf,
- "",
- description,
- BILL_SATAUS_UNDISPOSED);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO("FinalCost database open successfully.");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Insert final_cost error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("Insert final_cost successfully");
- }
- sprintf(insertSql, "delete from final_cost where idx < (select idx from final_cost order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("delete final_cost error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("delete final_cost successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Update_FinalCost_Status(sqlite3 *db, int txId, int status)
- {
- char timeBuf[32];
- int result = PASS;
- char* errMsg = NULL;
- char updateSql[1024];
- getNowDatetime((unsigned char *)timeBuf);
- sprintf(updateSql, "update final_cost set updateStatus = %d, updateDatetime = '%s' where transactionId = '%d';",
- status,
- timeBuf,
- txId);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- if(sqlite3_exec(db, updateSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- LOG_ERROR("update final_cost status error message: %s", errMsg);
- result = FAIL;
- }
- else
- {
- //LOG_INFO("update final_cost txId[%d] status %d ok", txId, status);
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Get_Undisposed_FinalCost(sqlite3 *db, int gunIndex, char *costString)
- {
- int txId = -1;
- char **rs;
- int rows, cols;
- char* errMsg = NULL;
- char sqlString[1024];
- sprintf(sqlString, "select * from final_cost where updateStatus = -1 and gun = '%d' order by idx asc limit 1;",
- gunIndex + 1);
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sqlite3_get_table(db, sqlString, &rs, &rows, &cols, &errMsg);
- if(rows > 0)
- {
- for(int idxRow = 1; idxRow <= rows; idxRow++)
- {
- txId = atoi(rs[(idxRow * cols) + 2]);
- strcpy(costString, rs[(idxRow * cols) + 5]);
- }
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return txId;
- }
- void CheckInProgress(uint8_t gun_index)
- {
- if((ShmChargerInfo->Connector[gun_index].Status > S_IDLE && ShmChargerInfo->Connector[gun_index].Status <= S_FAULT) ||
- (ShmChargerInfo->Connector[gun_index].Status >= S_CCS_PRECHARGE_ST0 && ShmChargerInfo->Connector[gun_index].Status <= S_CCS_PRECHARGE_ST1))
- {
- if(chargingInfo[gun_index]->InProgress == NO)
- {
- LOG_INFO("Gun %d In Progress", gun_index + 1);
- }
- chargingInfo[gun_index]->InProgress = YES;
- }
- else
- {
- if(chargingInfo[gun_index]->InProgress == YES)
- {
- LOG_INFO("Gun %d Real Idle", gun_index + 1);
- }
- chargingInfo[gun_index]->InProgress = NO;
- }
- }
- void CheckDebugMode(uint8_t gun_index)
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
- {
- if(chargingInfo[gun_index]->SystemStatus != S_DEBUG)
- {
- setChargerMode(gun_index, MODE_DEBUG);
- }
- }
- }
- int DB_Reboot_Record(sqlite3 *db)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[256];
- sprintf(insertSql, "insert into reboot_record(rebootDatetime, model_name, serial_number) values(CURRENT_TIMESTAMP, '%s', '%s');",
- (char *)ShmSysConfigAndInfo->SysConfig.ModelName,
- (char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO("Local charging record database open successfully.");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Insert reboot record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("Insert reboot record successfully");
- }
- sprintf(insertSql, "delete from reboot_record where idx < (select idx from reboot_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("delete reboot record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("delete reboot record successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Insert_Ocmf(sqlite3 *db, int gun_index, char *txId, char *ocmfKey, char *ocmfInfo)
- {
- char timeBuf[32];
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[3072];
- getNowDatetime((unsigned char *)timeBuf);
- sprintf(insertSql, "insert into ocmf_record(gun, transactionId, publicKey, ocmfInfo, updateStatus, occurDatetime, updateDatetime) "
- "values('%d', '%s', '%s', '%s', '%d', '%s', '%s');",
- gun_index + 1,
- txId,
- ocmfKey,
- ocmfInfo,
- OCMF_SATAUS_INSERTED,
- timeBuf,
- "");
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO("OCMF database open successfully.");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Insert ocmf_record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("Insert ocmf_record successfully");
- }
- sprintf(insertSql, "delete from ocmf_record where idx < (select idx from ocmf_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("delete ocmf_record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("delete ocmf_record successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Update_Ocmf_Status(sqlite3 *db, char *txId, int status)
- {
- char timeBuf[32];
- int result = PASS;
- char* errMsg = NULL;
- char updateSql[1024];
- getNowDatetime((unsigned char *)timeBuf);
- sprintf(updateSql, "update ocmf_record set updateStatus = %d, updateDatetime = '%s' where transactionId = '%s';",
- status,
- timeBuf,
- txId);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- if(sqlite3_exec(db, updateSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- LOG_ERROR("update updateStatus status error message: %s", errMsg);
- result = FAIL;
- }
- else
- {
- //LOG_INFO("update updateStatus txId[%s] status %d ok", txId, status);
- }
- sqlite3_close(db);
- }
- return result;
- }
- // return YES if exist undisposed ocmf
- int DB_Get_Undisposed_Ocmf(sqlite3 *db, int *gunIndex, char *txId, char *ocmfKey, char *ocmfInfo)
- {
- char **rs;
- int rows, cols;
- char* errMsg = NULL;
- char sqlString[1024];
- int result = NO;
- sprintf(sqlString, "select * from ocmf_record where updateStatus = 0 order by idx asc limit 1;");
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sqlite3_get_table(db, sqlString, &rs, &rows, &cols, &errMsg);
- if(rows > 0)
- {
- for(int idxRow = 1; idxRow <= rows; idxRow++)
- {
- *gunIndex = atoi(rs[(idxRow * cols + 1)]) - 1;
- strncpy(txId, rs[(idxRow * cols) + 2], 36);
- strncpy(ocmfKey, rs[(idxRow * cols) + 3], 200);
- strcpy(ocmfInfo, rs[(idxRow * cols) + 4]);
- }
- result = YES;
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- void DB_TryAddRebootRecordColumn(sqlite3 *db)
- {
- char **rs;
- int rows, cols;
- char* errMsg = NULL;
- char sqlString[1024];
- int result = 0;
- strcpy(sqlString, "select count(*) from pragma_table_info('reboot_record') where name = 'model_name';");
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sqlite3_get_table(db, sqlString, &rs, &rows, &cols, &errMsg);
- if(rows > 0)
- {
- for(int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atoi(rs[(idxRow * cols) + 0]);
- }
- }
- sqlite3_free_table(rs);
- if(result == 0)
- {
- strcpy(sqlString, "ALTER TABLE 'reboot_record' ADD COLUMN 'model_name' TEXT;");
- if(sqlite3_exec(db, sqlString, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("reboot_record add column 'model_name' error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("reboot_record ADD COLUMN 'model_name' successfully");
- }
- strcpy(sqlString, "ALTER TABLE 'reboot_record' ADD COLUMN 'serial_number' TEXT;");
- if(sqlite3_exec(db, sqlString, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("reboot_record add column 'serial_number' error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("reboot_record ADD COLUMN 'serial_number' successfully");
- }
- }
- sqlite3_close(db);
- }
- }
- void DB_TryAddChargingRecordColumn(sqlite3 *db)
- {
- char **rs;
- int rows, cols;
- char* errMsg = NULL;
- char sqlString[1024];
- int result = 0;
- strcpy(sqlString, "select count(*) from pragma_table_info('charging_record') where name = 'connector';");
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sqlite3_get_table(db, sqlString, &rs, &rows, &cols, &errMsg);
- if(rows > 0)
- {
- for(int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atoi(rs[(idxRow * cols) + 0]);
- }
- }
- sqlite3_free_table(rs);
- if(result == 0)
- {
- strcpy(sqlString, "ALTER TABLE 'charging_record' ADD COLUMN 'connector' INTEGER;");
- if(sqlite3_exec(db, sqlString, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("charging_record add column connector error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("charging_record ADD COLUMN connector successfully");
- }
- }
- sqlite3_close(db);
- }
- }
- //===============================================
- // Config process
- //===============================================
- void AddPlugInTimes(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
- else if(chargingInfo[gunIndex]->Type == _Type_CCS_2)
- ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
- else if(chargingInfo[gunIndex]->Type == _Type_GB)
- ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
- }
- void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
- {
- char cmdBuf[32];
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
- tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- tmCSU->tm_sec);
- if (isStart)
- strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
- else
- strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
- }
- void zipLogFiles()
- {
- const char* logPath = "/Storage/SystemLog";
- // 獲取目錄
- DIR* pDir = opendir(logPath);
- if (pDir != NULL)
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- // LOG_INFO("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
- // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- // tmCSU->tm_sec);
- // Read items inside the folder
- struct dirent* pEntry = NULL;
- while ((pEntry = readdir(pDir)) != NULL)
- {
- if (strcmp(pEntry->d_name, ".") != 0 &&
- strcmp(pEntry->d_name, "..") != 0 &&
- strncmp(pEntry->d_name, "[", 1) == 0 &&
- strstr(pEntry->d_name, "tar") < 0)
- {
- char yearC[5];
- unsigned short year = 0;
- char monthC[3];
- unsigned short month = 0;
- yearC[4] = '\0';
- strncpy(yearC, pEntry->d_name + 1, 4);
- monthC[2] = '\0';
- strncpy(monthC, pEntry->d_name + 6, 2);
- year = atoi(yearC);
- month = atoi(monthC);
- if (year != 0)
- {
- if (year < tmCSU->tm_year + 1900 ||
- (year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1))
- {
- LOG_INFO("tar file name : %s", pEntry->d_name);
- char file[256];
- memset(file, 0x00, sizeof(file));
- strcat(file, "tar zcvf ");
- strcat(file, logPath);
- strncat(file, "/", 1);
- strcat(file, pEntry->d_name);
- strcat(file, ".tar");
- strncat(file, " ", 1);
- strcat(file, logPath);
- strncat(file, "/", 1);
- strcat(file, pEntry->d_name);
- LOG_INFO("zip = %s \n", file);
- system(file);
- }
- }
- }
- }
- }
- // Close folder
- closedir(pDir);
- }
- void StopProcessingLoop()
- {
- for (;;)
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
- {
- ChkPrimaryStatus();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 0)
- {
- LOG_INFO("Soft reboot for retry self-tets (Primary).");
- KillAllTask();
- sleep(3);
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- }
- if(Is_Ocpp_ResetReq())
- {
- if(Chk_Ocpp_Reset_Type("Hard") || Chk_Ocpp_Reset_Type("Immediate"))
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
- }
- if(Chk_Ocpp_Reset_Type("Soft") || Chk_Ocpp_Reset_Type("OnIdle"))
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
- }
- }
- CheckSoftHardReset();
- sleep(1);
- }
- }
- void CreateWatchdog(void)
- {
- wtdFd = InitWatchDog();
- if(wtdFd < 0)
- {
- LOG_INFO("Watchdog Initial Fail");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- else
- {
- LOG_INFO("Watchdog Initial Success");
- }
- }
- void TryCloseWatchdog(void)
- {
- if(wtdFd > 0)
- {
- write(wtdFd, "V", 1);
- close(wtdFd);
- }
- }
- void TryFeedWatchdog(void)
- {
- if(wtdFd > 0)
- {
- write(wtdFd, "a", 1);
- }
- }
- bool IsParallelCabinetIdle(void)
- {
- bool result = true;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- result = false;
- }
- return result;
- }
- bool IsStandbyEnable(void)
- {
- bool result = true;
- if(ShmChargerInfo->Control.CustomizedInfo.Flag.bits.StandbyTimeDisableForTcc)
- {
- time_t timep;
- struct tm *tm;
- time(&timep);
- timep += (ShmChargerInfo->CabinetMiscValue.TimeOffset * 60);
- tm = localtime(&timep);
- if(tm->tm_hour >= 0 && tm->tm_hour < 8)
- {
- if(!_isStandbyEnable)
- {
- LOG_INFO("[TCC]Customer Enable Standby Function This Time[%02d:%02d:%02d], Offset[%d]",
- tm->tm_hour, tm->tm_min, tm->tm_sec, ShmChargerInfo->CabinetMiscValue.TimeOffset);
- }
- _isStandbyEnable = true;
- result = true;
- }
- else
- {
- if(_isStandbyEnable)
- {
- LOG_INFO("[TCC]Customer Disable Standby Function This Time[%02d:%02d:%02d], Offset[%d]",
- tm->tm_hour, tm->tm_min, tm->tm_sec, ShmChargerInfo->CabinetMiscValue.TimeOffset);
- }
- _isStandbyEnable = false;
- result = false;
- }
- }
- if(ShmChargerInfo->Control.CustomizedInfo.Flag.bits.StandbyTimeDisable)
- {
- result = false;
- }
- return result;
- }
- bool IsGunIdle(int gunIndex, int idleType)
- {
- bool idle = true;
- if(chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
- chargingInfo[gunIndex]->ConnectorPlugIn &&
- idleType == GUN_IDLE_TYPE_WHOLE)
- {
- idle = false;
- }
- else if (chargingInfo[gunIndex]->SystemStatus != S_IDLE &&
- chargingInfo[gunIndex]->SystemStatus != S_RESERVATION &&
- chargingInfo[gunIndex]->SystemStatus != S_FAULT &&
- chargingInfo[gunIndex]->SystemStatus != S_MAINTAIN)
- {
- idle = false;
- }
- return idle;
- }
- bool IsDispenserIdle(int dispenserIndex)
- {
- bool dispenserIdle = true;
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
- if(!IsGunIdle(gun, GUN_IDLE_TYPE_NORMAL))
- {
- dispenserIdle = false;
- break;
- }
- }
- return dispenserIdle;
- }
- bool IsConnectorWholeIdle(void)
- {
- bool result = true;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- if(!IsGunIdle(count, GUN_IDLE_TYPE_WHOLE))
- {
- result = false;
- break;
- }
- }
- return result;
- }
- bool IsUpgradeAvailable(void)
- {
- bool result = true;
- for(int count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- if(!IsGunIdle(count, GUN_IDLE_TYPE_NORMAL))
- {
- result = false;
- break;
- }
- }
- return result;
- }
- void ClearAlarmCodeWhenAcOff()
- {
- if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- }
- }
- //==========================================
- // Check task processing
- //==========================================
- void CheckTask()
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- if(system("pidof -s Module_4g > /dev/null") != 0 && ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable == false)
- {
- LOG_ERROR("Module_4g not running, restart it.");
- system("/root/Module_4g &");
- }
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- if(system("pidof -s Module_Wifi > /dev/null") != 0 && ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable == false)
- {
- LOG_ERROR("Module_Wifi not running, restart it.");
- system("/root/Module_Wifi &");
- }
- }
- }
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
- ShmChargerInfo->Control.SysCtrl.bits.BackendEnable = true;
- if((time((time_t*)NULL) - Get_Ocpp_procDogTime()) > 180)
- {
- LOG_ERROR("OcppBackend watch dog timeout task restart.");
- Clean_Ocpp_procDogTime();
- Kill_Ocpp_Service();
- }
- if(!Is_Ocpp_Task_Alive())
- {
- LOG_ERROR("OcppBackend not running, restart it.");
- Run_Ocpp_Service();
- }
- }
- else
- {
- ShmChargerInfo->Control.SysCtrl.bits.BackendEnable = false;
- }
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- if(!Is_MaintainOcpp_Task_Alive())
- {
- LOG_ERROR("Maintain Backend not running, restart it.");
- Run_MaintainOcpp_Service();
- }
- }
- if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
- {
- LOG_ERROR("Module_ProduceUtils not running, restart it.");
- system ("/root/Module_ProduceUtils &");
- }
- if(system("pidof -s Module_EvComm > /dev/null") != 0)
- {
- LOG_ERROR("Module_EvComm not running, restart it.");
- system ("/root/Module_EvComm &");
- }
- if(system("pidof -s Module_InternalComm > /dev/null") != 0)
- {
- LOG_ERROR("Module_InternalComm not running, restart it.");
- system ("/root/Module_InternalComm &");
- //ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
- }
- if(!Is_WebServer_Alive())
- {
- LOG_ERROR("lighttpd not running, restart it.");
- Run_WebServer_Service();
- }
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > _SYS_POWER_SHARING_MODE_DISABLE)
- {
- if(!Is_LocalPowerSharing_Alive())
- {
- LOG_ERROR("Module_PowerSharing not running, restart it.");
- Run_LocalPowerSharing_Service();
- }
- }
- }
- void InitialDHCP()
- {
- char tmpbuf[256];
- memset(tmpbuf,0,256);
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- void InitialDispenserDhcpServerConfig(void)
- {
- system("echo 'start 192.168.100.10' > /etc/udhcpd_eth1.conf");
- system("echo 'end 192.168.100.20' >> /etc/udhcpd_eth1.conf");
- system("echo 'interface eth1' >> /etc/udhcpd_eth1.conf");
- system("echo 'opt dns 8.8.8.8' >> /etc/udhcpd_eth1.conf");
- system("echo 'option subnet 255.255.255.0' >> /etc/udhcpd_eth1.conf");
- system("echo 'opt router 192.168.100.1' >> /etc/udhcpd_eth1.conf");
- system("echo 'option domain local' >> /etc/udhcpd_eth1.conf");
- system("echo 'option lease 86400' >> /etc/udhcpd_eth1.conf");
- usleep(1000);
- }
- void StartDispenserDhcpServer(void)
- {
- system("pgrep -f \"udhcpd /etc/udhcpd_eth1.conf\" | xargs kill");
- system("/usr/sbin/udhcpd /etc/udhcpd_eth1.conf > /dev/null &");
- }
- //==========================================
- // Check Smart Charging Profile
- //==========================================
- void Ocpp_ProfileReq_Cmd(byte gunIndex)
- {
- if(!Is_Ocpp_ChargingProfileConf(gunIndex))
- {
- if(!Is_Ocpp_ChargingProfileReq(gunIndex))
- {
- Set_Ocpp_ChargingProfileReq(gunIndex);
- }
- }
- }
- int GetStartScheduleTime(unsigned char *time)
- {
- int result = -1;
- struct tm tmScheduleStart;
- struct timeb tbScheduleStart;
- if((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
- {
- tmScheduleStart.tm_year -= 1900;
- tmScheduleStart.tm_mon -= 1;
- tbScheduleStart.time = mktime(&tmScheduleStart);
- tbScheduleStart.millitm = 0;
- result = DiffTimebWithNow(tbScheduleStart) / 1000;
- }
- return result;
- }
- void Ocpp_ChargingProfile_Process(byte _index)
- {
- int _startCount = NO_DEFINE;
- int _maxCount = 0;
- float _limit = 0;
- int _numberPhases = 0;
- if(Is_Ocpp_ChargingProfileKind(_index, "Absolute") && Is_Ocpp_ChargingProfileId(_index))
- {
- _maxCount = Get_Ocpp_ChargingProfileScheduleCount(_index);
- _startCount = Get_Ocpp_ChargingProfileStartIndex(_index);
- if(_startCount < _maxCount)
- {
- _limit = Get_Ocpp_ChargingProfileScheduleLimit(_index, _startCount);
- _numberPhases = Get_Ocpp_ChargingProfileScheduleNumberPhases(_index, _startCount);
- chargingInfo[_index]->ChargingProfilePower = _limit * AC_OUTPUT_VOL * _numberPhases;
- if(chargingInfo[_index]->EvBatterytargetVoltage > 0 &&
- (int)chargingInfo[_index]->PresentChargingVoltage > 0)
- {
- chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
- }
- else
- {
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- if((int)_lastProfilePower[_index] != (int)chargingInfo[_index]->ChargingProfilePower ||
- (int)_lastProfileCurrent[_index] != (int)chargingInfo[_index]->ChargingProfileCurrent)
- {
- _limit = Get_Ocpp_ChargingProfileScheduleLimit(_index, _startCount);
- LOG_INFO("Gun %d Get Profile - Index = %d, Limit = %f",
- _index + 1, _startCount, _limit);
- LOG_INFO("Max: %d kW, Gun %d ChargingProfile Power = %d, Current = %d",
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1 ? (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : ((int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000),
- _index + 1, (int)chargingInfo[_index]->ChargingProfilePower, (int)chargingInfo[_index]->ChargingProfileCurrent);
- }
- _lastProfilePower[_index] = chargingInfo[_index]->ChargingProfilePower;
- _lastProfileCurrent[_index] = chargingInfo[_index]->ChargingProfileCurrent;
- }
- void Ocpp_MaxChargingProfile_Process(void)
- {
- int _startCount = NO_DEFINE;
- int _maxCount = 0;
- float _limit = 0;
- int _numberPhases = 0;
- if(Is_Ocpp_MaxChargingProfileKind("Absolute") && Is_Ocpp_MaxChargingProfileId())
- {
- _maxCount = Get_Ocpp_MaxProfileScheduleCount();
- _startCount = Get_Ocpp_MaxProfileStartIndex();
- if(_startCount < _maxCount)
- {
- _limit = Get_Ocpp_MaxProfileScheduleLimit(_startCount);
- _numberPhases = Get_Ocpp_MaxProfileScheduleNumberPhases(_startCount);
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = _limit * AC_OUTPUT_VOL * _numberPhases;
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- }
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- }
- if((int)_lastMaxProfilePower != (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower)
- {
- _limit = Get_Ocpp_MaxProfileScheduleLimit(_startCount);
- LOG_INFO("Charger Get Max Profile - Index = %d, Limit = %f",
- _startCount, _limit);
- LOG_INFO("Charger Max Profile Power = %d", (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower);
- }
- _lastMaxProfilePower = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
- }
- void CheckSmartChargeProfile(byte _index)
- {
- if(Is_Ocpp_ChargingProfileConf(_index))
- {
- Clean_Ocpp_ChargingProfileConf(_index);
- Ocpp_MaxChargingProfile_Process();
- Ocpp_ChargingProfile_Process(_index);
- }
- }
- void GetLocalPowerLimit(byte gunIndex)
- {
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > _SYS_POWER_SHARING_MODE_DISABLE)
- {
- if(ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer)
- {
- float _localLimitPower = ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent[gunIndex] * AC_OUTPUT_VOL;
- if(chargingInfo[gunIndex]->EvBatterytargetVoltage > 0 && (int)chargingInfo[gunIndex]->PresentChargingVoltage > 0)
- {
- chargingInfo[gunIndex]->LocalPowerLimitCurrent = _localLimitPower / chargingInfo[gunIndex]->PresentChargingVoltage;
- }
- else
- {
- chargingInfo[gunIndex]->LocalPowerLimitCurrent = -1;
- }
- }
- else
- {
- chargingInfo[gunIndex]->LocalPowerLimitCurrent = 0;
- }
- }
- else
- {
- chargingInfo[gunIndex]->LocalPowerLimitCurrent = -1;
- }
- }
- void TheEndCharging(byte gun_index)
- {
- chargingInfo[gun_index]->isRemoteStart = NO;
- if(strlen((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL) > 0 && ShmChargerInfo->UserTransaction[gun_index].TransactionId > 0)
- {
- char receiptString[512];
- sprintf(receiptString, "%s%d",
- (char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL[0], ShmChargerInfo->UserTransaction[gun_index].TransactionId);
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gun_index][0], receiptString);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_RECEIPT);
- LOG_INFO("Gun %d ReceiptrURL: [%s]", gun_index + 1, receiptString);
- }
- ChangeStartOrStopDateTime(NO, gun_index);
- DB_Insert_Record(localDb, gun_index);
- }
- void UpdateErrorCodeToOcpp(byte index)
- {
- //printf("ConnectorAlarmCode = %s \n", chargingInfo[index]->ConnectorAlarmCode);
- if (strcmp((char *)chargingInfo[index]->ConnectorAlarmCode, "") != EQUAL)
- {
- SetOcppErrorCode(index, "InternalError");
- SetOcppVendorErrorCode(index, (char *)chargingInfo[index]->ConnectorAlarmCode);
- }
- else if (strcmp((char *)chargingInfo[index]->EvConnAlarmCode, "") != EQUAL)
- {
- SetOcppErrorCode(index, "OtherError");
- SetOcppVendorErrorCode(index, (char *)chargingInfo[index]->EvConnAlarmCode);
- }
- }
- void CheckMiscCommandRequirement(void)
- {
- BOOL NeedAnnouncement = FALSE;
- unsigned char connector = 0;
- if(ShmSysConfigAndInfo->SysInfo.FirmwareUpdate != YES)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- NeedAnnouncement = FALSE;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
- {
- if(ShmChargerInfo->DispenserMiscReq[i].CtrlValue != 0)
- {
- NeedAnnouncement = TRUE;
- }
- for(int j = 0; j < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity; j++)
- {
- connector = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorID[j] - 1;
- if(ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue != 0)
- {
- NeedAnnouncement = TRUE;
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.MiscNeedAnnouncement != NeedAnnouncement)
- {
- if(NeedAnnouncement)
- {
- //LOG_INFO("********** Dispenser %d Misc Command Need Announcement **********", i + 1);
- }
- else
- {
- //LOG_INFO("********** Dispenser %d Misc Command Announced **********", i + 1);
- }
- }
- }
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.MiscNeedAnnouncement = NeedAnnouncement;
- }
- }
- }
- void CheckDispenserVersionUpdateRequirement(void)
- {
- }
- bool IsReadyParalleling(void)
- {
- bool ready = true;
- for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
- {
- if(chargingInfo[i]->SystemStatus != S_IDLE && chargingInfo[i]->SystemStatus != S_MAINTAIN)
- {
- ready = false;
- break;
- }
- }
- return ready;
- }
- void SetParallelingStart(void)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(chargingInfo[i]->SystemStatus == S_IDLE)
- {
- setChargerMode(i, MODE_MAINTAIN);
- }
- }
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_Wait;
- }
- void SetParallelingDone(void)
- {
- unsigned short totalPow = 0;
- totalPow = GetTotalParallelCabinetPower();
- if(totalPow != ShmChargerInfo->ParallelCabinet.TotalParallelPower)
- {
- LOG_INFO("Total Parallel Cabinet Power: %d.%d kW", (totalPow / 10), (totalPow % 10));
- }
- ShmChargerInfo->ParallelCabinet.TotalParallelPower = totalPow;
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_None;
- }
- void SetPCabinetOutputRelay(unsigned char index, unsigned char OnOff)
- {
- unsigned char relay = 0;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle &&
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelConfirm)
- {
- relay = OnOff == YES ? YES : NO;
- if(ShmChargerInfo->ParallelCabinet.PCabinet[index].OutputRelaySetting[index] != relay)
- {
- LOG_INFO("Set Parallel Cabinet Gun %d Output Relay %s", index + 1, relay == YES ? "ON" : "OFF");
- }
- ShmChargerInfo->ParallelCabinet.PCabinet[i].OutputRelaySetting[index] = relay;
- }
- }
- }
- }
- void SetParallelCabinetAcContactor(unsigned char OnOff)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle &&
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelConfirm)
- {
- ShmChargerInfo->ParallelCabinet.PCabinet[i].AcContactorSetting = OnOff == YES ? YES : NO;
- }
- }
- }
- unsigned short GetTotalParallelCabinetPower(void)
- {
- unsigned short power = 0, slavePow = 0;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- slavePow = ParsingRatingPower((char *)ShmChargerInfo->ParallelCabinet.PCabinet[i].ModelName);
- power += slavePow;
- }
- }
- }
- return power;
- }
- unsigned char preParallelStatus = 0;
- void MCabinetParallelingProcess(void)
- {
- bool PsuReInitial = false;
- unsigned char status = 0;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- if(IsReadyParalleling())
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelRequest)
- {
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelRequest = false;
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelConfirm = true;
- PsuReInitial = true;
- }
- }
- if(PsuReInitial)
- {
- SetParallelingStart();
- }
- }
- status = ShmChargerInfo->ParallelCabinet.ParallelStatus;
- switch(status)
- {
- case _Parallel_None:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [None]");
- GetClockTime(&_Parallel_Time);
- }
- unsigned short totalPow = 0;
- totalPow = GetTotalParallelCabinetPower();
- if(totalPow != ShmChargerInfo->ParallelCabinet.TotalParallelPower)
- {
- LOG_INFO("Total Parallel Cabinet Power: %d.%d kW", (totalPow / 10), (totalPow % 10));
- }
- ShmChargerInfo->ParallelCabinet.TotalParallelPower = totalPow;
- break;
- case _Parallel_Wait:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [Wait]");
- SetAcContactor(OFF);
- SetParallelCabinetAcContactor(OFF);
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- SetPCabinetOutputRelay(i, OFF);
- }
- GetClockTime(&_Parallel_Time);
- }
- if((GetTimeoutValue(_Parallel_Time) / uSEC_VAL) >= PARALLEL_WAIT_TIME)
- {
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_Working;
- }
- break;
- case _Parallel_Working:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [Working]");
- SetAcContactor(ON);
- SetParallelCabinetAcContactor(ON);
- GetClockTime(&_Parallel_Time);
- }
- if(ShmPsuData->Work_Step == _WORK_CHARGING)
- {
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_Done;
- }
- break;
- case _Parallel_Done:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [Done]");
- GetClockTime(&_Parallel_Time);
- }
- if((GetTimeoutValue(_Parallel_Time) / uSEC_VAL) >= PARALLEL_WAIT_TIME)
- {
- SetParallelingDone();
- }
- break;
- }
- preParallelStatus = status;
- }
- }
- void SCabinetControllProcess(void)
- {
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- if(ShmChargerInfo->SCabinetControl.SAcContactor)
- {
- SetAcContactor(ON);
- }
- else
- {
- SetAcContactor(OFF);
- }
- unsigned short _parallelRelay = 0;
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- _parallelRelay = ShmChargerInfo->SCabinetControl.SParallelRelay[i] > 0 ? (1 < i) : 0;
- }
- if(_parallelRelay != ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue)
- {
- LOG_INFO("SCabinet Set Parallel Relay %X -> %X", ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue, _parallelRelay);
- }
- ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue = _parallelRelay;
- }
- }
- void CheckConnectorDisconnectionRecovery(unsigned char connector)
- {
- unsigned char dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].ParentDispensetIndex;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
- {
- LOG_INFO("Connector %d Disconnection Recovery", connector + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].Parameter.bits.Disconnection = false;
- }
- }
- bool ConnectorRequestToCharging(unsigned char connector)
- {
- unsigned char role = 0;
- bool done = false;
- role = ShmPsuGrouping->GroupCollection[connector].Role;
- switch(role)
- {
- case _GROLE_IDLE:
- if(!ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.ChargingRequest)
- {
- LOG_INFO("Request Gun %d To Start Charging", connector + 1);
- }
- ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.ChargingRequest = true;
- break;
- case _GROLE_MASTER:
- done = true;
- break;
- case _GROLE_SLAVE:
- if(!ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.SlaveChargingRequest)
- {
- LOG_INFO("Gun %d Wait For Re-Grouping", connector + 1);
- }
- ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.SlaveChargingRequest = true;
- break;
- case _GROLE_REQUEST_TO_CHARGING:
- done = true;
- break;
- default:
- break;
- }
- return done;
- }
- bool IsConnectorGroupingCompleted(unsigned char connector)
- {
- unsigned char role = 0;
- bool completed = false;
- role = ShmPsuGrouping->GroupCollection[connector].Role;
- switch(role)
- {
- case _GROLE_MASTER:
- completed = true;
- break;
- default:
- break;
- }
- return completed;
- }
- void SelfTestFailReason(void)
- {
- char reason[50];
- memset(reason, 0x00, sizeof(reason));
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip)
- {
- StatusCodeCompose(reason, "042251");
- }
- else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail)
- {
- StatusCodeCompose(reason, "042280");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail)
- {
- StatusCodeCompose(reason, "042281");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail)
- {
- StatusCodeCompose(reason, "042282");
- }
- }
- else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail)
- {
- StatusCodeCompose(reason, "042285");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail)
- {
- StatusCodeCompose(reason, "042286");
- }
- }
- else
- {
- StatusCodeCompose(reason, "Self Test Fail");
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- SetOcppErrorCode(gun_index, "InternalError");
- SetOcppVendorErrorCode(gun_index, reason);
- setChargerMode(gun_index, MODE_MAINTAIN);
- }
- }
- bool IsAvailableBackToIdle(int gun_index)
- {
- if(_plugInHold[gun_index] == false &&
- (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable == false || chargingInfo[gun_index]->ConnectorPlugIn == false))
- {
- _plugInHold[gun_index] = true;
- GetClockTime(&_PlugInHold_Time[gun_index]);
- LOG_INFO ("Gun %d Plug In Hold Delay", gun_index + 1);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Idle ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable == false ||
- (!chargingInfo[gun_index]->ConnectorPlugIn && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm) ||
- isResetStopChargeFlag(gun_index) == YES)
- {
- if(!_plugInHold[gun_index])
- {
- _plugInHold[gun_index] = true;
- GetClockTime(&_PlugInHold_Time[gun_index]);
- LOG_INFO ("Force Gun %d Plug In Hold Delay", gun_index + 1);
- }
- if((GetTimeoutValue(_PlugInHold_Time[gun_index]) / uSEC_VAL) >= PLUG_IN_HOLD_TIME)
- {
- return true;
- }
- }
- return false;
- }
- void CheckGunAvailable(void)
- {
- if(!ShmChargerInfo->Control.SysCtrl.bits.PsuInit)
- {
- if(ShmChargerInfo->Control.PsuCtrl.bits.SelfTestOK)
- {
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- if(ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity > 0)
- {
- ShmChargerInfo->Control.GunAvailable[i] = YES;
- }
- }
- ShmChargerInfo->Control.SysCtrl.bits.PsuInit = true;
- }
- }
- }
- int presentChargedEnergyClear(unsigned char gun_index)
- {
- int result = FAIL;
- chargingInfo[gun_index]->PresentChargedEnergy = 0;
- memset(chargingInfo[gun_index]->presentChargedEnergyPeriod, 0x00, ARRAY_SIZE(chargingInfo[gun_index]->presentChargedEnergyPeriod) * sizeof(float));
- result = PASS;
- return result;
- }
- float presentChargedEnergyTotal(unsigned char gun_index)
- {
- float result = 0.0f;
- for(int idx = 0; idx < ARRAY_SIZE(chargingInfo[gun_index]->presentChargedEnergyPeriod); idx++)
- {
- result += chargingInfo[gun_index]->presentChargedEnergyPeriod[idx];
- }
- return result;
- }
- int presentChargedEnergyUpdate(unsigned char gun_index, float kwh)
- {
- int result = FAIL;
- time_t CurrentTime;
- struct tm *tm;
- CurrentTime = time(NULL);
- tm=localtime(&CurrentTime);
- chargingInfo[gun_index]->presentChargedEnergyPeriod[tm->tm_hour] += kwh;
- return result;
- }
- void ChargedEnergySummation(unsigned char gun_index)
- {
- unsigned long time = 0;
- time = GetSecTimeoutValue(_ChargedEnergy_Time[gun_index]);
- if(time >= (chargingInfo[gun_index]->PresentChargedDuration + ENERAGY_INTERVAL))
- {
- chargingInfo[gun_index]->PresentChargedDuration++;
- float changedEnergy = 0;
- float _meterEnergy = 0;
- float _calChangingEnergy = (chargingInfo[gun_index]->PresentChargingPower) / 3600;
- if(ShmChargerInfo->MeterValue[gun_index].GunConsumption >= 0)
- {
- if(ShmChargerInfo->MeterValue[gun_index].GunConsumption >= _lsatGunMeterValue[gun_index])
- {
- _meterEnergy = ShmChargerInfo->MeterValue[gun_index].GunConsumption - _lsatGunMeterValue[gun_index];
- }
- else
- {
- _meterEnergy = 0;
- }
- changedEnergy = _meterEnergy;
- _lsatGunMeterValue[gun_index] = ShmChargerInfo->MeterValue[gun_index].GunConsumption;
- }
- else
- {
- changedEnergy = _calChangingEnergy;
- }
- if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
- {
- chargingInfo[gun_index]->ChargingFee += changedEnergy * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
- }
- presentChargedEnergyUpdate(gun_index, changedEnergy);
- chargingInfo[gun_index]->PresentChargedEnergy += changedEnergy;
- ShmChargerInfo->MeterValue[gun_index].LocalConsumption += changedEnergy;
- }
- }
- void ChkConnectorAction(void)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ConnectorActReq[i].Flag.bits.ChargingCancel)
- {
- if(ShmChargerInfo->AllBill.OccupancyInfo[i].Status != _Parking_WaitToPay)
- {
- LOG_INFO("Gun %d Charging Canceled", i + 1);
- Clean_Ocpp_TcciSerialNo(i);
- }
- else
- {
- LOG_INFO("Gun %d Occupancy Keep Counting", i + 1);
- Set_OccupancyKeepCountingReq(i);
- }
- ShmChargerInfo->ConnectorActReq[i].Flag.bits.ChargingCancel = false;
- }
- }
- }
- void Update_DispenserAvailability(int dispenserIndex)
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
- Set_Connector_MiscCommand(gun, MISC_CONN_AVAILABILITY);
- }
- }
- void InitialDataBaseValue(void)
- {
- // Local DB
- if(DB_Open(localDb) != PASS)
- {
- LOG_INFO("DB_Open fail.");
- isDb_ready = false;
- }
- else
- {
- isDb_ready = true;
- DB_TryAddRebootRecordColumn(localDb);
- DB_TryAddChargingRecordColumn(localDb);
- for(int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
- LOG_INFO("Gun %d IsAvailable Initial: [%s]", _index + 1, chargingInfo[_index]->IsAvailable == YES ? "Enable" : "Disable");
- }
- for(int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- ShmChargerInfo->MeterValue[_index].LocalConsumption = DB_Get_LocalConsumption(localDb, _index);
- LOG_INFO("Local Gun %d Consumption Initial: [%.4f kWh]", _index + 1, ShmChargerInfo->MeterValue[_index].LocalConsumption);
- }
- for(int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- ShmChargerInfo->MeterValue[_index].GunConsumption = DB_Get_GunConsumption(localDb, _index);
- LOG_INFO("Remote Gun %d Consumption Initial: [%.4f kWh]", _index + 1, ShmChargerInfo->MeterValue[_index].GunConsumption);
- }
- for(int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- Update_PowerConsumption(_index);
- LOG_INFO("Gun %d Power Consumption Initial: [%.4f kWh]", _index + 1, chargingInfo[_index]->PowerConsumption);
- }
- DB_Reboot_Record(localDb);
- }
- if (NetworkDB_Open(networkDb) != PASS)
- {
- LOG_ERROR("NetworkDB_Open fail.");
- }
- }
- float CalculateMaxOutputRatio(int gunIndex)
- {
- float ratio = 0;
- int inUsingCnt = 0;
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[i].Role == _GROLE_MASTER)
- {
- inUsingCnt += ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity;
- }
- }
- if(inUsingCnt != 0)
- {
- ratio = ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].Role == _GROLE_MASTER ?
- ((float)ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].GunPsuQuantity / inUsingCnt) : 0;
- }
- ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio = ratio;
- return ratio;
- }
- // return unit: 0.1kW
- unsigned short GetModelNameLimitPower(int gunIndex)
- {
- unsigned short limitPower = 0;
- float fPower = 0;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio != 0 &&
- ShmChargerInfo->Control.ChargerRatingPower != 0)
- {
- fPower = (float)ShmChargerInfo->Control.ChargerRatingPower / 10;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- fPower += (float)ShmChargerInfo->ParallelCabinet.TotalParallelPower / 10;
- }
- fPower = fPower * ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio;
- limitPower = (unsigned short)(fPower * 10);
- }
- return limitPower;
- }
- void GetWebPageConfigPowerLimit(int gunIndex)
- {
- unsigned short limitPower = 0;
- float fPower = 0;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio != 0 &&
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower != 0)
- {
- fPower = (float)ShmSysConfigAndInfo->SysConfig.MaxChargingPower;
- fPower = fPower * ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio;
- limitPower = (unsigned short)(fPower * 10);
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingPower = limitPower;
- }
- void GetWebPageConfigCurrentLimit(int gunIndex)
- {
- unsigned short limitCurrent = 0;
- float fCurrent = 0;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio != 0 &&
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent != 0)
- {
- fCurrent = (float)ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent;
- fCurrent = fCurrent * ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio;
- limitCurrent = (unsigned short)(fCurrent * 10);
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingCurrent = limitCurrent;
- }
- void GetOffLineMaxChargingPowerLimit(int gunIndex)
- {
- unsigned short limitPower = 0;
- float fPower = 0;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio != 0 &&
- ShmChargerInfo->OutputLimit.Offline_MaxChargingPower != 0 &&
- ShmStatusCodeData->InfoCode.InfoEvents.bits.BackendDisconnectedViaEthernet == YES)
- {
- fPower = ShmChargerInfo->OutputLimit.Offline_MaxChargingPower / 1000;
- fPower = fPower * ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio;
- limitPower = (unsigned short)(fPower * 10);
- }
- ShmChargerInfo->OutputLimit.GunOfflineMaxPower[gunIndex] = limitPower * 100;
- }
- void GetMaxChargingProfileLimit(int gunIndex)
- {
- unsigned short limitPower = 0, limitCurrent = 0;
- float fPower = 0;
- // max charging profile
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio != 0 &&
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower >= 0)
- {
- fPower = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000;
- fPower = fPower * ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio;
- limitPower = (unsigned short)(fPower * 10);
- if (chargingInfo[gunIndex]->EvBatterytargetVoltage > 0 &&
- (int)chargingInfo[gunIndex]->PresentChargingVoltage > 0)
- {
- limitCurrent = (limitPower * 100 / chargingInfo[gunIndex]->PresentChargingVoltage) * 10;
- }
- }
- ShmChargerInfo->OutputLimit.GunMaxProfilePower[gunIndex] = limitPower * 100;
- ShmChargerInfo->OutputLimit.GunMaxProfileCurrent[gunIndex] = limitCurrent;
- }
- void GetMaxChargingLimit(int gunIndex)
- {
- GetWebPageConfigPowerLimit(gunIndex);
- GetWebPageConfigCurrentLimit(gunIndex);
- GetOffLineMaxChargingPowerLimit(gunIndex);
- GetMaxChargingProfileLimit(gunIndex);
- }
- void GetGunOtpDerating(int gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].GeneralChargingData.deratingByConnOtp.isNeedDerating &&
- chargingInfo[gunIndex]->SystemStatus > S_IDLE &&
- chargingInfo[gunIndex]->SystemStatus <= S_CHARGING)
- {
- struct DERATING_BY_OTP *_derating;
- _derating = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].GeneralChargingData.deratingByConnOtp;
- if(_derating->deratingIndex < GUN_DERATING_COUNT)
- {
- int _connectorTemp = (int)chargingInfo[gunIndex]->ConnectorTemp - 60;
- int _chillerTemp = (int)chargingInfo[gunIndex]->ChillerTemp - 60;
- if(_connectorTemp >= GunDeratingTemp[_derating->deratingIndex] &&
- chargingInfo[gunIndex]->ConnectorTemp != 0xFF &&
- _derating->deratingTargetCurrent[_derating->deratingIndex + 1] > 0)
- {
- LOG_INFO("Gun %d GunTemp %d is Derating(%d) to %d A",
- gunIndex + 1,
- _connectorTemp,
- GunDeratingTemp[_derating->deratingIndex],
- ((int)_derating->deratingTargetCurrent[_derating->deratingIndex + 1] / 10));
- _derating->deratingIndex++;
- }
- else if(_chillerTemp >= GunDeratingTemp[_derating->deratingIndex] &&
- chargingInfo[gunIndex]->ChillerTemp != 0xFF &&
- _derating->deratingTargetCurrent[_derating->deratingIndex + 1] > 0)
- {
- LOG_INFO("Gun %d ChillerTemp %d is Derating(%d) to %d A",
- gunIndex + 1,
- _chillerTemp,
- GunDeratingTemp[_derating->deratingIndex],
- ((int)_derating->deratingTargetCurrent[_derating->deratingIndex + 1] / 10));
- _derating->deratingIndex++;
- }
- }
- if(chargingInfo[gunIndex]->ConnectorTemp != 0xFF || chargingInfo[gunIndex]->ChillerTemp != 0xFF)
- {
- ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex] = (int)_derating->deratingTargetCurrent[_derating->deratingIndex];
- ShmChargerInfo->OutputLimit.GunOtpMaxPower[gunIndex] = 0;
- }
- else
- {
- ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex] = 0;
- ShmChargerInfo->OutputLimit.GunOtpMaxPower[gunIndex] = 0;
- }
- }
- else
- {
- ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex] = 0;
- ShmChargerInfo->OutputLimit.GunOtpMaxPower[gunIndex] = 0;
- }
- }
- void CalculateGunAbsMaxPower(int gunIndex)
- {
- int maxValue = 0;
- maxValue = (int)GetModelNameLimitPower(gunIndex);
- ShmChargerInfo->OutputLimit.GunAbsoluteMaxPower[gunIndex] = maxValue != 0 ? (maxValue * 100) : 0;
- }
- void CalculateGunAbsMaxVoltage(int gunIndex)
- {
- int maxValue = 0;
- maxValue = (int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteMaxPhysicalVoltage;
- ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex] = maxValue;
- }
- void CalculateGunAbsMaxCurrent(int gunIndex)
- {
- int maxValue = 0;
- maxValue = (int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteMaxPhysicalCurrent;
- ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex] = maxValue;
- }
- void RestrictChargingCapability(int gunIndex, unsigned short *power, unsigned short *voltage, unsigned short *current)
- {
- unsigned short limitPower = 0;
- int _limitPowerResult = 0;
- int _limitVoltageResult = 0;
- int _limitCurrentResult = 0;
- _limitPowerResult = ShmPsuData->SystemAvailablePower;
- _limitVoltageResult = MAX_OUTPUT_VOLTAGE;
- _limitCurrentResult = ShmPsuData->SystemAvailableCurrent;
- if(ShmChargerInfo->OutputLimit.GunAbsoluteMaxPower[gunIndex] != 0)
- {
- limitPower = ShmChargerInfo->OutputLimit.GunAbsoluteMaxPower[gunIndex] / 100;
- if(limitPower != 0 && _limitPowerResult > limitPower)
- {
- _limitPowerResult = limitPower;
- }
- }
- if(ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex] != 0 &&
- _limitVoltageResult > ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex])
- {
- _limitVoltageResult = ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex];
- }
- if(ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex] != 0 &&
- _limitCurrentResult > ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex])
- {
- _limitCurrentResult = ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex];
- }
- // restrict from WebPageConfig power
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingPower != 0)
- {
- if(_limitPowerResult > ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingPower)
- {
- _limitPowerResult = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingPower;
- }
- }
- // restrict from WebPageConfig current
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingCurrent != 0)
- {
- if(_limitCurrentResult > ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingCurrent)
- {
- _limitCurrentResult = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingCurrent;
- }
- }
- // restrict from Offline_MaxChargingPower
- if(ShmChargerInfo->OutputLimit.GunOfflineMaxPower[gunIndex] != 0)
- {
- limitPower = ShmChargerInfo->OutputLimit.GunOfflineMaxPower[gunIndex] / 100;
- if(limitPower != 0 && _limitPowerResult > limitPower)
- {
- _limitPowerResult = limitPower;
- }
- }
- // restrict from MaxChargingProfile
- if(ShmChargerInfo->OutputLimit.GunMaxProfilePower[gunIndex] != 0)
- {
- limitPower = ShmChargerInfo->OutputLimit.GunMaxProfilePower[gunIndex] / 100;
- if(limitPower != 0 && _limitPowerResult > limitPower)
- {
- _limitPowerResult = limitPower;
- }
- }
- // restrict from MaxChargingProfile
- if(ShmChargerInfo->OutputLimit.GunMaxProfileCurrent[gunIndex] != 0)
- {
- if(_limitCurrentResult > ShmChargerInfo->OutputLimit.GunMaxProfileCurrent[gunIndex])
- {
- _limitCurrentResult = ShmChargerInfo->OutputLimit.GunMaxProfileCurrent[gunIndex];
- }
- }
- // restrict from ChargingProfile
- if((chargingInfo[gunIndex]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[gunIndex]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gunIndex]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if(chargingInfo[gunIndex]->ChargingProfilePower >= 0 && _limitPowerResult > ((int)chargingInfo[gunIndex]->ChargingProfilePower / 100))
- {
- _limitPowerResult = (int)chargingInfo[gunIndex]->ChargingProfilePower / 100;
- }
- if(chargingInfo[gunIndex]->ChargingProfileCurrent >= 0 && _limitCurrentResult > (int)chargingInfo[gunIndex]->ChargingProfileCurrent)
- {
- _limitCurrentResult = (int)chargingInfo[gunIndex]->ChargingProfileCurrent;
- }
- }
- // restrict from local power limit
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > _SYS_POWER_SHARING_MODE_DISABLE)
- {
- if(chargingInfo[gunIndex]->LocalPowerLimitCurrent >= 0 && _limitCurrentResult > (int)(chargingInfo[gunIndex]->LocalPowerLimitCurrent * 10))
- {
- _limitCurrentResult = (int)(chargingInfo[gunIndex]->LocalPowerLimitCurrent * 10);
- }
- }
- // restrict after otp
- if(ShmChargerInfo->OutputLimit.GunOtpMaxPower[gunIndex] != 0)
- {
- limitPower = ShmChargerInfo->OutputLimit.GunOtpMaxPower[gunIndex] / 100;
- if(limitPower != 0 && _limitPowerResult > limitPower)
- {
- _limitPowerResult = limitPower;
- }
- }
- // restrict after otp
- if(ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex] != 0 &&
- _limitCurrentResult > ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex])
- {
- _limitCurrentResult = ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex];
- }
- ShmChargerInfo->OutputLimit.GunLimitPower[gunIndex] = _limitPowerResult;
- ShmChargerInfo->OutputLimit.GunLimitVoltage[gunIndex] = _limitVoltageResult;
- ShmChargerInfo->OutputLimit.GunLimitCurrent[gunIndex] = _limitCurrentResult;
- if(_limitPowerResult != 0 && *power > _limitPowerResult)
- {
- *power = _limitPowerResult;
- }
- if(_limitVoltageResult != 0 && *voltage > _limitVoltageResult)
- {
- *voltage = _limitVoltageResult;
- }
- if(_limitCurrentResult != 0 && *current > _limitCurrentResult)
- {
- *current = _limitCurrentResult;
- }
- }
- void UpdateChargingCapability(void)
- {
- unsigned short voltage = 0, current = 0, power = 0;
- ShmChargerInfo->OutputLimit.Offline_MaxChargingPower = Get_Ocpp_OffLineMaxChargingPower();
- for(int i = 0; i < MAX_GUN_QUANTITY; i++)
- {
- voltage = (unsigned short)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.MaximumChargingVoltage;
- current = (unsigned short)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.AvailableChargingCurrent;
- power = (unsigned short)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.AvailableChargingPower;
- CalculateGunAbsMaxPower(i);
- CalculateGunAbsMaxVoltage(i);
- CalculateGunAbsMaxCurrent(i);
- CalculateMaxOutputRatio(i);
- GetMaxChargingLimit(i);
- GetLocalPowerLimit(i);
- GetGunOtpDerating(i);
- RestrictChargingCapability(i, &power, &voltage, ¤t);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CapabilityVoltage = voltage;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CapabilityCurrent = current;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CapabilityPower = power;
- }
- }
- void GunErrorCollection(void)
- {
- bool _PsuNoResource = false;
- for(int i = 0; i < MAX_GUN_QUANTITY; i++)
- {
- if(ShmPsuData->Work_Step == INITIAL_START)
- {
- ShmChargerInfo->GunError[i].ErrFlag.bits.PsuGroupNoResource = false;
- }
- else
- {
- if(ShmChargerInfo->GunError[i].ErrFlag.bits.PsuGroupNoResource)
- {
- _PsuNoResource = true;
- }
- }
- }
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = _PsuNoResource;
- }
- void UpdateGunPresentChargingPower(int gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Enable)
- {
- chargingInfo[gunIndex]->PresentChargingPower = (((float)((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteChargingVoltage) * (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteChargingCurrent))) / 1000 / 100);
- }
- else
- {
- chargingInfo[gunIndex]->PresentChargingPower = ((float)((chargingInfo[gunIndex]->PresentChargingVoltage) * (chargingInfo[gunIndex]->PresentChargingCurrent)) / 1000);
- }
- }
- void CheckPsuLostQuantity(void)
- {
- if(ShmPsuData->Work_Step == _WORK_CHARGING)
- {
- if(ShmChargerInfo->Control.PsuQuantityByModel == ShmPsuData->SystemPresentPsuQuantity)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.PsuQuantityNotMatch = false;
- ShmSysConfigAndInfo->SysInfo.PsuLostQuantity = 0;
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.PsuLostQuantity = ShmChargerInfo->Control.PsuQuantityByModel > ShmPsuData->SystemPresentPsuQuantity ?
- (ShmChargerInfo->Control.PsuQuantityByModel - ShmPsuData->SystemPresentPsuQuantity) : 0;
- if(!ShmStatusCodeData->InfoCode.InfoEvents.bits.PsuQuantityNotMatch ||
- _psuLostQuantity != ShmSysConfigAndInfo->SysInfo.PsuLostQuantity)
- {
- LOG_INFO("Psu Quantity is %d, it should be %d, Psu Lost: %d",
- ShmPsuData->SystemPresentPsuQuantity, ShmChargerInfo->Control.PsuQuantityByModel,
- ShmSysConfigAndInfo->SysInfo.PsuLostQuantity);
- }
- ShmStatusCodeData->InfoCode.InfoEvents.bits.PsuQuantityNotMatch = true;
- _psuLostQuantity = ShmSysConfigAndInfo->SysInfo.PsuLostQuantity;
- }
- }
- }
- void CheckOcmfHandler(void)
- {
- bool _newOcmf = false;
- int _ocmfLength = 0;
- int _gunIndex = 0;
- char _txId[37];
- char _ocmfKey[201];
- char _ocmfInfo[2048];
- // check new ocmf info
- for(int i = 0; i < MAX_GUN_QUANTITY; i++)
- {
- if(ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfFlag.bits.OcmfReceived)
- {
- _newOcmf = false;
- char fileName[256] = {0};
- sprintf(fileName, "/mnt/Gun_%d_%s_OCMF", i + 1, ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId);
- if(access(fileName, F_OK) != -1)
- {
- _newOcmf = true;
- }
- if(_newOcmf)
- {
- int fd = 0;
- fd = open(fileName, O_RDONLY);
- if(fd < 0)
- {
- LOG_INFO("Gun %d TxId[%s] OCMF file [%s] open fail", i + 1, ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId, fileName);
- }
- else
- {
- memset(_txId, 0x00, sizeof(_txId));
- memset(_ocmfKey, 0x00, sizeof(_ocmfKey));
- memset(_ocmfInfo, 0x00, sizeof(_ocmfInfo)); //-48 is take out the header
- _ocmfLength = read(fd, _ocmfInfo, sizeof(_ocmfInfo) - 1);
- close(fd);
- memcpy(_txId, ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId, sizeof(ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId));
- memcpy(_ocmfKey, ShmChargerInfo->OcmfInfo.GunOcmf[i].PublicKey, sizeof(ShmChargerInfo->OcmfInfo.GunOcmf[i].PublicKey));
- DB_Insert_Ocmf(localDb, i, _txId, _ocmfKey, _ocmfInfo);
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfPending = true;
- char cmdBuf[256] = {0};
- sprintf(cmdBuf, "rm -f %s", fileName);
- system(cmdBuf);
- LOG_INFO("Gun %d TxId[%s] insert OCMF info ok, length: %d", i + 1, ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId, _ocmfLength);
- }
- }
- else
- {
- LOG_INFO("Gun %d TxId[%s] OCMF info [%s] access fail", i + 1, ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId, fileName);
- }
- memset(ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId, 0x00, sizeof(ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId));
- memset(ShmChargerInfo->OcmfInfo.GunOcmf[i].PublicKey, 0x00, sizeof(ShmChargerInfo->OcmfInfo.GunOcmf[i].PublicKey));
- ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfFlag.bits.OcmfReceived = false;
- }
- }
- // try to find ocmf pending in database
- if(ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfPending && !ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfNeedUpload)
- {
- _gunIndex = 0;
- memset(_txId, 0x00, sizeof(_txId));
- memset(_ocmfKey, 0x00, sizeof(_ocmfKey));
- memset(_ocmfInfo, 0x00, sizeof(_ocmfInfo));
- ShmChargerInfo->OcmfInfo.SysOcmfIndex = 0;
- memset(ShmChargerInfo->OcmfInfo.SysOcmfTxId, 0x00, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfTxId));
- memset(ShmChargerInfo->OcmfInfo.SysOcmfPublicKey, 0x00, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfPublicKey));
- memset(ShmChargerInfo->OcmfInfo.SysOcmfInfo, 0x00, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfInfo));
- if(DB_Get_Undisposed_Ocmf(localDb, &_gunIndex, _txId, _ocmfKey, _ocmfInfo))
- {
- ShmChargerInfo->OcmfInfo.SysOcmfIndex = _gunIndex;
- memcpy(ShmChargerInfo->OcmfInfo.SysOcmfTxId, _txId, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfTxId));
- memcpy(ShmChargerInfo->OcmfInfo.SysOcmfPublicKey, _ocmfKey, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfPublicKey));
- memcpy(ShmChargerInfo->OcmfInfo.SysOcmfInfo, _ocmfInfo, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfInfo));
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfNeedUpload = true;
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading = false;
- LOG_INFO("Gun %d TxId[%s] OCMF info need upload", _gunIndex + 1, _txId);
- }
- else
- {
- LOG_INFO("There is no ocmf info pending");
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.CtrlValue = 0;
- }
- }
- // try to upload ocmf to backend
- if(ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfNeedUpload)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- if(!ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading)
- {
- if(!Is_Ocpp_SendOcmfDataReq(ShmChargerInfo->OcmfInfo.SysOcmfIndex))
- {
- Set_Ocpp_OcmfData(ShmChargerInfo->OcmfInfo.SysOcmfIndex, ShmChargerInfo->OcmfInfo.SysOcmfPublicKey, ShmChargerInfo->OcmfInfo.SysOcmfInfo);
- Set_Ocpp_SendOcmfDataReq(ShmChargerInfo->OcmfInfo.SysOcmfIndex);
- LOG_INFO("Set Gun %d TxId[%s] update OCMF request", ShmChargerInfo->OcmfInfo.SysOcmfIndex + 1, ShmChargerInfo->OcmfInfo.SysOcmfTxId);
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading = true;
- }
- }
- else
- {
- if(!Is_Ocpp_SendOcmfDataReq(ShmChargerInfo->OcmfInfo.SysOcmfIndex))
- {
- DB_Update_Ocmf_Status(localDb, ShmChargerInfo->OcmfInfo.SysOcmfTxId, OCMF_SATAUS_UPDATED_OK);
- LOG_INFO("Gun %d TxId[%s] update OCMF info to backend ok", ShmChargerInfo->OcmfInfo.SysOcmfIndex + 1, ShmChargerInfo->OcmfInfo.SysOcmfTxId);
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfNeedUpload = false;
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading = false;
- }
- }
- }
- else
- {
- if(ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading)
- {
- Clean_Ocpp_SendOcmfDataReq(ShmChargerInfo->OcmfInfo.SysOcmfIndex);
- LOG_INFO("Backend disconnected, Gun %d TxId[%s] ocmf will update later", ShmChargerInfo->OcmfInfo.SysOcmfIndex + 1, ShmChargerInfo->OcmfInfo.SysOcmfTxId);
- }
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading = false;
- }
- }
- }
- int main(void)
- {
- unsigned long time = 0;
- int _dispenser = 0;
- _isStandbyEnable = true;
- if(CreateShareMemory() == 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("CreatShareMemory NG");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- LOG_INFO("\n");
- LOG_INFO("===== Boot and Initialization start =====");
- LOG_INFO("Main Fork PID = %d", getpid());
- if (!InitialSystemDefaultConfig())
- {
- LOG_INFO("InitialSystemDefaultConfig NG");
- StopProcessingLoop();
- }
- LOG_INFO("ModelName: [%s], SN: [%s], SW Version: [%s][%s]",
- ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, fwVersion, subVersion);
- LOG_INFO("InitialShareMemoryInfo");
- InitialShareMemoryInfo();
- LOG_INFO("ChargerType (IEC or UL) = %d", ShmSysConfigAndInfo->SysInfo.ChargerType);
- if(!InitialChargerSetting())
- {
- isModelNameMatch = false;
- }
- Initialization();
- InitialDataBaseValue();
- LOG_INFO("Spawn all Task.");
- SpawnTask();
- if (!isModelNameMatch)
- {
- LOG_INFO("Module Name & HW info none match.");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
- // Module Name 與硬體對應不正確
- LOG_ERROR("Module Name & HW info none match.");
- sleep(3);
- KillAllTask();
- StopProcessingLoop();
- }
- LOG_INFO("Module Name & HW info correct. Initialize.......");
- CreateTimeoutFork();
- SelfTestRun();
- while(ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
- {
- sleep(1);
- }
- if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
- {
- sleep(1);
- SelfTestFailReason();
- }
- else
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_IDLE);
- if(ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity > 0 ||
- !ShmChargerInfo->Control.PsuCtrl.bits.SelfTestOK)
- {
- ShmChargerInfo->Control.GunAvailable[gun_index] = YES;
- }
- }
- }
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE)
- {
- SetAcContactor(ON);
- SpawnOcppService();
- SpawnMaintainOcppService();
- }
- else
- {
- InitSlaveCabinetEthernet();
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_MAINTAIN);
- }
- }
- sleep(1);
- CreateWatchdog();
- // Main loop
- LOG_INFO("%s \n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE ?
- "****************************Main Loop**********************************" :
- "********************** SelfTest Fail **********************");
- GetClockTime(&_cmdMainPriority_time);
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfPending = true;
- for (;;)
- {
- CheckGunAvailable();
- CheckOcppStatus();
- ChkPrimaryStatus();
- ChkPsuStatus();
- PsuFailureResume();
- ChkConnectorAction();
- if(IsUpgradeAvailable())
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- }
- if(CheckFlashUpdate() != YES)
- {
- // return fork process
- return 0;
- }
- CheckSoftHardReset();
- StandbyCheck();
- AuthorizeTimeoutProcess();
- // check ocmf request
- CheckOcmfHandler();
- // 當 AC 沒有搭上時,清除一些錯誤碼
- //ClearAlarmCodeWhenAcOff();
- if ((GetTimeoutValue(_cmdMainPriority_time) / uSEC_VAL) > MAIN_PRIORITY_INTERVAL)
- {
- CheckTask();
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if((chargingInfo[_index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[_index]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[_index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (chargingInfo[_index]->SystemStatus == S_CHARGING && _ocppProfileChkFlag[_index] == 12)
- {
- Ocpp_ProfileReq_Cmd(_index);
- gunOutputVol[_index] = chargingInfo[_index]->PresentChargingVoltage;
- _ocppProfileChkFlag[_index] = 0;
- }
- else if (chargingInfo[_index]->SystemStatus != S_CHARGING)
- {
- Ocpp_ProfileReq_Cmd(_index);
- _ocppProfileChkFlag[_index] = 0;
- }
- else
- {
- _ocppProfileChkFlag[_index]++;
- }
- }
- if (chargingInfo[_index]->SystemStatus >= SYS_MODE_CHARGING &&
- chargingInfo[_index]->SystemStatus <= SYS_MODE_ALARM)
- {
- DB_Update_LocalConsumption(localDb, _index, ShmChargerInfo->MeterValue[_index].LocalConsumption);
- if(ShmChargerInfo->MeterValue[_index].GunConsumption >= 0)
- {
- DB_Update_GunConsumption(localDb, _index, ShmChargerInfo->MeterValue[_index].GunConsumption);
- }
- }
- }
- CheckPsuLostQuantity();
- GetClockTime(&_cmdMainPriority_time);
- }
- CheckMiscCommandRequirement();
- CheckDispenserVersionUpdateRequirement();
- MCabinetParallelingProcess();
- SCabinetControllProcess();
- UpdateChargingCapability();
- GunErrorCollection();
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- //CheckGpioInStatus();
- CheckErrorOccurStatus(gun_index);
- ChkOcppStatus(gun_index);
- if((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[gun_index]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[gun_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun_index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if(chargingInfo[gun_index]->SystemStatus == S_CHARGING)
- {
- // 進充電後,如果輸出電壓落差大於 10V 則直接繼續看 ChargingProfile
- if (chargingInfo[gun_index]->PresentChargingVoltage >= gunOutputVol[gun_index] + 10 ||
- chargingInfo[gun_index]->PresentChargingVoltage <= gunOutputVol[gun_index] - 10)
- {
- _ocppProfileChkFlag[gun_index] = 12;
- gunOutputVol[gun_index] = chargingInfo[gun_index]->PresentChargingVoltage;
- }
- }
- }
- CheckSmartChargeProfile(gun_index);
- Update_PowerConsumption(gun_index);
- CheckInProgress(gun_index);
- CheckDebugMode(gun_index);
- //LOG_INFO("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
- switch(chargingInfo[gun_index]->SystemStatus)
- {
- case S_MAINTAIN:
- if(isModeChange(gun_index))
- {
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- LOG_INFO("================== Slave Cabinet %d ==================", ShmChargerInfo->Control.CabinetSwitch - 1);
- }
- LOG_INFO("================== S_MAINTAIN (%x) ================== \n", gun_index + 1);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_AVAILABILITY);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetSecTimeoutValue(_SystemStatus_Time[gun_index]);
- if(ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE ||
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE ||
- ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- break;
- }
- if(chargingInfo[gun_index]->IsAvailable == YES &&
- ShmChargerInfo->Control.GunAvailable[gun_index] == YES &&
- ShmChargerInfo->ParallelCabinet.ParallelStatus == _Parallel_None)
- {
- if(time >= MAINTAIN_RECOVERY_TIME)
- {
- Set_Connector_MiscCommand(gun_index, MISC_CONN_AVAILABILITY);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_RESERVATION:
- if(isModeChange(gun_index))
- {
- LOG_INFO("================== S_RESERVATION (%x) ================== \n", gun_index + 1);
- char expiryDate[128];
- Get_Ocpp_ReserveNowExpiryDate(gun_index, expiryDate);
- Get_Ocpp_ReserveNowIdTag(gun_index, &ShmChargerInfo->Control.ResevedIdTag[gun_index][0]);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_RESERVATION);
- LOG_INFO("****** Reservation IdTag: [%s], Expiry: [%s]", &ShmChargerInfo->Control.ResevedIdTag[gun_index][0], expiryDate);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- if(chargingInfo[gun_index]->ConnectorPlugIn)
- {
- SetAcContactor(ON);
- }
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Alarm ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- UpdateErrorCodeToOcpp(gun_index);
- setChargerMode(gun_index, MODE_FAULT);
- continue;
- }
- if(Is_Ocpp_ReserveNowExpired(gun_index))
- {
- chargingInfo[gun_index]->ReservationId = -1;
- LOG_INFO("Gun %d reservation is expired...", gun_index + 1);
- setChargerMode(gun_index, MODE_IDLE);
- }
- else
- {
- if(IsConnectorAuthorizeSuccess(gun_index))
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RemoteStart)
- {
- LOG_INFO("Gun %d remote start reserve charging", gun_index + 1);
- }
- else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RFID)
- {
- LOG_INFO("Gun %d swipe rfid start reserve charging", gun_index + 1);
- }
- setChargerMode(gun_index, MODE_AUTHORIZING);
- }
- else if(IsAutoGunSelectionAuthorizeSuccess(gun_index))
- {
- _dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex;
- if(Is_Ocpp_ReserveNowIdTag(gun_index, (char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthId))
- {
- SetAcContactor(ON);
- if(chargingInfo[gun_index]->ConnectorPlugIn &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Preparing)
- {
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthId);
- LOG_INFO("Gun %d reserve Auto Selection, CardNumber = %s", gun_index + 1, chargingInfo[gun_index]->StartUserId);
- if(strlen((char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[_dispenser][0]) > 0)
- {
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gun_index], (char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[_dispenser][0]);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_USER_PRICE_STRING);
- }
- DispenserAuthInitial(_dispenser);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- }
- }
- }
- else
- {
- if(chargingInfo[gun_index]->ReservationId == -1)
- {
- LOG_INFO("Gun %d reservation is clean", gun_index + 1);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- }
- break;
- case S_IDLE:
- case S_FAULT:
- {
- // clean PermissionRequest flag
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PermissionRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = true;
- if(isModeChange(gun_index))
- {
- if (chargingInfo[gun_index]->SystemStatus == S_IDLE)
- {
- LOG_INFO("================== S_IDLE (%x) ================== \n", gun_index + 1);
- chargingInfo[gun_index]->ReservationId = -1;
- _triggerTransaction[gun_index] = false;
- _plugInHold[gun_index] = false;
- chargingInfo[gun_index]->PresentChargedDuration = 0;
- chargingInfo[gun_index]->RemainChargingDuration = 0;
- strcpy((char *)chargingInfo[gun_index]->StartDateTime, "");
- strcpy((char *)chargingInfo[gun_index]->StopDateTime, "");
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
- memset(ShmChargerInfo->Timestamp[gun_index].StartCharging, 0x00, sizeof(ShmChargerInfo->Timestamp[gun_index].StartCharging));
- memset(ShmChargerInfo->Timestamp[gun_index].StopCharging, 0x00, sizeof(ShmChargerInfo->Timestamp[gun_index].StopCharging));
- Clean_Ocpp_StopReason(gun_index);
- ReleaseAlarmCode(gun_index);
- // clean connector information
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingVoltage = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingCurrent = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteRemainChargingDuration = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteSoc = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].UserPrice = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].TotalCost = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AccountBalance = -65535;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].CostDiscount = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemainAmount = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].EnergyCost = -1;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParkingFee = -1;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.AnnounceBalance = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.GetStartChargingSoc = false;
- memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.StartWaitPlug = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.OutputLimitEnable = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].GeneralChargingData.deratingByConnOtp.deratingIndex = 0;
- chargingInfo[gun_index]->EvBatterytargetVoltage = 0;
- chargingInfo[gun_index]->EvBatterytargetCurrent = 0;
- chargingInfo[gun_index]->EvBatteryMaxVoltage = 0;
- chargingInfo[gun_index]->EvBatterySoc = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteTargetVoltage = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteTargetCurrent = 0;
- // clean RemoteStart & RemoteStop flag
- Clean_Connector_MiscCommand(gun_index, MISC_CONN_REMOTE_START);
- Clean_Connector_MiscCommand(gun_index, MISC_CONN_REMOTE_STOP);
- Clean_Connector_MiscCommand(gun_index, MISC_CONN_UNLOCK);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStartConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStopConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.UnlockStopConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NormalStopRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.AlarmStopRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest = false;
- ShmChargerInfo->GunError[gun_index].ErrFlag.ErrorValue = 0;
- memset(chargingInfo[gun_index]->ConnectorAlarmCode, 0x00, sizeof(chargingInfo[gun_index]->ConnectorAlarmCode));
- Clean_Ocpp_RunningCost(gun_index);
- Clean_Ocpp_FinalCost(gun_index);
- Clean_DeductInfo(gun_index);
- Clean_Ocpp_TcciSerialNo(gun_index);
- Clean_UserTransaction(gun_index);
- Clean_UserPriceAndReceipt(gun_index);
- presentChargedEnergyClear(gun_index);
- chargingInfo[gun_index]->PresentChargingPower = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent = 0;
- chargingInfo[gun_index]->ChargingProfilePower = -1;
- chargingInfo[gun_index]->ChargingProfileCurrent = -1;
- if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.WebApiTrigger)
- {
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging = false;
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.WebApiTrigger = false;
- // reset dispenser availability
- Update_DispenserAvailability(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex);
- }
- // clean force charging info
- memset(&ShmChargerInfo->Control.FCharging[gun_index], 0x00, sizeof(ForceCharging));
- }
- else if (chargingInfo[gun_index]->SystemStatus == S_FAULT)
- {
- LOG_INFO("================== S_FAULT (%x) ================== \n", gun_index + 1);
- }
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- if (chargingInfo[gun_index]->IsAvailable == NO ||
- ShmChargerInfo->Control.GunAvailable[gun_index] == NO)
- {
- setChargerMode(gun_index, MODE_MAINTAIN);
- continue;
- }
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Alarm ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest)
- {
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemotenAlarmCode, 6);
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest = false;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, "042304", 6);
- LOG_INFO("Connector %d Disconnect Occur", gun_index + 1);
- }
- }
- if(chargingInfo[gun_index]->SystemStatus != S_FAULT)
- {
- UpdateErrorCodeToOcpp(gun_index);
- setChargerMode(gun_index, MODE_FAULT);
- }
- else
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- CheckConnectorDisconnectionRecovery(gun_index);
- }
- }
- }
- else
- {
- if (chargingInfo[gun_index]->SystemStatus == S_FAULT)
- {
- time = GetSecTimeoutValue(_SystemStatus_Time[gun_index]);
- if(time >= FAULT_RELEASE_TIME)
- {
- ReleaseAlarmCode(gun_index);
- setChargerMode(gun_index, MODE_IDLE);
- }
- break;
- }
- // clean stop charge flag
- chargingInfo[gun_index]->StopChargeFlag = false;
- chargingInfo[gun_index]->ChargingStopFlag.ChargingStopValue = 0;
- if(chargingInfo[gun_index]->ConnectorPlugIn || ShmChargerInfo->Control.CustomizedInfo.Flag.bits.StandbyTimeDisable)
- {
- SetAcContactor(ON);
- }
- { // Idle 正常程序起點
- // 判斷是否有啟用檢查插槍
- if(IsConnectorAuthorizeSuccess(gun_index))
- {
- if(chargingInfo[gun_index]->IsAvailable &&
- chargingInfo[gun_index]->SystemStatus == S_IDLE)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RemoteStart)
- {
- LOG_INFO("Gun %d remote start charging", gun_index + 1);
- Clean_Ocpp_TcciCreditInfo(gun_index);
- }
- else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RFID)
- {
- LOG_INFO("Gun %d swipe rfid start charging", gun_index + 1);
- }
- Set_StartIdType(gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthIdType);
- setChargerMode(gun_index, MODE_AUTHORIZING);
- continue;
- }
- }
- else if(IsAutoGunSelectionAuthorizeSuccess(gun_index))
- {
- SetAcContactor(ON);
- if(chargingInfo[gun_index]->IsAvailable &&
- chargingInfo[gun_index]->SystemStatus == S_IDLE &&
- chargingInfo[gun_index]->ConnectorPlugIn &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Preparing)
- {
- _dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex;
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthId);
- LOG_INFO("Gun %d Auto Selection, CardNumber = %s", gun_index + 1, chargingInfo[gun_index]->StartUserId);
- if(strlen((char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[_dispenser][0]) > 0)
- {
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gun_index], (char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[_dispenser][0]);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_USER_PRICE_STRING);
- }
- Set_StartIdType(gun_index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthIdType);
- DispenserAuthInitial(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- continue;
- }
- }
- // only for test & debug purpose
- else if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging &&
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.StartForceCharging)
- {
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.StartForceCharging = false;
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "ChargingTest");
- LOG_INFO("Gun %d Start Force Charging%s",
- gun_index + 1,
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.WebApiTrigger > 0 ? ", Triggered by WebAPI" : "");
- if(ShmChargerInfo->Control.TestCtrl.bits.FChargingReleaseExtend)
- {
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableReleaseAndExtend = true;
- LOG_INFO("Gun %d Enable ReleaseAndExtend At Force Charging", gun_index + 1);
- }
- if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.WebApiTrigger)
- {
- LOG_INFO("Set Dispenser %d Inoperative",
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex + 1);
- Update_DispenserAvailability(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex);
- }
- Set_StartIdType(gun_index, _Type_Local);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- continue;
- }
- else
- {
- }
- } // Idle 正常程序終點
- }
- }
- break;
- case S_AUTHORIZING:
- if(isModeChange(gun_index))
- {
- LOG_INFO("================== S_AUTHORIZING (%x) ================== \n", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- //StopSystemTimeoutDet();
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo = false;
- SetAcContactor(ON);
- GetClockTime(&_ConnectorAuthorizing_Time[gun_index]);
- }
- if(!_triggerTransaction[gun_index] &&
- ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RemoteStart)
- {
- if(GetTimeoutValue(_ConnectorAuthorizing_Time[gun_index]) / uSEC_VAL >= STARTTRANSATION_TIME)
- {
- OcppStartTransaction(gun_index);
- }
- }
- if(GetTimeoutValue(_ConnectorAuthorizing_Time[gun_index]) / uSEC_VAL >= FORCE_BALANCE_TIME)
- {
- FouceAnnounceAccountBalance(gun_index);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStartConfirm)
- {
- // sync with dispenser
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStartConfirm = false;
- GetClockTime(&_ConnectorAuthorizing_Time[gun_index]);
- LOG_INFO("Sync with Gun %d through remote start", gun_index + 1);
- FouceAnnounceAccountBalance(gun_index);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.SwipeRfidConfirm)
- {
- // sync with dispenser
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.SwipeRfidConfirm = false;
- GetClockTime(&_ConnectorAuthorizing_Time[gun_index]);
- LOG_INFO("Sync with Connector %d through swipe rfid", gun_index + 1);
- }
- if(GetTimeoutValue(_ConnectorAuthorizing_Time[gun_index]) / uSEC_VAL >= ShmChargerInfo->CabinetMiscValue.ConnectionTimeout)
- {
- if(!chargingInfo[gun_index]->ConnectorPlugIn)
- {
- LOG_INFO("*********** Gun %d Plug In Timeout ***********", gun_index + 1);
- }
- else
- {
- LOG_INFO("*********** Gun %d Preparing State Timeout ***********", gun_index + 1);
- }
- OcppStopTransaction(gun_index);
- setChargerMode(gun_index, MODE_IDLE);
- }
- else
- {
- if(chargingInfo[gun_index]->ConnectorPlugIn &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Preparing)
- {
- AddPlugInTimes(gun_index);
- LOG_INFO("Gun %d CardNumber = [%s]", gun_index + 1, chargingInfo[gun_index]->StartUserId);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- GunAuthInitial(gun_index);
- }
- else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.StartWaitPlug = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo = false;
- LOG_INFO("*********** Gun %d User Stop Plug In ***********", gun_index + 1);
- OcppStopTransaction(gun_index);
- setChargerMode(gun_index, MODE_IDLE);
- }
- else if(isEvBoardStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Alarm Stop (S_AUTHORIZING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_AUTHORIZING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_REASSIGN_CHECK:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_REASSIGN_CHECK (%x) ================== \n", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- //StopSystemTimeoutDet();
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputEnergy = ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputDuration = ShmSysConfigAndInfo->SysConfig.MaxChargingDuration;
- LOG_INFO("Max Total Current %d A, Max Total Power %d kW, Total Energy %d kWh, Total Duration %d",
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent,
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputEnergy,
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputDuration);
- SetAcContactor(ON);
- SetPCabinetOutputRelay(gun_index, ON);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if(ConnectorRequestToCharging(gun_index))
- {
- setChargerMode(gun_index, MODE_REASSIGN);
- }
- else if(time >= WAIT_REASSIGN_TIME)
- {
- if(ShmPsuData->Work_Step != _WORK_CHARGING)
- {
- LOG_INFO("Gun %d Wait PSU Work Step Timeout", gun_index + 1);
- }
- else
- {
- LOG_INFO("Gun %d Request Charging Timeout", gun_index + 1);
- }
- ShmChargerInfo->GunError[gun_index].ErrFlag.bits.PsuGroupNoResource = true;
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, "042279", 6);
- LOG_INFO("Gun %d No Psu Resource", gun_index + 1);
- }
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- //setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_REASSIGN:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_REASSIGN (%x) ================== \n", gun_index + 1);
- //gettimeofday(&_toAverage_time, NULL);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if(IsConnectorGroupingCompleted(gun_index))
- {
- setChargerMode(gun_index, MODE_PRECHARGE);
- }
- else if(time >= MAX_REQUEST_CHARGING_TIME)
- {
- LOG_INFO("Gun %d Grouping Timeout", gun_index + 1);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_PREPARNING:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_PREPARNING (%x) ================== \n", gun_index + 1);
- //StopGunInfoTimeoutDet(gun_index);
- //StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
- SetAcContactor(ON);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- UpdateGunPresentChargingPower(gun_index);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if ((chargingInfo[gun_index]->AvailableChargingPower > 10) && time >= MIN_WAIT_PREPARNING_TIME)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
- break;;
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端或後臺要求停止
- LOG_INFO("********** Gun %d Alarm Stop (S_PREPARNING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_PREPARNING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_PREPARNING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- else if(isBackendStopFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Stop (S_PREPARNING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Other");
- ChargingTerminalProcess(gun_index);
- }
- if(time > GUN_PREPARE_TIMEOUT)
- {
- LOG_INFO("********** Gun %d PrepareTimeout **********", gun_index + 1);
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, "012279", 6);
- LOG_INFO("Gun %d No Psu Resource", gun_index + 1);
- }
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- }
- break;
- case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_PREPARING_FOR_EV (%x) ================== \n", gun_index + 1);
- //strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- //StopGunInfoTimeoutDet(gun_index);
- //StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- UpdateGunPresentChargingPower(gun_index);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PermissionRequest)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- // only for test & debug purpose
- else if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- LOG_INFO("Gun %d [Force Charging] S_PREPARING_FOR_EV OK", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PermissionRequest = true;
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端或後臺要求停止
- LOG_INFO("********** Gun %d Alarm Stop (S_PREPARING_FOR_EV) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_PREPARING_FOR_EV) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_PREPARING_FOR_EV) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- else if(isBackendStopFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Stop (S_PREPARING_FOR_EV) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Other");
- ChargingTerminalProcess(gun_index);
- }
- if(time >= GUN_EV_WAIT_TIMEOUT)
- {
- LOG_INFO("********** Gun %d Wait Dispenser Timeout **********", gun_index + 1);
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_PREPARING_FOR_EVSE: // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_PREPARING_FOR_EVSE (%x) ================== \n", gun_index + 1);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- #ifdef STARTTRANSATION_IMMEDIATELY
- OcppStartTransaction(gun_index);
- #endif
- }
- CheckoutStartChargingSoc(gun_index, NO);
- UpdateGunPresentChargingPower(gun_index);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- // only for test & debug purpose
- if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- if(time >= FORCE_CHARGING_CMD_DELAY)
- {
- float voltage = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetVoltage / 10;
- float current = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetCurrent / 10;
- if(chargingInfo[gun_index]->EvBatterytargetVoltage != voltage || chargingInfo[gun_index]->EvBatterytargetCurrent != current)
- {
- LOG_INFO("Gun %d Set Force Charging Voltage %4d V, Current: %4d A", gun_index + 1, (int)voltage, (int)current);
- }
- chargingInfo[gun_index]->EvBatterytargetVoltage = voltage;
- chargingInfo[gun_index]->EvBatterytargetCurrent = current;
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Charging)
- {
- setChargerMode(gun_index, MODE_CHARGING);
- }
- // only for test & debug purpose
- else if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- if(time >= FORCE_CHARGING_WAIT_EVSE)
- {
- LOG_INFO("Gun %d [Charging Simulation] S_PREPARING_FOR_EVSE OK", gun_index + 1);
- setChargerMode(gun_index, MODE_CHARGING);
- }
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端或後臺要求停止
- LOG_INFO("********** Gun %d Alarm Stop (S_PREPARING_FOR_EVSE) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_PREPARING_FOR_EVSE) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_PREPARING_FOR_EVSE) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- else if(isInvalidIdStopFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d InvalidId Stop (S_PREPARING_FOR_EVSE) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "DeAuthorized");
- ChargingTerminalProcess(gun_index);
- }
- else if(isBackendStopFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Stop (S_PREPARING_FOR_EVSE) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Other");
- ChargingTerminalProcess(gun_index);
- }
- if(time >= GUN_EV_WAIT_TIMEOUT)
- {
- LOG_INFO("********** Gun %d GFD timeout **********", gun_index + 1);
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_CHARGING (%x) ================== \n", gun_index + 1);
- //StopGunInfoTimeoutDet(gun_index);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- GetClockTime(&_ChargedEnergy_Time[gun_index]);
- CheckoutStartChargingSoc(gun_index, YES);
- chargingInfo[gun_index]->PresentChargedDuration = 0;
- ChangeStartOrStopDateTime(YES, gun_index);
- #ifndef STARTTRANSATION_IMMEDIATELY
- OcppStartTransaction(gun_index);
- #endif
- }
- // only for test & debug purpose
- if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- float voltage = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetVoltage / 10;
- float current = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetCurrent / 10;
- if(chargingInfo[gun_index]->EvBatterytargetVoltage != voltage || chargingInfo[gun_index]->EvBatterytargetCurrent != current)
- {
- LOG_INFO("Gun %d Set Force Charging Voltage %4d V, Current: %4d A", gun_index + 1, (int)voltage, (int)current);
- }
- chargingInfo[gun_index]->EvBatterytargetVoltage = voltage;
- chargingInfo[gun_index]->EvBatterytargetCurrent = current;
- }
- // 計算 Power
- //chargingInfo[gun_index]->PresentChargingPower = ((float)((chargingInfo[gun_index]->PresentChargingVoltage) * (chargingInfo[gun_index]->PresentChargingCurrent)) / 1000);
- //chargingInfo[gun_index]->PresentChargingPower = (((float)((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingVoltage) * (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingCurrent))) / 1000 / 100);
- UpdateGunPresentChargingPower(gun_index);
- ChargedEnergySummation(gun_index);
- CheckSessionTargetStop(gun_index);
- if (isEvBoardStopChargeFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Alarm Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_CHARGING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_CHARGING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- else if(isInvalidIdStopFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d InvalidId Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "DeAuthorized");
- ChargingTerminalProcess(gun_index);
- }
- else if(CheckBackendChargingTimeout(gun_index) ||
- CheckBackendChargingEnergy(gun_index) ||
- IsReachConfigMaxChargingSoc(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Condition Stop (S_CHARGING) **********", gun_index + 1);
- ChargingTerminalProcess(gun_index);
- }
- else if(isSessionTargetStopFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d SessionTarget Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Other");
- ChargingTerminalProcess(gun_index);
- }
- else if(isBackendStopFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Other");
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_ALARM:
- case S_TERMINATING:
- {
- if (isModeChange(gun_index))
- {
- Set_Ocpp_StopReason(gun_index, "Other");
- if (chargingInfo[gun_index]->SystemStatus == S_ALARM)
- {
- LOG_INFO("================== S_ALARM (%x) ================== \n", gun_index + 1);
- UpdateErrorCodeToOcpp(gun_index);
- TheEndCharging(gun_index);
- }
- else
- {
- LOG_INFO("================== S_TERMINATING (%x) ================== \n", gun_index + 1);
- }
- //StopGunInfoTimeoutDet(gun_index);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- UpdateGunPresentChargingPower(gun_index);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if((Is_DispenserStop(gun_index) && time >= STOP_TARTTRANSATION_DELAY) ||
- time >= WAIT_DISPENSER_STOP_TIMEOUT)
- {
- OcppStopTransaction(gun_index);
- }
- else
- {
- ChargedEnergySummation(gun_index);
- }
- if (chargingInfo[gun_index]->SystemStatus == S_ALARM)
- {
- if(time >= GUN_COMP_WAIT_TIMEOUT)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- LOG_INFO ("********** Gun %d psu is releasable **********\n", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = true;
- }
- }
- if(IsAvailableBackToIdle(gun_index) == YES &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- ReleaseAlarmCode(gun_index);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- else
- {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- }
- break;
- case S_COMPLETE:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_COMPLETE (%x) ================== \n", gun_index + 1);
- TheEndCharging(gun_index);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- UpdateGunPresentChargingPower(gun_index);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if((Is_DispenserStop(gun_index) && time >= STOP_TARTTRANSATION_DELAY) ||
- time >= WAIT_DISPENSER_STOP_TIMEOUT)
- {
- OcppStopTransaction(gun_index);
- }
- else
- {
- ChargedEnergySummation(gun_index);
- }
- if(time >= GUN_COMP_WAIT_TIMEOUT)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- LOG_INFO ("********** Gun %d psu is releasable **********", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = true;
- }
- }
- if(IsAvailableBackToIdle(gun_index) == YES &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_CCS_PRECHARGE_ST0:
- if (isModeChange(gun_index))
- {
- LOG_INFO("CCS Precharge Processing 1....................%x \n", gun_index);
- //StopGunInfoTimeoutDet(gun_index);
- //StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
- }
- break;
- case S_CCS_PRECHARGE_ST1:
- if (isModeChange(gun_index))
- {
- LOG_INFO("CCS Precharge Processing 2....................%x \n", gun_index);
- }
- break;
- case S_DEBUG:
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_DEBUG (%x) ================== \n", gun_index + 1);
- }
- if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay &&
- !ShmChargerInfo->Control.FanCtrl.bits.AbnormalFan)
- {
- setChargerMode(gun_index, MODE_IDLE);
- }
- break;
- }
- }
- TryFeedWatchdog();
- usleep(whileLoopTime);
- }
- return FAIL;
- }
|