ReadCmdline.c 184 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479
  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()
  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. sprintf(strGunTemp, "%3d", _chargingData[i]->ConnectorTemp - 60);
  908. }
  909. if(_chargingData[i]->ChillerTemp != 0 && _chargingData[i]->ChillerTemp != 0xFF)
  910. {
  911. sprintf(strChillerTemp, "%3d", _chargingData[i]->ChillerTemp - 60);
  912. }
  913. printf(" %d %s %s ", i + 1, strGunTemp, strChillerTemp);
  914. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  915. {
  916. printf(" %3d/%3d/%3d",
  917. ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp,
  918. ShmPsuData->PsuGroup[i].PsuModule[j].InletTemp,
  919. ShmPsuData->PsuGroup[i].PsuModule[j].CriticalTemp1);
  920. }
  921. printf("\r\n");
  922. }
  923. GetClockTime(&_Loop_time);
  924. if((opt & OPTION_REFLASH) > 0)
  925. {
  926. reflash = true;
  927. }
  928. }
  929. if(keepRun)
  930. {
  931. keepRun = IsLoopStopCmd() ? false : true;
  932. usleep(10000);
  933. }
  934. }while(keepRun);
  935. }
  936. void GetInputVol(char *inputCmd, unsigned int opt)
  937. {
  938. bool keepRun = false;
  939. bool reflash = false;
  940. int time = 0;
  941. struct timespec _Loop_time;
  942. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  943. {
  944. keepRun = true;
  945. }
  946. printf("\r\n");
  947. do
  948. {
  949. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  950. if(time >= 1000)
  951. {
  952. if(reflash)
  953. {
  954. ConsoleReflash(1, 1);
  955. }
  956. printf("L1N_L12 = %4.1f V, L2N_L23 = %4.1f V, L3N_L31 = %4.1f V, DC Input: %4.1f V\r\n",
  957. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  958. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  959. ShmSysConfigAndInfo->SysInfo.InputVoltageT,
  960. ShmSysConfigAndInfo->SysInfo.InputVoltageDc);
  961. GetClockTime(&_Loop_time);
  962. if((opt & OPTION_REFLASH) > 0)
  963. {
  964. reflash = true;
  965. }
  966. }
  967. if(keepRun)
  968. {
  969. keepRun = IsLoopStopCmd() ? false : true;
  970. usleep(10000);
  971. }
  972. }while(keepRun);
  973. printf("\r\n");
  974. }
  975. void GetPsuInformation(char *v1, char *v2, char *v3)
  976. {
  977. printf("**********************AC Contact needed*************************\n");
  978. if(strcmp(v1, "count") == 0)
  979. {
  980. for (int i = 0; i < 4; i++)
  981. {
  982. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  983. }
  984. }
  985. else if(strcmp(v1, "ver") == 0)
  986. {
  987. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  988. {
  989. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  990. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  991. }
  992. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  993. {
  994. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  995. {
  996. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  997. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  998. }
  999. }
  1000. }
  1001. else if(strcmp(v1, "cap") == 0)
  1002. {
  1003. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  1004. {
  1005. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  1006. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  1007. }
  1008. }
  1009. else if(strcmp(v1, "input") == 0)
  1010. {
  1011. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  1012. {
  1013. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  1014. {
  1015. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  1016. i, count,
  1017. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  1018. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  1019. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  1020. }
  1021. }
  1022. }
  1023. else if (strcmp(v1, "output") == 0)
  1024. {
  1025. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  1026. {
  1027. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  1028. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  1029. }
  1030. }
  1031. else if (strcmp(v1, "test") == 0)
  1032. {
  1033. int mode = atoi(v2);
  1034. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  1035. {
  1036. ShmPsuData->Work_Step = mode;
  1037. }
  1038. }
  1039. else if (strcmp(v1, "out") == 0)
  1040. {
  1041. float vol = atof(v2);
  1042. float cur = atof(v3);
  1043. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  1044. {
  1045. if (!FindChargingInfoData(0, &_chargingData[0]))
  1046. {
  1047. printf ("FindChargingInfoData error\n");
  1048. return;
  1049. }
  1050. _chargingData[0]->EvBatterytargetVoltage = vol;
  1051. _chargingData[0]->EvBatterytargetCurrent = cur;
  1052. }
  1053. }
  1054. printf("*************************************************\n");
  1055. }
  1056. void GetConnectorCapInfo(char *v1)
  1057. {
  1058. int _GunIndex = atoi(v1);
  1059. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1060. {
  1061. printf ("FindChargingInfoData error\n");
  1062. return;
  1063. }
  1064. printf ("Charger Max Current = %d, Max Power = %d \n",
  1065. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  1066. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  1067. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  1068. _GunIndex,
  1069. _chargingData[_GunIndex]->RealMaxPower,
  1070. _chargingData[_GunIndex]->RealMaxVoltage,
  1071. _chargingData[_GunIndex]->RealMaxCurrent);
  1072. }
  1073. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  1074. {
  1075. int _GunIndex = atoi(v1);
  1076. float _Voltage = atof(v2);
  1077. float _Current = atof(v3);
  1078. unsigned char PreviousSystemStatus = 0xff;
  1079. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1080. {
  1081. printf ("FindChargingInfoData error\n");
  1082. return;
  1083. }
  1084. printf ("ReqVoltage = %f, ReqCurrent = %f\n", _Voltage, _Current);
  1085. if(_Voltage > 1000 || _Voltage < 50)
  1086. {
  1087. printf ("Input Voltage over range\n");
  1088. return;
  1089. }
  1090. // if(_Current > 100 || _Current < 2){
  1091. //
  1092. // printf ("Input Current over range\n");
  1093. // return;
  1094. // }
  1095. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  1096. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  1097. //kill ev task
  1098. system("killall Module_EvComm");
  1099. //_Voltage = (_Voltage * 10);
  1100. //_Current = (_Current * 10);
  1101. //system(STTY_US TTY_PATH);
  1102. while(true)
  1103. {
  1104. //fix gun 1
  1105. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  1106. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1107. {
  1108. case S_IDLE:
  1109. {
  1110. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1111. {
  1112. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1113. printf ("[UnconditionalCharge - S_IDLE]\n");
  1114. }
  1115. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  1116. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  1117. }
  1118. break;
  1119. case S_PREPARNING:
  1120. {
  1121. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1122. {
  1123. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1124. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  1125. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1126. printf ("wait find module\n");
  1127. }
  1128. //main 會在此階段判斷以下資料跳到下一個 state
  1129. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  1130. //ShmPsuData->SystemPresentPsuQuantity;
  1131. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  1132. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  1133. //_chargingData[gun_index]->AvailableChargingPower;
  1134. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1135. //sleep(10);
  1136. //清除 main timeout 機制
  1137. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1138. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1139. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1140. }
  1141. break;
  1142. case S_PREPARING_FOR_EV:
  1143. {
  1144. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1145. {
  1146. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1147. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  1148. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  1149. }
  1150. //清除 main timeout 機制
  1151. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1152. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1153. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1154. //充電電壓電流
  1155. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1156. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  1157. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  1158. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1159. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1160. //確定模組己升壓完成
  1161. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  1162. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  1163. {
  1164. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  1165. //EV done
  1166. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  1167. }
  1168. }
  1169. break;
  1170. case S_PREPARING_FOR_EVSE:
  1171. {
  1172. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1173. {
  1174. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1175. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  1176. }
  1177. //printf ("tar vol = %d \n", _Voltage);
  1178. //printf ("tar cur = %d \n", _Current);
  1179. //清除 main timeout 機制
  1180. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1181. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1182. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1183. //充電電壓電流
  1184. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1185. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  1186. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  1187. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1188. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  1189. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1190. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1191. //確定模組己升壓完成
  1192. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  1193. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  1194. //{
  1195. //printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1196. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  1197. sleep(5);
  1198. //EV done
  1199. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  1200. //}
  1201. //else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  1202. //{
  1203. // printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1204. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1205. //}
  1206. }
  1207. break;
  1208. case S_CHARGING:
  1209. {
  1210. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1211. {
  1212. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1213. //充電電壓電流
  1214. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1215. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  1216. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  1217. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1218. printf ("[UnconditionalCharge - S_CHARGING]\n");
  1219. }
  1220. //ev task do this
  1221. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  1222. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  1223. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  1224. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1225. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1226. }
  1227. }
  1228. break;
  1229. case S_TERMINATING:
  1230. {
  1231. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1232. {
  1233. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1234. system("/root/Module_EvComm &");
  1235. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  1236. //無阻塞偵測 keybaord 結束
  1237. system(STTY_DEF TTY_PATH);
  1238. }
  1239. sleep(3);
  1240. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  1241. return;
  1242. }
  1243. break;
  1244. case S_COMPLETE:
  1245. {
  1246. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1247. {
  1248. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1249. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  1250. }
  1251. sleep(3);
  1252. return;
  1253. }
  1254. break;
  1255. }
  1256. char word[128];
  1257. char newString[7][10];
  1258. int i,j,ctr;
  1259. memset(word, 0x00, sizeof(word));
  1260. get_char(word);
  1261. if (strlen(word) == 0)
  1262. {
  1263. continue;
  1264. }
  1265. j=0; ctr=0;
  1266. strcpy(newString[1], "-1");
  1267. strcpy(newString[2], "-1");
  1268. for (i = 0; i <= (strlen(word)); i++)
  1269. {
  1270. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1271. {
  1272. newString[ctr][j] = '\0';
  1273. ctr++;
  1274. j = 0;
  1275. }
  1276. else
  1277. {
  1278. newString[ctr][j] = word[i];
  1279. j++;
  1280. }
  1281. }
  1282. if(strcmp(newString[0], "chg") == 0)
  1283. {
  1284. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1285. continue;
  1286. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1287. continue;
  1288. float _vol = atof(newString[1]);
  1289. float _cur = atof(newString[2]);
  1290. if (_cur <= 0 || _cur <= 0)
  1291. continue;
  1292. printf("vol = %f, cur = %f \n", _vol, _cur);
  1293. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  1294. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  1295. }
  1296. else if (strcmp(newString[0], "c") == 0)
  1297. {
  1298. printf("stop \n\r");
  1299. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  1300. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1301. }
  1302. usleep(100000);
  1303. }
  1304. }
  1305. void RunUnconditionalCharge(char *v1, char *v2, char *v3, char *v4)
  1306. {
  1307. float _Voltage[2], _Current[2];
  1308. _Voltage[0] = atof(v1);
  1309. _Current[0] = atof(v2);
  1310. _Voltage[1] = atof(v3);
  1311. _Current[1] = atof(v4);
  1312. unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
  1313. if(!FindChargingInfoData(0, &_chargingData[0]))
  1314. {
  1315. printf ("FindChargingInfoData 0 error\n");
  1316. return;
  1317. }
  1318. if(!FindChargingInfoData(1, &_chargingData[0]))
  1319. {
  1320. printf ("FindChargingInfoData 1 error\n");
  1321. return;
  1322. }
  1323. printf ("Gun 1: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[0], _Current[0]);
  1324. printf ("Gun 2: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[1], _Current[1]);
  1325. if(_Voltage[0] > 1000 || _Voltage[0] < 50 || _Voltage[1] > 1000 || _Voltage[1] < 50)
  1326. {
  1327. printf ("Input Voltage over range\n");
  1328. return;
  1329. }
  1330. //kill ev task
  1331. system("killall Module_EvComm");
  1332. while(true)
  1333. {
  1334. if(_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE)
  1335. {
  1336. _chargingData[0]->SystemStatus = S_REASSIGN_CHECK;
  1337. _chargingData[1]->SystemStatus = S_REASSIGN_CHECK;
  1338. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  1339. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  1340. }
  1341. if(_chargingData[0]->SystemStatus == S_COMPLETE && _chargingData[1]->SystemStatus == S_COMPLETE)
  1342. {
  1343. system(STTY_DEF TTY_PATH);
  1344. sleep(5);
  1345. return;
  1346. }
  1347. for(int i = 0; i < 2; i++)
  1348. {
  1349. switch(_chargingData[i]->SystemStatus)
  1350. {
  1351. case S_IDLE:
  1352. {
  1353. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1354. {
  1355. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1356. printf ("[UnconditionalCharge (%d) - S_IDLE]\n", i);
  1357. }
  1358. }
  1359. break;
  1360. case S_PREPARNING:
  1361. {
  1362. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1363. {
  1364. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1365. printf ("[UnconditionalCharge (%d) - S_PREPARNIN]\n", i);
  1366. printf ("wait find module\n");
  1367. }
  1368. //清除 main timeout 機制
  1369. _chargingData[i]->TimeoutFlag = 0;
  1370. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1371. _chargingData[i]->Type = 9;
  1372. }
  1373. break;
  1374. case S_PREPARING_FOR_EV:
  1375. {
  1376. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1377. {
  1378. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1379. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EV]\n", i);
  1380. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[i] * 10,_Current[i] * 10);
  1381. }
  1382. //清除 main timeout 機制
  1383. _chargingData[i]->TimeoutFlag = 0;
  1384. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1385. _chargingData[i]->Type = 9;
  1386. //充電電壓電流
  1387. _chargingData[i]->EvBatterySoc = 50;
  1388. _chargingData[i]->EvBatterytargetVoltage = 500;
  1389. _chargingData[i]->EvBatterytargetCurrent = 2;
  1390. _chargingData[i]->AvailableChargingCurrent = 1000;
  1391. printf ("Precharge Done = %f \n", _chargingData[i]->PresentChargingVoltage);
  1392. _chargingData[i]->SystemStatus = S_PREPARING_FOR_EVSE;
  1393. }
  1394. break;
  1395. case S_PREPARING_FOR_EVSE:
  1396. {
  1397. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1398. {
  1399. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1400. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EVSE]\n", i);
  1401. }
  1402. //清除 main timeout 機制
  1403. _chargingData[i]->TimeoutFlag = 0;
  1404. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1405. _chargingData[i]->Type = 9;
  1406. //充電電壓電流
  1407. _chargingData[i]->EvBatterySoc = 50;
  1408. _chargingData[i]->EvBatterytargetVoltage = 500;
  1409. _chargingData[i]->EvBatterytargetCurrent = 2;
  1410. _chargingData[i]->AvailableChargingCurrent = 1000;
  1411. printf ("Wait K1K2 = %f \n", _chargingData[i]->PresentChargingVoltage);
  1412. sleep(5);
  1413. //EV done
  1414. _chargingData[i]->SystemStatus = S_CHARGING;
  1415. }
  1416. break;
  1417. case S_CHARGING:
  1418. {
  1419. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1420. {
  1421. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1422. //充電電壓電流
  1423. _chargingData[i]->EvBatterySoc = 50;
  1424. _chargingData[i]->EvBatterytargetVoltage = _Voltage[i];
  1425. _chargingData[i]->EvBatterytargetCurrent = _Current[i];
  1426. _chargingData[i]->AvailableChargingCurrent = 1000;
  1427. printf ("[UnconditionalCharge (%d) - S_CHARGING]\n", i);
  1428. }
  1429. }
  1430. break;
  1431. case S_TERMINATING:
  1432. {
  1433. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1434. {
  1435. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1436. system("/root/Module_EvComm &");
  1437. printf ("[UnconditionalCharge (%d) - S_TERMINATING]\n", i);
  1438. }
  1439. sleep(3);
  1440. _chargingData[i]->SystemStatus = S_COMPLETE;
  1441. }
  1442. break;
  1443. case S_COMPLETE:
  1444. {
  1445. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1446. {
  1447. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1448. printf ("[UnconditionalCharge (%d) - S_COMPLETE]\n", i);
  1449. }
  1450. }
  1451. break;
  1452. }
  1453. }
  1454. char word[128];
  1455. char newString[7][10];
  1456. int i,j,ctr;
  1457. memset(word, 0x00, sizeof(word));
  1458. get_char(word);
  1459. if (strlen(word) == 0)
  1460. {
  1461. continue;
  1462. }
  1463. j=0; ctr=0;
  1464. strcpy(newString[1], "-1");
  1465. strcpy(newString[2], "-1");
  1466. for (i = 0; i <= (strlen(word)); i++)
  1467. {
  1468. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1469. {
  1470. newString[ctr][j] = '\0';
  1471. ctr++;
  1472. j = 0;
  1473. }
  1474. else
  1475. {
  1476. newString[ctr][j] = word[i];
  1477. j++;
  1478. }
  1479. }
  1480. if(strcmp(newString[0], "chg") == 0)
  1481. {
  1482. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1483. continue;
  1484. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1485. continue;
  1486. if (strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  1487. continue;
  1488. int _gun = atoi(newString[1]);
  1489. float _vol = atof(newString[2]);
  1490. float _cur = atof(newString[3]);
  1491. if(_gun >= 2 || _gun < 0)
  1492. continue;
  1493. if (_cur <= 0 || _cur <= 0)
  1494. continue;
  1495. printf("gun %d: vol = %f, cur = %f \n", _gun + 1, _vol, _cur);
  1496. _chargingData[_gun]->EvBatterytargetVoltage = _vol;
  1497. _chargingData[_gun]->EvBatterytargetCurrent = _cur;
  1498. }
  1499. else if (strcmp(newString[0], "c") == 0)
  1500. {
  1501. printf("stop \n\r");
  1502. _chargingData[0]->SystemStatus = S_TERMINATING;
  1503. _chargingData[1]->SystemStatus = S_TERMINATING;
  1504. }
  1505. usleep(100000);
  1506. }
  1507. }
  1508. void SetWiringInfo(char *v1, char *v2)
  1509. {
  1510. int dispenser = atoi(v1);
  1511. int connector = atoi(v2);
  1512. if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
  1513. {
  1514. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
  1515. {
  1516. printf("\r\n");
  1517. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1518. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1519. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
  1520. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
  1521. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1522. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1523. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1524. }
  1525. else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
  1526. {
  1527. printf("\r\n");
  1528. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1529. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1530. int quantity = 0;
  1531. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1532. {
  1533. quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  1534. }
  1535. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
  1536. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1537. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1538. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1539. }
  1540. }
  1541. }
  1542. void ShowWiringInfo(void)
  1543. {
  1544. printf("\r\n");
  1545. printf("********** Wiring Info **********\r\n");
  1546. printf("Dispenser = %d, Connector = %d\r\n",
  1547. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
  1548. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
  1549. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
  1550. {
  1551. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1552. {
  1553. printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
  1554. }
  1555. }
  1556. printf("\r\n");
  1557. }
  1558. void CleanWiringInfo(void)
  1559. {
  1560. printf("\r\n");
  1561. printf("******* Clean Wiring Info *******\r\n");
  1562. memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
  1563. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1564. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  1565. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset = true;
  1566. printf("\r\n");
  1567. }
  1568. void SetSystemSoftRest(void)
  1569. {
  1570. printf("\r\n");
  1571. printf("********* Set Soft Reset ********\r\n\r\n");
  1572. ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
  1573. }
  1574. void SetSystemHardReboot(void)
  1575. {
  1576. printf("\r\n");
  1577. printf("******** Set Hard Reboot ********\r\n\r\n");
  1578. ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
  1579. }
  1580. void SetGroupRole(byte group, byte role)
  1581. {
  1582. if(group < GENERAL_GUN_QUANTITY)
  1583. {
  1584. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != role)
  1585. {
  1586. //printf("\r\nSet Group %d Role = %d", group, role);
  1587. }
  1588. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role = role;
  1589. }
  1590. }
  1591. void SetGroupToIdle(byte group)
  1592. {
  1593. if(group < GENERAL_GUN_QUANTITY)
  1594. {
  1595. SetGroupRole(group, _GROLE_IDLE);
  1596. ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity = 0;
  1597. memset(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1598. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = 0;
  1599. //printf("\r\n Reset Group %02X To Idle", group);
  1600. }
  1601. }
  1602. void SetGroupToMaster(byte group)
  1603. {
  1604. if(group < GENERAL_GUN_QUANTITY)
  1605. {
  1606. SetGroupRole(group, _GROLE_MASTER);
  1607. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = group + 1;
  1608. //printf("\r\n Set Group %02X As Master", group);
  1609. }
  1610. }
  1611. void SetGroupToSlave(byte group, byte target)
  1612. {
  1613. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1614. {
  1615. SetGroupRole(group, _GROLE_SLAVE);
  1616. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = target + 1;
  1617. //printf("\r\n Set Group %02X As Slave", group);
  1618. }
  1619. }
  1620. // group: group index, target: target index
  1621. // add group to target's member
  1622. void AddGroupCollection(byte group, byte target)
  1623. {
  1624. int ParallelConfig = 0;
  1625. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1626. {
  1627. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role != _GROLE_MASTER)
  1628. {
  1629. return;
  1630. }
  1631. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE &&
  1632. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_WAIT_IDLE &&
  1633. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_PRECHARGE_READY)
  1634. {
  1635. return;
  1636. }
  1637. SetGroupToSlave(group, target);
  1638. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity++] = group;
  1639. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1640. if(ParallelConfig != 0)
  1641. {
  1642. ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
  1643. }
  1644. //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);
  1645. }
  1646. }
  1647. // group: group index, target: target index
  1648. // remove group out of target's member
  1649. void RemoveGroupCollection(byte group, byte target)
  1650. {
  1651. int location = 0, slave = 0;
  1652. bool find = false;
  1653. int ParallelConfig = 0;
  1654. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1655. {
  1656. for(int i = 0; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1657. {
  1658. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i])
  1659. {
  1660. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1661. location = i;
  1662. find = true;
  1663. break;
  1664. }
  1665. }
  1666. if(find)
  1667. {
  1668. for(int i = location + 1; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1669. {
  1670. slave = ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i];
  1671. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1672. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i - 1] = slave;
  1673. }
  1674. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity--;
  1675. SetGroupToIdle(group);
  1676. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1677. if(ParallelConfig != 0)
  1678. {
  1679. ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
  1680. }
  1681. //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);
  1682. }
  1683. }
  1684. }
  1685. // Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay
  1686. // 1 (00) 00 3 00 [00] [00] [00] 0000 V 0000 A 0000 kW 0000 A 0000 A 00 XX
  1687. void ShowGroupingInfo(void)
  1688. {
  1689. byte target = 0;
  1690. printf("\r\n Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay");
  1691. for(int i = 0; i < 4; i++)
  1692. {
  1693. target = ShmPsuGrouping->Layout[i];
  1694. printf("\r\n %d (%2d) %2d %d %02X ",
  1695. target + 1, _chargingData[target]->SystemStatus, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role,
  1696. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup);
  1697. for(int j = 0; j < 3; j++)
  1698. {
  1699. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role == 1 && j < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity)
  1700. {
  1701. printf("[%02X] ", ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[j]);
  1702. }
  1703. else
  1704. {
  1705. printf(" ");
  1706. }
  1707. }
  1708. printf(" %4d V %4d A %4d kW %4d A %4d A ",
  1709. (int)_chargingData[target]->PresentChargingVoltage, (int)_chargingData[target]->PresentChargingCurrent,
  1710. (int)(_chargingData[target]->AvailableChargingPower / 10), (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1711. (int)(_chargingData[target]->DeratingChargingCurrent / 10));
  1712. printf("%02X %02X",ShmPsuGrouping->OutputRelayConfig[target].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
  1713. }
  1714. printf("\r\n\r\nSystem Capability Current = %4d.%01d A, Power = %3d.%01d kW",
  1715. (ShmPsuData->SystemAvailableCurrent / 10), (ShmPsuData->SystemAvailableCurrent % 10),
  1716. (ShmPsuData->SystemAvailablePower / 10), (ShmPsuData->SystemAvailablePower % 10));
  1717. printf("\r\n\r\n");
  1718. }
  1719. void PsuGroupSwitchToIdle(byte group)
  1720. {
  1721. int master = 0, quantity = 0, location = 0, total = 0;
  1722. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_SLAVE)
  1723. {
  1724. return;
  1725. }
  1726. master = ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup - 1;
  1727. quantity = ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Quantity;
  1728. //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
  1729. for(int i = 0; i < quantity; i++)
  1730. {
  1731. if(total == 0)
  1732. {
  1733. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i])
  1734. {
  1735. location = i;
  1736. total++;
  1737. //printf("\r\n Find Group %02X At Member Index = %d", group, location);
  1738. }
  1739. }
  1740. else
  1741. {
  1742. // find other group in the same direction
  1743. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
  1744. {
  1745. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
  1746. {
  1747. total++;
  1748. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1749. }
  1750. }
  1751. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
  1752. {
  1753. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
  1754. {
  1755. total++;
  1756. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1757. }
  1758. }
  1759. }
  1760. }
  1761. if(total > 0)
  1762. {
  1763. unsigned char collection[GENERAL_GUN_QUANTITY];
  1764. //printf("\r\n There are %d Group Need To Switch Idle:", total);
  1765. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member));
  1766. for(int i = 0; i < total; i++)
  1767. {
  1768. //printf(" %02X", collection[i + location]);
  1769. }
  1770. for(int i = 0; i < total; i++)
  1771. {
  1772. RemoveGroupCollection(collection[i + location], master);
  1773. }
  1774. }
  1775. }
  1776. void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
  1777. {
  1778. int slave = 0, location = 0;
  1779. PsuGroupPartner partner;
  1780. memset(&partner, 0x00, sizeof(PsuGroupPartner));
  1781. // search from left
  1782. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location - 1;
  1783. for(int i = location; i >= 0; i--)
  1784. {
  1785. if(partner.Quantity >= quantity)
  1786. {
  1787. break;
  1788. }
  1789. slave = ShmPsuGrouping->Layout[i];
  1790. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1791. {
  1792. //printf("\r\n Find Group %02X From Left", slave);
  1793. partner.Member[partner.Quantity++] = slave;
  1794. }
  1795. else
  1796. {
  1797. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1798. {
  1799. continue;
  1800. }
  1801. break;
  1802. }
  1803. }
  1804. // search from right
  1805. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location + 1;
  1806. for(int i = location; i < 4; i++)
  1807. {
  1808. if(partner.Quantity >= quantity)
  1809. {
  1810. break;
  1811. }
  1812. slave = ShmPsuGrouping->Layout[i];
  1813. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1814. {
  1815. //printf("\r\n Find Group %02X From Right", slave);
  1816. partner.Member[partner.Quantity++] = slave;
  1817. }
  1818. else
  1819. {
  1820. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1821. {
  1822. continue;
  1823. }
  1824. break;
  1825. }
  1826. }
  1827. memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
  1828. }
  1829. int GetPsuGroupAvailable(byte group)
  1830. {
  1831. //int slave = 0, location = 0, available = 0;
  1832. PsuGroupPartner partner;
  1833. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1834. //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
  1835. return partner.Quantity;
  1836. #if 0
  1837. // search from left
  1838. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1839. for(int i = location; i >= 0; i--)
  1840. {
  1841. slave = ShmPsuGrouping->Layout[i];
  1842. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1843. {
  1844. available++;
  1845. }
  1846. else
  1847. {
  1848. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1849. {
  1850. continue;
  1851. }
  1852. break;
  1853. }
  1854. }
  1855. // search from right
  1856. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1857. for(int i = location; i < 4; i++)
  1858. {
  1859. slave = ShmPsuGrouping->Layout[i];
  1860. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1861. {
  1862. available++;
  1863. }
  1864. else
  1865. {
  1866. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1867. {
  1868. continue;
  1869. }
  1870. break;
  1871. }
  1872. }
  1873. return available;
  1874. #endif
  1875. }
  1876. void PsuGroupShareCheck(byte group)
  1877. {
  1878. int slave = 0, target = 0, location = 0, share = 0, total = 0;
  1879. total = GetPsuGroupAvailable(group) + 1;
  1880. //printf("\r\n Gun %d Total Group = %d", group + 1, total);
  1881. // search from left
  1882. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1883. for(int i = location; i >= 0; i--)
  1884. {
  1885. slave = ShmPsuGrouping->Layout[i];
  1886. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1887. {
  1888. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1889. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1890. {
  1891. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1892. }
  1893. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1894. break;
  1895. }
  1896. else
  1897. {
  1898. break;
  1899. }
  1900. }
  1901. if(share == 0)
  1902. {
  1903. // search from right
  1904. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1905. for(int i = location; i < 4; i++)
  1906. {
  1907. slave = ShmPsuGrouping->Layout[i];
  1908. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1909. {
  1910. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1911. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1912. {
  1913. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1914. }
  1915. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1916. break;
  1917. }
  1918. else
  1919. {
  1920. break;
  1921. }
  1922. }
  1923. }
  1924. if(share > 0)
  1925. {
  1926. //printf("\r\n Grab %02X", slave);
  1927. PsuGroupSwitchToIdle(slave);
  1928. }
  1929. else
  1930. {
  1931. //printf("\r\n No Need To Grab");
  1932. }
  1933. }
  1934. void SimplePsuGroupStartCharging(byte group)
  1935. {
  1936. //int slave = 0, location = 0;
  1937. int available = 0;
  1938. PsuGroupPartner partner;
  1939. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1940. {
  1941. return;
  1942. }
  1943. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE && ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1944. {
  1945. return;
  1946. }
  1947. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_IDLE)
  1948. {
  1949. SetGroupToMaster(group);
  1950. PsuGroupShareCheck(group);
  1951. }
  1952. else
  1953. {
  1954. available = GetPsuGroupAvailable(group);
  1955. //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
  1956. if(available == 0)
  1957. {
  1958. return;
  1959. }
  1960. }
  1961. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1962. for(int i = 0; i < partner.Quantity; i++)
  1963. {
  1964. AddGroupCollection(partner.Member[i], group);
  1965. }
  1966. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = true;
  1967. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = true;
  1968. #if 0
  1969. // search from left
  1970. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1971. for(int i = location; i >= 0; i--)
  1972. {
  1973. slave = ShmPsuGrouping->Layout[i];
  1974. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1975. {
  1976. //printf("\r\n Find %02X From Left", slave);
  1977. AddGroupCollection(slave, group);
  1978. }
  1979. else
  1980. {
  1981. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1982. {
  1983. continue;
  1984. }
  1985. break;
  1986. }
  1987. }
  1988. // search from right
  1989. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1990. for(int i = location; i < 4; i++)
  1991. {
  1992. slave = ShmPsuGrouping->Layout[i];
  1993. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1994. {
  1995. //printf("\r\n Find %02X From Right", slave);
  1996. AddGroupCollection(slave, group);
  1997. }
  1998. else
  1999. {
  2000. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  2001. {
  2002. continue;
  2003. }
  2004. break;
  2005. }
  2006. }
  2007. #endif
  2008. }
  2009. void PsuGroupStopCharging(byte group)
  2010. {
  2011. int total = 0;
  2012. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  2013. {
  2014. return;
  2015. }
  2016. total = ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity;
  2017. if(total > 0)
  2018. {
  2019. unsigned char collection[GENERAL_GUN_QUANTITY];
  2020. //printf("\r\n There are %d Group Need To Stop:", ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity);
  2021. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  2022. for(int i = 0; i < total; i++)
  2023. {
  2024. //printf(" %02X", collection[i]);
  2025. }
  2026. for(int i = 0; i < total; i++)
  2027. {
  2028. RemoveGroupCollection(collection[i], group);
  2029. }
  2030. }
  2031. SetGroupToIdle(group);
  2032. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = false;
  2033. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = false;
  2034. }
  2035. void RunSimplePsuGrouping(char *v1, char *v2)
  2036. {
  2037. int group = 0, charging = 0;
  2038. group = atoi(v1);
  2039. charging = atoi(v2);
  2040. group -= 1;
  2041. if(group >= 0 && group < 4)
  2042. {
  2043. if(charging > 0)
  2044. {
  2045. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  2046. {
  2047. //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
  2048. PsuGroupSwitchToIdle(group);
  2049. }
  2050. SimplePsuGroupStartCharging(group);
  2051. }
  2052. if(charging == 0)
  2053. {
  2054. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_MASTER)
  2055. {
  2056. PsuGroupStopCharging(group);
  2057. }
  2058. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  2059. {
  2060. PsuGroupSwitchToIdle(group);
  2061. }
  2062. }
  2063. ShowGroupingInfo();
  2064. }
  2065. }
  2066. void ConnectionInfo(void)
  2067. {
  2068. int address = 0;
  2069. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2070. {
  2071. address = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  2072. printf(" Connection[%d] Status: %d, DispenserIndex: %d, IP: %d.%d.%d.%d\r\n", i,
  2073. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status,
  2074. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex,
  2075. ((address >> 0) & 0xFF), ((address >> 8) & 0xFF), ((address >> 16) & 0xFF), ((address >> 24) & 0xFF));
  2076. }
  2077. }
  2078. void GunEnableInfo(int gunIndex)
  2079. {
  2080. 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,
  2081. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Enable ? "Enable" : "Disable",
  2082. _chargingData[gunIndex]->PowerConsumption,
  2083. ShmChargerInfo->MeterValue[gunIndex].LocalConsumption,
  2084. ShmChargerInfo->MeterValue[gunIndex].GunConsumption);
  2085. }
  2086. int FindDispenserIpAddress(int dispenser)
  2087. {
  2088. int address = 0;
  2089. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2090. {
  2091. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched &&
  2092. dispenser == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex)
  2093. {
  2094. address = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  2095. }
  2096. }
  2097. return address;
  2098. }
  2099. int DispenserInfo(int dispenser)
  2100. {
  2101. int ipAddress = 0;
  2102. int gunCnt = 0;
  2103. printf(" Dispenser %d Status: %d", dispenser + 1, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus);
  2104. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  2105. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  2106. {
  2107. ipAddress = FindDispenserIpAddress(dispenser);
  2108. gunCnt = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ConnectorQuantity;
  2109. printf(", ModelName: %s, IP: %d.%d.%d.%d\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ModelName,
  2110. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  2111. for(int i = 0; i < gunCnt; i++)
  2112. {
  2113. unsigned char gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ConnectorID[i];
  2114. printf(" - Connector[%d] Gun %d, %s\r\n", i, gun, _chargingData[gun - 1]->ConnectorPlugIn ? "Plugged" : "Unplugged");
  2115. }
  2116. }
  2117. else
  2118. {
  2119. printf(", No Information\r\n");
  2120. }
  2121. return gunCnt;
  2122. }
  2123. void ShowCabinetInfo(char *inputCmd, unsigned int opt)
  2124. {
  2125. bool keepRun = false;
  2126. bool reflash = false;
  2127. int time = 0;
  2128. int dispenserLine = 0;
  2129. struct timespec _Loop_time;
  2130. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  2131. {
  2132. keepRun = true;
  2133. }
  2134. printf("\r\n");
  2135. printf("Power Cabinet & Dispenser Info\r\n");
  2136. do
  2137. {
  2138. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  2139. if(time >= 1000)
  2140. {
  2141. if(reflash)
  2142. {
  2143. ConsoleReflash(1, 2);
  2144. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  2145. dispenserLine = dispenserLine > 0 ? (dispenserLine + 1) : dispenserLine;
  2146. ConsoleReflash(1, dispenserLine);
  2147. dispenserLine = 0;
  2148. }
  2149. printf(" Dispenser: %d / %d, Connector: %d / %d\r\n",
  2150. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  2151. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
  2152. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
  2153. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  2154. printf("\r\n");
  2155. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2156. {
  2157. GunEnableInfo(i);
  2158. }
  2159. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity > 0)
  2160. {
  2161. printf("\r\n");
  2162. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  2163. {
  2164. dispenserLine += DispenserInfo(i) + 1;
  2165. }
  2166. }
  2167. GetClockTime(&_Loop_time);
  2168. if((opt & OPTION_REFLASH) > 0)
  2169. {
  2170. reflash = true;
  2171. }
  2172. }
  2173. if(keepRun)
  2174. {
  2175. keepRun = IsLoopStopCmd() ? false : true;
  2176. usleep(10000);
  2177. }
  2178. }while(keepRun);
  2179. printf("\r\n");
  2180. }
  2181. void SetTestControl(char *v1, char *v2)
  2182. {
  2183. int testItem = 0;
  2184. int testItemLen = 4;
  2185. int enable = 0;
  2186. char strTest[32][32] = {"tbl", "tfsb", "chgsm", "fcre"};
  2187. char strItem[32][32] = {"Balance", "Fast Standby Time", "Charging Simulation", "FCharging Release Extend"};
  2188. enable = atoi(v2);
  2189. if(enable < 0)
  2190. {
  2191. return;
  2192. }
  2193. for(int i = 0; i < testItemLen; i++)
  2194. {
  2195. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2196. {
  2197. testItem = i + 1;
  2198. break;
  2199. }
  2200. }
  2201. if(testItem != 0)
  2202. {
  2203. if(enable)
  2204. {
  2205. ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
  2206. }
  2207. else
  2208. {
  2209. ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
  2210. }
  2211. printf("%s %s Test Item, Test Control Value = %08X\n",
  2212. enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
  2213. }
  2214. else
  2215. {
  2216. printf("Test Item %s Not Found\n", v1);
  2217. for(int i = 0; i < testItemLen; i++)
  2218. {
  2219. printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
  2220. }
  2221. }
  2222. printf("\r\n");
  2223. }
  2224. // Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading DiffP_Ava DiffP_Cap DiffP_Lim
  2225. // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX XXX kw XXX kW XXX kW
  2226. void ShowGroupingDemand(void)
  2227. {
  2228. byte target = 0;
  2229. unsigned char k1k2 = 0;
  2230. printf("\r\n Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading DiffP_Ava DiffP_Cap DiffP_Lim");
  2231. for(int i = 0; i < 4; i++)
  2232. {
  2233. target = ShmPsuGrouping->Layout[i];
  2234. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup != 0)
  2235. {
  2236. k1k2 = _chargingData[ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
  2237. }
  2238. else
  2239. {
  2240. k1k2 = _chargingData[target]->RelayK1K2Status;
  2241. }
  2242. printf("\r\n %d %2d %02X %d %4d V %3d.%d A %4d A %3d.%02d",
  2243. target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup, k1k2,
  2244. (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
  2245. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
  2246. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
  2247. (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  2248. (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
  2249. (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
  2250. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup == target + 1)
  2251. {
  2252. printf(" %3d.%02d", (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading / 100), (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading % 100));
  2253. printf(" %3d kW %3d kW %3d kW",
  2254. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_Available,
  2255. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_Capability,
  2256. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_PhysicalLimit);
  2257. }
  2258. }
  2259. printf("\r\n\r\n");
  2260. }
  2261. // v1: gun
  2262. // v2: voltage
  2263. // v3: current
  2264. void SetGunStartCharging(char *inputCmd, unsigned int opt, unsigned char isWeb)
  2265. {
  2266. int totalCnt = 0, maxPara = 0;
  2267. maxPara = 3;
  2268. totalCnt = GetSubCommand(inputCmd);
  2269. if(totalCnt != maxPara)
  2270. {
  2271. printf("Input cmd fail ------ gunchg [gun 1-4] [voltage 0-1000] [current 0-100]\r\n\r\n");
  2272. return;
  2273. }
  2274. int gun = 0;
  2275. float _voltage = 0, _current = 0;
  2276. gun = atoi(&MultiSubCmd[0][0]);
  2277. _voltage = atof(&MultiSubCmd[1][0]);
  2278. _current = atof(&MultiSubCmd[2][0]);
  2279. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY || _voltage < 0 || _voltage > 1000 || _current < 0 || _current > 1200)
  2280. {
  2281. printf("\r\n");
  2282. printf("Gun Start Charging Input parameter %d, %.1f, %.1f out of range\r\n", gun, _voltage, _current);
  2283. printf("\r\n");
  2284. return;
  2285. }
  2286. bool wait = true;
  2287. int time = 0;
  2288. struct timespec _Wait_time;
  2289. unsigned char PreviousSystemStatus = 0xFF;
  2290. unsigned short _targetVoltage = 0, _targetCurrent = 0;
  2291. printf("\r\n");
  2292. while(wait)
  2293. {
  2294. switch(_chargingData[gun - 1]->SystemStatus)
  2295. {
  2296. case S_IDLE:
  2297. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2298. {
  2299. printf("Gun %d S_IDLE\r\n", gun);
  2300. printf("Set Gun %d Start Charging > Voltage: %4d, Current: %d\r\n", gun, (int)_voltage, (int)_current);
  2301. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  2302. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  2303. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2304. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2305. if(isWeb)
  2306. {
  2307. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.WebApiTrigger = true;
  2308. }
  2309. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2310. }
  2311. break;
  2312. case S_REASSIGN_CHECK:
  2313. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2314. {
  2315. printf("Gun %d S_REASSIGN_CHECK, Wait For Request Charging\r\n", gun);
  2316. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2317. }
  2318. break;
  2319. case S_REASSIGN:
  2320. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2321. {
  2322. printf("Gun %d S_REASSIGN, Wait For Grouping\r\n", gun);
  2323. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2324. }
  2325. break;
  2326. case S_PREPARNING:
  2327. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2328. {
  2329. printf("Gun %d S_PREPARNING\r\n", gun);
  2330. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2331. }
  2332. break;
  2333. case S_PREPARING_FOR_EV:
  2334. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2335. {
  2336. printf("Gun %d S_PREPARING_FOR_EV\r\n", gun);
  2337. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2338. }
  2339. break;
  2340. case S_PREPARING_FOR_EVSE:
  2341. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2342. {
  2343. printf("Gun %d S_PREPARING_FOR_EVSE, Wait For EVSE\r\n", gun);
  2344. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2345. }
  2346. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2347. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2348. {
  2349. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2350. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2351. printf("Gun %d Set Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  2352. }
  2353. break;
  2354. case S_CHARGING:
  2355. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2356. {
  2357. printf("Gun %d S_CHARGING\r\n", gun);
  2358. if(PreviousSystemStatus == 0xFF)
  2359. {
  2360. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2361. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2362. printf("Gun %d Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  2363. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  2364. {
  2365. printf("Set Gun %d Force Charging > Voltage: %4d, Current: %d\r\n", gun, (int)_voltage, (int)_current);
  2366. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2367. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2368. }
  2369. }
  2370. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2371. GetClockTime(&_Wait_time);
  2372. }
  2373. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2374. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2375. {
  2376. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2377. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2378. printf("Gun %d Set Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  2379. }
  2380. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2381. if(time >= 1)
  2382. {
  2383. wait = false;
  2384. printf("Done\r\n");
  2385. }
  2386. break;
  2387. case S_TERMINATING:
  2388. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2389. {
  2390. printf("Gun %d S_TERMINATING\r\n", gun);
  2391. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2392. }
  2393. wait = false;
  2394. break;
  2395. case S_COMPLETE:
  2396. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2397. {
  2398. printf("Gun %d S_COMPLETE\r\n", gun);
  2399. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2400. }
  2401. wait = false;
  2402. break;
  2403. case S_ALARM:
  2404. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2405. {
  2406. printf("Gun %d S_ALARM\r\n", gun);
  2407. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2408. }
  2409. wait = false;
  2410. break;
  2411. default:
  2412. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2413. {
  2414. printf("Gun SystemStatus %d Unknown(%d)\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2415. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2416. }
  2417. printf("Gun %d SystemStatus(%d) Is Not Available\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2418. wait = false;
  2419. break;
  2420. }
  2421. char word[128];
  2422. char newString[7][10];
  2423. int i,j,ctr;
  2424. memset(word, 0x00, sizeof(word));
  2425. get_char(word);
  2426. if (strlen(word) == 0)
  2427. {
  2428. continue;
  2429. }
  2430. j=0; ctr=0;
  2431. strcpy(newString[1], "-1");
  2432. strcpy(newString[2], "-1");
  2433. for (i = 0; i <= (strlen(word)); i++)
  2434. {
  2435. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2436. {
  2437. newString[ctr][j] = '\0';
  2438. ctr++;
  2439. j = 0;
  2440. }
  2441. else
  2442. {
  2443. newString[ctr][j] = word[i];
  2444. j++;
  2445. }
  2446. }
  2447. if(strcmp(newString[0], "c") == 0)
  2448. {
  2449. printf("Stop\r\n");
  2450. wait = false;
  2451. }
  2452. usleep(100000);
  2453. }
  2454. printf("\r\n");
  2455. }
  2456. // v1: gun
  2457. void SetGunStopCharging(char *inputCmd, unsigned int opt)
  2458. {
  2459. int totalCnt = 0, maxPara = 0;
  2460. maxPara = 1;
  2461. totalCnt = GetSubCommand(inputCmd);
  2462. if(totalCnt < maxPara)
  2463. {
  2464. printf("Input cmd fail ------ gunchg [gun 1-4]\r\n\r\n");
  2465. return;
  2466. }
  2467. int gun = 0;
  2468. gun = atoi(&MultiSubCmd[0][0]);
  2469. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  2470. {
  2471. printf("\r\n");
  2472. printf("Gun Stop Charging Input parameter %d over range\r\n", gun);
  2473. printf("\r\n");
  2474. return;
  2475. }
  2476. bool wait = true;
  2477. int time = 0;
  2478. struct timespec _Wait_time;
  2479. unsigned char PreviousSystemStatus = 0xFF;
  2480. printf("\r\n");
  2481. while(wait)
  2482. {
  2483. switch(_chargingData[gun - 1]->SystemStatus)
  2484. {
  2485. case S_IDLE:
  2486. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2487. {
  2488. printf("Gun %d S_IDLE\r\n", gun);
  2489. if(PreviousSystemStatus == 0xFF)
  2490. {
  2491. if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2492. {
  2493. printf("Set Group [%02X] Stop\r\n", gun - 1);
  2494. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2495. }
  2496. }
  2497. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2498. GetClockTime(&_Wait_time);
  2499. }
  2500. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2501. if(time >= 1)
  2502. {
  2503. wait = false;
  2504. printf("Done\r\n");
  2505. }
  2506. break;
  2507. case S_REASSIGN_CHECK:
  2508. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2509. {
  2510. printf("Gun %d S_REASSIGN_CHECK, Wait For Request Charging\r\n", gun);
  2511. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2512. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2513. {
  2514. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2515. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2516. }
  2517. }
  2518. break;
  2519. case S_REASSIGN:
  2520. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2521. {
  2522. printf("Gun %d S_REASSIGN, Wait For Grouping\r\n", gun);
  2523. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2524. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2525. {
  2526. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2527. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2528. }
  2529. }
  2530. break;
  2531. case S_PREPARNING:
  2532. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2533. {
  2534. printf("Gun %d S_PREPARNING\r\n", gun);
  2535. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2536. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2537. {
  2538. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2539. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2540. }
  2541. }
  2542. break;
  2543. case S_PREPARING_FOR_EV:
  2544. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2545. {
  2546. printf("Gun %d S_PREPARING_FOR_EV\r\n", gun);
  2547. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2548. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2549. {
  2550. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2551. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2552. }
  2553. }
  2554. break;
  2555. case S_PREPARING_FOR_EVSE:
  2556. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2557. {
  2558. printf("Gun %d S_PREPARING_FOR_EVSE, Wait For EVSE\r\n", gun);
  2559. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2560. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2561. {
  2562. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2563. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2564. }
  2565. }
  2566. break;
  2567. case S_CHARGING:
  2568. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2569. {
  2570. printf("Gun %d S_CHARGING\r\n", gun);
  2571. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2572. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2573. {
  2574. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2575. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2576. }
  2577. }
  2578. break;
  2579. case S_TERMINATING:
  2580. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2581. {
  2582. printf("Gun %d S_TERMINATING\r\n", gun);
  2583. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2584. }
  2585. break;
  2586. case S_COMPLETE:
  2587. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2588. {
  2589. printf("Gun %d S_COMPLETE\r\n", gun);
  2590. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2591. }
  2592. break;
  2593. case S_ALARM:
  2594. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2595. {
  2596. printf("Gun %d S_ALARM\r\n", gun);
  2597. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2598. }
  2599. break;
  2600. default:
  2601. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2602. {
  2603. printf("Gun SystemStatus %d Unknown(%d)\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2604. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2605. }
  2606. printf("Gun %d SystemStatus(%d) Is Not Available\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2607. wait = false;
  2608. break;
  2609. }
  2610. char word[128];
  2611. char newString[7][10];
  2612. int i,j,ctr;
  2613. memset(word, 0x00, sizeof(word));
  2614. get_char(word);
  2615. if (strlen(word) == 0)
  2616. {
  2617. continue;
  2618. }
  2619. j=0; ctr=0;
  2620. strcpy(newString[1], "-1");
  2621. strcpy(newString[2], "-1");
  2622. for (i = 0; i <= (strlen(word)); i++)
  2623. {
  2624. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2625. {
  2626. newString[ctr][j] = '\0';
  2627. ctr++;
  2628. j = 0;
  2629. }
  2630. else
  2631. {
  2632. newString[ctr][j] = word[i];
  2633. j++;
  2634. }
  2635. }
  2636. if(strcmp(newString[0], "c") == 0)
  2637. {
  2638. printf("Stop\r\n");
  2639. wait = false;
  2640. }
  2641. usleep(100000);
  2642. }
  2643. printf("\r\n");
  2644. }
  2645. void SetGunExtend(char *v1)
  2646. {
  2647. int gun = 0;
  2648. gun = atoi(v1);
  2649. if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
  2650. {
  2651. printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
  2652. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
  2653. }
  2654. else
  2655. {
  2656. printf("\r\nGun %d Extend Capability Is Not Available, SystemStatus(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2657. }
  2658. printf("\r\n\r\n");
  2659. }
  2660. // 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 ...
  2661. // 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
  2662. void ShowGunOutput(void)
  2663. {
  2664. byte target = 0;
  2665. unsigned short voltage = 0, current = 0;
  2666. 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 ...");
  2667. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2668. {
  2669. target = ShmPsuGrouping->Layout[i];
  2670. // "\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"
  2671. voltage = (unsigned short)(_chargingData[target]->EvBatterytargetVoltage * 10);
  2672. current = (unsigned short)(_chargingData[target]->EvBatterytargetCurrent * 10);
  2673. printf("\r\n %d %4d.%d V %3d.%d A", target + 1, (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2674. voltage = ShmPsuGrouping->GroupOutput[target].GTargetVoltage;
  2675. current = ShmPsuGrouping->GroupOutput[target].GTargetCurrent;
  2676. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2677. voltage = (unsigned short)(_chargingData[target]->PresentChargingVoltage * 10);
  2678. current = (unsigned short)(_chargingData[target]->PresentChargingCurrent * 10);
  2679. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2680. voltage = ShmPsuData->PsuGroup[target].GroupPresentOutputVoltage;
  2681. current = ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent;
  2682. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2683. /*
  2684. for(int j = 0; j < ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity; j++)
  2685. {
  2686. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2687. }
  2688. */
  2689. }
  2690. printf("\r\n\r\n");
  2691. }
  2692. void SetGpio(char *v1, char *v2)
  2693. {
  2694. int testItem = 0;
  2695. int testItemLen = 1;
  2696. int ioOutput = 0;
  2697. char strTest[32][32] = {"4g"};
  2698. char strItem[32][32] = {"4G Reset"};
  2699. ioOutput = atoi(v2);
  2700. if(ioOutput < 0)
  2701. {
  2702. return;
  2703. }
  2704. for(int i = 0; i < testItemLen; i++)
  2705. {
  2706. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2707. {
  2708. testItem = i + 1;
  2709. break;
  2710. }
  2711. }
  2712. if(testItem != 0)
  2713. {
  2714. if(ioOutput)
  2715. {
  2716. system("echo 1 > /sys/class/gpio/gpio104/value");
  2717. }
  2718. else
  2719. {
  2720. system("echo 0 > /sys/class/gpio/gpio104/value");
  2721. }
  2722. printf("Set %s %s\n",
  2723. strItem[testItem - 1], ioOutput > 0 ? "High" : "Low");
  2724. }
  2725. else
  2726. {
  2727. printf("Gpio Item %s Not Found\n", v1);
  2728. }
  2729. printf("\r\n");
  2730. }
  2731. void ShowStatus(void)
  2732. {
  2733. char *str_cabinet_role[] = {STR_CABINET_ROLE_NONE, STR_CABINET_ROLE_MASTER, STR_CABINET_ROLE_SLAVE};
  2734. for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
  2735. {
  2736. printf("\r\nGun %d Status = %d, IsAvailable = %d, GunEnable = %d",
  2737. i + 1,
  2738. _chargingData[i]->SystemStatus,
  2739. _chargingData[i]->IsAvailable,
  2740. ShmChargerInfo->Control.GunAvailable[i]);
  2741. printf("\r\nAlarmCode");
  2742. printf("\r\n Connector = %6s, EvConn = %6s, Remote = %6s, Vendor = %6s",
  2743. strncmp((char *)_chargingData[i]->ConnectorAlarmCode, "", 6) != 0 ?
  2744. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2745. strncmp((char *)_chargingData[i]->EvConnAlarmCode, "", 6) != 0 ?
  2746. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2747. strncmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode, "", 6) != 0 ?
  2748. (char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode : "No Err",
  2749. strncmp((char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode, "", 6) != 0 ?
  2750. (char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode : "No Err");
  2751. }
  2752. printf("\r\n");
  2753. printf("\r\nPower Cabinet Role: %s, Switch Value: %d",
  2754. ShmChargerInfo->Control.CabinetSwitch <= _CROLE_SLAVE ? str_cabinet_role[ShmChargerInfo->Control.CabinetSwitch] : "Unknown",
  2755. ShmChargerInfo->Control.CabinetSwitch);
  2756. printf("\r\nStatus Code Len = %d", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  2757. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
  2758. {
  2759. printf("\r\n WarningCode:");
  2760. for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  2761. {
  2762. printf(" %s", (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  2763. }
  2764. }
  2765. printf("\r\n\r\n");
  2766. }
  2767. void ShowWhiteCardList(void)
  2768. {
  2769. printf("\r\nWhite Card List");
  2770. for(int i = 0; i < 10; i++)
  2771. {
  2772. printf("\r\n White Card [%2d]: %s", i + 1, (char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i]);
  2773. }
  2774. printf("\r\n\r\n");
  2775. }
  2776. void WriteWhiteCard(char *v1, char *v2)
  2777. {
  2778. int cardIndex = 0;
  2779. cardIndex = atoi(v1);
  2780. if(cardIndex < 1 || cardIndex > 10)
  2781. {
  2782. printf("\r\n White Card Index Fail\r\n\r\n");
  2783. return;
  2784. }
  2785. if(strlen(v2) == 0 || strlen(v2) > 31)
  2786. {
  2787. printf("\r\n White Card Fail\r\n\r\n");
  2788. return;
  2789. }
  2790. printf("\r\n Str Len = %d = %s", strlen(v2), v2);
  2791. printf("\r\n Set White Card Index %d = %s", cardIndex, v2);
  2792. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], v2, strlen(v2));
  2793. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  2794. printf("\r\n\r\n");
  2795. }
  2796. void EraseWhiteCard(char *v1)
  2797. {
  2798. int cardIndex = 0;
  2799. cardIndex = atoi(v1);
  2800. if(cardIndex < 1 || cardIndex > 10)
  2801. {
  2802. printf("\r\n White Card Index Fail\r\n\r\n");
  2803. return;
  2804. }
  2805. printf("\r\n Erase White Card Index = %d", cardIndex);
  2806. memset((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], 0x00, 32);
  2807. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  2808. printf("\r\n\r\n");
  2809. }
  2810. void ShowMaxLimit(void)
  2811. {
  2812. printf(" Charger Max ChargingProfile Power: %d kW\r\n", ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1 ?
  2813. (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000);
  2814. printf(" Max Total Current: %d A, Max Total Power: %d kW, Total Energy: %d kW, Total Duration %d\r\n",
  2815. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent, ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  2816. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy, ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2817. }
  2818. void ShowGunLimit(int gun_index)
  2819. {
  2820. int limitPower = -1;
  2821. char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
  2822. unsigned char inUsingCnt = 0;
  2823. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2824. {
  2825. if(ShmChargerInfo->PsuGrouping.GroupCollection[i].Role == _GROLE_MASTER)
  2826. {
  2827. inUsingCnt += ShmChargerInfo->PsuGrouping.GroupCollection[gun_index].GunPsuQuantity;
  2828. }
  2829. }
  2830. // Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur
  2831. // 1 0 CHAdeMO 00 0000 V 0000 A 0000 / 0000 / 0000 kW 0000 / 0000 A
  2832. // Gun 1 Enable, Type: CCS, Psu Cnt: 00, Max Physical Vol: 0000 V, Cur: 0000 A, Max Config Pow: 0000 kW, Cur: 0000 A
  2833. printf(" %d %d ", gun_index + 1, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable);
  2834. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable)
  2835. {
  2836. printf(" %7s %2d",
  2837. _chargingData[gun_index]->Type <= _Type_GB ? str_gun_type[_chargingData[gun_index]->Type] : "???",
  2838. ShmChargerInfo->PsuGrouping.GroupCollection[gun_index].GunPsuQuantity);
  2839. printf(" %4d V %4d A",
  2840. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteMaxPhysicalVoltage / 10),
  2841. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteMaxPhysicalCurrent / 10));
  2842. if(ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower != -1)
  2843. {
  2844. limitPower = (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
  2845. if(inUsingCnt > 0)
  2846. {
  2847. limitPower = (limitPower * ShmChargerInfo->PsuGrouping.GroupCollection[gun_index].GunPsuQuantity) / inUsingCnt;
  2848. }
  2849. }
  2850. else
  2851. {
  2852. limitPower = -1;
  2853. }
  2854. printf(" %4d / %4d / %4d kW",
  2855. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower / 10),
  2856. _chargingData[gun_index]->ChargingProfilePower == -1 ? (int)_chargingData[gun_index]->ChargingProfilePower : ((int)_chargingData[gun_index]->ChargingProfilePower / 1000),
  2857. limitPower == -1 ? limitPower : (limitPower / 1000));
  2858. printf(" %4d / %4d A",
  2859. ((int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent / 10),
  2860. _chargingData[gun_index]->ChargingProfileCurrent == -1 ? (int)_chargingData[gun_index]->ChargingProfileCurrent : ((int)_chargingData[gun_index]->ChargingProfileCurrent / 10));
  2861. }
  2862. printf("\r\n");
  2863. }
  2864. void ShowChargerLimit(char *inputCmd, unsigned int opt)
  2865. {
  2866. bool keepRun = false;
  2867. bool reflash = false;
  2868. int time = 0;
  2869. struct timespec _Loop_time;
  2870. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  2871. {
  2872. keepRun = true;
  2873. }
  2874. printf("\r\n");
  2875. printf("Charger Limit\r\n");
  2876. do
  2877. {
  2878. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  2879. if(time >= 1000)
  2880. {
  2881. if(reflash)
  2882. {
  2883. ConsoleReflash(1, 4);
  2884. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  2885. }
  2886. ShowMaxLimit();
  2887. printf("\r\n");
  2888. printf(" Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur\r\n");
  2889. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2890. {
  2891. ShowGunLimit(i);
  2892. }
  2893. GetClockTime(&_Loop_time);
  2894. if((opt & OPTION_REFLASH) > 0)
  2895. {
  2896. reflash = true;
  2897. }
  2898. }
  2899. if(keepRun)
  2900. {
  2901. keepRun = IsLoopStopCmd() ? false : true;
  2902. usleep(10000);
  2903. }
  2904. }while(keepRun);
  2905. printf("\r\n");
  2906. }
  2907. void SetPsuCommand(char *inputCmd, unsigned int opt)
  2908. {
  2909. }
  2910. void SetGunCommand(char *v1, char *v2, char *v3)
  2911. {
  2912. int cmdItem = 0;
  2913. int cmdItemLen = 2;
  2914. int gunID = 0;
  2915. int enable = 0;
  2916. char strGunCmd[32][32] = {"enable", "operative"};
  2917. char strDescription[32][32] = {"Available", "Operative"};
  2918. gunID = atoi(v2);
  2919. enable = atoi(v3);
  2920. if(gunID <= 0 || gunID > CONNECTOR_QUANTITY || enable < 0)
  2921. {
  2922. return;
  2923. }
  2924. for(int i = 0; i < cmdItemLen; i++)
  2925. {
  2926. if(strcmp((char *)&strGunCmd[i][0], v1) == 0)
  2927. {
  2928. cmdItem = i + 1;
  2929. break;
  2930. }
  2931. }
  2932. if(cmdItem != 0)
  2933. {
  2934. switch(cmdItem)
  2935. {
  2936. case 1:
  2937. ShmChargerInfo->Control.GunAvailable[gunID - 1] = enable > 0 ? YES : NO;
  2938. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2939. break;
  2940. case 2:
  2941. _chargingData[gunID - 1]->IsAvailable = enable > 0 ? YES : NO;
  2942. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2943. break;
  2944. }
  2945. printf("Gun cmd [%s] [%s]\n", strDescription[cmdItem - 1], enable ? "Enable" : "Disable");
  2946. }
  2947. else
  2948. {
  2949. printf("Gun cmd %s not found\n", v1);
  2950. for(int i = 0; i < cmdItemLen; i++)
  2951. {
  2952. printf(" [%s] -> %s Test\n", strGunCmd[i], strDescription[i]);
  2953. }
  2954. }
  2955. printf("\r\n");
  2956. }
  2957. void ShowWebSystemInfo(void)
  2958. {
  2959. char *str_led_intensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  2960. char *str_qr_code_made[] = {STR_QR_DEFAULT, STR_QR_CUSTOMIZED, STR_QR_CHARGEBOXID};
  2961. char *str_rfid_endian[] = {STR_LITTLE_ENDIAN, STR_BIG_ENDIAN};
  2962. printf("\r\n");
  2963. printf("Web [System]\r\n");
  2964. printf(" *System ID: %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  2965. printf(" *AuthorisationMode[%7s]\r\n",
  2966. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE ? "Enable" : "Disable");
  2967. printf(" - APP [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAPP > 0 ? "Enable" : "Disable");
  2968. printf(" - QRCode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isQRCode > 0 ? "Enable" : "Disable");
  2969. printf(" - RFID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isRFID > 0 ? "Enable" : "Disable");
  2970. printf(" - EVCCID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID > 0 ? "Enable" : "Disable");
  2971. if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian <= RFID_ENDIAN_BIG)
  2972. {
  2973. printf(" *RfidCardNumEndian [%s]\r\n", str_rfid_endian[ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian]);
  2974. }
  2975. else
  2976. {
  2977. printf(" *RfidCardNumEndian: %d\r\n", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
  2978. }
  2979. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode <= _QR_MODE_Customized)
  2980. {
  2981. printf(" *QR Code Made [%s]\r\n", str_qr_code_made[ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode]);
  2982. }
  2983. else
  2984. {
  2985. printf(" *QR Code Made: %d\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode);
  2986. }
  2987. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == _QR_MODE_Customized)
  2988. {
  2989. printf(" - QR Code Content: %s\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  2990. }
  2991. if(ShmChargerInfo->AuthInfo.QRCodeMode <= _QR_MODE_ChargeBoxId)
  2992. {
  2993. printf(" *QR Code Mode [%s]\r\n", str_qr_code_made[ShmChargerInfo->AuthInfo.QRCodeMode]);
  2994. }
  2995. else
  2996. {
  2997. printf(" *QR Code Mode: %d\r\n", ShmChargerInfo->AuthInfo.QRCodeMode);
  2998. }
  2999. if(ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity <= _LED_INTENSITY_BRIGHTEST)
  3000. {
  3001. printf(" *LED Intensity[%s]\r\n", str_led_intensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  3002. }
  3003. else
  3004. {
  3005. printf(" *LED Intensity[%d]\r\n", ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity);
  3006. }
  3007. }
  3008. void ShowWebChargingInfo(void)
  3009. {
  3010. printf("\r\n");
  3011. printf("Web [Charging]\r\n");
  3012. printf(" *Max Charging Energy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
  3013. printf(" *Max Charging Power : %4d kW\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
  3014. printf(" *Max Charging Current : %4d A\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  3015. printf(" *Max Charging Duration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  3016. printf(" *StopCharging By Button[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton > 0 ? "Enable" : "Disable");
  3017. printf(" *Billing[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.isBilling > 0 ? "Enable" : "Disable");
  3018. printf(" - Currency[%2d]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
  3019. }
  3020. void ShowWebNetworkInfo(void)
  3021. {
  3022. char *str_wifi_mode[] = {"Disable", "Station", "AP Mode"};
  3023. printf("\r\n");
  3024. printf("Web [Network]\r\n");
  3025. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  3026. printf(" *DHCP Client[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0 ? "Enable" : "Disable");
  3027. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode <= _SYS_WIFI_MODE_AP)
  3028. {
  3029. printf(" *WiFi Mode [%7s]\r\n", str_wifi_mode[ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode]);
  3030. }
  3031. else
  3032. {
  3033. printf(" *WiFi Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
  3034. }
  3035. printf(" - ConnStatus[%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ? "Connected" : "Disconnected");
  3036. printf(" *3G/4G Mode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES ? "Enable" : "Disable");
  3037. printf(" - ConnStatus[%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ? "Connected" : "Disconnected");
  3038. printf(" - APN : %s\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
  3039. printf(" - RSSI: %d dBm\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
  3040. }
  3041. void ShowWebBackendInfo(void)
  3042. {
  3043. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  3044. char *str_security_profile[] = {
  3045. "None security",
  3046. "Unsecured Transport with Basic Atuentication",
  3047. "TLS with Basic Authentication",
  3048. "TLS with Client Side Certificates"
  3049. };
  3050. printf("\r\n");
  3051. printf("Web [Backend]\r\n");
  3052. printf(" *Common\r\n");
  3053. printf(" - Backend Timeout : %d s\r\n", ShmSysConfigAndInfo->SysConfig.BackendConnTimeout);
  3054. if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy <= _OFFLINE_POLICY_NO_CHARGING)
  3055. {
  3056. printf(" - Offline Policy : %s\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  3057. }
  3058. else
  3059. {
  3060. printf(" - Offline Policy : %d\r\n", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
  3061. }
  3062. printf(" - OfflineMaxEnergy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy);
  3063. printf(" - OfflineMaxDuration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration);
  3064. printf(" *OCPP\r\n");
  3065. printf(" - OcppStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES ? "Connected" : "Disconnected");
  3066. printf(" - OcppURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  3067. printf(" - ChargeBoxId: %s\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  3068. printf(" - Vendor : %s\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3069. if(ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile <= 3)
  3070. {
  3071. printf(" - Security : %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile]);
  3072. }
  3073. else
  3074. {
  3075. printf(" - Security : %d\r\n", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  3076. }
  3077. printf(" - MaintainStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus == YES ? "Connected" : "Disconnected");
  3078. printf(" - MaintainURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  3079. if(ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile <= 3)
  3080. {
  3081. printf(" - MaintainSecurity: %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile]);
  3082. }
  3083. else
  3084. {
  3085. printf(" - MaintainSecurity: %d\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile);
  3086. }
  3087. printf(" *TTIA[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES ? "Enable" : "Disable");
  3088. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES)
  3089. {
  3090. printf(" - ServerAddress: %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  3091. printf(" - ServerPort : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  3092. printf(" - BusVenderId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  3093. printf(" - Provider : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  3094. printf(" - CompanyNo : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  3095. printf(" - ChargeBoxId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  3096. printf(" - EVSEStation : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  3097. }
  3098. }
  3099. void ShowWebAllInfo(void)
  3100. {
  3101. ShowWebSystemInfo();
  3102. ShowWebChargingInfo();
  3103. ShowWebNetworkInfo();
  3104. ShowWebBackendInfo();
  3105. }
  3106. void ShowWebInfo(char *inputCmd, unsigned int opt)
  3107. {
  3108. int totalCnt = 0, maxPara = 0;
  3109. maxPara = 1;
  3110. totalCnt = GetSubCommand(inputCmd);
  3111. if(totalCnt > maxPara)
  3112. {
  3113. printf("Input cmd fail ------ web [cmd]\r\n\r\n");
  3114. return;
  3115. }
  3116. bool find = false;
  3117. int showItem = 0;
  3118. int itemLen = 5;
  3119. char strItem[32][32] = {"system", "charging", "network", "backend", "all"};
  3120. void *actionList[32] = {&ShowWebSystemInfo, &ShowWebChargingInfo, &ShowWebNetworkInfo, &ShowWebBackendInfo, &ShowWebAllInfo};
  3121. void (*ItemAction)();
  3122. for(showItem = 0; showItem < itemLen; showItem++)
  3123. {
  3124. if(strcmp((char *)&strItem[showItem][0], &MultiSubCmd[0][0]) == 0)
  3125. {
  3126. find = true;
  3127. break;
  3128. }
  3129. }
  3130. if(find)
  3131. {
  3132. ItemAction = actionList[showItem];
  3133. ItemAction();
  3134. }
  3135. else
  3136. {
  3137. printf("\r\n");
  3138. printf ("Input cmd fail ------ web [cmd]\r\n");
  3139. for(int i = 0; i < itemLen; i++)
  3140. {
  3141. printf(" [cmd] %s\r\n", (char *)&strItem[i][0]);
  3142. }
  3143. }
  3144. printf("\r\n");
  3145. }
  3146. // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXXXX.XXX kWh, IdTag: [XXXXXXXXXX]
  3147. // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW, TxId: [XXXXXXXXXX]
  3148. // PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Local: XXXXXXX.XXX kWh
  3149. // Start: [0000-00-00 00:00:00] PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Local: XXXXXXX.XXX kWh
  3150. // Gun: XXXX V, XXXX A, Remote: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  3151. // Stop: [0000-00-00 00:00:00] Gun: XXXX V, XXXX A, Remote: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  3152. void ShowGunInfo(int gun)
  3153. {
  3154. char *str_gun_type[] = {"CHAdeMO", " CCS ", " GBT "};
  3155. #if 0
  3156. printf(" Gun %d (%s) Soc: %3d %s, Energy: %10.3f kWh, IdTag [%20s] Transaction [%d], TotalCost: %.2f\r\n",
  3157. gun + 1,
  3158. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  3159. _chargingData[gun]->EvBatterySoc, "%",
  3160. _chargingData[gun]->PresentChargedEnergy,
  3161. _chargingData[gun]->StartUserId,
  3162. ShmChargerInfo->UserTransaction[gun].TransactionId,
  3163. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost);
  3164. #endif
  3165. //************************************************************************************************
  3166. printf(" Gun %d (%s) Soc: %3d %s, Energy: %11.3f kWh",
  3167. gun + 1,
  3168. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  3169. _chargingData[gun]->EvBatterySoc, "%",
  3170. _chargingData[gun]->PresentChargedEnergy);
  3171. if(strlen((char *)_chargingData[gun]->StartUserId) > 0)
  3172. {
  3173. printf(", IdTag: [%s]", _chargingData[gun]->StartUserId);
  3174. }
  3175. printf("\r\n");
  3176. //************************************************************************************************
  3177. printf(" (%2d) (%s) Target: %4d V, %4d A, Cap: %4d A, %4d kW",
  3178. _chargingData[gun]->SystemStatus,
  3179. _chargingData[gun]->ConnectorPlugIn ? "O" : "X",
  3180. (int)_chargingData[gun]->EvBatterytargetVoltage,
  3181. (int)_chargingData[gun]->EvBatterytargetCurrent,
  3182. (int)(_chargingData[gun]->AvailableChargingCurrent / 10),
  3183. (int)(_chargingData[gun]->AvailableChargingPower / 10));
  3184. if(ShmChargerInfo->UserTransaction[gun].TransactionId > 0)
  3185. {
  3186. printf(", TxId: [%d]", ShmChargerInfo->UserTransaction[gun].TransactionId);
  3187. }
  3188. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost > 0)
  3189. {
  3190. printf(", $: %.2f", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost);
  3191. }
  3192. printf("\r\n");
  3193. //************************************************************************************************
  3194. if(strlen(ShmChargerInfo->Timestamp[gun].StartCharging) > 0)
  3195. {
  3196. printf(" Start: [%s] ", ShmChargerInfo->Timestamp[gun].StartCharging);
  3197. }
  3198. else
  3199. {
  3200. printf(" ");
  3201. }
  3202. printf("PSU: %4d V, %4d A, Limit: %4d A, %4d kW, Local: %11.3f kWh\r\n",
  3203. (int)(_chargingData[gun]->PresentChargingVoltage),
  3204. (int)(_chargingData[gun]->PresentChargingCurrent),
  3205. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityCurrent / 10),
  3206. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityPower / 10),
  3207. ShmChargerInfo->MeterValue[gun].LocalConsumption);
  3208. //************************************************************************************************
  3209. if(strlen(ShmChargerInfo->Timestamp[gun].StopCharging) > 0)
  3210. {
  3211. printf(" Stop: [%s] ", ShmChargerInfo->Timestamp[gun].StopCharging);
  3212. }
  3213. else
  3214. {
  3215. printf(" ");
  3216. }
  3217. printf("Gun: %4d V, %4d A, Remote: %11.3f kWh, Meter: %11.3f kWh\r\n",
  3218. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingVoltage / 10),
  3219. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingCurrent / 10),
  3220. ShmChargerInfo->MeterValue[gun].GunConsumption, _chargingData[gun]->PowerConsumption);
  3221. }
  3222. void ShowInfo(char *inputCmd, unsigned int opt)
  3223. {
  3224. bool keepRun = false;
  3225. bool reflash = false;
  3226. int time = 0;
  3227. struct timespec _Loop_time;
  3228. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  3229. {
  3230. keepRun = true;
  3231. }
  3232. do
  3233. {
  3234. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  3235. if(time >= 1000)
  3236. {
  3237. if(reflash)
  3238. {
  3239. ConsoleReflash(CONNECTOR_QUANTITY, 5);
  3240. }
  3241. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  3242. {
  3243. printf("\r\n");
  3244. ShowGunInfo(i);
  3245. }
  3246. GetClockTime(&_Loop_time);
  3247. if((opt & OPTION_REFLASH) > 0)
  3248. {
  3249. reflash = true;
  3250. }
  3251. }
  3252. if(keepRun)
  3253. {
  3254. keepRun = IsLoopStopCmd() ? false : true;
  3255. usleep(10000);
  3256. }
  3257. }while(keepRun);
  3258. printf("\r\n");
  3259. }
  3260. void RtcSyncCmd(char *inputCmd, unsigned int opt)
  3261. {
  3262. int totalCnt = 0, maxPara = 0;
  3263. char hostAdd[32];
  3264. int dispenser = 0, offset = 0;
  3265. memset(hostAdd, 0x00, sizeof(hostAdd));
  3266. maxPara = 2;
  3267. totalCnt = GetSubCommand(inputCmd);
  3268. if(totalCnt != maxPara)
  3269. {
  3270. printf("Input cmd fail ------ rtc [dispenser 1-4] [offset minute]\r\n\r\n");
  3271. return;
  3272. }
  3273. printf("\r\n");
  3274. dispenser = atoi(&MultiSubCmd[0][0]);
  3275. offset = atoi(&MultiSubCmd[1][0]);
  3276. if(dispenser <= 0 || dispenser > CONNECTOR_QUANTITY)
  3277. {
  3278. printf("dispenser %d over range\r\n\r\n", dispenser);
  3279. return;
  3280. }
  3281. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser - 1].LocalStatus == _DS_None ||
  3282. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser - 1].LocalStatus == _DS_Timeout)
  3283. {
  3284. printf("dispenser %d is not available\r\n\r\n", dispenser);
  3285. return;
  3286. }
  3287. // find dispenser ip address
  3288. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  3289. {
  3290. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
  3291. {
  3292. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex == (dispenser - 1))
  3293. {
  3294. sprintf(hostAdd, "%d.%d.%d.%d",
  3295. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 0) &0xFF),
  3296. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 8) &0xFF),
  3297. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) &0xFF),
  3298. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) &0xFF));
  3299. }
  3300. }
  3301. }
  3302. if(strlen(hostAdd) == 0)
  3303. {
  3304. printf("dispenser %d ip is not available\r\n\r\n", dispenser);
  3305. return;
  3306. }
  3307. printf("try sycn dispenser %d [%s] rtc, offset: %d minutes\r\n", dispenser, hostAdd, offset);
  3308. // get current time and create offset time
  3309. time_t timep;
  3310. struct tm *tm;
  3311. time(&timep);
  3312. tm = localtime(&timep);
  3313. printf(" NowTime: %d/%02d/%02d %02d:%02d:%02d\r\n",
  3314. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3315. if(offset != 0)
  3316. {
  3317. timep += (offset * 60);
  3318. tm = localtime(&timep);
  3319. printf("OffsetTime: %d/%02d/%02d %02d:%02d:%02d\r\n\r\n",
  3320. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3321. }
  3322. // create send socket
  3323. int rtcfd = 0;
  3324. struct sockaddr_in serverInfo;
  3325. struct timeval tv;
  3326. char rtcTxBuffer[64];
  3327. char rtcRxBuffer[64];
  3328. int txLen = 0, rxLen = 0;
  3329. unsigned char chksum = 0x00;
  3330. rtcfd = socket(AF_INET, SOCK_STREAM, 0);
  3331. if (rtcfd < 0)
  3332. {
  3333. printf("create rtc socket fail\r\n\r\n");
  3334. return;
  3335. }
  3336. memset(rtcTxBuffer, 0x00, sizeof(rtcTxBuffer));
  3337. memset(rtcRxBuffer, 0x00, sizeof(rtcRxBuffer));
  3338. tv.tv_sec = 3;
  3339. tv.tv_usec = 0;
  3340. setsockopt(rtcfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); //設定等待3s
  3341. setsockopt(rtcfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval)); //設定傳送3s
  3342. bzero(&serverInfo,sizeof(serverInfo));
  3343. serverInfo.sin_family = AF_INET;
  3344. serverInfo.sin_addr.s_addr = inet_addr(hostAdd);
  3345. serverInfo.sin_port = htons(8234);
  3346. if(connect(rtcfd, (struct sockaddr *)&serverInfo, sizeof(serverInfo)) < 0)
  3347. {
  3348. printf("connect to host: %s fail\r\n\r\n", hostAdd);
  3349. close(rtcfd);
  3350. return;
  3351. }
  3352. // set tx header & data
  3353. rtcTxBuffer[0] = 0xAA; // Frame ID
  3354. rtcTxBuffer[1] = 0x00; // Master address
  3355. rtcTxBuffer[2] = 0xFF; // Slave address
  3356. rtcTxBuffer[3] = 0x87; // 0x87
  3357. rtcTxBuffer[4] = 0x0E; // Length_Low
  3358. rtcTxBuffer[5] = 0x00; // Length_High
  3359. sprintf(&rtcTxBuffer[6], "%04d%02d%02d%02d%02d%02d",
  3360. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3361. txLen = rtcTxBuffer[4] + (rtcTxBuffer[5] << 8);
  3362. chksum = 0;
  3363. for(int i = 0; i < txLen; i++)
  3364. {
  3365. chksum ^= rtcTxBuffer[6 + i];
  3366. }
  3367. rtcTxBuffer[6 + txLen] = chksum;
  3368. send(rtcfd, rtcTxBuffer, txLen + 7, MSG_NOSIGNAL);
  3369. // receive
  3370. if(recv(rtcfd, &rtcRxBuffer[0], 6, MSG_WAITALL) < 0)
  3371. {
  3372. printf("read head fail\r\n\r\n");
  3373. close(rtcfd);
  3374. return;
  3375. }
  3376. rxLen = rtcRxBuffer[4] + (rtcRxBuffer[5] << 8);
  3377. if(recv(rtcfd, &rtcRxBuffer[6], rxLen + 1, MSG_WAITALL) < 0)
  3378. {
  3379. printf("read data fail\r\n\r\n");
  3380. close(rtcfd);
  3381. return;
  3382. }
  3383. chksum = 0;
  3384. for(int i = 0; i < rxLen; i++)
  3385. {
  3386. chksum ^= rtcRxBuffer[6 + i];
  3387. }
  3388. if(chksum == rtcRxBuffer[6 + rxLen])
  3389. {
  3390. printf("set %s rtc: ", hostAdd);
  3391. for(int i = 0; i < txLen; i++)
  3392. {
  3393. printf("%c", rtcTxBuffer[6 + i]);
  3394. }
  3395. printf(" %s\r\n\r\n", rtcRxBuffer[6] == 0x01 ? "success" : "fail");
  3396. }
  3397. else
  3398. {
  3399. printf("receive rtc checksum fail\r\n\r\n");
  3400. }
  3401. close(rtcfd);
  3402. }
  3403. void ParsingModelName(char *modelName)
  3404. {
  3405. ParsingRatedCur parsingRatedCur = {0};
  3406. RateCurInfo *pRatedCurInfo = NULL;
  3407. if(RatedCurrentParsing(modelName, &parsingRatedCur) != PASS)
  3408. {
  3409. printf("Parsing [%s] failed\r\n", modelName);
  3410. return;
  3411. }
  3412. printf("Model Name: [%s]\r\n", modelName);
  3413. for(int i = 0; i < 2; i++)
  3414. {
  3415. pRatedCurInfo = (RateCurInfo *)&parsingRatedCur.ParsingInfo[i];
  3416. printf(" Gun %d Type %d, MaxVol: %d, MaxCur: %d\r\n",
  3417. i + 1, pRatedCurInfo->GunType, pRatedCurInfo->Voltage, pRatedCurInfo->Current);
  3418. }
  3419. }
  3420. void ParsingModelNameCmd(char *inputCmd, unsigned int opt)
  3421. {
  3422. int totalCnt = 0, maxPara = 0;
  3423. maxPara = 1;
  3424. totalCnt = GetSubCommand(inputCmd);
  3425. if(totalCnt > maxPara)
  3426. {
  3427. printf("Input cmd fail ------ pmodel [model_name]\r\n\r\n");
  3428. return;
  3429. }
  3430. printf("\r\n");
  3431. if(totalCnt != 0)
  3432. {
  3433. ParsingModelName(&MultiSubCmd[0][0]);
  3434. }
  3435. else
  3436. {
  3437. printf("Cabinet\r\n");
  3438. ParsingModelName((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  3439. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  3440. {
  3441. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  3442. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  3443. {
  3444. printf("\r\n");
  3445. printf("Dispenser %d\r\n", i + 1);
  3446. ParsingModelName((char *)&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName[0]);
  3447. }
  3448. }
  3449. }
  3450. printf("\r\n");
  3451. }
  3452. void CustomerPriceTest(char *inputCmd, unsigned int opt)
  3453. {
  3454. #if 0
  3455. char priceString[512];
  3456. float price = 0;
  3457. printf("\r\n");
  3458. // running cost
  3459. printf("Running Cost\r\n");
  3460. strcpy(priceString, "Connection Fee: $0 NTD; Session Fee: $15.96 NTD; Occupancy Fee: $0 NTD; Total Cost: $15.96 NTD; Account Balance: $37693 NTD");
  3461. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3462. printf("Connection Fee: %.2f\r\n", price);
  3463. price = PriceParsing((char *)priceString, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
  3464. printf("Session Fee: %.2f\r\n", price);
  3465. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3466. printf("Occupancy Fee: %.2f\r\n", price);
  3467. price = PriceParsing((char *)priceString, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
  3468. printf("Total Cost: %.2f\r\n", price);
  3469. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3470. printf("Account Balance: %.2f\r\n", price);
  3471. // final cost
  3472. printf("Final Cost\r\n");
  3473. strcpy(priceString, "Connection Fee: $0 NTD; Session Fee: $283.68 NTD; Occupancy Fee: $0 NTD; Total Cost: $283.68 NTD; Account Balance: $37410 NTD");
  3474. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3475. printf("Connection Fee: %.2f\r\n", price);
  3476. price = PriceParsing((char *)priceString, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
  3477. printf("Session Fee: %.2f\r\n", price);
  3478. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3479. printf("Occupancy Fee: %.2f\r\n", price);
  3480. price = PriceParsing((char *)priceString, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
  3481. printf("Total Cost: %.2f\r\n", price);
  3482. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3483. printf("Account Balance: %.2f\r\n", price);
  3484. // user price
  3485. printf("User Price\r\n");
  3486. strcpy(priceString, "Connection Fee: $0 NTD/time; Current Rate: $12 NTD/kWh; Occupancy Fee: $0 NTD/hr; Account Balance: $17553 NTD");
  3487. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3488. printf("Connection Fee: %.2f\r\n", price);
  3489. price = PriceParsing((char *)priceString, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
  3490. printf("Current Rate: %.2f\r\n", price);
  3491. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3492. printf("Occupancy Fee: %.2f\r\n", price);
  3493. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3494. printf("Account Balance: %.2f\r\n", price);
  3495. // default price
  3496. printf("Default Price\r\n");
  3497. strcpy(priceString, "Connection Fee: $0 NTD/time; Current Rate: $12 NTD/kWh; Occupancy Fee: $0 NTD/hr");
  3498. price = PriceParsing(priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3499. printf("Connection Fee: %.2f\r\n", price);
  3500. price = PriceParsing(priceString, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
  3501. printf("Current Rate: %.2f\r\n", price);
  3502. price = PriceParsing(priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3503. printf("Occupancy Fee: %.2f\r\n", price);
  3504. printf("\r\n");
  3505. printf("TCC Default Price\r\n");
  3506. strcpy(priceString, "$ 12/kWh");
  3507. price = PriceParsing(priceString, "", "");
  3508. printf("Default: %.2f\r\n", price);
  3509. printf("\r\n");
  3510. char userPrice[512];
  3511. printf("Shell Default Price\r\n");
  3512. 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");
  3513. ShellPriceParsing(priceString, userPrice);
  3514. printf("DefaultPrice: %s\r\n", userPrice);
  3515. printf("\r\n");
  3516. printf("Shell User Price\r\n");
  3517. ShellPriceParsing(priceString, userPrice);
  3518. printf("UserPrice: %s\r\n", userPrice);
  3519. printf("\r\n");
  3520. 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");
  3521. price = ShellRunningCostParsing(priceString);
  3522. printf("Shell Running Cost\r\n");
  3523. printf("Cost: %.2f\r\n", price);
  3524. printf("\r\n");
  3525. 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");
  3526. printf("Shell Final Cost\r\n");
  3527. int urlLen = 0;
  3528. char url[512];
  3529. price = ShellFinalCostParsing(priceString);
  3530. urlLen = GetShellReceiptInfo(priceString, url);
  3531. printf("Cost: %.2f\r\n", price);
  3532. if(urlLen > 0)
  3533. {
  3534. printf("Receipt: [%s]\r\n", url);
  3535. }
  3536. #endif
  3537. }
  3538. void EvCommMsgDebug(char *inputCmd, unsigned int opt)
  3539. {
  3540. int totalCnt = 0, maxPara = 0;
  3541. maxPara = 2;
  3542. totalCnt = GetSubCommand(inputCmd);
  3543. printf("\r\n");
  3544. if(totalCnt == 1)
  3545. {
  3546. if(strcmp(&MultiSubCmd[0][0], "clean") == 0)
  3547. {
  3548. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0] = 0;
  3549. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1] = 0;
  3550. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2] = 0;
  3551. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3] = 0;
  3552. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = false;
  3553. printf("Clean All EvComm Msg Flag\r\n");
  3554. printf("Disable MsgEvComm Flag Debug\r\n\r\n");
  3555. return;
  3556. }
  3557. }
  3558. if(totalCnt != maxPara)
  3559. {
  3560. printf("Input cmd fail ------ evmsg [reg] [enable 0-1]\r\n\r\n");
  3561. return;
  3562. }
  3563. bool find = false;
  3564. int reg = 0, enable = 0;
  3565. reg = atoi(&MultiSubCmd[0][0]);
  3566. enable = atoi(&MultiSubCmd[1][0]);
  3567. if(enable > 1 || enable < 0)
  3568. {
  3569. printf("enable(%d) out of range\r\n\r\n", enable);
  3570. return;
  3571. }
  3572. if(reg >= _Reg_Dispenser_Model_Name && reg < _Reg_None)
  3573. {
  3574. find = true;
  3575. if(enable)
  3576. {
  3577. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[reg / 32] |= (1 << (reg % 32));
  3578. printf("Set EvComm Msg Flag: 0x%02X\r\n", reg);
  3579. }
  3580. else
  3581. {
  3582. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[reg / 32] &= ~(1 << (reg % 32));
  3583. printf("Clean EvComm Msg Flag: 0x%02X\r\n", reg);
  3584. }
  3585. }
  3586. else
  3587. {
  3588. if(strcmp(&MultiSubCmd[0][0], "all") == 0)
  3589. {
  3590. find = true;
  3591. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.bits.RegDbg_All = enable;
  3592. printf("%s EvComm All Msg Flag\r\n", enable ? "Enable" : "Disable");
  3593. }
  3594. }
  3595. if(find)
  3596. {
  3597. printf("EvCommMsg[0]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0]);
  3598. printf("EvCommMsg[1]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1]);
  3599. printf("EvCommMsg[2]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2]);
  3600. printf("EvCommMsg[3]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3]);
  3601. printf("\r\n");
  3602. if(ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0] ||
  3603. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1] ||
  3604. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2] ||
  3605. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3])
  3606. {
  3607. if(!ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm)
  3608. {
  3609. printf("Enable MsgEvComm Flag Debug\r\n\r\n");
  3610. }
  3611. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = true;
  3612. }
  3613. else
  3614. {
  3615. if(ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm)
  3616. {
  3617. printf("Disable MsgEvComm Flag Debug\r\n\r\n");
  3618. }
  3619. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = false;
  3620. }
  3621. }
  3622. else
  3623. {
  3624. printf("reg: 0x%02X out of range\r\n", reg);
  3625. printf("\r\n");
  3626. }
  3627. }
  3628. void EvCommIdDebug(char *inputCmd, unsigned int opt)
  3629. {
  3630. int totalCnt = 0, maxPara = 0;
  3631. maxPara = 2;
  3632. totalCnt = GetSubCommand(inputCmd);
  3633. printf("\r\n");
  3634. if(totalCnt != maxPara)
  3635. {
  3636. printf("Input cmd fail ------ evid [id] [enable 0-1]\r\n\r\n");
  3637. return;
  3638. }
  3639. int id = 0, enable = 0;
  3640. id = atoi(&MultiSubCmd[0][0]);
  3641. enable = atoi(&MultiSubCmd[1][0]);
  3642. if(enable > 1 || enable < 0)
  3643. {
  3644. printf("enable(%d) out of range\r\n\r\n", enable);
  3645. return;
  3646. }
  3647. if(id > 0 && id <= CONNECTOR_QUANTITY)
  3648. {
  3649. if(enable)
  3650. {
  3651. ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal |= (1 << id);
  3652. printf("Set EvComm ID %d Enable\r\n", id);
  3653. }
  3654. else
  3655. {
  3656. ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal &= ~(1 << id);
  3657. printf("Clean EvComm ID %d\r\n", id);
  3658. }
  3659. printf("EvComm ID: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal);
  3660. printf("\r\n");
  3661. }
  3662. else
  3663. {
  3664. printf("id(%d) out of range\r\n\r\n", id);
  3665. }
  3666. }
  3667. bool SetModelName(char *modelName)
  3668. {
  3669. if(!IsCabinetModelNameLegal(modelName))
  3670. {
  3671. printf("Model Name: [%s] is Illegal\r\n", modelName);
  3672. return false;
  3673. }
  3674. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.ModelName, modelName, MODELNAME_LENGTH);
  3675. printf("Set Model Name: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.ModelName);
  3676. return true;
  3677. }
  3678. bool SetSerialNumber(char *serialNumber)
  3679. {
  3680. if(!IsSerialNumberLegal(serialNumber))
  3681. {
  3682. printf("Serial Number: [%s] is Illegal\r\n", serialNumber);
  3683. return false;
  3684. }
  3685. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.SerialNumber, serialNumber, SERIAL_NUMBER_LENGTH);
  3686. printf("Set Serial Number: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3687. return true;
  3688. }
  3689. bool SetSystemID(char *systemId)
  3690. {
  3691. if(!IsSystemIdLegal(systemId))
  3692. {
  3693. printf("System ID: [%s] is Illegal\r\n", systemId);
  3694. return false;
  3695. }
  3696. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  3697. printf("Set System ID: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  3698. return true;
  3699. }
  3700. bool CleanSystemID(void)
  3701. {
  3702. memset((char *)&ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.SystemId));
  3703. printf("Clean System ID OK\r\n");
  3704. return true;
  3705. }
  3706. bool SetAuthorisationMode(char *mode)
  3707. {
  3708. bool disable = false;
  3709. if(strcmp(mode, "disable") == EQUAL)
  3710. {
  3711. disable = true;
  3712. }
  3713. else
  3714. {
  3715. if(strcmp(mode, "enable") != EQUAL)
  3716. {
  3717. printf("Authorisation Mode: [%s] is Illegal\r\n", mode);
  3718. printf(" [value] enable | disable\r\n");
  3719. return false;
  3720. }
  3721. }
  3722. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = disable;
  3723. printf("Set Authorisation Mode: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.AuthorisationMode == 0 ? "Enable" : "Disable");
  3724. if(disable && ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID)
  3725. {
  3726. printf("AuthorisationMode Is Disable, AuthrizeByEVCCID Need To Set Disable\r\n");
  3727. ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID = false;
  3728. }
  3729. return true;
  3730. }
  3731. bool SetAuthrizeByEVCCID(char *isEVCCID)
  3732. {
  3733. bool enable = false;
  3734. if(strcmp(isEVCCID, "enable") == EQUAL)
  3735. {
  3736. enable = true;
  3737. }
  3738. else
  3739. {
  3740. if(strcmp(isEVCCID, "disable") != EQUAL)
  3741. {
  3742. printf("Authrize By EVCCID: [%s] is Illegal\r\n", isEVCCID);
  3743. printf(" [value] enable | disable\r\n");
  3744. return false;
  3745. }
  3746. }
  3747. if(enable && ShmSysConfigAndInfo->SysConfig.AuthorisationMode == 1)
  3748. {
  3749. printf("AuthorisationMode Is Disable, Reset AuthrizeByEVCCID To Disable\r\n");
  3750. enable = false;
  3751. }
  3752. ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID = enable;
  3753. printf("Set AuthrizeByEVCCID: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID ? "Enable" : "Disable");
  3754. return true;
  3755. }
  3756. bool SetQRCodeMadeMode(char *qrCodeMode)
  3757. {
  3758. bool customized = false;
  3759. if(strcmp(qrCodeMode, "customized") == EQUAL)
  3760. {
  3761. customized = true;
  3762. }
  3763. else
  3764. {
  3765. if(strcmp(qrCodeMode, "default") != EQUAL)
  3766. {
  3767. printf("QR Code Made Mode: [%s] is Illegal\r\n", qrCodeMode);
  3768. printf(" [value] default | customized\r\n");
  3769. return false;
  3770. }
  3771. }
  3772. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = customized;
  3773. printf("Set QRCodeMadeMode: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode ? "Customized" : "Default");
  3774. return true;
  3775. }
  3776. bool SetQRCodeContent(char *content)
  3777. {
  3778. if(strlen(content) >= sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent))
  3779. {
  3780. printf("QR Code Content: [%s] is Out Of Length\r\n", content);
  3781. return false;
  3782. }
  3783. memset((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent));
  3784. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, content, strlen(content));
  3785. printf("Set QRCodeContent: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  3786. return true;
  3787. }
  3788. bool CleanQRCodeContent(void)
  3789. {
  3790. memset((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent));
  3791. printf("Clean QRCode Content OK\r\n");
  3792. return true;
  3793. }
  3794. bool SetLEDIntensity(char *intensity)
  3795. {
  3796. int ledIntensity = _LED_INTENSITY_DARKEST;
  3797. char *strIntensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  3798. if(strcmp(intensity, "brightest") == EQUAL)
  3799. {
  3800. ledIntensity = _LED_INTENSITY_BRIGHTEST;
  3801. }
  3802. else if(strcmp(intensity, "medium") == EQUAL)
  3803. {
  3804. ledIntensity = _LED_INTENSITY_MEDIUM;
  3805. }
  3806. else if(strcmp(intensity, "darkest") != EQUAL)
  3807. {
  3808. printf("LED Intensity: [%s] is Illegal\r\n", intensity);
  3809. printf(" [value] darkest | medium | brightest\r\n");
  3810. return false;
  3811. }
  3812. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = ledIntensity;
  3813. printf("Set LED Intensity: [%s] OK\r\n", strIntensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  3814. return true;
  3815. }
  3816. bool SetStopChargingByButton(char *btn)
  3817. {
  3818. bool enable = false;
  3819. if(strcmp(btn, "enable") == EQUAL)
  3820. {
  3821. enable = true;
  3822. }
  3823. else
  3824. {
  3825. if(strcmp(btn, "disable") != EQUAL)
  3826. {
  3827. printf("Stop Charging By Button: [%s] is Illegal\r\n", btn);
  3828. printf(" [value] enable | disable\r\n");
  3829. return false;
  3830. }
  3831. }
  3832. ShmSysConfigAndInfo->SysConfig.StopChargingByButton = enable;
  3833. printf("Set Stop Charging By Button: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton ? "Enable" : "Disable");
  3834. return true;
  3835. }
  3836. bool SetOfflinePolicy(char *policy)
  3837. {
  3838. int offlinePolicy = _OFFLINE_POLICY_LOCAL_LIST;
  3839. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  3840. if(strcmp(policy, "free") == EQUAL)
  3841. {
  3842. offlinePolicy = _OFFLINE_POLICY_FREE_CHARGING;
  3843. }
  3844. else if(strcmp(policy, "nocharging") == EQUAL)
  3845. {
  3846. offlinePolicy = _OFFLINE_POLICY_NO_CHARGING;
  3847. }
  3848. else if(strcmp(policy, "local") != EQUAL)
  3849. {
  3850. printf("Offline Policy: [%s] is Illegal\r\n", policy);
  3851. printf(" [value] local | rfid | free | nocharging\r\n");
  3852. return false;
  3853. }
  3854. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = offlinePolicy;
  3855. printf("Set Offline Policy: [%s] OK\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  3856. return true;
  3857. }
  3858. bool SetOcppServerURL(char *url)
  3859. {
  3860. if(strlen(url) >= sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL))
  3861. {
  3862. printf("Ocpp Server URL: [%s] is Out Of Length\r\n", url);
  3863. return false;
  3864. }
  3865. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  3866. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, url);
  3867. printf("Set Ocpp Server URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  3868. return true;
  3869. }
  3870. bool CleanOcppServerURL(void)
  3871. {
  3872. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  3873. printf("Clean Ocpp Server URL OK\r\n");
  3874. return true;
  3875. }
  3876. bool SetChargeBoxId(char *boxId)
  3877. {
  3878. if(strlen(boxId) >= sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId))
  3879. {
  3880. printf("Charge Box Id: [%s] is Out Of Length\r\n", boxId);
  3881. return false;
  3882. }
  3883. memset((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  3884. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, boxId);
  3885. printf("Set Charge Box Id: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  3886. return true;
  3887. }
  3888. bool CleanChargeBoxId(void)
  3889. {
  3890. memset((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  3891. printf("Clean Charge Box Id OK\r\n");
  3892. return true;
  3893. }
  3894. bool SetChargePointVendor(char *vendor)
  3895. {
  3896. if(strlen(vendor) >= sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor))
  3897. {
  3898. printf("Charge Point Vendor: [%s] is Out Of Length\r\n", vendor);
  3899. return false;
  3900. }
  3901. memset((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  3902. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, vendor);
  3903. printf("Set Charge Point Vendor: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3904. return true;
  3905. }
  3906. bool CleanChargePointVendor(void)
  3907. {
  3908. memset((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  3909. printf("Clean Charge Point Vendor OK\r\n");
  3910. return true;
  3911. }
  3912. bool SetOcppReceiptrURL(char *receipt)
  3913. {
  3914. if(strlen(receipt) >= sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL))
  3915. {
  3916. printf("Ocpp Receiptr URL: [%s] is Out Of Length\r\n", receipt);
  3917. return false;
  3918. }
  3919. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL));
  3920. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, receipt);
  3921. printf("Set Ocpp Receiptr URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL);
  3922. return true;
  3923. }
  3924. bool CleanOcppReceiptrURL(void)
  3925. {
  3926. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL));
  3927. printf("Clean Ocpp Receiptr URL OK\r\n");
  3928. return true;
  3929. }
  3930. bool SetMaintainServerURL(char *url)
  3931. {
  3932. if(strlen(url) >= sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL))
  3933. {
  3934. printf("Maintain Server URL: [%s] is Out Of Length\r\n", url);
  3935. return false;
  3936. }
  3937. memset((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  3938. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, url);
  3939. printf("Set Maintain Server URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  3940. return true;
  3941. }
  3942. bool CleanMaintainServerURL(void)
  3943. {
  3944. memset((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  3945. printf("Clean Maintain Server URL OK\r\n");
  3946. return true;
  3947. }
  3948. void FlashSetCmd(char *inputCmd, unsigned int opt)
  3949. {
  3950. char subMain[MAX_SUB_CMD_LENGTH];
  3951. char subSub[MAX_SUB_CMD_LENGTH];
  3952. memset(subMain, 0x00, sizeof(subMain));
  3953. memset(subSub, 0x00, sizeof(subSub));
  3954. bool find = false;
  3955. int actIndex = 0;
  3956. int maxLen = 15;
  3957. char strWriteItem[32][32] = {
  3958. "model", "sn", "sysid", "auth", "evccid", "qrmode", "qrcode", "led",
  3959. "stopbtn", "policy", "backend", "boxid", "vendor", "receipt", "maintain"};
  3960. bool (*writeFlashList[32])(char *) = {
  3961. &SetModelName, &SetSerialNumber, &SetSystemID, &SetAuthorisationMode,
  3962. &SetAuthrizeByEVCCID, &SetQRCodeMadeMode, &SetQRCodeContent, &SetLEDIntensity,
  3963. &SetStopChargingByButton, &SetOfflinePolicy, &SetOcppServerURL, &SetChargeBoxId,
  3964. &SetChargePointVendor, &SetOcppReceiptrURL, &SetMaintainServerURL};
  3965. bool (*WriteFlashAct)(char *);
  3966. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3967. {
  3968. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3969. {
  3970. if(strcmp((char *)&strWriteItem[actIndex][0], subMain) == 0)
  3971. {
  3972. find = true;
  3973. break;
  3974. }
  3975. }
  3976. if(find)
  3977. {
  3978. printf("\r\n");
  3979. WriteFlashAct = writeFlashList[actIndex];
  3980. WriteFlashAct(subSub);
  3981. printf("\r\n");
  3982. return;
  3983. }
  3984. }
  3985. printf("\r\n");
  3986. printf("Input cmd fail ------ model [set] [cmd] [value]\r\n");
  3987. printf(" [cmd]");
  3988. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3989. {
  3990. printf("%s%s", actIndex == 0 ? " " : " | ", &strWriteItem[actIndex][0]);
  3991. }
  3992. printf("\r\n\r\n");
  3993. }
  3994. void FlashCleanCmd(char *inputCmd, unsigned int opt)
  3995. {
  3996. char subMain[MAX_SUB_CMD_LENGTH];
  3997. char subSub[MAX_SUB_CMD_LENGTH];
  3998. memset(subMain, 0x00, sizeof(subMain));
  3999. memset(subSub, 0x00, sizeof(subSub));
  4000. bool find = false;
  4001. int actIndex = 0;
  4002. int maxLen = 7;
  4003. char strCleanItem[32][32] = {
  4004. "sysid", "qrcode", "backend", "boxid", "vendor", "receipt", "maintain"};
  4005. bool (*cleanFlashList[32])() = {
  4006. &CleanSystemID, &CleanQRCodeContent, &CleanOcppServerURL, &CleanChargeBoxId,
  4007. &CleanChargePointVendor, &CleanOcppReceiptrURL, &CleanMaintainServerURL};
  4008. bool (*CleanFlashAct)();
  4009. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  4010. {
  4011. for(actIndex = 0; actIndex < maxLen; actIndex++)
  4012. {
  4013. if(strcmp((char *)&strCleanItem[actIndex][0], subMain) == 0)
  4014. {
  4015. find = true;
  4016. break;
  4017. }
  4018. }
  4019. if(find)
  4020. {
  4021. printf("\r\n");
  4022. CleanFlashAct = cleanFlashList[actIndex];
  4023. CleanFlashAct();
  4024. printf("\r\n");
  4025. return;
  4026. }
  4027. }
  4028. printf("\r\n");
  4029. printf("Input cmd fail ------ model [clean] [cmd]\r\n");
  4030. printf(" [cmd]");
  4031. for(actIndex = 0; actIndex < maxLen; actIndex++)
  4032. {
  4033. printf("%s%s", actIndex == 0 ? " " : " | ", &strCleanItem[actIndex][0]);
  4034. }
  4035. printf("\r\n\r\n");
  4036. }
  4037. void FlashWriteCmd(char *inputCmd, unsigned int opt)
  4038. {
  4039. if(strcmp(inputCmd, "now") == EQUAL)
  4040. {
  4041. printf("\r\n");
  4042. printf("Write Flash Immediately\r\n\r\n");
  4043. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  4044. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  4045. }
  4046. else
  4047. {
  4048. printf("\r\n");
  4049. printf("Write Flash Command Not Available\r\n\r\n");
  4050. }
  4051. }
  4052. void FlashCmd(char *inputCmd, unsigned int opt)
  4053. {
  4054. char subMain[MAX_SUB_CMD_LENGTH];
  4055. char subSub[MAX_SUB_CMD_LENGTH];
  4056. memset(subMain, 0x00, sizeof(subMain));
  4057. memset(subSub, 0x00, sizeof(subSub));
  4058. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  4059. {
  4060. if(strcmp(subMain, "set") == EQUAL)
  4061. {
  4062. FlashSetCmd(subSub, opt);
  4063. return;
  4064. }
  4065. if(strcmp(subMain, "write") == EQUAL)
  4066. {
  4067. FlashWriteCmd(subSub, opt);
  4068. return;
  4069. }
  4070. if(strcmp(subMain, "clean") == EQUAL)
  4071. {
  4072. FlashCleanCmd(subSub, opt);
  4073. return;
  4074. }
  4075. }
  4076. printf("\r\n");
  4077. printf("Input cmd fail ------ flash [set | write | clean] [cmd] [...]\r\n\r\n");
  4078. }
  4079. void EnableAbnormalRelay(void)
  4080. {
  4081. ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay = true;
  4082. printf("\r\n");
  4083. printf("Enable Abnormal Relay Cmd\r\n\r\n");
  4084. }
  4085. void DisableAbnormalRelay(void)
  4086. {
  4087. ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay = NO;
  4088. printf("\r\n");
  4089. printf("Disable Abnormal Relay Cmd\r\n\r\n");
  4090. }
  4091. void RelayWriteOutputCmd(char *inputCmd)
  4092. {
  4093. char subMain[MAX_SUB_CMD_LENGTH];
  4094. char subSub[MAX_SUB_CMD_LENGTH];
  4095. memset(subMain, 0x00, sizeof(subMain));
  4096. memset(subSub, 0x00, sizeof(subSub));
  4097. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  4098. {
  4099. int value = 0;
  4100. value = atoi(&subMain[0]);
  4101. if(value > 0 && value <= MAX_GUN_QUANTITY && (strcmp(subSub, "on") == 0 || strcmp(subSub, "off") == 0))
  4102. {
  4103. int OnOff = 0;
  4104. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  4105. {
  4106. EnableAbnormalRelay();
  4107. }
  4108. OnOff = strcmp(subSub, "on") == 0 ? YES : NO;
  4109. ShmChargerInfo->PsuGrouping.OutputRelayConfig[value - 1].bits.Output_N = OnOff;
  4110. ShmChargerInfo->PsuGrouping.OutputRelayConfig[value - 1].bits.Output_P = OnOff;
  4111. printf("\r\n");
  4112. printf("Write Gun %d OutputRelay %s\r\n\r\n", value, subSub);
  4113. return;
  4114. }
  4115. }
  4116. printf("\r\n");
  4117. printf("Input cmd fail ------ relay [write] [output] [value 1-4] [on | off]\r\n\r\n");
  4118. }
  4119. void RelayWriteParallelCmd(char *inputCmd)
  4120. {
  4121. char subMain[MAX_SUB_CMD_LENGTH];
  4122. char subSub[MAX_SUB_CMD_LENGTH];
  4123. memset(subMain, 0x00, sizeof(subMain));
  4124. memset(subSub, 0x00, sizeof(subSub));
  4125. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  4126. {
  4127. int value = 0;
  4128. value = atoi(&subMain[0]);
  4129. if(value > 0 && value <= PARALLEL_RELAY_COUNT && (strcmp(subSub, "on") == 0 || strcmp(subSub, "off") == 0))
  4130. {
  4131. int OnOff = 0;
  4132. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  4133. {
  4134. EnableAbnormalRelay();
  4135. }
  4136. OnOff = strcmp(subSub, "on") == 0 ? YES : NO;
  4137. if(OnOff)
  4138. {
  4139. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue |= 1 << (value - 1);
  4140. }
  4141. else
  4142. {
  4143. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue &= ~(1 << (value - 1));
  4144. }
  4145. printf("\r\n");
  4146. printf("Write ParallelRelay %d %s\r\n\r\n", value, subSub);
  4147. return;
  4148. }
  4149. }
  4150. printf("\r\n");
  4151. printf("Input cmd fail ------ relay [write] [parallel] [value 1-6] [on | off]\r\n\r\n");
  4152. }
  4153. void AbnormalRelayCmd(char *inputCmd, unsigned int opt)
  4154. {
  4155. char subMain[MAX_SUB_CMD_LENGTH];
  4156. char subSub[MAX_SUB_CMD_LENGTH];
  4157. memset(subMain, 0x00, sizeof(subMain));
  4158. memset(subSub, 0x00, sizeof(subSub));
  4159. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  4160. {
  4161. if(strcmp(subMain, "enable") == 0)
  4162. {
  4163. EnableAbnormalRelay();
  4164. return;
  4165. }
  4166. if(strcmp(subMain, "disable") == 0)
  4167. {
  4168. DisableAbnormalRelay();
  4169. return;
  4170. }
  4171. }
  4172. printf("\r\n");
  4173. printf("Input cmd fail ------ relay [abnormal] [enable | disable]\r\n\r\n");
  4174. }
  4175. void RelayWriteCmd(char *inputCmd, unsigned int opt)
  4176. {
  4177. char subMain[MAX_SUB_CMD_LENGTH];
  4178. char subSub[MAX_SUB_CMD_LENGTH];
  4179. memset(subMain, 0x00, sizeof(subMain));
  4180. memset(subSub, 0x00, sizeof(subSub));
  4181. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  4182. {
  4183. if(strcmp(subMain, "output") == 0)
  4184. {
  4185. RelayWriteOutputCmd(subSub);
  4186. return;
  4187. }
  4188. if(strcmp(subMain, "parallel") == 0)
  4189. {
  4190. RelayWriteParallelCmd(subSub);
  4191. return;
  4192. }
  4193. }
  4194. printf("\r\n");
  4195. printf("Input cmd fail ------ relay [write] [output | parallel] [value] [on | off]\r\n\r\n");
  4196. }
  4197. void RelayReadCmd(char *inputCmd, unsigned int opt)
  4198. {
  4199. }
  4200. void OutputRelayAutoTest(void)
  4201. {
  4202. int MaxGunCount = 0;
  4203. struct timespec _Loop_time;
  4204. int time = 0;
  4205. MaxGunCount = MAX_GUN_QUANTITY;
  4206. for(int i = 0; i < MaxGunCount; i++)
  4207. {
  4208. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = YES;
  4209. GetClockTime(&_Loop_time);
  4210. while(1)
  4211. {
  4212. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4213. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_N)
  4214. {
  4215. printf("Gun %d Output Relay N Driving Check OK\r\n", i + 1);
  4216. break;
  4217. }
  4218. if(time >= 3000)
  4219. {
  4220. printf("Gun %d Output Relay N Driving Check Fault\r\n", i + 1);
  4221. break;
  4222. }
  4223. usleep(10000);
  4224. }
  4225. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = YES;
  4226. GetClockTime(&_Loop_time);
  4227. while(1)
  4228. {
  4229. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4230. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_P)
  4231. {
  4232. printf("Gun %d Output Relay P Driving Check OK\r\n", i + 1);
  4233. break;
  4234. }
  4235. if(time >= 3000)
  4236. {
  4237. printf("Gun %d Output Relay P Driving Check Fault\r\n", i + 1);
  4238. break;
  4239. }
  4240. usleep(10000);
  4241. }
  4242. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = NO;
  4243. GetClockTime(&_Loop_time);
  4244. while(1)
  4245. {
  4246. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4247. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_N)
  4248. {
  4249. printf("Gun %d Output Relay N Welding Check OK\r\n", i + 1);
  4250. break;
  4251. }
  4252. if(time >= 3000)
  4253. {
  4254. printf("Gun %d Output Relay N Welding Check Fault\r\n", i + 1);
  4255. break;
  4256. }
  4257. usleep(10000);
  4258. }
  4259. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = NO;
  4260. GetClockTime(&_Loop_time);
  4261. while(1)
  4262. {
  4263. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4264. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_P)
  4265. {
  4266. printf("Gun %d Output Relay P Welding Check OK\r\n", i + 1);
  4267. break;
  4268. }
  4269. if(time >= 3000)
  4270. {
  4271. printf("Gun %d Output Relay P Welding Check Fault\r\n", i + 1);
  4272. break;
  4273. }
  4274. usleep(10000);
  4275. }
  4276. }
  4277. }
  4278. void ParallelRelayAutoTest(void)
  4279. {
  4280. int ParallelRelayCount = 0;
  4281. struct timespec _Loop_time;
  4282. int time = 0;
  4283. ParallelRelayCount = PARALLEL_RELAY_COUNT;
  4284. for(int i = 0; i < ParallelRelayCount; i++)
  4285. {
  4286. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue |= 1 << i;
  4287. GetClockTime(&_Loop_time);
  4288. while(1)
  4289. {
  4290. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4291. if(ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue == ShmChargerInfo->PsuGrouping.ParallelRelayConfirmed.CtrlValue)
  4292. {
  4293. printf("Location %d Parallel Relay Driving Check OK\r\n", i + 1);
  4294. break;
  4295. }
  4296. if(time >= 3000)
  4297. {
  4298. printf("Location %d Parallel Relay Driving Check Fault\r\n", i + 1);
  4299. break;
  4300. }
  4301. usleep(10000);
  4302. }
  4303. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue &= ~(1 << i);
  4304. GetClockTime(&_Loop_time);
  4305. while(1)
  4306. {
  4307. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4308. if(ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue == ShmChargerInfo->PsuGrouping.ParallelRelayConfirmed.CtrlValue)
  4309. {
  4310. printf("Location %d Parallel Relay Welding Check OK\r\n", i + 1);
  4311. break;
  4312. }
  4313. if(time >= 3000)
  4314. {
  4315. printf("Location %d Parallel Relay Welding Check Fault\r\n", i + 1);
  4316. break;
  4317. }
  4318. usleep(10000);
  4319. }
  4320. }
  4321. }
  4322. void RelayAutoTest(char *inputCmd)
  4323. {
  4324. if(strcmp(inputCmd, "now") != EQUAL)
  4325. {
  4326. printf("\r\n");
  4327. printf("Input cmd fail ------ relay [autotest] [now]\r\n\r\n");
  4328. return;
  4329. }
  4330. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  4331. {
  4332. EnableAbnormalRelay();
  4333. }
  4334. OutputRelayAutoTest();
  4335. ParallelRelayAutoTest();
  4336. printf("Relay Auto Test Completed\r\n");
  4337. DisableAbnormalRelay();
  4338. }
  4339. void RelayCmd(char *inputCmd, unsigned int opt)
  4340. {
  4341. char subMain[MAX_SUB_CMD_LENGTH];
  4342. char subSub[MAX_SUB_CMD_LENGTH];
  4343. memset(subMain, 0x00, sizeof(subMain));
  4344. memset(subSub, 0x00, sizeof(subSub));
  4345. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) >= 2)
  4346. {
  4347. if(strcmp(subMain, "abnormal") == EQUAL)
  4348. {
  4349. AbnormalRelayCmd(subSub, opt);
  4350. return;
  4351. }
  4352. if(strcmp(subMain, "write") == EQUAL)
  4353. {
  4354. RelayWriteCmd(subSub, opt);
  4355. return;
  4356. }
  4357. if(strcmp(subMain, "read") == EQUAL)
  4358. {
  4359. RelayReadCmd(subSub, opt);
  4360. return;
  4361. }
  4362. if(strcmp(subMain, "autotest") == EQUAL)
  4363. {
  4364. RelayAutoTest(subSub);
  4365. return;
  4366. }
  4367. }
  4368. printf("\r\n");
  4369. printf("Input cmd fail ------ relay [abnormal | write | read | autotest] [...]\r\n\r\n");
  4370. }
  4371. int main(void)
  4372. {
  4373. char newString[32][MAX_SUB_CMD_LENGTH];
  4374. char inputString[MAX_SUB_CMD_LENGTH], normalCmd[MAX_SUB_CMD_LENGTH];
  4375. char mainCmd[MAX_SUB_CMD_LENGTH], subCmd[MAX_SUB_CMD_LENGTH], multiCmd[MAX_SUB_CMD_LENGTH];
  4376. int cmdCnt = 0, parseCnt = 0;
  4377. unsigned int option = 0;
  4378. if(InitShareMemory() == FAIL)
  4379. {
  4380. printf ("InitShareMemory = FAIL \n");
  4381. if(ShmStatusCodeData != NULL)
  4382. {
  4383. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4384. }
  4385. sleep(5);
  4386. return 0;
  4387. }
  4388. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  4389. {
  4390. if (!FindChargingInfoData(i, &_chargingData[0]))
  4391. {
  4392. return 0;
  4393. }
  4394. }
  4395. // clean command
  4396. memset(mainCmd, 0x00, sizeof(mainCmd));
  4397. memset(subCmd, 0x00, sizeof(subCmd));
  4398. for(int i = 0; i < 32; i++)
  4399. {
  4400. memset(&newString[i], 0x00, 32);
  4401. }
  4402. for(;;)
  4403. {
  4404. memset(inputString, 0x00, sizeof(inputString));
  4405. memset(normalCmd, 0x00, sizeof(normalCmd));
  4406. get_char(inputString);
  4407. cmdCnt = InputStringNormalize(inputString, normalCmd, &option);
  4408. if(cmdCnt > 0)
  4409. {
  4410. // clean command
  4411. memset(mainCmd, 0x00, sizeof(mainCmd));
  4412. memset(subCmd, 0x00, sizeof(subCmd));
  4413. for(int i = 0; i < 32; i++)
  4414. {
  4415. memset(&newString[i], 0x00, MAX_SUB_CMD_LENGTH);
  4416. }
  4417. //printf("CmdCnt: %d\r\n", cmdCnt);
  4418. //printf("Input: %s", inputString);
  4419. //printf("Normalize: %s\r\n", normalCmd);
  4420. //printf("option: %08X\r\n", option);
  4421. MainAndSubCommandParsing(normalCmd, mainCmd, subCmd);
  4422. //printf("MainCmd: %s\r\n", mainCmd);
  4423. //printf("SubCmd: %s\r\n", subCmd);
  4424. parseCnt = 0;
  4425. strcpy(multiCmd, normalCmd);
  4426. do
  4427. {
  4428. MainAndSubCommandParsing(multiCmd, &newString[parseCnt][0], &newString[parseCnt + 1][0]);
  4429. strcpy(multiCmd, &newString[parseCnt + 1][0]);
  4430. //printf("MultiCmd Parse %d\r\n", parseCnt + 1);
  4431. //printf("MainCmd: %s\r\n", &newString[parseCnt][0]);
  4432. //printf("SubCmd: %s\r\n", &newString[parseCnt + 1][0]);
  4433. parseCnt++;
  4434. }while(parseCnt < cmdCnt - 1);
  4435. //printf("\r\n");
  4436. //for(int i = 0; i < cmdCnt; i++)
  4437. //{
  4438. // printf("MultiCmd %d: [%s]\r\n", i + 1, &newString[i][0]);
  4439. //}
  4440. }
  4441. else
  4442. {
  4443. usleep(100000);
  4444. continue;
  4445. }
  4446. if(strcmp(newString[0], "state") == 0)
  4447. {
  4448. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4449. continue;
  4450. // 槍狀態
  4451. RunStatusProc(newString[1], newString[2]);
  4452. }
  4453. else if(strcmp(newString[0], "card") == 0)
  4454. {
  4455. // 刷卡狀態
  4456. RunCardProc(newString[1], newString[2]);
  4457. }
  4458. else if(strcmp(newString[0], "gun") == 0)
  4459. {
  4460. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4461. continue;
  4462. // 插槍狀態
  4463. RunGunPlugitProc(newString[1], newString[2]);
  4464. }
  4465. else if(strcmp(newString[0], "lock") == 0)
  4466. {
  4467. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4468. continue;
  4469. // 插槍狀態
  4470. GetGunLockStatusProc(newString[1], newString[2]);
  4471. }
  4472. else if(strcmp(newString[0], "sysid") == 0)
  4473. {
  4474. // 測試 sys id
  4475. SetSystemIDProc();
  4476. }
  4477. else if(strcmp(newString[0], "self") == 0)
  4478. {
  4479. // CSU 自我檢測狀態
  4480. RunSelfProc(newString[1]);
  4481. }
  4482. else if(strcmp(newString[0], "ver") == 0)
  4483. {
  4484. //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4485. // continue;
  4486. // 取 FW 版號
  4487. //GetFwVerProc(newString[1]);
  4488. ShowFwVer();
  4489. }
  4490. else if (strcmp(newString[0], "update") == 0)
  4491. {
  4492. // 更新
  4493. FwUpdateFlagProc(newString[1]);
  4494. }
  4495. else if (strcmp(newString[0], "ac") == 0)
  4496. {
  4497. // AC contactor 狀態
  4498. CheckAcStatus(newString[1]);
  4499. }
  4500. else if (strcmp(newString[0], "cable") == 0)
  4501. {
  4502. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4503. continue;
  4504. // cable check pass
  4505. SetCableChkStatus(newString[1], newString[2]);
  4506. }
  4507. else if (strcmp(newString[0], "pow") == 0)
  4508. {
  4509. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4510. continue;
  4511. // cable check pass
  4512. SetPowerValue(newString[1], newString[2]);
  4513. }
  4514. else if(strcmp(mainCmd, "model") == 0)
  4515. {
  4516. ModelNameCmd(subCmd, option);
  4517. }
  4518. else if(strcmp(mainCmd, "sn") == 0)
  4519. {
  4520. SerialNumberCmd(subCmd, option);
  4521. }
  4522. else if(strcmp(newString[0], "fan") == 0)
  4523. {
  4524. // 設定風扇速度
  4525. SetFanSpeed(newString[1]);
  4526. }
  4527. else if(strcmp(newString[0], "speed") == 0)
  4528. {
  4529. // 取得風扇速度
  4530. GetFanSpeed();
  4531. }
  4532. else if(strcmp(newString[0], "debug") == 0)
  4533. {
  4534. // 設定 debug mode
  4535. SetDebugMode(newString[1]);
  4536. }
  4537. else if (strcmp(newString[0], "gfd") == 0)
  4538. {
  4539. // 設定盲沖使用 GFD 功能
  4540. SetGFDMode(newString[1]);
  4541. }
  4542. else if(strcmp(mainCmd, "temp") == 0)
  4543. {
  4544. // 取得溫度
  4545. GetTemperature(subCmd, option);
  4546. }
  4547. else if(strcmp(mainCmd, "acin") == 0)
  4548. {
  4549. // 取得三向輸入電壓
  4550. GetInputVol(subCmd, option);
  4551. }
  4552. else if(strcmp(newString[0], "psu") == 0)
  4553. {
  4554. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  4555. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4556. {
  4557. printf ("PSU : Param fail..Please retry again......\n");
  4558. continue;
  4559. }
  4560. // 取得 PSU 資訊
  4561. GetPsuInformation(newString[1], newString[2], newString[3]);
  4562. }
  4563. else if (strcmp(newString[0], "cap") == 0)
  4564. {
  4565. GetConnectorCapInfo(newString[1]);
  4566. }
  4567. else if(strcmp(newString[0], "error") == 0)
  4568. {
  4569. CreateOneError(newString[1]);
  4570. }
  4571. else if (strcmp(newString[0], "auth") == 0)
  4572. {
  4573. GetAuthorizeFlag(newString[1]);
  4574. }
  4575. else if (strcmp(newString[0], "id") == 0)
  4576. {
  4577. GetOrClearId(newString[1]);
  4578. }
  4579. #if 0
  4580. else if(strcmp(newString[0], "strchg") == 0)
  4581. {
  4582. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  4583. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4584. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  4585. {
  4586. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  4587. continue;
  4588. }
  4589. // 槍狀態
  4590. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  4591. }
  4592. else if(strcmp(newString[0], "str2chg") == 0)
  4593. {
  4594. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  4595. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4596. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  4597. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
  4598. strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
  4599. {
  4600. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  4601. continue;
  4602. }
  4603. // 槍狀態
  4604. RunUnconditionalCharge(newString[1], newString[2], newString[3], newString[4]);
  4605. }
  4606. #endif
  4607. else if(strcmp(newString[0], "wiring") == 0)
  4608. {
  4609. if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
  4610. strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
  4611. {
  4612. SetWiringInfo(newString[1], newString[2]);
  4613. }
  4614. ShowWiringInfo();
  4615. }
  4616. else if(strcmp(newString[0], "cwiring") == 0)
  4617. {
  4618. CleanWiringInfo();
  4619. }
  4620. else if(strcmp(newString[0], "reset") == 0)
  4621. {
  4622. SetSystemSoftRest();
  4623. }
  4624. else if(strcmp(newString[0], "reboot") == 0)
  4625. {
  4626. SetSystemHardReboot();
  4627. }
  4628. else if(strcmp(newString[0], "sgroup") == 0)
  4629. {
  4630. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4631. {
  4632. ShowGroupingInfo();
  4633. continue;
  4634. }
  4635. RunSimplePsuGrouping(newString[1], newString[2]);
  4636. }
  4637. else if(strcmp(mainCmd, "cabinet") == 0)
  4638. {
  4639. ShowCabinetInfo(subCmd, option);
  4640. }
  4641. else if(strcmp(newString[0], "tctl") == 0)
  4642. {
  4643. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4644. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  4645. {
  4646. printf("Test Control Value = %08X\n",ShmChargerInfo->Control.TestCtrl.CtrlValue);
  4647. printf ("Input cmd fail ------ tctl [tcmd] [value]\n\n");
  4648. continue;
  4649. }
  4650. SetTestControl(newString[1], newString[2]);
  4651. }
  4652. else if(strcmp(newString[0], "group") == 0)
  4653. {
  4654. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4655. {
  4656. ShowGroupingInfo();
  4657. continue;
  4658. }
  4659. }
  4660. else if(strcmp(newString[0], "gdmd") == 0)
  4661. {
  4662. ShowGroupingDemand();
  4663. }
  4664. else if(strcmp(mainCmd, "gunchg") == 0)
  4665. {
  4666. SetGunStartCharging(subCmd, option, NO);
  4667. }
  4668. else if(strcmp(mainCmd, "webchg") == 0)
  4669. {
  4670. SetGunStartCharging(subCmd, option, YES);
  4671. }
  4672. else if(strcmp(mainCmd, "gunstp") == 0)
  4673. {
  4674. SetGunStopCharging(subCmd, option);
  4675. }
  4676. else if(strcmp(newString[0], "gunext") == 0)
  4677. {
  4678. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4679. {
  4680. printf ("Input cmd fail ------ gunext [gun 1-4]\n\n");
  4681. continue;
  4682. }
  4683. SetGunExtend(newString[1]);
  4684. }
  4685. else if(strcmp(newString[0], "output") == 0)
  4686. {
  4687. ShowGunOutput();
  4688. }
  4689. else if(strcmp(newString[0], "gio") == 0)
  4690. {
  4691. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4692. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  4693. {
  4694. printf ("Input cmd fail ------ gio [io] [on-off 0-1]\n\n");
  4695. continue;
  4696. }
  4697. SetGpio(newString[1], newString[2]);
  4698. }
  4699. else if(strcmp(newString[0], "status") == 0)
  4700. {
  4701. ShowStatus();
  4702. }
  4703. else if(strcmp(newString[0], "whiteR") == 0)
  4704. {
  4705. ShowWhiteCardList();
  4706. }
  4707. else if(strcmp(newString[0], "whiteW") == 0)
  4708. {
  4709. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4710. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  4711. {
  4712. printf ("Input cmd fail ------ whiteW [index 1-10] [card id]\n\n");
  4713. continue;
  4714. }
  4715. WriteWhiteCard(newString[1], newString[2]);
  4716. }
  4717. else if(strcmp(newString[0], "whiteE") == 0)
  4718. {
  4719. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4720. {
  4721. printf ("Input cmd fail ------ whiteE [index 1-10]\n\n");
  4722. continue;
  4723. }
  4724. EraseWhiteCard(newString[1]);
  4725. }
  4726. else if(strcmp(mainCmd, "limit") == 0)
  4727. {
  4728. ShowChargerLimit(subCmd, option);
  4729. }
  4730. else if(strcmp(mainCmd, "pcmd") == 0)
  4731. {
  4732. SetPsuCommand(subCmd, option);
  4733. }
  4734. else if(strcmp(newString[0], "gcmd") == 0)
  4735. {
  4736. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4737. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  4738. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  4739. {
  4740. printf ("Input cmd fail ------ gcmd [cmd] [gun] [value]\n\n");
  4741. continue;
  4742. }
  4743. SetGunCommand(newString[1], newString[2], newString[3]);
  4744. }
  4745. else if(strcmp(mainCmd, "web") == 0)
  4746. {
  4747. ShowWebInfo(subCmd, option);
  4748. }
  4749. else if(strcmp(mainCmd, "info") == 0)
  4750. {
  4751. ShowInfo(subCmd, option);
  4752. }
  4753. else if(strcmp(mainCmd, "rtcsync") == 0)
  4754. {
  4755. RtcSyncCmd(subCmd, option);
  4756. }
  4757. else if(strcmp(mainCmd, "pmodel") == 0)
  4758. {
  4759. ParsingModelNameCmd(subCmd, option);
  4760. }
  4761. else if(strcmp(mainCmd, "pt") == 0)
  4762. {
  4763. CustomerPriceTest(subCmd, option);
  4764. }
  4765. else if(strcmp(mainCmd, "evmsg") == 0)
  4766. {
  4767. EvCommMsgDebug(subCmd, option);
  4768. }
  4769. else if(strcmp(mainCmd, "evid") == 0)
  4770. {
  4771. EvCommIdDebug(subCmd, option);
  4772. }
  4773. else if(strcmp(mainCmd, "flash") == 0)
  4774. {
  4775. FlashCmd(subCmd, option);
  4776. }
  4777. else if(strcmp(mainCmd, "relay") == 0)
  4778. {
  4779. RelayCmd(subCmd, option);
  4780. }
  4781. else
  4782. {
  4783. printf ("%s\n", msg);
  4784. }
  4785. usleep(100000);
  4786. }
  4787. return 0;
  4788. }