ReadCmdline.c 218 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599
  1. /*
  2. * Main.c
  3. *
  4. * Created on: 2019年8月6日
  5. * Author: 7564
  6. */
  7. #include <sys/time.h>
  8. #include <sys/timeb.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/types.h>
  12. #include <sys/ioctl.h>
  13. #include <sys/socket.h>
  14. #include <sys/ipc.h>
  15. #include <sys/shm.h>
  16. #include <sys/shm.h>
  17. #include <sys/mman.h>
  18. #include <linux/wireless.h>
  19. #include <arpa/inet.h>
  20. #include <netinet/in.h>
  21. #include <unistd.h>
  22. #include <stdarg.h>
  23. #include <stdio.h> /*標準輸入輸出定義*/
  24. #include <stdlib.h> /*標準函數庫定義*/
  25. #include <unistd.h> /*Unix 標準函數定義*/
  26. #include <fcntl.h> /*檔控制定義*/
  27. #include <termios.h> /*PPSIX 終端控制定義*/
  28. #include <errno.h> /*錯誤號定義*/
  29. #include <errno.h>
  30. #include <string.h>
  31. #include <time.h>
  32. #include <ctype.h>
  33. #include <ifaddrs.h>
  34. #include <math.h>
  35. #include <stdbool.h>
  36. #include "../../define.h"
  37. #include "Config.h"
  38. #include "Module_EvComm.h"
  39. #include "Common.h"
  40. typedef unsigned char byte;
  41. #define NO_DEFINE 255
  42. #define OPTION_CNT 4
  43. #define STR_OPTION '-'
  44. #define OPTION_REFLASH 0x00000001
  45. #define OPTION_LOOP 0x00000002
  46. #define OPTION_OUTPUT_FILE 0x00000004
  47. #define OPTION_TIME 0x00000008
  48. #define MAX_SUB_CMD_QUANTITY 16
  49. #define MAX_SUB_CMD_LENGTH 128
  50. #define STR_OPT_REFLASH 'f'
  51. #define STR_OPT_LOOP 'l'
  52. #define STR_OPT_OUTPUT_FILE 'o'
  53. #define STR_OPT_TIME 't'
  54. #define TTY_PATH "/dev/tty"
  55. #define STTY_US "stty raw -echo -F "
  56. #define STTY_DEF "stty -raw echo -F "
  57. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  58. struct StatusCodeData *ShmStatusCodeData;
  59. struct PrimaryMcuData *ShmPrimaryMcuData;
  60. struct CHAdeMOData *ShmCHAdeMOData;
  61. struct CcsData *ShmCcsData;
  62. struct GBTData *ShmGBTData;
  63. struct FanModuleData *ShmFanModuleData;
  64. struct RelayModuleData *ShmRelayModuleData;
  65. struct LedModuleData *ShmLedModuleData;
  66. struct PsuData *ShmPsuData;
  67. ChargerInfoData *ShmChargerInfo;
  68. PsuPositionInfoData *ShmPsuPosition;
  69. PsuGroupingInfoData *ShmPsuGrouping;
  70. struct OCPP16Data *ShmOCPP16Data;
  71. struct OCPP20Data *ShmOCPP20Data;
  72. struct ChargingInfoData *_chargingData[CONNECTOR_QUANTITY];
  73. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  74. char MultiSubCmd[MAX_SUB_CMD_QUANTITY][MAX_SUB_CMD_LENGTH];
  75. int totalSubCnt = 0;
  76. char *msg = "state : get gun state (index) \n"
  77. "card : scanning card (x) : \n"
  78. "gun : get gun plugit state (index) \n"
  79. "lock : get gun locked state (index) \n"
  80. "self : self test state (x) \n"
  81. "ver : ver of board (407 or index or rb or fan) \n"
  82. "ac : get ac relay state (x) \n"
  83. "gunchg: set gun start charging \n"
  84. "gunstp: set gun stop charging \n"
  85. "gunext: extend gun capability \n";
  86. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  87. {
  88. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  89. {
  90. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  91. {
  92. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  93. return true;
  94. }
  95. }
  96. for (byte index = 0; index < CCS_QUANTITY; index++)
  97. {
  98. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  99. {
  100. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  101. return true;
  102. }
  103. }
  104. for (byte index = 0; index < GB_QUANTITY; index++)
  105. {
  106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  107. {
  108. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  109. return true;
  110. }
  111. }
  112. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  113. {
  114. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  115. return true;
  116. }
  117. return false;
  118. }
  119. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  120. {
  121. if (target < AC_QUANTITY)
  122. {
  123. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  124. return true;
  125. }
  126. return false;
  127. }
  128. int InitShareMemory()
  129. {
  130. int result = PASS;
  131. int MeterSMId;
  132. //initial ShmSysConfigAndInfo
  133. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  134. {
  135. result = FAIL;
  136. }
  137. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  138. {
  139. result = FAIL;
  140. }
  141. else
  142. {}
  143. //initial ShmStatusCodeData
  144. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  145. {
  146. result = FAIL;
  147. }
  148. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  149. {
  150. result = FAIL;
  151. }
  152. else
  153. {}
  154. if (CHAdeMO_QUANTITY > 0) {
  155. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  156. IPC_CREAT | 0777)) < 0) {
  157. result = FAIL;
  158. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  159. == (void *) -1) {
  160. result = FAIL;
  161. } else {
  162. }
  163. }
  164. if (CCS_QUANTITY > 0) {
  165. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  166. IPC_CREAT | 0777)) < 0) {
  167. result = FAIL;
  168. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  169. result = FAIL;
  170. } else {
  171. }
  172. }
  173. if (GB_QUANTITY > 0) {
  174. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  175. IPC_CREAT | 0777)) < 0) {
  176. return 0;
  177. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  178. return 0;
  179. }
  180. memset(ShmGBTData, 0, sizeof(struct GBTData));
  181. }
  182. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  183. {
  184. result = FAIL;
  185. }
  186. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  187. {
  188. result = FAIL;
  189. }
  190. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  191. {
  192. result = FAIL;
  193. }
  194. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  195. {
  196. result = FAIL;
  197. }
  198. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  199. {
  200. result = FAIL;
  201. }
  202. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  203. {
  204. result = FAIL;
  205. }
  206. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  207. {
  208. result = FAIL;
  209. }
  210. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  211. {
  212. result = FAIL;
  213. }
  214. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  215. {
  216. result = FAIL;
  217. }
  218. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  219. {
  220. result = FAIL;
  221. }
  222. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
  223. {
  224. result = FAIL;
  225. }
  226. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  227. {
  228. result = FAIL;
  229. }
  230. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  231. {
  232. result = FAIL;
  233. }
  234. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  235. {
  236. result = FAIL;
  237. }
  238. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  239. {
  240. result = FAIL;
  241. }
  242. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  243. {
  244. result = FAIL;
  245. }
  246. if(result == PASS)
  247. {
  248. ShmPsuPosition = &ShmChargerInfo->PsuPosition;
  249. ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
  250. }
  251. return result;
  252. }
  253. void Get_Ocpp_TransactionId(int gun_index, char *transactionId)
  254. {
  255. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  256. {
  257. sprintf(transactionId, "%d", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  258. return;
  259. }
  260. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  261. {
  262. strcpy(transactionId, (char *)&ShmOCPP20Data->TransactionEvent [gun_index].transactionInfo.transactionId[0]);
  263. return;
  264. }
  265. sprintf(transactionId, "%d", 0);
  266. }
  267. static void get_char(char *word)
  268. {
  269. fd_set rfds;
  270. struct timeval tv;
  271. FD_ZERO(&rfds);
  272. FD_SET(0, &rfds);
  273. tv.tv_sec = 0;
  274. tv.tv_usec = 10; //wait input timout time
  275. //if input
  276. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  277. {
  278. fgets(word, 128, stdin);
  279. }
  280. }
  281. // return command length
  282. int ParsingCmd(char *inputString, char *outputString)
  283. {
  284. bool valid = false, done = false;
  285. int len = 0, start = 0;
  286. for(int i = 0; i < strlen(inputString); i++)
  287. {
  288. if(!valid)
  289. {
  290. if(inputString[i] != ' ' && inputString[i] != '\0' && inputString[i] != '\r' && inputString[i] != '\n')
  291. {
  292. valid = true;
  293. start = i;
  294. }
  295. }
  296. else
  297. {
  298. if(inputString[i] == ' ' || inputString[i] == '\0' || inputString[i] == '\r' || inputString[i] == '\n' || len >= MAX_SUB_CMD_LENGTH)
  299. {
  300. done = true;
  301. break;
  302. }
  303. }
  304. len = (valid && !done) ? len + 1 : len;
  305. }
  306. if(valid)
  307. {
  308. memcpy(outputString, &inputString[start], len);
  309. outputString[len] = '\0';
  310. }
  311. return len;
  312. }
  313. bool IsOption(char *strCmd, unsigned int *opt)
  314. {
  315. int len = 0;
  316. char str_opt[OPTION_CNT] = {STR_OPT_REFLASH, STR_OPT_LOOP, STR_OPT_OUTPUT_FILE, STR_OPT_TIME};
  317. unsigned int opt_value[OPTION_CNT] = {OPTION_REFLASH, OPTION_LOOP, OPTION_OUTPUT_FILE, OPTION_TIME};
  318. len = strlen(strCmd);
  319. if(len == 2)
  320. {
  321. if(strCmd[0] == STR_OPTION)
  322. {
  323. for(int i = 0; i < OPTION_CNT; i++)
  324. {
  325. if(strCmd[1] == str_opt[i])
  326. {
  327. *opt |= opt_value[i];
  328. return true;
  329. }
  330. }
  331. }
  332. }
  333. return false;
  334. }
  335. // inputCmdString: console input string
  336. // outputCmdString: input string parsed
  337. // return command quantity
  338. int InputStringNormalize(char *inputCmdString, char *outputCmdString, unsigned int *opt)
  339. {
  340. int len = 0, cnt = 0, start = 0;
  341. int cmdLen = 0, totalLen = 0;
  342. len = strlen(inputCmdString);
  343. *opt = 0;
  344. if(len > 0)
  345. {
  346. while(start < len)
  347. {
  348. if(inputCmdString[start] != ' ' && inputCmdString[start] != '\0' &&
  349. inputCmdString[start] != '\r' && inputCmdString[start] != '\n')
  350. {
  351. cmdLen = ParsingCmd(&inputCmdString[start], &outputCmdString[totalLen]);
  352. if(cmdLen > 0)
  353. {
  354. //printf("Find %d Cmd: %s\r\n", cnt + 1, &outputCmdString[totalLen]);
  355. if(!IsOption(&outputCmdString[totalLen], opt))
  356. {
  357. outputCmdString[totalLen + cmdLen] = ' ';
  358. cnt++;
  359. totalLen += cmdLen + 1;
  360. }
  361. start += cmdLen;
  362. }
  363. }
  364. else
  365. {
  366. start++;
  367. }
  368. }
  369. outputCmdString[totalLen - 1] = '\0';
  370. }
  371. return cnt;
  372. }
  373. int MainAndSubCommandParsing(char *normalCmd, char *mainCmd, char *subCmd)
  374. {
  375. int len = 0, totalLen = 0;
  376. int quantity = 0;
  377. strcpy(mainCmd, "");
  378. strcpy(subCmd, "");
  379. totalLen = strlen(normalCmd);
  380. if(totalLen > 0)
  381. {
  382. len = ParsingCmd(normalCmd, mainCmd);
  383. //printf("Find MainCmd: %s\r\n", mainCmd);
  384. quantity = len > 0 ? (quantity + 1) : quantity;
  385. if(len > 0 && totalLen > len)
  386. {
  387. strcpy(subCmd, &normalCmd[len + 1]);
  388. //printf("Find SubCmd: %s\r\n", subCmd);
  389. len = strlen(subCmd);
  390. quantity = len > 0 ? (quantity + 1) : quantity;
  391. }
  392. }
  393. return quantity;
  394. }
  395. int GetCommandSring(char *outputCmdString)
  396. {
  397. int len = 0, cnt = 0;
  398. int cmdLen = 0, totalLen = 0;
  399. char word[128];
  400. memset(word, 0x00, sizeof(word));
  401. get_char(word);
  402. len = strlen(word);
  403. if(len == 0)
  404. {
  405. return -1;
  406. }
  407. int start = 0;
  408. while(start < len - 1)
  409. {
  410. if(word[start] != ' ' && word[start] != '\0')
  411. {
  412. cmdLen = ParsingCmd(&word[start], &outputCmdString[totalLen]);
  413. char newCmd[MAX_SUB_CMD_LENGTH];
  414. memset(newCmd, 0x00, MAX_SUB_CMD_LENGTH);
  415. memcpy(newCmd, &outputCmdString[totalLen], cmdLen);
  416. cnt = cmdLen > 0 ? cnt + 1 : cnt;
  417. totalLen += cmdLen + 1;
  418. start += cmdLen;
  419. }
  420. else
  421. {
  422. start++;
  423. }
  424. }
  425. return cnt;
  426. }
  427. bool IsLoopStopCmd(void)
  428. {
  429. bool stop = false;
  430. int cnt = 0;
  431. char cmd[256];
  432. char totalCmd[256];
  433. memset(cmd, 0x00, 256);
  434. memset(totalCmd, 0x00, 256);
  435. cnt = GetCommandSring(totalCmd);
  436. if(cnt > 0)
  437. {
  438. strcpy(&cmd[0], totalCmd);
  439. if(strcmp(&cmd[0], "c") == 0)
  440. {
  441. stop = true;
  442. }
  443. }
  444. return stop;
  445. }
  446. void ConsoleReflash(int groupCnt, int lineCnt)
  447. {
  448. for(int i = 0; i < groupCnt; i++)
  449. {
  450. for(int i = 0; i < lineCnt; i++)
  451. {
  452. printf("\033[1A");
  453. printf("\033[K");
  454. }
  455. }
  456. printf("\r");
  457. }
  458. int GetSubCommand(char *inputCmd)
  459. {
  460. unsigned int paraOpt = 0;
  461. int loopLimit = 0;
  462. char normalString[128];
  463. totalSubCnt = InputStringNormalize(inputCmd, normalString, &paraOpt);
  464. if(totalSubCnt > MAX_SUB_CMD_QUANTITY)
  465. {
  466. totalSubCnt = MAX_SUB_CMD_QUANTITY;
  467. }
  468. if(totalSubCnt > 0)
  469. {
  470. loopLimit = totalSubCnt > 1 ? totalSubCnt - 1 : 1;
  471. for(int i = 0; i < loopLimit; i++)
  472. {
  473. memset(&MultiSubCmd[i][0], 0x00, MAX_SUB_CMD_LENGTH);
  474. memset(&MultiSubCmd[i + 1][0], 0x00, MAX_SUB_CMD_LENGTH);
  475. MainAndSubCommandParsing(normalString, &MultiSubCmd[i][0], &MultiSubCmd[i + 1][0]);
  476. strcpy(normalString, &MultiSubCmd[i + 1][0]);
  477. }
  478. }
  479. return totalSubCnt;
  480. }
  481. void RunStatusProc(char *v1, char *v2)
  482. {
  483. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  484. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  485. if (strcmp(v1, "ac") == 0)
  486. {
  487. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  488. {
  489. printf("FindChargingInfoData (AC) false \n");
  490. }
  491. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  492. return;
  493. }
  494. int _index = atoi(v1);
  495. if (_index <= 3)
  496. {
  497. if (!FindChargingInfoData(_index, &_chargingData[0]))
  498. {
  499. printf ("FindChargingInfoData error\n");
  500. return;
  501. }
  502. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  503. {
  504. // get
  505. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  506. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  507. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  508. printf("ConnectorAlarmCode = %s \n", _chargingData[_index]->ConnectorAlarmCode);
  509. printf("EvConnAlarmCode = %s \n", _chargingData[_index]->EvConnAlarmCode);
  510. printf("RemotenAlarmCode = %s \n", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].RemotenAlarmCode);
  511. }
  512. else
  513. {
  514. // set
  515. _chargingData[_index]->SystemStatus = atoi(v2);
  516. }
  517. }
  518. else
  519. {
  520. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  521. {
  522. printf("FindChargingInfoData (AC) false \n");
  523. }
  524. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  525. {
  526. // get
  527. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  528. }
  529. else
  530. {
  531. // set
  532. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  533. }
  534. }
  535. }
  536. void RunCardProc(char *v1, char *v2)
  537. {
  538. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  539. {
  540. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  541. {
  542. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  543. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  544. }
  545. else
  546. {
  547. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  548. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  549. }
  550. }
  551. else
  552. {
  553. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  554. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  555. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  556. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  557. }
  558. }
  559. void RunGunPlugitProc(char *v1, char *v2)
  560. {
  561. if (strcmp(v1, "ac") == 0)
  562. {
  563. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  564. {
  565. printf("FindChargingInfoData (AC) false \n");
  566. }
  567. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  568. {
  569. // get
  570. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  571. }
  572. else
  573. {
  574. // set
  575. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  576. }
  577. return;
  578. }
  579. int _index = atoi(v1);
  580. if (!FindChargingInfoData(_index, &_chargingData[0]))
  581. {
  582. printf("FindChargingInfoData error\n");
  583. return;
  584. }
  585. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  586. {
  587. // get
  588. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  589. }
  590. else
  591. {
  592. // set
  593. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  594. }
  595. }
  596. void GetGunLockStatusProc(char *v1, char *v2)
  597. {
  598. int _index = atoi(v1);
  599. if (!FindChargingInfoData(_index, &_chargingData[0]))
  600. {
  601. printf("FindChargingInfoData error\n");
  602. return;
  603. }
  604. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  605. {
  606. _chargingData[_index]->GunLocked = atoi(v2);
  607. }
  608. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  609. }
  610. void SetSystemIDProc()
  611. {
  612. char *systemId = "Alston_Test";
  613. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  614. }
  615. void RunSelfProc()
  616. {
  617. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  618. }
  619. void ShowCabinetVer(void)
  620. {
  621. printf("Power Cabinet, Model Name: %s, SN: %s\r\n", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  622. printf(" Csu Bootload: %s\r\n", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
  623. printf(" Csu Kernel: ");
  624. for(int i = 0; i < strlen((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev); i++)
  625. {
  626. if(ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\r' && ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\n')
  627. {
  628. printf("%c", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i]);
  629. }
  630. }
  631. printf("\r\n");
  632. printf(" Csu Root Fs: %s [%s]\r\n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, ShmChargerInfo->SysMisc.SubVersion);
  633. printf(" Csu Primary: %s\r\n", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
  634. printf(" Fan Module: %s\r\n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  635. printf(" Relay1 Module: %s\r\n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  636. printf(" Relay2 Module: %s\r\n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  637. }
  638. void ShowDispenserVer(int DispenserIndex)
  639. {
  640. printf("Dispenser %d Status: %d", DispenserIndex + 1, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].LocalStatus);
  641. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].LocalStatus != _DS_None &&
  642. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].LocalStatus != _DS_Timeout)
  643. {
  644. printf(", Model Name: %s\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].ModelName);
  645. printf(" Csu Bootload: %s\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].CsuBootLoadFwRev);
  646. printf(" Csu Kernel: ");
  647. for(int i = 0; i < strlen((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].CsuKernelFwRev); i++)
  648. {
  649. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].CsuKernelFwRev[i] != '\r' &&
  650. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].CsuKernelFwRev[i] != '\n')
  651. {
  652. printf("%c", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].CsuKernelFwRev[i]);
  653. }
  654. }
  655. printf("\r\n");
  656. printf(" Csu Root Fs: %s\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].CsuRootFsFwRev);
  657. printf(" Csu Primary: %s\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].CsuPrimFwRev);
  658. printf(" Fan Module: %s\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].FanModuleFwRev);
  659. printf(" Relay Module: %s\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].RelayModuleFwRev);
  660. printf(" Connector 1: %s\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].Connector1FwRev);
  661. printf(" Connector 2: %s\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].Connector2FwRev);
  662. printf(" Led Module: %s\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].LedModuleFwRev);
  663. }
  664. else
  665. {
  666. printf("\r\n");
  667. }
  668. }
  669. void ShowAllVer(void)
  670. {
  671. ShowCabinetVer();
  672. printf("\r\n");
  673. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  674. {
  675. ShowDispenserVer(i);
  676. printf("\r\n");
  677. }
  678. }
  679. void ShowFwVer(char *inputCmd, unsigned int opt)
  680. {
  681. int totalCnt = 0, maxPara = 0, dispenser = 0;
  682. maxPara = 2;
  683. totalCnt = GetSubCommand(inputCmd);
  684. printf("\r\n");
  685. if(totalCnt > maxPara)
  686. {
  687. printf("Input cmd fail ------ ver [all | cabinet | dispenser] [...]\r\n\r\n");
  688. return;
  689. }
  690. if(totalCnt == 0)
  691. {
  692. ShowAllVer();
  693. return;
  694. }
  695. else if(totalCnt == 1)
  696. {
  697. if(strcmp(&MultiSubCmd[0][0], "all") == 0)
  698. {
  699. ShowAllVer();
  700. return;
  701. }
  702. else if(strcmp(&MultiSubCmd[0][0], "cabinet") == 0)
  703. {
  704. ShowCabinetVer();
  705. printf("\r\n");
  706. return;
  707. }
  708. }
  709. else if(totalCnt == 2)
  710. {
  711. dispenser = atoi(&MultiSubCmd[1][0]);
  712. if(strcmp(&MultiSubCmd[0][0], "dispenser") == 0)
  713. {
  714. if(dispenser > 0 && dispenser <= MAX_DISPENSER_QUANTITY)
  715. {
  716. ShowDispenserVer(dispenser - 1);
  717. printf("\r\n");
  718. return;
  719. }
  720. printf("Input cmd fail ------ ver [dispenser] [id 1-%d]\r\n\r\n", MAX_DISPENSER_QUANTITY);
  721. return;
  722. }
  723. printf("Input cmd fail ------ ver [dispenser] [id]\r\n\r\n");
  724. return;
  725. }
  726. printf("Input cmd fail ------ ver [all | cabinet | dispenser] [...]\r\n\r\n");
  727. }
  728. void GetFwVerProc(char *v1)
  729. {
  730. if (strcmp(v1, "407") == 0)
  731. {
  732. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  733. }
  734. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0 || strcmp(v1, "2") == 0 || strcmp(v1, "3") == 0)
  735. {
  736. int _index = atoi(v1);
  737. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Enable)
  738. {
  739. int dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].ParentDispensetIndex;
  740. int ParentIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].GeneralChargingData.Index;
  741. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  742. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  743. {
  744. if(ParentIndex == 0)
  745. {
  746. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  747. }
  748. else
  749. {
  750. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  751. }
  752. }
  753. }
  754. else
  755. {
  756. printf("Gun %d is disable\r\n", _index);
  757. }
  758. }
  759. else if (strcmp(v1, "rb") == 0)
  760. {
  761. printf("RB1 Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  762. printf("RB2 Version = %s \n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  763. }
  764. else if (strcmp(v1, "fan") == 0)
  765. {
  766. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  767. }
  768. else if (strcmp(v1, "dc") == 0)
  769. {
  770. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  771. }
  772. else if (strcmp(v1, "led") == 0)
  773. {
  774. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  775. }
  776. }
  777. void CreateOneError(char *v1)
  778. {
  779. int value = atoi(v1);
  780. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
  781. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  782. }
  783. void GetAuthorizeFlag(char *v1)
  784. {
  785. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  786. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  787. else
  788. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  789. }
  790. void GetOrClearId(char *v1)
  791. {
  792. int _index = atoi(v1);
  793. if (!FindChargingInfoData(_index, &_chargingData[0]))
  794. {
  795. printf("FindChargingInfoData error\n");
  796. return;
  797. }
  798. printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
  799. }
  800. void FwUpdateFlagProc(char *inputCmd, unsigned int opt)
  801. {
  802. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  803. }
  804. void CheckAcStatus(char *v1)
  805. {
  806. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  807. {
  808. printf(" AC Contactor Ctrl: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactor);
  809. printf(" AC Off By Psu : %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu);
  810. printf(" AC Off ByEmergency: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency);
  811. printf("AC Contactor Status: %d\r\n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  812. }
  813. else
  814. {
  815. if(system("pidof -s main > /dev/null") != 0)
  816. {
  817. if(strcmp(v1, "0") == 0)
  818. {
  819. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = false;
  820. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  821. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  822. printf("Set AC Contactor Off\r\n");
  823. }
  824. else
  825. {
  826. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = true;
  827. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  828. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  829. printf("Set AC Contactor On\r\n");
  830. }
  831. }
  832. else
  833. {
  834. printf("main task is running\r\n");
  835. }
  836. }
  837. }
  838. void SetCableChkStatus(char *v1, char *v2)
  839. {
  840. int _index = atoi(v1);
  841. if (!FindChargingInfoData(_index, &_chargingData[0]))
  842. {
  843. printf ("FindChargingInfoData error\n");
  844. return;
  845. }
  846. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  847. }
  848. void SetPowerValue(char *v1, char *v2)
  849. {
  850. int _index = atoi(v1);
  851. float _Current = atof(v2);
  852. // 盲沖的時候才允許使用~
  853. if (_chargingData[_index]->Type != 9)
  854. return;
  855. if (!FindChargingInfoData(_index, &_chargingData[0]))
  856. {
  857. printf ("FindChargingInfoData error\n");
  858. return;
  859. }
  860. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  861. }
  862. void GetSystemInfo(void)
  863. {
  864. printf ("Power Cabinet\r\n");
  865. printf (" -System ID: [%s]\r\n", (char *)&ShmSysConfigAndInfo->SysConfig.SystemId);
  866. printf (" -ModelName: [%s], SerialNumber: [%s]\r\n",
  867. (char *)&ShmSysConfigAndInfo->SysConfig.ModelName,
  868. (char *)&ShmSysConfigAndInfo->SysConfig.SerialNumber);
  869. printf (" -CSURootFs: %s [%s]\r\n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, ShmChargerInfo->SysMisc.SubVersion);
  870. }
  871. bool SetModelName(char *modelName);
  872. void ModelNameCmd(char *inputCmd, unsigned int opt)
  873. {
  874. int totalCnt = 0, maxPara = 0;
  875. maxPara = 2;
  876. totalCnt = GetSubCommand(inputCmd);
  877. printf("\r\n");
  878. if(totalCnt == 0)
  879. {
  880. GetSystemInfo();
  881. printf("\r\n");
  882. return;
  883. }
  884. if(totalCnt != maxPara || strcmp(&MultiSubCmd[0][0], "set") != EQUAL)
  885. {
  886. printf("Input cmd fail ------ model [set] [model name]\r\n\r\n");
  887. return;
  888. }
  889. if(SetModelName(&MultiSubCmd[0][0]))
  890. {
  891. printf("\r\n");
  892. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  893. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  894. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset = true;
  895. }
  896. }
  897. bool SetSerialNumber(char *serialNumber);
  898. void SerialNumberCmd(char *inputCmd, unsigned int opt)
  899. {
  900. int totalCnt = 0, maxPara = 0;
  901. maxPara = 2;
  902. totalCnt = GetSubCommand(inputCmd);
  903. printf("\r\n");
  904. if(totalCnt != maxPara || strcmp(&MultiSubCmd[0][0], "set") != EQUAL)
  905. {
  906. printf("Input cmd fail ------ model [set] [serial number]\r\n\r\n");
  907. return;
  908. }
  909. if(SetSerialNumber(&MultiSubCmd[1][0]))
  910. {
  911. printf("\r\n");
  912. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  913. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  914. }
  915. }
  916. void SetFanSpeed(char *v1)
  917. {
  918. int speed = atoi(v1);
  919. ShmFanModuleData->TestFanSpeed = speed;
  920. }
  921. void SetDebugMode(char *v1)
  922. {
  923. int mode = atoi(v1);
  924. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  925. }
  926. void SetGFDMode(char *v1)
  927. {
  928. int mode = atoi(v1);
  929. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  930. }
  931. // PSU 0 PSU 1 PSU 2 ...
  932. // Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb
  933. // 1 XXX XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX
  934. void GetTemperature(char *inputCmd, unsigned int opt)
  935. {
  936. bool keepRun = false;
  937. bool reflash = false;
  938. int time = 0;
  939. struct timespec _Loop_time;
  940. char strGunTemp[16], strChillerTemp[16];
  941. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  942. {
  943. keepRun = true;
  944. }
  945. printf("\r\n");
  946. printf(" PSU 0 PSU 1 PSU 2 .....\r\n");
  947. printf(" Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb\r\n");
  948. do
  949. {
  950. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  951. if(time >= 1000)
  952. {
  953. if(reflash)
  954. {
  955. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  956. }
  957. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  958. {
  959. sprintf(strGunTemp, "N/A");
  960. sprintf(strChillerTemp, "N/A");
  961. if(_chargingData[i]->ConnectorTemp != 0 && _chargingData[i]->ConnectorTemp != 0xFF)
  962. {
  963. int _connectorTemp = (int)_chargingData[i]->ConnectorTemp - 60;
  964. sprintf(strGunTemp, "%3d", _connectorTemp);
  965. }
  966. if(_chargingData[i]->ChillerTemp != 0 && _chargingData[i]->ChillerTemp != 0xFF)
  967. {
  968. int _chillerTemp = (int)_chargingData[i]->ChillerTemp - 60;
  969. sprintf(strChillerTemp, "%3d", _chillerTemp);
  970. }
  971. printf(" %d %s %s ", i + 1, strGunTemp, strChillerTemp);
  972. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  973. {
  974. int ExletTemp = (int)ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp - 60;
  975. int InletTemp = (int)ShmPsuData->PsuGroup[i].PsuModule[j].InletTemp - 60;
  976. int CriticalTemp1 = (int)ShmPsuData->PsuGroup[i].PsuModule[j].CriticalTemp1 - 60;
  977. printf(" %3d/%3d/%3d", ExletTemp, InletTemp, CriticalTemp1);
  978. }
  979. printf("\r\n");
  980. }
  981. GetClockTime(&_Loop_time);
  982. if((opt & OPTION_REFLASH) > 0)
  983. {
  984. reflash = true;
  985. }
  986. }
  987. if(keepRun)
  988. {
  989. keepRun = IsLoopStopCmd() ? false : true;
  990. usleep(10000);
  991. }
  992. }while(keepRun);
  993. printf("\r\n");
  994. }
  995. void GetInputVol(char *inputCmd, unsigned int opt)
  996. {
  997. bool keepRun = false;
  998. bool reflash = false;
  999. int time = 0;
  1000. struct timespec _Loop_time;
  1001. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  1002. {
  1003. keepRun = true;
  1004. }
  1005. printf("\r\n");
  1006. do
  1007. {
  1008. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  1009. if(time >= 1000)
  1010. {
  1011. if(reflash)
  1012. {
  1013. ConsoleReflash(1, 1);
  1014. }
  1015. printf("L1N_L12 = %4.1f V, L2N_L23 = %4.1f V, L3N_L31 = %4.1f V, DC Input: %4.1f V\r\n",
  1016. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  1017. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  1018. ShmSysConfigAndInfo->SysInfo.InputVoltageT,
  1019. ShmSysConfigAndInfo->SysInfo.InputVoltageDc);
  1020. GetClockTime(&_Loop_time);
  1021. if((opt & OPTION_REFLASH) > 0)
  1022. {
  1023. reflash = true;
  1024. }
  1025. }
  1026. if(keepRun)
  1027. {
  1028. keepRun = IsLoopStopCmd() ? false : true;
  1029. usleep(10000);
  1030. }
  1031. }while(keepRun);
  1032. printf("\r\n");
  1033. }
  1034. void GetConnectorCapInfo(char *v1)
  1035. {
  1036. int _GunIndex = atoi(v1);
  1037. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1038. {
  1039. printf ("FindChargingInfoData error\n");
  1040. return;
  1041. }
  1042. printf ("Charger Max Current = %d, Max Power = %d \n",
  1043. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  1044. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  1045. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  1046. _GunIndex,
  1047. _chargingData[_GunIndex]->RealMaxPower,
  1048. _chargingData[_GunIndex]->RealMaxVoltage,
  1049. _chargingData[_GunIndex]->RealMaxCurrent);
  1050. }
  1051. void SetWiringInfo(char *v1, char *v2)
  1052. {
  1053. int dispenser = atoi(v1);
  1054. int connector = atoi(v2);
  1055. if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
  1056. {
  1057. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
  1058. {
  1059. printf("\r\n");
  1060. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1061. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1062. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
  1063. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
  1064. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1065. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1066. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1067. }
  1068. else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
  1069. {
  1070. printf("\r\n");
  1071. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1072. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1073. int quantity = 0;
  1074. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1075. {
  1076. quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  1077. }
  1078. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
  1079. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1080. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1081. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1082. }
  1083. }
  1084. }
  1085. void ShowWiringInfo(void)
  1086. {
  1087. printf("\r\n");
  1088. printf("********** Wiring Info **********\r\n");
  1089. printf("Dispenser = %d, Connector = %d\r\n",
  1090. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
  1091. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
  1092. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
  1093. {
  1094. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1095. {
  1096. printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
  1097. }
  1098. }
  1099. printf("\r\n");
  1100. }
  1101. void CleanWiringInfo(void)
  1102. {
  1103. printf("\r\n");
  1104. printf("******* Clean Wiring Info *******\r\n");
  1105. memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
  1106. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1107. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  1108. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset = true;
  1109. printf("\r\n");
  1110. }
  1111. void SetSystemSoftRest(void)
  1112. {
  1113. printf("\r\n");
  1114. printf("********* Set Soft Reset ********\r\n\r\n");
  1115. ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
  1116. }
  1117. void SetSystemHardReboot(void)
  1118. {
  1119. printf("\r\n");
  1120. printf("******** Set Hard Reboot ********\r\n\r\n");
  1121. ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
  1122. }
  1123. void SetGroupRole(byte group, byte role)
  1124. {
  1125. if(group < GENERAL_GUN_QUANTITY)
  1126. {
  1127. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != role)
  1128. {
  1129. //printf("\r\nSet Group %d Role = %d", group, role);
  1130. }
  1131. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role = role;
  1132. }
  1133. }
  1134. void SetGroupToIdle(byte group)
  1135. {
  1136. if(group < GENERAL_GUN_QUANTITY)
  1137. {
  1138. SetGroupRole(group, _GROLE_IDLE);
  1139. ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity = 0;
  1140. memset(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1141. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = 0;
  1142. //printf("\r\n Reset Group %02X To Idle", group);
  1143. }
  1144. }
  1145. void SetGroupToMaster(byte group)
  1146. {
  1147. if(group < GENERAL_GUN_QUANTITY)
  1148. {
  1149. SetGroupRole(group, _GROLE_MASTER);
  1150. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = group + 1;
  1151. //printf("\r\n Set Group %02X As Master", group);
  1152. }
  1153. }
  1154. void SetGroupToSlave(byte group, byte target)
  1155. {
  1156. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1157. {
  1158. SetGroupRole(group, _GROLE_SLAVE);
  1159. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = target + 1;
  1160. //printf("\r\n Set Group %02X As Slave", group);
  1161. }
  1162. }
  1163. // group: group index, target: target index
  1164. // add group to target's member
  1165. void AddGroupCollection(byte group, byte target)
  1166. {
  1167. int ParallelConfig = 0;
  1168. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1169. {
  1170. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role != _GROLE_MASTER)
  1171. {
  1172. return;
  1173. }
  1174. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE &&
  1175. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_WAIT_IDLE &&
  1176. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_PRECHARGE_READY)
  1177. {
  1178. return;
  1179. }
  1180. SetGroupToSlave(group, target);
  1181. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity++] = group;
  1182. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1183. if(ParallelConfig != 0)
  1184. {
  1185. ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
  1186. }
  1187. //printf("\r\n Add Group %02X To Gun %d (Quantity %d), Set Parallel Relay %d On", group, target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ParallelConfig);
  1188. }
  1189. }
  1190. // group: group index, target: target index
  1191. // remove group out of target's member
  1192. void RemoveGroupCollection(byte group, byte target)
  1193. {
  1194. int location = 0, slave = 0;
  1195. bool find = false;
  1196. int ParallelConfig = 0;
  1197. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1198. {
  1199. for(int i = 0; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1200. {
  1201. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i])
  1202. {
  1203. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1204. location = i;
  1205. find = true;
  1206. break;
  1207. }
  1208. }
  1209. if(find)
  1210. {
  1211. for(int i = location + 1; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1212. {
  1213. slave = ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i];
  1214. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1215. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i - 1] = slave;
  1216. }
  1217. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity--;
  1218. SetGroupToIdle(group);
  1219. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1220. if(ParallelConfig != 0)
  1221. {
  1222. ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
  1223. }
  1224. //printf("\r\n Remove Group %02X From Gun %d (Quantity %d), Clean Parallel Relay %d Off", group, target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ParallelConfig);
  1225. }
  1226. }
  1227. }
  1228. int ShowSingleGroupingInfo(int gun)
  1229. {
  1230. printf(" %d (%2d) %2d %d %02X ",
  1231. gun + 1, _chargingData[gun]->SystemStatus, ShmChargerInfo->PsuGrouping.GroupCollection[gun].Role,
  1232. ShmChargerInfo->PsuGrouping.GroupCollection[gun].Partner.Quantity, ShmChargerInfo->PsuGrouping.GroupCollection[gun].TargetGroup);
  1233. for(int j = 0; j < 3; j++)
  1234. {
  1235. if(ShmChargerInfo->PsuGrouping.GroupCollection[gun].Role == 1 && j < ShmChargerInfo->PsuGrouping.GroupCollection[gun].Partner.Quantity)
  1236. {
  1237. printf("[%02X] ", ShmChargerInfo->PsuGrouping.GroupCollection[gun].Partner.Member[j]);
  1238. }
  1239. else
  1240. {
  1241. printf(" ");
  1242. }
  1243. }
  1244. printf(" %4d V %4d A %4d kW %4d A %4d A ",
  1245. (int)_chargingData[gun]->PresentChargingVoltage, (int)_chargingData[gun]->PresentChargingCurrent,
  1246. (int)(_chargingData[gun]->AvailableChargingPower / 10), (int)(_chargingData[gun]->AvailableChargingCurrent / 10),
  1247. (int)(_chargingData[gun]->DeratingChargingCurrent / 10));
  1248. printf("%02X %02X",ShmPsuGrouping->OutputRelayConfig[gun].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
  1249. printf("\r\n");
  1250. return 1;
  1251. }
  1252. void ShowGroupingInfo(void)
  1253. {
  1254. int target = 0;
  1255. printf("\r\n");
  1256. printf(" Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay\r\n");
  1257. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  1258. {
  1259. target = ShmPsuGrouping->Layout[i];
  1260. ShowSingleGroupingInfo(target);
  1261. }
  1262. printf("\r\n");
  1263. }
  1264. // Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay
  1265. // 1 (00) 00 3 00 [00] [00] [00] 0000 V 0000 A 0000 kW 0000 A 0000 A 00 XX
  1266. void ShowGroupingCmd(char *inputCmd, unsigned int opt)
  1267. {
  1268. bool keepRun = false;
  1269. bool reflash = false;
  1270. int time = 0, target = 0;
  1271. struct timespec _Loop_time;
  1272. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  1273. {
  1274. keepRun = true;
  1275. }
  1276. printf("\r\n");
  1277. printf(" Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay\r\n");
  1278. do
  1279. {
  1280. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  1281. if(time >= 1000)
  1282. {
  1283. if(reflash)
  1284. {
  1285. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  1286. }
  1287. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  1288. {
  1289. target = ShmPsuGrouping->Layout[i];
  1290. ShowSingleGroupingInfo(target);
  1291. }
  1292. GetClockTime(&_Loop_time);
  1293. if((opt & OPTION_REFLASH) > 0)
  1294. {
  1295. reflash = true;
  1296. }
  1297. }
  1298. if(keepRun)
  1299. {
  1300. keepRun = IsLoopStopCmd() ? false : true;
  1301. usleep(10000);
  1302. }
  1303. }while(keepRun);
  1304. printf("\r\n");
  1305. }
  1306. void PsuGroupSwitchToIdle(byte group)
  1307. {
  1308. int master = 0, quantity = 0, location = 0, total = 0;
  1309. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_SLAVE)
  1310. {
  1311. return;
  1312. }
  1313. master = ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup - 1;
  1314. quantity = ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Quantity;
  1315. //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
  1316. for(int i = 0; i < quantity; i++)
  1317. {
  1318. if(total == 0)
  1319. {
  1320. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i])
  1321. {
  1322. location = i;
  1323. total++;
  1324. //printf("\r\n Find Group %02X At Member Index = %d", group, location);
  1325. }
  1326. }
  1327. else
  1328. {
  1329. // find other group in the same direction
  1330. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
  1331. {
  1332. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
  1333. {
  1334. total++;
  1335. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1336. }
  1337. }
  1338. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
  1339. {
  1340. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
  1341. {
  1342. total++;
  1343. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1344. }
  1345. }
  1346. }
  1347. }
  1348. if(total > 0)
  1349. {
  1350. unsigned char collection[GENERAL_GUN_QUANTITY];
  1351. //printf("\r\n There are %d Group Need To Switch Idle:", total);
  1352. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member));
  1353. for(int i = 0; i < total; i++)
  1354. {
  1355. //printf(" %02X", collection[i + location]);
  1356. }
  1357. for(int i = 0; i < total; i++)
  1358. {
  1359. RemoveGroupCollection(collection[i + location], master);
  1360. }
  1361. }
  1362. }
  1363. void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
  1364. {
  1365. int slave = 0, location = 0;
  1366. PsuGroupPartner partner;
  1367. memset(&partner, 0x00, sizeof(PsuGroupPartner));
  1368. // search from left
  1369. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location - 1;
  1370. for(int i = location; i >= 0; i--)
  1371. {
  1372. if(partner.Quantity >= quantity)
  1373. {
  1374. break;
  1375. }
  1376. slave = ShmPsuGrouping->Layout[i];
  1377. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1378. {
  1379. //printf("\r\n Find Group %02X From Left", slave);
  1380. partner.Member[partner.Quantity++] = slave;
  1381. }
  1382. else
  1383. {
  1384. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1385. {
  1386. continue;
  1387. }
  1388. break;
  1389. }
  1390. }
  1391. // search from right
  1392. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location + 1;
  1393. for(int i = location; i < 4; i++)
  1394. {
  1395. if(partner.Quantity >= quantity)
  1396. {
  1397. break;
  1398. }
  1399. slave = ShmPsuGrouping->Layout[i];
  1400. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1401. {
  1402. //printf("\r\n Find Group %02X From Right", slave);
  1403. partner.Member[partner.Quantity++] = slave;
  1404. }
  1405. else
  1406. {
  1407. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1408. {
  1409. continue;
  1410. }
  1411. break;
  1412. }
  1413. }
  1414. memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
  1415. }
  1416. int GetPsuGroupAvailable(byte group)
  1417. {
  1418. //int slave = 0, location = 0, available = 0;
  1419. PsuGroupPartner partner;
  1420. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1421. //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
  1422. return partner.Quantity;
  1423. #if 0
  1424. // search from left
  1425. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1426. for(int i = location; i >= 0; i--)
  1427. {
  1428. slave = ShmPsuGrouping->Layout[i];
  1429. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1430. {
  1431. available++;
  1432. }
  1433. else
  1434. {
  1435. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1436. {
  1437. continue;
  1438. }
  1439. break;
  1440. }
  1441. }
  1442. // search from right
  1443. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1444. for(int i = location; i < 4; i++)
  1445. {
  1446. slave = ShmPsuGrouping->Layout[i];
  1447. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1448. {
  1449. available++;
  1450. }
  1451. else
  1452. {
  1453. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1454. {
  1455. continue;
  1456. }
  1457. break;
  1458. }
  1459. }
  1460. return available;
  1461. #endif
  1462. }
  1463. void PsuGroupShareCheck(byte group)
  1464. {
  1465. int slave = 0, target = 0, location = 0, share = 0, total = 0;
  1466. total = GetPsuGroupAvailable(group) + 1;
  1467. //printf("\r\n Gun %d Total Group = %d", group + 1, total);
  1468. // search from left
  1469. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1470. for(int i = location; i >= 0; i--)
  1471. {
  1472. slave = ShmPsuGrouping->Layout[i];
  1473. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1474. {
  1475. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1476. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1477. {
  1478. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1479. }
  1480. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1481. break;
  1482. }
  1483. else
  1484. {
  1485. break;
  1486. }
  1487. }
  1488. if(share == 0)
  1489. {
  1490. // search from right
  1491. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1492. for(int i = location; i < 4; i++)
  1493. {
  1494. slave = ShmPsuGrouping->Layout[i];
  1495. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1496. {
  1497. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1498. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1499. {
  1500. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1501. }
  1502. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1503. break;
  1504. }
  1505. else
  1506. {
  1507. break;
  1508. }
  1509. }
  1510. }
  1511. if(share > 0)
  1512. {
  1513. //printf("\r\n Grab %02X", slave);
  1514. PsuGroupSwitchToIdle(slave);
  1515. }
  1516. else
  1517. {
  1518. //printf("\r\n No Need To Grab");
  1519. }
  1520. }
  1521. void SimplePsuGroupStartCharging(byte group)
  1522. {
  1523. //int slave = 0, location = 0;
  1524. int available = 0;
  1525. PsuGroupPartner partner;
  1526. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1527. {
  1528. return;
  1529. }
  1530. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE && ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1531. {
  1532. return;
  1533. }
  1534. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_IDLE)
  1535. {
  1536. SetGroupToMaster(group);
  1537. PsuGroupShareCheck(group);
  1538. }
  1539. else
  1540. {
  1541. available = GetPsuGroupAvailable(group);
  1542. //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
  1543. if(available == 0)
  1544. {
  1545. return;
  1546. }
  1547. }
  1548. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1549. for(int i = 0; i < partner.Quantity; i++)
  1550. {
  1551. AddGroupCollection(partner.Member[i], group);
  1552. }
  1553. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = true;
  1554. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = true;
  1555. #if 0
  1556. // search from left
  1557. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1558. for(int i = location; i >= 0; i--)
  1559. {
  1560. slave = ShmPsuGrouping->Layout[i];
  1561. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1562. {
  1563. //printf("\r\n Find %02X From Left", slave);
  1564. AddGroupCollection(slave, group);
  1565. }
  1566. else
  1567. {
  1568. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1569. {
  1570. continue;
  1571. }
  1572. break;
  1573. }
  1574. }
  1575. // search from right
  1576. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1577. for(int i = location; i < 4; i++)
  1578. {
  1579. slave = ShmPsuGrouping->Layout[i];
  1580. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1581. {
  1582. //printf("\r\n Find %02X From Right", slave);
  1583. AddGroupCollection(slave, group);
  1584. }
  1585. else
  1586. {
  1587. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1588. {
  1589. continue;
  1590. }
  1591. break;
  1592. }
  1593. }
  1594. #endif
  1595. }
  1596. void PsuGroupStopCharging(byte group)
  1597. {
  1598. int total = 0;
  1599. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1600. {
  1601. return;
  1602. }
  1603. total = ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity;
  1604. if(total > 0)
  1605. {
  1606. unsigned char collection[GENERAL_GUN_QUANTITY];
  1607. //printf("\r\n There are %d Group Need To Stop:", ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity);
  1608. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1609. for(int i = 0; i < total; i++)
  1610. {
  1611. //printf(" %02X", collection[i]);
  1612. }
  1613. for(int i = 0; i < total; i++)
  1614. {
  1615. RemoveGroupCollection(collection[i], group);
  1616. }
  1617. }
  1618. SetGroupToIdle(group);
  1619. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = false;
  1620. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = false;
  1621. }
  1622. void RunSimplePsuGrouping(char *v1, char *v2)
  1623. {
  1624. int group = 0, charging = 0;
  1625. group = atoi(v1);
  1626. charging = atoi(v2);
  1627. group -= 1;
  1628. if(group >= 0 && group < 4)
  1629. {
  1630. if(charging > 0)
  1631. {
  1632. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1633. {
  1634. //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
  1635. PsuGroupSwitchToIdle(group);
  1636. }
  1637. SimplePsuGroupStartCharging(group);
  1638. }
  1639. if(charging == 0)
  1640. {
  1641. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_MASTER)
  1642. {
  1643. PsuGroupStopCharging(group);
  1644. }
  1645. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1646. {
  1647. PsuGroupSwitchToIdle(group);
  1648. }
  1649. }
  1650. ShowGroupingInfo();
  1651. }
  1652. }
  1653. void ConnectionInfo(void)
  1654. {
  1655. int address = 0;
  1656. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  1657. {
  1658. address = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  1659. printf(" Connection[%d] Status: %d, DispenserIndex: %d, IP: %d.%d.%d.%d\r\n", i,
  1660. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status,
  1661. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex,
  1662. ((address >> 0) & 0xFF), ((address >> 8) & 0xFF), ((address >> 16) & 0xFF), ((address >> 24) & 0xFF));
  1663. }
  1664. }
  1665. void GunEnableInfo(int gunIndex)
  1666. {
  1667. printf(" Gun %d Index: %2X, Status = %2d , %7s, MeterValue: %10.4f, Local: : %10.4f, Gun: : %10.4f\r\n", gunIndex + 1, _chargingData[gunIndex]->Index, _chargingData[gunIndex]->SystemStatus,
  1668. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Enable ? "Enable" : "Disable",
  1669. _chargingData[gunIndex]->PowerConsumption,
  1670. ShmChargerInfo->MeterValue[gunIndex].LocalConsumption,
  1671. ShmChargerInfo->MeterValue[gunIndex].GunConsumption);
  1672. }
  1673. int FindDispenserIpAddress(int dispenser)
  1674. {
  1675. int address = 0;
  1676. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  1677. {
  1678. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched &&
  1679. dispenser == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex)
  1680. {
  1681. address = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  1682. }
  1683. }
  1684. return address;
  1685. }
  1686. int DispenserInfo(int dispenser)
  1687. {
  1688. int ipAddress = 0;
  1689. int gunCnt = 0;
  1690. printf(" Dispenser %d Status: %d", dispenser + 1, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus);
  1691. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  1692. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  1693. {
  1694. ipAddress = FindDispenserIpAddress(dispenser);
  1695. gunCnt = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ConnectorQuantity;
  1696. printf(", ModelName: %s, IP: %d.%d.%d.%d\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ModelName,
  1697. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  1698. for(int i = 0; i < gunCnt; i++)
  1699. {
  1700. unsigned char gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ConnectorID[i];
  1701. printf(" - Connector[%d] Gun %d, %s\r\n", i, gun, _chargingData[gun - 1]->ConnectorPlugIn ? "Plugged" : "Unplugged");
  1702. }
  1703. }
  1704. else
  1705. {
  1706. printf(", No Information\r\n");
  1707. }
  1708. return gunCnt;
  1709. }
  1710. void ShowCabinetInfo(char *inputCmd, unsigned int opt)
  1711. {
  1712. bool keepRun = false;
  1713. bool reflash = false;
  1714. int time = 0;
  1715. int dispenserLine = 0;
  1716. struct timespec _Loop_time;
  1717. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  1718. {
  1719. keepRun = true;
  1720. }
  1721. printf("\r\n");
  1722. printf("Power Cabinet & Dispenser Info\r\n");
  1723. do
  1724. {
  1725. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  1726. if(time >= 1000)
  1727. {
  1728. if(reflash)
  1729. {
  1730. ConsoleReflash(1, 2);
  1731. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  1732. dispenserLine = dispenserLine > 0 ? (dispenserLine + 1) : dispenserLine;
  1733. ConsoleReflash(1, dispenserLine);
  1734. dispenserLine = 0;
  1735. }
  1736. printf(" Dispenser: %d / %d, Connector: %d / %d\r\n",
  1737. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  1738. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
  1739. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
  1740. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  1741. printf("\r\n");
  1742. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  1743. {
  1744. GunEnableInfo(i);
  1745. }
  1746. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity > 0)
  1747. {
  1748. printf("\r\n");
  1749. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  1750. {
  1751. dispenserLine += DispenserInfo(i) + 1;
  1752. }
  1753. }
  1754. GetClockTime(&_Loop_time);
  1755. if((opt & OPTION_REFLASH) > 0)
  1756. {
  1757. reflash = true;
  1758. }
  1759. }
  1760. if(keepRun)
  1761. {
  1762. keepRun = IsLoopStopCmd() ? false : true;
  1763. usleep(10000);
  1764. }
  1765. }while(keepRun);
  1766. printf("\r\n");
  1767. }
  1768. void SetTestControl(char *v1, char *v2)
  1769. {
  1770. int testItem = 0;
  1771. int testItemLen = 5;
  1772. int enable = 0;
  1773. char strTest[32][32] = {"tbl", "tfsb", "chgsm", "fcre", "ubill"};
  1774. char strItem[32][32] = {"Balance", "Fast Standby Time", "Charging Simulation", "FCharging Release Extend", "Undisposed Bill"};
  1775. enable = atoi(v2);
  1776. if(enable < 0)
  1777. {
  1778. return;
  1779. }
  1780. for(int i = 0; i < testItemLen; i++)
  1781. {
  1782. if(strcmp((char *)&strTest[i][0], v1) == 0)
  1783. {
  1784. testItem = i + 1;
  1785. break;
  1786. }
  1787. }
  1788. if(testItem != 0)
  1789. {
  1790. if(enable)
  1791. {
  1792. ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
  1793. }
  1794. else
  1795. {
  1796. ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
  1797. }
  1798. printf("%s %s Test Item, Test Control Value = %08X\n",
  1799. enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
  1800. }
  1801. else
  1802. {
  1803. printf("Test Item %s Not Found\n", v1);
  1804. for(int i = 0; i < testItemLen; i++)
  1805. {
  1806. printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
  1807. }
  1808. }
  1809. printf("\r\n");
  1810. }
  1811. // Group Gun Available Psu Group Control
  1812. // Gun Role Master K1K2 GTVol GTCur StableCur Loading Loading DiffP_Ava DiffP_Cap DiffP_Lim Partner IdleCtrl Master Stop Derating Extend Slave
  1813. // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX XXX kw XXX kW XXX kW XX 0xXXXX 0xXXXX 0xXXXX 0xXXXX 0xXXXX 0xXXXX
  1814. // Group Gun DiffP Available Psu Group Control
  1815. // Gun Role Master K1K2 GTVol GTCur StableCur Loading Loading DiffP_Ava DiffP_Cap DiffP_Lim ConfigLim Partner IdleCtrl Master Stop Derating Extend Slave Dummy
  1816. // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX XXX kw XXX kW XXX kW XXX kW XX 0xXXXX 0xXXXX 0xXXXX 0xXXXX 0xXXXX 0xXXXX 0xXXXX
  1817. void ShowGroupingDemand(char *inputCmd, unsigned int opt)
  1818. {
  1819. bool keepRun = false;
  1820. bool reflash = false;
  1821. bool outputFile = false;
  1822. bool allRoleIdle = false;
  1823. bool fullInfo = false;
  1824. int totalCnt = 0;
  1825. totalCnt = GetSubCommand(inputCmd);
  1826. if(totalCnt == 1)
  1827. {
  1828. if(strcmp(&MultiSubCmd[0][0], "full") == 0)
  1829. {
  1830. fullInfo = true;
  1831. }
  1832. }
  1833. int time = 0;
  1834. struct timespec _Loop_time;
  1835. char lineString[512];
  1836. char tempString[128];
  1837. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  1838. {
  1839. keepRun = true;
  1840. }
  1841. if((opt & OPTION_OUTPUT_FILE) > 0)
  1842. {
  1843. outputFile = true;
  1844. }
  1845. byte target = 0;
  1846. unsigned char k1k2 = 0;
  1847. //printf(" Group Gun Available Psu Group Control\r\n");
  1848. //printf(" Gun Role Master K1K2 GTVol GTCur StableCur Loading Loading DiffP_Ava DiffP_Cap DiffP_Lim Partner IdleCtrl Master Stop Derating Extend Slave\r\n");
  1849. memset(lineString, 0x00, sizeof(lineString));
  1850. sprintf(lineString, " Group Gun DiffP");
  1851. if(fullInfo)
  1852. {
  1853. sprintf(tempString, " Available Psu Group Control");
  1854. strcat(lineString, tempString);
  1855. }
  1856. if(!outputFile)
  1857. {
  1858. printf("%s\r\n", lineString);
  1859. }
  1860. else
  1861. {
  1862. ReadCmd_INFO("%s", lineString);
  1863. }
  1864. sprintf(lineString, " Gun Role Master K1K2 GTVol GTCur StableCur Loading Loading DiffP_Ava DiffP_Cap DiffP_Lim ConfigLim");
  1865. if(fullInfo)
  1866. {
  1867. sprintf(tempString, " Partner IdleCtrl Master Stop Derating Extend Slave Dummy");
  1868. strcat(lineString, tempString);
  1869. }
  1870. if(!outputFile)
  1871. {
  1872. printf("%s\r\n", lineString);
  1873. }
  1874. else
  1875. {
  1876. ReadCmd_INFO("%s", lineString);
  1877. }
  1878. do
  1879. {
  1880. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  1881. if(time >= 1000)
  1882. {
  1883. if(reflash)
  1884. {
  1885. ConsoleReflash(MAX_GROUP_QUANTITY, 1);
  1886. }
  1887. for(int i = 0; i < MAX_GROUP_QUANTITY; i++)
  1888. {
  1889. target = ShmPsuGrouping->Layout[i];
  1890. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup != 0)
  1891. {
  1892. k1k2 = _chargingData[ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
  1893. }
  1894. else
  1895. {
  1896. k1k2 = _chargingData[target]->RelayK1K2Status;
  1897. }
  1898. memset(lineString, 0x00, sizeof(lineString));
  1899. sprintf(tempString, " %d %2d %02X %d %4d V %3d.%d A %4d A %3d.%02d",
  1900. target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup, k1k2,
  1901. (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
  1902. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
  1903. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
  1904. (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1905. (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
  1906. (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
  1907. strcat(lineString, tempString);
  1908. //if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup == target + 1)
  1909. //{
  1910. sprintf(tempString, " %3d.%02d", (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading / 100), (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading % 100));
  1911. strcat(lineString, tempString);
  1912. sprintf(tempString, " %3d kW %3d kW %3d kW %3d kW",
  1913. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_Available,
  1914. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_Capability,
  1915. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_PhysicalLimit,
  1916. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_ConfigLimit);
  1917. strcat(lineString, tempString);
  1918. if(fullInfo)
  1919. {
  1920. int partner_quantity = GetPsuGroupAvailable(target);
  1921. sprintf(tempString, " %2d 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X",
  1922. partner_quantity,
  1923. ShmPsuGrouping->GroupCollection[target].GroupCtrl.RoleCtrl.IdleCtrlValue,
  1924. ShmPsuGrouping->GroupCollection[target].GroupCtrl.RoleCtrl.MasterCtrlValue,
  1925. ShmPsuGrouping->GroupCollection[target].GroupCtrl.RoleCtrl.StopChargingCtrlValue,
  1926. ShmPsuGrouping->GroupCollection[target].GroupCtrl.RoleCtrl.DeratingCtrlValue,
  1927. ShmPsuGrouping->GroupCollection[target].GroupCtrl.RoleCtrl.ExtendCapabilityCtrlValue,
  1928. ShmPsuGrouping->GroupCollection[target].GroupCtrl.RoleCtrl.SlaveCtrlValue,
  1929. ShmPsuGrouping->GroupCollection[target].GroupCtrl.RoleCtrl.DummyMasterCtrlValue);
  1930. strcat(lineString, tempString);
  1931. }
  1932. //}
  1933. if(!outputFile)
  1934. {
  1935. printf("%s\r\n", lineString);
  1936. }
  1937. else
  1938. {
  1939. if(!allRoleIdle)
  1940. {
  1941. ReadCmd_INFO("%s", lineString);
  1942. }
  1943. }
  1944. }
  1945. allRoleIdle = true;
  1946. for(int i = 0; i < MAX_GROUP_QUANTITY; i++)
  1947. {
  1948. if(ShmChargerInfo->PsuGrouping.GroupCollection[i].Role != _GROLE_IDLE)
  1949. {
  1950. allRoleIdle = false;
  1951. }
  1952. }
  1953. GetClockTime(&_Loop_time);
  1954. if((opt & OPTION_REFLASH) > 0 && !outputFile)
  1955. {
  1956. reflash = true;
  1957. }
  1958. }
  1959. if(keepRun)
  1960. {
  1961. keepRun = IsLoopStopCmd() ? false : true;
  1962. usleep(10000);
  1963. }
  1964. }while(keepRun);
  1965. printf("\r\n");
  1966. }
  1967. // v1: gun
  1968. // v2: voltage
  1969. // v3: current
  1970. void SetGunStartCharging(char *inputCmd, unsigned int opt, unsigned char isWeb)
  1971. {
  1972. int totalCnt = 0, maxPara = 0;
  1973. maxPara = 3;
  1974. totalCnt = GetSubCommand(inputCmd);
  1975. if(totalCnt != maxPara)
  1976. {
  1977. printf("Input cmd fail ------ gunchg [gun 1-4] [voltage 0-1000] [current 0-1000]\r\n\r\n");
  1978. return;
  1979. }
  1980. int gun = 0;
  1981. float _voltage = 0, _current = 0;
  1982. gun = atoi(&MultiSubCmd[0][0]);
  1983. _voltage = atof(&MultiSubCmd[1][0]);
  1984. _current = atof(&MultiSubCmd[2][0]);
  1985. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY || _voltage < 0 || _voltage > 1000 || _current < 0 || _current > 1200)
  1986. {
  1987. printf("\r\n");
  1988. printf("Gun Start Charging Input parameter %d, %.1f, %.1f out of range\r\n", gun, _voltage, _current);
  1989. printf("\r\n");
  1990. return;
  1991. }
  1992. bool wait = true;
  1993. int time = 0;
  1994. struct timespec _Wait_time;
  1995. unsigned char PreviousSystemStatus = 0xFF;
  1996. unsigned short _targetVoltage = 0, _targetCurrent = 0;
  1997. printf("\r\n");
  1998. while(wait)
  1999. {
  2000. switch(_chargingData[gun - 1]->SystemStatus)
  2001. {
  2002. case S_IDLE:
  2003. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2004. {
  2005. printf("Gun %d S_IDLE\r\n", gun);
  2006. printf("Set Gun %d Start Charging > Voltage: %4d, Current: %d\r\n", gun, (int)_voltage, (int)_current);
  2007. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  2008. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  2009. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2010. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2011. if(isWeb)
  2012. {
  2013. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.WebApiTrigger = true;
  2014. }
  2015. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2016. }
  2017. break;
  2018. case S_REASSIGN_CHECK:
  2019. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2020. {
  2021. printf("Gun %d S_REASSIGN_CHECK, Wait For Request Charging\r\n", gun);
  2022. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2023. }
  2024. break;
  2025. case S_REASSIGN:
  2026. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2027. {
  2028. printf("Gun %d S_REASSIGN, Wait For Grouping\r\n", gun);
  2029. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2030. }
  2031. break;
  2032. case S_PREPARNING:
  2033. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2034. {
  2035. printf("Gun %d S_PREPARNING\r\n", gun);
  2036. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2037. }
  2038. break;
  2039. case S_PREPARING_FOR_EV:
  2040. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2041. {
  2042. printf("Gun %d S_PREPARING_FOR_EV\r\n", gun);
  2043. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2044. }
  2045. break;
  2046. case S_PREPARING_FOR_EVSE:
  2047. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2048. {
  2049. printf("Gun %d S_PREPARING_FOR_EVSE, Wait For EVSE\r\n", gun);
  2050. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2051. }
  2052. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2053. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2054. {
  2055. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2056. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2057. printf("Gun %d Set Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  2058. }
  2059. break;
  2060. case S_CHARGING:
  2061. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2062. {
  2063. printf("Gun %d S_CHARGING\r\n", gun);
  2064. if(PreviousSystemStatus == 0xFF)
  2065. {
  2066. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2067. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2068. printf("Gun %d Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  2069. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  2070. {
  2071. printf("Set Gun %d Force Charging > Voltage: %4d, Current: %d\r\n", gun, (int)_voltage, (int)_current);
  2072. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2073. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2074. }
  2075. }
  2076. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2077. GetClockTime(&_Wait_time);
  2078. }
  2079. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2080. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2081. {
  2082. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2083. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2084. printf("Gun %d Set Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  2085. }
  2086. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2087. if(time >= 1)
  2088. {
  2089. wait = false;
  2090. printf("Done\r\n");
  2091. }
  2092. break;
  2093. case S_TERMINATING:
  2094. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2095. {
  2096. printf("Gun %d S_TERMINATING\r\n", gun);
  2097. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2098. }
  2099. wait = false;
  2100. break;
  2101. case S_COMPLETE:
  2102. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2103. {
  2104. printf("Gun %d S_COMPLETE\r\n", gun);
  2105. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2106. }
  2107. wait = false;
  2108. break;
  2109. case S_ALARM:
  2110. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2111. {
  2112. printf("Gun %d S_ALARM\r\n", gun);
  2113. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2114. }
  2115. wait = false;
  2116. break;
  2117. default:
  2118. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2119. {
  2120. printf("Gun SystemStatus %d Unknown(%d)\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2121. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2122. }
  2123. printf("Gun %d SystemStatus(%d) Is Not Available\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2124. wait = false;
  2125. break;
  2126. }
  2127. char word[128];
  2128. char newString[7][10];
  2129. int i,j,ctr;
  2130. memset(word, 0x00, sizeof(word));
  2131. get_char(word);
  2132. if (strlen(word) == 0)
  2133. {
  2134. continue;
  2135. }
  2136. j=0; ctr=0;
  2137. strcpy(newString[1], "-1");
  2138. strcpy(newString[2], "-1");
  2139. for (i = 0; i <= (strlen(word)); i++)
  2140. {
  2141. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2142. {
  2143. newString[ctr][j] = '\0';
  2144. ctr++;
  2145. j = 0;
  2146. }
  2147. else
  2148. {
  2149. newString[ctr][j] = word[i];
  2150. j++;
  2151. }
  2152. }
  2153. if(strcmp(newString[0], "c") == 0)
  2154. {
  2155. printf("Stop\r\n");
  2156. wait = false;
  2157. }
  2158. usleep(100000);
  2159. }
  2160. printf("\r\n");
  2161. }
  2162. void GenerateManualStop(int gunIndex, bool isAlarm, char *alarmCode)
  2163. {
  2164. if(isAlarm)
  2165. {
  2166. if(!_chargingData[gunIndex]->ChargingStopFlag.bits.AlarmStop)
  2167. {
  2168. if(strncmp((char *)_chargingData[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL)
  2169. {
  2170. memcpy((char *)_chargingData[gunIndex]->ConnectorAlarmCode, alarmCode, 6);
  2171. }
  2172. _chargingData[gunIndex]->ChargingStopFlag.bits.AlarmStop = true;
  2173. printf("Set Gun %d Stop Charging(ManualAlarm)\r\n", gunIndex + 1);
  2174. }
  2175. }
  2176. else
  2177. {
  2178. if(!_chargingData[gunIndex]->ChargingStopFlag.bits.ManualStop)
  2179. {
  2180. _chargingData[gunIndex]->ChargingStopFlag.bits.ManualStop = true;
  2181. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gunIndex + 1);
  2182. }
  2183. }
  2184. }
  2185. // v1: gun
  2186. void SetGunStopCharging(char *inputCmd, unsigned int opt)
  2187. {
  2188. int totalCnt = 0, maxPara = 0;
  2189. maxPara = 2;
  2190. totalCnt = GetSubCommand(inputCmd);
  2191. if(totalCnt > maxPara || totalCnt == 0)
  2192. {
  2193. printf("Input cmd fail ------ gunstp [gun 1-4] [status code]\r\n\r\n");
  2194. return;
  2195. }
  2196. int gun = 0;
  2197. gun = atoi(&MultiSubCmd[0][0]);
  2198. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  2199. {
  2200. printf("\r\n");
  2201. printf("Gun Stop Charging Input parameter %d over range\r\n", gun);
  2202. printf("\r\n");
  2203. return;
  2204. }
  2205. bool isAlarmStop = false;
  2206. char manualAlarm[7];
  2207. if(totalCnt == 2)
  2208. {
  2209. if((strlen(&MultiSubCmd[1][0]) == 6) && atoi(&MultiSubCmd[1][0]) != 0)
  2210. {
  2211. memset(manualAlarm, 0x00, sizeof(manualAlarm));
  2212. memcpy(manualAlarm, &MultiSubCmd[1][0], 6);
  2213. isAlarmStop = true;
  2214. }
  2215. }
  2216. bool wait = true;
  2217. int time = 0;
  2218. struct timespec _Wait_time;
  2219. unsigned char PreviousSystemStatus = 0xFF;
  2220. printf("\r\n");
  2221. while(wait)
  2222. {
  2223. switch(_chargingData[gun - 1]->SystemStatus)
  2224. {
  2225. case S_IDLE:
  2226. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2227. {
  2228. printf("Gun %d S_IDLE\r\n", gun);
  2229. if(PreviousSystemStatus == 0xFF)
  2230. {
  2231. if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2232. {
  2233. printf("Set Group [%02X] Stop\r\n", gun - 1);
  2234. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2235. }
  2236. }
  2237. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2238. GetClockTime(&_Wait_time);
  2239. }
  2240. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2241. if(time >= 1)
  2242. {
  2243. wait = false;
  2244. printf("Done\r\n");
  2245. }
  2246. break;
  2247. case S_REASSIGN_CHECK:
  2248. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2249. {
  2250. printf("Gun %d S_REASSIGN_CHECK, Wait For Request Charging\r\n", gun);
  2251. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2252. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2253. }
  2254. break;
  2255. case S_REASSIGN:
  2256. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2257. {
  2258. printf("Gun %d S_REASSIGN, Wait For Grouping\r\n", gun);
  2259. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2260. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2261. }
  2262. break;
  2263. case S_PREPARNING:
  2264. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2265. {
  2266. printf("Gun %d S_PREPARNING\r\n", gun);
  2267. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2268. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2269. }
  2270. break;
  2271. case S_PREPARING_FOR_EV:
  2272. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2273. {
  2274. printf("Gun %d S_PREPARING_FOR_EV\r\n", gun);
  2275. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2276. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2277. }
  2278. break;
  2279. case S_PREPARING_FOR_EVSE:
  2280. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2281. {
  2282. printf("Gun %d S_PREPARING_FOR_EVSE, Wait For EVSE\r\n", gun);
  2283. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2284. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2285. }
  2286. break;
  2287. case S_CHARGING:
  2288. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2289. {
  2290. printf("Gun %d S_CHARGING\r\n", gun);
  2291. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2292. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2293. }
  2294. break;
  2295. case S_TERMINATING:
  2296. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2297. {
  2298. printf("Gun %d S_TERMINATING\r\n", gun);
  2299. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2300. }
  2301. break;
  2302. case S_COMPLETE:
  2303. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2304. {
  2305. printf("Gun %d S_COMPLETE\r\n", gun);
  2306. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2307. }
  2308. break;
  2309. case S_ALARM:
  2310. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2311. {
  2312. printf("Gun %d S_ALARM\r\n", gun);
  2313. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2314. }
  2315. break;
  2316. default:
  2317. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2318. {
  2319. printf("Gun SystemStatus %d Unknown(%d)\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2320. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2321. }
  2322. printf("Gun %d SystemStatus(%d) Is Not Available\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2323. wait = false;
  2324. break;
  2325. }
  2326. char word[128];
  2327. char newString[7][10];
  2328. int i,j,ctr;
  2329. memset(word, 0x00, sizeof(word));
  2330. get_char(word);
  2331. if (strlen(word) == 0)
  2332. {
  2333. continue;
  2334. }
  2335. j=0; ctr=0;
  2336. strcpy(newString[1], "-1");
  2337. strcpy(newString[2], "-1");
  2338. for (i = 0; i <= (strlen(word)); i++)
  2339. {
  2340. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2341. {
  2342. newString[ctr][j] = '\0';
  2343. ctr++;
  2344. j = 0;
  2345. }
  2346. else
  2347. {
  2348. newString[ctr][j] = word[i];
  2349. j++;
  2350. }
  2351. }
  2352. if(strcmp(newString[0], "c") == 0)
  2353. {
  2354. printf("Stop\r\n");
  2355. wait = false;
  2356. }
  2357. usleep(100000);
  2358. }
  2359. printf("\r\n");
  2360. }
  2361. void SetGunExtend(char *v1)
  2362. {
  2363. int gun = 0;
  2364. gun = atoi(v1);
  2365. if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
  2366. {
  2367. printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
  2368. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
  2369. }
  2370. else
  2371. {
  2372. printf("\r\nGun %d Extend Capability Is Not Available, SystemStatus(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2373. }
  2374. printf("\r\n\r\n");
  2375. }
  2376. // Gun TargetV TargetC GTargetV GTargetC OutputV OutputC G_Psu_V G_Psu_C Psu 0_V Psu 0_C Psu 1_V Psu 1_C Psu 2_V Psu 2_C ...
  2377. // X XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A
  2378. void ShowGunOutput(void)
  2379. {
  2380. byte target = 0;
  2381. unsigned short voltage = 0, current = 0;
  2382. printf("\r\n Gun TargetV TargetC GTargetV GTargetC OutputV OutputC G_Psu_V G_Psu_C Psu 0_V Psu 0_C Psu 1_V Psu 1_C Psu 2_V Psu 2_C ...");
  2383. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2384. {
  2385. target = ShmPsuGrouping->Layout[i];
  2386. // "\r\n %d %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A"
  2387. voltage = (unsigned short)(_chargingData[target]->EvBatterytargetVoltage * 10);
  2388. current = (unsigned short)(_chargingData[target]->EvBatterytargetCurrent * 10);
  2389. printf("\r\n %d %4d.%d V %3d.%d A", target + 1, (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2390. voltage = ShmPsuGrouping->GroupOutput[target].GTargetVoltage;
  2391. current = ShmPsuGrouping->GroupOutput[target].GTargetCurrent;
  2392. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2393. voltage = (unsigned short)(_chargingData[target]->PresentChargingVoltage * 10);
  2394. current = (unsigned short)(_chargingData[target]->PresentChargingCurrent * 10);
  2395. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2396. voltage = ShmPsuData->PsuGroup[target].GroupPresentOutputVoltage;
  2397. current = ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent;
  2398. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2399. /*
  2400. for(int j = 0; j < ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity; j++)
  2401. {
  2402. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2403. }
  2404. */
  2405. }
  2406. printf("\r\n\r\n");
  2407. }
  2408. void SetGpio(char *v1, char *v2)
  2409. {
  2410. int testItem = 0;
  2411. int testItemLen = 1;
  2412. int ioOutput = 0;
  2413. char strTest[32][32] = {"4g"};
  2414. char strItem[32][32] = {"4G Reset"};
  2415. ioOutput = atoi(v2);
  2416. if(ioOutput < 0)
  2417. {
  2418. return;
  2419. }
  2420. for(int i = 0; i < testItemLen; i++)
  2421. {
  2422. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2423. {
  2424. testItem = i + 1;
  2425. break;
  2426. }
  2427. }
  2428. if(testItem != 0)
  2429. {
  2430. if(ioOutput)
  2431. {
  2432. system("echo 1 > /sys/class/gpio/gpio104/value");
  2433. }
  2434. else
  2435. {
  2436. system("echo 0 > /sys/class/gpio/gpio104/value");
  2437. }
  2438. printf("Set %s %s\n",
  2439. strItem[testItem - 1], ioOutput > 0 ? "High" : "Low");
  2440. }
  2441. else
  2442. {
  2443. printf("Gpio Item %s Not Found\n", v1);
  2444. }
  2445. printf("\r\n");
  2446. }
  2447. void ShowStatus(void)
  2448. {
  2449. char *str_cabinet_role[] = {STR_CABINET_ROLE_NONE, STR_CABINET_ROLE_MASTER, STR_CABINET_ROLE_SLAVE};
  2450. for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
  2451. {
  2452. printf("\r\nGun %d Status = %d, IsAvailable = %d, GunEnable = %d",
  2453. i + 1,
  2454. _chargingData[i]->SystemStatus,
  2455. _chargingData[i]->IsAvailable,
  2456. ShmChargerInfo->Control.GunAvailable[i]);
  2457. printf("\r\nAlarmCode");
  2458. printf("\r\n Connector = %6s, EvConn = %6s, Remote = %6s, Vendor = %6s",
  2459. strncmp((char *)_chargingData[i]->ConnectorAlarmCode, "", 6) != 0 ?
  2460. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2461. strncmp((char *)_chargingData[i]->EvConnAlarmCode, "", 6) != 0 ?
  2462. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2463. strncmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode, "", 6) != 0 ?
  2464. (char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode : "No Err",
  2465. strncmp((char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode, "", 6) != 0 ?
  2466. (char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode : "No Err");
  2467. }
  2468. printf("\r\n");
  2469. printf("\r\nPower Cabinet Role: %s, Switch Value: %d, ",
  2470. ShmChargerInfo->Control.CabinetSwitch <= _CROLE_SLAVE ? str_cabinet_role[ShmChargerInfo->Control.CabinetSwitch] : "Unknown",
  2471. ShmChargerInfo->Control.CabinetSwitch);
  2472. printf("\r\nStatus Code Len = %d", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  2473. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
  2474. {
  2475. printf("\r\n WarningCode:");
  2476. for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  2477. {
  2478. printf(" %s", (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  2479. }
  2480. }
  2481. printf("\r\n\r\n");
  2482. }
  2483. void ShowWhiteCardList(void)
  2484. {
  2485. printf("\r\n");
  2486. printf("White Card List\r\n");
  2487. for(int i = 0; i < 10; i++)
  2488. {
  2489. printf(" *White Card [%2d]: %s\r\n", i + 1, (char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i]);
  2490. }
  2491. }
  2492. void WriteWhiteCard(char *v1, char *v2)
  2493. {
  2494. int cardIndex = 0;
  2495. cardIndex = atoi(v1);
  2496. if(cardIndex < 1 || cardIndex > 10)
  2497. {
  2498. printf("\r\n White Card Index Fail\r\n\r\n");
  2499. return;
  2500. }
  2501. if(strlen(v2) == 0 || strlen(v2) > 31)
  2502. {
  2503. printf("\r\n White Card Fail\r\n\r\n");
  2504. return;
  2505. }
  2506. printf("\r\n Str Len = %d = %s", strlen(v2), v2);
  2507. printf("\r\n Set White Card Index %d = %s", cardIndex, v2);
  2508. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], v2, strlen(v2));
  2509. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  2510. printf("\r\n\r\n");
  2511. }
  2512. void EraseWhiteCard(char *v1)
  2513. {
  2514. int cardIndex = 0;
  2515. cardIndex = atoi(v1);
  2516. if(cardIndex < 1 || cardIndex > 10)
  2517. {
  2518. printf("\r\n White Card Index Fail\r\n\r\n");
  2519. return;
  2520. }
  2521. printf("\r\n Erase White Card Index = %d", cardIndex);
  2522. memset((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], 0x00, 32);
  2523. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  2524. printf("\r\n\r\n");
  2525. }
  2526. // MaxChargingProfile: %s
  2527. // Offline MaxPower: %s
  2528. // LocalPowerSharing: %s
  2529. // Max Total Power: XXXX kW, Total Current: XXXX A, MaxSoc: XXX %
  2530. // Total Energy: XXXX kWh, Duration: XXXX Minute(s)
  2531. void ShowMaxLimit(void)
  2532. {
  2533. char tempString[64];
  2534. //************************************************************************************************
  2535. memset(tempString, 0x00, sizeof(tempString));
  2536. if(ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1)
  2537. {
  2538. sprintf(tempString, " %s", "Unlimited");
  2539. }
  2540. else
  2541. {
  2542. sprintf(tempString, " %4d kW", (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000);
  2543. }
  2544. printf(" MaxChargingProfile: %s\r\n", tempString);
  2545. //************************************************************************************************
  2546. memset(tempString, 0x00, sizeof(tempString));
  2547. if(ShmChargerInfo->OutputLimit.Offline_MaxChargingPower <= 0)
  2548. {
  2549. sprintf(tempString, " %s", "Unlimited");
  2550. }
  2551. else
  2552. {
  2553. sprintf(tempString, " %4d kW", ShmChargerInfo->OutputLimit.Offline_MaxChargingPower / 1000);
  2554. }
  2555. printf(" Offline MaxPower: %s\r\n", tempString);
  2556. //************************************************************************************************
  2557. memset(tempString, 0x00, sizeof(tempString));
  2558. if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing == _SYS_POWER_SHARING_MODE_DISABLE)
  2559. {
  2560. sprintf(tempString, " %s", "Disable");
  2561. }
  2562. else
  2563. {
  2564. if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing == _SYS_POWER_SHARING_MODE_MASTER)
  2565. {
  2566. sprintf(tempString, " %s, PowerSharingPower: %d W", "Master", ShmSysConfigAndInfo->SysConfig.PowerSharingCapacityPower);
  2567. }
  2568. else
  2569. {
  2570. sprintf(tempString, " %s", "Slave");
  2571. }
  2572. }
  2573. printf(" LocalPowerSharing: %s\r\n", tempString);
  2574. //************************************************************************************************
  2575. printf(" Max Total Power: %4d kW, Total Current: %4d A, MaxSoc: %3d %%\r\n",
  2576. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  2577. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent,
  2578. ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
  2579. //************************************************************************************************
  2580. printf(" Total Energy: %4d kWh, Duration: %4d Minute(s)\r\n",
  2581. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy, ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2582. }
  2583. void ShowGunLimit(int gun_index)
  2584. {
  2585. char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
  2586. // Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur LocalPowerSharing
  2587. // 1 0 CHAdeMO 00 0000 V 0000 A 0000 / 0000 / 0000 kW 0000 / 0000 A 0000 >> 0000 A
  2588. printf(" %d %d ", gun_index + 1, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable);
  2589. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable)
  2590. {
  2591. printf(" %7s %2d",
  2592. _chargingData[gun_index]->Type <= _Type_GB ? str_gun_type[_chargingData[gun_index]->Type] : "???",
  2593. ShmChargerInfo->PsuGrouping.GroupCollection[gun_index].GunPsuQuantity);
  2594. printf(" %4d V %4d A",
  2595. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteMaxPhysicalVoltage / 10),
  2596. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteMaxPhysicalCurrent / 10));
  2597. printf(" %4d / %4d / %4d kW",
  2598. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower / 10),
  2599. _chargingData[gun_index]->ChargingProfilePower == -1 ? (int)_chargingData[gun_index]->ChargingProfilePower : ((int)_chargingData[gun_index]->ChargingProfilePower / 1000),
  2600. ShmChargerInfo->OutputLimit.GunMaxProfilePower[gun_index] == 0 ? (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : (ShmChargerInfo->OutputLimit.GunMaxProfilePower[gun_index] / 1000));
  2601. printf(" %4d / %4d A",
  2602. ((int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent / 10),
  2603. _chargingData[gun_index]->ChargingProfileCurrent == -1 ? (int)_chargingData[gun_index]->ChargingProfileCurrent : ((int)_chargingData[gun_index]->ChargingProfileCurrent / 10));
  2604. printf(" %4d >> %4d A", ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent[gun_index], (int)_chargingData[gun_index]->LocalPowerLimitCurrent);
  2605. }
  2606. printf("\r\n");
  2607. }
  2608. void ShowChargerLimit(char *inputCmd, unsigned int opt)
  2609. {
  2610. bool keepRun = false;
  2611. bool reflash = false;
  2612. int time = 0;
  2613. struct timespec _Loop_time;
  2614. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  2615. {
  2616. keepRun = true;
  2617. }
  2618. printf("\r\n");
  2619. printf("Charger Limit\r\n");
  2620. do
  2621. {
  2622. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  2623. if(time >= 1000)
  2624. {
  2625. if(reflash)
  2626. {
  2627. ConsoleReflash(1, 7);
  2628. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  2629. }
  2630. ShowMaxLimit();
  2631. printf("\r\n");
  2632. printf(" Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur LocalPowerSharing\r\n");
  2633. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2634. {
  2635. ShowGunLimit(i);
  2636. }
  2637. GetClockTime(&_Loop_time);
  2638. if((opt & OPTION_REFLASH) > 0)
  2639. {
  2640. reflash = true;
  2641. }
  2642. }
  2643. if(keepRun)
  2644. {
  2645. keepRun = IsLoopStopCmd() ? false : true;
  2646. usleep(10000);
  2647. }
  2648. }while(keepRun);
  2649. printf("\r\n");
  2650. }
  2651. void SetPsuCommand(char *inputCmd, unsigned int opt)
  2652. {
  2653. }
  2654. void SetGunCommand(char *v1, char *v2, char *v3)
  2655. {
  2656. int cmdItem = 0;
  2657. int cmdItemLen = 2;
  2658. int gunID = 0;
  2659. int enable = 0;
  2660. char strGunCmd[32][32] = {"enable", "operative"};
  2661. char strDescription[32][32] = {"Available", "Operative"};
  2662. gunID = atoi(v2);
  2663. enable = atoi(v3);
  2664. if(gunID <= 0 || gunID > CONNECTOR_QUANTITY || enable < 0)
  2665. {
  2666. return;
  2667. }
  2668. for(int i = 0; i < cmdItemLen; i++)
  2669. {
  2670. if(strcmp((char *)&strGunCmd[i][0], v1) == 0)
  2671. {
  2672. cmdItem = i + 1;
  2673. break;
  2674. }
  2675. }
  2676. if(cmdItem != 0)
  2677. {
  2678. switch(cmdItem)
  2679. {
  2680. case 1:
  2681. ShmChargerInfo->Control.GunAvailable[gunID - 1] = enable > 0 ? YES : NO;
  2682. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2683. break;
  2684. case 2:
  2685. _chargingData[gunID - 1]->IsAvailable = enable > 0 ? YES : NO;
  2686. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2687. break;
  2688. }
  2689. printf("Gun cmd [%s] [%s]\n", strDescription[cmdItem - 1], enable ? "Enable" : "Disable");
  2690. }
  2691. else
  2692. {
  2693. printf("Gun cmd %s not found\n", v1);
  2694. for(int i = 0; i < cmdItemLen; i++)
  2695. {
  2696. printf(" [%s] -> %s Test\n", strGunCmd[i], strDescription[i]);
  2697. }
  2698. }
  2699. printf("\r\n");
  2700. }
  2701. void ShowWebSystemInfo(void)
  2702. {
  2703. char *str_led_intensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  2704. char *str_qr_code_made[] = {STR_QR_DEFAULT, STR_QR_CUSTOMIZED, STR_QR_CHARGEBOXID};
  2705. char *str_rfid_endian[] = {STR_LITTLE_ENDIAN, STR_BIG_ENDIAN};
  2706. printf("\r\n");
  2707. printf("Web [System]\r\n");
  2708. printf(" *System ID: %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  2709. printf(" *AuthorisationMode[%7s]\r\n",
  2710. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE ? "Enable" : "Disable");
  2711. printf(" - APP [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAPP > 0 ? "Enable" : "Disable");
  2712. printf(" - QRCode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isQRCode > 0 ? "Enable" : "Disable");
  2713. printf(" - RFID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isRFID > 0 ? "Enable" : "Disable");
  2714. printf(" - EVCCID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID > 0 ? "Enable" : "Disable");
  2715. if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian <= RFID_ENDIAN_BIG)
  2716. {
  2717. printf(" *RfidCardNumEndian [%s]\r\n", str_rfid_endian[ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian]);
  2718. }
  2719. else
  2720. {
  2721. printf(" *RfidCardNumEndian: %d\r\n", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
  2722. }
  2723. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode <= _QR_MODE_Customized)
  2724. {
  2725. printf(" *QR Code Made [%s]\r\n", str_qr_code_made[ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode]);
  2726. }
  2727. else
  2728. {
  2729. printf(" *QR Code Made: %d\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode);
  2730. }
  2731. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == _QR_MODE_Customized)
  2732. {
  2733. printf(" - QR Code Content: %s\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  2734. }
  2735. if(ShmChargerInfo->AuthInfo.QRCodeMode <= _QR_MODE_ChargeBoxId)
  2736. {
  2737. printf(" *QR Code Mode [%s]\r\n", str_qr_code_made[ShmChargerInfo->AuthInfo.QRCodeMode]);
  2738. }
  2739. else
  2740. {
  2741. printf(" *QR Code Mode: %d\r\n", ShmChargerInfo->AuthInfo.QRCodeMode);
  2742. }
  2743. if(ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity <= _LED_INTENSITY_BRIGHTEST)
  2744. {
  2745. printf(" *LED Intensity[%s]\r\n", str_led_intensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  2746. }
  2747. else
  2748. {
  2749. printf(" *LED Intensity[%d]\r\n", ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity);
  2750. }
  2751. }
  2752. void ShowWebChargingInfo(void)
  2753. {
  2754. printf("\r\n");
  2755. printf("Web [Charging]\r\n");
  2756. printf(" *Max Charging Energy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
  2757. printf(" *Max Charging Power : %4d kW\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
  2758. printf(" *Max Charging Current : %4d A\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  2759. printf(" *Max Charging Duration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2760. printf(" *Max Charging Soc : %4d %%\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
  2761. printf(" *StopCharging By Button[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton > 0 ? "Enable" : "Disable");
  2762. printf(" *Fan Control Policy : %s\r\n", ShmSysConfigAndInfo->SysConfig.FanControlPolicy == _FAN_POLICY_AUTO_MODE ? STR_FAN_AUTO_MODE : STR_FAN_QUITE_MODE);
  2763. printf(" *Billing[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.isBilling > 0 ? "Enable" : "Disable");
  2764. printf(" - Currency[%2d]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
  2765. }
  2766. // *DHCP Client [Enable]
  2767. // - MAC Add [%s]
  2768. // - IP Add [%s]
  2769. // - Submask [%s]
  2770. // - Gateway [%s]
  2771. void ShowEthernetInfo(void)
  2772. {
  2773. printf(" *DHCP Client [%s]\r\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0 ? "Enable" : "Disable");
  2774. printf(" - MAC Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress : "NULL");
  2775. printf(" - IP Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress : "NULL");
  2776. printf(" - SubMask [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress : "NULL");
  2777. printf(" - Gateway [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress : "NULL");
  2778. }
  2779. // *WiFi Mode [Station]
  2780. // - SSID [%s]
  2781. // - PWD [%s]
  2782. // - TargetMac [%s]
  2783. // - RSSI [%s]
  2784. // - DHCP [%s]
  2785. // - MAC Add [%s]
  2786. // - IP Add [%s]
  2787. // - Submask [%s]
  2788. // - Gateway [%s]
  2789. // - ConnStatus [Connected]
  2790. void ShowWiFiInfo(void)
  2791. {
  2792. char *str_wifi_mode[] = {"Disable", "Station", "AP Mode"};
  2793. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode <= _SYS_WIFI_MODE_AP)
  2794. {
  2795. printf(" *WiFi Mode [%s]\r\n", str_wifi_mode[ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode]);
  2796. }
  2797. else
  2798. {
  2799. printf(" *WiFi Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
  2800. }
  2801. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_STATION)
  2802. {
  2803. printf(" - SSID [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid : "NULL");
  2804. printf(" - PWD [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword : "NULL");
  2805. printf(" - TargetMac [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac : "NULL");
  2806. printf(" - RSSI [%d dBm]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi);
  2807. printf(" - DHCP [%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient == 0 ? "Enable" : "Disable");
  2808. printf(" - MAC Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress : "NULL");
  2809. printf(" - IP Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress : "NULL");
  2810. printf(" - SubMask [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress : "NULL");
  2811. printf(" - Gateway [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress : "NULL");
  2812. printf(" - ConnStatus [%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ? "Connected" : "Disconnected");
  2813. }
  2814. }
  2815. // *3G/4G Mode [%s]
  2816. // - APN [%s]
  2817. // - NetworkType[%s]
  2818. // - RSSI [%d dBm]
  2819. // - ChapPapId [%s]
  2820. // - ChapPapPwd [%s]
  2821. // - Modem IMEI [%s]
  2822. // - SIM IMSI [%s]
  2823. // - SIM ICCID [%s]
  2824. // - SIM Status [%s]
  2825. // - Modem Mode [%s]
  2826. // - IP Add [%s]
  2827. // - ConnStatus [%s]
  2828. void Show3G4GInfo(void)
  2829. {
  2830. char *strNetworkType[] = {"Auto", "CDMA", "WCDMA", "LTE", "TD-SCDMA", "UMTS", "CDMA", "HDR", "CDMA/HDR"};
  2831. char *strSimStatus[] = {"No SIM Card", "Valid SIM Card", "Invalid SIM Card"};
  2832. char *strModemMode[] = {"No Services", "CDMA", "GSM/GPRS", "WCDMA", "GSM/WCDMA", "TD_SCDMA", "HSPA", "LTE", "Mode 8", "Unknown"};
  2833. printf(" *3G/4G Mode [%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES ? "Enable" : "Disable");
  2834. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
  2835. {
  2836. printf(" - APN [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn : "NULL");
  2837. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkType <= 8)
  2838. {
  2839. printf(" - NetworkType[%s]\r\n", strNetworkType[ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkType]);
  2840. }
  2841. else
  2842. {
  2843. printf(" - NetworkType[%d]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkType);
  2844. }
  2845. printf(" - RSSI [%d dBm]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
  2846. printf(" - ChapPapId [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId : "NULL");
  2847. printf(" - ChapPapPwd [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd : "NULL");
  2848. printf(" - Modem IMEI [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei : "NULL");
  2849. printf(" - SIM IMSI [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi : "NULL");
  2850. printf(" - SIM ICCID [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid : "NULL");
  2851. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus <= 2)
  2852. {
  2853. printf(" - SIM Status [%s]\r\n", strSimStatus[ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus]);
  2854. }
  2855. else
  2856. {
  2857. printf(" - SIM Status [%d]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus);
  2858. }
  2859. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode <= 9)
  2860. {
  2861. printf(" - Modem Mode [%s]\r\n", strModemMode[ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode]);
  2862. }
  2863. else
  2864. {
  2865. printf(" - Modem Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode);
  2866. }
  2867. printf(" - IP Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress : "NULL");
  2868. printf(" - ConnStatus [%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ? "Connected" : "Disconnected");
  2869. }
  2870. }
  2871. void ShowWebNetworkInfo(void)
  2872. {
  2873. printf("\r\n");
  2874. printf("Web [Network]\r\n");
  2875. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2876. ShowEthernetInfo();
  2877. ShowWiFiInfo();
  2878. Show3G4GInfo();
  2879. }
  2880. void ShowWebEthernetOnly(void)
  2881. {
  2882. printf("\r\n");
  2883. printf("Web [Network]\r\n");
  2884. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2885. ShowEthernetInfo();
  2886. }
  2887. void ShowWebWiFiOnly(void)
  2888. {
  2889. printf("\r\n");
  2890. printf("Web [Network]\r\n");
  2891. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2892. ShowWiFiInfo();
  2893. }
  2894. void ShowWeb3G4GOnly(void)
  2895. {
  2896. printf("\r\n");
  2897. printf("Web [Network]\r\n");
  2898. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2899. Show3G4GInfo();
  2900. }
  2901. void ShowWebBackendInfo(void)
  2902. {
  2903. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  2904. char *str_security_profile[] = {
  2905. "None security",
  2906. "Unsecured Transport with Basic Atuentication",
  2907. "TLS with Basic Authentication",
  2908. "TLS with Client Side Certificates"
  2909. };
  2910. printf("\r\n");
  2911. printf("Web [Backend]\r\n");
  2912. printf(" *Common\r\n");
  2913. printf(" - Backend Timeout : %d s\r\n", ShmSysConfigAndInfo->SysConfig.BackendConnTimeout);
  2914. if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy <= _OFFLINE_POLICY_NO_CHARGING)
  2915. {
  2916. printf(" - Offline Policy : %s\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  2917. }
  2918. else
  2919. {
  2920. printf(" - Offline Policy : %d\r\n", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
  2921. }
  2922. printf(" - OfflineMaxEnergy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy);
  2923. printf(" - OfflineMaxDuration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration);
  2924. printf(" *OCPP\r\n");
  2925. printf(" - OcppStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES ? "Connected" : "Disconnected");
  2926. printf(" - OcppURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  2927. printf(" - ChargeBoxId: %s\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2928. printf(" - Vendor : %s\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2929. if(ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile <= 3)
  2930. {
  2931. printf(" - Security : %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile]);
  2932. }
  2933. else
  2934. {
  2935. printf(" - Security : %d\r\n", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2936. }
  2937. printf(" - MaintainStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus == YES ? "Connected" : "Disconnected");
  2938. printf(" - MaintainURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  2939. if(ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile <= 3)
  2940. {
  2941. printf(" - MaintainSecurity: %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile]);
  2942. }
  2943. else
  2944. {
  2945. printf(" - MaintainSecurity: %d\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile);
  2946. }
  2947. printf(" *TTIA[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES ? "Enable" : "Disable");
  2948. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES)
  2949. {
  2950. printf(" - ServerAddress: %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  2951. printf(" - ServerPort : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  2952. printf(" - BusVenderId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  2953. printf(" - Provider : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  2954. printf(" - CompanyNo : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  2955. printf(" - ChargeBoxId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  2956. printf(" - EVSEStation : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  2957. }
  2958. }
  2959. void ShowWebAllInfo(void)
  2960. {
  2961. ShowWebSystemInfo();
  2962. ShowWebChargingInfo();
  2963. ShowWebNetworkInfo();
  2964. ShowWebBackendInfo();
  2965. }
  2966. void ShowFanSpeed(void)
  2967. {
  2968. printf("\r\n");
  2969. printf("Fan Speed\r\n");
  2970. printf(" *TestFanSpeed : %5d\r\n", ShmFanModuleData->TestFanSpeed);
  2971. printf(" *FanSpeed [Auto]: %5d\r\n", ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed);
  2972. printf(" *FanSpeed Target: %5d\r\n", ShmFanModuleData->SetFan1Speed);
  2973. printf(" *Present Speed\r\n");
  2974. printf(" -Fan 1 Speed : %5d \n", ShmFanModuleData->PresentFan1Speed);
  2975. printf(" -Fan 2 Speed : %5d \n", ShmFanModuleData->PresentFan2Speed);
  2976. printf(" -Fan 3 Speed : %5d \n", ShmFanModuleData->PresentFan3Speed);
  2977. printf(" -Fan 4 Speed : %5d \n", ShmFanModuleData->PresentFan4Speed);
  2978. }
  2979. void ShowWebInfo(char *inputCmd, unsigned int opt)
  2980. {
  2981. int totalCnt = 0, maxPara = 0;
  2982. maxPara = 1;
  2983. totalCnt = GetSubCommand(inputCmd);
  2984. if(totalCnt > maxPara)
  2985. {
  2986. printf("Input cmd fail ------ web [cmd]\r\n\r\n");
  2987. return;
  2988. }
  2989. bool find = false;
  2990. int showItem = 0;
  2991. int itemLen = 10;
  2992. char strItem[32][32] = {"system", "charging", "network", "backend", "all", "eth", "wifi", "4g", "white", "speed"};
  2993. void *actionList[32] = {
  2994. &ShowWebSystemInfo, &ShowWebChargingInfo, &ShowWebNetworkInfo, &ShowWebBackendInfo,
  2995. &ShowWebAllInfo, &ShowWebEthernetOnly, &ShowWebWiFiOnly, &ShowWeb3G4GOnly,
  2996. &ShowWhiteCardList, &ShowFanSpeed};
  2997. void (*ItemAction)();
  2998. for(showItem = 0; showItem < itemLen; showItem++)
  2999. {
  3000. if(strcmp((char *)&strItem[showItem][0], &MultiSubCmd[0][0]) == 0)
  3001. {
  3002. find = true;
  3003. break;
  3004. }
  3005. }
  3006. if(find)
  3007. {
  3008. ItemAction = actionList[showItem];
  3009. ItemAction();
  3010. }
  3011. else
  3012. {
  3013. printf("\r\n");
  3014. printf ("Input cmd fail ------ web [cmd]\r\n");
  3015. for(int i = 0; i < itemLen; i++)
  3016. {
  3017. printf(" [cmd] %s\r\n", (char *)&strItem[i][0]);
  3018. }
  3019. }
  3020. printf("\r\n");
  3021. }
  3022. // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXXXX.XXX kWh, IdTag: [XXXXXXXXXX]
  3023. // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW, TxId: [XXXXXXXXXX]
  3024. // PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Local: XXXXXXX.XXX kWh
  3025. // Start: [0000-00-00 00:00:00] PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Local: XXXXXXX.XXX kWh
  3026. // Gun: XXXX V, XXXX A, Remote: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  3027. // Stop: [0000-00-00 00:00:00] Gun: XXXX V, XXXX A, Remote: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  3028. // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXXXX.XXX kWh, IdTag: [XXXXXXXXXX]
  3029. // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW, TxId: [XXXXXXXXXX]
  3030. // Start: [0000-00-00 00:00:00] PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Ratio: X.XX %
  3031. // Stop: [0000-00-00 00:00:00] Gun: XXXX V, XXXX A, Power: XXXX.X kW, FireV: XXXX.X V
  3032. // Remote: XXXXXXX.XXX kWh, Local: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  3033. void ShowGunInfo(int gun)
  3034. {
  3035. char *str_gun_type[] = {"CHAdeMO", " CCS ", " GBT "};
  3036. #if 0
  3037. printf(" Gun %d (%s) Soc: %3d %s, Energy: %10.3f kWh, IdTag [%20s] Transaction [%d], TotalCost: %.2f\r\n",
  3038. gun + 1,
  3039. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  3040. _chargingData[gun]->EvBatterySoc, "%",
  3041. _chargingData[gun]->PresentChargedEnergy,
  3042. _chargingData[gun]->StartUserId,
  3043. ShmChargerInfo->UserTransaction[gun].TransactionId,
  3044. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost);
  3045. #endif
  3046. //************************************************************************************************
  3047. printf(" Gun %d (%s) Soc: %3d %s, Energy: %11.3f kWh",
  3048. gun + 1,
  3049. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  3050. _chargingData[gun]->EvBatterySoc, "%",
  3051. _chargingData[gun]->PresentChargedEnergy);
  3052. if(strlen((char *)_chargingData[gun]->StartUserId) > 0)
  3053. {
  3054. printf(", IdTag: [%s]", _chargingData[gun]->StartUserId);
  3055. }
  3056. printf("\r\n");
  3057. //************************************************************************************************
  3058. printf(" (%2d) (%s) Target: %4d V, %4d A, Cap: %4d A, %4d kW",
  3059. _chargingData[gun]->SystemStatus,
  3060. _chargingData[gun]->ConnectorPlugIn ? "O" : "X",
  3061. (int)_chargingData[gun]->EvBatterytargetVoltage,
  3062. (int)_chargingData[gun]->EvBatterytargetCurrent,
  3063. (int)(_chargingData[gun]->AvailableChargingCurrent / 10),
  3064. (int)(_chargingData[gun]->AvailableChargingPower / 10));
  3065. if(ShmChargerInfo->UserTransaction[gun].TransactionId > 0)
  3066. {
  3067. printf(", TxId: [%d]", ShmChargerInfo->UserTransaction[gun].TransactionId);
  3068. }
  3069. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost > 0)
  3070. {
  3071. printf(", $: %.2f", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost);
  3072. }
  3073. printf("\r\n");
  3074. //************************************************************************************************
  3075. if(strlen(ShmChargerInfo->Timestamp[gun].StartCharging) > 0)
  3076. {
  3077. printf(" Start: [%s] ", ShmChargerInfo->Timestamp[gun].StartCharging);
  3078. }
  3079. else
  3080. {
  3081. printf(" ");
  3082. }
  3083. printf("PSU: %4d V, %4d A, Limit: %4d A, %4d kW, Ratio: %4.2f %%\r\n",
  3084. (int)(_chargingData[gun]->PresentChargingVoltage),
  3085. (int)(_chargingData[gun]->PresentChargingCurrent),
  3086. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityCurrent / 10),
  3087. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityPower / 10),
  3088. ShmPsuGrouping->GroupCollection[gun].MaxOutputRatio);
  3089. //************************************************************************************************
  3090. if(strlen(ShmChargerInfo->Timestamp[gun].StopCharging) > 0)
  3091. {
  3092. printf(" Stop: [%s] ", ShmChargerInfo->Timestamp[gun].StopCharging);
  3093. }
  3094. else
  3095. {
  3096. printf(" ");
  3097. }
  3098. printf("Gun: %4d V, %4d A, Power: %6.1f kW, FireV: %6.1f V\r\n",
  3099. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingVoltage / 10),
  3100. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingCurrent / 10),
  3101. _chargingData[gun]->PresentChargingPower,
  3102. (_chargingData[gun]->FireChargingVoltage / 10));
  3103. //************************************************************************************************
  3104. printf(" Remote: %11.3f kWh, Local: %11.3f kWh, Meter: %11.3f kWh\r\n",
  3105. ShmChargerInfo->MeterValue[gun].GunConsumption,
  3106. ShmChargerInfo->MeterValue[gun].LocalConsumption,
  3107. _chargingData[gun]->PowerConsumption);
  3108. }
  3109. void ShowInfo(char *inputCmd, unsigned int opt)
  3110. {
  3111. bool keepRun = false;
  3112. bool reflash = false;
  3113. int time = 0;
  3114. struct timespec _Loop_time;
  3115. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  3116. {
  3117. keepRun = true;
  3118. }
  3119. do
  3120. {
  3121. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  3122. if(time >= 1000)
  3123. {
  3124. if(reflash)
  3125. {
  3126. ConsoleReflash(CONNECTOR_QUANTITY, 6);
  3127. }
  3128. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  3129. {
  3130. printf("\r\n");
  3131. ShowGunInfo(i);
  3132. }
  3133. GetClockTime(&_Loop_time);
  3134. if((opt & OPTION_REFLASH) > 0)
  3135. {
  3136. reflash = true;
  3137. }
  3138. }
  3139. if(keepRun)
  3140. {
  3141. keepRun = IsLoopStopCmd() ? false : true;
  3142. usleep(10000);
  3143. }
  3144. }while(keepRun);
  3145. printf("\r\n");
  3146. }
  3147. void RtcSyncCmd(char *inputCmd, unsigned int opt)
  3148. {
  3149. int totalCnt = 0, maxPara = 0;
  3150. char hostAdd[32];
  3151. int dispenser = 0, offset = 0;
  3152. memset(hostAdd, 0x00, sizeof(hostAdd));
  3153. maxPara = 2;
  3154. totalCnt = GetSubCommand(inputCmd);
  3155. if(totalCnt != maxPara)
  3156. {
  3157. printf("Input cmd fail ------ rtc [dispenser 1-4] [offset minute]\r\n\r\n");
  3158. return;
  3159. }
  3160. printf("\r\n");
  3161. dispenser = atoi(&MultiSubCmd[0][0]);
  3162. offset = atoi(&MultiSubCmd[1][0]);
  3163. if(dispenser <= 0 || dispenser > CONNECTOR_QUANTITY)
  3164. {
  3165. printf("dispenser %d over range\r\n\r\n", dispenser);
  3166. return;
  3167. }
  3168. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser - 1].LocalStatus == _DS_None ||
  3169. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser - 1].LocalStatus == _DS_Timeout)
  3170. {
  3171. printf("dispenser %d is not available\r\n\r\n", dispenser);
  3172. return;
  3173. }
  3174. // find dispenser ip address
  3175. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  3176. {
  3177. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
  3178. {
  3179. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex == (dispenser - 1))
  3180. {
  3181. sprintf(hostAdd, "%d.%d.%d.%d",
  3182. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 0) &0xFF),
  3183. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 8) &0xFF),
  3184. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) &0xFF),
  3185. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) &0xFF));
  3186. }
  3187. }
  3188. }
  3189. if(strlen(hostAdd) == 0)
  3190. {
  3191. printf("dispenser %d ip is not available\r\n\r\n", dispenser);
  3192. return;
  3193. }
  3194. printf("try sycn dispenser %d [%s] rtc, offset: %d minutes\r\n", dispenser, hostAdd, offset);
  3195. // get current time and create offset time
  3196. time_t timep;
  3197. struct tm *tm;
  3198. time(&timep);
  3199. tm = localtime(&timep);
  3200. printf(" NowTime: %d/%02d/%02d %02d:%02d:%02d\r\n",
  3201. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3202. if(offset != 0)
  3203. {
  3204. timep += (offset * 60);
  3205. tm = localtime(&timep);
  3206. printf("OffsetTime: %d/%02d/%02d %02d:%02d:%02d\r\n\r\n",
  3207. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3208. }
  3209. // create send socket
  3210. int rtcfd = 0;
  3211. struct sockaddr_in serverInfo;
  3212. struct timeval tv;
  3213. char rtcTxBuffer[64];
  3214. char rtcRxBuffer[64];
  3215. int txLen = 0, rxLen = 0;
  3216. unsigned char chksum = 0x00;
  3217. rtcfd = socket(AF_INET, SOCK_STREAM, 0);
  3218. if (rtcfd < 0)
  3219. {
  3220. printf("create rtc socket fail\r\n\r\n");
  3221. return;
  3222. }
  3223. memset(rtcTxBuffer, 0x00, sizeof(rtcTxBuffer));
  3224. memset(rtcRxBuffer, 0x00, sizeof(rtcRxBuffer));
  3225. tv.tv_sec = 3;
  3226. tv.tv_usec = 0;
  3227. setsockopt(rtcfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); //設定等待3s
  3228. setsockopt(rtcfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval)); //設定傳送3s
  3229. bzero(&serverInfo,sizeof(serverInfo));
  3230. serverInfo.sin_family = AF_INET;
  3231. serverInfo.sin_addr.s_addr = inet_addr(hostAdd);
  3232. serverInfo.sin_port = htons(8234);
  3233. if(connect(rtcfd, (struct sockaddr *)&serverInfo, sizeof(serverInfo)) < 0)
  3234. {
  3235. printf("connect to host: %s fail\r\n\r\n", hostAdd);
  3236. close(rtcfd);
  3237. return;
  3238. }
  3239. // set tx header & data
  3240. rtcTxBuffer[0] = 0xAA; // Frame ID
  3241. rtcTxBuffer[1] = 0x00; // Master address
  3242. rtcTxBuffer[2] = 0xFF; // Slave address
  3243. rtcTxBuffer[3] = 0x87; // 0x87
  3244. rtcTxBuffer[4] = 0x0E; // Length_Low
  3245. rtcTxBuffer[5] = 0x00; // Length_High
  3246. sprintf(&rtcTxBuffer[6], "%04d%02d%02d%02d%02d%02d",
  3247. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3248. txLen = rtcTxBuffer[4] + (rtcTxBuffer[5] << 8);
  3249. chksum = 0;
  3250. for(int i = 0; i < txLen; i++)
  3251. {
  3252. chksum ^= rtcTxBuffer[6 + i];
  3253. }
  3254. rtcTxBuffer[6 + txLen] = chksum;
  3255. send(rtcfd, rtcTxBuffer, txLen + 7, MSG_NOSIGNAL);
  3256. // receive
  3257. if(recv(rtcfd, &rtcRxBuffer[0], 6, MSG_WAITALL) < 0)
  3258. {
  3259. printf("read head fail\r\n\r\n");
  3260. close(rtcfd);
  3261. return;
  3262. }
  3263. rxLen = rtcRxBuffer[4] + (rtcRxBuffer[5] << 8);
  3264. if(recv(rtcfd, &rtcRxBuffer[6], rxLen + 1, MSG_WAITALL) < 0)
  3265. {
  3266. printf("read data fail\r\n\r\n");
  3267. close(rtcfd);
  3268. return;
  3269. }
  3270. chksum = 0;
  3271. for(int i = 0; i < rxLen; i++)
  3272. {
  3273. chksum ^= rtcRxBuffer[6 + i];
  3274. }
  3275. if(chksum == rtcRxBuffer[6 + rxLen])
  3276. {
  3277. printf("set %s rtc: ", hostAdd);
  3278. for(int i = 0; i < txLen; i++)
  3279. {
  3280. printf("%c", rtcTxBuffer[6 + i]);
  3281. }
  3282. printf(" %s\r\n\r\n", rtcRxBuffer[6] == 0x01 ? "success" : "fail");
  3283. }
  3284. else
  3285. {
  3286. printf("receive rtc checksum fail\r\n\r\n");
  3287. }
  3288. close(rtcfd);
  3289. }
  3290. void ParsingModelName(char *modelName)
  3291. {
  3292. ParsingRatedCur parsingRatedCur = {0};
  3293. RateCurInfo *pRatedCurInfo = NULL;
  3294. if(RatedCurrentParsing(modelName, &parsingRatedCur) != PASS)
  3295. {
  3296. printf("Parsing [%s] failed\r\n", modelName);
  3297. return;
  3298. }
  3299. printf("Model Name: [%s]\r\n", modelName);
  3300. for(int i = 0; i < 2; i++)
  3301. {
  3302. pRatedCurInfo = (RateCurInfo *)&parsingRatedCur.ParsingInfo[i];
  3303. printf(" Gun %d Type %d, MaxVol: %d, MaxCur: %d\r\n",
  3304. i + 1, pRatedCurInfo->GunType, pRatedCurInfo->Voltage, pRatedCurInfo->Current);
  3305. }
  3306. }
  3307. void ParsingModelNameCmd(char *inputCmd, unsigned int opt)
  3308. {
  3309. int totalCnt = 0, maxPara = 0;
  3310. maxPara = 1;
  3311. totalCnt = GetSubCommand(inputCmd);
  3312. if(totalCnt > maxPara)
  3313. {
  3314. printf("Input cmd fail ------ pmodel [model_name]\r\n\r\n");
  3315. return;
  3316. }
  3317. printf("\r\n");
  3318. if(totalCnt != 0)
  3319. {
  3320. ParsingModelName(&MultiSubCmd[0][0]);
  3321. }
  3322. else
  3323. {
  3324. printf("Cabinet\r\n");
  3325. ParsingModelName((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  3326. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  3327. {
  3328. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  3329. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  3330. {
  3331. printf("\r\n");
  3332. printf("Dispenser %d\r\n", i + 1);
  3333. ParsingModelName((char *)&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName[0]);
  3334. }
  3335. }
  3336. }
  3337. printf("\r\n");
  3338. }
  3339. void CustomerPriceTest(char *inputCmd, unsigned int opt)
  3340. {
  3341. #if 0
  3342. char priceString[512];
  3343. float price = 0;
  3344. printf("\r\n");
  3345. // running cost
  3346. printf("Running Cost\r\n");
  3347. strcpy(priceString, "Connection Fee: $0 NTD; Session Fee: $15.96 NTD; Occupancy Fee: $0 NTD; Total Cost: $15.96 NTD; Account Balance: $37693 NTD");
  3348. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3349. printf("Connection Fee: %.2f\r\n", price);
  3350. price = PriceParsing((char *)priceString, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
  3351. printf("Session Fee: %.2f\r\n", price);
  3352. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3353. printf("Occupancy Fee: %.2f\r\n", price);
  3354. price = PriceParsing((char *)priceString, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
  3355. printf("Total Cost: %.2f\r\n", price);
  3356. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3357. printf("Account Balance: %.2f\r\n", price);
  3358. // final cost
  3359. printf("Final Cost\r\n");
  3360. strcpy(priceString, "Connection Fee: $0 NTD; Session Fee: $283.68 NTD; Occupancy Fee: $0 NTD; Total Cost: $283.68 NTD; Account Balance: $37410 NTD");
  3361. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3362. printf("Connection Fee: %.2f\r\n", price);
  3363. price = PriceParsing((char *)priceString, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
  3364. printf("Session Fee: %.2f\r\n", price);
  3365. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3366. printf("Occupancy Fee: %.2f\r\n", price);
  3367. price = PriceParsing((char *)priceString, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
  3368. printf("Total Cost: %.2f\r\n", price);
  3369. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3370. printf("Account Balance: %.2f\r\n", price);
  3371. // user price
  3372. printf("User Price\r\n");
  3373. strcpy(priceString, "Connection Fee: $0 NTD/time; Current Rate: $12 NTD/kWh; Occupancy Fee: $0 NTD/hr; Account Balance: $17553 NTD");
  3374. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3375. printf("Connection Fee: %.2f\r\n", price);
  3376. price = PriceParsing((char *)priceString, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
  3377. printf("Current Rate: %.2f\r\n", price);
  3378. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3379. printf("Occupancy Fee: %.2f\r\n", price);
  3380. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3381. printf("Account Balance: %.2f\r\n", price);
  3382. // default price
  3383. printf("Default Price\r\n");
  3384. strcpy(priceString, "Connection Fee: $0 NTD/time; Current Rate: $12 NTD/kWh; Occupancy Fee: $0 NTD/hr");
  3385. price = PriceParsing(priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3386. printf("Connection Fee: %.2f\r\n", price);
  3387. price = PriceParsing(priceString, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
  3388. printf("Current Rate: %.2f\r\n", price);
  3389. price = PriceParsing(priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3390. printf("Occupancy Fee: %.2f\r\n", price);
  3391. printf("\r\n");
  3392. printf("TCC Default Price\r\n");
  3393. strcpy(priceString, "$ 12/kWh");
  3394. price = PriceParsing(priceString, "", "");
  3395. printf("Default: %.2f\r\n", price);
  3396. printf("\r\n");
  3397. char userPrice[512];
  3398. printf("Shell Default Price\r\n");
  3399. strcpy(priceString, "100.0 kW\nPrice\nTransaction Fee: $0.6165/Flat\nIdle Fee: $0.5/Flat\n\n100.0 kW\nPrice\nTransaction Fee: $0.6165/Flat\nIdle Fee: $0.5/Flat\n\n");
  3400. ShellPriceParsing(priceString, userPrice);
  3401. printf("DefaultPrice: %s\r\n", userPrice);
  3402. printf("\r\n");
  3403. printf("Shell User Price\r\n");
  3404. ShellPriceParsing(priceString, userPrice);
  3405. printf("UserPrice: %s\r\n", userPrice);
  3406. printf("\r\n");
  3407. strcpy(priceString, "Current Period Price:$0.35/kWh\nCurrent Idle Fee: $5.0/hr\nCurrent Total: 2.70kWh $2.53 ConnectorId: 1\nLast update: 2021-06-28T11:22:31");
  3408. price = ShellRunningCostParsing(priceString);
  3409. printf("Shell Running Cost\r\n");
  3410. printf("Cost: %.2f\r\n", price);
  3411. printf("\r\n");
  3412. strcpy(priceString, "2022-01-18 07:00:00-2022-01-18 08:15:30\n07:00 AM $1.00/kWh 4.30kWh Cost: $4.300\n07:30 AM $2.00/kWh 0.00kWh Cost: $4.300\n07:46 AM $0.00/Flat 10m Cost: $0.000\n07:56 AM $0.50/Flat 19m Cost: $0.500\nTotal\nSale: $4.80\nTax: $0.00\nTransaction Fee: $0.62\nDiscount: $0.00\nCost: $5.42\nEnergy: 4.3000kWh\nTime: 1 Hrs 15 Mins\nPayment: RFID\nReceipt: https://qa.qa.greenlotstest-qa.com/greenlots/receipt.jsf?session5658739 | Call 1 800 Greenlots or check app for more detailed receipt\nEV_DISCONNECTED");
  3413. printf("Shell Final Cost\r\n");
  3414. int urlLen = 0;
  3415. char url[512];
  3416. price = ShellFinalCostParsing(priceString);
  3417. urlLen = GetShellReceiptInfo(priceString, url);
  3418. printf("Cost: %.2f\r\n", price);
  3419. if(urlLen > 0)
  3420. {
  3421. printf("Receipt: [%s]\r\n", url);
  3422. }
  3423. #endif
  3424. }
  3425. void EvCommMsgDebug(char *inputCmd, unsigned int opt)
  3426. {
  3427. int totalCnt = 0, maxPara = 0;
  3428. maxPara = 2;
  3429. totalCnt = GetSubCommand(inputCmd);
  3430. printf("\r\n");
  3431. if(totalCnt == 1)
  3432. {
  3433. if(strcmp(&MultiSubCmd[0][0], "clean") == 0)
  3434. {
  3435. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0] = 0;
  3436. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1] = 0;
  3437. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2] = 0;
  3438. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3] = 0;
  3439. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = false;
  3440. printf("Clean All EvComm Msg Flag\r\n");
  3441. printf("Disable MsgEvComm Flag Debug\r\n\r\n");
  3442. return;
  3443. }
  3444. }
  3445. if(totalCnt != maxPara)
  3446. {
  3447. printf("Input cmd fail ------ evmsg [reg] [enable 0-1]\r\n\r\n");
  3448. return;
  3449. }
  3450. bool find = false;
  3451. int reg = 0, enable = 0;
  3452. if(strncmp(&MultiSubCmd[0][0], "0x", 2) == EQUAL && strlen(&MultiSubCmd[0][0]) > 2)
  3453. {
  3454. reg = (int)strtol(&MultiSubCmd[0][0], NULL, 16);
  3455. }
  3456. else
  3457. {
  3458. reg = atoi(&MultiSubCmd[0][0]);
  3459. }
  3460. if(strcmp(&MultiSubCmd[1][0], "enable") == EQUAL)
  3461. {
  3462. enable = 1;
  3463. }
  3464. else if(strcmp(&MultiSubCmd[1][0], "disable") == EQUAL)
  3465. {
  3466. enable = 0;
  3467. }
  3468. else
  3469. {
  3470. enable = atoi(&MultiSubCmd[1][0]);
  3471. }
  3472. if(enable > 1 || enable < 0)
  3473. {
  3474. printf("enable(%d) out of range\r\n\r\n", enable);
  3475. return;
  3476. }
  3477. if(reg >= _Reg_Dispenser_Model_Name && reg < _Reg_None)
  3478. {
  3479. find = true;
  3480. if(enable)
  3481. {
  3482. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[reg / 32] |= (1 << (reg % 32));
  3483. printf("Set EvComm Msg Flag: 0x%02X\r\n", reg);
  3484. }
  3485. else
  3486. {
  3487. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[reg / 32] &= ~(1 << (reg % 32));
  3488. printf("Clean EvComm Msg Flag: 0x%02X\r\n", reg);
  3489. }
  3490. }
  3491. else
  3492. {
  3493. if(strcmp(&MultiSubCmd[0][0], "all") == 0)
  3494. {
  3495. find = true;
  3496. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.bits.RegDbg_All = enable;
  3497. printf("%s EvComm All Msg Flag\r\n", enable ? "Enable" : "Disable");
  3498. }
  3499. }
  3500. if(find)
  3501. {
  3502. printf("EvCommMsg[0]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0]);
  3503. printf("EvCommMsg[1]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1]);
  3504. printf("EvCommMsg[2]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2]);
  3505. printf("EvCommMsg[3]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3]);
  3506. printf("\r\n");
  3507. if(ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0] ||
  3508. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1] ||
  3509. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2] ||
  3510. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3])
  3511. {
  3512. if(!ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm)
  3513. {
  3514. printf("Enable MsgEvComm Flag Debug\r\n\r\n");
  3515. }
  3516. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = true;
  3517. }
  3518. else
  3519. {
  3520. if(ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm)
  3521. {
  3522. printf("Disable MsgEvComm Flag Debug\r\n\r\n");
  3523. }
  3524. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = false;
  3525. }
  3526. }
  3527. else
  3528. {
  3529. printf("reg: 0x%02X out of range\r\n", reg);
  3530. printf("\r\n");
  3531. }
  3532. }
  3533. void EvCommIdDebug(char *inputCmd, unsigned int opt)
  3534. {
  3535. int totalCnt = 0, maxPara = 0;
  3536. maxPara = 2;
  3537. totalCnt = GetSubCommand(inputCmd);
  3538. printf("\r\n");
  3539. if(totalCnt != maxPara)
  3540. {
  3541. printf("Input cmd fail ------ evid [id] [enable 0-1]\r\n\r\n");
  3542. return;
  3543. }
  3544. int id = 0, enable = 0;
  3545. id = atoi(&MultiSubCmd[0][0]);
  3546. if(strcmp(&MultiSubCmd[1][0], "enable") == EQUAL)
  3547. {
  3548. enable = 1;
  3549. }
  3550. else if(strcmp(&MultiSubCmd[1][0], "disable") == EQUAL)
  3551. {
  3552. enable = 0;
  3553. }
  3554. else
  3555. {
  3556. enable = atoi(&MultiSubCmd[1][0]);
  3557. }
  3558. if(enable > 1 || enable < 0)
  3559. {
  3560. printf("enable(%d) out of range\r\n\r\n", enable);
  3561. return;
  3562. }
  3563. if(id > 0 && id <= CONNECTOR_QUANTITY)
  3564. {
  3565. if(enable)
  3566. {
  3567. ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal |= (1 << id);
  3568. printf("Set EvComm ID %d Enable\r\n", id);
  3569. }
  3570. else
  3571. {
  3572. ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal &= ~(1 << id);
  3573. printf("Clean EvComm ID %d\r\n", id);
  3574. }
  3575. printf("EvComm ID: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal);
  3576. printf("\r\n");
  3577. }
  3578. else
  3579. {
  3580. printf("id(%d) out of range\r\n\r\n", id);
  3581. }
  3582. }
  3583. bool SetModelName(char *modelName)
  3584. {
  3585. if(!IsCabinetModelNameLegal(modelName))
  3586. {
  3587. printf("Model Name: [%s] is Illegal\r\n", modelName);
  3588. return false;
  3589. }
  3590. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.ModelName, modelName, MODELNAME_LENGTH);
  3591. printf("Set Model Name: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.ModelName);
  3592. return true;
  3593. }
  3594. bool SetSerialNumber(char *serialNumber)
  3595. {
  3596. if(!IsSerialNumberLegal(serialNumber))
  3597. {
  3598. printf("Serial Number: [%s] is Illegal\r\n", serialNumber);
  3599. return false;
  3600. }
  3601. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.SerialNumber, serialNumber, SERIAL_NUMBER_LENGTH);
  3602. printf("Set Serial Number: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3603. return true;
  3604. }
  3605. bool SetSystemID(char *systemId)
  3606. {
  3607. if(!IsSystemIdLegal(systemId))
  3608. {
  3609. printf("System ID: [%s] is Illegal\r\n", systemId);
  3610. return false;
  3611. }
  3612. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  3613. printf("Set System ID: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  3614. return true;
  3615. }
  3616. bool CleanSystemID(void)
  3617. {
  3618. memset((char *)&ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.SystemId));
  3619. printf("Clean System ID OK\r\n");
  3620. return true;
  3621. }
  3622. bool SetAuthorisationMode(char *mode)
  3623. {
  3624. bool disable = false;
  3625. if(strcmp(mode, "disable") == EQUAL)
  3626. {
  3627. disable = true;
  3628. }
  3629. else
  3630. {
  3631. if(strcmp(mode, "enable") != EQUAL)
  3632. {
  3633. printf("Authorisation Mode: [%s] is Illegal\r\n", mode);
  3634. printf(" [value] enable | disable\r\n");
  3635. return false;
  3636. }
  3637. }
  3638. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = disable;
  3639. printf("Set Authorisation Mode: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.AuthorisationMode == 0 ? "Enable" : "Disable");
  3640. if(disable && ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID)
  3641. {
  3642. printf("AuthorisationMode Is Disable, AuthrizeByEVCCID Need To Set Disable\r\n");
  3643. ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID = false;
  3644. }
  3645. return true;
  3646. }
  3647. bool SetAuthrizeByEVCCID(char *isEVCCID)
  3648. {
  3649. bool enable = false;
  3650. if(strcmp(isEVCCID, "enable") == EQUAL)
  3651. {
  3652. enable = true;
  3653. }
  3654. else
  3655. {
  3656. if(strcmp(isEVCCID, "disable") != EQUAL)
  3657. {
  3658. printf("Authrize By EVCCID: [%s] is Illegal\r\n", isEVCCID);
  3659. printf(" [value] enable | disable\r\n");
  3660. return false;
  3661. }
  3662. }
  3663. if(enable && ShmSysConfigAndInfo->SysConfig.AuthorisationMode == 1)
  3664. {
  3665. printf("AuthorisationMode Is Disable, Reset AuthrizeByEVCCID To Disable\r\n");
  3666. enable = false;
  3667. }
  3668. ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID = enable;
  3669. printf("Set AuthrizeByEVCCID: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID ? "Enable" : "Disable");
  3670. return true;
  3671. }
  3672. bool SetQRCodeMadeMode(char *qrCodeMode)
  3673. {
  3674. bool customized = false;
  3675. if(strcmp(qrCodeMode, "customized") == EQUAL)
  3676. {
  3677. customized = true;
  3678. }
  3679. else
  3680. {
  3681. if(strcmp(qrCodeMode, "default") != EQUAL)
  3682. {
  3683. printf("QR Code Made Mode: [%s] is Illegal\r\n", qrCodeMode);
  3684. printf(" [value] default | customized\r\n");
  3685. return false;
  3686. }
  3687. }
  3688. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = customized;
  3689. printf("Set QRCodeMadeMode: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode ? "Customized" : "Default");
  3690. return true;
  3691. }
  3692. bool SetQRCodeContent(char *content)
  3693. {
  3694. if(strlen(content) >= sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent))
  3695. {
  3696. printf("QR Code Content: [%s] is Out Of Length\r\n", content);
  3697. return false;
  3698. }
  3699. memset((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent));
  3700. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, content, strlen(content));
  3701. printf("Set QRCodeContent: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  3702. return true;
  3703. }
  3704. bool CleanQRCodeContent(void)
  3705. {
  3706. memset((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent));
  3707. printf("Clean QRCode Content OK\r\n");
  3708. return true;
  3709. }
  3710. bool SetLEDIntensity(char *intensity)
  3711. {
  3712. int ledIntensity = _LED_INTENSITY_DARKEST;
  3713. char *strIntensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  3714. if(strcmp(intensity, "brightest") == EQUAL)
  3715. {
  3716. ledIntensity = _LED_INTENSITY_BRIGHTEST;
  3717. }
  3718. else if(strcmp(intensity, "medium") == EQUAL)
  3719. {
  3720. ledIntensity = _LED_INTENSITY_MEDIUM;
  3721. }
  3722. else if(strcmp(intensity, "darkest") != EQUAL)
  3723. {
  3724. printf("LED Intensity: [%s] is Illegal\r\n", intensity);
  3725. printf(" [value] darkest | medium | brightest\r\n");
  3726. return false;
  3727. }
  3728. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = ledIntensity;
  3729. printf("Set LED Intensity: [%s] OK\r\n", strIntensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  3730. return true;
  3731. }
  3732. bool SetMaxChargingEnergy(char *energy)
  3733. {
  3734. int _energy = 0;
  3735. _energy = atoi(energy);
  3736. if(_energy < 0)
  3737. {
  3738. printf("MaxChargingEnergy: [%s] is Illegal\r\n", energy);
  3739. printf(" [value] > 0\r\n");
  3740. return false;
  3741. }
  3742. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = _energy;
  3743. printf("Set MaxChargingEnergy: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
  3744. return true;
  3745. }
  3746. bool SetMaxChargingPower(char *power)
  3747. {
  3748. int _power = 0;
  3749. _power = atoi(power);
  3750. if(_power < 0)
  3751. {
  3752. printf("MaxChargingEnergy: [%s] is Illegal\r\n", power);
  3753. printf(" [value] > 0\r\n");
  3754. return false;
  3755. }
  3756. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = _power;
  3757. printf("Set MaxChargingPower: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
  3758. return true;
  3759. }
  3760. bool SetMaxChargingCurrent(char *current)
  3761. {
  3762. int _current = 0;
  3763. _current = atoi(current);
  3764. if(_current < 0)
  3765. {
  3766. printf("MaxChargingEnergy: [%s] is Illegal\r\n", current);
  3767. printf(" [value] > 0\r\n");
  3768. return false;
  3769. }
  3770. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = _current;
  3771. printf("Set MaxChargingCurrent: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  3772. return true;
  3773. }
  3774. bool SetMaxChargingDuration(char *duration)
  3775. {
  3776. int _duration = 0;
  3777. _duration = atoi(duration);
  3778. if(_duration < 0)
  3779. {
  3780. printf("MaxChargingDuration: [%s] is Illegal\r\n", duration);
  3781. printf(" [value] > 0\r\n");
  3782. return false;
  3783. }
  3784. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = _duration;
  3785. printf("Set MaxChargingDuration: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  3786. return true;
  3787. }
  3788. bool SetMaxChargingSoc(char *soc)
  3789. {
  3790. int _soc = 0;
  3791. _soc = atoi(soc);
  3792. if(_soc < 0 || _soc > 100)
  3793. {
  3794. printf("MaxChargingSoc: [%s] is Illegal\r\n", soc);
  3795. printf(" [value] 0 ~ 100\r\n");
  3796. return false;
  3797. }
  3798. ShmSysConfigAndInfo->SysConfig.MaxChargingSoc = _soc;
  3799. printf("Set MaxChargingSoc: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
  3800. return true;
  3801. }
  3802. bool SetStopChargingByButton(char *btn)
  3803. {
  3804. bool enable = false;
  3805. if(strcmp(btn, "enable") == EQUAL)
  3806. {
  3807. enable = true;
  3808. }
  3809. else
  3810. {
  3811. if(strcmp(btn, "disable") != EQUAL)
  3812. {
  3813. printf("Stop Charging By Button: [%s] is Illegal\r\n", btn);
  3814. printf(" [value] enable | disable\r\n");
  3815. return false;
  3816. }
  3817. }
  3818. ShmSysConfigAndInfo->SysConfig.StopChargingByButton = enable;
  3819. printf("Set Stop Charging By Button: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton ? "Enable" : "Disable");
  3820. return true;
  3821. }
  3822. bool SetOfflinePolicy(char *policy)
  3823. {
  3824. int offlinePolicy = _OFFLINE_POLICY_LOCAL_LIST;
  3825. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  3826. if(strcmp(policy, "free") == EQUAL)
  3827. {
  3828. offlinePolicy = _OFFLINE_POLICY_FREE_CHARGING;
  3829. }
  3830. else if(strcmp(policy, "nocharging") == EQUAL)
  3831. {
  3832. offlinePolicy = _OFFLINE_POLICY_NO_CHARGING;
  3833. }
  3834. else if(strcmp(policy, "local") != EQUAL)
  3835. {
  3836. printf("Offline Policy: [%s] is Illegal\r\n", policy);
  3837. printf(" [value] local | rfid | free | nocharging\r\n");
  3838. return false;
  3839. }
  3840. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = offlinePolicy;
  3841. printf("Set Offline Policy: [%s] OK\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  3842. return true;
  3843. }
  3844. bool SetOcppServerURL(char *url)
  3845. {
  3846. if(strlen(url) >= sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL))
  3847. {
  3848. printf("Ocpp Server URL: [%s] is Out Of Length\r\n", url);
  3849. return false;
  3850. }
  3851. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  3852. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, url);
  3853. printf("Set Ocpp Server URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  3854. return true;
  3855. }
  3856. bool CleanOcppServerURL(void)
  3857. {
  3858. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  3859. printf("Clean Ocpp Server URL OK\r\n");
  3860. return true;
  3861. }
  3862. bool SetChargeBoxId(char *boxId)
  3863. {
  3864. if(strlen(boxId) >= sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId))
  3865. {
  3866. printf("Charge Box Id: [%s] is Out Of Length\r\n", boxId);
  3867. return false;
  3868. }
  3869. memset((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  3870. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, boxId);
  3871. printf("Set Charge Box Id: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  3872. return true;
  3873. }
  3874. bool CleanChargeBoxId(void)
  3875. {
  3876. memset((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  3877. printf("Clean Charge Box Id OK\r\n");
  3878. return true;
  3879. }
  3880. bool SetChargePointVendor(char *vendor)
  3881. {
  3882. if(strlen(vendor) >= sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor))
  3883. {
  3884. printf("Charge Point Vendor: [%s] is Out Of Length\r\n", vendor);
  3885. return false;
  3886. }
  3887. memset((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  3888. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, vendor);
  3889. printf("Set Charge Point Vendor: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3890. return true;
  3891. }
  3892. bool CleanChargePointVendor(void)
  3893. {
  3894. memset((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  3895. printf("Clean Charge Point Vendor OK\r\n");
  3896. return true;
  3897. }
  3898. bool SetOcppReceiptrURL(char *receipt)
  3899. {
  3900. if(strlen(receipt) >= sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL))
  3901. {
  3902. printf("Ocpp Receiptr URL: [%s] is Out Of Length\r\n", receipt);
  3903. return false;
  3904. }
  3905. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL));
  3906. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, receipt);
  3907. printf("Set Ocpp Receiptr URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL);
  3908. return true;
  3909. }
  3910. bool CleanOcppReceiptrURL(void)
  3911. {
  3912. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL));
  3913. printf("Clean Ocpp Receiptr URL OK\r\n");
  3914. return true;
  3915. }
  3916. bool SetMaintainServerURL(char *url)
  3917. {
  3918. if(strlen(url) >= sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL))
  3919. {
  3920. printf("Maintain Server URL: [%s] is Out Of Length\r\n", url);
  3921. return false;
  3922. }
  3923. memset((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  3924. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, url);
  3925. printf("Set Maintain Server URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  3926. return true;
  3927. }
  3928. bool CleanMaintainServerURL(void)
  3929. {
  3930. memset((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  3931. printf("Clean Maintain Server URL OK\r\n");
  3932. return true;
  3933. }
  3934. bool SetFanControlPolicy(char *policy)
  3935. {
  3936. int _FanMode = _FAN_POLICY_AUTO_MODE;
  3937. char *strFanMode[] = {STR_FAN_AUTO_MODE, STR_FAN_QUITE_MODE};
  3938. if(strcmp(policy, "auto") == EQUAL)
  3939. {
  3940. _FanMode = _FAN_POLICY_AUTO_MODE;
  3941. }
  3942. else if(strcmp(policy, "quite") == EQUAL)
  3943. {
  3944. _FanMode = _FAN_POLICY_QUITE_MODE;
  3945. }
  3946. else
  3947. {
  3948. printf("Fan Policy: [%s] is Illegal\r\n", policy);
  3949. printf(" [value] auto | quite\r\n");
  3950. return false;
  3951. }
  3952. ShmSysConfigAndInfo->SysConfig.FanControlPolicy = _FanMode;
  3953. printf("Set Fan Policy: [%s] OK\r\n", strFanMode[ShmSysConfigAndInfo->SysConfig.FanControlPolicy]);
  3954. return true;
  3955. }
  3956. void FlashSetCmd(char *inputCmd, unsigned int opt)
  3957. {
  3958. char subMain[MAX_SUB_CMD_LENGTH];
  3959. char subSub[MAX_SUB_CMD_LENGTH];
  3960. memset(subMain, 0x00, sizeof(subMain));
  3961. memset(subSub, 0x00, sizeof(subSub));
  3962. bool find = false;
  3963. int actIndex = 0;
  3964. int maxLen = 21;
  3965. char strWriteItem[32][32] = {
  3966. "model", "sn", "sysid", "auth", "evccid", "qrmode", "qrcode", "led",
  3967. "energy", "power", "current", "time", "soc", "stopbtn", "policy", "backend",
  3968. "boxid", "vendor", "receipt", "maintain", "fan"};
  3969. bool (*writeFlashList[32])(char *) = {
  3970. &SetModelName, &SetSerialNumber, &SetSystemID, &SetAuthorisationMode,
  3971. &SetAuthrizeByEVCCID, &SetQRCodeMadeMode, &SetQRCodeContent, &SetLEDIntensity,
  3972. &SetMaxChargingEnergy, &SetMaxChargingPower, &SetMaxChargingCurrent, &SetMaxChargingDuration,
  3973. &SetMaxChargingSoc, &SetStopChargingByButton, &SetOfflinePolicy, &SetOcppServerURL,
  3974. &SetChargeBoxId, &SetChargePointVendor, &SetOcppReceiptrURL, &SetMaintainServerURL,
  3975. &SetFanControlPolicy};
  3976. bool (*WriteFlashAct)(char *);
  3977. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3978. {
  3979. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3980. {
  3981. if(strcmp((char *)&strWriteItem[actIndex][0], subMain) == 0)
  3982. {
  3983. find = true;
  3984. break;
  3985. }
  3986. }
  3987. if(find)
  3988. {
  3989. printf("\r\n");
  3990. WriteFlashAct = writeFlashList[actIndex];
  3991. WriteFlashAct(subSub);
  3992. printf("\r\n");
  3993. return;
  3994. }
  3995. }
  3996. printf("\r\n");
  3997. printf("Input cmd fail ------ model [set] [cmd] [value]\r\n");
  3998. printf(" [cmd]");
  3999. for(actIndex = 0; actIndex < maxLen; actIndex++)
  4000. {
  4001. printf("%s%s", actIndex == 0 ? " " : " | ", &strWriteItem[actIndex][0]);
  4002. }
  4003. printf("\r\n\r\n");
  4004. }
  4005. void FlashCleanCmd(char *inputCmd, unsigned int opt)
  4006. {
  4007. char subMain[MAX_SUB_CMD_LENGTH];
  4008. char subSub[MAX_SUB_CMD_LENGTH];
  4009. memset(subMain, 0x00, sizeof(subMain));
  4010. memset(subSub, 0x00, sizeof(subSub));
  4011. bool find = false;
  4012. int actIndex = 0;
  4013. int maxLen = 7;
  4014. char strCleanItem[32][32] = {
  4015. "sysid", "qrcode", "backend", "boxid", "vendor", "receipt", "maintain"};
  4016. bool (*cleanFlashList[32])() = {
  4017. &CleanSystemID, &CleanQRCodeContent, &CleanOcppServerURL, &CleanChargeBoxId,
  4018. &CleanChargePointVendor, &CleanOcppReceiptrURL, &CleanMaintainServerURL};
  4019. bool (*CleanFlashAct)();
  4020. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  4021. {
  4022. for(actIndex = 0; actIndex < maxLen; actIndex++)
  4023. {
  4024. if(strcmp((char *)&strCleanItem[actIndex][0], subMain) == 0)
  4025. {
  4026. find = true;
  4027. break;
  4028. }
  4029. }
  4030. if(find)
  4031. {
  4032. printf("\r\n");
  4033. CleanFlashAct = cleanFlashList[actIndex];
  4034. CleanFlashAct();
  4035. printf("\r\n");
  4036. return;
  4037. }
  4038. }
  4039. printf("\r\n");
  4040. printf("Input cmd fail ------ model [clean] [cmd]\r\n");
  4041. printf(" [cmd]");
  4042. for(actIndex = 0; actIndex < maxLen; actIndex++)
  4043. {
  4044. printf("%s%s", actIndex == 0 ? " " : " | ", &strCleanItem[actIndex][0]);
  4045. }
  4046. printf("\r\n\r\n");
  4047. }
  4048. void FlashWriteCmd(char *inputCmd, unsigned int opt)
  4049. {
  4050. if(strcmp(inputCmd, "now") == EQUAL)
  4051. {
  4052. printf("\r\n");
  4053. printf("Write Flash Immediately\r\n\r\n");
  4054. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  4055. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  4056. }
  4057. else
  4058. {
  4059. printf("\r\n");
  4060. printf("Write Flash Command Not Available\r\n\r\n");
  4061. }
  4062. }
  4063. void FlashCmd(char *inputCmd, unsigned int opt)
  4064. {
  4065. char subMain[MAX_SUB_CMD_LENGTH];
  4066. char subSub[MAX_SUB_CMD_LENGTH];
  4067. memset(subMain, 0x00, sizeof(subMain));
  4068. memset(subSub, 0x00, sizeof(subSub));
  4069. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  4070. {
  4071. if(strcmp(subMain, "set") == EQUAL)
  4072. {
  4073. FlashSetCmd(subSub, opt);
  4074. return;
  4075. }
  4076. if(strcmp(subMain, "write") == EQUAL)
  4077. {
  4078. FlashWriteCmd(subSub, opt);
  4079. return;
  4080. }
  4081. if(strcmp(subMain, "clean") == EQUAL)
  4082. {
  4083. FlashCleanCmd(subSub, opt);
  4084. return;
  4085. }
  4086. }
  4087. printf("\r\n");
  4088. printf("Input cmd fail ------ flash [set | write | clean] [cmd] [...]\r\n\r\n");
  4089. }
  4090. void EnableAbnormalRelay(void)
  4091. {
  4092. ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay = true;
  4093. printf("\r\n");
  4094. printf("Enable Abnormal Relay Cmd\r\n\r\n");
  4095. }
  4096. void DisableAbnormalRelay(void)
  4097. {
  4098. ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay = NO;
  4099. printf("\r\n");
  4100. printf("Disable Abnormal Relay Cmd\r\n\r\n");
  4101. }
  4102. void RelayWriteOutputCmd(char *inputCmd)
  4103. {
  4104. char subMain[MAX_SUB_CMD_LENGTH];
  4105. char subSub[MAX_SUB_CMD_LENGTH];
  4106. memset(subMain, 0x00, sizeof(subMain));
  4107. memset(subSub, 0x00, sizeof(subSub));
  4108. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  4109. {
  4110. int value = 0;
  4111. value = atoi(&subMain[0]);
  4112. if(value > 0 && value <= MAX_GUN_QUANTITY && (strcmp(subSub, "on") == 0 || strcmp(subSub, "off") == 0))
  4113. {
  4114. int OnOff = 0;
  4115. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  4116. {
  4117. EnableAbnormalRelay();
  4118. }
  4119. OnOff = strcmp(subSub, "on") == 0 ? YES : NO;
  4120. ShmChargerInfo->PsuGrouping.OutputRelayConfig[value - 1].bits.Output_N = OnOff;
  4121. ShmChargerInfo->PsuGrouping.OutputRelayConfig[value - 1].bits.Output_P = OnOff;
  4122. printf("\r\n");
  4123. printf("Write Gun %d OutputRelay %s\r\n\r\n", value, subSub);
  4124. return;
  4125. }
  4126. }
  4127. printf("\r\n");
  4128. printf("Input cmd fail ------ relay [write] [output] [value 1-4] [on | off]\r\n\r\n");
  4129. }
  4130. void RelayWriteParallelCmd(char *inputCmd)
  4131. {
  4132. char subMain[MAX_SUB_CMD_LENGTH];
  4133. char subSub[MAX_SUB_CMD_LENGTH];
  4134. memset(subMain, 0x00, sizeof(subMain));
  4135. memset(subSub, 0x00, sizeof(subSub));
  4136. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  4137. {
  4138. int value = 0;
  4139. value = atoi(&subMain[0]);
  4140. if(value > 0 && value <= PARALLEL_RELAY_COUNT && (strcmp(subSub, "on") == 0 || strcmp(subSub, "off") == 0))
  4141. {
  4142. int OnOff = 0;
  4143. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  4144. {
  4145. EnableAbnormalRelay();
  4146. }
  4147. OnOff = strcmp(subSub, "on") == 0 ? YES : NO;
  4148. if(OnOff)
  4149. {
  4150. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue |= 1 << (value - 1);
  4151. }
  4152. else
  4153. {
  4154. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue &= ~(1 << (value - 1));
  4155. }
  4156. printf("\r\n");
  4157. printf("Write ParallelRelay %d %s\r\n\r\n", value, subSub);
  4158. return;
  4159. }
  4160. }
  4161. printf("\r\n");
  4162. printf("Input cmd fail ------ relay [write] [parallel] [value 1-6] [on | off]\r\n\r\n");
  4163. }
  4164. void AbnormalRelayCmd(char *inputCmd, unsigned int opt)
  4165. {
  4166. char subMain[MAX_SUB_CMD_LENGTH];
  4167. char subSub[MAX_SUB_CMD_LENGTH];
  4168. memset(subMain, 0x00, sizeof(subMain));
  4169. memset(subSub, 0x00, sizeof(subSub));
  4170. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  4171. {
  4172. if(strcmp(subMain, "enable") == 0)
  4173. {
  4174. EnableAbnormalRelay();
  4175. return;
  4176. }
  4177. if(strcmp(subMain, "disable") == 0)
  4178. {
  4179. DisableAbnormalRelay();
  4180. return;
  4181. }
  4182. }
  4183. printf("\r\n");
  4184. printf("Input cmd fail ------ relay [abnormal] [enable | disable]\r\n\r\n");
  4185. }
  4186. void RelayWriteCmd(char *inputCmd, unsigned int opt)
  4187. {
  4188. char subMain[MAX_SUB_CMD_LENGTH];
  4189. char subSub[MAX_SUB_CMD_LENGTH];
  4190. memset(subMain, 0x00, sizeof(subMain));
  4191. memset(subSub, 0x00, sizeof(subSub));
  4192. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  4193. {
  4194. if(strcmp(subMain, "output") == 0)
  4195. {
  4196. RelayWriteOutputCmd(subSub);
  4197. return;
  4198. }
  4199. if(strcmp(subMain, "parallel") == 0)
  4200. {
  4201. RelayWriteParallelCmd(subSub);
  4202. return;
  4203. }
  4204. }
  4205. printf("\r\n");
  4206. printf("Input cmd fail ------ relay [write] [output | parallel] [value] [on | off]\r\n\r\n");
  4207. }
  4208. void RelayReadCmd(char *inputCmd, unsigned int opt)
  4209. {
  4210. }
  4211. void RelayStatusCmd(char *inputCmd, unsigned int opt)
  4212. {
  4213. }
  4214. void OutputRelayAutoTest(void)
  4215. {
  4216. int MaxGunCount = 0;
  4217. struct timespec _Loop_time;
  4218. int time = 0;
  4219. MaxGunCount = ShmChargerInfo->Control.MaxConnector;
  4220. for(int i = 0; i < MaxGunCount; i++)
  4221. {
  4222. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = YES;
  4223. GetClockTime(&_Loop_time);
  4224. while(1)
  4225. {
  4226. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4227. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_N)
  4228. {
  4229. printf("Gun %d Output Relay N Driving Check OK\r\n", i + 1);
  4230. break;
  4231. }
  4232. if(time >= 3000)
  4233. {
  4234. printf("Gun %d Output Relay N Driving Check Fault\r\n", i + 1);
  4235. break;
  4236. }
  4237. usleep(10000);
  4238. }
  4239. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = YES;
  4240. GetClockTime(&_Loop_time);
  4241. while(1)
  4242. {
  4243. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4244. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_P)
  4245. {
  4246. printf("Gun %d Output Relay P Driving Check OK\r\n", i + 1);
  4247. break;
  4248. }
  4249. if(time >= 3000)
  4250. {
  4251. printf("Gun %d Output Relay P Driving Check Fault\r\n", i + 1);
  4252. break;
  4253. }
  4254. usleep(10000);
  4255. }
  4256. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = NO;
  4257. GetClockTime(&_Loop_time);
  4258. while(1)
  4259. {
  4260. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4261. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_N)
  4262. {
  4263. printf("Gun %d Output Relay N Welding Check OK\r\n", i + 1);
  4264. break;
  4265. }
  4266. if(time >= 3000)
  4267. {
  4268. printf("Gun %d Output Relay N Welding Check Fault\r\n", i + 1);
  4269. break;
  4270. }
  4271. usleep(10000);
  4272. }
  4273. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = NO;
  4274. GetClockTime(&_Loop_time);
  4275. while(1)
  4276. {
  4277. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4278. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_P)
  4279. {
  4280. printf("Gun %d Output Relay P Welding Check OK\r\n", i + 1);
  4281. break;
  4282. }
  4283. if(time >= 3000)
  4284. {
  4285. printf("Gun %d Output Relay P Welding Check Fault\r\n", i + 1);
  4286. break;
  4287. }
  4288. usleep(10000);
  4289. }
  4290. }
  4291. }
  4292. void ParallelRelayAutoTest(void)
  4293. {
  4294. int ParallelRelayCount = 0;
  4295. struct timespec _Loop_time;
  4296. int time = 0;
  4297. if(ShmChargerInfo->Control.MaxConnector == GENERAL_GUN_QUANTITY)
  4298. {
  4299. ParallelRelayCount = ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay == 1 ? PARALLEL_RELAY_COUNT : 3;
  4300. }
  4301. else
  4302. {
  4303. ParallelRelayCount = 1;
  4304. }
  4305. for(int i = 0; i < ParallelRelayCount; i++)
  4306. {
  4307. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue |= 1 << i;
  4308. GetClockTime(&_Loop_time);
  4309. while(1)
  4310. {
  4311. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4312. if(ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue == ShmChargerInfo->PsuGrouping.ParallelRelayConfirmed.CtrlValue)
  4313. {
  4314. printf("Location %d Parallel Relay Driving Check OK\r\n", i + 1);
  4315. break;
  4316. }
  4317. if(time >= 3000)
  4318. {
  4319. printf("Location %d Parallel Relay Driving Check Fault\r\n", i + 1);
  4320. break;
  4321. }
  4322. usleep(10000);
  4323. }
  4324. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue &= ~(1 << i);
  4325. GetClockTime(&_Loop_time);
  4326. while(1)
  4327. {
  4328. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4329. if(ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue == ShmChargerInfo->PsuGrouping.ParallelRelayConfirmed.CtrlValue)
  4330. {
  4331. printf("Location %d Parallel Relay Welding Check OK\r\n", i + 1);
  4332. break;
  4333. }
  4334. if(time >= 3000)
  4335. {
  4336. printf("Location %d Parallel Relay Welding Check Fault\r\n", i + 1);
  4337. break;
  4338. }
  4339. usleep(10000);
  4340. }
  4341. }
  4342. }
  4343. void RelayAutoTest(char *inputCmd)
  4344. {
  4345. if(strcmp(inputCmd, "now") != EQUAL)
  4346. {
  4347. printf("\r\n");
  4348. printf("Input cmd fail ------ relay [autotest] [now]\r\n\r\n");
  4349. return;
  4350. }
  4351. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  4352. {
  4353. EnableAbnormalRelay();
  4354. }
  4355. OutputRelayAutoTest();
  4356. ParallelRelayAutoTest();
  4357. printf("Relay Auto Test Completed\r\n");
  4358. DisableAbnormalRelay();
  4359. }
  4360. void RelayAllOn(void)
  4361. {
  4362. int MaxGunCount = 0;
  4363. MaxGunCount = ShmChargerInfo->Control.MaxConnector;
  4364. for(int i = 0; i < MaxGunCount; i++)
  4365. {
  4366. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = YES;
  4367. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = YES;
  4368. }
  4369. int ParallelRelayCount = 0;
  4370. if(ShmChargerInfo->Control.MaxConnector == GENERAL_GUN_QUANTITY)
  4371. {
  4372. ParallelRelayCount = ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay == 1 ? PARALLEL_RELAY_COUNT : 3;
  4373. }
  4374. else
  4375. {
  4376. ParallelRelayCount = 1;
  4377. }
  4378. for(int i = 0; i < ParallelRelayCount; i++)
  4379. {
  4380. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue |= 1 << i;
  4381. }
  4382. }
  4383. void RelayAllOff(void)
  4384. {
  4385. int MaxGunCount = 0;
  4386. MaxGunCount = ShmChargerInfo->Control.MaxConnector;
  4387. for(int i = 0; i < MaxGunCount; i++)
  4388. {
  4389. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = NO;
  4390. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = NO;
  4391. }
  4392. int ParallelRelayCount = 0;
  4393. if(ShmChargerInfo->Control.MaxConnector == GENERAL_GUN_QUANTITY)
  4394. {
  4395. ParallelRelayCount = ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay == 1 ? PARALLEL_RELAY_COUNT : 3;
  4396. }
  4397. else
  4398. {
  4399. ParallelRelayCount = 1;
  4400. }
  4401. for(int i = 0; i < ParallelRelayCount; i++)
  4402. {
  4403. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue &= ~(1 << i);
  4404. }
  4405. }
  4406. void RelayLongTimeTest(char *inputCmd)
  4407. {
  4408. int time = 0;
  4409. struct timespec _Loop_time;
  4410. bool keepRun = true;
  4411. bool _relayOn = false;
  4412. if(strcmp(inputCmd, "now") != EQUAL)
  4413. {
  4414. printf("\r\n");
  4415. printf("Input cmd fail ------ relay [timetest] [now]\r\n\r\n");
  4416. return;
  4417. }
  4418. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  4419. {
  4420. EnableAbnormalRelay();
  4421. }
  4422. printf("Relay Long Time Test Start\r\n");
  4423. do
  4424. {
  4425. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4426. if(time >= 10000)
  4427. {
  4428. if(!_relayOn)
  4429. {
  4430. printf("Set Relay All On\r\n");
  4431. RelayAllOn();
  4432. _relayOn = true;
  4433. }
  4434. else
  4435. {
  4436. printf("Set Relay All Off\r\n");
  4437. RelayAllOff();
  4438. _relayOn = false;
  4439. }
  4440. GetClockTime(&_Loop_time);
  4441. }
  4442. if(keepRun)
  4443. {
  4444. keepRun = IsLoopStopCmd() ? false : true;
  4445. usleep(10000);
  4446. }
  4447. }while(keepRun);
  4448. printf("\r\n");
  4449. DisableAbnormalRelay();
  4450. }
  4451. void RelayCmd(char *inputCmd, unsigned int opt)
  4452. {
  4453. char subMain[MAX_SUB_CMD_LENGTH];
  4454. char subSub[MAX_SUB_CMD_LENGTH];
  4455. memset(subMain, 0x00, sizeof(subMain));
  4456. memset(subSub, 0x00, sizeof(subSub));
  4457. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  4458. {
  4459. if(strcmp(subMain, "abnormal") == EQUAL)
  4460. {
  4461. AbnormalRelayCmd(subSub, opt);
  4462. return;
  4463. }
  4464. if(strcmp(subMain, "write") == EQUAL)
  4465. {
  4466. RelayWriteCmd(subSub, opt);
  4467. return;
  4468. }
  4469. if(strcmp(subMain, "read") == EQUAL)
  4470. {
  4471. RelayReadCmd(subSub, opt);
  4472. return;
  4473. }
  4474. if(strcmp(subMain, "status") == EQUAL)
  4475. {
  4476. RelayStatusCmd(subSub, opt);
  4477. return;
  4478. }
  4479. if(strcmp(subMain, "autotest") == EQUAL)
  4480. {
  4481. RelayAutoTest(subSub);
  4482. return;
  4483. }
  4484. if(strcmp(subMain, "longtime") == EQUAL)
  4485. {
  4486. RelayLongTimeTest(subSub);
  4487. return;
  4488. }
  4489. }
  4490. printf("\r\n");
  4491. printf("Input cmd fail ------ relay [abnormal | write | read | autotest] [...]\r\n\r\n");
  4492. }
  4493. // Sys CurrentRate: [XX.XX]
  4494. // TimeOfDayPrice: [00-01: XX.XX] [01-02: XX.XX] [02-03: XX.XX] [03-04: XX.XX] [04-05: XX.XX] [05-06: XX.XX]
  4495. // : [06-07: XX.XX] [07-08: XX.XX] [08-09: XX.XX] [09-10: XX.XX] [10-11: XX.XX] [11-12: XX.XX]
  4496. // : [12-13: XX.XX] [13-14: XX.XX] [14-15: XX.XX] [15-16: XX.XX] [16-17: XX.XX] [17-18: XX.XX]
  4497. // : [18-19: XX.XX] [19-20: XX.XX] [20-21: XX.XX] [21-22: XX.XX] [22-23: XX.XX] [23-24: XX.XX]
  4498. int ShowSysPriceInfo(void)
  4499. {
  4500. int showLine = 1;
  4501. char priceString[1024];
  4502. //************************************************************************************************
  4503. printf(" Sys CurrentRate: [%5.2f]\r\n", ShmChargerInfo->PriceAndReceiptInfo.CurrentRate);
  4504. if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
  4505. {
  4506. //************************************************************************************************
  4507. memset(priceString, 0x00, sizeof(priceString));
  4508. for(int i = 0; i < 6; i++)
  4509. {
  4510. char strTemp[64];
  4511. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4512. strcat(priceString, strTemp);
  4513. }
  4514. printf(" TimeOfDayPrice:%s\r\n", priceString);
  4515. //************************************************************************************************
  4516. memset(priceString, 0x00, sizeof(priceString));
  4517. for(int i = 6; i < 12; i++)
  4518. {
  4519. char strTemp[64];
  4520. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4521. strcat(priceString, strTemp);
  4522. }
  4523. printf(" :%s\r\n", priceString);
  4524. //************************************************************************************************
  4525. memset(priceString, 0x00, sizeof(priceString));
  4526. for(int i = 12; i < 18; i++)
  4527. {
  4528. char strTemp[64];
  4529. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4530. strcat(priceString, strTemp);
  4531. }
  4532. printf(" :%s\r\n", priceString);
  4533. //************************************************************************************************
  4534. memset(priceString, 0x00, sizeof(priceString));
  4535. for(int i = 18; i < 24; i++)
  4536. {
  4537. char strTemp[64];
  4538. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4539. strcat(priceString, strTemp);
  4540. }
  4541. printf(" :%s\r\n", priceString);
  4542. showLine += 4;
  4543. }
  4544. return showLine;
  4545. }
  4546. // Gun X UserPrice: [%s]
  4547. // Receipt: [%s]
  4548. int ShowGunPriceInfo(int gun)
  4549. {
  4550. int showLine = 2;
  4551. char priceString[1024];
  4552. //************************************************************************************************
  4553. memset(priceString, 0x00, sizeof(priceString));
  4554. if(strlen(&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gun][0]) > 0)
  4555. {
  4556. strcpy(priceString, &ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gun][0]);
  4557. }
  4558. else
  4559. {
  4560. strcpy(priceString, "NULL");
  4561. }
  4562. printf(" Gun %d UserPrice: [%s]\r\n", gun + 1, priceString);
  4563. //************************************************************************************************
  4564. memset(priceString, 0x00, sizeof(priceString));
  4565. if(strlen(&ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gun][0]) > 0)
  4566. {
  4567. strcpy(priceString, &ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gun][0]);
  4568. }
  4569. else
  4570. {
  4571. strcpy(priceString, "NULL");
  4572. }
  4573. printf(" Receipt: [%s]\r\n", priceString);
  4574. return showLine;
  4575. }
  4576. void ShowPrice(char *inputCmd, unsigned int opt)
  4577. {
  4578. int totalLine = 0;
  4579. bool keepRun = false;
  4580. bool reflash = false;
  4581. int time = 0;
  4582. struct timespec _Loop_time;
  4583. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  4584. {
  4585. keepRun = true;
  4586. }
  4587. do
  4588. {
  4589. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4590. if(time >= 1000)
  4591. {
  4592. if(reflash)
  4593. {
  4594. ConsoleReflash(1, totalLine);
  4595. }
  4596. totalLine = 0;
  4597. printf("\r\n");
  4598. totalLine += ShowSysPriceInfo() + 1;
  4599. printf("\r\n");
  4600. totalLine += 1;
  4601. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  4602. {
  4603. totalLine += ShowGunPriceInfo(i);
  4604. }
  4605. GetClockTime(&_Loop_time);
  4606. if((opt & OPTION_REFLASH) > 0)
  4607. {
  4608. reflash = true;
  4609. }
  4610. }
  4611. if(keepRun)
  4612. {
  4613. keepRun = IsLoopStopCmd() ? false : true;
  4614. usleep(10000);
  4615. }
  4616. }while(keepRun);
  4617. printf("\r\n");
  4618. }
  4619. void SetOccupancyNotifyDisplay(char *inputCmd)
  4620. {
  4621. int gun = 0;
  4622. float fee = 0;
  4623. int totalCnt = 0;
  4624. char *str_occupancy_status[] = {STR_NO_OCCUPANCY, STR_SYNC_OCCUPANCY, STR_OCCUPIED, STR_REQUEST_FEE, STR_WAIT_TO_PAY, STR_PAID_ONLINE_OK, STR_PAID_ONLINE_FAIL};
  4625. char _sn[37];
  4626. char cmdBuf[32];
  4627. struct timeb nowTime;
  4628. struct tm *tm;
  4629. memset(_sn, 0x00, sizeof(_sn));
  4630. totalCnt = GetSubCommand(inputCmd);
  4631. if(totalCnt == 3)
  4632. {
  4633. gun = atoi(&MultiSubCmd[0][0]);
  4634. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  4635. {
  4636. printf("\r\n");
  4637. printf("Gun [%s] out of range\r\n\r\n", &MultiSubCmd[0][0]);
  4638. return;
  4639. }
  4640. strncpy(_sn, &MultiSubCmd[1][0], strlen(&MultiSubCmd[1][0]) >= (sizeof(_sn) - 1) ? (sizeof(_sn) - 1) : strlen(&MultiSubCmd[1][0]));
  4641. fee = atof(&MultiSubCmd[2][0]);
  4642. if(fee <= 0)
  4643. {
  4644. printf("\r\n");
  4645. printf("Fee [%s] out of range\r\n\r\n", &MultiSubCmd[2][0]);
  4646. return;
  4647. }
  4648. ShmChargerInfo->AllBill.OccupancyInfo[gun - 1].Status = _Parking_Occupied;
  4649. memcpy(ShmChargerInfo->AllBill.OccupancyInfo[gun - 1].OccupancyBill.Sn, _sn, sizeof(_sn));
  4650. ShmChargerInfo->AllBill.OccupancyInfo[gun - 1].OccupancyBill.Fee = fee;
  4651. ShmChargerInfo->AllBill.OccupancyInfo[gun - 1].OccupancyBill.Duration = 5;
  4652. ftime(&nowTime);
  4653. tm = localtime(&nowTime.time);
  4654. // StartTime: [2022/09/27 13:50]
  4655. sprintf(cmdBuf, "%04d//%02d//%02d %02d:%02d",
  4656. tm->tm_year + 1900,
  4657. tm->tm_mon + 1,
  4658. tm->tm_mday,
  4659. tm->tm_hour,
  4660. tm->tm_min);
  4661. memcpy(ShmChargerInfo->AllBill.OccupancyInfo[gun - 1].OccupancyBill.StartTime, cmdBuf, sizeof(cmdBuf));
  4662. ShmChargerInfo->AllBill.OccupancyInfo[gun - 1].OccupancyReq.bits.SelfReq = true;
  4663. printf("\r\n");
  4664. printf("Set Gun [%s] [%s], SN: [%s], Fee: [%.2f]\r\n\r\n", &MultiSubCmd[0][0], str_occupancy_status[_Parking_Occupied], _sn, fee);
  4665. return;
  4666. }
  4667. printf("\r\n");
  4668. printf("Input cmd fail ------ parking notify display [gun 1-4] [sn] [fee]\r\n\r\n");
  4669. }
  4670. void SetOccupancyNotifyCancel(char *inputCmd)
  4671. {
  4672. int gun = 0;
  4673. char subMain[MAX_SUB_CMD_LENGTH];
  4674. char subSub[MAX_SUB_CMD_LENGTH];
  4675. char *str_occupancy_status[] = {STR_NO_OCCUPANCY, STR_SYNC_OCCUPANCY, STR_OCCUPIED, STR_REQUEST_FEE, STR_WAIT_TO_PAY, STR_PAID_ONLINE_OK, STR_PAID_ONLINE_FAIL};
  4676. memset(subMain, 0x00, sizeof(subMain));
  4677. memset(subSub, 0x00, sizeof(subSub));
  4678. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  4679. {
  4680. gun = atoi(subMain);
  4681. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  4682. {
  4683. printf("\r\n");
  4684. printf("Gun [%s] out of range\r\n\r\n", subMain);
  4685. return;
  4686. }
  4687. ShmChargerInfo->AllBill.OccupancyInfo[gun - 1].Status = _Parking_NoOccupancy;
  4688. printf("\r\n");
  4689. printf("Set Gun [%s] [%s]\r\n\r\n", subMain, str_occupancy_status[_Parking_NoOccupancy]);
  4690. return;
  4691. }
  4692. printf("\r\n");
  4693. printf("Input cmd fail ------ parking notify cancel [gun 1-4]\r\n\r\n");
  4694. }
  4695. void OccupancyNotifyCmd(char *inputCmd, unsigned int opt)
  4696. {
  4697. char subMain[MAX_SUB_CMD_LENGTH];
  4698. char subSub[MAX_SUB_CMD_LENGTH];
  4699. memset(subMain, 0x00, sizeof(subMain));
  4700. memset(subSub, 0x00, sizeof(subSub));
  4701. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  4702. {
  4703. if(strcmp(subMain, "display") == 0)
  4704. {
  4705. SetOccupancyNotifyDisplay(subSub);
  4706. return;
  4707. }
  4708. if(strcmp(subMain, "cancel") == 0)
  4709. {
  4710. SetOccupancyNotifyCancel(subSub);
  4711. return;
  4712. }
  4713. }
  4714. printf("\r\n");
  4715. printf("Input cmd fail ------ parking notify [display | cancel] [gun 1-4] [...]\r\n\r\n");
  4716. }
  4717. void OccupancySetCmd(char *inputCmd, unsigned int opt)
  4718. {
  4719. char subMain[MAX_SUB_CMD_LENGTH];
  4720. char subSub[MAX_SUB_CMD_LENGTH];
  4721. memset(subMain, 0x00, sizeof(subMain));
  4722. memset(subSub, 0x00, sizeof(subSub));
  4723. float _price = 0;
  4724. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  4725. {
  4726. _price = atof(subMain);
  4727. if(_price > 0)
  4728. {
  4729. ShmChargerInfo->CabinetMiscValue.ParkingPrice = _price;
  4730. for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
  4731. {
  4732. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  4733. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  4734. {
  4735. ShmChargerInfo->DispenserMiscReq[i].bits.ParkingPrice = true;
  4736. printf("Set Dispenser %d Parking price [%s]\r\n\r\n", i + 1, subMain);
  4737. }
  4738. }
  4739. return;
  4740. }
  4741. else
  4742. {
  4743. printf("\r\n");
  4744. printf("Parking price [%s] out of range\r\n\r\n", subMain);
  4745. return;
  4746. }
  4747. }
  4748. printf("\r\n");
  4749. printf("Input cmd fail ------ parking set [price]\r\n\r\n");
  4750. }
  4751. void OccupancyCmd(char *inputCmd, unsigned int opt)
  4752. {
  4753. char subMain[MAX_SUB_CMD_LENGTH];
  4754. char subSub[MAX_SUB_CMD_LENGTH];
  4755. memset(subMain, 0x00, sizeof(subMain));
  4756. memset(subSub, 0x00, sizeof(subSub));
  4757. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) >= 2)
  4758. {
  4759. if(strcmp(subMain, "notify") == EQUAL)
  4760. {
  4761. OccupancyNotifyCmd(subSub, opt);
  4762. return;
  4763. }
  4764. if(strcmp(subMain, "set") == EQUAL)
  4765. {
  4766. OccupancySetCmd(subSub, opt);
  4767. return;
  4768. }
  4769. }
  4770. printf("\r\n");
  4771. printf("Input cmd fail ------ parking [set | notify] [...]\r\n\r\n");
  4772. }
  4773. // Status SN Fee StartTime Duration
  4774. // 4fb5beab-c1dc-4fa8-8f80-aee1a26df705 XXXXX.XX
  4775. // Gun 1 NoOccupancy XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXX.XX YYYY/MM/DD HH:MM XXXX
  4776. int ShowOccupancyInfo(int gun)
  4777. {
  4778. int showLine = 1;
  4779. char *str_occupancy_status[] = {STR_NO_OCCUPANCY, STR_SYNC_OCCUPANCY, STR_OCCUPIED, STR_REQUEST_FEE, STR_WAIT_TO_PAY, STR_PAID_ONLINE_OK, STR_PAID_ONLINE_FAIL};
  4780. char _sn[37], _time[32];
  4781. if(ShmChargerInfo->AllBill.OccupancyInfo[gun].Status == _Parking_NoOccupancy)
  4782. {
  4783. sprintf(_sn, " N/A ");
  4784. }
  4785. else
  4786. {
  4787. sprintf(_sn, "%s", ShmChargerInfo->AllBill.OccupancyInfo[gun].OccupancyBill.Sn);
  4788. }
  4789. if(ShmChargerInfo->AllBill.OccupancyInfo[gun].Status == _Parking_WaitToPay)
  4790. {
  4791. sprintf(_time, "%s", ShmChargerInfo->AllBill.OccupancyInfo[gun].OccupancyBill.StartTime);
  4792. }
  4793. else
  4794. {
  4795. sprintf(_time, " N/A ");
  4796. }
  4797. //************************************************************************************************
  4798. printf(" Gun %d %11s %36s %8.2f %16s %4d\r\n",
  4799. gun + 1,
  4800. str_occupancy_status[ShmChargerInfo->AllBill.OccupancyInfo[gun].Status],
  4801. _sn,
  4802. ShmChargerInfo->AllBill.OccupancyInfo[gun].OccupancyBill.Fee,
  4803. _time,
  4804. ShmChargerInfo->AllBill.OccupancyInfo[gun].OccupancyBill.Duration
  4805. );
  4806. return showLine;
  4807. }
  4808. void ShowOccupancy(char *inputCmd, unsigned int opt)
  4809. {
  4810. int totalLine = 0;
  4811. bool keepRun = false;
  4812. bool reflash = false;
  4813. int time = 0;
  4814. struct timespec _Loop_time;
  4815. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  4816. {
  4817. keepRun = true;
  4818. }
  4819. printf("\r\n");
  4820. do
  4821. {
  4822. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4823. if(time >= 1000)
  4824. {
  4825. if(reflash)
  4826. {
  4827. ConsoleReflash(1, 2);
  4828. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  4829. }
  4830. printf("OccupancyPrice: [%.2f]\r\n", ShmChargerInfo->CabinetMiscValue.ParkingPrice);
  4831. printf(" Status SN Fee StartTime Duration\r\n");
  4832. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  4833. {
  4834. totalLine += ShowOccupancyInfo(i);
  4835. }
  4836. GetClockTime(&_Loop_time);
  4837. if((opt & OPTION_REFLASH) > 0)
  4838. {
  4839. reflash = true;
  4840. }
  4841. }
  4842. if(keepRun)
  4843. {
  4844. keepRun = IsLoopStopCmd() ? false : true;
  4845. usleep(10000);
  4846. }
  4847. }while(keepRun);
  4848. printf("\r\n");
  4849. }
  4850. void SetCustomizedFlag(int shift, bool enable)
  4851. {
  4852. if(enable)
  4853. {
  4854. ShmChargerInfo->Control.CustomizedInfo.Flag.CtrlValue |= (1 << shift);
  4855. }
  4856. else
  4857. {
  4858. ShmChargerInfo->Control.CustomizedInfo.Flag.CtrlValue &= ~(1 << shift);
  4859. }
  4860. }
  4861. // super customized standby [enable/disable]
  4862. // super customized tccstandby [enable/disable]
  4863. // super customized standbyfast [enable/disable]
  4864. // super customized freestandby [enable/disable]
  4865. // super customized tilt [enable/disable]
  4866. void SetCustomizedCmd(char *inputCmd)
  4867. {
  4868. int totalCnt = 0, maxPara = 0;
  4869. maxPara = 2;
  4870. totalCnt = GetSubCommand(inputCmd);
  4871. if(totalCnt != maxPara)
  4872. {
  4873. printf("Input cmd fail ------ super [customized] [disstandby | tccstandby | standbyfast | cstandby | tilt] [enable | disable]\r\n\r\n");
  4874. return;
  4875. }
  4876. int maxCustomized = 5;
  4877. int shift = 0;
  4878. bool enable = false, find = false;;
  4879. enable = strcmp(&MultiSubCmd[1][0], "enable") == EQUAL ? true : false;
  4880. char *str_customized[] = {"disstandby", "tccstandby", "standbyfast", "freestandby", "tilt"};
  4881. for(int i = 0; i < maxCustomized; i++)
  4882. {
  4883. if(strcmp(&MultiSubCmd[0][0], str_customized[i]) == EQUAL)
  4884. {
  4885. shift = i;
  4886. find = true;
  4887. break;
  4888. }
  4889. }
  4890. if(find)
  4891. {
  4892. SetCustomizedFlag(shift, enable);
  4893. printf("\r\n");
  4894. printf("%s %s customized flag\r\n\r\n", enable ? "Enable" : "Disable", str_customized[shift]);
  4895. return;
  4896. }
  4897. printf("\r\n");
  4898. printf("Input cmd fail ------ super [customized] [disstandby | tccstandby | standbyfast | cstandby | tilt] [enable | disable]\r\n\r\n");
  4899. }
  4900. void TiltSensorTrigger(void)
  4901. {
  4902. ShmChargerInfo->Control.CustomizedInfo.TiltSensorStep = _TILT_SENSOR_NONE;
  4903. printf("\r\n");
  4904. printf("Reset tilt sensor step\r\n\r\n");
  4905. }
  4906. void TiltSensorCmd(char *inputCmd)
  4907. {
  4908. char subMain[MAX_SUB_CMD_LENGTH];
  4909. char subSub[MAX_SUB_CMD_LENGTH];
  4910. memset(subMain, 0x00, sizeof(subMain));
  4911. memset(subSub, 0x00, sizeof(subSub));
  4912. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  4913. {
  4914. if(strcmp(subMain, "test") == 0)
  4915. {
  4916. TiltSensorTrigger();
  4917. return;
  4918. }
  4919. }
  4920. printf("\r\n");
  4921. printf("Input cmd fail ------ super [tilt] [test]\r\n\r\n");
  4922. }
  4923. void SetStandbyTime(int time)
  4924. {
  4925. if(time != 0)
  4926. {
  4927. ShmChargerInfo->Control.CustomizedInfo.StandbyTime = time;
  4928. printf("\r\n");
  4929. printf("Set standby time [%d] (s)\r\n\r\n", ShmChargerInfo->Control.CustomizedInfo.StandbyTime);
  4930. }
  4931. else
  4932. {
  4933. printf("\r\n");
  4934. printf("Unavailable value, standby time [%d] (s)\r\n\r\n", ShmChargerInfo->Control.CustomizedInfo.StandbyTime);
  4935. }
  4936. }
  4937. void StandbyTimeCmd(char *inputCmd)
  4938. {
  4939. char subMain[MAX_SUB_CMD_LENGTH];
  4940. char subSub[MAX_SUB_CMD_LENGTH];
  4941. memset(subMain, 0x00, sizeof(subMain));
  4942. memset(subSub, 0x00, sizeof(subSub));
  4943. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  4944. {
  4945. int _time = atoi(subMain);
  4946. SetStandbyTime(_time);
  4947. return;
  4948. }
  4949. printf("\r\n");
  4950. printf("Input cmd fail ------ super [standby] [value(seconds)]\r\n\r\n");
  4951. }
  4952. void DiagnosticsEnable(void)
  4953. {
  4954. ShmChargerInfo->Control.Diagnostics.DiagnosticsType = DIAGNOSTICS_TYPE_ALL;
  4955. printf("\r\n");
  4956. printf("Dispenser Diagnostics Enable\r\n\r\n");
  4957. }
  4958. void DiagnosticsCmd(char *inputCmd)
  4959. {
  4960. char subMain[MAX_SUB_CMD_LENGTH];
  4961. char subSub[MAX_SUB_CMD_LENGTH];
  4962. memset(subMain, 0x00, sizeof(subMain));
  4963. memset(subSub, 0x00, sizeof(subSub));
  4964. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  4965. {
  4966. if(strcmp(subMain, "enable") == 0)
  4967. {
  4968. DiagnosticsEnable();
  4969. return;
  4970. }
  4971. }
  4972. printf("\r\n");
  4973. printf("Input cmd fail ------ super [diagnostics] [enable]\r\n\r\n");
  4974. }
  4975. void Rs485DebugEnable(bool enable)
  4976. {
  4977. ShmChargerInfo->Control.DebugCtrl.bits.MsgInternalComm = enable ? true : false;
  4978. printf("\r\n");
  4979. printf("Rs485 internal comm debug %s\r\n\r\n", enable ? "enable" : "disable");
  4980. }
  4981. void Rs485DebugCmd(char *inputCmd)
  4982. {
  4983. char subMain[MAX_SUB_CMD_LENGTH];
  4984. char subSub[MAX_SUB_CMD_LENGTH];
  4985. memset(subMain, 0x00, sizeof(subMain));
  4986. memset(subSub, 0x00, sizeof(subSub));
  4987. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  4988. {
  4989. bool enable = strcmp(subMain, "enable") == 0 ? true : false;
  4990. Rs485DebugEnable(enable);
  4991. return;
  4992. }
  4993. printf("\r\n");
  4994. printf("Input cmd fail ------ super [rs485debug] [enable | disable]\r\n\r\n");
  4995. }
  4996. void SuperMode(char *inputCmd, unsigned int opt)
  4997. {
  4998. char subMain[MAX_SUB_CMD_LENGTH];
  4999. char subSub[MAX_SUB_CMD_LENGTH];
  5000. memset(subMain, 0x00, sizeof(subMain));
  5001. memset(subSub, 0x00, sizeof(subSub));
  5002. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) >= 1)
  5003. {
  5004. if(strcmp(subMain, "customized") == 0)
  5005. {
  5006. SetCustomizedCmd(subSub);
  5007. return;
  5008. }
  5009. if(strcmp(subMain, "tilt") == 0)
  5010. {
  5011. TiltSensorCmd(subSub);
  5012. return;
  5013. }
  5014. if(strcmp(subMain, "standby") == 0)
  5015. {
  5016. StandbyTimeCmd(subSub);
  5017. return;
  5018. }
  5019. if(strcmp(subMain, "diagnostics") == 0)
  5020. {
  5021. DiagnosticsCmd(subSub);
  5022. return;
  5023. }
  5024. if(strcmp(subMain, "rs485debug") == 0)
  5025. {
  5026. Rs485DebugCmd(subSub);
  5027. return;
  5028. }
  5029. }
  5030. printf("\r\n");
  5031. printf("Input cmd fail ------ super [customized | tilt | standby | diagnostics | rs485debug] [...]\r\n\r\n");
  5032. }
  5033. int ShowPsuCount(void)
  5034. {
  5035. int line = 0;
  5036. for(int i = 0; i < MAX_GROUP_QUANTITY; i++)
  5037. {
  5038. printf("Group Index = %d, Module Count = %2d\r\n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  5039. line++;
  5040. }
  5041. return line;
  5042. }
  5043. int ShowPsuVersion(void)
  5044. {
  5045. int line = 0;
  5046. for(int i = 0; i < ShmPsuData->SystemInitialPsuQuantity; i++)
  5047. {
  5048. printf("Psu Index = %2d, PriVersion = %s, SecVersion = %s\r\n",
  5049. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  5050. line++;
  5051. }
  5052. for(int i = 0; i < ShmPsuData->GroupCount; i++)
  5053. {
  5054. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  5055. {
  5056. printf("Group Index = %d, Psu Index = %2d, Version = %s\r\n",
  5057. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  5058. line++;
  5059. }
  5060. }
  5061. return line;
  5062. }
  5063. int ShowPsuCap(void)
  5064. {
  5065. int line = 0;
  5066. for(int i = 0; i < ShmPsuData->GroupCount; i++)
  5067. {
  5068. printf("Group Index = %d, MaxCur = %4d.%d A, Power = %d kW\r\n",
  5069. i,
  5070. (ShmPsuData->PsuGroup[i].GroupAvailableCurrent / 10),
  5071. (ShmPsuData->PsuGroup[i].GroupAvailableCurrent % 10),
  5072. (ShmPsuData->PsuGroup[i].GroupAvailablePower / 10));
  5073. line++;
  5074. }
  5075. return line;
  5076. }
  5077. int ShowPsuInput(void)
  5078. {
  5079. int line = 0;
  5080. for(int i = 0; i < ShmPsuData->GroupCount; i++)
  5081. {
  5082. for(byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  5083. {
  5084. printf("Group[%d] Index = %2d, VolR = %d, VolS = %d, VolT = %d\r\n",
  5085. i, count,
  5086. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  5087. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  5088. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  5089. line++;
  5090. }
  5091. }
  5092. return line;
  5093. }
  5094. int ShowPsuOutput(void)
  5095. {
  5096. int line = 0;
  5097. for(int i = 0; i < ShmPsuData->GroupCount; i++)
  5098. {
  5099. printf("Group Index = %d, OutputV = %4d.%d V, OutputC = %4d.%d A\r\n",
  5100. i,
  5101. (ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage / 10),
  5102. (ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage % 10),
  5103. (ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent / 10),
  5104. (ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent % 10));
  5105. line++;
  5106. }
  5107. return line;
  5108. }
  5109. int ShowPsuGroupInfo(int group)
  5110. {
  5111. //if(ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity > 0)
  5112. //{
  5113. printf(" G-%d %2d %4d.%d V %4d.%d A %4d kW",
  5114. group + 1,
  5115. ShmPsuPosition->GroupLocationInfo[group].GroupPsuQuantity,
  5116. (ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage / 10),
  5117. (ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage % 10),
  5118. (ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent / 10),
  5119. (ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent % 10),
  5120. (ShmPsuData->PsuGroup[group].GroupPresentOutputPower / 10));
  5121. printf(" %4d V %4d A %4d A %4d kW",
  5122. (ShmPsuGrouping->GroupOutput[group].GTargetVoltage / 10),
  5123. (ShmPsuGrouping->GroupOutput[group].GTargetCurrent / 10),
  5124. (ShmPsuData->PsuGroup[group].GroupAvailableCurrent / 10),
  5125. (ShmPsuData->PsuGroup[group].GroupAvailablePower / 10));
  5126. printf(" | %d%d%d%d | %d%d%d%d\r\n",
  5127. ShmChargerInfo->PsuGrouping.GroupPsuStatus_OR[group].bits.Lock,
  5128. ShmChargerInfo->PsuGrouping.GroupPsuStatus_OR[group].bits.Alarm,
  5129. ShmChargerInfo->PsuGrouping.GroupPsuStatus_OR[group].bits.Fault,
  5130. ShmChargerInfo->PsuGrouping.GroupPsuStatus_OR[group].bits.Output,
  5131. ShmChargerInfo->PsuGrouping.GroupPsuStatus_AND[group].bits.Lock,
  5132. ShmChargerInfo->PsuGrouping.GroupPsuStatus_AND[group].bits.Alarm,
  5133. ShmChargerInfo->PsuGrouping.GroupPsuStatus_AND[group].bits.Fault,
  5134. ShmChargerInfo->PsuGrouping.GroupPsuStatus_AND[group].bits.Output);
  5135. //}
  5136. //else
  5137. //{
  5138. // printf(" G-%d %2d N/A N/A N/A N/A N/A\r\n", group + 1, ShmPsuPosition->GroupLocationInfo[group].GroupPsuQuantity);
  5139. //}
  5140. return 1;
  5141. }
  5142. int ShowSinglePsuInfo(int psu_index)
  5143. {
  5144. int group = 0, gIndex = 0;
  5145. unsigned int _power = 0;
  5146. group = ShmPsuPosition->PsuAddressInfo[psu_index].GroupNo;
  5147. gIndex = ShmPsuPosition->PsuAddressInfo[psu_index].GIndex;
  5148. printf(" %2d %2d %4d.%d V %4d.%d A %4d kW %4d A %4d kW",
  5149. gIndex + 1,
  5150. psu_index,
  5151. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].PresentOutputVoltage / 10),
  5152. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].PresentOutputVoltage % 10),
  5153. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].PresentOutputCurrent / 10),
  5154. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].PresentOutputCurrent % 10),
  5155. _power,
  5156. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].IAvailableCurrent / 10),
  5157. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].AvailablePower / 10));
  5158. printf(" %3d.%d V %3d.%d V %3d.%d V",
  5159. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].InputVoltageL1 / 10),
  5160. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].InputVoltageL1 % 10),
  5161. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].InputVoltageL2 / 10),
  5162. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].InputVoltageL2 % 10),
  5163. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].InputVoltageL3 / 10),
  5164. (ShmPsuData->PsuGroup[group].PsuModule[gIndex].InputVoltageL3 % 10));
  5165. printf(" | %d%d%d%d",
  5166. ShmPsuPosition->SinglePsuStatus[psu_index].bits.Lock,
  5167. ShmPsuPosition->SinglePsuStatus[psu_index].bits.Alarm,
  5168. ShmPsuPosition->SinglePsuStatus[psu_index].bits.Fault,
  5169. ShmPsuPosition->SinglePsuStatus[psu_index].bits.Output);
  5170. printf("\r\n");
  5171. return 1;
  5172. }
  5173. // Group Psu Out_Vol Out_Cur Out_Pow TargetV TargetC Ava_Cur Ava_Pow Ambient Liq_In_Out DD_In 1 & 2 DD_Out 1 & 2 OR_LAFO AND_LAFO InVol L1 InVol L2 InVol L3
  5174. // G-X 4 XXXX.X V XXXX.X A XXXX kW XXXX V XXXX A XXXX A XXXX kW | XXXX | XXXX
  5175. // G-X 0 N/A N/A N/A N/A N/A
  5176. // X 0 XXXX.X V XXXX.X A XXXX kW XXXX A XXXX kW XXXX XXXX / XXXX XXXX / XXXX XXXX / XXXX | XXXX | XXXX XXX.X V XXX.X V XXX.X V
  5177. // Group Psu Out_Vol Out_Cur Out_Pow TargetV TargetC Ava_Cur Ava_Pow InVol L1 InVol L2 InVol L3 OR_LAFO AND_LAFO
  5178. // G-X 4 XXXX.X V XXXX.X A XXXX kW XXXX V XXXX A XXXX A XXXX kW | XXXX | XXXX
  5179. // G-X 0 N/A N/A N/A N/A N/A N/A N/A
  5180. // X 0 XXXX.X V XXXX.X A XXXX kW XXXX A XXXX kW XXX.X V XXX.X V XXX.X V | XXXX | XXXX
  5181. int ShowPsuInfo(void)
  5182. {
  5183. int line = 1;
  5184. //printf(" Group Psu Out_Vol Out_Cur Out_Pow Ava_Cur Ava_Pow InVol L1 InVol L2 InVol L3 OR_LAFO AND_LAFO\r\n");
  5185. printf(" Group Psu Out_Vol Out_Cur Out_Pow TargetV TargetC Ava_Cur Ava_Pow InVol L1 InVol L2 InVol L3 OR_LAFO AND_LAFO\r\n");
  5186. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  5187. {
  5188. line += ShowPsuGroupInfo(i);
  5189. if(ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity > 0)
  5190. {
  5191. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  5192. {
  5193. int psu_index = ShmPsuPosition->GroupLocationInfo[i].PsuIndex[j];
  5194. line += ShowSinglePsuInfo(psu_index);
  5195. }
  5196. }
  5197. }
  5198. return line;
  5199. }
  5200. int ShowSinglePsuTemperature(int psu_index)
  5201. {
  5202. int group = 0, gIndex = 0;
  5203. group = ShmPsuPosition->PsuAddressInfo[psu_index].GroupNo;
  5204. gIndex = ShmPsuPosition->PsuAddressInfo[psu_index].GIndex;
  5205. int CriticalTemp1 = 0, CriticalTemp2 = 0, CriticalTemp3 = 0, InletTemp = 0, OutletTemp = 0, InletTemp_1 = 0, InletTemp_2 = 0;
  5206. CriticalTemp1 = (int)ShmPsuData->PsuGroup[group].PsuModule[gIndex].CriticalTemp1 - 60;
  5207. CriticalTemp2 = (int)ShmPsuData->PsuGroup[group].PsuModule[gIndex].CriticalTemp2 - 60;
  5208. CriticalTemp3 = (int)ShmPsuData->PsuGroup[group].PsuModule[gIndex].CriticalTemp3 - 60;
  5209. InletTemp = (int)ShmPsuData->PsuGroup[group].PsuModule[gIndex].InletTemp - 60;
  5210. OutletTemp = (int)ShmPsuData->PsuGroup[group].PsuModule[gIndex].OutletTemp - 60;
  5211. InletTemp_1 = (int)ShmPsuData->PsuGroup[group].PsuModule[gIndex].InletTemp_1 - 60;
  5212. InletTemp_2 = (int)ShmPsuData->PsuGroup[group].PsuModule[gIndex].InletTemp_2 - 60;
  5213. printf(" %d %2d %4d %4d / %4d %4d / %4d %4d / %4d\r\n",
  5214. group, psu_index, CriticalTemp1, InletTemp, OutletTemp, InletTemp_1, InletTemp_2, CriticalTemp2, CriticalTemp3);
  5215. return 1;
  5216. }
  5217. // PFC & DD
  5218. // Group Psu Ambi Liq_In_Out DD_In 1 & 2 DD_Out 1 & 2
  5219. // X XX XXXX XXXX / XXXX XXXX / XXXX XXXX / XXXX
  5220. int ShowPsuTemperature(void)
  5221. {
  5222. int line = 2;
  5223. printf(" PFC & DD\r\n");
  5224. printf(" Group Psu Ambi Liq_In_Out DD_In 1 & 2 DD_Out 1 & 2\r\n");
  5225. for(int i = 0; i < MAX_GROUP_QUANTITY; i++)
  5226. {
  5227. if(ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity > 0)
  5228. {
  5229. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  5230. {
  5231. int psu_index = ShmPsuPosition->GroupLocationInfo[i].PsuIndex[j];
  5232. line += ShowSinglePsuTemperature(psu_index);
  5233. }
  5234. }
  5235. }
  5236. return line;
  5237. }
  5238. void SetPsuIndication(int psuIndex)
  5239. {
  5240. if(psuIndex >= MAX_PSU_MODULE_QUANTITY)
  5241. {
  5242. printf("psu index(%d) over range(%d)\r\n", psuIndex, MAX_PSU_MODULE_QUANTITY);
  5243. return;
  5244. }
  5245. if(ShmChargerInfo->Control.LibCtrl.bits.InfyPwrLib)
  5246. {
  5247. ShmPsuPosition->SingleInfyPwrState[psuIndex].InfyPwrStateFlag.bits.Indicated = true;
  5248. printf("Set Psu[%2d] Led Blinking\r\n", psuIndex);
  5249. }
  5250. if(ShmChargerInfo->Control.LibCtrl.bits.PhPwrLib)
  5251. {
  5252. printf("PhPwer not support this function\r\n");
  5253. }
  5254. }
  5255. void PsuCmd(char *inputCmd, unsigned int opt)
  5256. {
  5257. bool keepRun = false;
  5258. bool reflash = false;
  5259. int reflashLine = 0;
  5260. int time = 0;
  5261. struct timespec _Loop_time;
  5262. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  5263. {
  5264. keepRun = true;
  5265. }
  5266. int totalCnt = 0, maxPara = 0;
  5267. maxPara = 1;
  5268. totalCnt = GetSubCommand(inputCmd);
  5269. if(totalCnt < maxPara)
  5270. {
  5271. printf("Input cmd fail ------ psu [count | ver | cap | input | output | info | temp | indi]\r\n\r\n");
  5272. return;
  5273. }
  5274. printf("\r\n");
  5275. do
  5276. {
  5277. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  5278. if(time >= 1000)
  5279. {
  5280. if(reflash && reflashLine > 0)
  5281. {
  5282. ConsoleReflash(1, reflashLine);
  5283. }
  5284. if(strcmp(&MultiSubCmd[0][0], "info") == EQUAL)
  5285. {
  5286. reflashLine = ShowPsuInfo();
  5287. }
  5288. else if(strcmp(&MultiSubCmd[0][0], "temp") == EQUAL)
  5289. {
  5290. reflashLine = ShowPsuTemperature();
  5291. }
  5292. else if(strcmp(&MultiSubCmd[0][0], "count") == EQUAL)
  5293. {
  5294. reflashLine = ShowPsuCount();
  5295. }
  5296. else if(strcmp(&MultiSubCmd[0][0], "ver") == EQUAL)
  5297. {
  5298. reflashLine = ShowPsuVersion();
  5299. }
  5300. else if(strcmp(&MultiSubCmd[0][0], "cap") == EQUAL)
  5301. {
  5302. reflashLine = ShowPsuCap();
  5303. }
  5304. else if(strcmp(&MultiSubCmd[0][0], "input") == EQUAL)
  5305. {
  5306. reflashLine = ShowPsuInput();
  5307. }
  5308. else if(strcmp(&MultiSubCmd[0][0], "output") == EQUAL)
  5309. {
  5310. reflashLine = ShowPsuOutput();
  5311. }
  5312. else if(strcmp(&MultiSubCmd[0][0], "indi") == EQUAL)
  5313. {
  5314. int psuIndex = 0;
  5315. if(totalCnt == 2)
  5316. {
  5317. psuIndex = atoi(&MultiSubCmd[1][0]);
  5318. SetPsuIndication(psuIndex);
  5319. }
  5320. else
  5321. {
  5322. printf("Input cmd parsing fail ------ psu [indi] [index]\r\n");
  5323. }
  5324. keepRun = false;
  5325. }
  5326. else
  5327. {
  5328. printf("Input cmd parsing fail ------ psu [count | ver | cap | input | output | info | temp | indi]\r\n");
  5329. keepRun = false;
  5330. }
  5331. GetClockTime(&_Loop_time);
  5332. if((opt & OPTION_REFLASH) > 0)
  5333. {
  5334. reflash = true;
  5335. }
  5336. }
  5337. if(keepRun)
  5338. {
  5339. keepRun = IsLoopStopCmd() ? false : true;
  5340. usleep(10000);
  5341. }
  5342. }while(keepRun);
  5343. printf("\r\n");
  5344. }
  5345. void FanSpeedCmd(char *inputCmd, unsigned int opt)
  5346. {
  5347. bool keepRun = false;
  5348. bool reflash = false;
  5349. int time = 0;
  5350. struct timespec _Loop_time;
  5351. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  5352. {
  5353. keepRun = true;
  5354. }
  5355. do
  5356. {
  5357. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  5358. if(time >= 1000)
  5359. {
  5360. if(reflash)
  5361. {
  5362. ConsoleReflash(1, 10);
  5363. }
  5364. ShowFanSpeed();
  5365. GetClockTime(&_Loop_time);
  5366. if((opt & OPTION_REFLASH) > 0)
  5367. {
  5368. reflash = true;
  5369. }
  5370. }
  5371. if(keepRun)
  5372. {
  5373. keepRun = IsLoopStopCmd() ? false : true;
  5374. usleep(10000);
  5375. }
  5376. }while(keepRun);
  5377. printf("\r\n");
  5378. }
  5379. int main(int argc, char *argv[])
  5380. {
  5381. char newString[32][MAX_SUB_CMD_LENGTH];
  5382. char inputString[MAX_SUB_CMD_LENGTH], normalCmd[MAX_SUB_CMD_LENGTH];
  5383. char mainCmd[MAX_SUB_CMD_LENGTH], subCmd[MAX_SUB_CMD_LENGTH], multiCmd[MAX_SUB_CMD_LENGTH];
  5384. int cmdCnt = 0, parseCnt = 0;
  5385. unsigned int option = 0;
  5386. if(InitShareMemory() == FAIL)
  5387. {
  5388. printf ("InitShareMemory = FAIL \n");
  5389. if(ShmStatusCodeData != NULL)
  5390. {
  5391. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  5392. }
  5393. sleep(5);
  5394. return 0;
  5395. }
  5396. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  5397. {
  5398. if (!FindChargingInfoData(i, &_chargingData[0]))
  5399. {
  5400. return 0;
  5401. }
  5402. }
  5403. // clean command
  5404. memset(mainCmd, 0x00, sizeof(mainCmd));
  5405. memset(subCmd, 0x00, sizeof(subCmd));
  5406. for(int i = 0; i < 32; i++)
  5407. {
  5408. memset(&newString[i], 0x00, 32);
  5409. }
  5410. memset(inputString, 0x00, sizeof(inputString));
  5411. memset(normalCmd, 0x00, sizeof(normalCmd));
  5412. if(argc > 1)
  5413. {
  5414. for(int i = 0; i < argc - 1; i++)
  5415. {
  5416. strcat(inputString, argv[i + 1]);
  5417. if(i + 1 < argc - 1)
  5418. {
  5419. strcat(inputString, " ");
  5420. }
  5421. }
  5422. }
  5423. for(;;)
  5424. {
  5425. if(argc == 1)
  5426. {
  5427. memset(inputString, 0x00, sizeof(inputString));
  5428. memset(normalCmd, 0x00, sizeof(normalCmd));
  5429. get_char(inputString);
  5430. }
  5431. cmdCnt = InputStringNormalize(inputString, normalCmd, &option);
  5432. if(cmdCnt > 0)
  5433. {
  5434. // clean command
  5435. memset(mainCmd, 0x00, sizeof(mainCmd));
  5436. memset(subCmd, 0x00, sizeof(subCmd));
  5437. for(int i = 0; i < 32; i++)
  5438. {
  5439. memset(&newString[i], 0x00, MAX_SUB_CMD_LENGTH);
  5440. }
  5441. //printf("CmdCnt: %d\r\n", cmdCnt);
  5442. //printf("Input: %s", inputString);
  5443. //printf("Normalize: %s\r\n", normalCmd);
  5444. //printf("option: %08X\r\n", option);
  5445. MainAndSubCommandParsing(normalCmd, mainCmd, subCmd);
  5446. //printf("MainCmd: %s\r\n", mainCmd);
  5447. //printf("SubCmd: %s\r\n", subCmd);
  5448. parseCnt = 0;
  5449. strcpy(multiCmd, normalCmd);
  5450. do
  5451. {
  5452. MainAndSubCommandParsing(multiCmd, &newString[parseCnt][0], &newString[parseCnt + 1][0]);
  5453. strcpy(multiCmd, &newString[parseCnt + 1][0]);
  5454. //printf("MultiCmd Parse %d\r\n", parseCnt + 1);
  5455. //printf("MainCmd: %s\r\n", &newString[parseCnt][0]);
  5456. //printf("SubCmd: %s\r\n", &newString[parseCnt + 1][0]);
  5457. parseCnt++;
  5458. }while(parseCnt < cmdCnt - 1);
  5459. //printf("\r\n");
  5460. //for(int i = 0; i < cmdCnt; i++)
  5461. //{
  5462. // printf("MultiCmd %d: [%s]\r\n", i + 1, &newString[i][0]);
  5463. //}
  5464. }
  5465. else
  5466. {
  5467. usleep(100000);
  5468. continue;
  5469. }
  5470. if(strcmp(newString[0], "state") == 0)
  5471. {
  5472. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  5473. continue;
  5474. // 槍狀態
  5475. RunStatusProc(newString[1], newString[2]);
  5476. }
  5477. else if(strcmp(newString[0], "card") == 0)
  5478. {
  5479. // 刷卡狀態
  5480. RunCardProc(newString[1], newString[2]);
  5481. }
  5482. else if(strcmp(newString[0], "gun") == 0)
  5483. {
  5484. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  5485. continue;
  5486. // 插槍狀態
  5487. RunGunPlugitProc(newString[1], newString[2]);
  5488. }
  5489. else if(strcmp(newString[0], "lock") == 0)
  5490. {
  5491. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  5492. continue;
  5493. // 插槍狀態
  5494. GetGunLockStatusProc(newString[1], newString[2]);
  5495. }
  5496. else if(strcmp(newString[0], "sysid") == 0)
  5497. {
  5498. // 測試 sys id
  5499. SetSystemIDProc();
  5500. }
  5501. else if(strcmp(newString[0], "self") == 0)
  5502. {
  5503. // CSU 自我檢測狀態
  5504. RunSelfProc(newString[1]);
  5505. }
  5506. else if(strcmp(mainCmd, "ver") == 0)
  5507. {
  5508. ShowFwVer(subCmd, option);
  5509. }
  5510. else if(strcmp(mainCmd, "update") == 0)
  5511. {
  5512. // 更新
  5513. FwUpdateFlagProc(subCmd, option);
  5514. }
  5515. else if (strcmp(newString[0], "ac") == 0)
  5516. {
  5517. // AC contactor 狀態
  5518. CheckAcStatus(newString[1]);
  5519. }
  5520. else if (strcmp(newString[0], "cable") == 0)
  5521. {
  5522. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  5523. continue;
  5524. // cable check pass
  5525. SetCableChkStatus(newString[1], newString[2]);
  5526. }
  5527. else if (strcmp(newString[0], "pow") == 0)
  5528. {
  5529. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  5530. continue;
  5531. // cable check pass
  5532. SetPowerValue(newString[1], newString[2]);
  5533. }
  5534. else if(strcmp(mainCmd, "model") == 0)
  5535. {
  5536. ModelNameCmd(subCmd, option);
  5537. }
  5538. else if(strcmp(mainCmd, "sn") == 0)
  5539. {
  5540. SerialNumberCmd(subCmd, option);
  5541. }
  5542. else if(strcmp(newString[0], "fan") == 0)
  5543. {
  5544. // 設定風扇速度
  5545. SetFanSpeed(newString[1]);
  5546. }
  5547. else if(strcmp(mainCmd, "speed") == 0)
  5548. {
  5549. FanSpeedCmd(subCmd, option);
  5550. }
  5551. else if(strcmp(newString[0], "debug") == 0)
  5552. {
  5553. // 設定 debug mode
  5554. SetDebugMode(newString[1]);
  5555. }
  5556. else if (strcmp(newString[0], "gfd") == 0)
  5557. {
  5558. // 設定盲沖使用 GFD 功能
  5559. SetGFDMode(newString[1]);
  5560. }
  5561. else if(strcmp(mainCmd, "temp") == 0)
  5562. {
  5563. // 取得溫度
  5564. GetTemperature(subCmd, option);
  5565. }
  5566. else if(strcmp(mainCmd, "acin") == 0 || strcmp(mainCmd, "input") == 0)
  5567. {
  5568. // 取得三向輸入電壓
  5569. GetInputVol(subCmd, option);
  5570. }
  5571. else if(strcmp(mainCmd, "psu") == 0)
  5572. {
  5573. PsuCmd(subCmd, option);
  5574. }
  5575. else if (strcmp(newString[0], "cap") == 0)
  5576. {
  5577. GetConnectorCapInfo(newString[1]);
  5578. }
  5579. else if(strcmp(newString[0], "error") == 0)
  5580. {
  5581. CreateOneError(newString[1]);
  5582. }
  5583. else if (strcmp(newString[0], "auth") == 0)
  5584. {
  5585. GetAuthorizeFlag(newString[1]);
  5586. }
  5587. else if (strcmp(newString[0], "id") == 0)
  5588. {
  5589. GetOrClearId(newString[1]);
  5590. }
  5591. else if(strcmp(newString[0], "wiring") == 0)
  5592. {
  5593. if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
  5594. strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
  5595. {
  5596. SetWiringInfo(newString[1], newString[2]);
  5597. }
  5598. ShowWiringInfo();
  5599. }
  5600. else if(strcmp(newString[0], "cwiring") == 0)
  5601. {
  5602. CleanWiringInfo();
  5603. }
  5604. else if(strcmp(newString[0], "reset") == 0)
  5605. {
  5606. SetSystemSoftRest();
  5607. }
  5608. else if(strcmp(newString[0], "reboot") == 0)
  5609. {
  5610. SetSystemHardReboot();
  5611. }
  5612. else if(strcmp(newString[0], "sgroup") == 0)
  5613. {
  5614. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  5615. {
  5616. ShowGroupingInfo();
  5617. continue;
  5618. }
  5619. RunSimplePsuGrouping(newString[1], newString[2]);
  5620. }
  5621. else if(strcmp(mainCmd, "cabinet") == 0)
  5622. {
  5623. ShowCabinetInfo(subCmd, option);
  5624. }
  5625. else if(strcmp(newString[0], "tctl") == 0)
  5626. {
  5627. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  5628. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  5629. {
  5630. printf("Test Control Value = %08X\n",ShmChargerInfo->Control.TestCtrl.CtrlValue);
  5631. printf ("Input cmd fail ------ tctl [tcmd] [value]\n\n");
  5632. continue;
  5633. }
  5634. SetTestControl(newString[1], newString[2]);
  5635. }
  5636. else if(strcmp(newString[0], "group") == 0)
  5637. {
  5638. ShowGroupingCmd(subCmd, option);
  5639. }
  5640. else if(strcmp(mainCmd, "gdmd") == 0)
  5641. {
  5642. ShowGroupingDemand(subCmd, option);
  5643. }
  5644. else if(strcmp(mainCmd, "gunchg") == 0)
  5645. {
  5646. SetGunStartCharging(subCmd, option, NO);
  5647. }
  5648. else if(strcmp(mainCmd, "webchg") == 0)
  5649. {
  5650. SetGunStartCharging(subCmd, option, YES);
  5651. }
  5652. else if(strcmp(mainCmd, "gunstp") == 0)
  5653. {
  5654. SetGunStopCharging(subCmd, option);
  5655. }
  5656. else if(strcmp(newString[0], "gunext") == 0)
  5657. {
  5658. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  5659. {
  5660. printf ("Input cmd fail ------ gunext [gun 1-4]\n\n");
  5661. continue;
  5662. }
  5663. SetGunExtend(newString[1]);
  5664. }
  5665. else if(strcmp(newString[0], "output") == 0)
  5666. {
  5667. ShowGunOutput();
  5668. }
  5669. else if(strcmp(newString[0], "gio") == 0)
  5670. {
  5671. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  5672. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  5673. {
  5674. printf ("Input cmd fail ------ gio [io] [on-off 0-1]\n\n");
  5675. continue;
  5676. }
  5677. SetGpio(newString[1], newString[2]);
  5678. }
  5679. else if(strcmp(newString[0], "status") == 0)
  5680. {
  5681. ShowStatus();
  5682. }
  5683. else if(strcmp(newString[0], "whiteR") == 0)
  5684. {
  5685. ShowWhiteCardList();
  5686. printf("\r\n");
  5687. }
  5688. else if(strcmp(newString[0], "whiteW") == 0)
  5689. {
  5690. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  5691. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  5692. {
  5693. printf ("Input cmd fail ------ whiteW [index 1-10] [card id]\n\n");
  5694. continue;
  5695. }
  5696. WriteWhiteCard(newString[1], newString[2]);
  5697. }
  5698. else if(strcmp(newString[0], "whiteE") == 0)
  5699. {
  5700. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  5701. {
  5702. printf ("Input cmd fail ------ whiteE [index 1-10]\n\n");
  5703. continue;
  5704. }
  5705. EraseWhiteCard(newString[1]);
  5706. }
  5707. else if(strcmp(mainCmd, "limit") == 0)
  5708. {
  5709. ShowChargerLimit(subCmd, option);
  5710. }
  5711. else if(strcmp(mainCmd, "pcmd") == 0)
  5712. {
  5713. SetPsuCommand(subCmd, option);
  5714. }
  5715. else if(strcmp(newString[0], "gcmd") == 0)
  5716. {
  5717. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  5718. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  5719. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  5720. {
  5721. printf ("Input cmd fail ------ gcmd [cmd] [gun] [value]\n\n");
  5722. continue;
  5723. }
  5724. SetGunCommand(newString[1], newString[2], newString[3]);
  5725. }
  5726. else if(strcmp(mainCmd, "web") == 0)
  5727. {
  5728. ShowWebInfo(subCmd, option);
  5729. }
  5730. else if(strcmp(mainCmd, "info") == 0)
  5731. {
  5732. ShowInfo(subCmd, option);
  5733. }
  5734. else if(strcmp(mainCmd, "rtcsync") == 0)
  5735. {
  5736. RtcSyncCmd(subCmd, option);
  5737. }
  5738. else if(strcmp(mainCmd, "pmodel") == 0)
  5739. {
  5740. ParsingModelNameCmd(subCmd, option);
  5741. }
  5742. else if(strcmp(mainCmd, "pt") == 0)
  5743. {
  5744. CustomerPriceTest(subCmd, option);
  5745. }
  5746. else if(strcmp(mainCmd, "evmsg") == 0)
  5747. {
  5748. EvCommMsgDebug(subCmd, option);
  5749. }
  5750. else if(strcmp(mainCmd, "evid") == 0)
  5751. {
  5752. EvCommIdDebug(subCmd, option);
  5753. }
  5754. else if(strcmp(mainCmd, "flash") == 0)
  5755. {
  5756. FlashCmd(subCmd, option);
  5757. }
  5758. else if(strcmp(mainCmd, "relay") == 0)
  5759. {
  5760. RelayCmd(subCmd, option);
  5761. }
  5762. else if(strcmp(mainCmd, "price") == 0)
  5763. {
  5764. ShowPrice(subCmd, option);
  5765. }
  5766. else if(strcmp(mainCmd, "parking") == 0)
  5767. {
  5768. OccupancyCmd(subCmd, option);
  5769. }
  5770. else if(strcmp(mainCmd, "occupancy") == 0)
  5771. {
  5772. ShowOccupancy(subCmd, option);
  5773. }
  5774. else if(strcmp(mainCmd, "super") == 0)
  5775. {
  5776. SuperMode(subCmd, option);
  5777. }
  5778. else
  5779. {
  5780. printf ("%s\n", msg);
  5781. }
  5782. usleep(100000);
  5783. if(argc > 1)
  5784. {
  5785. break;
  5786. }
  5787. }
  5788. return 0;
  5789. }