main.c 294 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <sys/time.h>
  4. #include <sys/timeb.h>
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <sys/ipc.h>
  9. #include <sys/shm.h>
  10. #include <sys/mman.h>
  11. #include <linux/wireless.h>
  12. #include <arpa/inet.h>
  13. #include <netinet/in.h>
  14. #include <unistd.h>
  15. #include <stdarg.h>
  16. #include <stdio.h> /*標準輸入輸出定義*/
  17. #include <stdlib.h> /*標準函數庫定義*/
  18. #include <unistd.h> /*Unix 標準函數定義*/
  19. #include <fcntl.h> /*檔控制定義*/
  20. #include <termios.h> /*PPSIX 終端控制定義*/
  21. #include <errno.h> /*錯誤號定義*/
  22. #include <errno.h>
  23. #include <string.h>
  24. #include <stdint.h>
  25. #include <time.h>
  26. #include <ctype.h>
  27. #include <ifaddrs.h>
  28. #include <math.h>
  29. #include "./Define/define.h"
  30. #include <stdbool.h>
  31. #include <dirent.h>
  32. #include "Config.h"
  33. #include "main.h"
  34. #include "common.h"
  35. #include "timeout.h"
  36. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  37. #include "./SelectGun/SelectGun.h"
  38. #endif //defined DD360Audi
  39. //------------------------------------------------------------------------------
  40. char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
  41. uint8_t mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
  42. int whileLoopTime = 10000; // 10 ms
  43. int wtdFd = -1;
  44. uint8_t _authorizeIndex = NO_DEFINE;
  45. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  46. struct StatusCodeData *ShmStatusCodeData;
  47. struct PsuData *ShmPsuData;
  48. struct CHAdeMOData *ShmCHAdeMOData;
  49. struct GBTData *ShmGBTData;
  50. struct CcsData *ShmCcsData;
  51. struct PrimaryMcuData *ShmPrimaryMcuData;
  52. struct FanModuleData *ShmFanModuleData;
  53. struct RelayModuleData *ShmRelayModuleData;
  54. struct LedModuleData *ShmLedModuleData;
  55. struct OCPP16Data *ShmOCPP16Data;
  56. DcCommonInfo *ShmDcCommonData;
  57. struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  58. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  59. struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  60. struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  61. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  62. static SelectGunInfo *gAudiCustInfo = NULL; //Jerry add
  63. #endif //defined DD360Audi
  64. // for initial index to check EV board type is correct
  65. uint8_t _gunIndex = 0;
  66. uint8_t _acgunIndex = 0;
  67. uint8_t _chademoIndex = 0;
  68. uint8_t _ccsIndex = 0;
  69. uint8_t _gb_Index = 0;
  70. uint8_t _ac_Index = 0;
  71. uint8_t bd0_1_status = 0;
  72. uint8_t bd0_2_status = 0;
  73. uint8_t bd1_1_status = 0;
  74. uint8_t bd1_2_status = 0;
  75. static uint8_t restartFlag = 0;
  76. bool isCardScan = false;
  77. bool isModelNameMatch = true;
  78. int rfidFd = -1;
  79. char *rfidPortName = "/dev/ttyS2";
  80. char *fwVersion = "V1.08.00.0000.00"; // "V0.16.00.0000.00";
  81. sqlite3 *localDb;
  82. bool isDb_ready;
  83. EvBoardErrMsg gEvBoardErr = {0};
  84. //------------------------------------------------------------------------------
  85. bool IsAuthorizingMode();
  86. void ClearAuthorizedFlag();
  87. bool isDetectPlugin();
  88. void ClearDetectPluginFlag();
  89. long long DiffTimebWithNow(struct timeb ST);
  90. uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
  91. void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
  92. void ChargingTerminalProcess(uint8_t gunIndex);
  93. void ChkPrimaryStatus();
  94. void StartSystemTimeoutDet(uint8_t flag);
  95. void StopSystemTimeoutDet();
  96. void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag);
  97. void StopGunInfoTimeoutDet(uint8_t gunIndex);
  98. int StoreLogMsg_1(const char *fmt, ...);
  99. unsigned long GetTimeoutValue(struct timeval _sour_time);
  100. void gpio_set_value(unsigned int gpio, unsigned int value);
  101. void ChangeGunSelectByIndex(uint8_t sel);
  102. void InformOcppErrOccur(uint8_t codeType);
  103. void RecordAlarmCode(uint8_t gunIndex, char *code);
  104. void RecordWarningCode(uint8_t gunIndex, char *code);
  105. void ReleaseWarningCodeByString(uint8_t gunIndex, char *code);
  106. void ReleaseAlarmCode(uint8_t gunIndex);
  107. void ResetChargerAlarmCode(uint8_t gunIndex, char *code);
  108. int DB_Open(sqlite3 *db);
  109. int DB_Insert_Record(sqlite3 *db, int gun_index);
  110. int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
  111. int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
  112. //------------------------------------------------------------------------------
  113. //--- share memory value ---
  114. //------------------------------------------------------------------------------
  115. static void changeLcmPage(uint8_t index)
  116. {
  117. ShmSysConfigAndInfo->SysInfo.SystemPage = index;
  118. }
  119. static uint8_t getCurLcmPage(void)
  120. {
  121. return ShmSysConfigAndInfo->SysInfo.SystemPage;
  122. }
  123. //------------------------------------------------------------------------------
  124. static void destroySelGun(uint8_t curGun)
  125. {
  126. uint8_t i = 0;
  127. uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
  128. #if !defined DD360Audi
  129. return;
  130. #endif //!defined DD360Audi
  131. //for status timeout
  132. if (curGun == DESTROY_ALL_SEL) {
  133. gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
  134. gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
  135. log_info("destroy all gun = %d, %d\r\n",
  136. gAudiCustInfo->SelGunInfo.LeftGun,
  137. gAudiCustInfo->SelGunInfo.RightGun);
  138. for (i = 0; i < totalGun; i++) {
  139. StopGunInfoTimeoutDet(i);
  140. memset(&gAudiCustInfo->PricesInfo[i], 0, sizeof(PricesInfo));
  141. }
  142. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  143. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  144. //changeLcmPage(_LCM_SELECT_GUN);
  145. return;
  146. }
  147. //for charging timeout or complete
  148. if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
  149. if (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
  150. gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
  151. changeLcmPage(_LCM_SELECT_GUN);
  152. }
  153. gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
  154. StopGunInfoTimeoutDet(LEFT_GUN_NUM);
  155. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
  156. ClearAuthorizedFlag();
  157. }
  158. log_info("destroy left gun, cur page = %d\r\n", getCurLcmPage());
  159. if (getCurLcmPage() == ShmSysConfigAndInfo->SysInfo.SystemPage) {
  160. log_info("clear left balance\r\n");
  161. memset(&gAudiCustInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
  162. gAudiCustInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
  163. }
  164. }
  165. if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
  166. if (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
  167. gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
  168. changeLcmPage(_LCM_SELECT_GUN);
  169. }
  170. gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
  171. StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
  172. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
  173. ClearAuthorizedFlag();
  174. }
  175. log_info("destroy right gun, cur page = %d\r\n", getCurLcmPage());
  176. if (getCurLcmPage() == ShmSysConfigAndInfo->SysInfo.SystemPage) {
  177. log_info("clear right balance\r\n");
  178. memset(&gAudiCustInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
  179. gAudiCustInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
  180. }
  181. }
  182. }
  183. static int waitRightGunPlugIt(uint8_t curGun)
  184. {
  185. #if !defined DD360Audi
  186. return;
  187. #endif //!defined DD360Audi
  188. if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
  189. return PASS;
  190. }
  191. return FAIL;
  192. }
  193. static int waitLeftGunPlugIt(uint8_t curGun)
  194. {
  195. #if !defined DD360Audi
  196. return;
  197. #endif //!defined DD360Audi
  198. if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
  199. return PASS;
  200. }
  201. return FAIL;
  202. }
  203. static void setSelGunWaitToAuthor(uint8_t curSel)
  204. {
  205. #if !defined DD360Audi
  206. return;
  207. #endif //!defined DD360Audi
  208. if (curSel == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
  209. gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
  210. //printf("setSelGunWaitToAuthor left\r\n");
  211. StopGunInfoTimeoutDet(curSel);
  212. } else if (curSel == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
  213. gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
  214. //printf("setSelGunWaitToAuthor right\r\n");
  215. StopGunInfoTimeoutDet(curSel);
  216. }
  217. }
  218. static int getConfirmSelectedGun(uint8_t curSel)
  219. {
  220. #if !defined DD360Audi
  221. return;
  222. #endif //!defined DD360Audi
  223. if (((curSel == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
  224. ((curSel == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
  225. return PASS;
  226. }
  227. return FAIL;
  228. }
  229. static void confirmSelGun(uint8_t selGun)
  230. {
  231. #if !defined DD360Audi
  232. return;
  233. #endif //!defined DD360Audi
  234. if (selGun == LEFT_GUN_NUM) {
  235. gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
  236. StopGunInfoTimeoutDet(selGun);
  237. //printf("confirmSelGun left\r\n");
  238. } else if (selGun == RIGHT_GUN_NUM) {
  239. gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
  240. StopGunInfoTimeoutDet(selGun);
  241. //printf("confirmSelGun right\r\n");
  242. }
  243. changeLcmPage(_LCM_IDLE);
  244. StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
  245. }
  246. static void checkGunOTPState(uint8_t _index)
  247. {
  248. switch (chargingInfo[_index]->Type) {
  249. case _Type_Chademo:
  250. if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
  251. if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
  252. RecordAlarmCode(_index, "012229");
  253. } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
  254. chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY) {
  255. ResetChargerAlarmCode(_index, "012229");
  256. }
  257. } else {
  258. // 沒接上 Sensor or 異常
  259. //RecordAlarmCode(_index, "011018");
  260. ResetChargerAlarmCode(_index, "012229");
  261. }
  262. break;
  263. case _Type_CCS_2:
  264. // CCS 不管甚麼輸出都會有槍溫偵測!!~
  265. if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
  266. ResetChargerAlarmCode(_index, "011019");
  267. if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
  268. RecordAlarmCode(_index, "012230");
  269. } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
  270. chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY) {
  271. ResetChargerAlarmCode(_index, "012230");
  272. }
  273. //ResetChargerAlarmCode(_index, "011019");
  274. } else {
  275. // 沒接上 Sensor or 異常
  276. RecordAlarmCode(_index, "011019");
  277. ResetChargerAlarmCode(_index, "012230");
  278. }
  279. break;
  280. case _Type_GB:
  281. if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP) {
  282. if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE) {
  283. RecordAlarmCode(_index, "012231");
  284. } else if (chargingInfo[_index]->ConnectorTemp != 0 &&
  285. chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY) {
  286. ResetChargerAlarmCode(_index, "012231");
  287. }
  288. } else {
  289. // 沒接上 Sensor or 異常
  290. RecordAlarmCode(_index, "011020");
  291. ResetChargerAlarmCode(_index, "012231");
  292. }
  293. break;
  294. }
  295. }
  296. static void collectError(uint8_t gunIndex)
  297. {
  298. gEvBoardErr.GunErrMessage |= ShmDcCommonData->ConnectErrList[gunIndex].GunErrMessage;
  299. }
  300. static void checkGBTAlarmState(uint8_t gunType)
  301. {
  302. // GFD Trip
  303. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  304. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES;
  305. } else {
  306. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO;
  307. }
  308. // UVP
  309. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  310. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES;
  311. } else {
  312. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO;
  313. }
  314. // OTP
  315. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  316. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = YES;
  317. } else {
  318. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = NO;
  319. }
  320. // OVP
  321. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  322. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = YES;
  323. } else {
  324. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
  325. }
  326. // GFD Warning
  327. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  328. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES;
  329. } else {
  330. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO;
  331. }
  332. // Relay Welding
  333. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  334. ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
  335. } else {
  336. ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = NO;
  337. }
  338. // Relay Driving
  339. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  340. ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
  341. } else {
  342. ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = NO;
  343. }
  344. // Connect temp Sensor broken
  345. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  346. ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = YES;
  347. } else {
  348. ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = NO;
  349. }
  350. }
  351. static void checkCCSAlarmState(uint8_t gunType)
  352. {
  353. // GFD Trip
  354. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  355. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
  356. } else {
  357. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
  358. }
  359. // UVP
  360. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  361. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES;
  362. } else {
  363. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO;
  364. }
  365. // OTP
  366. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  367. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = YES;
  368. } else {
  369. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = NO;
  370. }
  371. // OVP
  372. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  373. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = YES;
  374. } else {
  375. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
  376. }
  377. // GFD Warning
  378. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  379. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES;
  380. } else {
  381. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO;
  382. }
  383. // Relay Welding
  384. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  385. ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
  386. } else {
  387. ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = NO;
  388. }
  389. // Relay Driving
  390. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  391. ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
  392. } else {
  393. ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
  394. }
  395. // Connect temp Sensor broken
  396. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  397. ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = YES;
  398. } else {
  399. ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = NO;
  400. }
  401. }
  402. static void checkChaDeMoAlarmState(uint8_t gunType)
  403. {
  404. // GFD Trip
  405. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
  406. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
  407. } else {
  408. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
  409. }
  410. // UVP
  411. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
  412. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES;
  413. } else {
  414. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO;
  415. }
  416. // OTP
  417. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
  418. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = YES;
  419. } else {
  420. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = NO;
  421. }
  422. // OVP
  423. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
  424. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = YES;
  425. } else {
  426. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
  427. }
  428. // GFD Warning
  429. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
  430. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES;
  431. } else {
  432. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO;
  433. }
  434. // Relay Welding
  435. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
  436. ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
  437. } else {
  438. ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = NO;
  439. }
  440. // Relay Driving
  441. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
  442. ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
  443. } else {
  444. ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
  445. }
  446. // Connect temp Sensor broken
  447. if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
  448. ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = YES;
  449. } else {
  450. ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = NO;
  451. }
  452. }
  453. static void checkEvBoardAlarmState(uint8_t gunType)
  454. {
  455. switch (gunType) {
  456. case _Type_Chademo:
  457. checkChaDeMoAlarmState(gunType);
  458. break;
  459. case _Type_CCS_2:
  460. checkCCSAlarmState(gunType);
  461. break;
  462. case _Type_GB:
  463. checkGBTAlarmState(gunType);
  464. break;
  465. }
  466. }
  467. static uint8_t checkCabinetEthConnectState(LedConfig *ledConfig)
  468. {
  469. uint8_t ret = NO;
  470. LedConfig *pLedConfig = (LedConfig *)ledConfig;
  471. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == YES) {
  472. ret = YES;
  473. if (pLedConfig->RedLED == YES) {
  474. pLedConfig->RedLED = NO;
  475. } else {
  476. pLedConfig->RedLED = YES;
  477. }
  478. }
  479. return ret;
  480. }
  481. static void startPrimaryLedIndicatorCtrlFork(void)
  482. {
  483. #if !defined DD360ComBox
  484. return;
  485. #endif //!defined DD360ComBox
  486. pid_t pid = fork();
  487. if (pid == 0) {
  488. uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
  489. uint8_t gunIndex = 0;
  490. int isContinue = 1;
  491. LedConfig *pLedConfig = (LedConfig *)&ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
  492. while (isContinue) {
  493. for (gunIndex = 0; gunIndex < totalGun; gunIndex++) {
  494. //printf("led indicator status = %d\r\n", chargingInfo[gunIndex]->SystemStatus);
  495. //printf("level = %d\r\n", ShmSysConfigAndInfo->SysWarningInfo.Level);
  496. switch (chargingInfo[gunIndex]->SystemStatus) {
  497. case S_BOOTING:
  498. if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE) {
  499. //Module_DoComm tcp disconnect
  500. if (pLedConfig->RedLED == YES ||
  501. pLedConfig->YellowLED == YES ||
  502. pLedConfig->GreenLED == YES) {
  503. pLedConfig->RedLED = NO;
  504. pLedConfig->YellowLED = NO;
  505. pLedConfig->GreenLED = NO;
  506. } else {
  507. pLedConfig->RedLED = YES;
  508. pLedConfig->YellowLED = YES;
  509. pLedConfig->GreenLED = YES;
  510. }
  511. break;
  512. }
  513. pLedConfig->RedLED = YES;
  514. pLedConfig->YellowLED = YES;
  515. pLedConfig->GreenLED = YES;
  516. break;
  517. case S_IDLE:
  518. //Module_DoComm connected and system idle
  519. pLedConfig->RedLED = NO;
  520. pLedConfig->YellowLED = NO;
  521. pLedConfig->GreenLED = YES;
  522. break;
  523. case S_RESERVATION:
  524. case S_AUTHORIZING:
  525. case S_REASSIGN_CHECK:
  526. case S_REASSIGN:
  527. case S_PREPARNING:
  528. case S_PREPARING_FOR_EV:
  529. case S_PREPARING_FOR_EVSE:
  530. case S_CCS_PRECHARGE_ST0:
  531. case S_CCS_PRECHARGE_ST1:
  532. //precharging status
  533. if (pLedConfig->GreenLED == YES) {
  534. pLedConfig->GreenLED = NO;
  535. } else {
  536. pLedConfig->GreenLED = YES;
  537. }
  538. break;
  539. case S_CHARGING:
  540. pLedConfig->RedLED = NO;
  541. if (pLedConfig->YellowLED == YES) {
  542. pLedConfig->YellowLED = NO;
  543. } else {
  544. pLedConfig->YellowLED = YES;
  545. }
  546. pLedConfig->GreenLED = NO;
  547. break;
  548. case S_ALARM:
  549. pLedConfig->YellowLED = NO;
  550. pLedConfig->GreenLED = NO;
  551. if (checkCabinetEthConnectState(pLedConfig) == YES) {
  552. break;
  553. }
  554. pLedConfig->RedLED = YES;
  555. break;
  556. case S_TERMINATING:
  557. case S_COMPLETE:
  558. if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
  559. pLedConfig->YellowLED = NO;
  560. pLedConfig->GreenLED = NO;
  561. if (checkCabinetEthConnectState(pLedConfig) == YES) {
  562. break;
  563. }
  564. pLedConfig->RedLED = YES;
  565. } else {
  566. pLedConfig->RedLED = NO;
  567. pLedConfig->YellowLED = YES;
  568. pLedConfig->GreenLED = NO;
  569. }
  570. break;
  571. case S_MAINTAIN:
  572. case S_FAULT:
  573. pLedConfig->YellowLED = NO;
  574. pLedConfig->GreenLED = NO;
  575. if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
  576. if (checkCabinetEthConnectState(pLedConfig) == YES) {
  577. break;
  578. }
  579. pLedConfig->RedLED = YES;
  580. }
  581. break;
  582. case S_BOOKING:
  583. case S_DEBUG:
  584. case S_UPDATE:
  585. case S_NONE:
  586. break;
  587. }
  588. usleep(500000);
  589. }//switch
  590. }//for
  591. }//while
  592. }
  593. //================================================
  594. // initial can-bus
  595. //================================================
  596. int InitCanBus()
  597. {
  598. int s0, nbytes;
  599. struct timeval tv;
  600. struct ifreq ifr0;
  601. struct sockaddr_can addr0;
  602. system("/sbin/ip link set can0 down");
  603. system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
  604. system("/sbin/ip link set can0 up");
  605. s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
  606. tv.tv_sec = 0;
  607. tv.tv_usec = 10000;
  608. if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) {
  609. #ifdef SystemLogMessage
  610. log_error("Set SO_RCVTIMEO NG");
  611. #endif
  612. }
  613. nbytes = 40960;
  614. if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0) {
  615. #ifdef SystemLogMessage
  616. log_error("Set SO_RCVBUF NG");
  617. #endif
  618. }
  619. nbytes = 40960;
  620. if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) {
  621. #ifdef SystemLogMessage
  622. log_error("Set SO_SNDBUF NG");
  623. #endif
  624. }
  625. strcpy(ifr0.ifr_name, "can0" );
  626. ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
  627. addr0.can_family = AF_CAN;
  628. addr0.can_ifindex = ifr0.ifr_ifindex;
  629. bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
  630. return s0;
  631. }
  632. //================================================
  633. // initial uart port
  634. //================================================
  635. char *_priPortName = "/dev/ttyS1";
  636. char *_485PortName = "/dev/ttyS5";
  637. int InitComPort(uint8_t target)
  638. {
  639. int fd;
  640. struct termios tios;
  641. if (target == UPGRADE_PRI) {
  642. fd = open(_priPortName, O_RDWR);
  643. } else if (target == UPGRADE_FAN || target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED) {
  644. fd = open(_485PortName, O_RDWR);
  645. }
  646. if (fd <= 0) {
  647. #ifdef SystemLogMessage
  648. log_error("open 407 Communication port NG \n");
  649. #endif
  650. return -1;
  651. }
  652. ioctl (fd, TCGETS, &tios);
  653. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  654. tios.c_lflag = 0;
  655. tios.c_iflag = 0;
  656. tios.c_oflag = 0;
  657. tios.c_cc[VMIN] = 0;
  658. tios.c_cc[VTIME] = (uint8_t)1;
  659. tios.c_lflag = 0;
  660. tcflush(fd, TCIFLUSH);
  661. ioctl (fd, TCSETS, &tios);
  662. return fd;
  663. }
  664. //=================================
  665. // Common routine
  666. //=================================
  667. int InitWatchDog()
  668. {
  669. int fd;
  670. system("/usr/bin/fuser -k /dev/watchdog");
  671. sleep(1);
  672. system("echo V > /dev/watchdog");
  673. sleep(1);
  674. fd = open("/dev/watchdog", O_RDWR);
  675. if (fd <= 0) {
  676. log_error("System watch dog initial fail.\r\n");
  677. }
  678. return fd;
  679. }
  680. int StoreLogMsg_1(const char *fmt, ...)
  681. {
  682. char Buf[4096 + 256];
  683. char buffer[4096];
  684. va_list args;
  685. struct timeb SeqEndTime;
  686. struct tm *tm;
  687. va_start(args, fmt);
  688. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  689. va_end(args);
  690. memset(Buf, 0, sizeof(Buf));
  691. ftime(&SeqEndTime);
  692. SeqEndTime.time = time(NULL);
  693. tm = localtime(&SeqEndTime.time);
  694. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
  695. sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
  696. tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
  697. printf("%s \n", Buf);
  698. } else {
  699. sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  700. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
  701. buffer,
  702. tm->tm_year + 1900, tm->tm_mon + 1);
  703. system(Buf);
  704. }
  705. return rc;
  706. }
  707. unsigned long GetTimeoutValue(struct timeval _sour_time)
  708. {
  709. struct timeval _end_time;
  710. gettimeofday(&_end_time, NULL);
  711. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  712. }
  713. int DiffTimeb(struct timeb ST, struct timeb ET)
  714. {
  715. //return milli-second
  716. unsigned int StartTime, StopTime;
  717. StartTime = (unsigned int)ST.time;
  718. StopTime = (unsigned int)ET.time;
  719. //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  720. return (StopTime - StartTime);
  721. }
  722. bool CheckTimeOut(struct timeb ST)
  723. {
  724. struct timeb ET;
  725. unsigned int StartTime, StopTime;
  726. ftime(&ET);
  727. StartTime = (unsigned int) ST.time;
  728. StopTime = (unsigned int) ET.time;
  729. return (StopTime > StartTime) ? YES : NO;
  730. }
  731. void setChargerMode(uint8_t gun_index, uint8_t mode)
  732. {
  733. chargingInfo[gun_index]->SystemStatus = mode;
  734. }
  735. long long DiffTimebWithNow(struct timeb ST)
  736. {
  737. //return milli-second
  738. struct timeb ET;
  739. long long StartTime, StopTime;
  740. ftime(&ET);
  741. StartTime = (long long)ST.time;
  742. StopTime = (long long)ET.time;
  743. return ((StopTime - StartTime) * 1000) + (ET.millitm - ST.millitm);
  744. }
  745. //==========================================
  746. // Log
  747. //==========================================
  748. void CheckFwSlotStatusLog()
  749. {
  750. if (bd0_1_status == 0 && bd0_2_status == 1) {
  751. log_info("Connector 1 : Chademo");
  752. } else if (bd0_1_status == 1 && bd0_2_status == 0) {
  753. log_info("Connector 1 : CCS");
  754. } else if (bd0_1_status == 1 && bd0_2_status == 1) {
  755. log_info("Connector 1 : GB");
  756. }
  757. if (bd1_1_status == 0 && bd1_2_status == 1) {
  758. log_info("Connector 2 : Chademo");
  759. } else if (bd1_1_status == 1 && bd1_2_status == 0) {
  760. log_info("Connector 2 : CCS");
  761. } else if (bd1_1_status == 1 && bd1_2_status == 1) {
  762. log_info("Connector 2 : GB");
  763. }
  764. }
  765. void CheckHwSlotStatusLog(uint8_t index)
  766. {
  767. if (chargingInfo[index]->Type == _Type_Chademo) {
  768. log_info("Hw check : Connector %d, Type : Chademo, Evboard_id = %d \n",
  769. index, chargingInfo[index]->Evboard_id);
  770. } else if (chargingInfo[index]->Type == _Type_CCS_2) {
  771. log_info("Hw check : Connector %d, Type : CCS, Evboard_id = %d \n",
  772. index, chargingInfo[index]->Evboard_id);
  773. } else if (chargingInfo[index]->Type == _Type_GB) {
  774. log_info("Hw check : Connector %d, Type : GB, Evboard_id = %d \n",
  775. index, chargingInfo[index]->Evboard_id);
  776. }
  777. }
  778. //==========================================
  779. // Check interface status
  780. //==========================================
  781. int isInterfaceUp(const char *interface)
  782. {
  783. int result = FAIL;
  784. FILE *fp;
  785. char cmd[256];
  786. char buf[512];
  787. strcpy(cmd, "ifconfig");
  788. fp = popen(cmd, "r");
  789. if (fp != NULL) {
  790. while (fgets(buf, sizeof(buf), fp) != NULL) {
  791. if (strstr(buf, interface) > 0) {
  792. result = PASS;
  793. }
  794. }
  795. }
  796. pclose(fp);
  797. return result;
  798. }
  799. //=================================
  800. // Create all share memory
  801. //=================================
  802. int CreateShareMemory()
  803. {
  804. uint8_t rebootCount = 0;
  805. int MeterSMId = FAIL;
  806. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0) {
  807. return FAIL;
  808. } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  809. return FAIL;
  810. }
  811. memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  812. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0) {
  813. return FAIL;
  814. } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  815. return FAIL;
  816. }
  817. memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
  818. //creat ShmPsuData
  819. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0) {
  820. return FAIL;
  821. } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  822. return FAIL;
  823. }
  824. memset(ShmPsuData, 0, sizeof(struct PsuData));
  825. if (CHAdeMO_QUANTITY > 0) {
  826. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0) {
  827. return FAIL;
  828. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  829. return FAIL;
  830. }
  831. memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
  832. }
  833. if (GB_QUANTITY > 0) {
  834. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0) {
  835. return FAIL;
  836. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  837. return FAIL;
  838. }
  839. memset(ShmGBTData, 0, sizeof(struct GBTData));
  840. }
  841. //creat ShmCcsData
  842. if (CCS_QUANTITY > 0) {
  843. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0) {
  844. return FAIL;
  845. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  846. return FAIL;
  847. }
  848. memset(ShmCcsData, 0, sizeof(struct CcsData));
  849. }
  850. //creat ShmPrimaryMcuData
  851. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0) {
  852. return FAIL;
  853. } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  854. return FAIL;
  855. }
  856. memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
  857. //creat ShmFanModuleData
  858. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0) {
  859. return FAIL;
  860. } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  861. return FAIL;
  862. }
  863. memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
  864. //creat ShmRelayModuleData
  865. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0) {
  866. return FAIL;
  867. } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  868. return FAIL;
  869. }
  870. memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
  871. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0) {
  872. return FAIL;
  873. } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  874. return FAIL;
  875. }
  876. memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
  877. //creat ShmOCPP16Data
  878. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0) {
  879. return FAIL;
  880. } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  881. return FAIL;
  882. }
  883. // memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
  884. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  885. //creat Audi customization info
  886. if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
  887. return FAIL;
  888. } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  889. return FAIL;
  890. }
  891. memset(gAudiCustInfo, 0, sizeof(SelectGunInfo));
  892. #endif //defined DD360Audi
  893. if ((MeterSMId = shmget(ShmCommonKey, sizeof(DcCommonInfo), IPC_CREAT | 0777)) < 0) {
  894. return FAIL;
  895. } else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  896. return FAIL;
  897. }
  898. if (ShmDcCommonData->RebootCount == 1) {
  899. rebootCount = ShmDcCommonData->RebootCount;
  900. }
  901. memset(ShmDcCommonData, 0, sizeof(DcCommonInfo));
  902. ShmDcCommonData->RebootCount = rebootCount;
  903. return PASS;
  904. }
  905. //=================================
  906. // LCM Page
  907. //=================================
  908. void ChangeLcmByIndex(uint8_t page_index)
  909. {
  910. if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
  911. page_index == _LCM_COMPLETE || page_index == _LCM_FIX) {
  912. ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
  913. }
  914. }
  915. //======================================================
  916. // Peripheral initial
  917. //======================================================
  918. void InitGPIO()
  919. {
  920. /*****************0~3, 4 bank, bank x 32+ num*********************/
  921. /***************************************************************/
  922. /*************** GPIO 0 ***************************************/
  923. /***************************************************************/
  924. /* GPMC_AD8 => GPIO0_22 *//*ID BD1_1*/
  925. system("echo 22 > /sys/class/gpio/export");
  926. system("echo \"in\" > /sys/class/gpio/gpio22/direction");
  927. /* GPMC_AD9 => GPIO0_23 *//*ID BD1_2*/
  928. system("echo 23 > /sys/class/gpio/export");
  929. system("echo \"in\" > /sys/class/gpio/gpio23/direction");
  930. /* GPMC_AD10 => GPIO0_26 *//*IO BD1_1*/
  931. system("echo 26 > /sys/class/gpio/export");
  932. system("echo \"out\" > /sys/class/gpio/gpio26/direction");
  933. system("echo 1 > /sys/class/gpio/gpio26/value");
  934. /* GPMC_AD11 => GPIO0_27 *//*IO BD1_2*/
  935. system("echo 27 > /sys/class/gpio/export");
  936. system("echo \"in\" > /sys/class/gpio/gpio27/direction");
  937. /* RMII1_REF_CLK => GPIO0_29 *//*USB 0 OCP detection*/
  938. system("echo 29 > /sys/class/gpio/export");
  939. system("echo \"in\" > /sys/class/gpio/gpio29/direction");
  940. /*XDMA_EVENT_INTR0 => GPIO0_19 *//*AM_RFID_RST*/
  941. system("echo 19 > /sys/class/gpio/export");
  942. system("echo \"out\" > /sys/class/gpio/gpio19/direction");
  943. system("echo 1 > /sys/class/gpio/gpio19/value");
  944. /*XDMA_EVENT_INTR1 => GPIO0_20 *//*AM_RFID_ICC*/
  945. system("echo 20 > /sys/class/gpio/export");
  946. system("echo \"in\" > /sys/class/gpio/gpio20/direction");
  947. /***************************************************************/
  948. /*************** GPIO 1 ***************************************/
  949. /***************************************************************/
  950. /* GPMC_AD12 => GPIO1_12 *//*ID BD2_1*/
  951. system("echo 44 > /sys/class/gpio/export");
  952. system("echo \"in\" > /sys/class/gpio/gpio44/direction");
  953. /* GPMC_AD13 => GPIO1_13 *//*ID BD2_2*/
  954. system("echo 45 > /sys/class/gpio/export");
  955. system("echo \"in\" > /sys/class/gpio/gpio45/direction");
  956. /* GPMC_AD14 => GPIO1_14 *//*IO BD2_1*/
  957. system("echo 46 > /sys/class/gpio/export");
  958. system("echo \"out\" > /sys/class/gpio/gpio46/direction");
  959. system("echo 0 > /sys/class/gpio/gpio46/value");
  960. /* GPMC_AD15 => GPIO1_15 *//*IO BD2_2*/
  961. system("echo 47 > /sys/class/gpio/export");
  962. system("echo \"in\" > /sys/class/gpio/gpio47/direction");
  963. /***************************************************************/
  964. /*************** GPIO 2 ***************************************/
  965. /***************************************************************/
  966. /*LCD_AC_BIAS_EN => GPIO2_25*//*RS-485 for module DE control*/
  967. system("echo 89 > /sys/class/gpio/export");
  968. system("echo \"out\" > /sys/class/gpio/gpio89/direction");
  969. system("echo 1 > /sys/class/gpio/gpio89/value");
  970. /*LCD_HSYNC => GPIO2_23*//*RS-485 for module RE control*/
  971. system("echo 87 > /sys/class/gpio/export");
  972. system("echo \"out\" > /sys/class/gpio/gpio87/direction");
  973. system("echo 0 > /sys/class/gpio/gpio87/value");
  974. /*LCD_PCLK => GPIO2_24*//*CCS communication board 1 proximity*/
  975. system("echo 88 > /sys/class/gpio/export");
  976. system("echo \"in\" > /sys/class/gpio/gpio88/direction");
  977. /*LCD_VSYNC => GPIO2_22*//*CCS communication board 2 proximity*/
  978. system("echo 86 > /sys/class/gpio/export");
  979. system("echo \"in\" > /sys/class/gpio/gpio86/direction");
  980. /***************************************************************/
  981. /*************** GPIO 3 ***************************************/
  982. /***************************************************************/
  983. /*MCASP0_FSX => GPIO3_15*//*Emergency Stop button detect*/
  984. system("echo 111 > /sys/class/gpio/export");
  985. system("echo \"in\" > /sys/class/gpio/gpio111/direction");
  986. /*MCASP0_ACLKR => GPIO3_18*//*USB1 OCP detect*/
  987. system("echo 114 > /sys/class/gpio/export");
  988. system("echo \"in\" > /sys/class/gpio/gpio114/direction");
  989. /*MCASP0_AHCLKR => GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
  990. system("echo 113 > /sys/class/gpio/export");
  991. system("echo \"in\" > /sys/class/gpio/gpio113/direction");
  992. /*MCASP0_ACLKX => GPIO3_14*//*Ethernet PHY reset*/
  993. system("echo 110 > /sys/class/gpio/export");
  994. system("echo \"out\" > /sys/class/gpio/gpio110/direction");
  995. system("echo 0 > /sys/class/gpio/gpio110/value");
  996. /* MCASP0_FSR => GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
  997. system("echo 115 > /sys/class/gpio/export");
  998. system("echo \"out\" > /sys/class/gpio/gpio115/direction");
  999. system("echo 0 > /sys/class/gpio/gpio115/value");
  1000. /* MCASP0_AXR0 => GPIO3_16 *//*CSU board function OK indicator.*/
  1001. system("echo 112 > /sys/class/gpio/export");
  1002. system("echo \"out\" > /sys/class/gpio/gpio112/direction");
  1003. system("echo 1 > /sys/class/gpio/gpio112/value");
  1004. /* MCASP0_AXR1 => GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
  1005. system("echo 116 > /sys/class/gpio/export");
  1006. system("echo \"out\" > /sys/class/gpio/gpio116/direction");
  1007. system("echo 0 > /sys/class/gpio/gpio116/value");
  1008. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1009. /* (C14) EMU0.gpio3[7] */ /*CP open/short feature enable/disable, pull low for default enable*/
  1010. system("echo 103 > /sys/class/gpio/export");
  1011. system("echo \"out\" > /sys/class/gpio/gpio103/direction");
  1012. system("echo 0 > /sys/class/gpio/gpio103/value");
  1013. /* (B14) EMU1.gpio3[8] */ /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
  1014. system("echo 104 > /sys/class/gpio/export");
  1015. system("echo \"out\" > /sys/class/gpio/gpio104/direction");
  1016. system("echo 0 > /sys/class/gpio/gpio104/value");
  1017. #endif //!defined DD360 && !defined DD360Audi
  1018. log_info("Initial GPIO OK");
  1019. }
  1020. int LoadSysConfigAndInfo(struct SysConfigData *ptr)
  1021. {
  1022. int fd, wrd;
  1023. uint8_t *buf;
  1024. unsigned int ChkSum, ChkSumOrg;
  1025. if ((buf = malloc(MtdBlockSize)) == NULL) {
  1026. log_error("malloc buffer NG,rebooting..\r\n");
  1027. if (ShmStatusCodeData != NULL) {
  1028. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  1029. }
  1030. sleep(5);
  1031. system("reboot -f");
  1032. sleep(5);
  1033. system("reboot -f");
  1034. }
  1035. memset(buf, 0, MtdBlockSize);
  1036. //================================================
  1037. // Load configuration from mtdblock10
  1038. //================================================
  1039. fd = open("/dev/mtdblock10", O_RDWR);
  1040. if (fd < 0) {
  1041. free(buf);
  1042. log_error("open mtdblock10 NG,rebooting..\r\n");
  1043. if (ShmStatusCodeData != NULL) {
  1044. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  1045. }
  1046. sleep(5);
  1047. system("reboot -f");
  1048. sleep(5);
  1049. system("reboot -f");
  1050. }
  1051. wrd = read(fd, buf, MtdBlockSize);
  1052. close(fd);
  1053. if (wrd < MtdBlockSize) {
  1054. free(buf);
  1055. log_error("read SysConfigData data NG,rebooting..\r\n");
  1056. if (ShmStatusCodeData != NULL) {
  1057. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  1058. }
  1059. sleep(5);
  1060. system("reboot -f");
  1061. sleep(5);
  1062. system("reboot -f");
  1063. }
  1064. ChkSum = 0;
  1065. for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
  1066. ChkSum += buf[wrd];
  1067. }
  1068. memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
  1069. //================================================
  1070. // Load configuration from mtdblock11
  1071. //================================================
  1072. if (ChkSum != ChkSumOrg) {
  1073. log_error("Primary SysConfigData checksum NG, read backup\r\n");
  1074. fd = open("/dev/mtdblock11", O_RDWR);
  1075. if (fd < 0) {
  1076. free(buf);
  1077. log_error("open mtdblock11 (backup) NG,rebooting..\r\n");
  1078. if (ShmStatusCodeData != NULL) {
  1079. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  1080. }
  1081. sleep(5);
  1082. system("reboot -f");
  1083. sleep(5);
  1084. system("reboot -f");
  1085. }
  1086. memset(buf, 0, MtdBlockSize);
  1087. wrd = read(fd, buf, MtdBlockSize);
  1088. close(fd);
  1089. if (wrd < MtdBlockSize) {
  1090. free(buf);
  1091. log_error("read backup SysConfigData data NG,rebooting..\r\n");
  1092. if (ShmStatusCodeData != NULL) {
  1093. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  1094. }
  1095. sleep(5);
  1096. system("reboot -f");
  1097. sleep(5);
  1098. system("reboot -f");
  1099. }
  1100. ChkSum = 0;
  1101. for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
  1102. ChkSum += buf[wrd];
  1103. }
  1104. memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
  1105. //================================================
  1106. // Load configuration from mtdblock12 (Factory default)
  1107. //================================================
  1108. if (ChkSum != ChkSumOrg) {
  1109. log_error("backup SysConfigData checksum NG, read Factory default\r\n");
  1110. fd = open("/dev/mtdblock12", O_RDWR);
  1111. if (fd < 0) {
  1112. free(buf);
  1113. log_error("open mtdblock12 (Factory default) NG,rebooting..\r\n");
  1114. if (ShmStatusCodeData != NULL) {
  1115. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  1116. }
  1117. sleep(5);
  1118. system("reboot -f");
  1119. sleep(5);
  1120. system("reboot -f");
  1121. }
  1122. memset(buf, 0, MtdBlockSize);
  1123. wrd = read(fd, buf, MtdBlockSize);
  1124. close(fd);
  1125. if (wrd < MtdBlockSize) {
  1126. free(buf);
  1127. log_error("read factory default SysConfigData data NG,rebooting..\r\n");
  1128. if (ShmStatusCodeData != NULL) {
  1129. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  1130. }
  1131. sleep(5);
  1132. system("reboot -f");
  1133. sleep(5);
  1134. system("reboot -f");
  1135. }
  1136. ChkSum = 0;
  1137. for (wrd = 0; wrd < MtdBlockSize - 4; wrd++) {
  1138. ChkSum += buf[wrd];
  1139. }
  1140. memcpy(&ChkSumOrg, buf + (0x00600000 - 4), sizeof(ChkSumOrg));
  1141. if (ChkSum != ChkSumOrg) {
  1142. log_error("factory default SysConfigData checksum NG, restore factory default\r\n");
  1143. free(buf);
  1144. system("cd /root;./FactoryConfig -m");
  1145. system("sync");
  1146. sleep(5);
  1147. system("reboot -f");
  1148. sleep(5);
  1149. system("reboot -f");
  1150. return FAIL;
  1151. }
  1152. }
  1153. }
  1154. //load OK
  1155. memcpy((struct SysConfigData *)ptr, buf, sizeof(struct SysConfigData));
  1156. free(buf);
  1157. //log_info("Load SysConfigData OK\n");
  1158. return PASS;
  1159. }
  1160. int isRouteFail()
  1161. {
  1162. int result = YES;
  1163. FILE *fp;
  1164. char buf[512];
  1165. fp = popen("route -n", "r");
  1166. if (fp != NULL) {
  1167. while (fgets(buf, sizeof(buf), fp) != NULL) {
  1168. if (strstr(buf, "eth0") != NULL) {
  1169. result = NO;
  1170. }
  1171. }
  1172. }
  1173. pclose(fp);
  1174. return result;
  1175. }
  1176. //static void eth0Down(void)
  1177. //{
  1178. // char cmdbuf[256] = {0};
  1179. //
  1180. // sprintf(cmdbuf, "/sbin/ifconfig eth0 down");
  1181. //}
  1182. //static void eth0Up(void)
  1183. //{
  1184. // char cmdbuf[256] = {0};
  1185. //
  1186. // sprintf(cmdbuf, "/sbin/ifconfig eth0 %s up", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
  1187. //}
  1188. int isReachableInternet()
  1189. {
  1190. int result = FAIL;
  1191. FILE *fp;
  1192. char cmd[256];
  1193. char buf[512];
  1194. char tmp[512];
  1195. strcpy(cmd, "ifconfig eth0");
  1196. fp = popen(cmd, "r");
  1197. if (fp != NULL) {
  1198. while (fgets(buf, sizeof(buf), fp) != NULL) {
  1199. if (strstr(buf, "inet addr:") > 0) {
  1200. sscanf(buf, "%*s%s", tmp);
  1201. substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf) - strspn(tmp, "addr:"));
  1202. if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != EQUAL) {
  1203. strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
  1204. }
  1205. }
  1206. }
  1207. }
  1208. pclose(fp);
  1209. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  1210. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == NORMAL) {
  1211. result = FAIL;
  1212. } else {
  1213. result = PASS;
  1214. }
  1215. #else
  1216. memset(buf, 0x00, sizeof(buf));
  1217. for (int idx = 0; idx < ARRAY_SIZE(valid_Internet); idx++) {
  1218. sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
  1219. fp = popen(cmd, "r");
  1220. if (fp != NULL) {
  1221. while (fgets(buf, sizeof(buf), fp) != NULL) {
  1222. if (strstr(buf, "transmitted") > 0) {
  1223. //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
  1224. if (strstr(buf, "100%") != NULL) {
  1225. } else {
  1226. result = PASS;
  1227. }
  1228. //DEBUG_INFO("%s",buf);
  1229. //DEBUG_INFO("%s\n",tmp);
  1230. }
  1231. }
  1232. }
  1233. pclose(fp);
  1234. }
  1235. #endif //defined DD360 || defined DD360Audi
  1236. return result;
  1237. }
  1238. void InitEthernet()
  1239. {
  1240. char tmpbuf[256];
  1241. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1242. bool ethResult = false;
  1243. uint8_t cnt_pingDNS_Fail = 0;
  1244. #endif //!defined DD360 && !defined DD360Audi
  1245. system("ifconfig eth0 down");// eth0 down
  1246. system("ifconfig eth1 down");// eth1 down
  1247. sleep(2);
  1248. // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
  1249. system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
  1250. sleep(2);
  1251. //Init Eth0 for internet
  1252. memset(tmpbuf, 0, 256);
  1253. sprintf(tmpbuf, "/sbin/ifconfig eth0 %s netmask %s up",
  1254. ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
  1255. ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
  1256. //sprintf(tmpbuf,"/sbin/ifconfig eth0 192.168.100.10 netmask 255.255.255.0 up");
  1257. system(tmpbuf);
  1258. memset(tmpbuf, 0, 256);
  1259. sprintf(tmpbuf, "route add default gw %s eth0 ",
  1260. ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
  1261. //sprintf(tmpbuf,"route add default gw 192.168.100.1 eth0 ");
  1262. system(tmpbuf);
  1263. //system("ifconfig lo up");
  1264. // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
  1265. //Init Eth1 for administrator tool
  1266. memset(tmpbuf, 0, 256);
  1267. sprintf(tmpbuf, "/sbin/ifconfig eth1 %s netmask %s up",
  1268. ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
  1269. ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
  1270. system(tmpbuf);
  1271. //Run DHCP client if enabled
  1272. system("killall udhcpc");
  1273. system("rm -rf /etc/resolv.conf");
  1274. system("echo nameserver 8.8.8.8 > /etc/resolv.conf"); //Google DNS server
  1275. system("echo nameserver 180.76.76.76 > /etc/resolv.conf"); //Baidu DNS server
  1276. //system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
  1277. if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
  1278. sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
  1279. ShmSysConfigAndInfo->SysConfig.SystemId);
  1280. system(tmpbuf);
  1281. }
  1282. //Upgrade system id to /etc/hostname
  1283. sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
  1284. system(tmpbuf);
  1285. pid_t pid = fork();
  1286. if (pid == 0) {
  1287. log_info("InitEthernet = %d\r\n", pid);
  1288. for (;;) {
  1289. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1290. if (isRouteFail()) {
  1291. //log_info("eth0 not in route, restart eht0. \n");
  1292. system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
  1293. if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
  1294. InitialDHCP();
  1295. }
  1296. }
  1297. if (isReachableInternet() == PASS) {
  1298. ShmSysConfigAndInfo->SysInfo.ethInternetConn = YES;
  1299. cnt_pingDNS_Fail = 0;
  1300. } else {
  1301. if (++cnt_pingDNS_Fail > 3) {
  1302. ShmSysConfigAndInfo->SysInfo.ethInternetConn = NO;
  1303. }
  1304. }
  1305. ethResult = ShmSysConfigAndInfo->SysInfo.ethInternetConn;
  1306. if (ethResult == YES) {
  1307. system("/sbin/ifmetric eth0 0");
  1308. if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
  1309. (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
  1310. system("/sbin/ifmetric mlan0 1");
  1311. }
  1312. if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
  1313. (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
  1314. system("/sbin/ifmetric ppp0 2");
  1315. }
  1316. }
  1317. if (!ethResult &&
  1318. ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
  1319. (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' ||
  1320. ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
  1321. //ethResult = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn;
  1322. ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
  1323. if (ethResult) {
  1324. if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
  1325. (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
  1326. system("/sbin/ifmetric eth0 1");
  1327. system("/sbin/ifmetric mlan0 0");
  1328. }
  1329. if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
  1330. (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
  1331. system("/sbin/ifmetric ppp0 2");
  1332. }
  1333. }
  1334. }
  1335. if (!ethResult &&
  1336. ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
  1337. (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' ||
  1338. ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
  1339. //ethResult = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn;
  1340. ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == YES ? NO : YES;
  1341. if (ethResult) {
  1342. if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
  1343. (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
  1344. system("/sbin/ifmetric mlan0 2");
  1345. }
  1346. if ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
  1347. (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')) {
  1348. system("/sbin/ifmetric eth0 1");
  1349. system("/sbin/ifmetric ppp0 0");
  1350. }
  1351. }
  1352. }
  1353. ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
  1354. #else
  1355. isReachableInternet();
  1356. #endif //!defined DD360 && !defined DD360
  1357. sleep(5);
  1358. }
  1359. }
  1360. log_info("Initial Ethernet OK\r\n");
  1361. }
  1362. int InitialRfidPort()
  1363. {
  1364. int uartO2 = open(rfidPortName, O_RDWR);
  1365. struct termios tios;
  1366. if (uartO2 != FAIL) {
  1367. ioctl (uartO2, TCGETS, &tios);
  1368. tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
  1369. tios.c_lflag = 0;
  1370. tios.c_iflag = 0;
  1371. tios.c_oflag = 0;
  1372. tios.c_cc[VMIN] = 0;
  1373. tios.c_cc[VTIME] = (uint8_t) 1;
  1374. tios.c_lflag = 0;
  1375. tcflush(uartO2, TCIFLUSH);
  1376. ioctl(uartO2, TCSETS, &tios);
  1377. }
  1378. if (uartO2 < 0) {
  1379. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
  1380. }
  1381. return uartO2;
  1382. }
  1383. void GetMacAddress()
  1384. {
  1385. for (uint8_t index = 0; index < 2; index++) {
  1386. int fd;
  1387. struct ifreq ifr;
  1388. char tarEth[5];
  1389. char Mac[18];
  1390. sprintf(tarEth, "eth%d", index);
  1391. fd = socket(AF_INET, SOCK_DGRAM, 0);
  1392. ifr.ifr_addr.sa_family = AF_INET;
  1393. strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
  1394. ioctl(fd, SIOCGIFHWADDR, &ifr);
  1395. close(fd);
  1396. sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
  1397. ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
  1398. ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
  1399. if (index == 0) {
  1400. strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
  1401. } else {
  1402. strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
  1403. }
  1404. }
  1405. }
  1406. void GetFirmwareVersion()
  1407. {
  1408. // Get CSU root file system version
  1409. sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
  1410. uint8_t count = 0, chademo = 0, ccs = 0, gb = 0;
  1411. for (uint8_t idx = 0; idx < 3; idx++) {
  1412. if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'J') {
  1413. chademo++;
  1414. count++;
  1415. } else if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'G') {
  1416. gb++;
  1417. count++;
  1418. } else if (ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'U' ||
  1419. ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'V' ||
  1420. ShmSysConfigAndInfo->SysConfig.ModelName[7 + idx] == 'E') {
  1421. ccs++;
  1422. count++;
  1423. }
  1424. }
  1425. if (count == 1) {
  1426. if (chademo > 0) {
  1427. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
  1428. } else if (ccs > 0) {
  1429. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
  1430. } else if (gb > 0) {
  1431. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
  1432. }
  1433. } else {
  1434. if (chademo > 0 && ccs > 0) {
  1435. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
  1436. } else if (chademo > 0 && gb > 0) {
  1437. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
  1438. } else if (ccs > 0 && gb > 0) {
  1439. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
  1440. }
  1441. }
  1442. // Get network option from model name
  1443. switch (ShmSysConfigAndInfo->SysConfig.ModelName[10]) {
  1444. case 'B':
  1445. case 'U':
  1446. //Blue tooth
  1447. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
  1448. break;
  1449. case 'W':
  1450. // WIFI
  1451. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
  1452. break;
  1453. case 'T':
  1454. // 3G/4G
  1455. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
  1456. break;
  1457. case 'D': //DS60-120 add
  1458. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '5';
  1459. break;
  1460. default:
  1461. // LAN
  1462. ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
  1463. break;
  1464. }
  1465. // Get rating power from model name
  1466. memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
  1467. // Get IEC or UL
  1468. char _buf[3] = {0};
  1469. memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 2);
  1470. if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL) {
  1471. ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
  1472. log_info("IEC model");
  1473. } else if (strcmp(_buf, "WU") == EQUAL) {
  1474. ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
  1475. log_info("UL model");
  1476. }
  1477. }
  1478. //DS60-120 add
  1479. void InitialGunIndexToUnUse()
  1480. {
  1481. for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
  1482. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index = NO_DEFINE;
  1483. }
  1484. for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
  1485. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index = NO_DEFINE;
  1486. }
  1487. for (uint8_t index = 0; index < GB_QUANTITY; index++) {
  1488. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index = NO_DEFINE;
  1489. }
  1490. for (uint8_t index = 0; index < AC_QUANTITY; index++) {
  1491. ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index = NO_DEFINE;
  1492. }
  1493. }
  1494. void InitialShareMemoryInfo()
  1495. {
  1496. FILE *fp;
  1497. char cmd[512];
  1498. char buf[512];
  1499. sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
  1500. sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
  1501. sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
  1502. ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
  1503. ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
  1504. ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
  1505. ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
  1506. ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
  1507. ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
  1508. ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
  1509. ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
  1510. ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
  1511. ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
  1512. ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
  1513. ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
  1514. sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
  1515. memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
  1516. sprintf(cmd, "/bin/uname -r");
  1517. fp = popen(cmd, "r");
  1518. if (fp == NULL) {
  1519. sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
  1520. } else {
  1521. while (fgets(buf, sizeof(buf), fp) != NULL) {
  1522. strcpy((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
  1523. }
  1524. }
  1525. // 雙槍 CCS + Chademo
  1526. GetFirmwareVersion();
  1527. //sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
  1528. sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
  1529. sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
  1530. sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
  1531. sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
  1532. sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
  1533. sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
  1534. sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
  1535. sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
  1536. sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
  1537. sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
  1538. sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
  1539. sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
  1540. sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
  1541. ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
  1542. ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
  1543. ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
  1544. ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
  1545. ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
  1546. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
  1547. ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
  1548. strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
  1549. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
  1550. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
  1551. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
  1552. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = NO; //DS60-120 Add
  1553. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
  1554. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
  1555. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
  1556. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
  1557. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail = NO; //DS60-120 Add
  1558. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = NO; //DS60-120 add
  1559. memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  1560. memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  1561. ShmPrimaryMcuData->SelfTest_Comp = NO;
  1562. ShmRelayModuleData->SelfTest_Comp = NO;
  1563. ShmFanModuleData->SelfTest_Comp = NO;
  1564. ShmLedModuleData->SelfTest_Comp = NO;
  1565. #if defined DD360Audi
  1566. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
  1567. #else
  1568. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  1569. #endif //defined DD360Audi
  1570. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  1571. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  1572. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  1573. ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOTTING; //DS60-120 add
  1574. ShmFanModuleData->TestFanSpeed = 0;
  1575. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
  1576. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
  1577. //--- DS60-120 remove -----
  1578. /*char EvsePower[2];
  1579. EvsePower[2] = '\0';
  1580. unsigned short buf_pow = 0;
  1581. if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6) {
  1582. strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
  1583. if (strcmp(EvsePower, "15") == EQUAL) {
  1584. buf_pow = 150;
  1585. } else if (strcmp(EvsePower, "30") == EQUAL) {
  1586. buf_pow = 30;
  1587. } else if (strcmp(EvsePower, "60") == EQUAL) {
  1588. buf_pow = 60;
  1589. } else if (strcmp(EvsePower, "12") == EQUAL) {
  1590. buf_pow = 120;
  1591. } else if (strcmp(EvsePower, "18") == EQUAL) {
  1592. buf_pow = 180;
  1593. } else if (strcmp(EvsePower, "36") == EQUAL) {
  1594. buf_pow = 360;
  1595. }
  1596. ShmSysConfigAndInfo->SysConfig.RatingCurrent = (buf_pow / 30) * PSU_MIN_CUR;
  1597. if (ShmSysConfigAndInfo->SysConfig.MaxChargingPower == 0 ||
  1598. ShmSysConfigAndInfo->SysConfig.MaxChargingPower > buf_pow) {
  1599. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = buf_pow;
  1600. }
  1601. }
  1602. */
  1603. //--------------------------------------------------------------------------
  1604. InitialGunIndexToUnUse();//DS60-120 add
  1605. //ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0;
  1606. //ShmDcCommonData->psuKeepCommunication = NO;
  1607. //ShmDcCommonData->acContactSwitch = NO;
  1608. ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0;
  1609. ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0;
  1610. //ShmDcCommonData->LcmFwVersion = 0;
  1611. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
  1612. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
  1613. log_info("3InitialShareMemoryInfo done...\r\n");
  1614. }
  1615. int Initialization()
  1616. {
  1617. // 初始化卡號驗證的 Flag
  1618. ClearAuthorizedFlag();
  1619. // 初始化插槍驗證的 Flag
  1620. ClearDetectPluginFlag();
  1621. // UART 2 for Rfid
  1622. rfidFd = InitialRfidPort();
  1623. int pinOut[2] = { 116, 115 };
  1624. for (uint8_t count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
  1625. chargingInfo[count]->RemoteStartFlag = NO;
  1626. if (chargingInfo[count]->Type == _Type_Chademo) {
  1627. gpio_set_value(pinOut[count], 0x00);
  1628. ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
  1629. } else if (chargingInfo[count]->Type == _Type_GB) {
  1630. gpio_set_value(pinOut[count], 0x00);
  1631. ShmGBTData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
  1632. } else if (chargingInfo[count]->Type == _Type_CCS_2) {
  1633. //if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) { //DS60-120 remove
  1634. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
  1635. gpio_set_value(pinOut[1], 0x01);
  1636. } else {
  1637. gpio_set_value(pinOut[count], 0x01);
  1638. }
  1639. ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
  1640. //}
  1641. }
  1642. strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
  1643. }
  1644. for (uint8_t count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++) {
  1645. ac_chargingInfo[count]->RemoteStartFlag = NO;
  1646. if (ac_chargingInfo[count]->Type == _Type_AC) {
  1647. ac_chargingInfo[count]->SelfTest_Comp = NO;
  1648. strcpy((char *)ShmOCPP16Data->StatusNotification[count + ShmSysConfigAndInfo->SysConfig.TotalConnectorCount].ErrorCode, "NoError");
  1649. }
  1650. }
  1651. //log_info("Initialization OK \n");
  1652. return PASS;
  1653. }
  1654. bool InitialSystemDefaultConfig()
  1655. {
  1656. bool result = true;
  1657. LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
  1658. InitGPIO();
  1659. InitEthernet();
  1660. GetMacAddress();
  1661. // system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
  1662. // sleep(3);
  1663. // system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
  1664. // sleep(1);
  1665. // system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
  1666. return result;
  1667. }
  1668. bool DisplaySelfTestFailReason()
  1669. {
  1670. bool result = false;
  1671. // RB、FB、407、EV 小板中有些板子無回應
  1672. if (ShmRelayModuleData->SelfTest_Comp == NO)
  1673. { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = true; }
  1674. if (ShmFanModuleData->SelfTest_Comp == NO)
  1675. { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = true; }
  1676. if (ShmPrimaryMcuData->SelfTest_Comp == NO)
  1677. { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = true; }
  1678. if (ShmLedModuleData->SelfTest_Comp == NO)
  1679. { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = true; }
  1680. for (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
  1681. if (chargingInfo[index]->Type == _Type_Chademo) {
  1682. if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
  1683. { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = true; }
  1684. } else if (chargingInfo[index]->Type == _Type_GB) {
  1685. if (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
  1686. { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtboardStestFail = true; }
  1687. } else if (chargingInfo[index]->Type == _Type_CCS_2) {
  1688. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  1689. if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
  1690. { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = true; }
  1691. }
  1692. }
  1693. }
  1694. for (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++) {
  1695. // 先借 GBT 顯示
  1696. if (ac_chargingInfo[index]->SelfTest_Comp == NO)
  1697. { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcConnectorStestFail = true; }
  1698. }
  1699. if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO) {
  1700. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1701. // AC Contact 未搭上
  1702. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = true;
  1703. result = true;
  1704. #endif //!defined DD360 && !defined DD360Audi
  1705. }
  1706. #if 0
  1707. else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES) { //DS60-120 add
  1708. result = true;
  1709. }
  1710. #endif //0
  1711. else if (ShmPsuData->SystemAvailablePower <= 0 && ShmPsuData->SystemAvailableCurrent <= 0) {
  1712. // PSU 通訊問題
  1713. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = true;
  1714. result = true;
  1715. }
  1716. return result;
  1717. }
  1718. void SelfTestRun()
  1719. {
  1720. bool evInitFlag = false;
  1721. StartSystemTimeoutDet(Timeout_SelftestChk);
  1722. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
  1723. while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE //||
  1724. //GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL <= 20 //DS60-120 add
  1725. ) {
  1726. if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE) {
  1727. return;
  1728. }
  1729. ChkPrimaryStatus();
  1730. if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 //||
  1731. //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES //DS60-120 add
  1732. ) {
  1733. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
  1734. return;
  1735. }
  1736. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) {
  1737. if (ShmPsuData->Work_Step == _NO_WORKING ||
  1738. ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL) {
  1739. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
  1740. return;
  1741. }
  1742. switch (ShmSysConfigAndInfo->SysInfo.SelfTestSeq) {
  1743. case _STEST_VERSION: {
  1744. if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
  1745. ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
  1746. && (ShmRelayModuleData->SelfTest_Comp != YES)
  1747. ) {
  1748. log_info("Relay Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  1749. ShmRelayModuleData->SelfTest_Comp = YES;
  1750. }
  1751. #if !defined NO_FAN_BOARD && !defined DD360ComBox
  1752. if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
  1753. ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
  1754. && (ShmFanModuleData->SelfTest_Comp != YES)
  1755. ) {
  1756. log_info("Fan Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  1757. ShmFanModuleData->SelfTest_Comp = YES;
  1758. }
  1759. #else
  1760. ShmFanModuleData->SelfTest_Comp = YES;
  1761. #endif //NO_FAN_BOARD
  1762. if ((strlen((char *)ShmPrimaryMcuData->version) != 0 ||
  1763. ShmPrimaryMcuData->version[0] != '\0')
  1764. && (ShmPrimaryMcuData->SelfTest_Comp != YES)
  1765. ) {
  1766. log_info("Primary FW Rev = %s", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
  1767. ShmPrimaryMcuData->SelfTest_Comp = YES;
  1768. }
  1769. #if 0 //DS60-120 remove
  1770. if ((strlen((char *)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev) != 0 ||
  1771. ShmSysConfigAndInfo->SysInfo.LedModuleFwRev[0] != '\0')
  1772. && (ShmLedModuleData->SelfTest_Comp != YES)
  1773. ) {
  1774. log_info("LED Board FW Rev = %s", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  1775. ShmLedModuleData->SelfTest_Comp = YES;
  1776. }
  1777. #endif //0
  1778. // EV 小板
  1779. if (!evInitFlag) {
  1780. evInitFlag = YES;
  1781. for (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
  1782. //log_info("index = %d, charging index = %d, type = %d\r\n",
  1783. // index,
  1784. // chargingInfo[index]->type_index,
  1785. // chargingInfo[index]->Type);
  1786. if (chargingInfo[index]->Type == _Type_Chademo) {
  1787. if ((strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
  1788. ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
  1789. //&& (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp != YES)
  1790. ) {
  1791. log_info("CHAdeMO[%d] FW Rev = %s", chargingInfo[index]->type_index, ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
  1792. ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
  1793. } else {
  1794. //log_info("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
  1795. evInitFlag = NO;
  1796. }
  1797. } else if (chargingInfo[index]->Type == _Type_GB) {
  1798. if ((strlen((char *)ShmGBTData->evse[chargingInfo[index]->type_index].version) != 0 ||
  1799. ShmGBTData->evse[chargingInfo[index]->type_index].version[0] != '\0')
  1800. //&& (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp != YES)
  1801. ) {
  1802. log_info("GBT[%d] FW Rev = %s", chargingInfo[index]->type_index, ShmGBTData->evse[chargingInfo[index]->type_index].version);
  1803. ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
  1804. } else {
  1805. //log_info("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
  1806. evInitFlag = NO;
  1807. }
  1808. } else if (chargingInfo[index]->Type == _Type_CCS_2) {
  1809. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  1810. if ((strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
  1811. ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
  1812. /*&&(ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp != YES)*/
  1813. ) {
  1814. log_info("CCS[%d] FW Rev = %s",
  1815. chargingInfo[index]->type_index,
  1816. ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
  1817. ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp = YES;
  1818. } else {
  1819. //log_info("CCS[%d] ccs fw lose...... %s \n",
  1820. // chargingInfo[index]->type_index,
  1821. // ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
  1822. evInitFlag = NO;
  1823. }
  1824. }
  1825. }
  1826. }
  1827. for (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++) {
  1828. if (ac_chargingInfo[index]->Type == _Type_AC) {
  1829. if ((strlen((char *)ac_chargingInfo[index]->version) != 0 || ac_chargingInfo[index]->version[0] != '\0')
  1830. && (ac_chargingInfo[index]->SelfTest_Comp != YES)
  1831. ) {
  1832. log_info("AC connector[%d] FW Rev = %s", index, ac_chargingInfo[index]->version);
  1833. ac_chargingInfo[index]->SelfTest_Comp = YES;
  1834. } else {
  1835. evInitFlag = NO;
  1836. }
  1837. }
  1838. }
  1839. }
  1840. if ( ShmFanModuleData->SelfTest_Comp &&
  1841. ShmRelayModuleData->SelfTest_Comp &&
  1842. ShmPrimaryMcuData->SelfTest_Comp &&
  1843. //ShmLedModuleData->SelfTest_Comp &&
  1844. evInitFlag
  1845. ) {
  1846. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
  1847. }
  1848. }
  1849. break;
  1850. case _STEST_AC_CONTACTOR: {
  1851. //ShmPsuData->Work_Step = _TEST_COMPLETE;
  1852. // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
  1853. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1854. if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES) {
  1855. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
  1856. log_info("AC contactor self test OK");
  1857. }
  1858. #else
  1859. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
  1860. log_info("Waiting for DO communication");
  1861. #endif //!defined DD360 && !defined DD360Audi
  1862. }
  1863. break;
  1864. case _STEST_PSU_DETECT: {
  1865. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1866. if (ShmPsuData->Work_Step >= GET_SYS_CAP) {
  1867. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
  1868. }
  1869. #else
  1870. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
  1871. #endif //defined DD360 && !defined DD360Audi
  1872. }
  1873. break;
  1874. case _STEST_PSU_CAP: {
  1875. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1876. // 此測試是要確認當前總輸出能力
  1877. // 如果沒有 PSU 模組請 bypass
  1878. if (ShmPsuData->Work_Step == BOOTING_COMPLETE) {
  1879. sleep(1);
  1880. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
  1881. ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
  1882. }
  1883. #else
  1884. //check the power limit from DO
  1885. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
  1886. ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
  1887. log_info("Successful Self Test");
  1888. #endif //defined DD360 && !defined DD360Audi
  1889. }
  1890. break;
  1891. }
  1892. } else {
  1893. break;
  1894. }
  1895. usleep(100000);
  1896. }
  1897. }
  1898. int SpawnTask()
  1899. {
  1900. sleep(2);
  1901. system("/root/Module_EventLogging &");
  1902. system("/root/Module_PrimaryComm &");
  1903. system("/root/Module_EvComm &");
  1904. system("/root/Module_LcmControl &");
  1905. system("/root/Module_InternalComm &");
  1906. system("/root/Module_ProduceUtils &");
  1907. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  1908. system("/root/Module_DoComm &");
  1909. #else
  1910. system("/root/Module_PsuComm &");
  1911. if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
  1912. strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL) {
  1913. system("/root/OcppBackend &");
  1914. }
  1915. if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') {
  1916. system("/root/Module_4g &");
  1917. }
  1918. if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') {
  1919. system("/root/Module_Wifi &");
  1920. }
  1921. if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D') {
  1922. system("/root/Module_4g &");
  1923. system("/root/Module_Wifi &");
  1924. }
  1925. #endif //defined DD360 || defined DD360Audi
  1926. return PASS;
  1927. }
  1928. int StoreUsrConfigData(struct SysConfigData *UsrData)
  1929. {
  1930. int result = PASS;
  1931. int fd, wrd;
  1932. unsigned int i, Chk;
  1933. uint8_t *ptr, *BufTmp;
  1934. Chk = 0;
  1935. ptr = (uint8_t *)UsrData;
  1936. if ((BufTmp = malloc(MtdBlockSize)) != NULL) {
  1937. memset(BufTmp, 0, MtdBlockSize);
  1938. memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
  1939. for (i = 0; i < MtdBlockSize - 4; i++) {
  1940. Chk += *(ptr + i);
  1941. }
  1942. memcpy(BufTmp + MtdBlockSize - 4, &Chk, 4);
  1943. fd = open("/dev/mtdblock10", O_RDWR);
  1944. if (fd > 0) {
  1945. wrd = write(fd, BufTmp, MtdBlockSize);
  1946. close(fd);
  1947. if (wrd >= MtdBlockSize) {
  1948. fd = open("/dev/mtdblock11", O_RDWR);
  1949. if (fd > 0) {
  1950. wrd = write(fd, BufTmp, MtdBlockSize);
  1951. close(fd);
  1952. if (wrd < MtdBlockSize) {
  1953. log_error("write /dev/mtdblock11(backup) NG\r\n");
  1954. result = FAIL;
  1955. }
  1956. } else {
  1957. log_error("open /dev/mtdblock11(backup) NG\r\n");
  1958. result = FAIL;
  1959. }
  1960. } else {
  1961. log_error("write /dev/mtdblock10 NG\r\n");
  1962. result = FAIL;
  1963. }
  1964. } else {
  1965. log_error("open /dev/mtdblock10 NG\r\n");
  1966. result = FAIL;
  1967. }
  1968. } else {
  1969. log_error("alloc BlockSize NG\r\n");
  1970. result = FAIL;
  1971. }
  1972. if (BufTmp != NULL) {
  1973. free(BufTmp);
  1974. }
  1975. return result;
  1976. }
  1977. //===============================================
  1978. // Common Detect Chk - Stop Charging ?
  1979. //===============================================
  1980. int isEvBoardStopChargeFlag(uint8_t gunIndex)
  1981. {
  1982. //printf("StopChargeFlag = %d\r\n", chargingInfo[gunIndex]->StopChargeFlag);
  1983. return chargingInfo[gunIndex]->StopChargeFlag;
  1984. }
  1985. bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
  1986. {
  1987. return chargingInfo[gunIndex]->NormalStopChargeFlag;
  1988. }
  1989. //===============================================
  1990. // 掃描插槍狀況
  1991. //===============================================
  1992. void ClearDetectPluginFlag()
  1993. {
  1994. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
  1995. //DS60-120 add
  1996. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  1997. if (chargingInfo[gun_index]->RemoteStartFlag == YES) {
  1998. chargingInfo[gun_index]->RemoteStartFlag = NO;
  1999. }
  2000. }
  2001. if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE) {
  2002. ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
  2003. }
  2004. }
  2005. void DetectPluginStart()
  2006. {
  2007. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
  2008. }
  2009. bool isDetectPlugin()
  2010. {
  2011. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
  2012. return YES;
  2013. }
  2014. return NO;
  2015. }
  2016. //===============================================
  2017. // Common Detect Chk - Chademo
  2018. //===============================================
  2019. bool isEvGunLocked_chademo(uint8_t gunIndex)
  2020. {
  2021. return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
  2022. }
  2023. bool isEvContactorWelding_chademo(uint8_t gunIndex)
  2024. {
  2025. return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
  2026. }
  2027. bool isEvStopReq_chademo(uint8_t gunIndex)
  2028. {
  2029. return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
  2030. }
  2031. bool isEvStopCharging_chademo(uint8_t gunIndex)
  2032. {
  2033. if (isEvGunLocked_chademo(gunIndex) == NO) {
  2034. // 無鎖槍 = 停止
  2035. log_info("gun locked none (%d) \n", gunIndex);
  2036. return YES;
  2037. }
  2038. return NO;
  2039. }
  2040. uint8_t isPrechargeStatus_chademo(uint8_t gunIndex)
  2041. {
  2042. uint8_t result = 0x00;
  2043. result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
  2044. return result;
  2045. }
  2046. //===============================================
  2047. // Common Detect Chk - GB
  2048. //===============================================
  2049. bool isEvGunLocked_gb(uint8_t gunIndex)
  2050. {
  2051. return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
  2052. }
  2053. bool isEvStopCharging_gb(uint8_t gunIndex)
  2054. {
  2055. if (isEvGunLocked_gb(gunIndex) == NO) {
  2056. // 無鎖槍 = 停止
  2057. log_info("gun locked none. \n");
  2058. return YES;
  2059. }
  2060. return NO;
  2061. }
  2062. uint8_t isPrechargeStatus_gb(uint8_t gunIndex)
  2063. {
  2064. uint8_t result = 0x00;
  2065. result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
  2066. return result;
  2067. }
  2068. //===============================================
  2069. // Common Detect Chk - CCS
  2070. //===============================================
  2071. bool isEvGunLocked_ccs(uint8_t gunIndex)
  2072. {
  2073. return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0) ? NO : YES;
  2074. }
  2075. uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
  2076. {
  2077. uint8_t result = 0x00;
  2078. if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
  2079. result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
  2080. }
  2081. return result;
  2082. }
  2083. bool isEvStopCharging_ccs(uint8_t gunIndex)
  2084. {
  2085. if (isEvGunLocked_ccs(gunIndex) == NO) {
  2086. // 無鎖槍 = 停止
  2087. log_info("gun locked none. \n");
  2088. return YES;
  2089. }
  2090. return NO;
  2091. }
  2092. //===============================================
  2093. // Callback
  2094. //===============================================
  2095. void DisplayChargingInfo()
  2096. {
  2097. log_info("*********** DisplayChargingInfo *********** \n");
  2098. for (uint8_t i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
  2099. if (chargingInfo[i]->SystemStatus != S_IDLE &&
  2100. chargingInfo[i]->SystemStatus != S_RESERVATION) {
  2101. ChangeGunSelectByIndex(i);
  2102. return;
  2103. }
  2104. }
  2105. if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  2106. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
  2107. ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE) {
  2108. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  2109. }
  2110. usleep(50000);
  2111. #if defined DD360Audi
  2112. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
  2113. #else
  2114. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  2115. #endif //defined DD360Audi
  2116. }
  2117. void _AutoReturnTimeout()
  2118. {
  2119. log_info("*********** _AutoReturnTimeout %d*********** \n", ShmSysConfigAndInfo->SysInfo.PageIndex);
  2120. if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG) {
  2121. ClearDetectPluginFlag();
  2122. } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP) {
  2123. DetectPluginStart();
  2124. }
  2125. usleep(50000);
  2126. #if defined DD360Audi
  2127. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
  2128. #else
  2129. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  2130. #endif //defined DD360Audi
  2131. }
  2132. void _SelfTestTimeout()
  2133. {
  2134. if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE) {
  2135. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  2136. setChargerMode(gun_index, MODE_ALARM);
  2137. }
  2138. }
  2139. ShmPsuData->Work_Step = _NO_WORKING;
  2140. ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
  2141. log_info("Self test timeout. \n");
  2142. }
  2143. void _AuthorizedTimeout()
  2144. {
  2145. if (IsAuthorizingMode()) {
  2146. log_info("*********** _AuthorizedTimeout *********** \n");
  2147. isCardScan = false;
  2148. //gAudiCustInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance = 0.0; //Jerry add
  2149. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
  2150. //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
  2151. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  2152. ClearAuthorizedFlag();
  2153. }
  2154. }
  2155. void _DetectPlugInTimeout()
  2156. {
  2157. log_info("*********** _DetectPlugInTimeout *********** \n");
  2158. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  2159. ClearDetectPluginFlag();
  2160. //usleep(50000);
  2161. sleep(1); //Jerry add
  2162. #if defined DD360Audi
  2163. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
  2164. #else
  2165. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  2166. #endif //defined DD360Audi
  2167. }
  2168. void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
  2169. {
  2170. if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
  2171. if (!isEvGunLocked_chademo(gunIndex)) {
  2172. log_info("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
  2173. }
  2174. } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
  2175. if (!isEvGunLocked_ccs(gunIndex)) {
  2176. log_info("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
  2177. }
  2178. } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
  2179. if (!isEvGunLocked_ccs(gunIndex)) {
  2180. log_info("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
  2181. }
  2182. }
  2183. ChargingTerminalProcess(gunIndex);
  2184. _AutoReturnTimeout();
  2185. }
  2186. void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
  2187. {
  2188. log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
  2189. //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
  2190. {
  2191. setChargerMode(gunIndex, MODE_IDLE);
  2192. _AutoReturnTimeout();
  2193. }
  2194. }
  2195. void _PrepareTimeout(uint8_t gunIndex)
  2196. {
  2197. log_info("*********** _PrepareTimeout ***********\n");
  2198. setChargerMode(gunIndex, MODE_IDLE);
  2199. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
  2200. _AutoReturnTimeout();
  2201. }
  2202. void _CcsPrechargeTimeout(uint8_t gunIndex)
  2203. {
  2204. log_info("*********** _CcsPrechargeTimeout ***********\n");
  2205. setChargerMode(gunIndex, MODE_IDLE);
  2206. }
  2207. //===============================================
  2208. // 取得卡號與卡號驗證
  2209. //===============================================
  2210. bool canStartCharging()
  2211. {
  2212. char buf2[16] = "";
  2213. memset(buf2, 0, ARRAY_SIZE(buf2));
  2214. for (uint8_t index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
  2215. sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
  2216. }
  2217. sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2218. // 因為無法得知實際的長度,所以只能用搜尋的方式
  2219. if (strcmp(buf2, "Accepted") == EQUAL) {
  2220. return true;
  2221. } else {
  2222. }
  2223. return false;
  2224. }
  2225. void AuthorizingStart()
  2226. {
  2227. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
  2228. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
  2229. }
  2230. void ClearAuthorizedFlag()
  2231. {
  2232. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
  2233. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
  2234. }
  2235. bool isAuthorizedComplete()
  2236. {
  2237. if (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == YES) {
  2238. return false;
  2239. }
  2240. return true;
  2241. }
  2242. bool IsAuthorizingMode()
  2243. {
  2244. if (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO) {
  2245. return false;
  2246. }
  2247. return true;
  2248. }
  2249. //===============================================
  2250. // 紀錄 Alarm Code
  2251. //===============================================
  2252. void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
  2253. {
  2254. if (strcmp(code, "012229") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO; }
  2255. else if (strcmp(code, "012230") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO; }
  2256. else if (strcmp(code, "012231") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO; }
  2257. else if (strcmp(code, "011011") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO; }
  2258. else if (strcmp(code, "011013") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO; }
  2259. else if (strcmp(code, "011015") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO; }
  2260. else if (strcmp(code, "011012") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO; }
  2261. else if (strcmp(code, "011014") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO; }
  2262. else if (strcmp(code, "011016") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO; }
  2263. else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO; }
  2264. else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO; }
  2265. else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO; }
  2266. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
  2267. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012229", 6) == EQUAL ||
  2268. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012230", 6) == EQUAL ||
  2269. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012231", 6) == EQUAL ||
  2270. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011011", 6) == EQUAL ||
  2271. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011013", 6) == EQUAL ||
  2272. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011015", 6) == EQUAL ||
  2273. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011012", 6) == EQUAL ||
  2274. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011014", 6) == EQUAL ||
  2275. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011016", 6) == EQUAL ||
  2276. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011018", 6) == EQUAL ||
  2277. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011019", 6) == EQUAL ||
  2278. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011020", 6) == EQUAL) {
  2279. strncpy((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2280. }
  2281. }
  2282. }
  2283. void RecordAlarmCode(uint8_t gunIndex, char *code)
  2284. {
  2285. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL) {
  2286. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6);
  2287. }
  2288. //if (strcmp(code, "012234") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES; }
  2289. //if (strcmp(code, "012235") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES; }
  2290. //if (strcmp(code, "012236") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES; }
  2291. //if (strcmp(code, "012288") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES; }
  2292. //if (strcmp(code, "012289") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES; }
  2293. //if (strcmp(code, "012290") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES; }
  2294. if (strcmp(code, "012234") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES; }
  2295. else if (strcmp(code, "012235") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES; }
  2296. else if (strcmp(code, "012236") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES; }
  2297. else if (strcmp(code, "012288") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = YES; }
  2298. else if (strcmp(code, "012289") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = YES; }
  2299. else if (strcmp(code, "012290") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = YES; }
  2300. else if (strcmp(code, "012229") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES; }
  2301. else if (strcmp(code, "012230") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES; }
  2302. else if (strcmp(code, "012231") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES; }
  2303. else if (strcmp(code, "012296") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES; }
  2304. else if (strcmp(code, "012297") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES; }
  2305. else if (strcmp(code, "012298") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES; }
  2306. else if (strcmp(code, "011011") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES; }
  2307. else if (strcmp(code, "011013") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES; }
  2308. else if (strcmp(code, "011015") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES; }
  2309. else if (strcmp(code, "011012") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES; }
  2310. else if (strcmp(code, "011014") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES; }
  2311. else if (strcmp(code, "011016") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES; }
  2312. else if (strcmp(code, "011018") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES; }
  2313. else if (strcmp(code, "011019") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES; }
  2314. else if (strcmp(code, "011020") == EQUAL) { ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES; }
  2315. }
  2316. void RecordWarningCode(uint8_t gunIndex, char *code)
  2317. {
  2318. memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, code, 6);
  2319. if (strcmp(code, "012296") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES; }
  2320. if (strcmp(code, "012297") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES; }
  2321. if (strcmp(code, "012298") == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES; }
  2322. }
  2323. void ReleaseAlarmCode(uint8_t gunIndex)
  2324. {
  2325. #if 0
  2326. bool isCleanCheck = false;
  2327. char code[7];
  2328. if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
  2329. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL &&
  2330. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES) {
  2331. memcpy(code, "012234", 6);
  2332. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2333. isCleanCheck = true;
  2334. } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL &&
  2335. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail == YES) {
  2336. memcpy(code, "012289", 6);
  2337. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2338. isCleanCheck = true;
  2339. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES) {
  2340. ReleaseWarningCodeByString(gunIndex, "012296");
  2341. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
  2342. memcpy(code, "012217", 6);
  2343. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2344. isCleanCheck = true;
  2345. }
  2346. } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
  2347. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL &&
  2348. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES) {
  2349. memcpy(code, "012236", 6);
  2350. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2351. isCleanCheck = true;
  2352. } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL &&
  2353. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail == YES) {
  2354. memcpy(code, "012290", 6);
  2355. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2356. isCleanCheck = true;
  2357. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES) {
  2358. ReleaseWarningCodeByString(gunIndex, "012298");
  2359. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
  2360. memcpy(code, "012221", 6);
  2361. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2362. isCleanCheck = true;
  2363. }
  2364. } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
  2365. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL &&
  2366. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES) {
  2367. memcpy(code, "012235", 6);
  2368. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2369. isCleanCheck = true;
  2370. } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL &&
  2371. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail == YES) {
  2372. memcpy(code, "012288", 6);
  2373. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2374. isCleanCheck = true;
  2375. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES) {
  2376. ReleaseWarningCodeByString(gunIndex, "012297");
  2377. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
  2378. memcpy(code, "012219", 6);
  2379. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2380. isCleanCheck = true;
  2381. }
  2382. }
  2383. if (isCleanCheck) {
  2384. for (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
  2385. if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
  2386. if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, code, 6) != EQUAL) {
  2387. if (strncmp(code, "012234", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO; }
  2388. if (strncmp(code, "012289", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO; }
  2389. if (strncmp(code, "012217", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO; }
  2390. if (strncmp(code, "012236", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO; }
  2391. if (strncmp(code, "012290", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO; }
  2392. if (strncmp(code, "012221", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO; }
  2393. if (strncmp(code, "012235", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO; }
  2394. if (strncmp(code, "012288", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO; }
  2395. if (strncmp(code, "012219", 6) == EQUAL) {ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;}
  2396. }
  2397. }
  2398. }
  2399. }
  2400. #endif //0
  2401. // 回 idle 後主要清除 GFD Trip、UVP、OVP、GFD Warning
  2402. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
  2403. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
  2404. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL) {
  2405. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2406. }
  2407. }
  2408. if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
  2409. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
  2410. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
  2411. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
  2412. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
  2413. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
  2414. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL ||
  2415. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL ||
  2416. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012217", 6) == EQUAL ||
  2417. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012296", 6) == EQUAL) {
  2418. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2419. }
  2420. }
  2421. } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
  2422. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
  2423. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
  2424. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
  2425. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
  2426. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
  2427. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL ||
  2428. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL ||
  2429. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012219", 6) == EQUAL ||
  2430. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012297", 6) == EQUAL) {
  2431. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2432. }
  2433. }
  2434. } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
  2435. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
  2436. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
  2437. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
  2438. ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
  2439. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL) {
  2440. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL ||
  2441. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL ||
  2442. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012221", 6) == EQUAL ||
  2443. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012298", 6) == EQUAL) {
  2444. memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
  2445. }
  2446. }
  2447. }
  2448. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
  2449. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL ||
  2450. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012238", 6) == EQUAL ||
  2451. strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012304", 6) == EQUAL
  2452. ) {
  2453. memset(chargingInfo[gunIndex]->ConnectorAlarmCode, 0, sizeof(chargingInfo[gunIndex]->ConnectorAlarmCode));
  2454. }
  2455. }
  2456. void ReleaseWarningCodeByString(uint8_t gunIndex, char *code)
  2457. {
  2458. bool isCleanCheck = false;
  2459. if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
  2460. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES) {
  2461. memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
  2462. isCleanCheck = true;
  2463. } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
  2464. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES) {
  2465. memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
  2466. isCleanCheck = true;
  2467. } else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
  2468. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES) {
  2469. memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
  2470. isCleanCheck = true;
  2471. }
  2472. if (isCleanCheck) {
  2473. for (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
  2474. if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
  2475. if (strncmp((char *)chargingInfo[index]->ConnectorWarningCode, code, 6) != EQUAL) {
  2476. if (strncmp(code, "012296", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO; }
  2477. if (strncmp(code, "012297", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO; }
  2478. if (strncmp(code, "012298", 6) == EQUAL) { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO; }
  2479. }
  2480. }
  2481. }
  2482. }
  2483. }
  2484. //===============================================
  2485. // EmergencyStop and Charging Stop
  2486. //===============================================
  2487. void ChargingTerminalProcess(uint8_t gunIndex)
  2488. {
  2489. setChargerMode(gunIndex, MODE_TERMINATING);
  2490. }
  2491. void ChargingAlarmProcess(uint8_t gunIndex)
  2492. {
  2493. setChargerMode(gunIndex, MODE_ALARM);
  2494. }
  2495. void AcChargingTerminalProcess()
  2496. {
  2497. ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
  2498. }
  2499. void StopChargingProcessByString(uint8_t level)
  2500. {
  2501. if (level > ShmSysConfigAndInfo->SysWarningInfo.Level) {
  2502. ShmSysConfigAndInfo->SysWarningInfo.Level = level;
  2503. }
  2504. }
  2505. void ReleaseChargingProcessByString(uint8_t level)
  2506. {
  2507. if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level) {
  2508. ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
  2509. }
  2510. }
  2511. // 一般錯誤停止充電處理函式
  2512. void BoardErrOccurByString(uint8_t index, char *code)
  2513. {
  2514. uint8_t level = 1;
  2515. if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
  2516. (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  2517. if (strncmp(code, "023730", 6) == EQUAL && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO) {
  2518. ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
  2519. }
  2520. ChargingTerminalProcess(index);
  2521. }
  2522. StopChargingProcessByString(level);
  2523. }
  2524. // 急停狀況的停止充電處理函式
  2525. void EmcOccureByString(char *code)
  2526. {
  2527. uint8_t level = 2;
  2528. // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
  2529. // 其錯誤等級為 2
  2530. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  2531. //DS60-120 remove
  2532. if (strncmp(code, "012251", 6) == EQUAL ||
  2533. strncmp(code, "012252", 6) == EQUAL ||
  2534. strncmp(code, "012238", 6) == EQUAL ||
  2535. strncmp(code, "042251", 6) == EQUAL ||
  2536. strncmp(code, "042252", 6) == EQUAL ||
  2537. strncmp(code, "012304", 6) == EQUAL ||
  2538. strncmp(code, "042200", 6) == EQUAL ||
  2539. strncmp(code, "042201", 6) == EQUAL ||
  2540. strncmp(code, "042202", 6) == EQUAL ||
  2541. strncmp(code, "042267", 6) == EQUAL)
  2542. #endif //defined DD360 || defined DD360Audi
  2543. {
  2544. for (uint8_t gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++) {
  2545. //strncpy((char *)ShmOCPP16Data->StatusNotification[gun].VendorErrorCode, code, 6);
  2546. if ((chargingInfo[gun]->SystemStatus > S_IDLE &&
  2547. chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
  2548. (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  2549. chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  2550. //ChargingTerminalProcess(gun);
  2551. ChargingAlarmProcess(gun);
  2552. }
  2553. }
  2554. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  2555. StopChargingProcessByString(level);
  2556. InformOcppErrOccur(4);
  2557. #endif //defined DD360 || defined DD360Audi
  2558. }
  2559. }
  2560. void ReleaseBoardErrOccurByString(uint8_t index, char *code)
  2561. {
  2562. bool isTrigger = false;
  2563. uint8_t level = 1;
  2564. if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
  2565. isTrigger = true;
  2566. ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
  2567. }
  2568. if (isTrigger) {
  2569. ReleaseChargingProcessByString(level);
  2570. }
  2571. }
  2572. void ReleaseEmsOccureByString(uint8_t index, char *code)
  2573. {
  2574. bool isTrigger = false;
  2575. uint8_t level = 2;
  2576. if (strncmp(code, "042251", 6) == 0 ) {
  2577. isTrigger = true;
  2578. } else if (strncmp(code, "012251", 6) == 0 &&
  2579. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES) {
  2580. isTrigger = true;
  2581. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
  2582. } else if (strncmp(code, "012252", 6) == 0 &&
  2583. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES) {
  2584. isTrigger = true;
  2585. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
  2586. } else if (strncmp(code, "012237", 6) == 0 &&
  2587. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES) {
  2588. isTrigger = true;
  2589. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
  2590. } else if (strncmp(code, "012238", 6) == 0 &&
  2591. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES) {
  2592. isTrigger = true;
  2593. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
  2594. }
  2595. if (isTrigger) {
  2596. ReleaseChargingProcessByString(level);
  2597. InformOcppErrOccur(6);
  2598. }
  2599. }
  2600. //===============================================
  2601. // 確認硬體 (按鈕) 狀態
  2602. //===============================================
  2603. bool leftBtnPush = false;
  2604. bool rightBtnPush = false;
  2605. void ChkPrimaryStatus()
  2606. {
  2607. uint8_t Rtn;
  2608. if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
  2609. Rtn = 0;
  2610. for (uint8_t i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
  2611. if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042251", 6) == 0) {
  2612. EmcOccureByString("042251");
  2613. Rtn = 1;
  2614. } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042252", 6) == 0) {
  2615. EmcOccureByString("042252");
  2616. Rtn = 1;
  2617. } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042200", 6) == 0) {
  2618. EmcOccureByString("042200");
  2619. Rtn = 1;
  2620. } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042201", 6) == 0) {
  2621. EmcOccureByString("042201");
  2622. Rtn = 1;
  2623. } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042202", 6) == 0) {
  2624. EmcOccureByString("042202");
  2625. Rtn = 1;
  2626. } else if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == 0) {
  2627. EmcOccureByString("012304");
  2628. Rtn = 1;
  2629. }
  2630. }
  2631. if (Rtn == 0) {
  2632. ReleaseEmsOccureByString(0, "042251");
  2633. ReleaseEmsOccureByString(0, "042252");
  2634. ReleaseEmsOccureByString(0, "042200");
  2635. ReleaseEmsOccureByString(0, "042201");
  2636. ReleaseEmsOccureByString(0, "042202");
  2637. ReleaseEmsOccureByString(0, "012304");
  2638. }
  2639. } else {
  2640. ReleaseEmsOccureByString(0, "042251");
  2641. ReleaseEmsOccureByString(0, "042252");
  2642. ReleaseEmsOccureByString(0, "042200");
  2643. ReleaseEmsOccureByString(0, "042201");
  2644. ReleaseEmsOccureByString(0, "042202");
  2645. ReleaseEmsOccureByString(0, "012304");
  2646. }
  2647. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL) {
  2648. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
  2649. EmcOccureByString("012251");
  2650. } else {
  2651. ReleaseEmsOccureByString(0, "012251");
  2652. }
  2653. if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL) {
  2654. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
  2655. EmcOccureByString("012238");
  2656. } else {
  2657. ReleaseEmsOccureByString(0, "012238");
  2658. }
  2659. if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL) {
  2660. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
  2661. } else {
  2662. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
  2663. }
  2664. if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL) {
  2665. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
  2666. EmcOccureByString("012252");
  2667. } else {
  2668. ReleaseEmsOccureByString(0, "012252");
  2669. }
  2670. //DS60-120 add
  2671. //if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
  2672. // ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS) {
  2673. // ShmSysConfigAndInfo->SysConfig.ShowInformation = YES;
  2674. //} else {
  2675. // ShmSysConfigAndInfo->SysConfig.ShowInformation = NO;
  2676. //}
  2677. if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
  2678. !leftBtnPush
  2679. #if defined DD360Audi
  2680. &&
  2681. getCurLcmPage() != _LCM_AUTHORIZING &&
  2682. getCurLcmPage() != _LCM_AUTHORIZ_COMP &&
  2683. getCurLcmPage() != _LCM_AUTHORIZ_FAIL
  2684. #endif //defined DD360Audi
  2685. ) {
  2686. if (!leftBtnPush) {
  2687. leftBtnPush = true;
  2688. log_info("left btn down...............................%x\n",
  2689. chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus);
  2690. if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
  2691. switch (ac_chargingInfo[0]->SystemStatus) {
  2692. case S_IDLE: {
  2693. if (isDetectPlugin()) {
  2694. _DetectPlugInTimeout();
  2695. StopSystemTimeoutDet();
  2696. }
  2697. }
  2698. break;
  2699. case S_REASSIGN_CHECK:
  2700. case S_REASSIGN:
  2701. case S_PREPARNING:
  2702. case S_PREPARING_FOR_EV:
  2703. case S_PREPARING_FOR_EVSE:
  2704. case S_CCS_PRECHARGE_ST0:
  2705. case S_CCS_PRECHARGE_ST1: {
  2706. // 取消充電
  2707. AcChargingTerminalProcess();
  2708. }
  2709. break;
  2710. case S_CHARGING: {
  2711. if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
  2712. // 停止充電
  2713. AcChargingTerminalProcess();
  2714. }
  2715. }
  2716. break;
  2717. case S_COMPLETE:
  2718. {}
  2719. break;
  2720. }
  2721. }
  2722. switch (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
  2723. case S_IDLE: {
  2724. if (isDetectPlugin()) {
  2725. _DetectPlugInTimeout();
  2726. StopSystemTimeoutDet();
  2727. destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2728. }
  2729. #if defined DD360Audi
  2730. else {
  2731. if (getConfirmSelectedGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected) == PASS) {
  2732. //printf("destroy gun = %d\r\n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2733. destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2734. } else {
  2735. confirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2736. log_info("confirm select gun ............................... %d \n",
  2737. ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2738. }
  2739. }
  2740. #endif //defined DD360Audi
  2741. }
  2742. break;
  2743. case S_REASSIGN_CHECK:
  2744. case S_REASSIGN:
  2745. case S_PREPARNING:
  2746. case S_PREPARING_FOR_EV:
  2747. case S_PREPARING_FOR_EVSE:
  2748. case S_CCS_PRECHARGE_ST0:
  2749. case S_CCS_PRECHARGE_ST1: {
  2750. // 取消充電
  2751. if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
  2752. AcChargingTerminalProcess();
  2753. } else {
  2754. ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2755. }
  2756. }
  2757. break;
  2758. case S_CHARGING: {
  2759. if (ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES ||
  2760. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
  2761. // 停止充電
  2762. ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2763. }
  2764. }
  2765. break;
  2766. case S_COMPLETE: {
  2767. // 回 IDLE
  2768. //log_info("right btn down.................S_COMPLETE \n");
  2769. //chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_IDLE;
  2770. }
  2771. break;
  2772. }
  2773. }
  2774. } else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE) {
  2775. if (leftBtnPush) {
  2776. leftBtnPush = false;
  2777. //log_info("left btn up............................... \n");
  2778. }
  2779. }
  2780. if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS &&
  2781. !rightBtnPush
  2782. #if defined DD360Audi
  2783. &&
  2784. getCurLcmPage() != _LCM_IDLE &&
  2785. getCurLcmPage() != _LCM_AUTHORIZING &&
  2786. getCurLcmPage() != _LCM_AUTHORIZ_COMP &&
  2787. getCurLcmPage() != _LCM_AUTHORIZ_FAIL &&
  2788. getCurLcmPage() != _LCM_WAIT_FOR_PLUG
  2789. #endif //defined DD360Audi
  2790. ) {
  2791. if (!rightBtnPush) {
  2792. rightBtnPush = true;
  2793. //log_info("right btn down............................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2794. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
  2795. ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO) {
  2796. ShmSysConfigAndInfo->SysInfo.CurGunSelected++;
  2797. ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2798. } else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  2799. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE) {
  2800. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  2801. } else if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
  2802. for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  2803. if (chargingInfo[_index]->SystemStatus != S_BOOTING &&
  2804. chargingInfo[_index]->SystemStatus != S_IDLE &&
  2805. chargingInfo[_index]->SystemStatus != S_RESERVATION) {
  2806. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  2807. ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2808. return;
  2809. }
  2810. }
  2811. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  2812. ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2813. } else {
  2814. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  2815. ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2816. }
  2817. }
  2818. log_info("current select gun ............................... %d \n",
  2819. ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  2820. } else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE) {
  2821. if (rightBtnPush) {
  2822. rightBtnPush = false;
  2823. //log_info("right btn up............................... \n");
  2824. }
  2825. }
  2826. }
  2827. //===============================================
  2828. // 確認各小板偵測的錯誤狀況
  2829. //===============================================
  2830. void CheckErrorOccurStatus(uint8_t index)
  2831. {
  2832. #if 0
  2833. // 小板
  2834. if (chargingInfo[index]->Type == _Type_Chademo) {
  2835. if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
  2836. BoardErrOccurByString(index, "011012");
  2837. }
  2838. // else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
  2839. // BoardErrOccurByString(index, "012234");
  2840. } else if (chargingInfo[index]->Type == _Type_GB) {
  2841. if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
  2842. BoardErrOccurByString(index, "011016");
  2843. }
  2844. // else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
  2845. // BoardErrOccurByString(index, "012236");
  2846. } else if (chargingInfo[index]->Type == _Type_CCS_2) {
  2847. if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
  2848. BoardErrOccurByString(index, "011014");
  2849. }
  2850. // else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
  2851. // BoardErrOccurByString(index, "012235");
  2852. }
  2853. #endif //0
  2854. // RB
  2855. if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES) {
  2856. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
  2857. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
  2858. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
  2859. if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
  2860. ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
  2861. StopChargingProcessByString(2);
  2862. InformOcppErrOccur(13);
  2863. }
  2864. //DS60-120 add -----
  2865. if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
  2866. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES) {
  2867. memcpy(chargingInfo[index]->ConnectorAlarmCode, "012203", 6);
  2868. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES) {
  2869. memcpy(chargingInfo[index]->ConnectorAlarmCode, "012204", 6);
  2870. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES) {
  2871. memcpy(chargingInfo[index]->ConnectorAlarmCode, "012205", 6);
  2872. }
  2873. }
  2874. //log_info("1 CheckErrorOccurStatus\r\n");
  2875. chargingInfo[index]->StopChargeFlag = YES;
  2876. //------------------------------------------------------------------
  2877. } else {
  2878. if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
  2879. ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  2880. ReleaseChargingProcessByString(2);
  2881. InformOcppErrOccur(6);
  2882. }
  2883. }
  2884. } else {
  2885. if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
  2886. ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  2887. ReleaseChargingProcessByString(2);
  2888. InformOcppErrOccur(6);
  2889. }
  2890. }
  2891. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
  2892. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
  2893. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES) {
  2894. if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
  2895. ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
  2896. StopChargingProcessByString(2);
  2897. InformOcppErrOccur(14);
  2898. }
  2899. //DS60-120 -----
  2900. if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL) {
  2901. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES) {
  2902. memcpy(chargingInfo[index]->ConnectorAlarmCode, "012200", 6);
  2903. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES) {
  2904. memcpy(chargingInfo[index]->ConnectorAlarmCode, "012201", 6);
  2905. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES) {
  2906. memcpy(chargingInfo[index]->ConnectorAlarmCode, "012202", 6);
  2907. }
  2908. }
  2909. //log_info("2 CheckErrorOccurStatus\r\n");
  2910. chargingInfo[index]->StopChargeFlag = YES;
  2911. //----------------------------------------------------------------------
  2912. } else {
  2913. if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP) {
  2914. ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
  2915. ReleaseChargingProcessByString(2);
  2916. InformOcppErrOccur(6);
  2917. }
  2918. }
  2919. //DS60-120 ----
  2920. //if (chargingInfo[index]->Type == _Type_Chademo) {
  2921. // if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding == YES) {
  2922. // memcpy(chargingInfo[index]->ConnectorAlarmCode, "011011", 6);
  2923. // } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES) {
  2924. // memcpy(chargingInfo[index]->ConnectorAlarmCode, "011012", 6);
  2925. // } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
  2926. // memcpy(chargingInfo[index]->ConnectorAlarmCode, "012217", 6);
  2927. // }
  2928. //} else if (chargingInfo[index]->Type == _Type_GB) {
  2929. // if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding == YES) {
  2930. // memcpy(chargingInfo[index]->ConnectorAlarmCode, "011015", 6);
  2931. // } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES) {
  2932. // memcpy(chargingInfo[index]->ConnectorAlarmCode, "011016", 6);
  2933. // } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
  2934. // memcpy(chargingInfo[index]->ConnectorAlarmCode, "012221", 6);
  2935. // }
  2936. //} else if (chargingInfo[index]->Type == _Type_CCS_2) {
  2937. // if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding == YES) {
  2938. // memcpy(chargingInfo[index]->ConnectorAlarmCode, "011013", 6);
  2939. // } else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES) {
  2940. // memcpy(chargingInfo[index]->ConnectorAlarmCode, "011014", 6);
  2941. // } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
  2942. // memcpy(chargingInfo[index]->ConnectorAlarmCode, "012219", 6);
  2943. // }
  2944. //}
  2945. //--------------------------------------------------------------------------
  2946. if (strlen((char *)chargingInfo[index]->ConnectorAlarmCode) == 0) {
  2947. //Primary
  2948. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES) {
  2949. memcpy(chargingInfo[index]->ConnectorAlarmCode, "012251", 6);
  2950. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES) {
  2951. memcpy(chargingInfo[index]->ConnectorAlarmCode, "012252", 6);
  2952. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES) {
  2953. memcpy(chargingInfo[index]->ConnectorAlarmCode, "012238", 6);
  2954. } else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo == YES) {
  2955. memcpy(chargingInfo[index]->ConnectorAlarmCode, "012304", 6);
  2956. }
  2957. }
  2958. }
  2959. //===============================================
  2960. // 確認 GPIO 狀態
  2961. //===============================================
  2962. void gpio_set_value(unsigned int gpio, unsigned int value)
  2963. {
  2964. int fd;
  2965. char buf[MAX_BUF];
  2966. snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
  2967. fd = open(buf, O_WRONLY);
  2968. if (fd < 0) {
  2969. perror("gpio/set-value");
  2970. return;
  2971. }
  2972. if (value) {
  2973. write(fd, "1", 2);
  2974. } else {
  2975. write(fd, "0", 2);
  2976. }
  2977. close(fd);
  2978. }
  2979. int gpio_get_value(unsigned int gpio, unsigned int *value)
  2980. {
  2981. int fd;
  2982. char buf[MAX_BUF];
  2983. char ch;
  2984. snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
  2985. fd = open(buf, O_RDONLY);
  2986. if (fd < 0) {
  2987. perror("gpio/get-value");
  2988. return fd;
  2989. }
  2990. read(fd, &ch, 1);
  2991. if (ch != '0') {
  2992. *value = 1;
  2993. } else {
  2994. *value = 0;
  2995. }
  2996. close(fd);
  2997. return 0;
  2998. }
  2999. void CheckGunTypeFromHw()
  3000. {
  3001. uint8_t i = 0;
  3002. int pinIn[4] = {22, 23, 44, 45};
  3003. unsigned int gpioValue = 0;
  3004. uint8_t tmp[2] = {0};
  3005. log_info("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
  3006. for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
  3007. gpio_get_value(pinIn[i], &gpioValue);
  3008. switch (pinIn[i]) {
  3009. //right slot
  3010. case 22:
  3011. bd1_1_status = gpioValue;
  3012. break;
  3013. case 23:
  3014. bd1_2_status = gpioValue;
  3015. break;
  3016. //left slot
  3017. case 44:
  3018. bd0_1_status = gpioValue;
  3019. break;
  3020. case 45:
  3021. bd0_2_status = gpioValue;
  3022. break;
  3023. }
  3024. }
  3025. #if 1 //DS60-120 remove
  3026. //BD1(Left-CCS-CND1-SMR2-左槍), BD2(Right-CHADEMO-CND2-SMR1-右槍), CCS: 10 , CHAdeMO: 01 , GBT: 11
  3027. //CcsChargingData [0至1] 分別為 Right至Left
  3028. //model name 槍順序左至右分別為Right至Left
  3029. tmp[1] = (bd0_1_status << 4 | bd0_2_status);
  3030. tmp[0] = (bd1_1_status << 4 | bd1_2_status);
  3031. for (i = 0; i < 2; i++) {
  3032. switch (tmp[i]) {
  3033. case 0x01:
  3034. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CHAdeMO");
  3035. break;
  3036. case 0x10:
  3037. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CCS");
  3038. break;
  3039. case 0x11:
  3040. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "GBT");
  3041. break;
  3042. case 0x00:
  3043. log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "None");
  3044. break;
  3045. }
  3046. }
  3047. #endif //0
  3048. }
  3049. void CheckGpioInStatus()
  3050. {
  3051. int pinIn[2] = { 27, 47 };//{IO BD1_2, IO BD2_2}
  3052. unsigned int gpioValue = 0;
  3053. for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
  3054. gpio_get_value(pinIn[i], &gpioValue);
  3055. if (gpioValue == 0x01) {
  3056. switch (pinIn[i]) {
  3057. // 小板緊急停止
  3058. case 47: {
  3059. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
  3060. if (chargingInfo[i]->slotsIndex == 1) {
  3061. if (chargingInfo[i]->Type == _Type_Chademo) {
  3062. BoardErrOccurByString(i, "023730");
  3063. } else if (chargingInfo[i]->Type == _Type_CCS_2) {
  3064. BoardErrOccurByString(i, "013627");
  3065. }
  3066. break;
  3067. }
  3068. }
  3069. }
  3070. break;
  3071. case 27: {
  3072. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
  3073. if (chargingInfo[i]->slotsIndex == 3) {
  3074. if (chargingInfo[i]->Type == _Type_Chademo) {
  3075. BoardErrOccurByString(i, "023730");
  3076. } else if (chargingInfo[i]->Type == _Type_CCS_2) {
  3077. BoardErrOccurByString(i, "013627");
  3078. }
  3079. break;
  3080. }
  3081. }
  3082. }
  3083. break;
  3084. }
  3085. } else {
  3086. switch (pinIn[i]) {
  3087. // 小板解除緊急停止
  3088. case 47: {
  3089. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
  3090. if (chargingInfo[i]->slotsIndex == 1) {
  3091. if (chargingInfo[i]->Type == _Type_Chademo) {
  3092. ReleaseBoardErrOccurByString(i, "023730");
  3093. } else if (chargingInfo[i]->Type == _Type_CCS_2) {
  3094. ReleaseBoardErrOccurByString(i, "013627");
  3095. }
  3096. break;
  3097. }
  3098. }
  3099. }
  3100. break;
  3101. case 27: {
  3102. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
  3103. if (chargingInfo[i]->slotsIndex == 3) {
  3104. if (chargingInfo[i]->Type == _Type_Chademo) {
  3105. ReleaseBoardErrOccurByString(i, "023730");
  3106. } else if (chargingInfo[i]->Type == _Type_CCS_2) {
  3107. ReleaseBoardErrOccurByString(i, "013627");
  3108. }
  3109. break;
  3110. }
  3111. }
  3112. }
  3113. break;
  3114. }
  3115. }
  3116. }
  3117. }
  3118. //===============================================
  3119. // Main process
  3120. //===============================================
  3121. // 檢查 uint8_t 中某個 Bit 的值
  3122. // _byte : 欲改變的 byte
  3123. // _bit : 該 byte 的第幾個 bit
  3124. uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit)
  3125. {
  3126. return ( _byte & mask_table[_bit] ) != 0x00;
  3127. }
  3128. // 設定 Byte 中某個 Bit的值
  3129. // _byte : 欲改變的 byte
  3130. // _bit : 該 byte 的第幾個 bit
  3131. // value : 修改的值為 0 or 1
  3132. void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value)
  3133. {
  3134. if (value == 1) {
  3135. *_byte |= (1 << _bit);
  3136. } else if (value == 0) {
  3137. *_byte ^= (1 << _bit);
  3138. }
  3139. }
  3140. void UserScanFunction()
  3141. {
  3142. bool idleReq = false;
  3143. uint8_t stopReq = 255;
  3144. // 當前非驗證的狀態
  3145. if (!IsAuthorizingMode()) {
  3146. #if defined DD360Audi
  3147. //當前沒有選槍
  3148. if (getConfirmSelectedGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected) == FAIL) { //Jerry add
  3149. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3150. return;
  3151. }
  3152. #endif //defined DD360Audi
  3153. // 先判斷現在是否可以提供刷卡
  3154. // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
  3155. // 2. 停止充電
  3156. if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) {
  3157. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3158. return;
  3159. }
  3160. for (uint8_t i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
  3161. if (chargingInfo[i]->SystemStatus == S_CHARGING) {
  3162. stopReq = i;
  3163. }
  3164. if ((chargingInfo[i]->SystemStatus == S_IDLE &&
  3165. chargingInfo[i]->IsAvailable) == YES ||
  3166. (_acgunIndex > 0 && ac_chargingInfo[0]->SystemStatus ==
  3167. S_IDLE && ac_chargingInfo[0]->IsAvailable)
  3168. ) {
  3169. idleReq = true;
  3170. }
  3171. }
  3172. if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
  3173. ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
  3174. stopReq = DEFAULT_AC_INDEX;
  3175. }
  3176. if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0) {
  3177. if (_acgunIndex > 0 && stopReq == DEFAULT_AC_INDEX &&
  3178. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) {
  3179. char value[32];
  3180. log_info("ac stop charging \n");
  3181. log_info("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
  3182. ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
  3183. memcpy(value, (uint8_t *)ac_chargingInfo[0]->StartUserId,
  3184. ARRAY_SIZE(ac_chargingInfo[0]->StartUserId));
  3185. if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL) {
  3186. AcChargingTerminalProcess();
  3187. }
  3188. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3189. } else if (stopReq < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
  3190. chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING &&
  3191. (_acgunIndex <= 0 || (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE))) {
  3192. char value[32];
  3193. log_info("stop charging \n");
  3194. log_info("index = %d, card number = %s, UserId = %s \n",
  3195. ShmSysConfigAndInfo->SysInfo.CurGunSelected,
  3196. chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
  3197. ShmSysConfigAndInfo->SysConfig.UserId);
  3198. memcpy(value, (uint8_t *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
  3199. ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
  3200. // 同一張卡直接停掉
  3201. if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL) {
  3202. ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  3203. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3204. } else {
  3205. // 進驗證
  3206. if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) {
  3207. _authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
  3208. } else {
  3209. _authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
  3210. }
  3211. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  3212. StartSystemTimeoutDet(Timeout_AuthorizingForStop);
  3213. AuthorizingStart();
  3214. #else
  3215. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3216. #endif //!defined DD360 && !defined DD360Audi
  3217. }
  3218. } else if (idleReq) {
  3219. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
  3220. stopReq != 255 &&
  3221. ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
  3222. idleReq = false;
  3223. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3224. } else if ((_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
  3225. chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE) {
  3226. log_info("// LCM => Authorizing \n");
  3227. #if defined DD360Audi
  3228. setSelGunWaitToAuthor(ShmSysConfigAndInfo->SysInfo.CurGunSelected); //Jerry add
  3229. #endif //defined DD360Audi
  3230. // LCM => Authorizing
  3231. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
  3232. // 進入確認卡號狀態
  3233. AuthorizingStart();
  3234. } else {
  3235. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3236. }
  3237. } else {
  3238. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3239. }
  3240. }
  3241. } else {
  3242. // 透過後臺停止充電的判斷
  3243. if (isAuthorizedComplete()
  3244. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  3245. || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
  3246. ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
  3247. #endif //!defined DD360 && !defined DD360Audi
  3248. ) {
  3249. // 判斷後台回覆狀態
  3250. if (canStartCharging()
  3251. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  3252. || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
  3253. ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
  3254. #endif //!defined DD360 && !defined DD360Audi
  3255. ) {
  3256. if (_authorizeIndex != NO_DEFINE) {
  3257. // 先找 AC
  3258. if (_authorizeIndex == DEFAULT_AC_INDEX) {
  3259. if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
  3260. strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL) {
  3261. AcChargingTerminalProcess();
  3262. }
  3263. } else {
  3264. if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
  3265. strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL) {
  3266. ChargingTerminalProcess(_authorizeIndex);
  3267. }
  3268. }
  3269. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3270. _authorizeIndex = NO_DEFINE;
  3271. }
  3272. } else {
  3273. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3274. }
  3275. ClearAuthorizedFlag();
  3276. } else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
  3277. // 白名單驗證
  3278. for (int i = 0; i < 10; i++) {
  3279. if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL) {
  3280. if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL) {
  3281. ChargingTerminalProcess(_authorizeIndex);
  3282. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3283. ClearAuthorizedFlag();
  3284. break;
  3285. }
  3286. }
  3287. }
  3288. }
  3289. }
  3290. }
  3291. uint8_t isModeChange(uint8_t gun_index)
  3292. {
  3293. uint8_t result = NO;
  3294. if (chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus) {
  3295. result = YES;
  3296. chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
  3297. }
  3298. return result;
  3299. }
  3300. void ScannerCardProcess()
  3301. {
  3302. if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level != 2 &&
  3303. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
  3304. isCardScan = true;
  3305. // 處理刷卡及驗證卡號的動作
  3306. UserScanFunction();
  3307. }
  3308. if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING) {
  3309. StartSystemTimeoutDet(Timeout_Authorizing);
  3310. // 確認驗證卡號完成沒
  3311. if (isAuthorizedComplete()
  3312. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  3313. || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
  3314. #else
  3315. && gAudiCustInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance != FAIL_BALANCE_PRICES
  3316. #endif //!defined DD360 && !defined DD360Audi
  3317. ) {
  3318. StopSystemTimeoutDet();
  3319. // 判斷後台回覆狀態
  3320. if (canStartCharging()
  3321. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  3322. || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
  3323. #endif //!defined DD360 && !defined DD360Audi
  3324. ) {
  3325. // LCM => Authorize complete
  3326. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
  3327. } else {
  3328. // LCM => Authorize fail
  3329. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
  3330. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  3331. }
  3332. ClearAuthorizedFlag();
  3333. } else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
  3334. // 白名單驗證
  3335. for (int i = 0; i < 10; i++) {
  3336. if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL) {
  3337. if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL) {
  3338. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
  3339. ClearAuthorizedFlag();
  3340. break;
  3341. }
  3342. }
  3343. }
  3344. }
  3345. } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL) {
  3346. StartSystemTimeoutDet(Timeout_VerifyFail);
  3347. isCardScan = false;
  3348. } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP) {
  3349. StartSystemTimeoutDet(Timeout_VerifyComp);
  3350. } else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG) {
  3351. StartSystemTimeoutDet(Timeout_WaitPlug);
  3352. } else {
  3353. isCardScan = false;
  3354. }
  3355. }
  3356. bool AddGunInfoByConnector(uint8_t typeValue, uint8_t slots)
  3357. {
  3358. bool result = true;
  3359. switch (typeValue) {
  3360. case '0': // none
  3361. break;
  3362. case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
  3363. break;
  3364. case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
  3365. break;
  3366. case '3': // IEC 62196-2 Type 2 Plug
  3367. case '4': // IEC 62196-2 Type 2 Socket
  3368. if (AC_QUANTITY > _ac_Index) {
  3369. ac_chargingInfo[_acgunIndex] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[_ac_Index];
  3370. // AC 固定 index
  3371. ac_chargingInfo[_acgunIndex]->Index = 0;
  3372. ac_chargingInfo[_acgunIndex]->ReservationId = -1;
  3373. ac_chargingInfo[_acgunIndex]->SystemStatus = S_IDLE;
  3374. ac_chargingInfo[_acgunIndex]->Type = _Type_AC;
  3375. ac_chargingInfo[_acgunIndex]->IsAvailable = YES;
  3376. ac_chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO; //DS60-120 add
  3377. ac_chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
  3378. _ac_Index++;
  3379. _acgunIndex++;
  3380. } else {
  3381. result = false;
  3382. }
  3383. break;
  3384. case '5': // GB/T AC Plug
  3385. break;
  3386. case '6': // GB/T AC Socket
  3387. break;
  3388. case 'J':
  3389. case 'K': { // CHAdeMO
  3390. if (CHAdeMO_QUANTITY > _chademoIndex) {
  3391. chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
  3392. chargingInfo[_gunIndex]->Index = _gunIndex;
  3393. chargingInfo[_gunIndex]->ReservationId = -1;
  3394. chargingInfo[_gunIndex]->slotsIndex = slots;
  3395. chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
  3396. chargingInfo[_gunIndex]->Type = _Type_Chademo;
  3397. chargingInfo[_gunIndex]->type_index = _chademoIndex;
  3398. chargingInfo[_gunIndex]->IsAvailable = YES;
  3399. chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO; //DS60-120 add
  3400. chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
  3401. _chademoIndex++;
  3402. _gunIndex++;
  3403. } else {
  3404. result = false;
  3405. }
  3406. }
  3407. break;
  3408. case 'T': //Rema CCS1
  3409. case 'D': //Rema CCS2
  3410. case 'U': // CCS1 combo
  3411. case 'E': // CCS2 combo
  3412. case 'V': // Liquid CCS1 combo
  3413. case 'F': { // Liquid CCS2 combo
  3414. if (CCS_QUANTITY > _ccsIndex) {
  3415. chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
  3416. chargingInfo[_gunIndex]->Index = _gunIndex;
  3417. chargingInfo[_gunIndex]->ReservationId = -1;
  3418. chargingInfo[_gunIndex]->slotsIndex = slots;
  3419. chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
  3420. chargingInfo[_gunIndex]->Type = _Type_CCS_2;
  3421. chargingInfo[_gunIndex]->type_index = _ccsIndex;
  3422. chargingInfo[_gunIndex]->IsAvailable = YES;
  3423. chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;//DS60-120 add
  3424. chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
  3425. // 現階段預設為走 DIN70121
  3426. ShmCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
  3427. _ccsIndex++;
  3428. _gunIndex++;
  3429. } else {
  3430. result = false;
  3431. }
  3432. }
  3433. break;
  3434. case 'G': { // GBT DC
  3435. if (GB_QUANTITY > _gb_Index) {
  3436. chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[_gb_Index];
  3437. chargingInfo[_gunIndex]->Index = _gunIndex;
  3438. chargingInfo[_gunIndex]->ReservationId = -1;
  3439. chargingInfo[_gunIndex]->slotsIndex = slots;
  3440. chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
  3441. chargingInfo[_gunIndex]->Type = _Type_GB;
  3442. chargingInfo[_gunIndex]->type_index = _gb_Index;
  3443. chargingInfo[_gunIndex]->IsAvailable = YES;
  3444. chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;//DS60-120 add
  3445. chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO; //DS60-120 add
  3446. _gb_Index++;
  3447. _gunIndex++;
  3448. } else {
  3449. result = false;
  3450. }
  3451. }
  3452. break;
  3453. //case 'D': // GBT DC x 2
  3454. // break;
  3455. }
  3456. return result;
  3457. }
  3458. bool CheckConnectorTypeStatus()
  3459. {
  3460. bool result = true;
  3461. //log_info("bd0_1_status = %d, bd0_2_status = %d, bd1_1_status = %d, bd1_2_status = %d \n",
  3462. // bd0_1_status,
  3463. // bd0_2_status,
  3464. // bd1_1_status,
  3465. // bd1_2_status);
  3466. if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9) {
  3467. //printf("1 CheckConnectorTypeStatus\r\n");
  3468. uint8_t slots = 1;
  3469. for (uint8_t typeIndex = 7; typeIndex <= 9; typeIndex++) {
  3470. if (!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots)) {
  3471. return false;
  3472. }
  3473. slots++;
  3474. }
  3475. // AC index 接在 DC 後面
  3476. //if (AC_QUANTITY > 0) {
  3477. if (_ac_Index > 0) { //DS60-120 add
  3478. ac_chargingInfo[0]->Index += _gunIndex;
  3479. }
  3480. ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
  3481. ShmSysConfigAndInfo->SysConfig.AcConnectorCount = _acgunIndex;
  3482. log_info("DC connector Quality = %d, AC connector Quality = %d",
  3483. ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
  3484. ShmSysConfigAndInfo->SysConfig.AcConnectorCount);
  3485. log_info("Type 0~3 = CHAdeMO, CCS, GB, AC");
  3486. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0 &&
  3487. ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0) {
  3488. result = false;
  3489. }
  3490. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
  3491. //DS60-120 add
  3492. bool isFind = false;
  3493. if (chargingInfo[0]->Type == _Type_Chademo) {
  3494. if ((bd0_1_status == 0 && bd0_2_status == 1) ||
  3495. (bd1_1_status == 0 && bd1_2_status == 1)) {
  3496. isFind = true;
  3497. }
  3498. } else if (chargingInfo[0]->Type == _Type_CCS_2) {
  3499. if ((bd0_1_status == 1 && bd0_2_status == 0) ||
  3500. (bd1_1_status == 1 && bd1_2_status == 0)) {
  3501. isFind = true;
  3502. }
  3503. } else if (chargingInfo[0]->Type == _Type_GB) {
  3504. if ((bd0_1_status == 1 && bd0_2_status == 1) ||
  3505. (bd1_1_status == 1 && bd1_2_status == 1)) {
  3506. isFind = true;
  3507. }
  3508. }
  3509. if (isFind) {
  3510. //if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "0", 1) != 0) {
  3511. // if (bd0_1_status == 1 || bd0_2_status == 1) {
  3512. // chargingInfo[0]->Evboard_id = 0x01;
  3513. // } else if (bd1_1_status == 1 || bd1_2_status == 1) {
  3514. // chargingInfo[0]->Evboard_id = 0x02;
  3515. // }
  3516. //} else if (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "0", 1) != 0) {
  3517. // if (bd0_1_status == 1 || bd0_2_status == 1) {
  3518. // chargingInfo[0]->Evboard_id = 0x01;
  3519. // } else if (bd1_1_status == 1 || bd1_2_status == 1) {
  3520. // chargingInfo[0]->Evboard_id = 0x02;
  3521. // }
  3522. //} else {
  3523. // chargingInfo[0]->Evboard_id = 0x01;
  3524. //}
  3525. if (bd0_1_status == 1 || bd0_2_status == 1) {
  3526. chargingInfo[0]->Evboard_id = 0x01;
  3527. }
  3528. if (bd1_1_status == 1 || bd1_2_status == 1) {
  3529. chargingInfo[0]->Evboard_id = 0x02;
  3530. }
  3531. CheckHwSlotStatusLog(0);
  3532. } else {
  3533. result = false;
  3534. }
  3535. //chargingInfo[0]->Evboard_id = 0x01;
  3536. log_info("index = %d, Type = %d, Evboard_id = %d", 0, chargingInfo[0]->Type, chargingInfo[0]->Evboard_id);
  3537. } else {
  3538. char type = NO_DEFINE; //DS60-120 add
  3539. // 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
  3540. for (uint8_t gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++) {
  3541. if (gunIndex == 0 && bd0_1_status == 0 && bd0_2_status == 1) {
  3542. // 與硬體相同 type : Chademo
  3543. if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
  3544. chargingInfo[gunIndex]->Evboard_id = 0x01;
  3545. }
  3546. } else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 0) {
  3547. // 與硬體相同 type : CCS
  3548. if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
  3549. chargingInfo[gunIndex]->Evboard_id = 0x01;
  3550. }
  3551. } else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 1) {
  3552. // 與硬體相同 type : GB
  3553. if (chargingInfo[gunIndex]->Type == _Type_GB) {
  3554. chargingInfo[gunIndex]->Evboard_id = 0x01;
  3555. }
  3556. }
  3557. if (gunIndex == 1 && bd1_1_status == 0 && bd1_2_status == 1) {
  3558. // 與硬體相同 type : Chademo
  3559. if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
  3560. chargingInfo[gunIndex]->Evboard_id = 0x02;
  3561. }
  3562. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
  3563. chargingInfo[gunIndex]->Evboard_id = 0x01;
  3564. }
  3565. } else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 0) {
  3566. // 與硬體相同 type : CCS
  3567. if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
  3568. chargingInfo[gunIndex]->Evboard_id = 0x02;
  3569. }
  3570. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
  3571. chargingInfo[gunIndex]->Evboard_id = 0x01;
  3572. }
  3573. } else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 1) {
  3574. // 與硬體相同 type : GB
  3575. if (chargingInfo[gunIndex]->Type == _Type_GB) {
  3576. chargingInfo[gunIndex]->Evboard_id = 0x02;
  3577. }
  3578. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1) {
  3579. chargingInfo[gunIndex]->Evboard_id = 0x01;
  3580. }
  3581. }
  3582. log_info("index = %d, Type = %d, Evboard_id = %d",
  3583. gunIndex,
  3584. chargingInfo[gunIndex]->Type,
  3585. chargingInfo[gunIndex]->Evboard_id);
  3586. CheckHwSlotStatusLog(gunIndex);
  3587. if (type == NO_DEFINE) {
  3588. type = chargingInfo[gunIndex]->Type;
  3589. }
  3590. if (chargingInfo[gunIndex]->Evboard_id == 0x00) {
  3591. result = false;
  3592. }
  3593. }
  3594. }
  3595. } else {
  3596. // Module Name 不正確 - 告警
  3597. result = false;
  3598. }
  3599. return result;
  3600. }
  3601. void KillTask()
  3602. {
  3603. ChangeLcmByIndex(_LCM_FIX);
  3604. system("killall Module_EventLogging");
  3605. system("killall Module_PrimaryComm");
  3606. system("killall Module_EvComm");
  3607. system("killall Module_LcmControl");
  3608. system("killall Module_InternalComm");
  3609. //system("killall Module_DoComm");
  3610. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  3611. system("killall Module_PsuComm");
  3612. system("killall OcppBackend &");
  3613. system("killall Module_4g &");
  3614. system("killall Module_Wifi &");
  3615. #endif //!defined DD360 && !defined DD360Audi
  3616. }
  3617. void KillTaskExceptPrimary()
  3618. {
  3619. ChangeLcmByIndex(_LCM_FIX);
  3620. system("killall Module_EvComm");
  3621. system("killall Module_InternalComm");
  3622. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  3623. system("killall Module_PsuComm");
  3624. system("killall Module_4g &");
  3625. system("killall Module_Wifi &");
  3626. #endif //!defined DD360 && !defined DD360Audi
  3627. }
  3628. void KillAllTask()
  3629. {
  3630. ChangeLcmByIndex(_LCM_FIX);
  3631. system("killall Module_EventLogging");
  3632. system("killall Module_PrimaryComm");
  3633. system("killall Module_EvComm");
  3634. system("killall Module_LcmControl");
  3635. system("killall Module_InternalComm");
  3636. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  3637. system("killall Module_PsuComm");
  3638. system("killall OcppBackend &");
  3639. system("killall Module_4g &");
  3640. system("killall Module_Wifi &");
  3641. #else
  3642. system("killall Module_DoComm");
  3643. #endif //!defined DD360 && !defined DD360Audi
  3644. }
  3645. int CheckUpdateProcess(void)
  3646. {
  3647. //bool isPass = true;
  3648. uint8_t retSucc = 0;
  3649. uint8_t retFail = 0;
  3650. uint8_t index = 0;
  3651. uint8_t target = 0;
  3652. char Buf[256];
  3653. char *new_str = NULL;
  3654. uint8_t *ptr = NULL;
  3655. int fd = 0;
  3656. int CanFd = 0;
  3657. int uartFd = 0;
  3658. unsigned int Type = 0;
  3659. long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
  3660. DIR *d;
  3661. struct dirent *dir;
  3662. d = opendir("/mnt/");
  3663. if (d) {
  3664. while ((dir = readdir(d)) != NULL) {
  3665. if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
  3666. continue;
  3667. }
  3668. new_str = calloc(strlen("/mnt/") + strlen(dir->d_name) + 1, sizeof(char));
  3669. //new_str[0] = '\0';
  3670. strcat(new_str, "/mnt/");
  3671. strcat(new_str, dir->d_name);
  3672. log_info("%s%s\r\n", "/mnt/", dir->d_name);
  3673. fd = open(new_str, O_RDONLY);
  3674. if (fd < 0) {
  3675. return FAIL;
  3676. }
  3677. ptr = calloc(MaxLen, sizeof(char)); //-48 is take out the header
  3678. //memset(ptr, 0xFF, MaxLen); //-48 is take out the header
  3679. //get the image length
  3680. ImageLen = read(fd, ptr, MaxLen);
  3681. for (uint8_t i = 0; i < 16; i++) {
  3682. if (ShmSysConfigAndInfo->SysConfig.ModelName[i] != ptr[i]) {
  3683. return FAIL;
  3684. }
  3685. }
  3686. log_info("model name check pass. \n");
  3687. if (ImageLen > 20) {
  3688. Type = (((unsigned int)ptr[16]) << 24 |
  3689. ((unsigned int)ptr[17]) << 16 |
  3690. ((unsigned int)ptr[18]) << 8 |
  3691. ((unsigned int)ptr[19]));
  3692. log_info("Typed...%x \r\n", Type);
  3693. switch (Type) {
  3694. case 0x10000001:
  3695. case 0x10000002:
  3696. case 0x10000003:
  3697. case 0x10000004:
  3698. case 0x10000005:
  3699. if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
  3700. //return PASS;
  3701. retSucc++;
  3702. } else {
  3703. log_info("Upgrade %x Failed\r\n", Type);
  3704. //return FAIL;
  3705. retFail++;
  3706. }
  3707. break;
  3708. case 0x10000007:
  3709. case 0x10000008:
  3710. case 0x10000009:
  3711. case 0x1000000A:
  3712. CanFd = InitCanBus();
  3713. if (CanFd > 0) {
  3714. for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
  3715. if (chargingInfo[index]->Type == _Type_CCS_2) {
  3716. uint8_t targetID = chargingInfo[index]->Evboard_id;
  3717. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1 &&
  3718. ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
  3719. targetID += 1;
  3720. }
  3721. system("echo 3 > /proc/sys/vm/drop_caches");
  3722. sleep(2);
  3723. log_info("Upgrade CCS Processing..target id = %d \n", targetID);
  3724. if (Upgrade_CCS(CanFd, Type, targetID, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL) {
  3725. log_info("Upgrade CCS Failed \n");
  3726. retFail++;
  3727. } else {
  3728. retSucc++;
  3729. }
  3730. }
  3731. }
  3732. close(CanFd);
  3733. }
  3734. memset(Buf, 0, sizeof(Buf));
  3735. sprintf(Buf, "rm -rvf /mnt/%s", new_str);
  3736. system(Buf);
  3737. //isPass = true;
  3738. #if 0
  3739. CanFd = InitCanBus();
  3740. if (CanFd > 0) {
  3741. for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
  3742. //if (!isPass) {
  3743. // break;
  3744. //}
  3745. if (chargingInfo[index]->Type == _Type_CCS_2) {
  3746. if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL) {
  3747. //isPass = false;
  3748. log_info("Upgrade %x Failed\r\n", Type);
  3749. retFail++;
  3750. }
  3751. }
  3752. }
  3753. } else {
  3754. log_error("Upgrade CCS open CAN FD fail.\n");
  3755. //isPass = false;
  3756. return FAIL;
  3757. }
  3758. if (retFail != 0) {
  3759. break;
  3760. } else {
  3761. retSucc++;
  3762. }
  3763. //return isPass;
  3764. #endif //0
  3765. break;
  3766. case 0x10000006:
  3767. case 0x1000000D:
  3768. case 0x1000000E:
  3769. case 0x20000002:
  3770. case 0x10000014:
  3771. // CSU_PRIMARY_CONTROLLER : 0x10000006
  3772. target = 0x00;
  3773. if (Type == 0x10000006) {
  3774. target = UPGRADE_PRI;
  3775. } else if (Type == 0x1000000D) {
  3776. target = UPGRADE_RB;
  3777. } else if (Type == 0x1000000E) {
  3778. target = UPGRADE_FAN;
  3779. } else if (Type == 0x20000002) {
  3780. target = UPGRADE_AC;
  3781. } else if (Type == 0x10000014) {
  3782. target = UPGRADE_LED;
  3783. }
  3784. uartFd = InitComPort(target);
  3785. if (Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
  3786. //return PASS;
  3787. retSucc++;
  3788. } else {
  3789. log_info("Upgrade %x Failed\r\n", Type);
  3790. //return FAIL;
  3791. return FAIL;
  3792. }
  3793. if (uartFd > 0) {
  3794. close(uartFd);
  3795. }
  3796. break;
  3797. case 0x1000000B:
  3798. case 0x1000000C:
  3799. // CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
  3800. //bool isPass = true;
  3801. CanFd = InitCanBus();
  3802. if (CanFd > 0) {
  3803. for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
  3804. //if (!isPass) {
  3805. // break;
  3806. //}
  3807. if ((Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo) ||
  3808. (Type == 0x1000000C && chargingInfo[index]->Type == _Type_GB)) {
  3809. if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
  3810. //isPass = PASS;
  3811. retSucc++;
  3812. } else {
  3813. log_info("Upgrade %x Failed\r\n", Type);
  3814. //isPass = FAIL;
  3815. retFail++;
  3816. }
  3817. }
  3818. }
  3819. } else {
  3820. log_info("Upgrad FD fail. \n");
  3821. //isPass = false;
  3822. return FAIL;
  3823. }
  3824. //return isPass;
  3825. break;
  3826. }
  3827. }
  3828. free(new_str);
  3829. free(ptr);
  3830. }
  3831. }
  3832. free(dir);
  3833. closedir(d);
  3834. if (retFail != 0) {
  3835. return FAIL;
  3836. }
  3837. return PASS;
  3838. }
  3839. void CreateRfidFork()
  3840. {
  3841. pid_t rfidRecPid;
  3842. rfidRecPid = fork();
  3843. log_info("CreateRfidFork = %d\r\n", rfidRecPid);
  3844. if (rfidRecPid == 0) {
  3845. while (true) {
  3846. // 刷卡判斷
  3847. RFID rfid;
  3848. if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
  3849. !ShmSysConfigAndInfo->SysConfig.isRFID)
  3850. {}
  3851. else if (getRequestCardSN(rfidFd, 0, &rfid)) {
  3852. //log_info("Get Card..-%s- \n", ShmSysConfigAndInfo->SysConfig.UserId);
  3853. if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0) {
  3854. if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
  3855. switch (rfid.snType) {
  3856. case RFID_SN_TYPE_6BYTE:
  3857. sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
  3858. "%02X%02X%02X%02X%02X%02X",
  3859. rfid.currentCard[0], rfid.currentCard[1],
  3860. rfid.currentCard[2], rfid.currentCard[3],
  3861. rfid.currentCard[4], rfid.currentCard[5]);
  3862. break;
  3863. case RFID_SN_TYPE_7BYTE:
  3864. sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
  3865. "%02X%02X%02X%02X%02X%02X%02X",
  3866. rfid.currentCard[0], rfid.currentCard[1],
  3867. rfid.currentCard[2], rfid.currentCard[3],
  3868. rfid.currentCard[4], rfid.currentCard[5],
  3869. rfid.currentCard[6]);
  3870. break;
  3871. case RFID_SN_TYPE_10BYTE:
  3872. sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
  3873. "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
  3874. rfid.currentCard[0], rfid.currentCard[1],
  3875. rfid.currentCard[2], rfid.currentCard[3],
  3876. rfid.currentCard[4], rfid.currentCard[5],
  3877. rfid.currentCard[6], rfid.currentCard[7],
  3878. rfid.currentCard[8], rfid.currentCard[9]);
  3879. break;
  3880. case RFID_SN_TYPE_4BYTE:
  3881. sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
  3882. "%02X%02X%02X%02X",
  3883. rfid.currentCard[0], rfid.currentCard[1],
  3884. rfid.currentCard[2], rfid.currentCard[3]);
  3885. break;
  3886. }
  3887. } else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG) {
  3888. switch (rfid.snType) {
  3889. case RFID_SN_TYPE_6BYTE:
  3890. sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
  3891. "%02X%02X%02X%02X%02X%02X",
  3892. rfid.currentCard[5], rfid.currentCard[4],
  3893. rfid.currentCard[3], rfid.currentCard[2],
  3894. rfid.currentCard[1], rfid.currentCard[0]);
  3895. break;
  3896. case RFID_SN_TYPE_7BYTE:
  3897. sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
  3898. "%02X%02X%02X%02X%02X%02X%02X",
  3899. rfid.currentCard[6], rfid.currentCard[5],
  3900. rfid.currentCard[4], rfid.currentCard[3],
  3901. rfid.currentCard[2], rfid.currentCard[1],
  3902. rfid.currentCard[0]);
  3903. break;
  3904. case RFID_SN_TYPE_10BYTE:
  3905. sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
  3906. "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
  3907. rfid.currentCard[9], rfid.currentCard[8],
  3908. rfid.currentCard[7], rfid.currentCard[6],
  3909. rfid.currentCard[5], rfid.currentCard[4],
  3910. rfid.currentCard[3], rfid.currentCard[2],
  3911. rfid.currentCard[1], rfid.currentCard[0]);
  3912. break;
  3913. case RFID_SN_TYPE_4BYTE:
  3914. sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
  3915. "%02X%02X%02X%02X",
  3916. rfid.currentCard[3], rfid.currentCard[2],
  3917. rfid.currentCard[1], rfid.currentCard[0]);
  3918. break;
  3919. }
  3920. }
  3921. log_info("card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3922. }
  3923. }
  3924. usleep(500000);
  3925. }
  3926. }
  3927. }
  3928. void StartSystemTimeoutDet(uint8_t flag)
  3929. {
  3930. if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag) {
  3931. gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
  3932. }
  3933. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
  3934. }
  3935. void StopSystemTimeoutDet()
  3936. {
  3937. gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
  3938. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
  3939. }
  3940. void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
  3941. {
  3942. if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
  3943. if (chargingInfo[gunIndex]->TimeoutFlag != flag) {
  3944. gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
  3945. }
  3946. chargingInfo[gunIndex]->TimeoutFlag = flag;
  3947. }
  3948. }
  3949. void StopGunInfoTimeoutDet(uint8_t gunIndex)
  3950. {
  3951. if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
  3952. chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
  3953. }
  3954. }
  3955. void CheckConnectionTimeout(void)
  3956. {
  3957. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  3958. if (gAudiCustInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
  3959. _connectionTimeout = gAudiCustInfo->RemoteSetup.ConnectionTimeout;
  3960. } else {
  3961. _connectionTimeout = CONN_PLUG_TIME_OUT;
  3962. }
  3963. return;
  3964. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  3965. if (system("pidof -s OcppBackend > /dev/null") != 0) {
  3966. _connectionTimeout = CONN_PLUG_TIME_OUT;
  3967. } else {
  3968. if (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0) {
  3969. _connectionTimeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3970. if (_connectionTimeout <= 0) {
  3971. _connectionTimeout = CONN_PLUG_TIME_OUT;
  3972. }
  3973. } else {
  3974. _connectionTimeout = CONN_PLUG_TIME_OUT;
  3975. }
  3976. }
  3977. }
  3978. void CreateTimeoutFork()
  3979. {
  3980. pid_t timeoutPid;
  3981. timeoutPid = fork();
  3982. log_info("CreateTimeoutFork = %d\r\n", timeoutPid);
  3983. if (timeoutPid == 0) {
  3984. gettimeofday(&_cmdSubPriority_time, NULL);
  3985. CheckConnectionTimeout();
  3986. while (1) {
  3987. if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000) {
  3988. CheckConnectionTimeout();
  3989. gettimeofday(&_cmdSubPriority_time, NULL);
  3990. }
  3991. //printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
  3992. // 系統
  3993. switch (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag) {
  3994. case Timeout_SelftestChk:
  3995. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
  3996. _SelfTestTimeout();
  3997. StopSystemTimeoutDet();
  3998. destroySelGun(DESTROY_ALL_SEL); //jerry add
  3999. }
  4000. break;
  4001. case Timeout_Authorizing:
  4002. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
  4003. _AuthorizedTimeout();
  4004. StopSystemTimeoutDet();
  4005. destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  4006. if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
  4007. gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
  4008. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  4009. log_error("Author timeout restart DoComm\r\n");
  4010. system("killall Module_DoComm");
  4011. sleep(1);
  4012. system("/root/Module_DoComm &");
  4013. }
  4014. }
  4015. break;
  4016. case Timeout_VerifyFail:
  4017. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
  4018. _AutoReturnTimeout();
  4019. StopSystemTimeoutDet();
  4020. destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  4021. if (gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] == YES) { //DoComm no ask cabinet balance
  4022. gAudiCustInfo->AuthorStateFromCabinet[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = NO;
  4023. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
  4024. log_error("Author timeout restart DoComm\r\n");
  4025. system("killall Module_DoComm");
  4026. sleep(1);
  4027. system("/root/Module_DoComm &");
  4028. }
  4029. }
  4030. break;
  4031. case Timeout_VerifyComp:
  4032. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
  4033. _AutoReturnTimeout();
  4034. StopSystemTimeoutDet();
  4035. }
  4036. break;
  4037. case Timeout_WaitPlug:
  4038. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
  4039. _DetectPlugInTimeout();
  4040. StopSystemTimeoutDet();
  4041. destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  4042. }
  4043. break;
  4044. case Timeout_ReturnToChargingGunDet:
  4045. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
  4046. #if defined DD360Audi
  4047. if (getCurLcmPage() != _LCM_PRE_CHARGE &&
  4048. getCurLcmPage() != _LCM_CHARGING &&
  4049. getCurLcmPage() != _LCM_COMPLETE) {
  4050. destroySelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected); //jerry add
  4051. }
  4052. #endif //defined DD360Audi
  4053. DisplayChargingInfo();
  4054. StopSystemTimeoutDet();
  4055. }
  4056. break;
  4057. case Timeout_AuthorizingForStop:
  4058. if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
  4059. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  4060. ClearAuthorizedFlag();
  4061. StopSystemTimeoutDet();
  4062. }
  4063. break;
  4064. }
  4065. // 各槍
  4066. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  4067. //printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
  4068. switch (chargingInfo[gun_index]->TimeoutFlag) {
  4069. case Timeout_Preparing:
  4070. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
  4071. _PrepareTimeout(gun_index);
  4072. StopGunInfoTimeoutDet(gun_index);
  4073. destroySelGun(gun_index); //jerry add
  4074. }
  4075. break;
  4076. case Timeout_EvChargingDet:
  4077. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
  4078. _DetectEvChargingEnableTimeout(gun_index);
  4079. StopGunInfoTimeoutDet(gun_index);
  4080. destroySelGun(gun_index); //jerry add
  4081. }
  4082. break;
  4083. case Timeout_EvseChargingDet:
  4084. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
  4085. _DetectEvseChargingEnableTimeout(gun_index);
  4086. StopGunInfoTimeoutDet(gun_index);
  4087. destroySelGun(gun_index); //jerry add
  4088. }
  4089. break;
  4090. case Timeout_EvseCompleteDet:
  4091. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
  4092. StopGunInfoTimeoutDet(gun_index);
  4093. destroySelGun(gun_index); //jerry add
  4094. }
  4095. break;
  4096. case Timeout_ForCcsPrechargeDet:
  4097. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
  4098. _CcsPrechargeTimeout(gun_index);
  4099. StopGunInfoTimeoutDet(gun_index);
  4100. destroySelGun(gun_index); //jerry add
  4101. }
  4102. break;
  4103. case Timeout_SelectGun: //Jerry add
  4104. if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
  4105. log_info("Timeout_SelectGun\r\n");
  4106. StopGunInfoTimeoutDet(gun_index);
  4107. destroySelGun(gun_index); //jerry add
  4108. }
  4109. break;
  4110. }
  4111. }
  4112. sleep(1);
  4113. }
  4114. }
  4115. }
  4116. void GetSystemTime()
  4117. {
  4118. struct timeb csuTime;
  4119. struct tm *tmCSU;
  4120. ftime(&csuTime);
  4121. tmCSU = localtime(&csuTime.time);
  4122. log_info("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
  4123. tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  4124. tmCSU->tm_sec);
  4125. // uint8_t date[14];
  4126. //
  4127. //
  4128. // //sprintf(&date, "%d", );
  4129. //
  4130. // date[0] = '0' + ((tmCSU->tm_year + 1900) / 1000 % 10);
  4131. // date[0] = (tmCSU->tm_year + 1900) / 1000 % 10;
  4132. // date[1] = (tmCSU->tm_year + 1900) / 100 % 10;
  4133. // date[2] = (tmCSU->tm_year + 1900) / 10 % 10;
  4134. // date[3] = (tmCSU->tm_year + 1900) / 1 % 10;
  4135. //
  4136. // date[4] = (tmCSU->tm_mon + 1) / 10 % 10;
  4137. // date[5] = (tmCSU->tm_mon + 1) / 1 % 10;
  4138. //
  4139. // date[6] = (tmCSU->tm_mday) / 10 % 10;
  4140. // date[7] = (tmCSU->tm_mday) / 1 % 10;
  4141. //
  4142. // date[8] = (tmCSU->tm_hour) / 10 % 10;
  4143. // date[9] = (tmCSU->tm_hour) / 1 % 10;
  4144. //
  4145. // date[10] = (tmCSU->tm_min) / 10 % 10;
  4146. // date[11] = (tmCSU->tm_min) / 1 % 10;
  4147. //
  4148. // date[12] = (tmCSU->tm_sec) / 10 % 10;
  4149. // date[13] = (tmCSU->tm_sec) / 1 % 10;
  4150. // log_info("%x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x \n", date[0], date[1], date[2], date[3],
  4151. // date[4], date[5], date[6], date[7],
  4152. // date[8], date[9], date[10], date[11],
  4153. // date[12], date[13]);
  4154. }
  4155. void CheckFactoryConfigFunction(void)
  4156. {
  4157. char Buf[256] = {0};
  4158. if (ShmSysConfigAndInfo->SysInfo.FactoryConfiguration) {
  4159. sprintf(Buf, "cd /root;./FactoryConfig -m %s %s",
  4160. ShmSysConfigAndInfo->SysConfig.ModelName,
  4161. ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4162. system(Buf);
  4163. system("rm -f /Storage/OCPP/OCPPConfiguration");
  4164. system("sync");
  4165. sleep(5);
  4166. system("reboot -f");
  4167. sleep(5);
  4168. system("reboot -f");
  4169. }
  4170. }
  4171. void CheckFwUpdateFunction()
  4172. {
  4173. //log_info("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
  4174. if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
  4175. log_info("ftp : update start. \n");
  4176. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  4177. setChargerMode(gun_index, MODE_UPDATE);
  4178. }
  4179. uint8_t updateResult = CheckUpdateProcess();
  4180. if (updateResult == PASS) {
  4181. log_info("ftp : update complete. \n");
  4182. } else if (updateResult == MODELNAME_FAIL) {
  4183. log_info("ftp : model name is none match. \n");
  4184. KillAllTask();
  4185. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
  4186. sleep(5);
  4187. system("/usr/bin/run_evse_restart.sh");
  4188. return;
  4189. } else {
  4190. log_info("ftp : update fail. \n");
  4191. }
  4192. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
  4193. sleep(5);
  4194. system("reboot -f");
  4195. } else if (ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES) {
  4196. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
  4197. if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
  4198. log_info("Backend : update start. \n");
  4199. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
  4200. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
  4201. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  4202. KillTask();
  4203. for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  4204. setChargerMode(_index, MODE_UPDATE);
  4205. }
  4206. for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++) {
  4207. ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
  4208. }
  4209. uint8_t updateResult = CheckUpdateProcess();
  4210. if (updateResult == PASS) {
  4211. log_info("Backend : update complete. \n");
  4212. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
  4213. } else if (updateResult == MODELNAME_FAIL) {
  4214. log_info("Backend : model name is none match. \n");
  4215. KillAllTask();
  4216. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
  4217. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  4218. sleep(5);
  4219. system("/usr/bin/run_evse_restart.sh");
  4220. return;
  4221. } else {
  4222. log_info("Backend : update fail. \n");
  4223. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
  4224. }
  4225. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
  4226. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  4227. sleep(5);
  4228. system("reboot -f");
  4229. }
  4230. }
  4231. }
  4232. //===============================================
  4233. // Check reservation date is expired
  4234. //===============================================
  4235. int isReservationExpired(uint8_t gun_index)
  4236. {
  4237. int result = NO;
  4238. struct tm expiredDate;
  4239. struct timeb expiredTime;
  4240. if (sscanf((char *) ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,
  4241. "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
  4242. &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
  4243. &expiredDate.tm_min, &expiredDate.tm_sec) == 6) {
  4244. expiredDate.tm_year -= 1900;
  4245. expiredDate.tm_mon -= 1;
  4246. expiredTime.time = mktime(&expiredDate);
  4247. if (!CheckTimeOut(expiredTime)) {
  4248. result = YES;
  4249. }
  4250. }
  4251. return result;
  4252. }
  4253. //===============================================
  4254. // OCPP
  4255. //===============================================
  4256. void CheckOcppStatus(void)
  4257. {
  4258. bool canReset = true;
  4259. //bool canHardReset = true; //DS60-120 add
  4260. if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
  4261. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
  4262. }
  4263. if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES) {
  4264. if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
  4265. for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  4266. if (chargingInfo[_index]->SystemStatus != S_IDLE &&
  4267. chargingInfo[_index]->SystemStatus != S_RESERVATION &&
  4268. chargingInfo[_index]->SystemStatus != S_MAINTAIN) {
  4269. canReset = false;
  4270. if (chargingInfo[_index]->SystemStatus >= S_REASSIGN &&
  4271. chargingInfo[_index]->SystemStatus < S_TERMINATING) {
  4272. //canHardReset = false;
  4273. ChargingTerminalProcess(_index);
  4274. restartFlag = 1;
  4275. }
  4276. }
  4277. }
  4278. }
  4279. if (canReset) {
  4280. ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
  4281. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
  4282. if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
  4283. log_error("****** Hard Reboot ****** \n");
  4284. ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
  4285. sleep(3);
  4286. system("reboot -f");
  4287. } else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
  4288. log_error("****** Soft Reboot ****** \n");
  4289. ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
  4290. sleep(3);
  4291. system("killall OcppBackend &");
  4292. KillAllTask();
  4293. system("/usr/bin/run_evse_restart.sh");
  4294. }
  4295. }
  4296. }
  4297. }
  4298. void OcppStartTransation(uint8_t gunIndex)
  4299. {
  4300. uint8_t _OcppGunIndex = gunIndex;
  4301. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  4302. if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
  4303. _OcppGunIndex = 2;
  4304. }
  4305. if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
  4306. strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
  4307. } else {
  4308. strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
  4309. }
  4310. log_info("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
  4311. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
  4312. }
  4313. void OcppStopTransation(uint8_t gunIndex)
  4314. {
  4315. uint8_t _OcppGunIndex = gunIndex;
  4316. // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
  4317. if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1) {
  4318. _OcppGunIndex = 2;
  4319. }
  4320. if (strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL) {
  4321. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  4322. } else {
  4323. strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
  4324. }
  4325. log_info("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
  4326. ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
  4327. }
  4328. bool OcppRemoteStop(uint8_t gunIndex)
  4329. {
  4330. uint8_t acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
  4331. // 有 AC 槍的話
  4332. if (acDirIndex > 0 && gunIndex > 0) {
  4333. gunIndex += acDirIndex;
  4334. }
  4335. bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
  4336. if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
  4337. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
  4338. ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
  4339. }
  4340. return result;
  4341. }
  4342. bool WifiScheduleStop(uint8_t gunIndex)
  4343. {
  4344. bool result = false;
  4345. result = chargingInfo[gunIndex]->schedule.isTriggerStop;
  4346. chargingInfo[gunIndex]->schedule.isTriggerStop = NO;
  4347. return result;
  4348. }
  4349. void OcppRemoteStartChk()
  4350. {
  4351. if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
  4352. {}
  4353. else if (!isDetectPlugin()) {
  4354. // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
  4355. uint8_t acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
  4356. for (uint8_t ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++) {
  4357. if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
  4358. if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
  4359. ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION) {
  4360. ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
  4361. ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
  4362. ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
  4363. //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
  4364. ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
  4365. DetectPluginStart();
  4366. return;
  4367. }
  4368. ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
  4369. }
  4370. }
  4371. uint8_t threeGunIndex = 0;
  4372. uint8_t dcIndex = 0;
  4373. bool isGunUsingStatus = false;
  4374. for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  4375. // 如果有 AC 槍,且 DC 槍也有兩把
  4376. if (acDirIndex == 1 && _index == 1) {
  4377. threeGunIndex = 1;
  4378. }
  4379. if (ShmOCPP16Data->CsMsg.bits[_index + threeGunIndex].RemoteStartTransactionReq == YES) {
  4380. dcIndex = _index;
  4381. }
  4382. if (chargingInfo[_index]->SystemStatus != S_IDLE) {
  4383. isGunUsingStatus = true;
  4384. }
  4385. }
  4386. // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
  4387. if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
  4388. if (dcIndex == 0) {
  4389. threeGunIndex = 0;
  4390. }
  4391. ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
  4392. return;
  4393. }
  4394. if (dcIndex == 0) {
  4395. threeGunIndex = 0;
  4396. }
  4397. if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES) {
  4398. if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
  4399. chargingInfo[dcIndex]->SystemStatus == S_RESERVATION) {
  4400. chargingInfo[dcIndex]->RemoteStartFlag = YES;
  4401. ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
  4402. //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
  4403. ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
  4404. DetectPluginStart();
  4405. #if defined DD360Audi
  4406. setSelGunWaitToAuthor(dcIndex); //Jerry add
  4407. #endif //defined DD360Audi
  4408. }
  4409. ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
  4410. }
  4411. }
  4412. }
  4413. void ChkOcppStatus(uint8_t gunIndex)
  4414. {
  4415. if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
  4416. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
  4417. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
  4418. if (isReservationExpired(gunIndex)) {
  4419. log_info("***************ChkOcppStatus : OcppReservedStatus******************** \n");
  4420. log_error("***************ChkOcppStatus : OcppReservedStatus******************** \n");
  4421. chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
  4422. chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
  4423. }
  4424. ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
  4425. }
  4426. if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
  4427. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
  4428. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
  4429. if (isReservationExpired(gunIndex)) {
  4430. log_info("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
  4431. log_error("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
  4432. chargingInfo[gunIndex]->ReservationId = 0;
  4433. chargingInfo[gunIndex]->SystemStatus = S_IDLE;
  4434. }
  4435. ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
  4436. }
  4437. if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
  4438. log_info("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
  4439. log_error("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
  4440. ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
  4441. if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL) {
  4442. if (isDb_ready) {
  4443. DB_Update_Operactive(localDb, gunIndex, true);
  4444. }
  4445. chargingInfo[gunIndex]->IsAvailable = YES;
  4446. if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
  4447. chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
  4448. chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
  4449. setChargerMode(gunIndex, MODE_IDLE);
  4450. }
  4451. } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
  4452. if (isDb_ready) {
  4453. DB_Update_Operactive(localDb, gunIndex, false);
  4454. }
  4455. chargingInfo[gunIndex]->IsAvailable = NO;
  4456. if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
  4457. chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
  4458. chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN) {
  4459. setChargerMode(gunIndex, MODE_MAINTAIN);
  4460. }
  4461. }
  4462. }
  4463. if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
  4464. ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
  4465. if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK && // DS60-120 add ||
  4466. chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) {
  4467. // 充電中,需停止充電
  4468. strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
  4469. ChargingTerminalProcess(gunIndex);
  4470. }
  4471. strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
  4472. ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
  4473. }
  4474. }
  4475. bool CheckBackendChargingTimeout(uint8_t gunIndex)
  4476. {
  4477. bool result = false;
  4478. if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
  4479. if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) {
  4480. if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60)) {
  4481. result = true;
  4482. }
  4483. }
  4484. } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
  4485. // 隨插即充電的要看 offline
  4486. if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0) {
  4487. if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60)) {
  4488. result = true;
  4489. }
  4490. }
  4491. }
  4492. return result;
  4493. }
  4494. bool CheckBackendChargingEnergy(uint8_t gunIndex)
  4495. {
  4496. bool result = false;
  4497. if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) {
  4498. if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) {
  4499. if (chargingInfo[gunIndex]->PresentChargedEnergy > ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy) {
  4500. result = true;
  4501. }
  4502. }
  4503. } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) {
  4504. // 隨插即充電的要看 offline
  4505. if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0) {
  4506. if (chargingInfo[gunIndex]->PresentChargedEnergy > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy)) {
  4507. result = true;
  4508. }
  4509. }
  4510. }
  4511. return result;
  4512. }
  4513. void InformOcppErrOccur(uint8_t codeType)
  4514. {
  4515. char _error[25];
  4516. switch (codeType) {
  4517. case 4: strcpy(_error, "InternalError"); break;
  4518. case 6: strcpy(_error, "NoError"); break;
  4519. case 7: strcpy(_error, "OtherError"); break;
  4520. case 13: strcpy(_error, "UnderVoltage"); break;
  4521. case 14: strcpy(_error, "OverVoltage"); break;
  4522. }
  4523. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  4524. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, _error);
  4525. }
  4526. }
  4527. //===============================================
  4528. // SQLite3 related routine
  4529. //===============================================
  4530. int DB_Open(sqlite3 *db)
  4531. {
  4532. int result = PASS;
  4533. char *errMsg = NULL;
  4534. char *createRecordSql = "CREATE TABLE IF NOT EXISTS charging_record("
  4535. "idx integer primary key AUTOINCREMENT, "
  4536. "reservationId text, "
  4537. "transactionId text, "
  4538. "startMethod text, "
  4539. "userId text, "
  4540. "dateTimeStart text, "
  4541. "dateTimeStop text,"
  4542. "socStart text, "
  4543. "socStop text, "
  4544. "chargeEnergy text, "
  4545. "stopReason text"
  4546. ");";
  4547. /*char *createCfgSql = "CREATE TABLE IF NOT EXISTS `config` ( "
  4548. "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
  4549. "`IsAvailable` TEXT NOT NULL, "
  4550. "`connector` INTEGER NOT NULL, "
  4551. "`val` TEXT NOT NULL, unique(IsAvailable,connector) on conflict replace);";
  4552. */
  4553. //DS60-120 add
  4554. char *createCfgSql = "CREATE TABLE IF NOT EXISTS `config` ( "
  4555. "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
  4556. "`item` TEXT NOT NULL, "
  4557. "`connector` INTEGER NOT NULL, "
  4558. "`val` TEXT NOT NULL, unique(item,connector) on conflict replace);";
  4559. char *createrecordSql = "CREATE TABLE IF NOT EXISTS `event_record` ( "
  4560. "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
  4561. "`occurDatetime` TEXT NOT NULL, "
  4562. "`statusCode` TEXT NOT NULL, unique(occurDatetime,statusCode) on conflict replace);";
  4563. char *createrebootSql = "CREATE TABLE IF NOT EXISTS `reboot_record` ( "
  4564. "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
  4565. "`rebootDatetime` TEXT NOT NULL, unique(rebootDatetime) on conflict replace);";
  4566. if (sqlite3_open(DB_FILE, &db)) {
  4567. result = FAIL;
  4568. log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
  4569. sqlite3_close(db);
  4570. } else {
  4571. log_info( "Local charging record database open successfully.\r\n");
  4572. if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK) {
  4573. result = FAIL;
  4574. log_info( "Create local charging record table error message: %s\n", errMsg);
  4575. } else {
  4576. log_info( "Opened local charging record table successfully\n");
  4577. }
  4578. if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK) {
  4579. result = FAIL;
  4580. log_info( "Create local config table error message: %s\n", errMsg);
  4581. } else {
  4582. log_info( "Opened local config table successfully\n");
  4583. }
  4584. //DS60-120
  4585. if (sqlite3_exec(db, createrecordSql, 0, 0, &errMsg) != SQLITE_OK) {
  4586. result = FAIL;
  4587. log_info( "Create local record table error message: %s\n", errMsg);
  4588. } else {
  4589. log_info( "Opened local record table successfully\n");
  4590. }
  4591. if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK) {
  4592. result = FAIL;
  4593. log_info( "Create reboot record table error message: %s\n", errMsg);
  4594. } else {
  4595. log_info( "Opened reboot record table successfully\n");
  4596. }
  4597. //-----
  4598. sqlite3_close(db);
  4599. }
  4600. return result;
  4601. }
  4602. int DB_Insert_Record(sqlite3 *db, int gun_index)
  4603. {
  4604. int result = PASS;
  4605. char *errMsg = NULL;
  4606. char insertSql[1024];
  4607. sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
  4608. "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
  4609. chargingInfo[gun_index]->ReservationId, //DS60-120 add
  4610. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
  4611. chargingInfo[gun_index]->StartMethod,
  4612. chargingInfo[gun_index]->StartUserId,
  4613. chargingInfo[gun_index]->StartDateTime,
  4614. chargingInfo[gun_index]->StopDateTime,
  4615. chargingInfo[gun_index]->EvBatteryStartSoc,
  4616. chargingInfo[gun_index]->EvBatterySoc,
  4617. chargingInfo[gun_index]->PresentChargedEnergy,
  4618. //DS60-120 remove
  4619. //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
  4620. //ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
  4621. //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
  4622. //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
  4623. //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
  4624. //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
  4625. //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
  4626. //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
  4627. //ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
  4628. ShmOCPP16Data->StopTransaction[gun_index].StopReason);
  4629. //if (sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db)) {
  4630. if (sqlite3_open(DB_FILE, &db)) { //DS60-120 add
  4631. result = FAIL;
  4632. log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
  4633. sqlite3_close(db);
  4634. } else {
  4635. log_info( "Local charging record database open successfully.\r\n");
  4636. if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
  4637. result = FAIL;
  4638. log_info( "Insert local charging record error message: %s\n", errMsg);
  4639. } else {
  4640. log_info( "Insert local charging record successfully\n");
  4641. }
  4642. //DS60-120 add
  4643. sprintf(insertSql, "delete from charging_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
  4644. if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
  4645. result = FAIL;
  4646. log_info( "delete local charging error message: %s\n", errMsg);
  4647. } else {
  4648. log_info( "delete local charging record successfully\n");
  4649. }
  4650. sqlite3_close(db);
  4651. }
  4652. return result;
  4653. }
  4654. int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable)
  4655. {
  4656. uint8_t result = false;
  4657. char *errMsg = NULL;
  4658. char sqlStr[1024];
  4659. srand(time(NULL));
  4660. if (sqlite3_open(DB_FILE, &db)) {
  4661. result = FAIL;
  4662. log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
  4663. sqlite3_close(db);
  4664. } else {
  4665. log_info( "Local charging record database open successfully (%d).\r\n", IsAvailable);
  4666. //sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
  4667. sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable); //DS60-120 add
  4668. log_info("sqlStr= %s\r\n", sqlStr);
  4669. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK) {
  4670. result = FAIL;
  4671. log_info( "update config error message: %s\n", errMsg);
  4672. } else {
  4673. log_info("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
  4674. }
  4675. sqlite3_close(db);
  4676. }
  4677. return result;
  4678. }
  4679. int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
  4680. {
  4681. uint8_t result = true;
  4682. char *errMsg = NULL;
  4683. char sqlStr[1024];
  4684. char **rs;
  4685. int rows, cols;
  4686. //sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gun_index);
  4687. sprintf(sqlStr, "select * from config where item='IsAvailable' and connector=%d;", gun_index); //DS60-120 add
  4688. //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
  4689. if (sqlite3_open(DB_FILE, &db)) {
  4690. result = FAIL;
  4691. log_info( "Can't open database: %s\r\n", sqlite3_errmsg(db));
  4692. sqlite3_close(db);
  4693. } else {
  4694. log_info( "Local config query database open successfully.\r\n");
  4695. sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
  4696. if (rows > 0) {
  4697. for (int idxRow = 1; idxRow <= rows; idxRow++) {
  4698. if (strcmp(rs[(idxRow * cols) + 3], "0") == 0) {
  4699. result = false;
  4700. }
  4701. log_info("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow * cols) + 3]);
  4702. }
  4703. } else {
  4704. log_info("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
  4705. }
  4706. sqlite3_free_table(rs);
  4707. sqlite3_close(db);
  4708. }
  4709. return result;
  4710. }
  4711. int DB_Reboot_Record(sqlite3 *db)
  4712. {
  4713. int result = PASS;
  4714. char *errMsg = NULL;
  4715. char insertSql[256];
  4716. sprintf(insertSql, "insert into reboot_record(rebootDatetime) values(CURRENT_TIMESTAMP);");
  4717. if (sqlite3_open(DB_FILE, &db)) {
  4718. result = FAIL;
  4719. log_info( "Can't open database: %s\n", sqlite3_errmsg(db));
  4720. sqlite3_close(db);
  4721. } else {
  4722. log_info( "Local charging record database open successfully.\n");
  4723. if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
  4724. result = FAIL;
  4725. log_info( "Insert reboot record error message: %s\n", errMsg);
  4726. } else {
  4727. log_info( "Insert reboot record successfully\n");
  4728. }
  4729. sprintf(insertSql, "delete from reboot_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
  4730. if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK) {
  4731. result = FAIL;
  4732. log_info( "delete reboot record error message: %s\n", errMsg);
  4733. } else {
  4734. log_info( "delete reboot record successfully\n");
  4735. }
  4736. sqlite3_close(db);
  4737. }
  4738. return result;
  4739. }
  4740. //===============================================
  4741. // Config process
  4742. //===============================================
  4743. void AddPlugInTimes(uint8_t gunIndex)
  4744. {
  4745. if (chargingInfo[gunIndex]->Type == _Type_Chademo) {
  4746. ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
  4747. } else if (chargingInfo[gunIndex]->Type == _Type_CCS_2) {
  4748. ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
  4749. } else if (chargingInfo[gunIndex]->Type == _Type_GB) {
  4750. ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
  4751. }
  4752. }
  4753. void ChangeStartOrStopDateTime(uint8_t isStart, uint8_t gunIndex)
  4754. {
  4755. char cmdBuf[32];
  4756. struct timeb csuTime;
  4757. struct tm *tmCSU;
  4758. ftime(&csuTime);
  4759. tmCSU = localtime(&csuTime.time);
  4760. sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
  4761. tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  4762. tmCSU->tm_sec);
  4763. if (isStart) {
  4764. strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
  4765. } else {
  4766. strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
  4767. }
  4768. }
  4769. void zipLogFiles()
  4770. {
  4771. const char *logPath = "/Storage/SystemLog";
  4772. // 獲取目錄
  4773. DIR *pDir = opendir(logPath);
  4774. if (pDir != NULL) {
  4775. struct timeb csuTime;
  4776. struct tm *tmCSU;
  4777. ftime(&csuTime);
  4778. tmCSU = localtime(&csuTime.time);
  4779. // log_info("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
  4780. // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
  4781. // tmCSU->tm_sec);
  4782. // Read items inside the folder
  4783. struct dirent *pEntry = NULL;
  4784. while ((pEntry = readdir(pDir)) != NULL) {
  4785. if (strcmp(pEntry->d_name, ".") != 0 &&
  4786. strcmp(pEntry->d_name, "..") != 0 &&
  4787. strncmp(pEntry->d_name, "[", 1) == 0 &&
  4788. strstr(pEntry->d_name, "tar") < 0) {
  4789. char yearC[5];
  4790. unsigned short year = 0;
  4791. char monthC[3];
  4792. unsigned short month = 0;
  4793. yearC[4] = '\0';
  4794. strncpy(yearC, pEntry->d_name + 1, 4);
  4795. monthC[2] = '\0';
  4796. strncpy(monthC, pEntry->d_name + 6, 2);
  4797. year = atoi(yearC);
  4798. month = atoi(monthC);
  4799. if (year != 0) {
  4800. if (year < tmCSU->tm_year + 1900 ||
  4801. (year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1)) {
  4802. log_info("tar file name : %s \n", pEntry->d_name);
  4803. char file[256];
  4804. memset(file, 0x00, sizeof(file));
  4805. strcat(file, "tar zcvf ");
  4806. strcat(file, logPath);
  4807. strncat(file, "/", 1);
  4808. strcat(file, pEntry->d_name);
  4809. strcat(file, ".tar");
  4810. strncat(file, " ", 1);
  4811. strcat(file, logPath);
  4812. strncat(file, "/", 1);
  4813. strcat(file, pEntry->d_name);
  4814. log_info("zip = %s \n", file);
  4815. system(file);
  4816. }
  4817. }
  4818. }
  4819. }
  4820. }
  4821. // Close folder
  4822. closedir(pDir);
  4823. }
  4824. void ChangeGunSelectByIndex(uint8_t sel)
  4825. {
  4826. ShmSysConfigAndInfo->SysInfo.CurGunSelected = sel;
  4827. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  4828. }
  4829. void CheckIsAlternatvieByModelName()
  4830. {
  4831. // 黑白機 ?
  4832. /*if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWWU301J0UT1PH") == EQUAL ||
  4833. strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYE301J0ET1PH") == EQUAL ||
  4834. strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DSYE301J3EW2PH") == EQUAL ||
  4835. strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYC301J0UW1PH") == EQUAL) {
  4836. */
  4837. if (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W') { //DS60-120
  4838. // 壁掛
  4839. ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = YES;
  4840. } else {
  4841. ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = NO;
  4842. }
  4843. }
  4844. void StopProcessingLoop()
  4845. {
  4846. for (;;) {
  4847. CheckFactoryConfigFunction();
  4848. CheckFwUpdateFunction();
  4849. if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
  4850. ChkPrimaryStatus();
  4851. if (ShmSysConfigAndInfo->SysWarningInfo.Level == 0) {
  4852. log_info("Soft reboot for retry self-tets (Primary). \n");
  4853. KillAllTask();
  4854. sleep(3);
  4855. system("/usr/bin/run_evse_restart.sh");
  4856. return;
  4857. }
  4858. }
  4859. sleep(1);
  4860. }
  4861. }
  4862. void CreateWatchdog()
  4863. {
  4864. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO) {
  4865. wtdFd = InitWatchDog();
  4866. if (wtdFd < 0) {
  4867. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  4868. }
  4869. }
  4870. }
  4871. bool IsConnectorWholeIdle()
  4872. {
  4873. bool result = true;
  4874. for (uint8_t count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
  4875. if (chargingInfo[count]->SystemStatus != S_IDLE &&
  4876. chargingInfo[count]->SystemStatus != S_RESERVATION) {
  4877. result = false;
  4878. break;
  4879. }
  4880. }
  4881. for (uint8_t count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++) {
  4882. if (ac_chargingInfo[count]->SystemStatus != S_IDLE &&
  4883. ac_chargingInfo[count]->IsErrorOccur == NO) {
  4884. result = false;
  4885. break;
  4886. }
  4887. }
  4888. return result;
  4889. }
  4890. void ClearAlarmCodeWhenAcOff()
  4891. {
  4892. if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus) {
  4893. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
  4894. }
  4895. }
  4896. //==========================================
  4897. // Check task processing
  4898. //==========================================
  4899. void CheckTask()
  4900. {
  4901. /*+++ 20200908, vern, disable it for DD360 +++*/
  4902. #if 0
  4903. if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') {
  4904. if (system("pidof -s Module_4g > /dev/null") != 0) {
  4905. log_error("Module_4g not running, restart it.\r\n");
  4906. system("/root/Module_4g &");
  4907. }
  4908. } else if (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') {
  4909. if (system("pidof -s Module_Wifi > /dev/null") != 0) {
  4910. log_error("Module_Wifi not running, restart it.\r\n");
  4911. system("/root/Module_Wifi &");
  4912. }
  4913. }
  4914. if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
  4915. strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL) {
  4916. if (system("pidof -s OcppBackend > /dev/null") != 0) {
  4917. log_error("OcppBackend not running, restart it.\r\n");
  4918. system("/root/OcppBackend &");
  4919. }
  4920. }
  4921. #endif
  4922. /*--- 20200908, vern, disable it for DD360 ---*/
  4923. if (system("pidof -s Module_ProduceUtils > /dev/null") != 0) {
  4924. log_error("Module_ProduceUtils not running, restart it.\r\n");
  4925. system ("/root/Module_ProduceUtils &");
  4926. }
  4927. }
  4928. void InitialDHCP()
  4929. {
  4930. char tmpbuf[256] = {0};
  4931. system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
  4932. sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
  4933. ShmSysConfigAndInfo->SysConfig.SystemId);
  4934. system(tmpbuf);
  4935. }
  4936. //==========================================
  4937. // Check Smart Charging Profile
  4938. //==========================================
  4939. int GetStartScheduleTime(uint8_t *time)
  4940. {
  4941. int result = -1;
  4942. struct tm tmScheduleStart;
  4943. struct timeb tbScheduleStart;
  4944. 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)) {
  4945. tmScheduleStart.tm_year -= 1900;
  4946. tmScheduleStart.tm_mon -= 1;
  4947. tbScheduleStart.time = mktime(&tmScheduleStart);
  4948. tbScheduleStart.millitm = 0;
  4949. result = DiffTimebWithNow(tbScheduleStart) / 1000;
  4950. }
  4951. return result;
  4952. }
  4953. void CheckSmartChargeProfile(uint8_t _index)
  4954. {
  4955. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
  4956. // Get Charging Profile
  4957. ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
  4958. if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
  4959. ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES //DS60-120 add
  4960. ) {
  4961. int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
  4962. uint8_t _startCount = NO_DEFINE;
  4963. uint8_t _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
  4964. for (uint8_t _count = 0; _count < _maxCount; _count++) {
  4965. // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
  4966. if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod) {
  4967. if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
  4968. ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR) {
  4969. _startCount = _count;
  4970. }
  4971. }
  4972. }
  4973. log_info("_startCount = %d \n", _startCount);
  4974. if (_startCount < _maxCount) {
  4975. //DS60-120 add
  4976. log_info("Profile Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
  4977. chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
  4978. if (chargingInfo[_index]->EvBatterytargetVoltage > 0 && chargingInfo[_index]->PresentChargingVoltage > 0) {
  4979. chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
  4980. } else {
  4981. chargingInfo[_index]->ChargingProfileCurrent = 0;
  4982. }
  4983. //DS60-120 remove
  4984. //log_info("*********Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
  4985. //chargingInfo[_index]->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * 10;
  4986. //chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * chargingInfo[_index]->EvBatterytargetVoltage / 100;
  4987. //chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
  4988. // if ((chargingInfo[_index]->EvBatterytargetVoltage * 10) > 0)
  4989. // {
  4990. // chargingInfo[_index]->ChargingProfileCurrent = chargingInfo[_index]->ChargingProfilePower / (chargingInfo[_index]->EvBatterytargetVoltage * 10);
  4991. // }
  4992. } else {
  4993. chargingInfo[_index]->ChargingProfilePower = -1;
  4994. chargingInfo[_index]->ChargingProfileCurrent = -1;
  4995. }
  4996. } else {
  4997. chargingInfo[_index]->ChargingProfilePower = -1;
  4998. chargingInfo[_index]->ChargingProfileCurrent = -1;
  4999. }
  5000. log_info("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
  5001. log_info("ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
  5002. }
  5003. //
  5004. // printf("-------------Schedule------------\n");
  5005. // printf("index = %d \n", _index);
  5006. // printf("StartSchedule = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
  5007. // printf("ChargingRateUnit = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
  5008. // printf("----------SchedulePeriod---------\n");
  5009. // for (int v = 0; v < 10; v++)
  5010. // {
  5011. // printf("StartPeriod = %d \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
  5012. // printf("Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
  5013. // }
  5014. // printf("---------------------------------\n");
  5015. }
  5016. void ChargingProfileFlat(uint8_t _index)
  5017. {
  5018. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO) {
  5019. if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO) {
  5020. ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
  5021. }
  5022. }
  5023. }
  5024. void CheckReturnToChargingConn()
  5025. {
  5026. if ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ShmSysConfigAndInfo->SysConfig.AcConnectorCount) > 1 &&
  5027. ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
  5028. ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
  5029. ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
  5030. ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG) {
  5031. bool isReturnTimeout = false;
  5032. for (uint8_t count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++) {
  5033. // 如果選的 DC 槍在充電~ 則 DC 槍不改變
  5034. if (count == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
  5035. if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
  5036. (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  5037. isReturnTimeout = false;
  5038. break;
  5039. }
  5040. } else if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
  5041. if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
  5042. (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  5043. isReturnTimeout = true;
  5044. StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
  5045. }
  5046. }
  5047. }
  5048. // AC 槍
  5049. if (!isReturnTimeout && ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0) {
  5050. // 沒有選中 AC,且 AC 在充電中
  5051. if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
  5052. (ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE)) {
  5053. // 當前 DC 充電槍在 idle 狀態
  5054. if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE ||
  5055. chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_RESERVATION) {
  5056. isReturnTimeout = true;
  5057. StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
  5058. }
  5059. } else if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
  5060. ((chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_COMPLETE) ||
  5061. (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_CCS_PRECHARGE_ST1))) {
  5062. // 當前 DC 充電槍在 idle 狀態
  5063. if (ac_chargingInfo[0]->SystemStatus == S_IDLE ||
  5064. ac_chargingInfo[0]->SystemStatus == S_RESERVATION) {
  5065. isReturnTimeout = true;
  5066. StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
  5067. }
  5068. }
  5069. }
  5070. if (!isReturnTimeout) {
  5071. StopSystemTimeoutDet();
  5072. }
  5073. }
  5074. }
  5075. bool GetStartChargingByAlterMode(uint8_t _gun)
  5076. {
  5077. bool result = true;
  5078. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
  5079. ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES) {
  5080. for (uint8_t _select = 0; _select < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _select++) {
  5081. if (_select != _gun) {
  5082. if (chargingInfo[_select]->SystemStatus != S_IDLE &&
  5083. chargingInfo[_select]->SystemStatus != S_RESERVATION) {
  5084. result = false;
  5085. break;
  5086. }
  5087. }
  5088. }
  5089. }
  5090. return result;
  5091. }
  5092. void TheEndCharging(uint8_t gun_index)
  5093. {
  5094. ftime(&endChargingTime[gun_index]);
  5095. if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
  5096. chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
  5097. }
  5098. chargingInfo[gun_index]->isRemoteStart = NO;
  5099. StopGunInfoTimeoutDet(gun_index);
  5100. StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
  5101. ChangeStartOrStopDateTime(NO, gun_index);
  5102. DB_Insert_Record(localDb, gun_index);
  5103. }
  5104. void UpdateErrorCodeToOcpp(uint8_t index)
  5105. {
  5106. //log_info("%d = ConnectorAlarmCode = %s\r\n", index, (char *)chargingInfo[index]->ConnectorAlarmCode);
  5107. //log_info("%d = EvConnAlarmCode = %s\r\n", index, (char *)chargingInfo[index]->EvConnAlarmCode);
  5108. if (strcmp((char *)chargingInfo[index]->ConnectorAlarmCode, "") != EQUAL) {
  5109. //if (strlen((char *)chargingInfo[index]->ConnectorAlarmCode) == EQUAL) {
  5110. strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "InternalError");
  5111. strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)chargingInfo[index]->ConnectorAlarmCode);
  5112. } else if (strcmp((char *)chargingInfo[index]->EvConnAlarmCode, "") != EQUAL) {
  5113. //} else if (strlen((char *)chargingInfo[index]->EvConnAlarmCode) == EQUAL) {
  5114. strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "OtherError");
  5115. strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)chargingInfo[index]->EvConnAlarmCode);
  5116. }
  5117. //log_info("2 %d = VendorErrorCode = %s\r\n", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
  5118. }
  5119. void AdjustChargerCurrent()
  5120. {
  5121. ShmSysConfigAndInfo->SysConfig.RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
  5122. // 設定的電流~ 如超過可輸出的電流,則 bypass
  5123. if (ShmSysConfigAndInfo->SysConfig.RatingCurrent < ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent ||
  5124. ShmSysConfigAndInfo->SysConfig.RatingCurrent == 0) {
  5125. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = 0;
  5126. }
  5127. log_info ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
  5128. ShmPsuData->SystemAvailablePower / 10,
  5129. ShmPsuData->SystemAvailableCurrent / 10
  5130. );
  5131. log_info ("Config : ChargingPower = %d, ChargingCurrent = %d",
  5132. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  5133. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent
  5134. );
  5135. }
  5136. void ResetDetAlarmStatus(uint8_t gun)
  5137. {
  5138. if (chargingInfo[gun]->Type == _Type_Chademo) {
  5139. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP == YES) {
  5140. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
  5141. }
  5142. } else if (chargingInfo[gun]->Type == _Type_GB) {
  5143. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP == YES) {
  5144. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
  5145. }
  5146. } else if (chargingInfo[gun]->Type == _Type_CCS_2) {
  5147. if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP == YES) {
  5148. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
  5149. }
  5150. }
  5151. }
  5152. static void powerCabinetPsuAlarmStatus(void)
  5153. {
  5154. uint8_t i = 0;
  5155. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  5156. return;
  5157. #endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
  5158. for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
  5159. if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042267", 6) == 0) {
  5160. EmcOccureByString("042267");
  5161. }
  5162. }
  5163. }
  5164. static void autoStartChargingForComBox(uint8_t gunIndex)
  5165. {
  5166. #if !defined DD360ComBox
  5167. return ;
  5168. #endif //!defined DD360ComBox
  5169. if ((chargingInfo[gunIndex]->ConnectorPlugIn == YES) &&
  5170. (chargingInfo[gunIndex]->SystemStatus == S_IDLE)
  5171. ) {
  5172. ShmSysConfigAndInfo->SysInfo.CurGunSelected = gunIndex;
  5173. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
  5174. }
  5175. }
  5176. static bool PrecheckIsPass(uint8_t gun_index)
  5177. {
  5178. bool result = true;
  5179. // relay welding or driving 是反向
  5180. result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
  5181. return result;
  5182. }
  5183. static void ReviewCriticalAlarm(void)
  5184. {
  5185. if (ShmDcCommonData->GunRelayDrivingOccur[0] == YES ||
  5186. ShmDcCommonData->GunRelayDrivingOccur[1] == YES ||
  5187. ShmDcCommonData->GunRelayWeldingOccur[0] == YES ||
  5188. ShmDcCommonData->GunRelayWeldingOccur[1] == YES ||
  5189. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
  5190. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip ||
  5191. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen ||
  5192. ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
  5193. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm ||
  5194. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo
  5195. ) {
  5196. ShmSysConfigAndInfo->SysWarningInfo.Level = 2;
  5197. } else {
  5198. ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
  5199. }
  5200. }
  5201. static void CheckRelayWeldingOrDrivingFault(uint8_t gun_index)
  5202. {
  5203. // relay welding fault then stop the charging process.
  5204. uint8_t faultCode = RELAY_STATUS_ERROR_NONE;
  5205. if (gun_index == 0) {
  5206. if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  5207. ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  5208. faultCode = RELAY_STATUS_ERROR_WELDING;
  5209. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  5210. ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  5211. faultCode = RELAY_STATUS_ERROR_DRIVING;
  5212. }
  5213. } else if (gun_index == 1) {
  5214. if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  5215. ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  5216. faultCode = RELAY_STATUS_ERROR_WELDING;
  5217. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  5218. ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  5219. faultCode = RELAY_STATUS_ERROR_DRIVING;
  5220. }
  5221. }
  5222. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2 &&
  5223. !ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf) {
  5224. // 橋接
  5225. if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
  5226. ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
  5227. faultCode = RELAY_STATUS_ERROR_WELDING;
  5228. } else if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
  5229. ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
  5230. faultCode = RELAY_STATUS_ERROR_DRIVING;
  5231. }
  5232. }
  5233. if (faultCode == RELAY_STATUS_ERROR_WELDING) {
  5234. // welding
  5235. if (chargingInfo[gun_index]->Type == _Type_Chademo) {
  5236. RecordAlarmCode(gun_index, "011011");
  5237. } else if (chargingInfo[gun_index]->Type == _Type_GB) {
  5238. RecordAlarmCode(gun_index, "011015");
  5239. } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
  5240. RecordAlarmCode(gun_index, "011013");
  5241. }
  5242. ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
  5243. EmcOccureByString("");
  5244. } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
  5245. // driving
  5246. if (chargingInfo[gun_index]->Type == _Type_Chademo) {
  5247. RecordAlarmCode(gun_index, "011012");
  5248. } else if (chargingInfo[gun_index]->Type == _Type_GB) {
  5249. RecordAlarmCode(gun_index, "011016");
  5250. } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
  5251. RecordAlarmCode(gun_index, "011014");
  5252. }
  5253. ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
  5254. EmcOccureByString("");
  5255. } else {
  5256. ShmDcCommonData->GunRelayWeldingOccur[gun_index] = NO;
  5257. ShmDcCommonData->GunRelayDrivingOccur[gun_index] = NO;
  5258. if (chargingInfo[gun_index]->Type == _Type_Chademo) {
  5259. ResetChargerAlarmCode(gun_index, "011012");
  5260. ResetChargerAlarmCode(gun_index, "011011");
  5261. } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
  5262. ResetChargerAlarmCode(gun_index, "011014");
  5263. ResetChargerAlarmCode(gun_index, "011013");
  5264. } else if (chargingInfo[gun_index]->Type == _Type_GB) {
  5265. ResetChargerAlarmCode(gun_index, "011016");
  5266. ResetChargerAlarmCode(gun_index, "011015");
  5267. }
  5268. }
  5269. }
  5270. int main(void)
  5271. {
  5272. uint8_t evBoardStopState = 0;
  5273. uint8_t _ocppProfileChkFlag;
  5274. if (CreateShareMemory() == 0) {
  5275. log_error("CreatShareMemory NG\r\n");
  5276. if (ShmStatusCodeData != NULL) {
  5277. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  5278. }
  5279. sleep(5);
  5280. system("reboot -f");
  5281. sleep(5);
  5282. system("reboot -f");
  5283. }
  5284. log_info(" **************** FileSystem Boot up ***************\n");
  5285. if (!InitialSystemDefaultConfig()) {
  5286. log_error("InitialSystemDefaultConfig NG \n");
  5287. //StopProcessingLoop();
  5288. sleep(5);
  5289. system("reboot -f");
  5290. }
  5291. CheckGunTypeFromHw();
  5292. CheckIsAlternatvieByModelName();
  5293. InitialShareMemoryInfo();
  5294. ChangeLcmByIndex(_LCM_INIT);
  5295. if (!CheckConnectorTypeStatus()) {
  5296. isModelNameMatch = false;
  5297. }
  5298. Initialization();
  5299. SpawnTask();
  5300. log_info("Spawned all Task");
  5301. if (!isModelNameMatch) {
  5302. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
  5303. ChangeLcmByIndex(_LCM_FIX);
  5304. // Module Name 與硬體對應不正確
  5305. log_error("Module Name & HW info none match. \n");
  5306. sleep(3);
  5307. KillAllTask();
  5308. StopProcessingLoop();
  5309. }
  5310. CreateTimeoutFork();
  5311. log_info("Start self test... \n");
  5312. startPrimaryLedIndicatorCtrlFork();
  5313. SelfTestRun();
  5314. StopSystemTimeoutDet();
  5315. log_info("Self test finished : SelfTestSeq = %d, Work_Step = %d ",
  5316. ShmSysConfigAndInfo->SysInfo.SelfTestSeq,
  5317. ShmPsuData->Work_Step);
  5318. if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
  5319. ShmPsuData->Work_Step == _NO_WORKING ||
  5320. ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES //DS60-120 add
  5321. ) {
  5322. if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
  5323. if (!DisplaySelfTestFailReason()) { //DS60-120 add
  5324. log_info("Soft reboot for retry self-tets. \n");
  5325. sleep(3);
  5326. system("killall OcppBackend &");
  5327. KillAllTask();
  5328. system("/usr/bin/run_evse_restart.sh");
  5329. }
  5330. }
  5331. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  5332. setChargerMode(gun_index, MODE_ALARM);
  5333. }
  5334. //ChangeLcmByIndex(_LCM_FIX);
  5335. sleep(3);
  5336. if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) { //DS60-120 add
  5337. KillTaskExceptPrimary();
  5338. } else {
  5339. KillTask();
  5340. }
  5341. StopProcessingLoop();
  5342. } else {
  5343. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  5344. setChargerMode(gun_index, MODE_IDLE);
  5345. }
  5346. }
  5347. // Local DB
  5348. if (DB_Open(localDb) != PASS) {
  5349. log_info("DB_Open fail. \n");
  5350. isDb_ready = false;
  5351. } else {
  5352. isDb_ready = true;
  5353. for (int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  5354. chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
  5355. }
  5356. DB_Reboot_Record(localDb);
  5357. }
  5358. log_info("===== Create DB End ===== \n");
  5359. #if defined DD360Audi
  5360. ChangeLcmByIndex(_LCM_SELECT_GUN);
  5361. #else
  5362. ChangeLcmByIndex(_LCM_IDLE);
  5363. #endif //defined DD360Audi
  5364. sleep(1);
  5365. //***** 須新增的偵測 *****//
  5366. // 1. Thernal - 控制風扇轉速
  5367. // 2. ouput fuse - 控制風扇轉速
  5368. CreateRfidFork();
  5369. // Create Watchdog
  5370. //CreateWatchdog();
  5371. // Main loop
  5372. log_info("===== Charger info ===== ");
  5373. log_info("SW Version = %s", fwVersion);
  5374. log_info("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
  5375. CheckFwSlotStatusLog();
  5376. AdjustChargerCurrent();
  5377. gettimeofday(&_cmdMainPriority_time, NULL);
  5378. for (;;) {
  5379. CheckOcppStatus();
  5380. ChkPrimaryStatus();
  5381. if ((IsConnectorWholeIdle() || ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) &&
  5382. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_ReturnToChargingGunDet) {
  5383. CheckFactoryConfigFunction();
  5384. CheckFwUpdateFunction();
  5385. }
  5386. // OCPP 邏輯
  5387. OcppRemoteStartChk();
  5388. // 讀卡邏輯
  5389. ScannerCardProcess();
  5390. // 當 AC 沒有搭上時,清除一些錯誤碼
  5391. ClearAlarmCodeWhenAcOff();
  5392. // 確認是否要回到充電中的槍畫面邏輯判斷
  5393. CheckReturnToChargingConn();
  5394. //確認Power cabinet PSU Status
  5395. powerCabinetPsuAlarmStatus();
  5396. if (_acgunIndex > 0 && isDetectPlugin() && !isCardScan) {
  5397. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
  5398. }
  5399. if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
  5400. CheckTask();
  5401. for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
  5402. if ((chargingInfo[_index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
  5403. chargingInfo[_index]->SystemStatus <= S_CHARGING) ||
  5404. (chargingInfo[_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  5405. chargingInfo[_index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  5406. if (chargingInfo[_index]->SystemStatus == S_CHARGING &&
  5407. _ocppProfileChkFlag == 12) {
  5408. ChargingProfileFlat(_index);
  5409. _ocppProfileChkFlag = 0;
  5410. } else if (chargingInfo[_index]->SystemStatus != S_CHARGING) {
  5411. ChargingProfileFlat(_index);
  5412. _ocppProfileChkFlag = 0;
  5413. } else {
  5414. _ocppProfileChkFlag++;
  5415. }
  5416. }
  5417. checkGunOTPState(_index); //check gun OTP
  5418. }
  5419. gettimeofday(&_cmdMainPriority_time, NULL);
  5420. }
  5421. // 確認當前錯誤 Level = 2 ?
  5422. ReviewCriticalAlarm();
  5423. gEvBoardErr.GunErrMessage = 0;
  5424. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  5425. autoStartChargingForComBox(gun_index); //for DD360ComBox
  5426. CheckGpioInStatus();
  5427. CheckErrorOccurStatus(gun_index);
  5428. // 確認 Relay Welding or Driving Fault
  5429. CheckRelayWeldingOrDrivingFault(gun_index);
  5430. // 收集各槍的錯誤狀態
  5431. collectError(gun_index);
  5432. ChkOcppStatus(gun_index);
  5433. if ((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
  5434. chargingInfo[gun_index]->SystemStatus <= S_CHARGING) ||
  5435. (chargingInfo[gun_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  5436. chargingInfo[gun_index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
  5437. CheckSmartChargeProfile(gun_index);
  5438. }
  5439. //log_info("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5440. switch (chargingInfo[gun_index]->SystemStatus) {
  5441. case S_IDLE:
  5442. ReleaseAlarmCode(gun_index);
  5443. if (isModeChange(gun_index)) {
  5444. log_info("S_IDLE================================== %x \n", gun_index);
  5445. chargingInfo[gun_index]->PresentChargedDuration = 0;
  5446. chargingInfo[gun_index]->RemainChargingDuration = 0;
  5447. chargingInfo[gun_index]->PresentChargingVoltage = 0;//DS60-120 add
  5448. chargingInfo[gun_index]->PresentChargingCurrent = 0;//DS60-120 add
  5449. strcpy((char *)chargingInfo[gun_index]->StartDateTime, "");
  5450. strcpy((char *)chargingInfo[gun_index]->StopDateTime, "");
  5451. strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
  5452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
  5453. //Jerry add
  5454. memset(&gAudiCustInfo->PricesInfo[gun_index], 0, sizeof(PricesInfo));
  5455. gAudiCustInfo->PricesInfo[gun_index].Balance = FAIL_BALANCE_PRICES;
  5456. destroySelGun(gun_index);
  5457. ResetDetAlarmStatus(gun_index); //recovery OVP status code
  5458. if (gAudiCustInfo->AuthorStateFromCabinet[gun_index] == YES) {
  5459. gAudiCustInfo->AuthorStateFromCabinet[gun_index] = NO;
  5460. }
  5461. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "");
  5462. }
  5463. case S_RESERVATION:
  5464. if (isModeChange(gun_index)) {
  5465. log_info("S_RESERVATION....................%x \n", gun_index);
  5466. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
  5467. }
  5468. if (chargingInfo[gun_index]->IsAvailable == NO) {
  5469. setChargerMode(gun_index, MODE_MAINTAIN);
  5470. }
  5471. case S_MAINTAIN:
  5472. case S_FAULT: {
  5473. if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
  5474. if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
  5475. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
  5476. } else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_IDLE &&
  5477. chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_RESERVATION &&
  5478. chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_MAINTAIN &&
  5479. chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_FAULT) {
  5480. if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING) {
  5481. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_COMPLETE;
  5482. } else {
  5483. #if defined DD360Audi
  5484. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
  5485. #else
  5486. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  5487. #endif //defined DD360Audi
  5488. }
  5489. }
  5490. ClearDetectPluginFlag();
  5491. //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  5492. UpdateErrorCodeToOcpp(gun_index);
  5493. //#endif //!defined DD360 && !defined DD360Audi
  5494. setChargerMode(gun_index, MODE_FAULT);
  5495. } else {
  5496. #if 1
  5497. if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
  5498. #if defined DD360Audi
  5499. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
  5500. #else
  5501. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  5502. #endif //defined DD360Audi
  5503. setChargerMode(gun_index, MODE_IDLE);
  5504. }
  5505. //if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX) {
  5506. // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;//_LCM_NONE; //Jerry add
  5507. // //for (uint8_t g_index = 0; g_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; g_index++) {
  5508. // setChargerMode(gun_index, MODE_IDLE);
  5509. // //}
  5510. //}
  5511. #endif //0
  5512. if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
  5513. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  5514. if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
  5515. #else
  5516. if (1)
  5517. #endif //!defined DD360 && !defined DD360Audi
  5518. {
  5519. // 均充 -> 最大充
  5520. if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO) {
  5521. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE) {
  5522. log_info("=============Smart Charging============= Step 11 \n");
  5523. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
  5524. }
  5525. } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
  5526. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING) {
  5527. log_info("=============Smart Charging============= Step 14 \n");
  5528. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
  5529. } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP) {
  5530. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  5531. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  5532. }
  5533. } else {
  5534. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  5535. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  5536. }
  5537. } else {
  5538. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  5539. }
  5540. if (PrecheckIsPass(gun_index)) {
  5541. if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
  5542. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  5543. setChargerMode(gun_index, MODE_IDLE);
  5544. }
  5545. if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
  5546. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  5547. #if defined DD360Audi
  5548. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
  5549. #else
  5550. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
  5551. #endif //
  5552. }
  5553. } else {
  5554. // Idle 正常程序起點
  5555. // 判斷是否有啟用檢查插槍
  5556. if (isDetectPlugin()) {
  5557. // 卡號驗證成功後,等待充電槍插入充電車
  5558. if (chargingInfo[gun_index]->RemoteStartFlag == YES) {
  5559. if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
  5560. chargingInfo[gun_index]->IsAvailable) {
  5561. log_info("-----------------1----------------- %d \n", gun_index);
  5562. chargingInfo[gun_index]->RemoteStartFlag = NO;
  5563. chargingInfo[gun_index]->isRemoteStart = YES; //DS60-120
  5564. ChangeGunSelectByIndex(gun_index);
  5565. AddPlugInTimes(gun_index);
  5566. setChargerMode(gun_index, MODE_REASSIGN_CHECK);
  5567. strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
  5568. ClearDetectPluginFlag();
  5569. continue;
  5570. }
  5571. } else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE) {
  5572. if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
  5573. chargingInfo[gun_index]->IsAvailable &&
  5574. chargingInfo[gun_index]->SystemStatus == S_IDLE
  5575. #if defined DD360Audi
  5576. && (waitRightGunPlugIt(gun_index) == PASS ||
  5577. waitLeftGunPlugIt(gun_index) == PASS)
  5578. #endif //defined DD360Audi
  5579. ) {
  5580. log_info("-----------------2----------------- \n");
  5581. ChangeGunSelectByIndex(gun_index);
  5582. AddPlugInTimes(gun_index);
  5583. strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5584. log_info("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
  5585. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  5586. // 當前操作的槍號,進入 Preparing
  5587. setChargerMode(gun_index, MODE_REASSIGN_CHECK);
  5588. ClearDetectPluginFlag();
  5589. continue;
  5590. }
  5591. }
  5592. if (!isCardScan) {
  5593. // LCM => Waiting for plugging
  5594. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
  5595. }
  5596. } else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION) {
  5597. if (!isReservationExpired(gun_index)) {
  5598. chargingInfo[gun_index]->SystemStatus = S_IDLE;
  5599. }
  5600. } else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
  5601. (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable)) {
  5602. log_info("-----------------3----------------- \n");
  5603. bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
  5604. if (isCanStartChargingFlag) {
  5605. ChangeGunSelectByIndex(gun_index);
  5606. AddPlugInTimes(gun_index);
  5607. setChargerMode(gun_index, MODE_REASSIGN_CHECK);
  5608. ClearDetectPluginFlag();
  5609. continue;
  5610. }
  5611. } else {
  5612. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  5613. #if defined DD360Audi
  5614. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;
  5615. #else
  5616. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
  5617. #endif // defined DD360Audi
  5618. }
  5619. }
  5620. } // Idle 正常程序終點
  5621. } else {
  5622. setChargerMode(gun_index, MODE_FAULT);
  5623. if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
  5624. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
  5625. }
  5626. }// PrecheckIsPass()
  5627. }
  5628. }
  5629. break;
  5630. case S_REASSIGN_CHECK: {
  5631. if (isModeChange(gun_index)) {
  5632. log_info("S_REASSIGN_CHECK================================== %x \n", gun_index);
  5633. #if defined DD360Audi
  5634. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
  5635. #else
  5636. ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  5637. #endif //defined DD360Audi
  5638. if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE) {
  5639. ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
  5640. }
  5641. StopSystemTimeoutDet();
  5642. }
  5643. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  5644. bool isRessign = false;
  5645. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO) {
  5646. if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
  5647. for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
  5648. // 有其他槍已經分配好 psu 模塊
  5649. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
  5650. chargingInfo[index]->SystemStatus >= S_PREPARNING &&
  5651. chargingInfo[index]->SystemStatus != S_MAINTAIN) {
  5652. log_info("=============Smart Charging============= Step 1 \n");
  5653. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
  5654. isRessign = true;
  5655. break;
  5656. }
  5657. }
  5658. } else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
  5659. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE) {
  5660. // 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
  5661. if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES) {
  5662. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
  5663. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING) {
  5664. log_info("=============Smart Charging============= Step 14 \n");
  5665. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
  5666. } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP) {
  5667. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  5668. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  5669. continue;
  5670. }
  5671. }
  5672. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  5673. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
  5674. }
  5675. continue;
  5676. }
  5677. }
  5678. #endif // !defined DD360 && !defined DD360Audi
  5679. if (0) { // if (isRessign)
  5680. #if defined DD360 ||defined DD360Audi || defined DD360ComBox
  5681. setChargerMode(gun_index, MODE_PRECHARGE);
  5682. #else
  5683. setChargerMode(gun_index, MODE_REASSIGN);
  5684. #endif //defined DD360 || defined DD360Audi
  5685. } else {
  5686. setChargerMode(gun_index, MODE_PRECHARGE);
  5687. }
  5688. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  5689. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
  5690. }
  5691. }
  5692. break;
  5693. case S_REASSIGN: {
  5694. if (isModeChange(gun_index)) {
  5695. log_info("S_REASSIGN================================== %x \n", gun_index);
  5696. gettimeofday(&_toAverage_time, NULL);
  5697. }
  5698. // 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
  5699. // 此狀態下~ 控制權在於 PSU 及 EV小板 Process
  5700. if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
  5701. ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
  5702. if (ShmSysConfigAndInfo->SysInfo.CanAverageCharging) {
  5703. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;//DS60-120 add
  5704. setChargerMode(gun_index, MODE_PRECHARGE);
  5705. } else {
  5706. setChargerMode(gun_index, MODE_IDLE);
  5707. }
  5708. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 add
  5709. } else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
  5710. ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO) {
  5711. log_info("=============Smart Charging : _REASSIGNED_COMP============= Step 6 \n");
  5712. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  5713. //ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE; //DS60-120 remove
  5714. ShmSysConfigAndInfo->SysInfo.CanAverageCharging = true; //DS60-120 add
  5715. }
  5716. //log_info("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);
  5717. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  5718. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
  5719. // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  5720. }
  5721. }
  5722. break;
  5723. case S_PREPARNING: {
  5724. if (isModeChange(gun_index)) {
  5725. log_info("S_PREPARNING================================== %x \n", gun_index);
  5726. StopGunInfoTimeoutDet(gun_index);
  5727. StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
  5728. }
  5729. if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
  5730. ShmPsuData->SystemAvailablePower > 10 &&
  5731. GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 5000000) {
  5732. //if ((chargingInfo[gun_index]->MaximumChargingVoltage > 0) && //DS60-120 remove
  5733. // (chargingInfo[gun_index]->AvailableChargingCurrent > 0) &&
  5734. // (chargingInfo[gun_index]->AvailableChargingPower > 0)) {
  5735. setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
  5736. //}
  5737. }
  5738. //DS60-120 add
  5739. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2) {
  5740. bool oughtAver = true;
  5741. for (uint8_t index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++) {
  5742. // 共同進入充電邏輯
  5743. if (chargingInfo[index]->SystemStatus != S_PREPARNING) {
  5744. oughtAver = false;
  5745. break;
  5746. }
  5747. }
  5748. if (oughtAver) {
  5749. log_info("********* Automatically change to aver mode ********** \n");
  5750. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  5751. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  5752. }
  5753. }
  5754. if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
  5755. // 板端要求停止 (錯誤)
  5756. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
  5757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
  5758. }
  5759. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  5760. ChargingAlarmProcess(gun_index);
  5761. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  5762. ChargingTerminalProcess(gun_index);
  5763. }
  5764. } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
  5765. // 板端要求停止 (正常)
  5766. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
  5767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
  5768. }
  5769. ChargingTerminalProcess(gun_index);
  5770. } else if (OcppRemoteStop(gun_index) == YES ||
  5771. WifiScheduleStop(gun_index)) {
  5772. // 後臺要求停止
  5773. ChargingTerminalProcess(gun_index);
  5774. }
  5775. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  5776. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
  5777. // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  5778. }
  5779. }
  5780. break;
  5781. case S_PREPARING_FOR_EV: { // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
  5782. if (isModeChange(gun_index)) {
  5783. log_info("S_PREPARING_FOR_EV================================== %x \n", gun_index);
  5784. //strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  5785. StopGunInfoTimeoutDet(gun_index);
  5786. StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
  5787. }
  5788. if (chargingInfo[gun_index]->Type == _Type_Chademo) {
  5789. // 檢查車端的槍鎖是否為鎖上
  5790. if (isEvGunLocked_chademo(gun_index) == YES) {
  5791. setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
  5792. }
  5793. } else if (chargingInfo[gun_index]->Type == _Type_GB) {
  5794. // 檢查車端的 charging enable 是否為 1
  5795. if (isEvGunLocked_gb(gun_index) == YES) {
  5796. setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
  5797. }
  5798. } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
  5799. // 檢查車端的 charging enable 是否為 1
  5800. if (isEvGunLocked_ccs(gun_index) == YES) {
  5801. setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
  5802. }
  5803. }
  5804. if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
  5805. // 板端要求停止 (錯誤)
  5806. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
  5807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
  5808. }
  5809. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  5810. ChargingAlarmProcess(gun_index);
  5811. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  5812. ChargingTerminalProcess(gun_index);
  5813. }
  5814. } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
  5815. // 板端要求停止 (正常)
  5816. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
  5817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
  5818. }
  5819. ChargingTerminalProcess(gun_index);
  5820. } else if (OcppRemoteStop(gun_index) == YES ||
  5821. WifiScheduleStop(gun_index)) {
  5822. // 後臺要求停止
  5823. ChargingTerminalProcess(gun_index);
  5824. }
  5825. // LCM => Pre-charging
  5826. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  5827. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
  5828. // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  5829. }
  5830. }
  5831. break;
  5832. case S_PREPARING_FOR_EVSE: { // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
  5833. if (isModeChange(gun_index)) {
  5834. log_info("S_PREPARING_FOR_EVSE================================== %x \n", gun_index);
  5835. StopGunInfoTimeoutDet(gun_index);
  5836. StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
  5837. }
  5838. if (chargingInfo[gun_index]->Type == _Type_Chademo) {
  5839. // 檢查樁端的 GFD 結果
  5840. if (isPrechargeStatus_chademo(gun_index) > 5 && isPrechargeStatus_chademo(gun_index) < 8) {
  5841. // 當前操作的槍號,進入 Charging
  5842. setChargerMode(gun_index, MODE_CHARGING);
  5843. }
  5844. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  5845. // GFD 錯誤停止
  5846. RecordAlarmCode(gun_index, "012234");
  5847. } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
  5848. // GFD 警告
  5849. RecordWarningCode(gun_index, "012296");
  5850. }
  5851. } else if (chargingInfo[gun_index]->Type == _Type_GB) {
  5852. // 檢查樁端的 GFD 結果
  5853. //if (isPrechargeStatus_gb(gun_index) > 5 && isPrechargeStatus_gb(gun_index) < 9) {
  5854. if (isPrechargeStatus_gb(gun_index) > 9) {
  5855. setChargerMode(gun_index, MODE_CHARGING);
  5856. }
  5857. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  5858. // GFD 錯誤停止
  5859. RecordAlarmCode(gun_index, "012236");
  5860. } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
  5861. // GFD 警告
  5862. RecordWarningCode(gun_index, "012298");
  5863. }
  5864. } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
  5865. // 檢查樁端的 GFD 結果
  5866. if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
  5867. chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)) {
  5868. setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
  5869. }
  5870. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  5871. // GFD 錯誤停止
  5872. RecordAlarmCode(gun_index, "012235");
  5873. } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
  5874. // GFD 警告
  5875. RecordWarningCode(gun_index, "012297");
  5876. }
  5877. }
  5878. if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
  5879. // 板端要求停止 (錯誤)
  5880. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
  5881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
  5882. }
  5883. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  5884. ChargingAlarmProcess(gun_index);
  5885. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  5886. ChargingTerminalProcess(gun_index);
  5887. }
  5888. } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
  5889. // 板端要求停止 (正常)
  5890. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
  5891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
  5892. }
  5893. ChargingTerminalProcess(gun_index);
  5894. } else if (OcppRemoteStop(gun_index) == YES ||
  5895. WifiScheduleStop(gun_index)) {
  5896. // 後臺要求停止
  5897. ChargingTerminalProcess(gun_index);
  5898. }
  5899. // LCM => Pre-charging
  5900. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  5901. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
  5902. // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  5903. }
  5904. }
  5905. break;
  5906. case S_CHARGING: { // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
  5907. if (isModeChange(gun_index)) {
  5908. log_info("S_CHARGING================================== %x \n", gun_index);
  5909. StopGunInfoTimeoutDet(gun_index);
  5910. ftime(&startChargingTime[gun_index]);
  5911. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, ""); //DS60-120 add
  5912. ChangeStartOrStopDateTime(YES, gun_index);
  5913. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  5914. OcppStartTransation(gun_index);
  5915. #endif //!defined DD360 && !defined DD360Audi
  5916. }
  5917. if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf) {
  5918. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
  5919. }
  5920. ftime(&endChargingTime[gun_index]);
  5921. chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
  5922. if (chargingInfo[gun_index]->Type == _Type_Chademo) {
  5923. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  5924. // GFD 錯誤停止
  5925. RecordAlarmCode(gun_index, "012234");
  5926. }
  5927. //else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
  5928. // (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)) {
  5929. // // UVP
  5930. // RecordAlarmCode(gun_index, "012289");
  5931. // ChargingTerminalProcess(gun_index);
  5932. //}
  5933. else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
  5934. // GFD 警告
  5935. RecordWarningCode(gun_index, "012296");
  5936. }
  5937. } else if (chargingInfo[gun_index]->Type == _Type_GB) {
  5938. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  5939. // GFD 錯誤停止
  5940. RecordAlarmCode(gun_index, "012236");
  5941. }
  5942. //else if (isPrechargeStatus_gb(gun_index) == 10 &&
  5943. // (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
  5944. // (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))) {
  5945. // // UVP
  5946. // RecordAlarmCode(gun_index, "012290");
  5947. // ChargingTerminalProcess(gun_index);
  5948. //}
  5949. else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
  5950. // GFD 警告
  5951. RecordWarningCode(gun_index, "012298");
  5952. }
  5953. } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
  5954. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  5955. // GFD 錯誤停止
  5956. RecordAlarmCode(gun_index, "012235");
  5957. }
  5958. //else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
  5959. // (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)) {
  5960. // // UVP
  5961. // RecordAlarmCode(gun_index, "012288");
  5962. // ChargingTerminalProcess(gun_index);
  5963. //}
  5964. else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
  5965. // GFD 警告
  5966. RecordWarningCode(gun_index, "012297");
  5967. }
  5968. }
  5969. if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
  5970. // 板端要求停止 (錯誤)
  5971. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
  5972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
  5973. }
  5974. //printf("%d evBoardStopState = %d\r\n", gun_index, evBoardStopState);
  5975. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  5976. ChargingAlarmProcess(gun_index);
  5977. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  5978. ChargingTerminalProcess(gun_index);
  5979. }
  5980. } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
  5981. // 板端要求停止 (正常)
  5982. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
  5983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
  5984. }
  5985. ChargingTerminalProcess(gun_index);
  5986. } else if (OcppRemoteStop(gun_index) == YES ||
  5987. WifiScheduleStop(gun_index) ||
  5988. CheckBackendChargingTimeout(gun_index) ||
  5989. CheckBackendChargingEnergy(gun_index) ||
  5990. strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
  5991. // 後臺要求停止
  5992. ChargingTerminalProcess(gun_index);
  5993. }
  5994. // LCM => Charging
  5995. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  5996. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
  5997. // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  5998. }
  5999. }
  6000. break;
  6001. case S_ALARM:
  6002. case S_TERMINATING: {
  6003. if (isModeChange(gun_index)) {
  6004. if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
  6005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
  6006. }
  6007. if (chargingInfo[gun_index]->SystemStatus == S_ALARM) {
  6008. log_info("================== S_ALARM (%x) ================ \n", gun_index);
  6009. UpdateErrorCodeToOcpp(gun_index);
  6010. if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
  6011. OcppStopTransation(gun_index);
  6012. }
  6013. TheEndCharging(gun_index);
  6014. } else {
  6015. log_info("================== S_TERMINATING (%x) ================ \n", gun_index);
  6016. }
  6017. //log_info ("terminating......................... %x \n", gun_index);
  6018. StopGunInfoTimeoutDet(gun_index);
  6019. }
  6020. if (chargingInfo[gun_index]->Type == _Type_Chademo) {
  6021. // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
  6022. //if (isEvStopCharging_chademo(gun_index) == YES) {
  6023. // /*+++ 20200908, vern, disable it for DD360 +++*/
  6024. // /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
  6025. // strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
  6026. // /*--- 20200908, vern, disable it for DD360 ---*/
  6027. //}
  6028. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  6029. // GFD 錯誤停止
  6030. RecordAlarmCode(gun_index, "012234");
  6031. } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
  6032. // GFD 警告
  6033. RecordWarningCode(gun_index, "012296");
  6034. }
  6035. //if (isEvStopCharging_chademo(gun_index) == YES ||
  6036. // isPrechargeStatus_chademo(gun_index) <= 0) {
  6037. // setChargerMode(gun_index, MODE_COMPLETE);
  6038. //}
  6039. } else if (chargingInfo[gun_index]->Type == _Type_GB) {
  6040. //log_info("************ GB lock Status = %d, status = %d \n",
  6041. // isEvStopCharging_gb(gun_index),
  6042. // isPrechargeStatus_gb(gun_index));
  6043. // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
  6044. //if (isEvStopCharging_chademo(gun_index) == YES) {
  6045. // /*+++ 20200908, vern, disable it for DD360 +++*/
  6046. // /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
  6047. // strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
  6048. // /*--- 20200908, vern, disable it for DD360 ---*/
  6049. //}
  6050. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  6051. // GFD 錯誤停止
  6052. RecordAlarmCode(gun_index, "012236");
  6053. } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
  6054. // GFD 警告
  6055. RecordWarningCode(gun_index, "012298");
  6056. }
  6057. //if (isEvStopCharging_gb(gun_index) == YES ||
  6058. // isPrechargeStatus_gb(gun_index) <= 0) {
  6059. // setChargerMode(gun_index, MODE_COMPLETE);
  6060. //}
  6061. } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
  6062. // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
  6063. //if (isEvStopCharging_chademo(gun_index) == YES) {
  6064. // /*+++ 20200908, vern, disable it for DD360 +++*/
  6065. // /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
  6066. // strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
  6067. // /*--- 20200908, vern, disable it for DD360 ---*/
  6068. //}
  6069. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  6070. // GFD 錯誤停止
  6071. RecordAlarmCode(gun_index, "012235");
  6072. } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
  6073. // GFD 警告
  6074. RecordWarningCode(gun_index, "012297");
  6075. }
  6076. //if (isEvStopCharging_ccs(gun_index) == YES &&
  6077. // (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
  6078. // isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
  6079. // setChargerMode(gun_index, MODE_COMPLETE);
  6080. //}
  6081. }
  6082. if (chargingInfo[gun_index]->SystemStatus == S_ALARM) {
  6083. if (chargingInfo[gun_index]->ConnectorPlugIn == NO &&
  6084. GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000) {
  6085. setChargerMode(gun_index, MODE_IDLE);
  6086. }
  6087. } else {
  6088. if (chargingInfo[gun_index]->Type == _Type_Chademo) {
  6089. if (isEvStopCharging_chademo(gun_index) == YES ||
  6090. isPrechargeStatus_chademo(gun_index) <= 0) {
  6091. setChargerMode(gun_index, MODE_COMPLETE);
  6092. }
  6093. } else if (chargingInfo[gun_index]->Type == _Type_GB) {
  6094. if (isEvStopCharging_gb(gun_index) == YES ||
  6095. isPrechargeStatus_gb(gun_index) <= 0) {
  6096. setChargerMode(gun_index, MODE_COMPLETE);
  6097. }
  6098. } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
  6099. if (isEvStopCharging_ccs(gun_index) == YES &&
  6100. (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
  6101. isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
  6102. setChargerMode(gun_index, MODE_COMPLETE);
  6103. }
  6104. }
  6105. }
  6106. // 車端的停止
  6107. //if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
  6108. // strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
  6109. //}
  6110. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  6111. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
  6112. // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  6113. }
  6114. }
  6115. break;
  6116. case S_COMPLETE: {
  6117. if (isModeChange(gun_index)) {
  6118. log_info ("complete......................... %x \n", gun_index);
  6119. if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
  6120. OcppStopTransation(gun_index);
  6121. }
  6122. TheEndCharging(gun_index);
  6123. //ftime(&endChargingTime[gun_index]);
  6124. //if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
  6125. // chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
  6126. //}
  6127. //StopGunInfoTimeoutDet(gun_index);
  6128. //StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
  6129. //ChangeStartOrStopDateTime(NO, gun_index);
  6130. }
  6131. //if (((chargingInfo[gun_index]->ConnectorPlugIn == NO) ||
  6132. // (restartFlag == 1)) &&
  6133. // (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)) {
  6134. // setChargerMode(gun_index, MODE_IDLE);
  6135. // destroySelGun(gun_index); //Jerry add
  6136. //}
  6137. if (chargingInfo[gun_index]->ConnectorPlugIn == NO &&
  6138. GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000) {
  6139. setChargerMode(gun_index, MODE_IDLE);
  6140. #if defined DD360Audi
  6141. destroySelGun(gun_index); //Jerry add
  6142. #endif //defined DD360Audi
  6143. }
  6144. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  6145. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
  6146. // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  6147. }
  6148. }
  6149. break;
  6150. case S_CCS_PRECHARGE_ST0: {
  6151. if (isModeChange(gun_index)) {
  6152. log_info("CCS Precharge Processing 1....................%x \n", gun_index);
  6153. StopGunInfoTimeoutDet(gun_index);
  6154. StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
  6155. }
  6156. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  6157. // GFD 錯誤停止
  6158. RecordAlarmCode(gun_index, "012235");
  6159. }
  6160. if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
  6161. // 板端要求停止 (錯誤)
  6162. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  6163. ChargingAlarmProcess(gun_index);
  6164. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  6165. ChargingTerminalProcess(gun_index);
  6166. }
  6167. } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
  6168. // 板端要求停止 (正常)
  6169. ChargingTerminalProcess(gun_index);
  6170. } else if (OcppRemoteStop(gun_index) == YES ||
  6171. WifiScheduleStop(gun_index)) {
  6172. // 後臺要求停止
  6173. ChargingTerminalProcess(gun_index);
  6174. }
  6175. // 等待 EV 小板 (CCS) 通知可以開始 Precharge
  6176. // 切換 D+ Relay to Precharge Relay
  6177. if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40) {
  6178. if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
  6179. //if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
  6180. {
  6181. //log_info("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
  6182. if (isPrechargeStatus_ccs(gun_index) == 39) {
  6183. log_info("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
  6184. } else if (isPrechargeStatus_ccs(gun_index) == 40) {
  6185. log_info("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
  6186. }
  6187. chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
  6188. }
  6189. } else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46) {
  6190. setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
  6191. }
  6192. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  6193. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
  6194. // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  6195. }
  6196. break;
  6197. }
  6198. case S_CCS_PRECHARGE_ST1: {
  6199. if (isModeChange(gun_index)) {
  6200. log_info("CCS Precharge Processing 2....................%x \n", gun_index);
  6201. }
  6202. if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
  6203. // GFD 錯誤停止
  6204. RecordAlarmCode(gun_index, "012235");
  6205. }
  6206. if ((evBoardStopState = isEvBoardStopChargeFlag(gun_index)) > 0) {
  6207. // 板端要求停止 (錯誤)
  6208. if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
  6209. ChargingAlarmProcess(gun_index);
  6210. } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
  6211. ChargingTerminalProcess(gun_index);
  6212. }
  6213. } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
  6214. // 板端要求停止 (正常)
  6215. ChargingTerminalProcess(gun_index);
  6216. } else if (OcppRemoteStop(gun_index) == YES ||
  6217. WifiScheduleStop(gun_index)) {
  6218. // 後臺要求停止
  6219. ChargingTerminalProcess(gun_index);
  6220. }
  6221. // 等待小板通知進入充電
  6222. // 切換 D+ Relay to Precharge Relay
  6223. if (chargingInfo[gun_index]->RelayK1K2Status == YES) {
  6224. chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
  6225. setChargerMode(gun_index, MODE_CHARGING);
  6226. }
  6227. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
  6228. ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
  6229. // ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
  6230. }
  6231. break;
  6232. }
  6233. }
  6234. }
  6235. #if defined DD360Audi
  6236. if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_SELECT_GUN) {
  6237. #else
  6238. if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE) {
  6239. #endif //defined DD360Audi
  6240. ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
  6241. } else {
  6242. bool dcPageRun = false;
  6243. if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
  6244. if (ac_chargingInfo[0]->SystemStatus == S_IDLE) {
  6245. ChangeLcmByIndex(_LCM_IDLE);
  6246. } else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING) {
  6247. ChangeLcmByIndex(_LCM_PRE_CHARGE);
  6248. } else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING) {
  6249. ChangeLcmByIndex(_LCM_CHARGING);
  6250. } else if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING ||
  6251. ac_chargingInfo[0]->SystemStatus == S_COMPLETE) {
  6252. ChangeLcmByIndex(_LCM_COMPLETE);
  6253. } else {
  6254. dcPageRun = true;
  6255. }
  6256. } else {
  6257. dcPageRun = true;
  6258. }
  6259. if (dcPageRun) {
  6260. ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
  6261. }
  6262. }
  6263. for (uint8_t gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++) {
  6264. checkEvBoardAlarmState(chargingInfo[gun_index]->Type);
  6265. }
  6266. write(wtdFd, "a", 1);
  6267. usleep(whileLoopTime);
  6268. }
  6269. return FAIL;
  6270. }