ReMain.c 277 KB

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