ReadCmdline.c 213 KB

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