ReadCmdline.c 199 KB

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