12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709 |
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <string.h>
- #include <stdint.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include "../../define.h"
- #include "Config.h"
- #include <stdbool.h>
- #include <dirent.h>
- #include "timeout.h"
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define PASS 1
- #define FAIL -1
- #define MODELNAME_FAIL 0
- #define BUFFER_SIZE 128
- #define YES 1
- #define NO 0
- #define NORMAL 0
- #define ABNORMAL 1
- #define EQUAL 0
- #define BTN_RELEASE 0
- #define BTN_PRESS 1
- #define MAX_BUF 64
- #define MtdBlockSize 0x600000
- #define SYSFS_GPIO_DIR "/sys/class/gpio"
- #define UPGRADE_FAN 0x02
- #define UPGRADE_RB 0x03
- #define UPGRADE_PRI 0x04
- #define UPGRADE_AC 0x05
- #define UPGRADE_LED 0x06
- #define SYSTEM_MIN_VOL 80
- #define MIN_OUTPUT_CUR 0
- #define AC_OUTPUT_VOL 220
- #define NO_DEFINE 255
- #define DEFAULT_AC_INDEX 2
- #define PSU_MIN_CUR 100
- #define DB_FILE "/Storage/ChargeLog/localCgargingRecord.db"
- #define GUN_OTP_VALUE 150
- #define GUN_OTP_RECOVERY 140
- #define UNDEFINED_TEMP 255
- #define uSEC_VAL 1000000
- #define SELFTEST_TIMEOUT 60
- #define AUTHORIZE_TIMEOUT 15
- #define AUTHORIZE_COMP_TIMEOUT 3
- #define AUTHORIZE_FAIL_TIMEOUT 3
- #define AUTHORIZE_STOP_TIMEOUT 30
- #define RETURN_TO_CHARGING_PAGE 30
- #define GUN_PREPARE_TIMEOUT 30
- #define GUN_EV_WAIT_TIMEOUT 120
- #define GUN_EVSE_WAIT_TIMEOUT 60
- #define GUN_COMP_WAIT_TIMEOUT 10
- #define GUN_PRECHARGING_TIMEOUT 60
- #define TIMEOUT_SPEC_HANDSHAKING 180000
- char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
- unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
- int whileLoopTime = 10000; // 10 ms
- int wtdFd = -1;
- byte _authorizeIndex = NO_DEFINE;
- bool IsAuthorizingMode();
- void ClearAuthorizedFlag();
- bool isDetectPlugin();
- void ClearDetectPluginFlag();
- int mystrcmp(unsigned char *p1, unsigned char *p2);
- long long DiffTimebWithNow(struct timeb ST);
- unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
- void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
- void ChargingTerminalProcess(byte gunIndex);
- void ChkPrimaryStatus();
- void StartSystemTimeoutDet(unsigned char flag);
- void StopSystemTimeoutDet();
- void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
- void StopGunInfoTimeoutDet(unsigned char gunIndex);
- int StoreLogMsg_1(const char *fmt, ...);
- unsigned long GetTimeoutValue(struct timeval _sour_time);
- void gpio_set_value(unsigned int gpio, unsigned int value);
- void PRINTF_FUNC(char *string, ...);
- void ChangeGunSelectByIndex(byte sel);
- void ChargingAlarmProcess(byte gunIndex);
- void CheckSystemErrorFunction(byte index);
- int opcc_chk_reserve_expired(byte gunIndex);
- void ocpp_process_start();
- void ocpp_auto_response_BootNotification();
- void ocpp_auto_response_StartTransationConf(byte gunIndex);
- bool ocpp_chk_authrization_cmd();
- void ocpp_chk_reset_cmd();
- void ocpp_chk_reserved_cmd(byte gunIndex);
- void ocpp_chk_availability_cmd(byte gunIndex);
- void ocpp_chk_unlock_cmd(byte gunIndex);
- bool ocpp_chk_remoteStop_cmd(byte gunIndex);
- void ocpp_chk_remoteStart_cmd();
- void ocpp_chk_update_cmd();
- bool ocpp_chk_invalid_id_cmd(byte gunIndex);
- void ocpp_set_startTransation_cmd(byte gunIndex);
- void ocpp_set_stopTransation_cmd(byte gunIndex);
- void ocpp_set_errorCode_cmd(byte gunIndex, char *errString);
- void ocpp_set_stopReason_by_cmd(byte gunIndex, char *reason);
- void ocpp_set_authorizeReq_cmd(byte value);
- void ocpp_set_authorizeConf_cmd(byte value);
- void ocpp_set_errCode_cmd(byte gunIndex);
- void ocpp_clear_errorCode_cmd(byte gunIndex);
- void ocpp_clear_idTag_cmd(byte gun_index);
- void ocpp_clear_stopReason(byte gun_index);
- bool ocpp_get_authorize_conf();
- unsigned short _ocpp_get_connect_timeout();
- void ocpp_chargingProfile_process(byte gun_index);
- bool _ocpp_get_disconnect_policy();
- void RecordAlarmCode(byte gunIndex, char *code);
- void ReleaseSysAlarmCode(byte gunIndex);
- void ReviewCriticalAlarm();
- int DB_Open(sqlite3 *db);
- int DB_Insert_Record(sqlite3 *db, int gun_index);
- int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
- int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
- void InitialDHCP();
- int GetStartScheduleTime(unsigned char *time);
- #define DEBUG_INFO_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- #define DEBUG_WARN_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- #define DEBUG_ERROR_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct PsuData *ShmPsuData;
- struct CHAdeMOData *ShmCHAdeMOData;
- struct GBTData *ShmGBTData;
- struct CcsData *ShmCcsData;
- struct PrimaryMcuData *ShmPrimaryMcuData;
- struct FanModuleData *ShmFanModuleData;
- struct RelayModuleData *ShmRelayModuleData;
- struct LedModuleData *ShmLedModuleData;
- struct OCPP16Data *ShmOCPP16Data;
- struct OCPP20Data *ShmOCPP20Data;
- struct MeterInformation *ShmCsuMeterData;
- struct DcCommonInformation *ShmDcCommonData;
- struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
- struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- int _presentChargingTimeBuf[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timeval _startTransation_time[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- float gunOutputVol [CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- GunErr errCollect;
- // for initial index to check EV board type is correct
- byte _gunIndex = 0;
- byte _acgunIndex = 0;
- byte _chademoIndex = 0;
- byte _ccsIndex = 0;
- byte _gb_Index = 0;
- byte _ac_Index = 0;
- byte bd0_1_status = 0;
- byte bd0_2_status = 0;
- byte bd1_1_status = 0;
- byte bd1_2_status = 0;
- bool isCardScan = false;
- bool isModelNameMatch = true;
- int rfidFd = -1;
- char* rfidPortName = "/dev/ttyS2";
- char* fwVersion = "V1.08.00.0000.00";
- sqlite3 *localDb;
- bool isDb_ready;
- //================================================
- // initial can-bus
- //================================================
- int InitCanBus()
- {
- int s0,nbytes;
- struct timeval tv;
- struct ifreq ifr0;
- struct sockaddr_can addr0;
- system("/sbin/ip link set can0 down");
- system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
- system("/sbin/ip link set can0 up");
- s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
- tv.tv_sec = 0;
- tv.tv_usec = 10000;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("Set SO_RCVTIMEO NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("Set SO_RCVBUF NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("Set SO_SNDBUF NG");
- #endif
- }
- strcpy(ifr0.ifr_name, "can0" );
- ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
- addr0.can_family = AF_CAN;
- addr0.can_ifindex = ifr0.ifr_ifindex;
- bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
- return s0;
- }
- //================================================
- // initial uart port
- //================================================
- char *_priPortName = "/dev/ttyS1";
- char *_485PortName = "/dev/ttyS5";
- int InitComPort(byte target)
- {
- int fd;
- struct termios tios;
- if(target == UPGRADE_PRI)
- fd = open(_priPortName, O_RDWR);
- else if (target == UPGRADE_FAN || target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED)
- fd = open(_485PortName, O_RDWR);
- if(fd<=0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("open 407 Communication port NG \n");
- #endif
- return -1;
- }
- ioctl (fd, TCGETS, &tios);
- tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN]=0;
- tios.c_cc[VTIME]=(unsigned char)5;
- tios.c_lflag=0;
- tcflush(fd, TCIFLUSH);
- ioctl (fd, TCSETS, &tios);
- return fd;
- }
- //=================================
- // Common routine
- //=================================
- void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
- {
- strncpy(dest, src + start, cnt);
- dest[cnt] = 0;
- }
- int InitWatchDog()
- {
- int fd;
- system("/usr/bin/fuser -k /dev/watchdog");
- sleep(1);
- system("echo V > /dev/watchdog");
- sleep(1);
- fd=open("/dev/watchdog", O_RDWR);
- if(fd<=0)
- {
- DEBUG_ERROR_MSG("System watch dog initial fail.\r\n");
- }
- return fd;
- }
- int StoreLogMsg_1(const char *fmt, ...)
- {
- char Buf[4096+256];
- char buffer[4096];
- va_list args;
- struct timeb SeqEndTime;
- struct tm *tm;
- va_start(args, fmt);
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- memset(Buf,0,sizeof(Buf));
- ftime(&SeqEndTime);
- SeqEndTime.time = time(NULL);
- tm=localtime(&SeqEndTime.time);
- if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
- {
- sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
- tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
- printf("%s \n", Buf);
- }
- else
- {
- sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
- buffer,
- tm->tm_year+1900,tm->tm_mon+1,
- ShmSysConfigAndInfo->SysConfig.SerialNumber);
- system(Buf);
- }
- return rc;
- }
- unsigned long GetTimeoutValue(struct timeval _sour_time)
- {
- struct timeval _end_time;
- gettimeofday(&_end_time, NULL);
- return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
- }
- int mystrcmp(unsigned char *p1, unsigned char *p2)
- {
- while(*p1==*p2)
- {
- if(*p1=='\0' || *p2=='\0')
- break;
- p1++;
- p2++;
- }
- if(*p1=='\0' && *p2=='\0')
- return(PASS);
- else
- return(FAIL);
- }
- int DiffTimeb(struct timeb ST, struct timeb ET)
- {
- //return milli-second
- unsigned int StartTime,StopTime;
- StartTime=(unsigned int)ST.time;
- StopTime=(unsigned int)ET.time;
- //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
- return (StopTime-StartTime);
- }
- bool CheckTimeOut(struct timeb ST)
- {
- struct timeb ET;
- unsigned int StartTime, StopTime;
- ftime(&ET);
- StartTime = (unsigned int) ST.time;
- StopTime = (unsigned int) ET.time;
- return (StopTime > StartTime)? YES : NO;
- }
- void setChargerMode(byte gun_index, byte mode)
- {
- chargingInfo[gun_index]->SystemStatus = mode;
- }
- void PRINTF_FUNC(char *string, ...)
- {
- va_list args;
- char buffer[4096];
- va_start(args, string);
- vsnprintf(buffer, sizeof(buffer), string, args);
- va_end(args);
- DEBUG_INFO_MSG("%s ", buffer);
- }
- long long DiffTimebWithNow(struct timeb ST)
- {
- //return milli-second
- struct timeb ET;
- long long StartTime, StopTime;
- ftime(&ET);
- StartTime = (long long)ST.time;
- StopTime = (long long)ET.time;
- return ((StopTime - StartTime)*1000) + (ET.millitm - ST.millitm);
- }
- bool CheckBackendChargingTimeout(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60))
- result = true;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- // 隨插即充電的要看 offline
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60))
- result = true;
- }
- }
- return result;
- }
- bool CheckBackendChargingEnergy(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy > ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)
- result = true;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- // 隨插即充電的要看 offline
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy))
- result = true;
- }
- }
- return result;
- }
- //==========================================
- // Log
- //==========================================
- void CheckFwSlotStatusLog()
- {
- if (bd0_1_status == 0 && bd0_2_status == 1)
- PRINTF_FUNC("Connector 1 : Chademo");
- else if (bd0_1_status == 1 && bd0_2_status == 0)
- PRINTF_FUNC("Connector 1 : CCS");
- else if (bd0_1_status == 1 && bd0_2_status == 1)
- PRINTF_FUNC("Connector 1 : GB");
- if (bd1_1_status == 0 && bd1_2_status == 1)
- PRINTF_FUNC("Connector 2 : Chademo");
- else if (bd1_1_status == 1 && bd1_2_status == 0)
- PRINTF_FUNC("Connector 2 : CCS");
- else if (bd1_1_status == 1 && bd1_2_status == 1)
- PRINTF_FUNC("Connector 2 : GB");
- }
- void CheckHwSlotStatusLog(byte index)
- {
- if (chargingInfo[index]->Type == _Type_Chademo)
- {
- PRINTF_FUNC("Hw check : Connector %d, Type : Chademo, Evboard_id = %d \n",
- index, chargingInfo[index]->Evboard_id);
- }
- else if (chargingInfo[index]->Type == _Type_CCS_2)
- {
- PRINTF_FUNC("Hw check : Connector %d, Type : CCS, Evboard_id = %d \n",
- index, chargingInfo[index]->Evboard_id);
- }
- else if (chargingInfo[index]->Type == _Type_GB)
- {
- PRINTF_FUNC("Hw check : Connector %d, Type : GB, Evboard_id = %d \n",
- index, chargingInfo[index]->Evboard_id);
- }
- }
- //==========================================
- // Check interface status
- //==========================================
- int isInterfaceUp(const char *interface)
- {
- int result = FAIL;
- FILE *fp;
- char cmd[256];
- char buf[512];
- strcpy(cmd, "ifconfig");
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, interface) > 0)
- {
- result = PASS;
- }
- }
- }
- pclose(fp);
- return result;
- }
- //=================================
- // Create all share memory
- //=================================
- int CreateShareMemory()
- {
- int MeterSMId;
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
- return 0;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
- return 0;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmStatusCodeData NG \n");
- return 0;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmStatusCodeData NG \n");
- return 0;
- }
- memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
- //creat ShmPsuData
- if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPsuData NG \n");
- return 0;
- }
- else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPsuData NG \n");
- return 0;
- }
- memset(ShmPsuData, 0, sizeof(struct PsuData));
- if(CHAdeMO_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCHAdeMOData NG \n");
- return 0;
- }
- else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCHAdeMOData NG \n");
- return 0;
- }
- memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
- }
- if(GB_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmGBTData NG \n");
- return 0;
- }
- else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmGBTData NG \n");
- return 0;
- }
- memset(ShmGBTData, 0, sizeof(struct GBTData));
- }
- //creat ShmCcsData
- if(CCS_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCcsData NG \n");
- return 0;
- }
- else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCcsData NG \n");
- return 0;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
- }
- //creat ShmPrimaryMcuData
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPrimaryMcuData NG \n");
- return 0;
- }
- else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG \n");
- return 0;
- }
- memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
- //creat ShmFanModuleData
- if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmFanModuleData NG \n");
- return 0;
- }
- else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmFanModuleData NG \n");
- return 0;
- }
- memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
- //creat ShmRelayModuleData
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmRelayModuleData NG \n");
- return 0;
- }
- else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmRelayModuleData NG \n");
- return 0;
- }
- memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
- if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmLedModuleData NG \n");
- return 0;
- }
- else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmLedModuleData NG \n");
- return 0;
- }
- memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
- //creat ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmOCPP16Data NG \n");
- return 0;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmOCPP16Data NG \n");
- return 0;
- }
- memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
- if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget OCPP20Data NG\n");
- return 0;
- }
- else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat OCPP20Data NG\n");
- return 0;
- }
- memset(ShmOCPP20Data,0,sizeof(struct OCPP20Data));
- if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCsuMeterKey NG \n");
- return 0;
- }
- else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCsuMeterData NG \n");
- return 0;
- }
- memset(ShmCsuMeterData, 0, sizeof(struct MeterInformation));
- if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCommonKey NG \n");
- return 0;
- }
- else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCommonKey NG \n");
- return 0;
- }
- byte buf = 0;
- if (ShmDcCommonData->rebootCount == 1)
- buf = ShmDcCommonData->rebootCount;
- memset(ShmDcCommonData, 0, sizeof(struct DcCommonInformation));
- ShmDcCommonData->rebootCount = buf;
- return 1;
- }
- void SetupRebootCount(byte value)
- {
- int MeterSMId;
- if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
- {
- DEBUG_ERROR_MSG("[main]RecordRebootCount:shmget ShmCommonKey NG \n");
- }
- else
- {
- ShmDcCommonData->rebootCount = value;
- shmctl(MeterSMId, IPC_SET, 0);
- }
- }
- //=================================
- // LCM Page
- //=================================
- void ChangeLcmByIndex(byte page_index)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
- page_index == _LCM_COMPLETE || page_index == _LCM_FIX || page_index == _LCM_EMC)
- {
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0 &&
- (page_index == _LCM_FIX || page_index == _LCM_EMC))
- {
- bool isUpdate = false;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus != S_RESERVATION &&
- chargingInfo[_index]->SystemStatus != S_MAINTAIN)
- {
- isUpdate = true;
- }
- }
- if (isUpdate &&
- ShmDcCommonData->LcmFwVersion > 0 &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_EMC;
- else
- ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_FIX;
- }
- else
- ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
- }
- }
- //======================================================
- // Peripheral initial
- //======================================================
- void InitGPIO()
- {
- /*****************0~3, 4 bank, bank x 32+ num*********************/
- /***************************************************************/
- /*************** GPIO 0 ***************************************/
- /***************************************************************/
- /* GPMC_AD8 => GPIO0_22 *//*ID BD1_1*/
- system("echo 22 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio22/direction");
- /* GPMC_AD9 => GPIO0_23 *//*ID BD1_2*/
- system("echo 23 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio23/direction");
- /* GPMC_AD10 => GPIO0_26 *//*IO BD1_1*/
- system("echo 26 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio26/direction");
- system("echo 1 > /sys/class/gpio/gpio26/value");
- /* GPMC_AD11 => GPIO0_27 *//*IO BD1_2*/
- system("echo 27 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio27/direction");
- /* RMII1_REF_CLK => GPIO0_29 *//*USB 0 OCP detection*/
- system("echo 29 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio29/direction");
- /*XDMA_EVENT_INTR0 => GPIO0_19 *//*AM_RFID_RST*/
- system("echo 19 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio19/direction");
- system("echo 1 > /sys/class/gpio/gpio19/value");
- /*XDMA_EVENT_INTR1 => GPIO0_20 *//*AM_RFID_ICC*/
- system("echo 20 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio20/direction");
- /***************************************************************/
- /*************** GPIO 1 ***************************************/
- /***************************************************************/
- /* GPMC_AD12 => GPIO1_12 *//*ID BD2_1*/
- system("echo 44 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio44/direction");
- /* GPMC_AD13 => GPIO1_13 *//*ID BD2_2*/
- system("echo 45 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio45/direction");
- /* GPMC_AD14 => GPIO1_14 *//*IO BD2_1*/
- system("echo 46 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio46/direction");
- system("echo 0 > /sys/class/gpio/gpio46/value");
- /* GPMC_AD15 => GPIO1_15 *//*IO BD2_2*/
- system("echo 47 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio47/direction");
- /***************************************************************/
- /*************** GPIO 2 ***************************************/
- /***************************************************************/
- /*LCD_AC_BIAS_EN => GPIO2_25*//*RS-485 for module DE control*/
- system("echo 89 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio89/direction");
- system("echo 1 > /sys/class/gpio/gpio89/value");
- /*LCD_HSYNC => GPIO2_23*//*RS-485 for module RE control*/
- system("echo 87 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio87/direction");
- system("echo 0 > /sys/class/gpio/gpio87/value");
- /*LCD_PCLK => GPIO2_24*//*CCS communication board 1 proximity*/
- system("echo 88 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio88/direction");
- /*LCD_VSYNC => GPIO2_22*//*CCS communication board 2 proximity*/
- system("echo 86 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio86/direction");
- /***************************************************************/
- /*************** GPIO 3 ***************************************/
- /***************************************************************/
- /*MCASP0_FSX => GPIO3_15*//*Emergency Stop button detect*/
- system("echo 111 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio111/direction");
- /*MCASP0_ACLKR => GPIO3_18*//*USB1 OCP detect*/
- system("echo 114 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio114/direction");
- /*MCASP0_AHCLKR => GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
- system("echo 113 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio113/direction");
- /*MCASP0_ACLKX => GPIO3_14*//*Ethernet PHY reset*/
- system("echo 110 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio110/direction");
- system("echo 0 > /sys/class/gpio/gpio110/value");
- /* MCASP0_FSR => GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
- system("echo 115 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio115/direction");
- system("echo 0 > /sys/class/gpio/gpio115/value");
- /* MCASP0_AXR0 => GPIO3_16 *//*CSU board function OK indicator.*/
- system("echo 112 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio112/direction");
- system("echo 1 > /sys/class/gpio/gpio112/value");
- /* MCASP0_AXR1 => GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
- system("echo 116 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio116/direction");
- system("echo 0 > /sys/class/gpio/gpio116/value");
- /* (C14) EMU0.gpio3[7] */ /*CP open/short feature enable/disable, pull low for default enable*/
- system("echo 103 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio103/direction");
- system("echo 0 > /sys/class/gpio/gpio103/value");
- /* (B14) EMU1.gpio3[8] */ /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
- system("echo 104 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio104/direction");
- system("echo 0 > /sys/class/gpio/gpio104/value");
- #ifdef SystemLogMessage
- DEBUG_INFO_MSG("[main]InitGPIO: Initial GPIO OK \n");
- #endif
- }
- int LoadSysConfigAndInfo(struct SysConfigData *ptr)
- {
- int fd,wrd;
- unsigned char *buf;
- unsigned int ChkSum,ChkSumOrg;
- if((buf=malloc(MtdBlockSize))==NULL)
- {
- DEBUG_ERROR_MSG("malloc buffer NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- //================================================
- // Load configuration from mtdblock10
- //================================================
- fd = open("/dev/mtdblock10", O_RDWR);
- if (fd < 0)
- {
- free(buf);
- DEBUG_ERROR_MSG("open mtdblock10 NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- wrd=read(fd, buf, MtdBlockSize);
- close(fd);
- if(wrd<MtdBlockSize)
- {
- free(buf);
- DEBUG_ERROR_MSG("read SysConfigData data NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum=0;
- for(wrd=0;wrd<MtdBlockSize-4;wrd++)
- {
- ChkSum+=buf[wrd];
- }
- memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
- //================================================
- // Load configuration from mtdblock11
- //================================================
- if(ChkSum!=ChkSumOrg)
- {
- DEBUG_ERROR_MSG("Primary SysConfigData checksum NG, read backup\r\n");
- fd = open("/dev/mtdblock11", O_RDWR);
- if (fd < 0)
- {
- free(buf);
- DEBUG_ERROR_MSG("open mtdblock11 (backup) NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- wrd=read(fd, buf,MtdBlockSize);
- close(fd);
- if(wrd<MtdBlockSize)
- {
- free(buf);
- DEBUG_ERROR_MSG("read backup SysConfigData data NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum=0;
- for(wrd=0;wrd<MtdBlockSize-4;wrd++)
- {
- ChkSum+=buf[wrd];
- }
- memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
- //================================================
- // Load configuration from mtdblock12 (Factory default)
- //================================================
- if(ChkSum!=ChkSumOrg)
- {
- DEBUG_ERROR_MSG("backup SysConfigData checksum NG, read Factory default\r\n");
- fd = open("/dev/mtdblock12", O_RDWR);
- if (fd < 0)
- {
- free(buf);
- DEBUG_ERROR_MSG("open mtdblock12 (Factory default) NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- wrd=read(fd, buf,MtdBlockSize);
- close(fd);
- if(wrd<MtdBlockSize)
- {
- free(buf);
- DEBUG_ERROR_MSG("read factory default SysConfigData data NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum=0;
- for(wrd=0;wrd<MtdBlockSize-4;wrd++)
- {
- ChkSum+=buf[wrd];
- }
- memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
- if(ChkSum!=ChkSumOrg)
- {
- DEBUG_ERROR_MSG("factory default SysConfigData checksum NG, restore factory default\r\n");
- free(buf);
- system("cd /root;./FactoryConfig -m");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- return FAIL;
- }
- }
- }
- //load OK
- memcpy((struct SysConfigData *)ptr,buf,sizeof(struct SysConfigData));
- free(buf);
- DEBUG_INFO_MSG("Load SysConfigData OK\r\n");
- return PASS;
- }
- int isRouteFail()
- {
- int result = YES;
- FILE *fp;
- char buf[512];
- fp = popen("route -n", "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, "eth0") != NULL)
- result = NO;
- }
- }
- pclose(fp);
- return result;
- }
- int isReachableInternet()
- {
- int result = FAIL;
- FILE *fp;
- char cmd[256];
- char buf[512];
- char tmp[512];
- // if (ShmOCPP16Data->OcppConnStatus == PASS)
- // {
- // result = PASS;
- // }
- // else
- {
- strcpy(cmd, "ifconfig eth0");
- fp = popen(cmd, "r");
- if (fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if (strstr(buf, "inet addr:") > 0)
- {
- sscanf(buf, "%*s%s", tmp);
- substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
- if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != EQUAL)
- {
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
- }
- sscanf(buf, "%*s%*s%*s%s", tmp);
- substr(tmp, tmp, strspn(tmp, "Mask:"), strlen(buf)-strspn(tmp, "Mask:"));
- if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress) != 0)
- {
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress, tmp);
- }
- }
- }
- }
- pclose(fp);
- memset(buf, 0x00, sizeof(buf));
- for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
- {
- sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, "transmitted") > 0)
- {
- //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
- if(strstr(buf,"100%") != NULL)
- {
- }
- else
- {
- result = PASS;
- }
- //DEBUG_INFO("%s",buf);
- //DEBUG_INFO("%s\n",tmp);
- }
- }
- }
- pclose(fp);
- }
- }
- return result;
- }
- void InitEthernet()
- {
- system("ifconfig eth0 down");// eth0 down
- system("ifconfig eth1 down");// eth1 down
- sleep(2);
- char tmpbuf[256];
- // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
- system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
- sleep(2);
- //Init Eth0 for internet
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- system(tmpbuf);
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"route add default gw %s eth0 ",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- system(tmpbuf);
- //system("ifconfig lo up");
- // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
- //Init Eth1 for administrator tool
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up",
- ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
- system(tmpbuf);
- //Run DHCP client if enabled
- system("killall udhcpc");
- system("rm -rf /etc/resolv.conf");
- system("echo nameserver 8.8.8.8 > /etc/resolv.conf"); //Google DNS server
- system("echo nameserver 180.76.76.76 > /etc/resolv.conf"); //Baidu DNS server
- //system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
- {
- sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- //Upgrade system id to /etc/hostname
- sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- pid_t pid = fork();
- uint8_t cnt_pingDNS_Fail;
- if(pid == 0)
- {
- for(;;)
- {
- if (isRouteFail())
- {
- //PRINTF_FUNC("eth0 not in route, restart eht0. \n");
- system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
- {
- InitialDHCP();
- }
- else
- {
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up &",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- system(tmpbuf);
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"route add default gw %s eth0 &",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- system(tmpbuf);
- }
- }
- if(isReachableInternet() == PASS)
- {
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = YES;
- cnt_pingDNS_Fail = 0;
- }
- else
- {
- if(++cnt_pingDNS_Fail > 3)
- {
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = NO;
- if((ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient==0))
- {
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- else
- {
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up &",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- system(tmpbuf);
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"route add default gw %s eth0 &",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- system(tmpbuf);
- }
- cnt_pingDNS_Fail = 0;
- }
- }
- bool ethResult = ShmSysConfigAndInfo->SysInfo.ethInternetConn;
- if(ethResult == YES)
- {
- system("/sbin/ifmetric eth0 0");
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- system("/sbin/ifmetric mlan0 1");
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- system("/sbin/ifmetric ppp0 2");
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- //ethResult = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn;
- ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
- if (ethResult)
- {
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- system("/sbin/ifmetric eth0 1");
- system("/sbin/ifmetric mlan0 0");
- }
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- system("/sbin/ifmetric ppp0 2");
- }
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- //ethResult = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn;
- ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == YES ? NO : YES;
- if (ethResult)
- {
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- system("/sbin/ifmetric mlan0 2");
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- system("/sbin/ifmetric eth0 1");
- system("/sbin/ifmetric ppp0 0");
- }
- }
- }
- ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
- sleep(5);
- }
- }
- #ifdef SystemLogMessage
- DEBUG_INFO_MSG("[main]InitEthernet: Initial Ethernet OK. \n");
- #endif
- }
- int InitialRfidPort()
- {
- int uartO2 = open(rfidPortName, O_RDWR);
- struct termios tios;
- if (uartO2 != FAIL)
- {
- ioctl (uartO2, TCGETS, &tios);
- tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN] = 0;
- tios.c_cc[VTIME] = (unsigned char) 1;
- tios.c_lflag = 0;
- tcflush(uartO2, TCIFLUSH);
- ioctl(uartO2, TCSETS, &tios);
- }
- if (uartO2 < 0)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
- }
- return uartO2;
- }
- void GetMacAddress()
- {
- for (byte index = 0; index < 2; index++)
- {
- int fd;
- struct ifreq ifr;
- char tarEth[5];
- char Mac[18];
- sprintf(tarEth,"eth%d",index);
- fd = socket(AF_INET, SOCK_DGRAM, 0);
- ifr.ifr_addr.sa_family = AF_INET;
- strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
- ioctl(fd, SIOCGIFHWADDR, &ifr);
- close(fd);
- sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
- ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
- ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
- if (index == 0)
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
- else
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
- }
- }
- void GetFirmwareVersion()
- {
- // Get CSU root file system version
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
- byte count = 0, chademo = 0, ccs = 0, gb = 0;
- for(uint8_t idx=0;idx<3;idx++)
- {
- if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'J' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'K')
- {
- chademo++;
- count++;
- }
- else if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'G')
- {
- gb++;
- count++;
- }
- else if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'U' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'E' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'T' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'D' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'M' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'N')
- {
- ccs++;
- count++;
- }
- }
- if (count == 1)
- {
- if (chademo > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
- else if (ccs > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
- else if (gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
- }
- else
- {
- if (chademo > 0 && ccs > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
- else if (chademo > 0 && gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
- else if (ccs > 0 && gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
- }
- // Get network option from model name
- switch(ShmSysConfigAndInfo->SysConfig.ModelName[10])
- {
- case 'B':
- case 'U':
- //Blue tooth
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
- break;
- case 'W':
- // WIFI
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
- break;
- case 'T':
- // 3G/4G
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
- break;
- case 'D':
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '5';
- break;
- default:
- // LAN
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
- break;
- }
- // Get rating power from model name
- memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
- // Get IEC or UL
- char _buf[3] = {0};
- memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 2);
- if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
- else if (strcmp(_buf, "WU") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
- memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[12], 2);
- if (strcmp(_buf, "PH") == EQUAL)
- ShmDcCommonData->ShowLogoFlag = YES;
- else
- ShmDcCommonData->ShowLogoFlag = NO;
- }
- void InitialGunIndexToUnUse()
- {
- for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
- {
- ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index = NO_DEFINE;
- }
- for (byte index = 0; index < CCS_QUANTITY; index++)
- {
- ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index = NO_DEFINE;
- }
- for (byte index = 0; index < GB_QUANTITY; index++)
- {
- ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index = NO_DEFINE;
- }
- for (byte index = 0; index < AC_QUANTITY; index++)
- {
- ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index = NO_DEFINE;
- }
- }
- void InitialShareMemoryInfo()
- {
- FILE *fp;
- char cmd[512];
- char buf[512];
- // sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
- // sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
- // sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
- ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
- ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
- ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
- sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
- memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
- sprintf(cmd, "/bin/uname -r");
- fp = popen(cmd, "r");
- if(fp == NULL)
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
- else
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
- }
- }
- GetFirmwareVersion();
- //sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
- ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
- ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
- ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
- ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
- ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
- ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail = NO;
- memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
- memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
- ShmPrimaryMcuData->SelfTest_Comp = NO;
- ShmRelayModuleData->SelfTest_Comp = NO;
- ShmFanModuleData->SelfTest_Comp = NO;
- ShmLedModuleData->SelfTest_Comp = NO;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOTTING;
- ShmFanModuleData->TestFanSpeed = 0;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- InitialGunIndexToUnUse();
- ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
- ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0;
- ShmDcCommonData->psuKeepCommunication = NO;
- ShmDcCommonData->acContactSwitch = NO;
- ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0;
- ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0;
- ShmDcCommonData->LcmFwVersion = 0;
- ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
- }
- int Initialization()
- {
- // 初始化卡號驗證的 Flag
- ClearAuthorizedFlag();
- // 初始化插槍驗證的 Flag
- ClearDetectPluginFlag();
- // UART 2 for Rfid
- rfidFd = InitialRfidPort();
- int pinOut[2] = { 116, 115 }; //D13(Cha)、C13(CCS)
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- chargingInfo[count]->RemoteStartFlag = NO;
- if (chargingInfo[count]->Type == _Type_Chademo)
- {
- gpio_set_value(pinOut[count], 0x00);
- ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
- }
- else if (chargingInfo[count]->Type == _Type_GB)
- {
- gpio_set_value(pinOut[count], 0x00);
- ShmGBTData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
- }
- else if (chargingInfo[count]->Type == _Type_CCS_2)
- {
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- gpio_set_value(pinOut[1], 0x01);
- else
- gpio_set_value(pinOut[count], 0x01);
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
- }
- ocpp_set_errorCode_cmd(count, "NoError");
- }
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
- {
- ac_chargingInfo[count]->RemoteStartFlag = NO;
- if (ac_chargingInfo[count]->Type == _Type_AC)
- {
- ac_chargingInfo[count]->SelfTest_Comp = NO;
- ocpp_set_errorCode_cmd(count + ShmSysConfigAndInfo->SysConfig.TotalConnectorCount, "NoError");
- }
- }
- PRINTF_FUNC("Information check done \n");
- return PASS;
- }
- bool InitialSystemDefaultConfig()
- {
- bool result = true;
- LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
- InitGPIO();
- InitEthernet();
- GetMacAddress();
- // system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
- // sleep(3);
- // system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
- // sleep(1);
- // system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
- return result;
- }
- bool DisplaySelfTestFailReason()
- {
- bool result = false;
- // RB、FB、407、EV 小板中有些板子無回應
- if (ShmRelayModuleData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = YES; result = true; }
- if (ShmFanModuleData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = YES; result = true; }
- if (ShmPrimaryMcuData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = YES; result = true; }
- // if (ShmLedModuleData->SelfTest_Comp == NO)
- // { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES; }
- if (ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
- { result = true; }
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (chargingInfo[index]->Type == _Type_Chademo)
- {
- if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = YES; result = true; }
- }
- else if (chargingInfo[index]->Type == _Type_GB)
- {
- if (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtboardStestFail = YES; result = true; }
- }
- else if (chargingInfo[index]->Type == _Type_CCS_2)
- {
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
- {
- if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = YES; result = true; }
- }
- }
- }
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++)
- {
- // 先借 GBT 顯示
- if (ac_chargingInfo[index]->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcConnectorStestFail = YES; result = true; }
- }
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
- {
- // AC Contact 未搭上
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = YES;
- result = true;
- }
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES)
- {
- result = true;
- }
- else if (ShmPsuData->SystemAvailablePower <= 0 && ShmPsuData->SystemAvailableCurrent <= 0)
- {
- // PSU 通訊問題
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = YES;
- result = true;
- }
- return result;
- }
- void SelfTestRun()
- {
- bool evInitFlag = false;
- StartSystemTimeoutDet(Timeout_SelftestChk);
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
- while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE ||
- GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL <= 20)
- {
- ReviewCriticalAlarm();
- ChkPrimaryStatus();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
- return;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0)
- {
- if (ShmPsuData->Work_Step == _NO_WORKING ||
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
- return;
- }
- switch(ShmSysConfigAndInfo->SysInfo.SelfTestSeq)
- {
- case _STEST_VERSION:
- {
- if (strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
- ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
- {
- //PRINTF_FUNC("RB pass \n");
- ShmRelayModuleData->SelfTest_Comp = YES;
- }
- if (strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
- ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
- {
- //PRINTF_FUNC("Fan pass \n");
- ShmFanModuleData->SelfTest_Comp = YES;
- }
- if (strlen((char *)ShmPrimaryMcuData->version) != 0 ||
- ShmPrimaryMcuData->version[0] != '\0')
- {
- //PRINTF_FUNC("407 pass \n");
- ShmPrimaryMcuData->SelfTest_Comp = YES;
- }
- // EV 小板
- if (!evInitFlag)
- {
- evInitFlag = YES;
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (chargingInfo[index]->Type == _Type_Chademo)
- {
- if (strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
- ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
- {
- //PRINTF_FUNC("chademo pass \n");
- ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
- }
- else
- {
- //PRINTF_FUNC("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
- evInitFlag = NO;
- }
- }
- else if (chargingInfo[index]->Type == _Type_GB)
- {
- if (strlen((char *)ShmGBTData->evse[chargingInfo[index]->type_index].version) != 0 ||
- ShmGBTData->evse[chargingInfo[index]->type_index].version[0] != '\0')
- {
- //PRINTF_FUNC("GBT pass \n");
- ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
- }
- else
- {
- //PRINTF_FUNC("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
- evInitFlag = NO;
- }
- }
- else if (chargingInfo[index]->Type == _Type_CCS_2)
- {
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
- {
- if (strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
- {
- //PRINTF_FUNC("ccs fw = %s \n", ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp = YES;
- }
- else
- {
- //PRINTF_FUNC("ccs fw lose...... %s \n", ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
- evInitFlag = NO;
- }
- }
- }
- }
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++)
- {
- if (ac_chargingInfo[index]->Type == _Type_AC)
- {
- if (strlen((char *)ac_chargingInfo[index]->version) != 0 ||
- ac_chargingInfo[index]->version[0] != '\0')
- {
- ac_chargingInfo[index]->SelfTest_Comp = YES;
- }
- else
- {
- evInitFlag = NO;
- }
- }
- }
- }
- if (ShmFanModuleData->SelfTest_Comp &&
- ShmRelayModuleData->SelfTest_Comp &&
- ShmPrimaryMcuData->SelfTest_Comp &&
- evInitFlag)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
- }
- }
- break;
- case _STEST_AC_CONTACTOR:
- {
- //ShmPsuData->Work_Step = _TEST_COMPLETE;
- // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
- PRINTF_FUNC("Communication board pass. \n");
- }
- }
- break;
- case _STEST_PSU_DETECT:
- {
- if (ShmPsuData->Work_Step >= GET_SYS_CAP)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
- }
- }
- break;
- case _STEST_PSU_CAP:
- {
- // 此測試是要確認當前總輸出能力
- // 如果沒有 PSU 模組請 bypass
- if (ShmPsuData->Work_Step == BOOTING_COMPLETE)
- {
- sleep(1);
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
- ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
- }
- }
- break;
- }
- }
- else
- break;
- usleep(100000);
- }
- }
- int SpawnTask()
- {
- sleep(2);
- system("/root/Module_EventLogging &");
- system("/root/Module_PrimaryComm &");
- system("/root/Module_EvComm &");
- system("/root/Module_LcmControl &");
- system("/root/Module_InternalComm &");
- system("/root/Module_PsuComm &");
- system("/root/Module_ProduceUtils &");
- //system("/root/OcppBackend &");
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
- {
- system("/root/Module_4g &");
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
- {
- system("/root/Module_Wifi &");
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- system("/root/Module_4g &");
- system("/root/Module_Wifi &");
- }
- return PASS;
- }
- int StoreUsrConfigData(struct SysConfigData *UsrData)
- {
- int result = PASS;
- int fd,wrd;
- unsigned int i,Chk;
- unsigned char *ptr, *BufTmp;
- Chk=0;
- ptr=(unsigned char *)UsrData;
- if((BufTmp = malloc(MtdBlockSize)) != NULL)
- {
- memset(BufTmp, 0, MtdBlockSize);
- memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
- for(i=0; i<MtdBlockSize-4; i++)
- Chk+=*(ptr+i);
- memcpy(BufTmp + MtdBlockSize-4, &Chk, 4);
- fd = open("/dev/mtdblock10", O_RDWR);
- if (fd > 0)
- {
- wrd=write(fd, BufTmp, MtdBlockSize);
- close(fd);
- if(wrd >= MtdBlockSize)
- {
- fd = open("/dev/mtdblock11", O_RDWR);
- if (fd > 0)
- {
- wrd=write(fd, BufTmp, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- DEBUG_ERROR_MSG("write /dev/mtdblock11(backup) NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("open /dev/mtdblock11(backup) NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("write /dev/mtdblock10 NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("open /dev/mtdblock10 NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("alloc BlockSize NG\r\n");
- result = FAIL;
- }
- if(BufTmp != NULL)
- free(BufTmp);
- return result;
- }
- //===============================================
- // Common Detect Chk - Stop Charging ?
- //===============================================
- bool isEvBoardStopChargeFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->StopChargeFlag;
- }
- bool isEvBoardNormalStopChargeFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->NormalStopChargeFlag;
- }
- //===============================================
- // 掃描插槍狀況
- //===============================================
- void ClearDetectPluginFlag()
- {
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- if (chargingInfo[gun_index]->RemoteStartFlag == YES)
- chargingInfo[gun_index]->RemoteStartFlag = NO;
- }
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- }
- void DetectPluginStart()
- {
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
- }
- bool isDetectPlugin()
- {
- if(ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES)
- return YES;
- return NO;
- }
- //===============================================
- // Common Detect Chk - Chademo
- //===============================================
- bool isEvGunLocked_chademo(byte gunIndex)
- {
- return chargingInfo[gunIndex]->GunLocked;
- }
- bool isEvContactorWelding_chademo(byte gunIndex)
- {
- return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
- }
- bool isEvStopReq_chademo(byte gunIndex)
- {
- return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
- }
- bool isEvStopCharging_chademo(byte gunIndex)
- {
- if (isEvGunLocked_chademo(gunIndex) == NO)
- {
- // 無鎖槍 = 停止
- return YES;
- }
- return NO;
- }
- byte isPrechargeStatus_chademo(byte gunIndex)
- {
- byte result = 0x00;
- result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- return result;
- }
- //===============================================
- // Common Detect Chk - GB
- //===============================================
- bool isEvGunLocked_gb(byte gunIndex)
- {
- return chargingInfo[gunIndex]->GunLocked;
- }
- bool isEvStopCharging_gb(byte gunIndex)
- {
- if (isEvGunLocked_gb(gunIndex) == NO)
- {
- // 無鎖槍 = 停止
- return YES;
- }
- return NO;
- }
- byte isPrechargeStatus_gb(byte gunIndex)
- {
- byte result = 0x00;
- result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- return result;
- }
- //===============================================
- // Common Detect Chk - CCS
- //===============================================
- bool isEvGunLocked_ccs(byte gunIndex)
- {
- return chargingInfo[gunIndex]->GunLocked;
- }
- byte isPrechargeStatus_ccs(byte gunIndex)
- {
- byte result = 0x00;
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
- {
- result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- }
- return result;
- }
- bool isEvStopCharging_ccs(byte gunIndex)
- {
- if (isEvGunLocked_ccs(gunIndex) == NO)
- {
- // 無鎖槍 = 停止
- return YES;
- }
- return NO;
- }
- //===============================================
- // Callback
- //===============================================
- void DisplayChargingInfo()
- {
- PRINTF_FUNC("*********** DisplayChargingInfo *********** \n");
- for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->SystemStatus != S_IDLE &&
- chargingInfo[i]->SystemStatus != S_RESERVATION)
- {
- ChangeGunSelectByIndex(i);
- usleep(50000);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- return;
- }
- }
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
- ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
- }
- usleep(50000);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- void _AutoReturnTimeout()
- {
- PRINTF_FUNC("*********** _AutoReturnTimeout %d*********** \n", ShmSysConfigAndInfo->SysInfo.PageIndex);
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
- {
- ClearDetectPluginFlag();
- }
- else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
- {
- DetectPluginStart();
- }
- usleep(50000);
- stopChargingChkByCard = false;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- void _SelfTestTimeout()
- {
- if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- ChargingAlarmProcess(gun_index);
- }
- }
- ShmPsuData->Work_Step = _NO_WORKING;
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
- PRINTF_FUNC("Self test timeout. \n");
- }
- void _AuthorizedTimeout()
- {
- //if(IsAuthorizingMode())
- {
- PRINTF_FUNC("*********** _AuthorizedTimeout *********** \n");
- isCardScan = false;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
- //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
- }
- }
- void _DetectPlugInTimeout()
- {
- PRINTF_FUNC("*********** _DetectPlugInTimeout *********** \n");
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearDetectPluginFlag();
- usleep(50000);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- void _DetectEvChargingEnableTimeout(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- if(!isEvGunLocked_chademo(gunIndex))
- {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- if(!isEvGunLocked_ccs(gunIndex))
- {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
- {
- if(!isEvGunLocked_ccs(gunIndex))
- {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
- }
- }
- ChargingTerminalProcess(gunIndex);
- _AutoReturnTimeout();
- }
- void _DetectEvseChargingEnableTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
- //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
- {
- setChargerMode(gunIndex, MODE_IDLE);
- _AutoReturnTimeout();
- }
- }
- void _PrepareTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _PrepareTimeout ***********\n");
- setChargerMode(gunIndex, MODE_IDLE);
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
- _AutoReturnTimeout();
- }
- void _CcsPrechargeTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _CcsPrechargeTimeout ***********\n");
- setChargerMode(gunIndex, MODE_IDLE);
- }
- //===============================================
- // 卡號驗證
- //===============================================
- void AuthorizingStart()
- {
- ocpp_set_authorizeReq_cmd(YES);
- ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
- }
- void ClearAuthorizedFlag()
- {
- ocpp_set_authorizeConf_cmd(NO);
- ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
- }
- bool isAuthorizedComplete()
- {
- return ocpp_get_authorize_conf();
- }
- bool IsAuthorizingMode()
- {
- if(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO)
- return false;
- return true;
- }
- //===============================================
- // 紀錄 Alarm Code
- //===============================================
- void RecordAlarmCode(byte gunIndex, char *code)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL)
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6);
- if (strcmp(code, "012234") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES;
- else if (strcmp(code, "012235") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
- else if (strcmp(code, "012236") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES;
- else if (strcmp(code, "012288") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = YES;
- else if (strcmp(code, "012289") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = YES;
- else if (strcmp(code, "012290") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = YES;
- else if (strcmp(code, "012229") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES;
- else if (strcmp(code, "012230") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES;
- else if (strcmp(code, "012231") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES;
- else if (strcmp(code, "012296") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES;
- else if (strcmp(code, "012297") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES;
- else if (strcmp(code, "012298") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES;
- else if (strcmp(code, "011011") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES;
- else if (strcmp(code, "011013") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES;
- else if (strcmp(code, "011015") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES;
- else if (strcmp(code, "011012") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES;
- else if (strcmp(code, "011014") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES;
- else if (strcmp(code, "011016") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES;
- else if (strcmp(code, "011018") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES;
- else if (strcmp(code, "011019") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES;
- else if (strcmp(code, "011020") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
- }
- void ResetChargerAlarmCode(byte gunIndex, char *code)
- {
- if (strcmp(code, "012229") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
- else if (strcmp(code, "012230") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
- else if (strcmp(code, "012231") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
- else if (strcmp(code, "011011") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
- else if (strcmp(code, "011013") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
- else if (strcmp(code, "011015") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
- else if (strcmp(code, "011012") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
- else if (strcmp(code, "011014") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
- else if (strcmp(code, "011016") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
- else if (strcmp(code, "011018") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
- else if (strcmp(code, "011019") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
- else if (strcmp(code, "011020") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012229", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012230", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012231", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011011", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011013", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011015", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011012", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011014", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011016", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011018", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011019", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011020", 6) == EQUAL)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- }
- }
- }
- void ReleaseSysAlarmCode(byte gunIndex)
- {
- // 回 idle 後主要清除 GFD Trip、UVP、OVP、GFD Warning
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- }
- }
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012217", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012296", 6) == EQUAL)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- }
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
- {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012219", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012297", 6) == EQUAL)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- }
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012221", 6) == EQUAL ||
- strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012298", 6) == EQUAL)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- }
- }
- }
- ocpp_clear_errorCode_cmd(gunIndex);
- }
- void NormalStop(byte gunIndex)
- {
- PRINTF_FUNC("NormalStop (%d) \n", gunIndex);
- }
- //===============================================
- // EmergencyStop and Charging Stop
- //===============================================
- void ChargingTerminalProcess(byte gunIndex)
- {
- setChargerMode(gunIndex, MODE_TERMINATING);
- }
- void ChargingAlarmProcess(byte gunIndex)
- {
- CheckSystemErrorFunction(gunIndex);
- ocpp_set_errCode_cmd(gunIndex);
- setChargerMode(gunIndex, MODE_ALARM);
- }
- void AcChargingTerminalProcess()
- {
- ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
- }
- //void StopChargingProcessByString(byte level)
- //{
- // if (level > ShmSysConfigAndInfo->SysWarningInfo.Level)
- // {
- // ShmSysConfigAndInfo->SysWarningInfo.Level = level;
- // }
- //}
- //void ReleaseChargingProcessByString(byte level)
- //{
- // if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level)
- // ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
- //}
- // 一般錯誤停止充電處理函式
- void BoardErrOccurByString(byte index, char *code)
- {
- //byte level = 1;
- if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
- (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (strncmp(code, "023730", 6) == EQUAL &&
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
- }
- ChargingAlarmProcess(index);
- }
- //60StopChargingProcessByString(level);
- }
- // 急停狀況的停止充電處理函式
- void EmcOccureThenStopCharging()
- {
- //byte level = 2;
- // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen...
- // 其錯誤等級為 2
- for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++)
- {
- if ((chargingInfo[gun]->SystemStatus > S_IDLE && chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
- (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- ChargingAlarmProcess(gun);
- }
- }
- //StopChargingProcessByString(level);
- }
- void ReleaseBoardErrOccurByString(byte index, char *code)
- {
- if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
- }
- }
- void ReleaseEmsOccureByString(byte index, char *code)
- {
- if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
- }
- else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
- }
- else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- }
- else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- }
- //===============================================
- // 確認硬體 (按鈕) 狀態
- //===============================================
- bool leftBtnPush = false;
- bool rightBtnPush = false;
- void ChkPrimaryStatus()
- {
- if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
- EmcOccureThenStopCharging();
- }
- else
- ReleaseEmsOccureByString(0, "012251");
- if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
- EmcOccureThenStopCharging();
- }
- else
- ReleaseEmsOccureByString(0, "012238");
- if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
- EmcOccureThenStopCharging();
- }
- else
- ReleaseEmsOccureByString(0, "012252");
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- {
- EmcOccureThenStopCharging();
- }
- else
- ReleaseEmsOccureByString(0, "012267");
- if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
- ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS)
- ShmSysConfigAndInfo->SysConfig.ShowInformation = YES;
- else
- ShmSysConfigAndInfo->SysConfig.ShowInformation = NO;
- if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush)
- {
- if(!leftBtnPush)
- {
- leftBtnPush = true;
- PRINTF_FUNC("left btn down............................... \n");
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
- {
- switch(ac_chargingInfo[0]->SystemStatus)
- {
- case S_IDLE:
- {
- if(isDetectPlugin())
- {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- }
- }
- break;
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1:
- {
- // 取消充電
- AcChargingTerminalProcess();
- }
- break;
- case S_CHARGING:
- {
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- // 停止充電
- AcChargingTerminalProcess();
- }
- }
- break;
- case S_COMPLETE:
- {}
- break;
- }
- }
- switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- case S_IDLE:
- {
- if(isDetectPlugin())
- {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- }
- }
- break;
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1:
- {
- // 按鈕 - 取消充電
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
- AcChargingTerminalProcess();
- else
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- break;
- case S_CHARGING:
- {
- if (ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES ||
- (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->isRemoteStart == NO))
- {
- // 按鈕 - 停止充電
- NormalStop(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- }
- break;
- case S_COMPLETE:
- {
- // 回 IDLE
- //PRINTF_FUNC("right btn down.................S_COMPLETE \n");
- //chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_IDLE;
- }
- break;
- }
- }
- }
- else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE)
- {
- if(leftBtnPush)
- {
- leftBtnPush = false;
- PRINTF_FUNC("left btn up............................... \n");
- }
- }
- if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush)
- {
- if(!rightBtnPush)
- {
- rightBtnPush = true;
- PRINTF_FUNC("right btn down............................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected++;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
- else if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
- {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus != S_BOOTING &&
- chargingInfo[_index]->SystemStatus != S_IDLE &&
- chargingInfo[_index]->SystemStatus != S_RESERVATION)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- return;
- }
- }
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- }
- }
- else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE)
- {
- if(rightBtnPush)
- {
- rightBtnPush = false;
- PRINTF_FUNC("right btn up............................... \n");
- }
- }
- }
- //===============================================
- // 確認各小板偵測的錯誤狀況
- //===============================================
- void CheckSystemErrorFunction(byte index)
- {
- // System
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip)
- RecordAlarmCode(index, "012251");
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip)
- RecordAlarmCode(index, "012238");
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen)
- RecordAlarmCode(index, "012252");
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- RecordAlarmCode(index, "012267");
- if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
- }
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES)
- RecordAlarmCode(index, "012203");
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES)
- RecordAlarmCode(index, "012204");
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
- RecordAlarmCode(index, "012205");
- chargingInfo[index]->StopChargeFlag = YES;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- }
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- }
- }
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
- }
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES)
- RecordAlarmCode(index, "012200");
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES)
- RecordAlarmCode(index, "012201");
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
- RecordAlarmCode(index, "012202");
- chargingInfo[index]->StopChargeFlag = YES;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- }
- }
- }
- //===============================================
- // 確認 GPIO 狀態
- //===============================================
- void gpio_set_value(unsigned int gpio, unsigned int value)
- {
- int fd;
- char buf[MAX_BUF];
- snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
- fd = open(buf, O_WRONLY);
- if (fd < 0)
- {
- perror("gpio/set-value");
- return;
- }
- if (value)
- write(fd, "1", 2);
- else
- write(fd, "0", 2);
- close(fd);
- }
- int gpio_get_value(unsigned int gpio, unsigned int *value)
- {
- int fd;
- char buf[MAX_BUF];
- char ch;
- snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
- fd = open(buf, O_RDONLY);
- if (fd < 0) {
- perror("gpio/get-value");
- return fd;
- }
- read(fd, &ch, 1);
- if (ch != '0') {
- *value = 1;
- } else {
- *value = 0;
- }
- close(fd);
- return 0;
- }
- void CheckGunTypeFromHw()
- {
- int pinIn[4] = { 22, 23, 44, 45 };
- unsigned int gpioValue = 0;
- for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
- gpio_get_value(pinIn[i], &gpioValue);
- {
- switch (pinIn[i])
- {
- case 22:
- bd1_1_status = gpioValue;
- break;
- case 23:
- bd1_2_status = gpioValue;
- break;
- case 44:
- bd0_1_status = gpioValue;
- break;
- case 45:
- bd0_2_status = gpioValue;
- break;
- }
- }
- }
- }
- void CheckGpioInStatus()
- {
- int pinIn[2] = { 27, 47 };
- unsigned int gpioValue = 0;
- for (int i = 0; i < ARRAY_SIZE(pinIn); i++)
- {
- gpio_get_value(pinIn[i], &gpioValue);
- if (gpioValue == 0x01)
- {
- switch(pinIn[i])
- {
- // 小板緊急停止
- case 47:
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->slotsIndex == 1)
- {
- if (chargingInfo[i]->Type == _Type_Chademo)
- BoardErrOccurByString(i, "023730");
- else if (chargingInfo[i]->Type == _Type_CCS_2)
- BoardErrOccurByString(i, "013627");
- break;
- }
- }
- }
- break;
- case 27:
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->slotsIndex == 3)
- {
- if (chargingInfo[i]->Type == _Type_Chademo)
- BoardErrOccurByString(i, "023730");
- else if (chargingInfo[i]->Type == _Type_CCS_2)
- BoardErrOccurByString(i, "013627");
- break;
- }
- }
- }
- break;
- }
- }
- else
- {
- switch (pinIn[i])
- {
- // 小板解除緊急停止
- case 47:
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->slotsIndex == 1)
- {
- if (chargingInfo[i]->Type == _Type_Chademo)
- ReleaseBoardErrOccurByString(i, "023730");
- else if (chargingInfo[i]->Type == _Type_CCS_2)
- ReleaseBoardErrOccurByString(i, "013627");
- break;
- }
- }
- }
- break;
- case 27:
- {
- for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->slotsIndex == 3)
- {
- if (chargingInfo[i]->Type == _Type_Chademo)
- ReleaseBoardErrOccurByString(i, "023730");
- else if (chargingInfo[i]->Type == _Type_CCS_2)
- ReleaseBoardErrOccurByString(i, "013627");
- break;
- }
- }
- }
- break;
- }
- }
- }
- }
- //===============================================
- // Main process
- //===============================================
- // 檢查 Byte 中某個 Bit 的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
- {
- return ( _byte & mask_table[_bit] ) != 0x00;
- }
- // 設定 Byte 中某個 Bit的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- // value : 修改的值為 0 or 1
- void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
- {
- if(value == 1)
- *_byte |= (1 << _bit);
- else if (value == 0)
- *_byte ^= (1 << _bit);
- }
- void UserScanFunction()
- {
- bool idleReq = false;
- unsigned char idleIndex = 255;
- unsigned char stopReq = 255;
- // 當前非驗證的狀態
- if(!IsAuthorizingMode())
- {
- // 先判斷現在是否可以提供刷卡
- // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
- // 2. 停止充電
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX ||
- ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_EMC)
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- return;
- }
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0)
- {
- if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
- {
- // 如果選 AC 槍
- if (ac_chargingInfo[0]->SystemStatus >= S_REASSIGN_CHECK &&
- ac_chargingInfo[0]->SystemStatus <= S_ALARM)
- {
- if (ac_chargingInfo[0]->SystemStatus == S_CHARGING)
- {
- char value[32];
- PRINTF_FUNC("ac stop charging \n");
- PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
- ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
- memcpy(value, (unsigned char *)ac_chargingInfo[0]->StartUserId, ARRAY_SIZE(ac_chargingInfo[0]->StartUserId));
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
- {
- AcChargingTerminalProcess();
- }
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- else if (ac_chargingInfo[0]->SystemStatus == S_IDLE)
- {
- idleReq = true;
- }
- }
- }
- else
- {
- if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_REASSIGN_CHECK &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_ALARM)
- {
- if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING)
- {
- char value[32];
- PRINTF_FUNC("stop charging \n");
- PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected,
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
- memcpy(value, (unsigned char *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
- ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
- // 同一張卡直接停掉
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
- {
- NormalStop(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- else
- {
- PRINTF_FUNC("_LCM_AUTHORIZ_FAIL \n");
- stopChargingChkByCard = true;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
- }
- }
- }
- else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE)
- {
- idleIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
- idleReq = true;
- }
- else
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != gun_index &&
- chargingInfo[gun_index]->SystemStatus == S_IDLE)
- {
- idleIndex = gun_index;
- idleReq = true;
- break;
- }
- }
- }
- }
- if (idleReq)
- {
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
- stopReq != 255 &&
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
- {
- idleReq = false;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- else if ((_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
- (idleIndex != 255 && chargingInfo[idleIndex]->SystemStatus == S_IDLE))
- {
- PRINTF_FUNC("Start Authorizing... \n");
- // LCM => Authorizing
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
- // 進入確認卡號狀態
- AuthorizingStart();
- }
- else
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- else
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- }
- }
- else
- {
- // 透過後臺停止充電的判斷
- if (isAuthorizedComplete() ||
- (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
- {
- // 判斷後台回覆狀態
- if(ocpp_chk_authrization_cmd() ||
- (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
- {
- if (_authorizeIndex != NO_DEFINE)
- {
- // 先找 AC
- if (_authorizeIndex == DEFAULT_AC_INDEX)
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
- strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL)
- {
- AcChargingTerminalProcess();
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
- strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL)
- {
- // 刷卡停止
- ChargingTerminalProcess(_authorizeIndex);
- }
- }
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- _authorizeIndex = NO_DEFINE;
- }
- }
- else
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
- }
- else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
- {
- // 白名單驗證
- for (int i = 0; i < 10; i++)
- {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
- {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
- {
- // 白名單驗證停止
- ChargingTerminalProcess(_authorizeIndex);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
- break;
- }
- }
- }
- }
- }
- }
- unsigned char isModeChange(unsigned char gun_index)
- {
- unsigned char result = NO;
- if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
- {
- result = YES;
- chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
- }
- return result;
- }
- void ScannerCardProcess()
- {
- if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level != 2 &&
- ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- isCardScan = true;
- // 處理刷卡及驗證卡號的動作
- UserScanFunction();
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING)
- {
- StartSystemTimeoutDet(Timeout_Authorizing);
- // 確認驗證卡號完成沒
- if (isAuthorizedComplete() || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
- {
- StopSystemTimeoutDet();
- // 判斷後台回覆狀態
- if(ocpp_chk_authrization_cmd() || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
- {
- // LCM => Authorize complete
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- }
- else
- {
- // LCM => Authorize fail
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- ClearAuthorizedFlag();
- }
- else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
- {
- // 白名單驗證
- for (int i = 0; i < 10; i++)
- {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
- {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- ClearAuthorizedFlag();
- break;
- }
- }
- }
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL)
- {
- StartSystemTimeoutDet(Timeout_VerifyFail);
- isCardScan = false;
- }
- else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
- {
- StartSystemTimeoutDet(Timeout_VerifyComp);
- }
- else if(ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE &&
- ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
- {
- StartSystemTimeoutDet(Timeout_WaitPlug);
- }
- else
- isCardScan = false;
- }
- bool AddGunInfoByConnector(byte typeValue, byte slots)
- {
- bool result = true;
- switch (typeValue)
- {
- case '0': // none
- break;
- case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
- break;
- case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
- break;
- case '3': // IEC 62196-2 Type 2 Plug
- case '4': // IEC 62196-2 Type 2 Socket
- if (AC_QUANTITY > _ac_Index)
- {
- ac_chargingInfo[_acgunIndex] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[_ac_Index];
- // AC 固定 index
- ac_chargingInfo[_acgunIndex]->Index = 0;
- ac_chargingInfo[_acgunIndex]->ReservationId = -1;
- ac_chargingInfo[_acgunIndex]->SystemStatus = S_IDLE;
- ac_chargingInfo[_acgunIndex]->Type = _Type_AC;
- ac_chargingInfo[_acgunIndex]->IsAvailable = YES;
- ac_chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
- ac_chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
- _ac_Index++;
- _acgunIndex++;
- }
- else
- result = false;
- break;
- case '5': // GB/T AC Plug
- break;
- case '6': // GB/T AC Socket
- break;
- case 'J': // CHAdeMO
- case 'K': // CHAdeMO - 200A / 500V
- {
- if (CHAdeMO_QUANTITY > _chademoIndex)
- {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = -1;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_Chademo;
- chargingInfo[_gunIndex]->type_index = _chademoIndex;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
- chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
- _chademoIndex++;
- _gunIndex++;
- }
- else
- result = false;
- }
- break;
- case 'U': // Natural cooling CCS1
- case 'E': // Natural cooling CCS2
- case 'T': // Rema CCS1 - 300A
- case 'D': // Rema CCS2 - 300A
- case 'M': // CCS2 - 80A
- case 'N': // CCS1 - 80A
- {
- if (CCS_QUANTITY > _ccsIndex)
- {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = -1;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_CCS_2;
- chargingInfo[_gunIndex]->type_index = _ccsIndex;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
- chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
- // 現階段預設為走 DIN70121
- ShmCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
- _ccsIndex++;
- _gunIndex++;
- }
- else
- result = false;
- }
- break;
- case 'G': // GBT DC
- {
- if (GB_QUANTITY > _gb_Index)
- {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[_gb_Index];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = -1;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_GB;
- chargingInfo[_gunIndex]->type_index = _gb_Index;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
- chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
- _gb_Index++;
- _gunIndex++;
- }
- else
- result = false;
- }
- break;
- }
- return result;
- }
- bool CheckConnectorTypeStatus()
- {
- bool result = true;
- // 硬體 0 1 => CCS,1 0 => Chademo,1 1 => GB
- //CheckFwSlotSta.tusLog();
- if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9)
- {
- byte slots = 1;
- for (byte typeIndex = 7; typeIndex <= 9; typeIndex++)
- {
- if(!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots))
- {
- return false;
- }
- slots++;
- }
- // AC index 接在 DC 後面
- if (_ac_Index > 0)
- ac_chargingInfo[0]->Index += _gunIndex;
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount = _acgunIndex;
- PRINTF_FUNC("Charger Count => DC-Count = %d, AC-Count = %d \n",
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount);
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0 &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0)
- result = false;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- {
- bool isFind = false;
- if (chargingInfo[0]->Type == _Type_Chademo)
- {
- if ((bd0_1_status == 0 && bd0_2_status == 1) ||
- (bd1_1_status == 0 && bd1_2_status == 1))
- {
- isFind = true;
- }
- }
- else if (chargingInfo[0]->Type == _Type_CCS_2)
- {
- if ((bd0_1_status == 1 && bd0_2_status == 0) ||
- (bd1_1_status == 1 && bd1_2_status == 0))
- {
- isFind = true;
- }
- }
- else if (chargingInfo[0]->Type == _Type_GB)
- {
- if ((bd0_1_status == 1 && bd0_2_status == 1) ||
- (bd1_1_status == 1 && bd1_2_status == 1))
- {
- isFind = true;
- }
- }
- if (isFind)
- {
- chargingInfo[0]->Evboard_id = 0x01;
- CheckHwSlotStatusLog(0);
- }
- else
- result = false;
- }
- else
- {
- char type = NO_DEFINE;
- // 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
- for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
- {
- if (gunIndex == 0 && bd0_1_status == 0 && bd0_2_status == 1)
- {
- PRINTF_FUNC("HW Conn %d (Chademo) \n", gunIndex);
- // 與硬體相同 type : Chademo
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 0)
- {
- PRINTF_FUNC("HW Conn %d (CCS) \n", gunIndex);
- // 與硬體相同 type : CCS
- if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 1)
- {
- PRINTF_FUNC("HW Conn %d (GB) \n", gunIndex);
- // 與硬體相同 type : GB
- if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- else if (gunIndex == 0)
- {
- PRINTF_FUNC("HW Conn fail, Gun_%d, Flag1 = %d, Flag2 = %d \n",
- gunIndex, bd0_1_status, bd0_2_status);
- }
- if (gunIndex == 1 && bd1_1_status == 0 && bd1_2_status == 1)
- {
- PRINTF_FUNC("HW Conn %d (Chademo) \n", gunIndex);
- // 與硬體相同 type : Chademo
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x02;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 0)
- {
- PRINTF_FUNC("HW Conn %d (CCS) \n", gunIndex);
- // 與硬體相同 type : CCS
- if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x02;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 1)
- {
- PRINTF_FUNC("HW Conn %d (GB) \n", gunIndex);
- // 與硬體相同 type : GB
- if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x02;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- else if (gunIndex == 1)
- {
- PRINTF_FUNC("HW Conn fail, Gun_%d, Flag1 = %d, Flag2 = %d \n",
- gunIndex, bd1_1_status, bd1_2_status);
- }
- CheckHwSlotStatusLog(gunIndex);
- if (type == NO_DEFINE)
- type = chargingInfo[gunIndex]->Type;
- else
- {
- // 雙槍都是同一個 type
- if (type == chargingInfo[gunIndex]->Type)
- ShmDcCommonData->SysGunAreSameType = YES;
- }
- if (chargingInfo[gunIndex]->Evboard_id == 0x00)
- result = false;
- }
- }
- }
- else
- {
- // Module Name 不正確 - 告警
- result = false;
- }
- return result;
- }
- void KillTask()
- {
- ChangeLcmByIndex(_LCM_FIX);
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_InternalComm");
- system("killall Module_PsuComm");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- }
- void KillTaskExceptDetectTask()
- {
- ChangeLcmByIndex(_LCM_FIX);
- system("killall Module_EvComm");
- //system("killall Module_InternalComm");
- system("killall Module_PsuComm");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- }
- void KillAllTask()
- {
- ChangeLcmByIndex(_LCM_FIX);
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_LcmControl");
- system("killall Module_InternalComm");
- system("killall Module_PsuComm");
- system("killall OcppBackend &");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- }
- int CheckUpdateProcess(void)
- {
- //bool isPass = true;
- uint8_t retSucc = 0;
- uint8_t retFail = 0;
- byte index = 0;
- byte target = 0;
- char new_str[256];
- unsigned char *ptr = NULL;
- int fd = 0;
- int CanFd = 0;
- int uartFd = 0;
- unsigned int Type = 0;
- long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
- DIR *d;
- struct dirent *dir;
- byte result = PASS;
- char Buf[256];
- d = opendir("/mnt/");
- if (d)
- {
- while ((dir = readdir(d)) != NULL)
- {
- if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0)
- {
- continue;
- }
- memset(new_str, 0x00, sizeof(new_str));
- strcat(new_str, "/mnt/");
- strcat(new_str, dir->d_name);
- PRINTF_FUNC("%s \n", new_str);
- fd = open(new_str, O_RDONLY);
- if (fd < 0)
- {
- close(fd);
- result = FAIL;
- sleep(1);
- continue;
- }
- ptr = malloc(MaxLen); //-48 is take out the header
- //memset(ptr, 0xFF, MaxLen); //-48 is take out the header
- //get the image length
- ImageLen = read(fd, ptr, MaxLen);
- bool isModelNameFail = false;
- // DS-----J0E-2PH
- if((ShmSysConfigAndInfo->SysConfig.ModelName[0] != ptr[0]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[1] != ptr[1]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[7] != ptr[7]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[8] != ptr[8]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[9] != ptr[9]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[11] != ptr[11]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[12] != ptr[12]) ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[13] != ptr[13]))
- {
- result = MODELNAME_FAIL;
- isModelNameFail = true;
- }
- if (isModelNameFail)
- {
- close(fd);
- continue;
- }
- PRINTF_FUNC("model name check pass. \n");
- if (ImageLen > 20) {
- Type = (((unsigned int)ptr[16]) << 24 |
- ((unsigned int)ptr[17]) << 16 |
- ((unsigned int)ptr[18]) << 8 |
- ((unsigned int)ptr[19]));
- PRINTF_FUNC("Typed...%x \r\n", Type);
- PRINTF_FUNC("Upgrade Status : PASS : %d, FAIL : %d \n", retSucc, retFail);
- switch (Type)
- {
- case 0x10000001:
- case 0x10000002:
- case 0x10000003:
- case 0x10000004:
- case 0x10000005:
- system("echo 3 > /proc/sys/vm/drop_caches");
- sleep(2);
- if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
- retSucc++;
- else
- {
- PRINTF_FUNC("Upgrade CSU Failed (%d) \n", Type);
- retFail++;
- }
- memset(Buf, 0, sizeof(Buf));
- sprintf(Buf, "rm -rvf /mnt/%s", new_str);
- system(Buf);
- break;
- case 0x10000007:
- case 0x10000008:
- case 0x10000009:
- case 0x1000000A:
- CanFd = InitCanBus();
- if (CanFd > 0)
- {
- for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (chargingInfo[index]->Type == _Type_CCS_2)
- {
- byte targetID = chargingInfo[index]->Evboard_id;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1 &&
- ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
- {
- targetID += 1;
- }
- system("echo 3 > /proc/sys/vm/drop_caches");
- sleep(2);
- PRINTF_FUNC("Upgrade CCS Processing..target id = %d \n", targetID);
- if (Upgrade_CCS(CanFd, Type, targetID, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL)
- {
- PRINTF_FUNC("Upgrade CCS Failed \n");
- retFail++;
- }
- else
- retSucc++;
- }
- }
- close(CanFd);
- }
- memset(Buf, 0, sizeof(Buf));
- sprintf(Buf, "rm -rvf /mnt/%s", new_str);
- system(Buf);
- break;
- case 0x10000006:
- case 0x1000000D:
- case 0x1000000E:
- case 0x20000002:
- case 0x10000014:
- // CSU_PRIMARY_CONTROLLER : 0x10000006
- target = 0x00;
- if (Type == 0x10000006) {
- target = UPGRADE_PRI;
- } else if (Type == 0x1000000D) {
- target = UPGRADE_RB;
- } else if (Type == 0x1000000E) {
- target = UPGRADE_FAN;
- } else if (Type == 0x20000002) {
- target = UPGRADE_AC;
- } else if (Type == 0x10000014) {
- target = UPGRADE_LED;
- }
- uartFd = InitComPort(target);
- if (Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
- {
- retSucc++;
- }
- else
- {
- PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
- retFail++;
- }
- if (uartFd > 0)
- {
- close(uartFd);
- }
- memset(Buf, 0, sizeof(Buf));
- sprintf(Buf, "rm -rvf /mnt/%s", new_str);
- system(Buf);
- break;
- case 0x1000000B:
- case 0x1000000C:
- // CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
- CanFd = InitCanBus();
- if (CanFd > 0)
- {
- for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if ((Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo) ||
- (Type == 0x1000000C && chargingInfo[index]->Type == _Type_GB))
- {
- if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
- retSucc++;
- else
- {
- if (chargingInfo[index]->Type == _Type_Chademo)
- PRINTF_FUNC("Upgrade Chademo Failed \n");
- else
- PRINTF_FUNC("Upgrade GBT Failed \n");
- retFail++;
- }
- }
- }
- close(CanFd);
- }
- memset(Buf, 0, sizeof(Buf));
- sprintf(Buf, "rm -rvf /mnt/%s", new_str);
- system(Buf);
- break;
- }
- }
- free(ptr);
- close(fd);
- }
- }
- free(dir);
- closedir(d);
- PRINTF_FUNC("Upgrade Result : PASS : %d, FAIL : %d \n", retSucc, retFail);
- sleep(1);
- system("rm -rvf /mnt/* ");
- if (retFail != 0)
- {
- result = FAIL;
- }
- return result;
- }
- void CreateRfidFork()
- {
- pid_t rfidRecPid;
- rfidRecPid = fork();
- if (rfidRecPid == 0)
- {
- while(true)
- {
- // 刷卡判斷
- RFID rfid;
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
- !ShmSysConfigAndInfo->SysConfig.isRFID)
- {}
- else if(getRequestCardSN(rfidFd, 0, &rfid))
- {
- //PRINTF_FUNC("Get Card..-%s- \n", ShmSysConfigAndInfo->SysConfig.UserId);
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0)
- {
- if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG)
- {
- switch (rfid.snType)
- {
- case RFID_SN_TYPE_6BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3],
- rfid.currentCard[4], rfid.currentCard[5]);
- break;
- case RFID_SN_TYPE_7BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3],
- rfid.currentCard[4], rfid.currentCard[5],
- rfid.currentCard[6]);
- break;
- case RFID_SN_TYPE_10BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3],
- rfid.currentCard[4], rfid.currentCard[5],
- rfid.currentCard[6], rfid.currentCard[7],
- rfid.currentCard[8], rfid.currentCard[9]);
- break;
- case RFID_SN_TYPE_4BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3]);
- break;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE)
- {
- switch (rfid.snType)
- {
- case RFID_SN_TYPE_6BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[5], rfid.currentCard[4],
- rfid.currentCard[3], rfid.currentCard[2],
- rfid.currentCard[1], rfid.currentCard[0]);
- break;
- case RFID_SN_TYPE_7BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[6], rfid.currentCard[5],
- rfid.currentCard[4], rfid.currentCard[3],
- rfid.currentCard[2], rfid.currentCard[1],
- rfid.currentCard[0]);
- break;
- case RFID_SN_TYPE_10BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[9], rfid.currentCard[8],
- rfid.currentCard[7], rfid.currentCard[6],
- rfid.currentCard[5], rfid.currentCard[4],
- rfid.currentCard[3], rfid.currentCard[2],
- rfid.currentCard[1], rfid.currentCard[0]);
- break;
- case RFID_SN_TYPE_4BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X",
- rfid.currentCard[3], rfid.currentCard[2],
- rfid.currentCard[1], rfid.currentCard[0]);
- break;
- }
- }
- PRINTF_FUNC("RFID : Get card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
- }
- }
- sleep(1);
- }
- }
- }
- void StartSystemTimeoutDet(unsigned char flag)
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag)
- {
- gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
- }
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
- }
- void StopSystemTimeoutDet()
- {
- gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
- }
- void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
- {
- if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
- {
- if (chargingInfo[gunIndex]->TimeoutFlag != flag)
- {
- gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
- }
- chargingInfo[gunIndex]->TimeoutFlag = flag;
- }
- }
- void StopGunInfoTimeoutDet(unsigned char gunIndex)
- {
- if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
- {
- chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
- }
- }
- void CheckConnectionTimeout()
- {
- if(system("pidof -s OcppBackend > /dev/null") != 0)
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- else
- {
- _connectionTimeout = _ocpp_get_connect_timeout();
- if(_connectionTimeout <= 0)
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- }
- void CheckDisconnectPolicy()
- {
- if(system("pidof -s OcppBackend > /dev/null") != 0)
- {
- _isAllowChargingOnDisconnect = false;
- }
- else
- {
- _isAllowChargingOnDisconnect = _ocpp_get_disconnect_policy();
- }
- }
- void CreateTimeoutFork()
- {
- pid_t timeoutPid;
- timeoutPid = fork();
- if (timeoutPid > 0)
- {
- gettimeofday(&_cmdSubPriority_time, NULL);
- CheckConnectionTimeout();
- unsigned long _timebuf = 0;
- while(true)
- {
- _timebuf = GetTimeoutValue(_cmdSubPriority_time);
- if (_timebuf < 0)
- {
- gettimeofday(&_cmdSubPriority_time, NULL);
- }
- else
- {
- if ((_timebuf / 1000) > 5000)
- {
- CheckConnectionTimeout();
- gettimeofday(&_cmdSubPriority_time, NULL);
- }
- }
- //printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
- // 系統
- _timebuf = GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer);
- if (_timebuf < 0)
- {
- gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
- }
- else
- {
- switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
- {
- case Timeout_SelftestChk:
- if (_timebuf / uSEC_VAL >= SELFTEST_TIMEOUT)
- {
- _SelfTestTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_Authorizing:
- if (_timebuf / uSEC_VAL >= AUTHORIZE_TIMEOUT)
- {
- _AuthorizedTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_VerifyFail:
- if (_timebuf / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT)
- {
- _AutoReturnTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_VerifyComp:
- if (_timebuf / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT)
- {
- _AutoReturnTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_WaitPlug:
- if (_timebuf / uSEC_VAL >= _connectionTimeout)
- {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_ReturnToChargingGunDet:
- {
- if (_timebuf / uSEC_VAL >= RETURN_TO_CHARGING_PAGE)
- {
- DisplayChargingInfo();
- StopSystemTimeoutDet();
- }
- }
- break;
- // case Timeout_AuthorizingForStop:
- // {
- // if (_timebuf / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT)
- // {
- // strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- // ClearAuthorizedFlag();
- // StopSystemTimeoutDet();
- // }
- // }
- // break;
- }
- }
- // 各槍
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- _timebuf = GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer);
- //printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
- switch(chargingInfo[gun_index]->TimeoutFlag)
- {
- case Timeout_Preparing:
- {
- if (_timebuf / uSEC_VAL >= GUN_PREPARE_TIMEOUT)
- {
- _PrepareTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_EvChargingDet:
- {
- if (_timebuf / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT)
- {
- _DetectEvChargingEnableTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_EvseChargingDet:
- {
- if (_timebuf / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT)
- {
- _DetectEvseChargingEnableTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_EvseCompleteDet:
- {
- if (_timebuf / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT)
- {
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_ForCcsPrechargeDet:
- {
- if (_timebuf / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT)
- {
- _CcsPrechargeTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- }
- }
- sleep(1);
- }
- }
- }
- void GetSystemTime()
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
- tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- tmCSU->tm_sec);
- // byte date[14];
- //
- //
- // //sprintf(&date, "%d", );
- //
- // date[0] = '0' + ((tmCSU->tm_year + 1900) / 1000 % 10);
- // date[0] = (tmCSU->tm_year + 1900) / 1000 % 10;
- // date[1] = (tmCSU->tm_year + 1900) / 100 % 10;
- // date[2] = (tmCSU->tm_year + 1900) / 10 % 10;
- // date[3] = (tmCSU->tm_year + 1900) / 1 % 10;
- //
- // date[4] = (tmCSU->tm_mon + 1) / 10 % 10;
- // date[5] = (tmCSU->tm_mon + 1) / 1 % 10;
- //
- // date[6] = (tmCSU->tm_mday) / 10 % 10;
- // date[7] = (tmCSU->tm_mday) / 1 % 10;
- //
- // date[8] = (tmCSU->tm_hour) / 10 % 10;
- // date[9] = (tmCSU->tm_hour) / 1 % 10;
- //
- // date[10] = (tmCSU->tm_min) / 10 % 10;
- // date[11] = (tmCSU->tm_min) / 1 % 10;
- //
- // date[12] = (tmCSU->tm_sec) / 10 % 10;
- // date[13] = (tmCSU->tm_sec) / 1 % 10;
- // 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],
- // date[4], date[5], date[6], date[7],
- // date[8], date[9], date[10], date[11],
- // date[12], date[13]);
- }
- void CheckFactoryConfigFunction()
- {
- if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
- {
- char Buf[256];
- sprintf(Buf, "cd /root;./FactoryConfig -m %s %s",
- ShmSysConfigAndInfo->SysConfig.ModelName,
- ShmSysConfigAndInfo->SysConfig.SerialNumber);
- system(Buf);
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- }
- void CheckFwUpdateFunction()
- {
- //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
- if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
- {
- DEBUG_INFO_MSG("ftp : update start. \n");
- KillTask();
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_UPDATE);
- }
- byte updateResult = CheckUpdateProcess();
- if (updateResult == PASS)
- DEBUG_INFO_MSG("ftp : update complete. \n");
- else if (updateResult == MODELNAME_FAIL)
- {
- DEBUG_INFO_MSG("ftp : model name is none match. \n");
- KillAllTask();
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
- sleep(5);
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- else
- DEBUG_INFO_MSG("ftp : update fail. \n");
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
- sleep(5);
- system("reboot -f");
- }
- else
- {
- ocpp_chk_update_cmd();
- }
- }
- //===============================================
- // Check reservation date is expired
- //===============================================
- int opcc_chk_reserve_expired(byte gun_index)
- {
- int result = NO;
- struct tm expiredDate;
- struct timeb expiredTime;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (sscanf((char*) ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,
- "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
- &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
- &expiredDate.tm_min, &expiredDate.tm_sec) == 6)
- {
- expiredDate.tm_year -= 1900;
- expiredDate.tm_mon -= 1;
- expiredTime.time = mktime(&expiredDate);
- if (!CheckTimeOut(expiredTime))
- {
- result = YES;
- }
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (sscanf((char*) ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,
- "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
- &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
- &expiredDate.tm_min, &expiredDate.tm_sec) == 6)
- {
- expiredDate.tm_year -= 1900;
- expiredDate.tm_mon -= 1;
- expiredTime.time = mktime(&expiredDate);
- if (!CheckTimeOut(expiredTime))
- {
- result = YES;
- }
- }
- }
- return result;
- }
- //===============================================
- // OCPP routine
- //===============================================
- void ocpp_process_start()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- system("/root/OcppBackend &");
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- system("/root/OcppBackend20 &");
- }
- void ocpp_auto_response_BootNotification()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES)
- ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->SpMsg.bits.BootNotificationConf == YES)
- ShmOCPP20Data->SpMsg.bits.BootNotificationConf = NO;
- }
- }
- bool ocpp_is_resPass_StartTransationConf(byte gun_index)
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- result = ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- result = ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf;
- }
- return result;
- }
- void ocpp_auto_response_StartTransationConf(byte gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf)
- ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf)
- ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = NO;
- }
- }
- void ocpp_auto_response_ReserveConf(byte gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
- }
- bool ocpp_chk_authrization_cmd()
- {
- char buf2[16] = "";
- memset(buf2, 0, ARRAY_SIZE(buf2));
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- sprintf(buf2, "%s", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
- // 因為無法得知實際的長度,所以只能用搜尋的方式
- if(strcmp(buf2, "Accepted") == EQUAL)
- return true;
- return false;
- }
- bool opcc_sub_get_reset_req()
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- result = ShmOCPP16Data->MsMsg.bits.ResetReq;
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- result = ShmOCPP20Data->MsMsg.bits.ResetReq;
- return result;
- }
- void ocpp_sub_run_reset(bool canReset)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL)
- {
- DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
- sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
- ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
- ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- system("reboot -f");
- }
- else if (canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL)
- {
- DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
- sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
- ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
- ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "Immediate") == EQUAL)
- {
- DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
- sprintf((char*)ShmOCPP20Data->Reset.Response_status, "Accepted");
- ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
- ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- system("reboot -f");
- }
- else if (canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "OnIdle") == EQUAL)
- {
- DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
- sprintf((char*)ShmOCPP20Data->Reset.Response_status, "Accepted");
- ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
- ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- void ocpp_chk_reset_cmd()
- {
- if (opcc_sub_get_reset_req())
- {
- bool canReset = true;
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
- {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus != S_IDLE &&
- chargingInfo[_index]->SystemStatus != S_RESERVATION &&
- chargingInfo[_index]->SystemStatus != S_MAINTAIN)
- {
- canReset = false;
- if (chargingInfo[_index]->SystemStatus >= S_REASSIGN &&
- chargingInfo[_index]->SystemStatus < S_TERMINATING)
- {
- // Reset 系統先停止充電
- ChargingTerminalProcess(_index);
- }
- }
- }
- }
- if (canReset)
- {
- // Reset -> change status to maintain.
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- setChargerMode(_index, MODE_MAINTAIN);
- }
- ChangeLcmByIndex(_LCM_FIX);
- }
- ocpp_sub_run_reset(canReset);
- }
- }
- void ocpp_chk_reserved_cmd(byte gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES)
- {
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
- if (opcc_chk_reserve_expired(gunIndex))
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
- chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
- }
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
- }
- if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES)
- {
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
- if (opcc_chk_reserve_expired(gunIndex))
- {
- PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
- chargingInfo[gunIndex]->ReservationId = 0;
- chargingInfo[gunIndex]->SystemStatus = S_IDLE;
- }
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
- ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowReq == YES)
- {
- ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
- if (opcc_chk_reserve_expired(gunIndex))
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- chargingInfo[gunIndex]->ReservationId = ShmOCPP20Data->ReserveNow[gunIndex].id;
- chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
- }
- ShmOCPP20Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
- }
- if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
- ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationReq == YES)
- {
- ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
- if (opcc_chk_reserve_expired(gunIndex))
- {
- PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
- chargingInfo[gunIndex]->ReservationId = 0;
- chargingInfo[gunIndex]->SystemStatus = S_IDLE;
- }
- ShmOCPP20Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
- }
- }
- }
- void ocpp_chk_availability_cmd(byte gunIndex)
- {
- byte type = 0; // 0 : none, 1 : operative, 2 inoperative
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES)
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
- if(strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, true);
- type = 1;
- }
- else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, false);
- type = 2;
- }
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES)
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- ShmOCPP20Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
- if(strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex].operationalStatus, "Operative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, true);
- type = 1;
- }
- else if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex].operationalStatus, "Inoperative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, false);
- type = 2;
- }
- }
- }
- if (type == 1)
- {
- chargingInfo[gunIndex]->IsAvailable = YES;
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
- {
- setChargerMode(gunIndex, MODE_IDLE);
- }
- }
- else if (type == 2)
- {
- chargingInfo[gunIndex]->IsAvailable = NO;
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
- {
- setChargerMode(gunIndex, MODE_MAINTAIN);
- }
- }
- }
- void ocpp_chk_unlock_cmd(byte gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES)
- {
- ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
- if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK &&
- chargingInfo[gunIndex]->SystemStatus <= S_CHARGING)
- {
- // Unlocked - 充電中,需停止充電
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
- ChargingTerminalProcess(gunIndex);
- }
- strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
- ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES)
- {
- ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
- if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK &&
- chargingInfo[gunIndex]->SystemStatus <= S_CHARGING)
- {
- // Unlocked - 充電中,需停止充電
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "UnlockCommand");
- ChargingTerminalProcess(gunIndex);
- }
- strcpy((char*)ShmOCPP20Data->UnlockConnector[gunIndex].Response_status, "Unlocked");
- ShmOCPP20Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
- }
- }
- }
- bool ocpp_chk_remoteStop_cmd(byte gunIndex)
- {
- byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- // 有 AC 槍的話
- if (acDirIndex > 0 && gunIndex > 0)
- {
- gunIndex += acDirIndex;
- }
- bool result = false;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- result = ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStopTransactionReq;
- if (result)
- {
- DEBUG_INFO_MSG("Remote Stop by OCPP (%d) \n", gunIndex);
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
- ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "Remote");
- ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStopTransactionReq = NO;
- }
- }
- return result;
- }
- bool ocpp_sub_get_remote_start_transaction_req(byte gun_index)
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- result = ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq;
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- result = ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq;
- }
- if (result)
- {
- strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,
- (char *)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag);
- }
- return result;
- }
- void ocpp_sub_set_remote_start_transaction_req(byte gunIndex, bool result)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStartTransactionReq = result;
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStartTransactionReq = result;
- }
- void ocpp_chk_remoteStart_cmd()
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
- {}
- else if(!isDetectPlugin())
- {
- // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
- byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++)
- {
- if (ocpp_sub_get_remote_start_transaction_req(acDirIndex))
- {
- if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
- ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION)
- {
- ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
- //ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
- DetectPluginStart();
- return;
- }
- ocpp_sub_set_remote_start_transaction_req(acDirIndex, NO);
- }
- }
- byte threeGunIndex = 0;
- byte dcIndex = 0;
- bool isGunUsingStatus = false;
- byte scheduleIndex = 0;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- // 如果有 AC 槍,且 DC 槍也有兩把
- if (acDirIndex == 1 && _index == 1)
- threeGunIndex = 1;
- if (ocpp_sub_get_remote_start_transaction_req(_index + threeGunIndex))
- dcIndex = _index;
- if (chargingInfo[_index]->SystemStatus != S_IDLE)
- {
- isGunUsingStatus = true;
- }
- if (chargingInfo[_index]->schedule.isTriggerStart)
- scheduleIndex = _index;
- }
- // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
- if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
- {
- if (dcIndex == 0)
- threeGunIndex = 0;
- ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
- return;
- }
- if (dcIndex == 0)
- threeGunIndex = 0;
- if (ocpp_sub_get_remote_start_transaction_req(dcIndex + threeGunIndex))
- {
- if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
- chargingInfo[dcIndex]->SystemStatus == S_RESERVATION)
- {
- chargingInfo[dcIndex]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
- DetectPluginStart();
- }
- ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
- }
- else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart)
- {
- if (chargingInfo[scheduleIndex]->SystemStatus == S_IDLE ||
- chargingInfo[scheduleIndex]->SystemStatus == S_RESERVATION)
- {
- chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- DetectPluginStart();
- }
- chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
- }
- }
- }
- void ocpp_chk_update_cmd()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES)
- {
- ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
- if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL)
- {
- DEBUG_INFO_MSG("Backend : update start. \n");
- sleep(2);
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- KillTask();
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- setChargerMode(_index, MODE_UPDATE);
- }
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
- {
- ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
- }
- byte updateResult = CheckUpdateProcess();
- if (updateResult == PASS)
- {
- DEBUG_INFO_MSG("Backend : update complete. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
- }
- else if (updateResult == MODELNAME_FAIL)
- {
- DEBUG_INFO_MSG("Backend : model name is none match. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- else
- {
- DEBUG_INFO_MSG("Backend : update fail. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
- }
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- system("reboot -f");
- }
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq == YES)
- {
- ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = NO;
- if (strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Downloaded") == EQUAL)
- {
- DEBUG_INFO_MSG("Backend : update start. \n");
- sleep(2);
- strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "");
- strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installing");
- ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- KillTask();
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- setChargerMode(_index, MODE_UPDATE);
- }
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
- {
- ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
- }
- byte updateResult = CheckUpdateProcess();
- if (updateResult == PASS)
- {
- DEBUG_INFO_MSG("Backend : update complete. \n");
- strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
- }
- else if (updateResult == MODELNAME_FAIL)
- {
- DEBUG_INFO_MSG("Backend : model name is none match. \n");
- strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
- ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- else
- {
- DEBUG_INFO_MSG("Backend : update fail. \n");
- strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
- }
- strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
- ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- system("reboot -f");
- }
- }
- }
- }
- bool ocpp_chk_invalid_id_cmd(byte gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE"))
- {
- if (strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Blocked") == EQUAL ||
- strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Expired") == EQUAL ||
- strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL)
- return true;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (strstr((char *) ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE"))
- {
- if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Blocked") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Expired") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Invalid") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NoCredit") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAllowedTypeEVSE") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAtThisLocation") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "NotAtThisTime") == EQUAL ||
- strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].Response_idTokenInfo.status, "Unknown") == EQUAL)
- return true;
- }
- }
- return false;
- }
- bool ocpp_chk_profileConf_cmd(byte _index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES)
- {
- ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
- return true;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CSUMsg.bits[_index].ChargingProfileConf == YES)
- {
- ShmOCPP20Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
- return true;
- }
- }
- return false;
- }
- void ocpp_lift_profileReq_cmd(byte gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO)
- {
- if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO)
- ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
- }
- }
- else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO)
- {
- if (ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO)
- ShmOCPP20Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
- }
- }
- }
- void ocpp_set_startTransation_cmd(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
- // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
- _OcppGunIndex = 2;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
- strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
- else
- strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
- PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
- ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
- strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
- else
- strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
- PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
- ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
- }
- }
- void ocpp_set_stopTransation_cmd(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
- // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
- _OcppGunIndex = 2;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
- strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
- else
- strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
- PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
- ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
- strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
- else
- strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
- PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
- ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
- }
- }
- void ocpp_set_errorCode_cmd(byte gunIndex, char *errString)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, errString);
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void ocpp_set_stopReason_by_cmd(byte gunIndex, char *reason)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, reason);
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex].transactionInfo.stoppedReason, reason);
- }
- }
- }
- void ocpp_set_authorizeReq_cmd(byte value)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = value;
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- ShmOCPP20Data->SpMsg.bits.AuthorizeReq = value;
- }
- void ocpp_set_authorizeConf_cmd(byte value)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- ShmOCPP16Data->SpMsg.bits.AuthorizeConf = value;
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- ShmOCPP20Data->SpMsg.bits.AuthorizeConf = value;
- }
- void ocpp_set_errCode_cmd(byte gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "InternalError");
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->ConnectorAlarmCode);
- }
- else if (strcmp((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "OtherError");
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->EvConnAlarmCode);
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void ocpp_clear_errorCode_cmd(byte gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "NoError") != EQUAL)
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, "NoError");
- if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "") != EQUAL)
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void ocpp_clear_idTag_cmd(byte gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "");
- }
- void ocpp_clear_stopReason(byte gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "");
- }
- unsigned short _ocpp_get_connect_timeout()
- {
- uint16_t result = (TIMEOUT_SPEC_HANDSHAKING / 1000);
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData,"") != 0)
- result = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value,"") != 0)
- result = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
- }
- return result;
- }
- bool _ocpp_get_disconnect_policy()
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE") == EQUAL &&
- strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == EQUAL)
- {
- result = true;
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthorizeOffline].variableAttribute[0].value, "") == EQUAL &&
- strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "") == EQUAL)
- {
- result = true;
- }
- }
- return result;
- }
- bool ocpp_get_authorize_conf()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- return ShmOCPP16Data->SpMsg.bits.AuthorizeConf;
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- return ShmOCPP20Data->SpMsg.bits.AuthorizeConf;
- return false;
- }
- bool ocpp_get_startTransation_req(byte gunIndex)
- {
- bool result = false;
- // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- result = ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq;
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- result = ShmOCPP20Data->CpMsg.bits[gunIndex].TransactionEventReq;
- }
- return result;
- }
- void ocpp_chargingProfile_process(byte _index)
- {
- int _time = 0;
- int _startCount = NO_DEFINE;
- int _maxCount = 0;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
- ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES)
- {
- _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
- _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
- _startCount = NO_DEFINE;
- for (byte _count = 0; _count < _maxCount; _count++)
- {
- // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
- if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod)
- {
- if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
- ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
- {
- _startCount = _count;
- }
- }
- }
- PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", _index, _startCount);
- if (_startCount < _maxCount)
- {
- PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
- chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL * ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
- if (chargingInfo[_index]->EvBatterytargetVoltage > 0 &&
- chargingInfo[_index]->PresentChargingVoltage > 0)
- chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
- else
- chargingInfo[_index]->ChargingProfileCurrent = 0;
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if (strcmp((char *)ShmOCPP20Data->SmartChargingProfile[_index].chargingProfileKind, "Absolute") == EQUAL &&
- ShmOCPP20Data->SmartChargingProfile[_index].id == YES)
- {
- _time = GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].startSchedule);
- _maxCount = ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod);
- _startCount = NO_DEFINE;
- for (byte _count = 0; _count < _maxCount; _count++)
- {
- // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
- if (_time >= ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].startPeriod)
- {
- if ((_count == 0 && ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].limit >= MIN_OUTPUT_CUR) ||
- ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_count].limit > MIN_OUTPUT_CUR)
- {
- _startCount = _count;
- }
- }
- }
- PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", _index, _startCount);
- if (_startCount < _maxCount)
- {
- PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit);
- chargingInfo[_index]->ChargingProfilePower = ShmOCPP20Data->SmartChargingProfile[_index].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit * AC_OUTPUT_VOL;
- if (chargingInfo[_index]->EvBatterytargetVoltage > 0 && chargingInfo[_index]->PresentChargingVoltage > 0)
- chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
- else
- chargingInfo[_index]->ChargingProfileCurrent = 0;
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- PRINTF_FUNC("Profile : ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
- PRINTF_FUNC("Profile : ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
- }
- //===============================================
- // wifi schedule
- //===============================================
- bool WifiScheduleStop(byte gunIndex)
- {
- bool result = false;
- result = chargingInfo[gunIndex]->schedule.isTriggerStop;
- chargingInfo[gunIndex]->schedule.isTriggerStop = NO;
- return result;
- }
- //===============================================
- // SQLite3 related routine
- //===============================================
- int DB_Open(sqlite3 *db)
- {
- int result = PASS;
- char* errMsg = NULL;
- char* createRecordSql="CREATE TABLE IF NOT EXISTS charging_record("
- "idx integer primary key AUTOINCREMENT, "
- "reservationId text, "
- "transactionId text, "
- "startMethod text, "
- "userId text, "
- "dateTimeStart text, "
- "dateTimeStop text,"
- "socStart text, "
- "socStop text, "
- "chargeEnergy text, "
- "stopReason text"
- ");";
- char* createCfgSql="CREATE TABLE IF NOT EXISTS `config` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`item` TEXT NOT NULL, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(item,connector) on conflict replace);";
- char* createrecordSql="CREATE TABLE IF NOT EXISTS `event_record` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`occurDatetime` TEXT NOT NULL, "
- "`statusCode` TEXT NOT NULL, unique(occurDatetime,statusCode) on conflict replace);";
- char* createrebootSql="CREATE TABLE IF NOT EXISTS `reboot_record` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`rebootDatetime` TEXT NOT NULL, unique(rebootDatetime) on conflict replace);";
- char * createconsumptionSql = "CREATE TABLE IF NOT EXISTS `power_consumption` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(connector) on conflict replace);";
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC( "Local charging record database open successfully.\r\n");
- if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create local charging record table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened local charging record table successfully\n");
- }
- if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create local config table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened local config table successfully\n");
- }
- if (sqlite3_exec(db, createrecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create local record table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened local record table successfully\n");
- }
- if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create reboot record table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened reboot record table successfully\n");
- }
- if (sqlite3_exec(db, createconsumptionSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create power consumption record table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened power consumption record table successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Insert_Record(sqlite3 *db, int gun_index)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[1024];
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
- "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
- chargingInfo[gun_index]->ReservationId,
- ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
- chargingInfo[gun_index]->StartMethod,
- chargingInfo[gun_index]->StartUserId,
- chargingInfo[gun_index]->StartDateTime,
- chargingInfo[gun_index]->StopDateTime,
- chargingInfo[gun_index]->EvBatteryStartSoc,
- chargingInfo[gun_index]->EvBatterySoc,
- chargingInfo[gun_index]->PresentChargedEnergy,
- ShmOCPP16Data->StopTransaction[gun_index].StopReason);
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
- "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
- chargingInfo[gun_index]->ReservationId,
- ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId,
- chargingInfo[gun_index]->StartMethod,
- chargingInfo[gun_index]->StartUserId,
- chargingInfo[gun_index]->StartDateTime,
- chargingInfo[gun_index]->StopDateTime,
- chargingInfo[gun_index]->EvBatteryStartSoc,
- chargingInfo[gun_index]->EvBatterySoc,
- chargingInfo[gun_index]->PresentChargedEnergy,
- ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason);
- }
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC( "Local charging record database open successfully.\n");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Insert local charging record error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Insert local charging record successfully\n");
- }
- sprintf(insertSql, "delete from charging_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "delete local charging error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "delete local charging record successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable)
- {
- uint8_t result = false;
- char* errMsg = NULL;
- char sqlStr[1024];
- srand(time(NULL));
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC( "Local charging record database open successfully (%d).\r\n", IsAvailable);
- sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
- PRINTF_FUNC("sqlStr= %s\r\n", sqlStr);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "update config error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
- }
- sqlite3_close(db);
- }
- return result;
- }
- void DB_Update_PowerConsumption(sqlite3 *db, uint8_t gun_index, float value)
- {
- char* errMsg = NULL;
- char sqlStr[1024];
- srand(time(NULL));
- if(sqlite3_open(DB_FILE, &db))
- {
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sprintf(sqlStr, "insert or replace into power_consumption (connector, val) values(%d, %f);", gun_index, value);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- PRINTF_FUNC( "update power_consumption error message: %s\n", errMsg);
- }
- else
- {
- //PRINTF_FUNC("update connector-%d power_consumption item consumption to %f \r\n", gun_index, value);
- }
- sqlite3_close(db);
- }
- }
- int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
- {
- uint8_t result = true;
- char* errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- sprintf(sqlStr, "select * from config where item='IsAvailable' and connector=%d;", gun_index);
- //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC( "Local config query database open successfully.\r\n");
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if(rows>0)
- {
- for(int idxRow=1;idxRow<=rows;idxRow++)
- {
- if(strcmp(rs[(idxRow*cols)+3], "0") == 0)
- {
- result = false;
- }
- PRINTF_FUNC("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow*cols)+3]);
- }
- }
- else
- {
- PRINTF_FUNC("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- float DB_Get_PowerConsumption(sqlite3 *db, uint8_t gun_index)
- {
- float result = 0;
- char* errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- sprintf(sqlStr, "select * from power_consumption where connector=%d;", gun_index);
- if (sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC("Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC("Local config query database open successfully.\r\n");
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if (rows > 0)
- {
- for (int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atof(rs[(idxRow * cols) + 2]);
- }
- }
- else
- {
- PRINTF_FUNC( "Query connector-%d fail, set default value to consumption.\r\n", gun_index);
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Reboot_Record(sqlite3 *db)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[256];
- sprintf(insertSql, "insert into reboot_record(rebootDatetime) values(CURRENT_TIMESTAMP);");
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC( "Local charging record database open successfully.\n");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Insert reboot record error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Insert reboot record successfully\n");
- }
- sprintf(insertSql, "delete from reboot_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "delete reboot record error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "delete reboot record successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- //===============================================
- // Config process
- //===============================================
- void AddPlugInTimes(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
- else if(chargingInfo[gunIndex]->Type == _Type_CCS_2)
- ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
- else if(chargingInfo[gunIndex]->Type == _Type_GB)
- ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
- }
- void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
- {
- char cmdBuf[32];
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
- tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- tmCSU->tm_sec);
- if (isStart)
- strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
- else
- strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
- }
- void zipLogFiles()
- {
- const char* logPath = "/Storage/SystemLog";
- // 獲取目錄
- DIR* pDir = opendir(logPath);
- if (pDir != NULL)
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- // PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
- // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- // tmCSU->tm_sec);
- // Read items inside the folder
- struct dirent* pEntry = NULL;
- while ((pEntry = readdir(pDir)) != NULL)
- {
- if (strcmp(pEntry->d_name, ".") != 0 &&
- strcmp(pEntry->d_name, "..") != 0 &&
- strncmp(pEntry->d_name, "[", 1) == 0 &&
- strstr(pEntry->d_name, "tar") < 0)
- {
- char yearC[5];
- unsigned short year = 0;
- char monthC[3];
- unsigned short month = 0;
- yearC[4] = '\0';
- strncpy(yearC, pEntry->d_name + 1, 4);
- monthC[2] = '\0';
- strncpy(monthC, pEntry->d_name + 6, 2);
- year = atoi(yearC);
- month = atoi(monthC);
- if (year != 0)
- {
- if (year < tmCSU->tm_year + 1900 ||
- (year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1))
- {
- DEBUG_INFO_MSG("tar file name : %s \n", pEntry->d_name);
- char file[256];
- memset(file, 0x00, sizeof(file));
- strcat(file, "tar zcvf ");
- strcat(file, logPath);
- strncat(file, "/", 1);
- strcat(file, pEntry->d_name);
- strcat(file, ".tar");
- strncat(file, " ", 1);
- strcat(file, logPath);
- strncat(file, "/", 1);
- strcat(file, pEntry->d_name);
- PRINTF_FUNC("zip = %s \n", file);
- system(file);
- }
- }
- }
- }
- }
- // Close folder
- closedir(pDir);
- }
- void ChangeGunSelectByIndex(byte sel)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = sel;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- }
- void CheckIsAlternatvieByModelName()
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W')
- {
- // 壁掛
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = YES;
- }
- else
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = NO;
- }
- void StopProcessingLoop()
- {
- system("/root/OcppBackend &");
- for (;;)
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- ocpp_chk_reset_cmd();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
- {
- ChkPrimaryStatus();
- ReviewCriticalAlarm();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 0)
- {
- PRINTF_FUNC("Soft reboot for retry self-tets (Primary). \n");
- KillAllTask();
- sleep(3);
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- }
- sleep(1);
- }
- }
- void CreateWatchdog()
- {
- if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
- {
- wtdFd = InitWatchDog();
- if (wtdFd < 0)
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- }
- bool IsConnectorWholeIdle()
- {
- bool result = true;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- if (chargingInfo[count]->SystemStatus != S_IDLE &&
- chargingInfo[count]->SystemStatus != S_RESERVATION)
- {
- result = false;
- break;
- }
- }
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
- {
- if (ac_chargingInfo[count]->SystemStatus != S_IDLE &&
- ac_chargingInfo[count]->IsErrorOccur == NO)
- {
- result = false;
- break;
- }
- }
- return result;
- }
- void ClearAlarmCodeWhenAcOff()
- {
- if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- }
- }
- //==========================================
- // Check task processing
- //==========================================
- void CheckTask()
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(system("pidof -s Module_4g > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_4g not running, restart it.\r\n");
- system("/root/Module_4g &");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(system("pidof -s Module_Wifi > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_Wifi not running, restart it.\r\n");
- system("/root/Module_Wifi &");
- }
- }
- if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
- if(system("pidof -s OcppBackend > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("OcppBackend not running, restart it.\r\n");
- ocpp_process_start();
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if((time((time_t*)NULL) - ShmOCPP16Data->procDogTime) > 180)
- {
- DEBUG_ERROR_MSG("OcppBackend watch dog timeout task restart.\n");
- ShmOCPP16Data->procDogTime = time((time_t*)NULL);
- system("pkill OcppBackend");
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if((time((time_t*)NULL) - ShmOCPP20Data->procDogTime) > 180)
- {
- DEBUG_ERROR_MSG("OcppBackend20 watch dog timeout task restart.\n");
- ShmOCPP16Data->procDogTime = time((time_t*)NULL);
- system("pkill OcppBackend20");
- }
- }
- }
- if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_ProduceUtils not running, restart it.\r\n");
- system ("/root/Module_ProduceUtils &");
- }
- }
- void InitialDHCP()
- {
- char tmpbuf[256];
- memset(tmpbuf,0,256);
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- //==========================================
- // Check Smart Charging Profile
- //==========================================
- int GetStartScheduleTime(unsigned char *time)
- {
- int result = -1;
- struct tm tmScheduleStart;
- struct timeb tbScheduleStart;
- if((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
- {
- tmScheduleStart.tm_year -= 1900;
- tmScheduleStart.tm_mon -= 1;
- tbScheduleStart.time = mktime(&tmScheduleStart);
- tbScheduleStart.millitm = 0;
- result = DiffTimebWithNow(tbScheduleStart) / 1000;
- }
- return result;
- }
- void CheckSmartChargeProfile(byte _index)
- {
- if (ocpp_chk_profileConf_cmd(_index))
- {
- ocpp_chargingProfile_process(_index);
- }
- }
- void CheckReturnToChargingConn()
- {
- if ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ShmSysConfigAndInfo->SysConfig.AcConnectorCount) > 1 &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG)
- {
- bool isReturnTimeout = false;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- // 如果選的 DC 槍在充電~ 則 DC 槍不改變
- if (count == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- {
- if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
- (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- isReturnTimeout = false;
- break;
- }
- }
- else if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- {
- if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
- (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- }
- // AC 槍
- if (!isReturnTimeout && ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- // 沒有選中 AC,且 AC 在充電中
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
- (ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE))
- {
- // 當前 DC 充電槍在 idle 狀態
- if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE ||
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_RESERVATION)
- {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
- ((chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_COMPLETE) ||
- (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_CCS_PRECHARGE_ST1)))
- {
- // 當前 DC 充電槍在 idle 狀態
- if (ac_chargingInfo[0]->SystemStatus == S_IDLE ||
- ac_chargingInfo[0]->SystemStatus == S_RESERVATION)
- {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- }
- if (!isReturnTimeout)
- StopSystemTimeoutDet();
- }
- }
- bool GetStartChargingByAlterMode(byte _gun)
- {
- bool result = true;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
- {
- for (byte _select = 0; _select < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _select++)
- {
- if (_select != _gun)
- {
- if (chargingInfo[_select]->SystemStatus != S_IDLE &&
- chargingInfo[_select]->SystemStatus != S_RESERVATION)
- {
- result = false;
- break;
- }
- }
- }
- }
- return result;
- }
- void TheEndCharging(byte gun_index)
- {
- int _diffTime = 0;
- ftime(&endChargingTime[gun_index]);
- _diffTime = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
- // below 0 or over 5 sec is abnormal
- if (_diffTime < 0 ||
- _diffTime > chargingInfo[gun_index]->PresentChargedDuration + 5)
- {
- PRINTF_FUNC("TimeZone changed End (%d) \n", gun_index);
- }
- else
- chargingInfo[gun_index]->PresentChargedDuration = _presentChargingTimeBuf[gun_index] + _diffTime;
- chargingInfo[gun_index]->isRemoteStart = NO;
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
- ChangeStartOrStopDateTime(NO, gun_index);
- DB_Insert_Record(localDb, gun_index);
- }
- void AdjustChargerCurrent()
- {
- ShmSysConfigAndInfo->SysConfig.RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
- // 設定的電流~ 如超過可輸出的電流,則 bypass
- if (ShmSysConfigAndInfo->SysConfig.RatingCurrent < ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent ||
- ShmSysConfigAndInfo->SysConfig.RatingCurrent == 0)
- {
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = 0;
- }
- PRINTF_FUNC ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
- ShmPsuData->SystemAvailablePower / 10,
- ShmPsuData->SystemAvailableCurrent / 10
- );
- PRINTF_FUNC ("Config : ChargingPower = %d, ChargingCurrent = %d",
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent
- );
- }
- void CheckStatusOfMeter()
- {
- // 橋接如果搭上~ 則兩個電表都是使用狀態
- // 如橋接沒有搭上~ 則視該火線 relay 狀態為電表使用狀態
- if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES)
- {
- for (byte mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++)
- ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
- }
- else
- {
- for (byte mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++)
- {
- if (chargingInfo[mIndex]->RelayKPK2Status == YES || chargingInfo[mIndex]->RelayK1K2Status)
- ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
- else
- ShmCsuMeterData->_meter[mIndex].isCalculation = NO;
- }
- }
- }
- void ReviewCriticalAlarm()
- {
- if (ShmDcCommonData->GunRelayDrivingOccur[0] == YES ||
- ShmDcCommonData->GunRelayDrivingOccur[1] == YES ||
- ShmDcCommonData->GunRelayWeldingOccur[0] == YES ||
- ShmDcCommonData->GunRelayWeldingOccur[1] == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen ||
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- {
- ShmSysConfigAndInfo->SysWarningInfo.Level = 2;
- }
- else
- ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
- }
- void CheckRelayWeldingOrDrivingFault(byte gun_index)
- {
- // relay welding fault then stop the charging process.
- byte faultCode = RELAY_STATUS_ERROR_NONE;
- if (gun_index == 0)
- {
- if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING)
- {
- faultCode = RELAY_STATUS_ERROR_WELDING;
- }
- else if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING)
- {
- faultCode = RELAY_STATUS_ERROR_DRIVING;
- }
- }
- else if (gun_index == 1)
- {
- if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING)
- {
- faultCode = RELAY_STATUS_ERROR_WELDING;
- }
- else if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING)
- {
- faultCode = RELAY_STATUS_ERROR_DRIVING;
- }
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2 &&
- !ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
- {
- // 橋接
- if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING)
- {
- faultCode = RELAY_STATUS_ERROR_WELDING;
- }
- else if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING)
- {
- faultCode = RELAY_STATUS_ERROR_DRIVING;
- }
- }
- if (faultCode == RELAY_STATUS_ERROR_WELDING)
- {
- // welding
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- RecordAlarmCode(gun_index, "011011");
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- RecordAlarmCode(gun_index, "011015");
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- RecordAlarmCode(gun_index, "011013");
- ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
- EmcOccureThenStopCharging();
- }
- else if (faultCode == RELAY_STATUS_ERROR_DRIVING)
- {
- // driving
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- RecordAlarmCode(gun_index, "011012");
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- RecordAlarmCode(gun_index, "011016");
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- RecordAlarmCode(gun_index, "011014");
- ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
- EmcOccureThenStopCharging();
- }
- else
- {
- ShmDcCommonData->GunRelayWeldingOccur[gun_index] = NO;
- ShmDcCommonData->GunRelayDrivingOccur[gun_index] = NO;
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- ResetChargerAlarmCode(gun_index, "011012");
- ResetChargerAlarmCode(gun_index, "011011");
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- {
- ResetChargerAlarmCode(gun_index, "011014");
- ResetChargerAlarmCode(gun_index, "011013");
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- ResetChargerAlarmCode(gun_index, "011016");
- ResetChargerAlarmCode(gun_index, "011015");
- }
- }
- }
- bool PrecheckIsPass(byte gun_index)
- {
- bool result = true;
- // relay welding or driving 是反向
- if (result)
- result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
- return result;
- }
- void CollectError(byte gun_index)
- {
- errCollect.GunErrMessage |= ShmDcCommonData->ConnectErrList[gun_index].GunErrMessage;
- }
- void AlarmCheck(byte type)
- {
- // type : Cha = 0、CCS = 1、GBT = 2
- if (type == _Type_Chademo)
- {
- // GFD Trip
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 0))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
- // UVP
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 1))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO;
- // OTP
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 2))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = NO;
- // OVP
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 3))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
- // GFD Warning
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 4))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO;
- // Relay Welding
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 5))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = NO;
- // Relay Driving
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 6))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
- // Connect temp Sensor broken
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 7))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = NO;
- }
- else if (type == _Type_CCS_2)
- {
- // GFD Trip
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 0))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
- // UVP
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 1))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO;
- // OTP
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 2))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = NO;
- // OVP
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 3))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
- // GFD Warning
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 4))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO;
- // Relay Welding
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 5))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = NO;
- // Relay Driving
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 6))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
- // Connect temp Sensor broken
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 7))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = NO;
- }
- else if (type == _Type_GB)
- {
- // GFD Trip
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 0))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO;
- // UVP
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 1))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO;
- // OTP
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 2))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = NO;
- // OVP
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 3))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
- // GFD Warning
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 4))
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES;
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO;
- // Relay Welding
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 5))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = NO;
- // Relay Driving
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 6))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = NO;
- // Connect temp Sensor broken
- if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 7))
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = YES;
- else
- ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = NO;
- }
- }
- void SavePresentChargedDuration(byte gun_index)
- {
- int _diffTime = 0;
- ftime(&endChargingTime[gun_index]);
- _diffTime = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
- // below 0 or over 5 sec is abnormal
- if (_diffTime < 0 ||
- _diffTime > chargingInfo[gun_index]->PresentChargedDuration + 5)
- {
- _presentChargingTimeBuf[gun_index] = chargingInfo[gun_index]->PresentChargedDuration;
- ftime(&startChargingTime[gun_index]);
- PRINTF_FUNC("TimeZone changed (%d) \n", gun_index);
- }
- else
- chargingInfo[gun_index]->PresentChargedDuration = _presentChargingTimeBuf[gun_index] + _diffTime;
- }
- int main(void)
- {
- if(CreateShareMemory() == 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("CreatShareMemory NG \n");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- PRINTF_FUNC("===== Boot and Initialization start ===== \n");
- if (!InitialSystemDefaultConfig())
- {
- DEBUG_ERROR_MSG("InitialSystemDefaultConfig NG \n");
- StopProcessingLoop();
- }
- PRINTF_FUNC("CheckConnectorTypeStatus and CheckIsAlternatvie \n");
- CheckGunTypeFromHw();
- CheckIsAlternatvieByModelName();
- InitialShareMemoryInfo();
- PRINTF_FUNC("InitialShareMemoryInfo OK. \n");
- if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
- PRINTF_FUNC("ChargerType (IEC or UL) = IEC \n");
- else
- PRINTF_FUNC("ChargerType (IEC or UL) = UL \n");
- ChangeLcmByIndex(_LCM_INIT);
- if (!CheckConnectorTypeStatus())
- isModelNameMatch = false;
- Initialization();
- PRINTF_FUNC("===== Initial Complete ===== \n");
- PRINTF_FUNC("===== Spawn all Task and self test start ===== \n");
- SpawnTask();
- if (!isModelNameMatch)
- {
- // Module Name 與硬體對應不正確
- PRINTF_FUNC("*** Module Name & HW info none match : Please check if the Model name and HW are matched. ***\n");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
- ChangeLcmByIndex(_LCM_FIX);
- sleep(3);
- KillTask();
- StopProcessingLoop();
- }
- PRINTF_FUNC("Module Name & HW info correct. Self test run..\n");
- CreateTimeoutFork();
- SelfTestRun();
- StopSystemTimeoutDet();
- if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
- ShmPsuData->Work_Step == _NO_WORKING ||
- ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES ||
- strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == EQUAL)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
- {
- if (!DisplaySelfTestFailReason() &&
- ShmDcCommonData->rebootCount < 1)
- {
- printf("Soft reboot for retry self-tets. \n");
- SetupRebootCount(1);
- sleep(3);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- else if (ShmDcCommonData->rebootCount < 1)
- {
- printf("Soft reboot for retry self-tets (Nomal). \n");
- SetupRebootCount(1);
- sleep(3);
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- else
- SetupRebootCount(0);
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- ChargingAlarmProcess(gun_index);
- }
- //ChangeLcmByIndex(_LCM_FIX);
- sleep(3);
- //if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
- //{
- KillTaskExceptDetectTask();
- //}
- //else
- // KillTask();
- StopProcessingLoop();
- }
- else
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_IDLE);
- }
- SetupRebootCount(0);
- }
- PRINTF_FUNC("===== Self Test Complete ===== \n");
- PRINTF_FUNC("===== Finally Create DB ===== \n");
- // Local DB
- if(DB_Open(localDb) != PASS)
- {
- PRINTF_FUNC("DB_Open fail. \n");
- isDb_ready = false;
- }
- else
- {
- isDb_ready = true;
- for(int _index=0; _index< ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;_index++)
- {
- chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
- chargingInfo[_index]->PowerConsumption = DB_Get_PowerConsumption(localDb, _index);
- }
- DB_Reboot_Record(localDb);
- }
- ChangeLcmByIndex(_LCM_IDLE);
- sleep(1);
- CreateRfidFork();
- // Create Watchdog
- //-------------------CreateWatchdog();
- PRINTF_FUNC("===== Create DB End ===== \n");
- PRINTF_FUNC("===== Charger info ===== ");
- PRINTF_FUNC("SW Version = %s", fwVersion);
- PRINTF_FUNC("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
- CheckFwSlotStatusLog();
- AdjustChargerCurrent();
- gettimeofday(&_cmdMainPriority_time, NULL);
- _ocppProfileChkFlag = 0;
- if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") == EQUAL)
- {
- DEBUG_ERROR_MSG("URL is empty kill Module_OcppBackend...\n");
- system ("pkill OcppBackend");
- }
- unsigned long _mainTimebuf = 0;
- for (;;)
- {
- ocpp_auto_response_BootNotification();
- ocpp_chk_reset_cmd();
- ChkPrimaryStatus();
- if ((IsConnectorWholeIdle() || ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) &&
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_ReturnToChargingGunDet)
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0)
- {
- sleep(1);
- continue;
- }
- // OCPP 邏輯
- ocpp_chk_remoteStart_cmd();
- // 讀卡邏輯
- ScannerCardProcess();
- // 當 AC 沒有搭上時,清除一些錯誤碼
- ClearAlarmCodeWhenAcOff();
- // 確認是否要回到充電中的槍畫面邏輯判斷
- CheckReturnToChargingConn();
- if ((_acgunIndex > 0 && isDetectPlugin() && !isCardScan))
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- _mainTimebuf = GetTimeoutValue(_cmdMainPriority_time);
- if (_mainTimebuf < 0)
- gettimeofday(&_cmdMainPriority_time, NULL);
- if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000)
- {
- CheckTask();
- CheckDisconnectPolicy();
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if ((chargingInfo[_index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[_index]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[_index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (chargingInfo[_index]->SystemStatus == S_CHARGING && _ocppProfileChkFlag == 12)
- {
- ocpp_lift_profileReq_cmd(_index);
- gunOutputVol[_index] = chargingInfo[_index]->PresentChargingVoltage;
- _ocppProfileChkFlag = 0;
- }
- else if (chargingInfo[_index]->SystemStatus != S_CHARGING)
- {
- ocpp_lift_profileReq_cmd(_index);
- _ocppProfileChkFlag = 0;
- }
- else
- _ocppProfileChkFlag++;
- if (chargingInfo[_index]->SystemStatus >= S_CHARGING &&
- chargingInfo[_index]->SystemStatus <= S_ALARM)
- {
- DB_Update_PowerConsumption(localDb, _index, chargingInfo[_index]->PowerConsumption);
- }
- }
- // OTP
- if (chargingInfo[_index]->Type == _Type_Chademo)
- {
- // if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
- // {
- // if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
- // RecordAlarmCode(_index, "012229");
- // else if (chargingInfo[_index]->ConnectorTemp != 0 &&
- // chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
- // ResetChargerAlarmCode(_index, "012229");
- // }
- // else
- // {
- // // 沒接上 Sensor or 異常
- // //RecordAlarmCode(_index, "011018");
- // ResetChargerAlarmCode(_index, "012229");
- // }
- }
- else if (chargingInfo[_index]->Type == _Type_CCS_2)
- {
- // CCS 不管甚麼輸出都會有槍溫偵測!!~
- if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
- {
- if(chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
- RecordAlarmCode(_index, "012230");
- else if (chargingInfo[_index]->ConnectorTemp != 0 &&
- chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
- ResetChargerAlarmCode(_index, "012230");
- ResetChargerAlarmCode(_index, "011019");
- }
- else
- {
- // 沒接上 Sensor or 異常
- RecordAlarmCode(_index, "011019");
- ResetChargerAlarmCode(_index, "012230");
- }
- }
- else if (chargingInfo[_index]->Type == _Type_GB)
- {
- // if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
- // {
- // if(chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
- // RecordAlarmCode(_index, "012231");
- // else if (chargingInfo[_index]->ConnectorTemp != 0 &&
- // chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
- // ResetChargerAlarmCode(_index, "012231");
- // }
- // else
- // {
- // // 沒接上 Sensor or 異常
- // RecordAlarmCode(_index, "011020");
- // ResetChargerAlarmCode(_index, "012231");
- // }
- }
- }
- gettimeofday(&_cmdMainPriority_time, NULL);
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'L')
- CheckStatusOfMeter();
- // 確認當前錯誤 Level = 2 ?
- ReviewCriticalAlarm();
- errCollect.GunErrMessage = 0;
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- CheckGpioInStatus();
- // 確認系統的錯誤狀態
- CheckSystemErrorFunction(gun_index);
- // 確認 Relay Welding or Driving Fault
- CheckRelayWeldingOrDrivingFault(gun_index);
- // 收集各槍的錯誤狀態
- CollectError(gun_index);
- ocpp_chk_reserved_cmd(gun_index);
- ocpp_chk_availability_cmd(gun_index);
- ocpp_chk_unlock_cmd(gun_index);
- if ((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[gun_index]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[gun_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun_index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (chargingInfo[gun_index]->SystemStatus == S_CHARGING)
- {
- // 進充電後,如果輸出電壓落差大於 10V 則直接繼續看 ChargingProfile
- if (chargingInfo[gun_index]->PresentChargingVoltage >= gunOutputVol[gun_index] + 10 ||
- chargingInfo[gun_index]->PresentChargingVoltage <= gunOutputVol[gun_index] - 10)
- {
- _ocppProfileChkFlag = 12;
- gunOutputVol[gun_index] = chargingInfo[gun_index]->PresentChargingVoltage;
- }
- }
- CheckSmartChargeProfile(gun_index);
- }
- //PRINTF_FUNC("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
- switch(chargingInfo[gun_index]->SystemStatus)
- {
- case S_IDLE:
- case S_RESERVATION:
- case S_MAINTAIN:
- case S_FAULT:
- {
- if (chargingInfo[gun_index]->SystemStatus == S_IDLE &&
- isModeChange(gun_index))
- {
- PRINTF_FUNC("================= S_IDLE (%x) ================ \n", gun_index);
- chargingInfo[gun_index]->PresentChargedDuration = 0;
- chargingInfo[gun_index]->RemainChargingDuration = 0;
- chargingInfo[gun_index]->PresentChargingVoltage = 0;
- chargingInfo[gun_index]->PresentChargingCurrent = 0;
- strcpy((char *)chargingInfo[gun_index]->StartDateTime, "");
- strcpy((char *)chargingInfo[gun_index]->StopDateTime, "");
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
- gunOutputVol[gun_index] = 0.0;
- ocpp_clear_stopReason(gun_index);
- ocpp_auto_response_StartTransationConf(gun_index);
- ShmDcCommonData->startTransationFlag[gun_index] = START_TRANSATION_STATUS_WAIT;
- }
- else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION &&
- isModeChange(gun_index))
- {
- ocpp_auto_response_ReserveConf(gun_index);
- }
- if (chargingInfo[gun_index]->IsAvailable == NO)
- {
- setChargerMode(gun_index, MODE_MAINTAIN);
- }
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
- {
- if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
- else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_IDLE &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_RESERVATION &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_MAINTAIN &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_FAULT)
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- ClearDetectPluginFlag();
- ocpp_set_errCode_cmd(gun_index);
- setChargerMode(gun_index, MODE_FAULT);
- }
- else
- {
- if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
- {
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
- {
- // 均充 -> 最大充
- if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
- {
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE)
- {
- PRINTF_FUNC("======= Start to change average to max mode (Step 11) ======= \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING)
- {
- PRINTF_FUNC("======= Adjust current to achieve balance (Step 14) ======= \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
- }
- else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
- {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- }
- else
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- if (PrecheckIsPass(gun_index))
- {
- if (chargingInfo[gun_index]->SystemStatus == S_FAULT)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- setChargerMode(gun_index, MODE_IDLE);
- }
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
- {
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
- }
- else
- {
- // Idle 正常程序起點
- // 判斷是否有啟用檢查插槍
- if(isDetectPlugin())
- {
- // 卡號驗證成功後,等待充電槍插入充電車
- if (chargingInfo[gun_index]->RemoteStartFlag == YES)
- {
- if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
- chargingInfo[gun_index]->IsAvailable)
- {
- PRINTF_FUNC("Conn %d Start Charging : Remote \n", gun_index);
- chargingInfo[gun_index]->RemoteStartFlag = NO;
- chargingInfo[gun_index]->isRemoteStart = YES;
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
- ClearDetectPluginFlag();
- continue;
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
- {
- if (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable &&
- chargingInfo[gun_index]->SystemStatus == S_IDLE)
- {
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
- PRINTF_FUNC("Conn %d Start Charging : RFID CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- // 當前操作的槍號,進入 Preparing
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- ClearDetectPluginFlag();
- continue;
- }
- }
- if (!isCardScan)
- {
- // LCM => Waiting for plugging
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- }
- else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION)
- {
- if (!opcc_chk_reserve_expired(gun_index))
- {
- chargingInfo[gun_index]->SystemStatus = S_IDLE;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
- (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable))
- {
- PRINTF_FUNC("Conn %d Start Charging : Plug and charing \n");
- bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
- if (isCanStartChargingFlag)
- {
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- ClearDetectPluginFlag();
- strncpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (char *)ShmSysConfigAndInfo->SysConfig.SerialNumber, sizeof(ShmOCPP16Data->StartTransaction[gun_index].IdTag));
- continue;
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE &&
- ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_WAIT_FOR_PLUG)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
- }
- }
- } // Idle 正常程序終點
- }
- else
- {
- setChargerMode(gun_index, MODE_FAULT);
- if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
- }
- ReleaseSysAlarmCode(gun_index);
- }
- }
- break;
- case S_REASSIGN_CHECK:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================= S_REASSIGN_CHECK (%x) ================ \n", gun_index);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- StopSystemTimeoutDet();
- }
- bool isRessign = false;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
- {
- if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
- {
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- // 有其他槍已經分配好 psu 模塊
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
- chargingInfo[index]->SystemStatus >= S_PREPARNING &&
- chargingInfo[index]->SystemStatus != S_MAINTAIN)
- {
- PRINTF_FUNC("======= Start to change max to average mode (Step 1) ======= \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
- isRessign = true;
- break;
- }
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
- {
- // 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
- if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES)
- {
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING)
- {
- PRINTF_FUNC("======= Adjust current to achieve balance (Step 14) ======= \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
- }
- else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
- {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- continue;
- }
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- continue;
- }
- }
- if (isRessign)
- setChargerMode(gun_index, MODE_REASSIGN);
- else
- setChargerMode(gun_index, MODE_PRECHARGE);
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_REASSIGN:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== S_REASSIGN (%x) ================ \n", gun_index);
- gettimeofday(&_toAverage_time, NULL);
- }
- // 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
- // 此狀態下~ 控制權在於 PSU 及 EV小板 Process
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
- ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
- {
- if (ShmSysConfigAndInfo->SysInfo.CanAverageCharging)
- {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
- setChargerMode(gun_index, MODE_PRECHARGE);
- }
- else
- setChargerMode(gun_index, MODE_IDLE);
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
- ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
- {
- PRINTF_FUNC("======= The Change to average charge mode is complete. (Step 5) ======= \n");
- ShmSysConfigAndInfo->SysInfo.CanAverageCharging = true;
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
- }
- //PRINTF_FUNC("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_PREPARNING:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("=================== S_PREPARNING (%x) =============== \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
- }
- if (ShmPsuData->SystemPresentPsuQuantity > 0 && ShmPsuData->SystemAvailablePower > 10 &&
- ShmPsuData->Work_Step == _WORK_CHARGING &&
- GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 5000000)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2)
- {
- bool oughtAver = true;
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- // 共同進入充電邏輯
- if (chargingInfo[index]->SystemStatus != S_PREPARNING)
- {
- oughtAver = false;
- break;
- }
- }
- if (oughtAver)
- {
- PRINTF_FUNC("********* Automatically change to aver mode ********** \n");
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (錯誤)
- ocpp_set_stopReason_by_cmd(gun_index, "EVDisconnected");
- ChargingAlarmProcess(gun_index);
- }
- else if (isEvBoardNormalStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (正常)
- ocpp_set_stopReason_by_cmd(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if (ocpp_chk_remoteStop_cmd(gun_index) == YES ||
- WifiScheduleStop(gun_index))
- {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== S_PREPARING_FOR_EV (%x) ================ \n", gun_index);
- _presentChargingTimeBuf[gun_index] = 0;
- //strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
- // Start Transation
- ocpp_set_startTransation_cmd(gun_index);
- gettimeofday(&_startTransation_time[gun_index], NULL);
- }
- ShmDcCommonData->startTransationFlag[gun_index] = ocpp_is_resPass_StartTransationConf(gun_index);
- if (ShmDcCommonData->startTransationFlag[gun_index] == START_TRANSATION_STATUS_PASS)
- {
- if (ocpp_chk_invalid_id_cmd(gun_index))
- ShmDcCommonData->startTransationFlag[gun_index] = START_TRANSATION_STATUS_FAIL;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO)
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING ||
- ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
- !ocpp_get_startTransation_req(gun_index) ||
- _isAllowChargingOnDisconnect)
- {
- ShmDcCommonData->startTransationFlag[gun_index] = START_TRANSATION_STATUS_PASS;
- }
- }
- }
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- // 檢查車端的槍鎖是否為鎖上
- if (isEvGunLocked_chademo(gun_index) == YES)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- // 檢查車端的 charging enable 是否為 1
- if (isEvGunLocked_gb(gun_index) == YES)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- {
- // 檢查車端的 charging enable 是否為 1
- if (isEvGunLocked_ccs(gun_index) == YES)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (錯誤)
- ocpp_set_stopReason_by_cmd(gun_index, "EVDisconnected");
- ChargingAlarmProcess(gun_index);
- }
- else if (isEvBoardNormalStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (正常)
- ocpp_set_stopReason_by_cmd(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if (ocpp_chk_remoteStop_cmd(gun_index) == YES ||
- WifiScheduleStop(gun_index) ||
- ShmDcCommonData->startTransationFlag[gun_index] == START_TRANSATION_STATUS_FAIL ||
- (ShmDcCommonData->startTransationFlag[gun_index] == START_TRANSATION_STATUS_WAIT && (GetTimeoutValue(_startTransation_time[gun_index]) / 1000) > 10000))
- {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- if (ShmDcCommonData->startTransationFlag[gun_index] == START_TRANSATION_STATUS_FAIL ||
- ShmDcCommonData->startTransationFlag[gun_index] == START_TRANSATION_STATUS_WAIT)
- {
- PRINTF_FUNC("StartTransaction req fail. (%d) \n", gun_index);
- }
- }
- // LCM => Pre-charging
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_PREPARING_FOR_EVSE: // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== S_PREPARING_FOR_EVSE (%x) ================ \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
- }
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- // 檢查樁端的 GFD 結果
- if (isPrechargeStatus_chademo(gun_index) == 8)
- {
- // 當前操作的槍號,進入 Charging
- setChargerMode(gun_index, MODE_CHARGING);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012234");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordAlarmCode(gun_index, "012296");
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- // 檢查樁端的 GFD 結果
- if (isPrechargeStatus_gb(gun_index) > 9)
- {
- setChargerMode(gun_index, MODE_CHARGING);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012236");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordAlarmCode(gun_index, "012298");
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- {
- // 檢查樁端的 GFD 結果
- if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
- chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING))
- {
- setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordAlarmCode(gun_index, "012297");
- }
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (錯誤)
- ocpp_set_stopReason_by_cmd(gun_index, "EVDisconnected");
- ChargingAlarmProcess(gun_index);
- }
- else if (isEvBoardNormalStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (正常)
- ocpp_set_stopReason_by_cmd(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if (ocpp_chk_remoteStop_cmd(gun_index) == YES ||
- WifiScheduleStop(gun_index))
- {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // LCM => Pre-charging
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== S_CHARGING (%x) ================ \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- ftime(&startChargingTime[gun_index]);
- ocpp_clear_idTag_cmd(gun_index);
- ChangeStartOrStopDateTime(YES, gun_index);
- }
- SavePresentChargedDuration(gun_index);
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012234");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordAlarmCode(gun_index, "012296");
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012236");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordAlarmCode(gun_index, "012298");
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordAlarmCode(gun_index, "012297");
- }
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (錯誤)
- ocpp_set_stopReason_by_cmd(gun_index, "EVDisconnected");
- ChargingAlarmProcess(gun_index);
- }
- else if (isEvBoardNormalStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (正常)
- ocpp_set_stopReason_by_cmd(gun_index, "EVDisconnected");
- ChargingTerminalProcess(gun_index);
- }
- else if (ocpp_chk_remoteStop_cmd(gun_index) == YES ||
- WifiScheduleStop(gun_index) ||
- CheckBackendChargingTimeout(gun_index) ||
- CheckBackendChargingEnergy(gun_index) ||
- (ocpp_is_resPass_StartTransationConf(gun_index) && ocpp_chk_invalid_id_cmd(gun_index)))
- {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // LCM => Charging
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
- if (!stopChargingChkByCard)
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_ALARM:
- case S_TERMINATING:
- {
- if (isModeChange(gun_index))
- {
- ocpp_set_stopReason_by_cmd(gun_index, "Local");
- if (chargingInfo[gun_index]->SystemStatus == S_ALARM)
- {
- PRINTF_FUNC("================== S_ALARM (%x) ================ \n", gun_index);
- if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL)
- {
- ocpp_auto_response_StartTransationConf(gun_index);
- ocpp_set_stopTransation_cmd(gun_index);
- }
- TheEndCharging(gun_index);
- }
- else
- {
- ocpp_set_errCode_cmd(gun_index);
- PRINTF_FUNC("================== S_TERMINATING (%x) ================ \n", gun_index);
- }
- StopGunInfoTimeoutDet(gun_index);
- }
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012234");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordAlarmCode(gun_index, "012296");
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- //PRINTF_FUNC("************ GB lock Status = %d, status = %d \n", isEvStopCharging_gb(gun_index), isPrechargeStatus_gb(gun_index));
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012236");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordAlarmCode(gun_index, "012298");
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordAlarmCode(gun_index, "012297");
- }
- }
- if (chargingInfo[gun_index]->SystemStatus == S_ALARM)
- {
- if(chargingInfo[gun_index]->ConnectorPlugIn == NO &&
- GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
- //if(GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
- {
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- else
- {
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- if (isEvStopCharging_chademo(gun_index) == YES ||
- isPrechargeStatus_chademo(gun_index) <= 0)
- {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- if (isEvStopCharging_gb(gun_index) == YES ||
- isPrechargeStatus_gb(gun_index) <= 0)
- {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- {
- if (isEvStopCharging_ccs(gun_index) == YES &&
- (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
- isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14))
- {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- }
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_COMPLETE:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== S_COMPLETE (%x) ================ \n", gun_index);
- if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL)
- {
- ocpp_set_errCode_cmd(gun_index);
- ocpp_auto_response_StartTransationConf(gun_index);
- ocpp_set_stopTransation_cmd(gun_index);
- }
- TheEndCharging(gun_index);
- }
- if(chargingInfo[gun_index]->ConnectorPlugIn == NO &&
- GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
- //if(GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
- {
- setChargerMode(gun_index, MODE_IDLE);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- }
- break;
- case S_CCS_PRECHARGE_ST0:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== S_CCS_PRECHARGE_ST0 (%x) ================ \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (錯誤)
- ChargingAlarmProcess(gun_index);
- }
- else if (isEvBoardNormalStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (正常)
- ChargingTerminalProcess(gun_index);
- }
- else if (ocpp_chk_remoteStop_cmd(gun_index) == YES ||
- WifiScheduleStop(gun_index))
- {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // 等待 EV 小板 (CCS) 通知可以開始 Precharge
- // 切換 D+ Relay to Precharge Relay
- if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40)
- {
- if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
- //if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
- {
- if (isPrechargeStatus_ccs(gun_index) == 39)
- PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
- else if (isPrechargeStatus_ccs(gun_index) == 40)
- PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
- chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
- }
- }
- else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46)
- {
- setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- break;
- }
- case S_CCS_PRECHARGE_ST1:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("================== S_CCS_PRECHARGE_ST1 (%x) ================ \n", gun_index);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (錯誤)
- ChargingAlarmProcess(gun_index);
- }
- else if (isEvBoardNormalStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止 (正常)
- ChargingTerminalProcess(gun_index);
- }
- else if (ocpp_chk_remoteStop_cmd(gun_index) == YES ||
- WifiScheduleStop(gun_index))
- {
- // 後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // 等待小板通知進入充電
- // 切換 D+ Relay to Precharge Relay
- if (chargingInfo[gun_index]->RelayK1K2Status == YES)
- {
- chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
- setChargerMode(gun_index, MODE_CHARGING);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- break;
- }
- }
- }
- if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE)
- {
- ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
- }
- else
- {
- bool dcPageRun = false;
- if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
- {
- if (ac_chargingInfo[0]->SystemStatus == S_IDLE)
- ChangeLcmByIndex(_LCM_IDLE);
- else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING)
- ChangeLcmByIndex(_LCM_PRE_CHARGE);
- else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING)
- ChangeLcmByIndex(_LCM_CHARGING);
- else if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING ||
- ac_chargingInfo[0]->SystemStatus == S_COMPLETE)
- ChangeLcmByIndex(_LCM_COMPLETE);
- else
- dcPageRun = true;
- }
- else
- dcPageRun = true;
- if (dcPageRun)
- ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- AlarmCheck(chargingInfo[gun_index]->Type);
- write(wtdFd, "a", 1);
- usleep(whileLoopTime);
- }
- return FAIL;
- }
|