1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967 |
- /*
- * Main.c
- *
- * Created on: 2019年8月6日
- * Author: 7564
- */
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include <stdbool.h>
- #include "../../define.h"
- #include "Config.h"
- #include "Module_EvComm.h"
- #include "Common.h"
- typedef unsigned char byte;
- #define NO_DEFINE 255
- #define OPTION_CNT 3
- #define STR_OPTION '-'
- #define OPTION_REFLASH 0x00000001
- #define OPTION_LOOP 0x00000002
- #define OPTION_TIME 0x00000004
- #define STR_OPT_REFLASH 'f'
- #define STR_OPT_LOOP 'l'
- #define STR_OPT_TIME 't'
- #define TTY_PATH "/dev/tty"
- #define STTY_US "stty raw -echo -F "
- #define STTY_DEF "stty -raw echo -F "
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct PrimaryMcuData *ShmPrimaryMcuData;
- struct CHAdeMOData *ShmCHAdeMOData;
- struct CcsData *ShmCcsData;
- struct GBTData *ShmGBTData;
- struct FanModuleData *ShmFanModuleData;
- struct RelayModuleData *ShmRelayModuleData;
- struct LedModuleData *ShmLedModuleData;
- struct PsuData *ShmPsuData;
- ChargerInfoData *ShmChargerInfo;
- PsuPositionInfoData *ShmPsuPosition;
- PsuGroupingInfoData *ShmPsuGrouping;
- struct OCPP16Data *ShmOCPP16Data;
- struct OCPP20Data *ShmOCPP20Data;
- struct ChargingInfoData *_chargingData[CONNECTOR_QUANTITY];
- struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
- char *msg = "state : get gun state (index) \n"
- "card : scanning card (x) : \n"
- "gun : get gun plugit state (index) \n"
- "lock : get gun locked state (index) \n"
- "self : self test state (x) \n"
- "ver : ver of board (407 or index or rb or fan) \n"
- "ac : get ac relay state (x) \n"
- "gunchg: set gun start charging \n"
- "gunstp: set gun stop charging \n"
- "gunext: extend gun capability \n";
- bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
- {
- for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
- {
- if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
- {
- chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
- return true;
- }
- }
- for (byte index = 0; index < CCS_QUANTITY; index++)
- {
- if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
- {
- chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
- return true;
- }
- }
- for (byte index = 0; index < GB_QUANTITY; index++)
- {
- if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
- {
- chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
- return true;
- }
- }
- if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
- {
- chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
- return true;
- }
- return false;
- }
- bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
- {
- if (target < AC_QUANTITY)
- {
- acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
- return true;
- }
- return false;
- }
- int InitShareMemory()
- {
- int result = PASS;
- int MeterSMId;
- //initial ShmSysConfigAndInfo
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- else
- {}
- //initial ShmStatusCodeData
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- else
- {}
- if (CHAdeMO_QUANTITY > 0) {
- if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
- IPC_CREAT | 0777)) < 0) {
- result = FAIL;
- } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
- == (void *) -1) {
- result = FAIL;
- } else {
- }
- }
- if (CCS_QUANTITY > 0) {
- if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
- IPC_CREAT | 0777)) < 0) {
- result = FAIL;
- } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
- result = FAIL;
- } else {
- }
- }
- if (GB_QUANTITY > 0) {
- if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
- IPC_CREAT | 0777)) < 0) {
- return 0;
- } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
- return 0;
- }
- memset(ShmGBTData, 0, sizeof(struct GBTData));
- }
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- if(result == PASS)
- {
- ShmPsuPosition = &ShmChargerInfo->PsuPosition;
- ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
- }
- return result;
- }
- void Get_Ocpp_TransactionId(int gun_index, char *transactionId)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- sprintf(transactionId, "%d", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(transactionId, (char *)&ShmOCPP20Data->TransactionEvent [gun_index].transactionInfo.transactionId[0]);
- return;
- }
- sprintf(transactionId, "%d", 0);
- }
- static void get_char(char *word)
- {
- fd_set rfds;
- struct timeval tv;
- FD_ZERO(&rfds);
- FD_SET(0, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = 10; //wait input timout time
- //if input
- if (select(1, &rfds, NULL, NULL, &tv) > 0)
- {
- fgets(word, 128, stdin);
- }
- }
- // return command length
- int ParsingCmd(char *inputString, char *outputString)
- {
- bool valid = false, done = false;
- int len = 0, start = 0;
- for(int i = 0; i < strlen(inputString); i++)
- {
- if(!valid)
- {
- if(inputString[i] != ' ' && inputString[i] != '\0' && inputString[i] != '\r' && inputString[i] != '\n')
- {
- valid = true;
- start = i;
- }
- }
- else
- {
- if(inputString[i] == ' ' || inputString[i] == '\0' || inputString[i] == '\r' || inputString[i] == '\n' || len >= 32)
- {
- done = true;
- break;
- }
- }
- len = (valid && !done) ? len + 1 : len;
- }
- if(valid)
- {
- memcpy(outputString, &inputString[start], len);
- outputString[len] = '\0';
- }
- return len;
- }
- bool IsOption(char *strCmd, unsigned int *opt)
- {
- int len = 0;
- char str_opt[OPTION_CNT] = {STR_OPT_REFLASH, STR_OPT_LOOP, STR_OPT_TIME};
- unsigned int opt_value[OPTION_CNT] = {OPTION_REFLASH, OPTION_LOOP, OPTION_TIME};
- len = strlen(strCmd);
- if(len == 2)
- {
- if(strCmd[0] == STR_OPTION)
- {
- for(int i = 0; i < OPTION_CNT; i++)
- {
- if(strCmd[1] == str_opt[i])
- {
- *opt |= opt_value[i];
- return true;
- }
- }
- }
- }
- return false;
- }
- // inputCmdString: console input string
- // outputCmdString: input string parsed
- // return command quantity
- int InputStringNormalize(char *inputCmdString, char *outputCmdString, unsigned int *opt)
- {
- int len = 0, cnt = 0, start = 0;
- int cmdLen = 0, totalLen = 0;
- len = strlen(inputCmdString);
- *opt = 0;
- if(len > 0)
- {
- while(start < len - 1)
- {
- if(inputCmdString[start] != ' ' && inputCmdString[start] != '\0')
- {
- cmdLen = ParsingCmd(&inputCmdString[start], &outputCmdString[totalLen]);
- if(cmdLen > 0)
- {
- //printf("Find %d Cmd: %s\r\n", cnt + 1, &outputCmdString[totalLen]);
- if(!IsOption(&outputCmdString[totalLen], opt))
- {
- outputCmdString[totalLen + cmdLen] = ' ';
- cnt++;
- totalLen += cmdLen + 1;
- }
- start += cmdLen;
- }
- }
- else
- {
- start++;
- }
- }
- outputCmdString[totalLen - 1] = '\0';
- }
- return cnt;
- }
- int MainAndSubCommandParsing(char *normalCmd, char *mainCmd, char *subCmd)
- {
- int len = 0, totalLen = 0;
- strcpy(mainCmd, "");
- strcpy(subCmd, "");
- totalLen = strlen(normalCmd);
- if(totalLen > 0)
- {
- len = ParsingCmd(normalCmd, mainCmd);
- //printf("Find MainCmd: %s\r\n", mainCmd);
- if(len > 0 && totalLen > len)
- {
- strcpy(subCmd, &normalCmd[len + 1]);
- //printf("Find SubCmd: %s\r\n", subCmd);
- }
- }
- return 0;
- }
- int GetCommandSring(char *outputCmdString)
- {
- int len = 0, cnt = 0;
- int cmdLen = 0, totalLen = 0;
- char word[128];
- memset(word, 0x00, sizeof(word));
- get_char(word);
- len = strlen(word);
- if(len == 0)
- {
- return -1;
- }
- int start = 0;
- while(start < len - 1)
- {
- if(word[start] != ' ' && word[start] != '\0')
- {
- cmdLen = ParsingCmd(&word[start], &outputCmdString[totalLen]);
- char newCmd[32];
- memset(newCmd, 0x00, 32);
- memcpy(newCmd, &outputCmdString[totalLen], cmdLen);
- cnt = cmdLen > 0 ? cnt + 1 : cnt;
- totalLen += cmdLen + 1;
- start += cmdLen;
- }
- else
- {
- start++;
- }
- }
- return cnt;
- }
- bool IsLoopStopCmd(void)
- {
- bool stop = false;
- int cnt = 0;
- char cmd[256];
- char totalCmd[256];
- memset(cmd, 0x00, 256);
- memset(totalCmd, 0x00, 256);
- cnt = GetCommandSring(totalCmd);
- if(cnt > 0)
- {
- strcpy(&cmd[0], totalCmd);
- if(strcmp(&cmd[0], "c") == 0)
- {
- stop = true;
- }
- }
- return stop;
- }
- void ConsoleReflash(int groupCnt, int lineCnt)
- {
- for(int i = 0; i < groupCnt; i++)
- {
- for(int i = 0; i < lineCnt; i++)
- {
- printf("\033[1A");
- printf("\033[K");
- }
- }
- printf("\r");
- }
- void RunStatusProc(char *v1, char *v2)
- {
- printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
- printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
- if (strcmp(v1, "ac") == 0)
- {
- if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
- {
- printf("FindChargingInfoData (AC) false \n");
- }
- printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
- return;
- }
- int _index = atoi(v1);
- if (_index <= 1)
- {
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
- {
- // get
- printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
- printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
- printf("ConnectorAlarmCode = %s \n", _chargingData[_index]->ConnectorAlarmCode);
- printf("EvConnAlarmCode = %s \n", _chargingData[_index]->EvConnAlarmCode);
- printf("RemotenAlarmCode = %s \n", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].RemotenAlarmCode);
- }
- else
- {
- // set
- _chargingData[_index]->SystemStatus = atoi(v2);
- }
- }
- else
- {
- if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
- {
- printf("FindChargingInfoData (AC) false \n");
- }
- if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
- {
- // get
- printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
- }
- else
- {
- // set
- ac_chargingInfo[0]->SystemStatus = atoi(v2);
- }
- }
- }
- void RunCardProc(char *v1, char *v2)
- {
- if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
- {
- if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
- {
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
- printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
- printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
- }
- }
- else
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
- ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
- printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
- }
- }
- void RunGunPlugitProc(char *v1, char *v2)
- {
- if (strcmp(v1, "ac") == 0)
- {
- if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
- {
- printf("FindChargingInfoData (AC) false \n");
- }
- if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
- {
- // get
- printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
- }
- else
- {
- // set
- ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
- }
- return;
- }
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf("FindChargingInfoData error\n");
- return;
- }
- if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
- {
- // get
- printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
- }
- else
- {
- // set
- _chargingData[_index]->ConnectorPlugIn = atoi(v2);
- }
- }
- void GetGunLockStatusProc(char *v1, char *v2)
- {
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf("FindChargingInfoData error\n");
- return;
- }
- if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
- {
- _chargingData[_index]->GunLocked = atoi(v2);
- }
- printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
- }
- void SetSystemIDProc()
- {
- char *systemId = "Alston_Test";
- memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
- }
- void RunSelfProc()
- {
- printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
- }
- void ShowFwVer(void)
- {
- printf("\r\nPower Cabinet, Model Name: %s, SN: %s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
- printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
- //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev);
- printf("\r\n Csu Kernel: ");
- for(int i = 0; i < strlen((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev); i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\r' && ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\n')
- {
- printf("%c", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i]);
- }
- }
- printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
- printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
- printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
- printf("\r\n Relay1 Module: %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
- printf("\r\n Relay2 Module: %s", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
- {
- printf("\r\n\r\nDispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
- {
- printf(", Model Name: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName);
- printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuBootLoadFwRev);
- //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev);
- printf("\r\n Csu Kernel: ");
- for(int j = 0; j < strlen((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev); j++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\r' &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\n')
- {
- printf("%c", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j]);
- }
- }
- printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuRootFsFwRev);
- printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuPrimFwRev);
- printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].FanModuleFwRev);
- printf("\r\n Relay Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].RelayModuleFwRev);
- printf("\r\n Connector 1: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector1FwRev);
- printf("\r\n Connector 2: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector2FwRev);
- printf("\r\n Led Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LedModuleFwRev);
- }
- }
- printf("\r\n\r\n");
- }
- void GetFwVerProc(char *v1)
- {
- if (strcmp(v1, "407") == 0)
- {
- printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
- }
- else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0 || strcmp(v1, "2") == 0 || strcmp(v1, "3") == 0)
- {
- int _index = atoi(v1);
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Enable)
- {
- int dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].ParentDispensetIndex;
- int ParentIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].GeneralChargingData.Index;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
- {
- if(ParentIndex == 0)
- {
- printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
- }
- else
- {
- printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
- }
- }
- }
- else
- {
- printf("Gun %d is disable\r\n", _index);
- }
- }
- else if (strcmp(v1, "rb") == 0)
- {
- printf("RB1 Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
- printf("RB2 Version = %s \n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
- }
- else if (strcmp(v1, "fan") == 0)
- {
- printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
- }
- else if (strcmp(v1, "dc") == 0)
- {
- printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
- }
- else if (strcmp(v1, "led") == 0)
- {
- printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
- }
- }
- void CreateOneError(char *v1)
- {
- int value = atoi(v1);
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
- ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
- }
- void GetAuthorizeFlag(char *v1)
- {
- if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
- printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
- else
- ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
- }
- void GetOrClearId(char *v1)
- {
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf("FindChargingInfoData error\n");
- return;
- }
- printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
- }
- void FwUpdateFlagProc()
- {
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
- }
- void CheckAcStatus(char *v1)
- {
- if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
- {
- printf(" AC Contactor Ctrl: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactor);
- printf(" AC Off By Psu : %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu);
- printf(" AC Off ByEmergency: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency);
- printf("AC Contactor Status: %d\r\n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
- }
- else
- {
- if(system("pidof -s main > /dev/null") != 0)
- {
- if(strcmp(v1, "0") == 0)
- {
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = false;
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
- printf("Set AC Contactor Off\r\n");
- }
- else
- {
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = true;
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
- printf("Set AC Contactor On\r\n");
- }
- }
- else
- {
- printf("main task is running\r\n");
- }
- }
- }
- void SetCableChkStatus(char *v1, char *v2)
- {
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- _chargingData[_index]->GroundFaultStatus = atoi(v2);
- }
- void SetPowerValue(char *v1, char *v2)
- {
- int _index = atoi(v1);
- float _Current = atof(v2);
- // 盲沖的時候才允許使用~
- if (_chargingData[_index]->Type != 9)
- return;
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- _chargingData[_index]->EvBatterytargetCurrent = _Current;
- }
- void GetSystemInfo()
- {
- printf ("\r\n ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
- printf ("\r\nSerialNumber = %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
- printf ("\r\nInternetConn = %d", ShmSysConfigAndInfo->SysInfo.InternetConn);
- printf ("\r\nMaxChargingPower = %d kW, MaxChargingCurrent = %d A",
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
- printf("\r\n\r\n");
- }
- void SetFanSpeed(char *v1)
- {
- int speed = atoi(v1);
- ShmFanModuleData->TestFanSpeed = speed;
- }
- void GetFanSpeed()
- {
- printf("Target Speed = %d \n", ShmFanModuleData->TestFanSpeed);
- printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
- printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
- printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
- printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
- }
- void SetDebugMode(char *v1)
- {
- int mode = atoi(v1);
- ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
- }
- void SetGFDMode(char *v1)
- {
- int mode = atoi(v1);
- ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
- }
- // PSU 0 PSU 1 PSU 2 ...
- // Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb
- // 1 XXX XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX
- void GetTemperature(char *inputCmd, unsigned int opt)
- {
- bool keepRun = false;
- bool reflash = false;
- int time = 0;
- struct timespec _Loop_time;
- char strGunTemp[16], strChillerTemp[16];
- if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
- {
- keepRun = true;
- }
- printf("\r\n");
- printf(" PSU 0 PSU 1 PSU 2 .....\r\n");
- printf(" Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb\r\n");
- do
- {
- time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
- if(time >= 1000)
- {
- if(reflash)
- {
- ConsoleReflash(CONNECTOR_QUANTITY, 1);
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- sprintf(strGunTemp, "N/A");
- sprintf(strChillerTemp, "N/A");
- if(_chargingData[i]->ConnectorTemp != 0 && _chargingData[i]->ConnectorTemp != 0xFF)
- {
- sprintf(strGunTemp, "%3d", _chargingData[i]->ConnectorTemp - 60);
- }
- if(_chargingData[i]->ChillerTemp != 0 && _chargingData[i]->ChillerTemp != 0xFF)
- {
- sprintf(strChillerTemp, "%3d", _chargingData[i]->ChillerTemp - 60);
- }
- printf(" %d %s %s ", i + 1, strGunTemp, strChillerTemp);
- for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
- {
- printf(" %3d/%3d/%3d",
- ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp,
- ShmPsuData->PsuGroup[i].PsuModule[j].InletTemp,
- ShmPsuData->PsuGroup[i].PsuModule[j].CriticalTemp1);
- }
- printf("\r\n");
- }
- GetClockTime(&_Loop_time);
- if((opt & OPTION_REFLASH) > 0)
- {
- reflash = true;
- }
- }
- if(keepRun)
- {
- keepRun = IsLoopStopCmd() ? false : true;
- usleep(10000);
- }
- }while(keepRun);
- }
- void GetInputVol(char *inputCmd, unsigned int opt)
- {
- bool keepRun = false;
- bool reflash = false;
- int time = 0;
- struct timespec _Loop_time;
- if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
- {
- keepRun = true;
- }
- printf("\r\n");
- do
- {
- time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
- if(time >= 1000)
- {
- if(reflash)
- {
- ConsoleReflash(1, 1);
- }
- printf("L1N_L12 = %4.1f V, L2N_L23 = %4.1f V, L3N_L31 = %4.1f V, DC Input: %4.1f V\r\n",
- ShmSysConfigAndInfo->SysInfo.InputVoltageR,
- ShmSysConfigAndInfo->SysInfo.InputVoltageS,
- ShmSysConfigAndInfo->SysInfo.InputVoltageT,
- ShmSysConfigAndInfo->SysInfo.InputVoltageDc);
- GetClockTime(&_Loop_time);
- if((opt & OPTION_REFLASH) > 0)
- {
- reflash = true;
- }
- }
- if(keepRun)
- {
- keepRun = IsLoopStopCmd() ? false : true;
- usleep(10000);
- }
- }while(keepRun);
- printf("\r\n");
- }
- void GetPsuInformation(char *v1, char *v2, char *v3)
- {
- printf("**********************AC Contact needed*************************\n");
- if(strcmp(v1, "count") == 0)
- {
- for (int i = 0; i < 4; i++)
- {
- printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
- }
- }
- else if(strcmp(v1, "ver") == 0)
- {
- for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
- {
- printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
- i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
- }
- for (int i = 0; i < ShmPsuData->GroupCount; i++)
- {
- for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
- {
- printf("Group Index = %d, Psu Index = %d, Version = %s \n",
- i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
- }
- }
- }
- else if(strcmp(v1, "cap") == 0)
- {
- for (int i = 0; i < ShmPsuData->GroupCount; i++)
- {
- printf("Group Index = %d, MaxCur = %d, Power = %d \n",
- i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
- }
- }
- else if(strcmp(v1, "input") == 0)
- {
- for (int i = 0; i < ShmPsuData->GroupCount; i++)
- {
- for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
- {
- printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
- i, count,
- ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
- ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
- ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
- }
- }
- }
- else if (strcmp(v1, "output") == 0)
- {
- for (int i = 0; i < ShmPsuData->GroupCount; i++)
- {
- printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
- i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
- }
- }
- else if (strcmp(v1, "test") == 0)
- {
- int mode = atoi(v2);
- if (mode >= _TEST_MODE && mode <= _TEST_MODE)
- {
- ShmPsuData->Work_Step = mode;
- }
- }
- else if (strcmp(v1, "out") == 0)
- {
- float vol = atof(v2);
- float cur = atof(v3);
- if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
- {
- if (!FindChargingInfoData(0, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- _chargingData[0]->EvBatterytargetVoltage = vol;
- _chargingData[0]->EvBatterytargetCurrent = cur;
- }
- }
- printf("*************************************************\n");
- }
- void GetConnectorCapInfo(char *v1)
- {
- int _GunIndex = atoi(v1);
- if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- printf ("Charger Max Current = %d, Max Power = %d \n",
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
- printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
- _GunIndex,
- _chargingData[_GunIndex]->RealMaxPower,
- _chargingData[_GunIndex]->RealMaxVoltage,
- _chargingData[_GunIndex]->RealMaxCurrent);
- }
- void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
- {
- int _GunIndex = atoi(v1);
- float _Voltage = atof(v2);
- float _Current = atof(v3);
- unsigned char PreviousSystemStatus = 0xff;
- if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- printf ("ReqVoltage = %f, ReqCurrent = %f\n", _Voltage, _Current);
- if(_Voltage > 1000 || _Voltage < 50)
- {
- printf ("Input Voltage over range\n");
- return;
- }
- // if(_Current > 100 || _Current < 2){
- //
- // printf ("Input Current over range\n");
- // return;
- // }
- //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
- //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
- //kill ev task
- system("killall Module_EvComm");
- //_Voltage = (_Voltage * 10);
- //_Current = (_Current * 10);
- //system(STTY_US TTY_PATH);
- while(true)
- {
- //fix gun 1
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
- switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- case S_IDLE:
- {
- if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
- printf ("[UnconditionalCharge - S_IDLE]\n");
- }
- ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
- }
- break;
- case S_PREPARNING:
- {
- if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
- printf ("[UnconditionalCharge - S_PREPARNIN]\n");
- //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
- printf ("wait find module\n");
- }
- //main 會在此階段判斷以下資料跳到下一個 state
- //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
- //ShmPsuData->SystemPresentPsuQuantity;
- //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
- //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
- //_chargingData[gun_index]->AvailableChargingPower;
- //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
- //sleep(10);
- //清除 main timeout 機制
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
- }
- break;
- case S_PREPARING_FOR_EV:
- {
- if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
- printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
- printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
- }
- //清除 main timeout 機制
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
- //充電電壓電流
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
- //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
- //確定模組己升壓完成
- //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
- // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
- {
- printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
- //EV done
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
- }
- }
- break;
- case S_PREPARING_FOR_EVSE:
- {
- if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
- printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
- }
- //printf ("tar vol = %d \n", _Voltage);
- //printf ("tar cur = %d \n", _Current);
- //清除 main timeout 機制
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
- //充電電壓電流
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
- //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
- // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
- //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
- //確定模組己升壓完成
- //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
- // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
- //{
- //printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
- printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
- sleep(5);
- //EV done
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
- //}
- //else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
- //{
- // printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
- // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
- //}
- }
- break;
- case S_CHARGING:
- {
- if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
- //充電電壓電流
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
- printf ("[UnconditionalCharge - S_CHARGING]\n");
- }
- //ev task do this
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
- ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
- if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
- printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
- }
- }
- break;
- case S_TERMINATING:
- {
- if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
- system("/root/Module_EvComm &");
- printf ("[UnconditionalCharge - S_TERMINATING]\n");
- //無阻塞偵測 keybaord 結束
- system(STTY_DEF TTY_PATH);
- }
- sleep(3);
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
- return;
- }
- break;
- case S_COMPLETE:
- {
- if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
- printf ("[UnconditionalCharge - S_COMPLETE]\n");
- }
- sleep(3);
- return;
- }
- break;
- }
- char word[128];
- char newString[7][10];
- int i,j,ctr;
- memset(word, 0x00, sizeof(word));
- get_char(word);
- if (strlen(word) == 0)
- {
- continue;
- }
- j=0; ctr=0;
- strcpy(newString[1], "-1");
- strcpy(newString[2], "-1");
- for (i = 0; i <= (strlen(word)); i++)
- {
- if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
- {
- newString[ctr][j] = '\0';
- ctr++;
- j = 0;
- }
- else
- {
- newString[ctr][j] = word[i];
- j++;
- }
- }
- if(strcmp(newString[0], "chg") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- continue;
- if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
- continue;
- float _vol = atof(newString[1]);
- float _cur = atof(newString[2]);
- if (_cur <= 0 || _cur <= 0)
- continue;
- printf("vol = %f, cur = %f \n", _vol, _cur);
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
- }
- else if (strcmp(newString[0], "c") == 0)
- {
- printf("stop \n\r");
- ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
- }
- usleep(100000);
- }
- }
- void RunUnconditionalCharge(char *v1, char *v2, char *v3, char *v4)
- {
- float _Voltage[2], _Current[2];
- _Voltage[0] = atof(v1);
- _Current[0] = atof(v2);
- _Voltage[1] = atof(v3);
- _Current[1] = atof(v4);
- unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
- if(!FindChargingInfoData(0, &_chargingData[0]))
- {
- printf ("FindChargingInfoData 0 error\n");
- return;
- }
- if(!FindChargingInfoData(1, &_chargingData[0]))
- {
- printf ("FindChargingInfoData 1 error\n");
- return;
- }
- printf ("Gun 1: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[0], _Current[0]);
- printf ("Gun 2: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[1], _Current[1]);
- if(_Voltage[0] > 1000 || _Voltage[0] < 50 || _Voltage[1] > 1000 || _Voltage[1] < 50)
- {
- printf ("Input Voltage over range\n");
- return;
- }
- //kill ev task
- system("killall Module_EvComm");
- while(true)
- {
- if(_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE)
- {
- _chargingData[0]->SystemStatus = S_REASSIGN_CHECK;
- _chargingData[1]->SystemStatus = S_REASSIGN_CHECK;
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- if(_chargingData[0]->SystemStatus == S_COMPLETE && _chargingData[1]->SystemStatus == S_COMPLETE)
- {
- system(STTY_DEF TTY_PATH);
- sleep(5);
- return;
- }
- for(int i = 0; i < 2; i++)
- {
- switch(_chargingData[i]->SystemStatus)
- {
- case S_IDLE:
- {
- if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
- {
- PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
- printf ("[UnconditionalCharge (%d) - S_IDLE]\n", i);
- }
- }
- break;
- case S_PREPARNING:
- {
- if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
- {
- PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
- printf ("[UnconditionalCharge (%d) - S_PREPARNIN]\n", i);
- printf ("wait find module\n");
- }
- //清除 main timeout 機制
- _chargingData[i]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[i]->Type = 9;
- }
- break;
- case S_PREPARING_FOR_EV:
- {
- if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
- {
- PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
- printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EV]\n", i);
- printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[i] * 10,_Current[i] * 10);
- }
- //清除 main timeout 機制
- _chargingData[i]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[i]->Type = 9;
- //充電電壓電流
- _chargingData[i]->EvBatterySoc = 50;
- _chargingData[i]->EvBatterytargetVoltage = 500;
- _chargingData[i]->EvBatterytargetCurrent = 2;
- _chargingData[i]->AvailableChargingCurrent = 1000;
- printf ("Precharge Done = %f \n", _chargingData[i]->PresentChargingVoltage);
- _chargingData[i]->SystemStatus = S_PREPARING_FOR_EVSE;
- }
- break;
- case S_PREPARING_FOR_EVSE:
- {
- if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
- {
- PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
- printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EVSE]\n", i);
- }
- //清除 main timeout 機制
- _chargingData[i]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[i]->Type = 9;
- //充電電壓電流
- _chargingData[i]->EvBatterySoc = 50;
- _chargingData[i]->EvBatterytargetVoltage = 500;
- _chargingData[i]->EvBatterytargetCurrent = 2;
- _chargingData[i]->AvailableChargingCurrent = 1000;
- printf ("Wait K1K2 = %f \n", _chargingData[i]->PresentChargingVoltage);
- sleep(5);
- //EV done
- _chargingData[i]->SystemStatus = S_CHARGING;
- }
- break;
- case S_CHARGING:
- {
- if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
- {
- PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
- //充電電壓電流
- _chargingData[i]->EvBatterySoc = 50;
- _chargingData[i]->EvBatterytargetVoltage = _Voltage[i];
- _chargingData[i]->EvBatterytargetCurrent = _Current[i];
- _chargingData[i]->AvailableChargingCurrent = 1000;
- printf ("[UnconditionalCharge (%d) - S_CHARGING]\n", i);
- }
- }
- break;
- case S_TERMINATING:
- {
- if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
- {
- PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
- system("/root/Module_EvComm &");
- printf ("[UnconditionalCharge (%d) - S_TERMINATING]\n", i);
- }
- sleep(3);
- _chargingData[i]->SystemStatus = S_COMPLETE;
- }
- break;
- case S_COMPLETE:
- {
- if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
- {
- PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
- printf ("[UnconditionalCharge (%d) - S_COMPLETE]\n", i);
- }
- }
- break;
- }
- }
- char word[128];
- char newString[7][10];
- int i,j,ctr;
- memset(word, 0x00, sizeof(word));
- get_char(word);
- if (strlen(word) == 0)
- {
- continue;
- }
- j=0; ctr=0;
- strcpy(newString[1], "-1");
- strcpy(newString[2], "-1");
- for (i = 0; i <= (strlen(word)); i++)
- {
- if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
- {
- newString[ctr][j] = '\0';
- ctr++;
- j = 0;
- }
- else
- {
- newString[ctr][j] = word[i];
- j++;
- }
- }
- if(strcmp(newString[0], "chg") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- continue;
- if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
- continue;
- if (strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
- continue;
- int _gun = atoi(newString[1]);
- float _vol = atof(newString[2]);
- float _cur = atof(newString[3]);
- if(_gun >= 2 || _gun < 0)
- continue;
- if (_cur <= 0 || _cur <= 0)
- continue;
- printf("gun %d: vol = %f, cur = %f \n", _gun + 1, _vol, _cur);
- _chargingData[_gun]->EvBatterytargetVoltage = _vol;
- _chargingData[_gun]->EvBatterytargetCurrent = _cur;
- }
- else if (strcmp(newString[0], "c") == 0)
- {
- printf("stop \n\r");
- _chargingData[0]->SystemStatus = S_TERMINATING;
- _chargingData[1]->SystemStatus = S_TERMINATING;
- }
- usleep(100000);
- }
- }
- void SetWiringInfo(char *v1, char *v2)
- {
- int dispenser = atoi(v1);
- int connector = atoi(v2);
- if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
- {
- if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
- {
- printf("\r\n");
- printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
- ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
- ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
- ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
- }
- else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
- {
- printf("\r\n");
- printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
- ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
- int quantity = 0;
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
- {
- quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
- }
- ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
- }
- }
- }
- void ShowWiringInfo(void)
- {
- printf("\r\n");
- printf("********** Wiring Info **********\r\n");
- printf("Dispenser = %d, Connector = %d\r\n",
- ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
- ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
- if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
- {
- printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
- }
- }
- printf("\r\n");
- }
- void CleanWiringInfo(void)
- {
- printf("\r\n");
- printf("******* Clean Wiring Info *******\r\n");
- memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.CleanWiringInfo = true;
- printf("\r\n");
- }
- void SetSystemSoftRest(void)
- {
- printf("********* Set Soft Reset ********\r\n");
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
- }
- void SetSystemHardReboot(void)
- {
- printf("******** Set Hard Reboot ********\r\n");
- ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
- }
- void SetGroupRole(byte group, byte role)
- {
- if(group < GENERAL_GUN_QUANTITY)
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != role)
- {
- //printf("\r\nSet Group %d Role = %d", group, role);
- }
- ShmChargerInfo->PsuGrouping.GroupCollection[group].Role = role;
- }
- }
- void SetGroupToIdle(byte group)
- {
- if(group < GENERAL_GUN_QUANTITY)
- {
- SetGroupRole(group, _GROLE_IDLE);
- ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity = 0;
- memset(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
- ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = 0;
- //printf("\r\n Reset Group %02X To Idle", group);
- }
- }
- void SetGroupToMaster(byte group)
- {
- if(group < GENERAL_GUN_QUANTITY)
- {
- SetGroupRole(group, _GROLE_MASTER);
- ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = group + 1;
- //printf("\r\n Set Group %02X As Master", group);
- }
- }
- void SetGroupToSlave(byte group, byte target)
- {
- if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
- {
- SetGroupRole(group, _GROLE_SLAVE);
- ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = target + 1;
- //printf("\r\n Set Group %02X As Slave", group);
- }
- }
- // group: group index, target: target index
- // add group to target's member
- void AddGroupCollection(byte group, byte target)
- {
- int ParallelConfig = 0;
- if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role != _GROLE_MASTER)
- {
- return;
- }
- if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE &&
- ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_WAIT_IDLE &&
- ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_PRECHARGE_READY)
- {
- return;
- }
- SetGroupToSlave(group, target);
- ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity++] = group;
- ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
- if(ParallelConfig != 0)
- {
- ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
- }
- //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);
- }
- }
- // group: group index, target: target index
- // remove group out of target's member
- void RemoveGroupCollection(byte group, byte target)
- {
- int location = 0, slave = 0;
- bool find = false;
- int ParallelConfig = 0;
- if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
- {
- for(int i = 0; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
- {
- if(group == ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i])
- {
- ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
- location = i;
- find = true;
- break;
- }
- }
- if(find)
- {
- for(int i = location + 1; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
- {
- slave = ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i];
- ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
- ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i - 1] = slave;
- }
- ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity--;
- SetGroupToIdle(group);
- ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
- if(ParallelConfig != 0)
- {
- ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
- }
- //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);
- }
- }
- }
- // Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay
- // 1 (00) 00 3 00 [00] [00] [00] 0000 V 0000 A 0000 kW 0000 A 0000 A 00 XX
- void ShowGroupingInfo(void)
- {
- byte target = 0;
- printf("\r\n Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay");
- for(int i = 0; i < 4; i++)
- {
- target = ShmPsuGrouping->Layout[i];
- printf("\r\n %d (%2d) %2d %d %02X ",
- target + 1, _chargingData[target]->SystemStatus, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role,
- ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup);
- for(int j = 0; j < 3; j++)
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role == 1 && j < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity)
- {
- printf("[%02X] ", ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[j]);
- }
- else
- {
- printf(" ");
- }
- }
- printf(" %4d V %4d A %4d kW %4d A %4d A ",
- (int)_chargingData[target]->PresentChargingVoltage, (int)_chargingData[target]->PresentChargingCurrent,
- (int)(_chargingData[target]->AvailableChargingPower / 10), (int)(_chargingData[target]->AvailableChargingCurrent / 10),
- (int)(_chargingData[target]->DeratingChargingCurrent / 10));
- printf("%02X %02X",ShmPsuGrouping->OutputRelayConfig[target].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
- }
- printf("\r\n\r\nSystem Capability Current = %4d.%01d A, Power = %3d.%01d kW",
- (ShmPsuData->SystemAvailableCurrent / 10), (ShmPsuData->SystemAvailableCurrent % 10),
- (ShmPsuData->SystemAvailablePower / 10), (ShmPsuData->SystemAvailablePower % 10));
- printf("\r\n\r\n");
- }
- void PsuGroupSwitchToIdle(byte group)
- {
- int master = 0, quantity = 0, location = 0, total = 0;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_SLAVE)
- {
- return;
- }
- master = ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup - 1;
- quantity = ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Quantity;
- //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
- for(int i = 0; i < quantity; i++)
- {
- if(total == 0)
- {
- if(group == ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i])
- {
- location = i;
- total++;
- //printf("\r\n Find Group %02X At Member Index = %d", group, location);
- }
- }
- else
- {
- // find other group in the same direction
- if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
- {
- if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
- {
- total++;
- //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
- }
- }
- if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
- {
- if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
- {
- total++;
- //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
- }
- }
- }
- }
- if(total > 0)
- {
- unsigned char collection[GENERAL_GUN_QUANTITY];
- //printf("\r\n There are %d Group Need To Switch Idle:", total);
- memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member));
- for(int i = 0; i < total; i++)
- {
- //printf(" %02X", collection[i + location]);
- }
- for(int i = 0; i < total; i++)
- {
- RemoveGroupCollection(collection[i + location], master);
- }
- }
- }
- void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
- {
- int slave = 0, location = 0;
- PsuGroupPartner partner;
- memset(&partner, 0x00, sizeof(PsuGroupPartner));
- // search from left
- location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location - 1;
- for(int i = location; i >= 0; i--)
- {
- if(partner.Quantity >= quantity)
- {
- break;
- }
- slave = ShmPsuGrouping->Layout[i];
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
- {
- //printf("\r\n Find Group %02X From Left", slave);
- partner.Member[partner.Quantity++] = slave;
- }
- else
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
- {
- continue;
- }
- break;
- }
- }
- // search from right
- location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location + 1;
- for(int i = location; i < 4; i++)
- {
- if(partner.Quantity >= quantity)
- {
- break;
- }
- slave = ShmPsuGrouping->Layout[i];
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
- {
- //printf("\r\n Find Group %02X From Right", slave);
- partner.Member[partner.Quantity++] = slave;
- }
- else
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
- {
- continue;
- }
- break;
- }
- }
- memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
- }
- int GetPsuGroupAvailable(byte group)
- {
- //int slave = 0, location = 0, available = 0;
- PsuGroupPartner partner;
- FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
- //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
- return partner.Quantity;
- #if 0
- // search from left
- location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
- for(int i = location; i >= 0; i--)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
- {
- available++;
- }
- else
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
- {
- continue;
- }
- break;
- }
- }
- // search from right
- location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
- for(int i = location; i < 4; i++)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
- {
- available++;
- }
- else
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
- {
- continue;
- }
- break;
- }
- }
- return available;
- #endif
- }
- void PsuGroupShareCheck(byte group)
- {
- int slave = 0, target = 0, location = 0, share = 0, total = 0;
- total = GetPsuGroupAvailable(group) + 1;
- //printf("\r\n Gun %d Total Group = %d", group + 1, total);
- // search from left
- location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
- for(int i = location; i >= 0; i--)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
- {
- target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
- if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
- {
- share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
- }
- //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
- break;
- }
- else
- {
- break;
- }
- }
- if(share == 0)
- {
- // search from right
- location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
- for(int i = location; i < 4; i++)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
- {
- target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
- if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
- {
- share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
- }
- //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
- break;
- }
- else
- {
- break;
- }
- }
- }
- if(share > 0)
- {
- //printf("\r\n Grab %02X", slave);
- PsuGroupSwitchToIdle(slave);
- }
- else
- {
- //printf("\r\n No Need To Grab");
- }
- }
- void SimplePsuGroupStartCharging(byte group)
- {
- //int slave = 0, location = 0;
- int available = 0;
- PsuGroupPartner partner;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
- {
- return;
- }
- if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE && ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
- {
- return;
- }
- if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_IDLE)
- {
- SetGroupToMaster(group);
- PsuGroupShareCheck(group);
- }
- else
- {
- available = GetPsuGroupAvailable(group);
- //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
- if(available == 0)
- {
- return;
- }
- }
- FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
- for(int i = 0; i < partner.Quantity; i++)
- {
- AddGroupCollection(partner.Member[i], group);
- }
- ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = true;
- ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = true;
- #if 0
- // search from left
- location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
- for(int i = location; i >= 0; i--)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
- {
- //printf("\r\n Find %02X From Left", slave);
- AddGroupCollection(slave, group);
- }
- else
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
- {
- continue;
- }
- break;
- }
- }
- // search from right
- location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
- for(int i = location; i < 4; i++)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
- {
- //printf("\r\n Find %02X From Right", slave);
- AddGroupCollection(slave, group);
- }
- else
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
- {
- continue;
- }
- break;
- }
- }
- #endif
- }
- void PsuGroupStopCharging(byte group)
- {
- int total = 0;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
- {
- return;
- }
- total = ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity;
- if(total > 0)
- {
- unsigned char collection[GENERAL_GUN_QUANTITY];
- //printf("\r\n There are %d Group Need To Stop:", ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity);
- memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
- for(int i = 0; i < total; i++)
- {
- //printf(" %02X", collection[i]);
- }
- for(int i = 0; i < total; i++)
- {
- RemoveGroupCollection(collection[i], group);
- }
- }
- SetGroupToIdle(group);
- ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = false;
- ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = false;
- }
- void RunSimplePsuGrouping(char *v1, char *v2)
- {
- int group = 0, charging = 0;
- group = atoi(v1);
- charging = atoi(v2);
- group -= 1;
- if(group >= 0 && group < 4)
- {
- if(charging > 0)
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
- {
- //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
- PsuGroupSwitchToIdle(group);
- }
- SimplePsuGroupStartCharging(group);
- }
- if(charging == 0)
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_MASTER)
- {
- PsuGroupStopCharging(group);
- }
- if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
- {
- PsuGroupSwitchToIdle(group);
- }
- }
- ShowGroupingInfo();
- }
- }
- void ShowCabinetInfo(void)
- {
- int ipAddress = 0;
- printf("\r\n");
- printf("Psu Work Step = %d, PsuComm: %d\r\n", ShmPsuData->Work_Step, ShmChargerInfo->Control.CommInfo.PsuComm.CommCnt);
- printf("Psu RxCnt: %d\r\n", ShmChargerInfo->Control.CommInfo.PsuComm.RxCnt);
- printf(" Dispenser: %d / %d, Connector: %d / %d\r\n",
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
- printf("\r\n");
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
- printf(" Dispenser Connection[%d] Status: %d, DispenserIndex: %d, IP: %d.%d.%d.%d\r\n", i,
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status,
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex,
- ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
- }
- printf("\r\n");
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- printf(" Connector[%d] Index: %2X, Status = %2d , %s\r\n", i, _chargingData[i]->Index, _chargingData[i]->SystemStatus,
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable ? "Enable" : "Disable");
- }
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
- {
- printf(" Dispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
- {
- ipAddress = 0;
- for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].Status == _CNS_DispenserMatched &&
- i == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].DispenserIndex)
- {
- ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].IpAddress;
- }
- }
- printf(", ModelName: %s, IP: %d.%d.%d.%d\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName,
- ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
- for(int j = 0; j < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity; j++)
- {
- unsigned char gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorID[j];
- printf(" - Connector[%d] Gun %d, %s\r\n", j, gun, _chargingData[gun - 1]->ConnectorPlugIn ? "Plugged" : "Unplugged");
- }
- }
- else
- {
- printf(", No Information\r\n");
- }
- }
- printf("\r\n");
- }
- void SetTestControl(char *v1, char *v2)
- {
- int testItem = 0;
- int testItemLen = 3;
- int enable = 0;
- char strTest[32][32] = {"tbl", "tfsb", "chgsm"};
- char strItem[32][32] = {"Balance", "Fast Standby Time", "Charging Simulation"};
- enable = atoi(v2);
- if(enable < 0)
- {
- return;
- }
- for(int i = 0; i < testItemLen; i++)
- {
- if(strcmp((char *)&strTest[i][0], v1) == 0)
- {
- testItem = i + 1;
- break;
- }
- }
- if(testItem != 0)
- {
- if(enable)
- {
- ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
- }
- else
- {
- ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
- }
- printf("%s %s Test Item, Test Control Value = %08X\n",
- enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
- }
- else
- {
- printf("Test Item %s Not Found\n", v1);
- for(int i = 0; i < testItemLen; i++)
- {
- printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
- }
- }
- printf("\r\n");
- }
- // Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading
- // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX
- void ShowGroupingDemand(void)
- {
- byte target = 0;
- unsigned char k1k2 = 0;
- printf("\r\n Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading");
- for(int i = 0; i < 4; i++)
- {
- target = ShmPsuGrouping->Layout[i];
- if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup != 0)
- {
- k1k2 = _chargingData[ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
- }
- else
- {
- k1k2 = _chargingData[target]->RelayK1K2Status;
- }
- printf("\r\n %d %2d %02X %d %4d V %3d.%d A %4d A %3d.%02d",
- target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup, k1k2,
- (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
- (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
- (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
- (int)(_chargingData[target]->AvailableChargingCurrent / 10),
- (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
- (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
- if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup == target + 1)
- {
- printf(" %3d.%02d", (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading / 100), (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading % 100));
- }
- }
- printf("\r\n\r\n");
- }
- // v1: gun
- // v2: voltage
- // v3: current
- void SetGunStartCharging(char *v1, char *v2, char *v3)
- {
- int gun = 0;
- float _voltage = 0, _current = 0;
- gun = atoi(v1);
- _voltage = atof(v2);
- _current = atof(v3);
- if(gun <= 0 || gun > GENERAL_GUN_QUANTITY || _voltage < 0 || _voltage > 1000 || _current < 0 || _current > 1200)
- {
- printf("\r\nGun Start Charging Input parameter %s, %s, %s over range", v1, v2, v3);
- printf("\r\n\r\n");
- return;
- }
- /*
- if(_chargingData[gun - 1]->SystemStatus == S_IDLE)
- {
- printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
- ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
- ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
- ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
- ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
- }
- else if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
- {
- if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
- {
- printf("\r\nSet Gun %d > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
- ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
- ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
- }
- else
- {
- printf("\r\nGun %d Force Charging Is Disable", gun);
- }
- }
- else
- {
- printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
- }
- printf("\r\n\r\n");
- */
- bool wait = true;
- int time = 0;
- struct timespec _Wait_time;
- unsigned char PreviousSystemStatus = 0xFF;
- unsigned short _targetVoltage = 0, _targetCurrent = 0;
- while(wait)
- {
- switch(_chargingData[gun - 1]->SystemStatus)
- {
- case S_IDLE:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_IDLE", gun);
- printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
- ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
- ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
- ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
- ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- break;
- case S_REASSIGN_CHECK:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_REASSIGN_CHECK, Wait For Request Charging", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- break;
- case S_REASSIGN:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_REASSIGN, Wait For Grouping", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- break;
- case S_PREPARNING:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_PREPARNING", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- break;
- case S_PREPARING_FOR_EV:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_PREPARING_FOR_EV", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- break;
- case S_PREPARING_FOR_EVSE:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_PREPARING_FOR_EVSE, Wait For EVSE", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
- _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
- {
- _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
- _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
- printf("\r\nGun %d Set Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
- }
- break;
- case S_CHARGING:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_CHARGING", gun);
- if(PreviousSystemStatus == 0xFF)
- {
- _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
- _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
- printf("\r\nGun %d Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
- if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
- {
- printf("\r\nSet Gun %d Force Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
- ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
- ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
- }
- }
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- GetClockTime(&_Wait_time);
- }
- if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
- _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
- {
- _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
- _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
- printf("\r\nGun %d Set Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
- }
- time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
- if(time >= 3)
- {
- wait = false;
- printf("\r\nDone");
- }
- break;
- case S_TERMINATING:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_TERMINATING", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- wait = false;
- break;
- case S_COMPLETE:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_COMPLETE", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- wait = false;
- break;
- case S_ALARM:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_ALARM", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- wait = false;
- break;
- default:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun SystemStatus %d Unknown(%d)", gun, _chargingData[gun - 1]->SystemStatus);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
- wait = false;
- break;
- }
- char word[128];
- char newString[7][10];
- int i,j,ctr;
- memset(word, 0x00, sizeof(word));
- get_char(word);
- if (strlen(word) == 0)
- {
- continue;
- }
- j=0; ctr=0;
- strcpy(newString[1], "-1");
- strcpy(newString[2], "-1");
- for (i = 0; i <= (strlen(word)); i++)
- {
- if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
- {
- newString[ctr][j] = '\0';
- ctr++;
- j = 0;
- }
- else
- {
- newString[ctr][j] = word[i];
- j++;
- }
- }
- if(strcmp(newString[0], "c") == 0)
- {
- printf("\r\nStop");
- wait = false;
- }
- usleep(100000);
- }
- printf("\r\n\r\n");
- }
- // v1: gun
- void SetGunStopCharging(char *v1)
- {
- int gun = 0;
- gun = atoi(v1);
- if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
- {
- printf("\r\nGun Stop Charging Input parameter %s over range", v1);
- printf("\r\n\r\n");
- return;
- }
- /*
- if(_chargingData[gun - 1]->SystemStatus >= S_REASSIGN_CHECK && _chargingData[gun - 1]->SystemStatus <= S_CHARGING)
- {
- printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
- _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
- }
- else if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
- {
- printf("\r\nSet Group [%02X] Stop", gun - 1);
- ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
- }
- else
- {
- printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
- }
- printf("\r\n\r\n");
- */
- bool wait = true;
- int time = 0;
- struct timespec _Wait_time;
- unsigned char PreviousSystemStatus = 0xFF;
- while(wait)
- {
- switch(_chargingData[gun - 1]->SystemStatus)
- {
- case S_IDLE:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_IDLE", gun);
- if(PreviousSystemStatus == 0xFF)
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
- {
- printf("\r\nSet Group [%02X] Stop", gun - 1);
- ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
- }
- }
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- GetClockTime(&_Wait_time);
- }
- time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
- if(time >= 3)
- {
- wait = false;
- printf("\r\nDone");
- }
- break;
- case S_REASSIGN_CHECK:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_REASSIGN_CHECK, Wait For Request Charging", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
- {
- _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
- printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
- }
- }
- break;
- case S_REASSIGN:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_REASSIGN, Wait For Grouping", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
- {
- _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
- printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
- }
- }
- break;
- case S_PREPARNING:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_PREPARNING", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
- {
- _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
- printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
- }
- }
- break;
- case S_PREPARING_FOR_EV:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_PREPARING_FOR_EV", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
- {
- _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
- printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
- }
- }
- break;
- case S_PREPARING_FOR_EVSE:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_PREPARING_FOR_EVSE, Wait For EVSE", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
- {
- _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
- printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
- }
- }
- break;
- case S_CHARGING:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_CHARGING", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
- {
- _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
- printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
- }
- }
- break;
- case S_TERMINATING:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_TERMINATING", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- break;
- case S_COMPLETE:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_COMPLETE", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- break;
- case S_ALARM:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun %d S_ALARM", gun);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- break;
- default:
- if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
- {
- printf("\r\nGun SystemStatus %d Unknown(%d)", gun, _chargingData[gun - 1]->SystemStatus);
- PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
- }
- printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
- wait = false;
- break;
- }
- char word[128];
- char newString[7][10];
- int i,j,ctr;
- memset(word, 0x00, sizeof(word));
- get_char(word);
- if (strlen(word) == 0)
- {
- continue;
- }
- j=0; ctr=0;
- strcpy(newString[1], "-1");
- strcpy(newString[2], "-1");
- for (i = 0; i <= (strlen(word)); i++)
- {
- if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
- {
- newString[ctr][j] = '\0';
- ctr++;
- j = 0;
- }
- else
- {
- newString[ctr][j] = word[i];
- j++;
- }
- }
- if(strcmp(newString[0], "c") == 0)
- {
- printf("\r\nStop");
- wait = false;
- }
- usleep(100000);
- }
- printf("\r\n\r\n");
- }
- void SetGunExtend(char *v1)
- {
- int gun = 0;
- gun = atoi(v1);
- if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
- {
- printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
- ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
- }
- else
- {
- printf("\r\nGun %d Extend Capability Is Not Available, SystemStatus(%d)", gun, _chargingData[gun - 1]->SystemStatus);
- }
- printf("\r\n\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 ...
- // 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
- void ShowGunOutput(void)
- {
- byte target = 0;
- unsigned short voltage = 0, current = 0;
- 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 ...");
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- target = ShmPsuGrouping->Layout[i];
- // "\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"
- voltage = (unsigned short)(_chargingData[target]->EvBatterytargetVoltage * 10);
- current = (unsigned short)(_chargingData[target]->EvBatterytargetCurrent * 10);
- printf("\r\n %d %4d.%d V %3d.%d A", target + 1, (voltage / 10), (voltage % 10), (current / 10), (current % 10));
- voltage = ShmPsuGrouping->GroupOutput[target].GTargetVoltage;
- current = ShmPsuGrouping->GroupOutput[target].GTargetCurrent;
- printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
- voltage = (unsigned short)(_chargingData[target]->PresentChargingVoltage * 10);
- current = (unsigned short)(_chargingData[target]->PresentChargingCurrent * 10);
- printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
- voltage = ShmPsuData->PsuGroup[target].GroupPresentOutputVoltage;
- current = ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent;
- printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
- /*
- for(int j = 0; j < ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity; j++)
- {
- printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
- }
- */
- }
- printf("\r\n\r\n");
- }
- void SetGpio(char *v1, char *v2)
- {
- int testItem = 0;
- int testItemLen = 1;
- int ioOutput = 0;
- char strTest[32][32] = {"4g"};
- char strItem[32][32] = {"4G Reset"};
- ioOutput = atoi(v2);
- if(ioOutput < 0)
- {
- return;
- }
- for(int i = 0; i < testItemLen; i++)
- {
- if(strcmp((char *)&strTest[i][0], v1) == 0)
- {
- testItem = i + 1;
- break;
- }
- }
- if(testItem != 0)
- {
- if(ioOutput)
- {
- system("echo 1 > /sys/class/gpio/gpio104/value");
- }
- else
- {
- system("echo 0 > /sys/class/gpio/gpio104/value");
- }
- printf("Set %s %s\n",
- strItem[testItem - 1], ioOutput > 0 ? "High" : "Low");
- }
- else
- {
- printf("Gpio Item %s Not Found\n", v1);
- }
- printf("\r\n");
- }
- void ShowStatus(void)
- {
- char *str_cabinet_role[] = {STR_CABINET_ROLE_NONE, STR_CABINET_ROLE_MASTER, STR_CABINET_ROLE_SLAVE};
- for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
- {
- printf("\r\nGun %d Status = %d, IsAvailable = %d, GunEnable = %d",
- i + 1,
- _chargingData[i]->SystemStatus,
- _chargingData[i]->IsAvailable,
- ShmChargerInfo->Control.GunAvailable[i]);
- printf("\r\nAlarmCode");
- printf("\r\n Connector = %6s, EvConn = %6s, Remote = %6s, Vendor = %6s",
- strncmp((char *)_chargingData[i]->ConnectorAlarmCode, "", 6) != 0 ?
- (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
- strncmp((char *)_chargingData[i]->EvConnAlarmCode, "", 6) != 0 ?
- (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
- strncmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode, "", 6) != 0 ?
- (char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode : "No Err",
- strncmp((char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode, "", 6) != 0 ?
- (char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode : "No Err");
- }
- printf("\r\n");
- printf("\r\nPower Cabinet Role: %s, Switch Value: %d",
- ShmChargerInfo->Control.CabinetSwitch <= _CROLE_SLAVE ? str_cabinet_role[ShmChargerInfo->Control.CabinetSwitch] : "Unknown",
- ShmChargerInfo->Control.CabinetSwitch);
- printf("\r\nStatus Code Len = %d", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
- if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
- {
- printf("\r\n WarningCode:");
- for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
- {
- printf(" %s", (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
- }
- }
- printf("\r\n\r\n");
- }
- void ShowWhiteCardList(void)
- {
- printf("\r\nWhite Card List");
- for(int i = 0; i < 10; i++)
- {
- printf("\r\n White Card [%2d]: %s", i + 1, (char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i]);
- }
- printf("\r\n\r\n");
- }
- void WriteWhiteCard(char *v1, char *v2)
- {
- int cardIndex = 0;
- cardIndex = atoi(v1);
- if(cardIndex < 1 || cardIndex > 10)
- {
- printf("\r\n White Card Index Fail\r\n\r\n");
- return;
- }
- if(strlen(v2) == 0 || strlen(v2) > 31)
- {
- printf("\r\n White Card Fail\r\n\r\n");
- return;
- }
- printf("\r\n Str Len = %d = %s", strlen(v2), v2);
- printf("\r\n Set White Card Index %d = %s", cardIndex, v2);
- memcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], v2, strlen(v2));
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
- printf("\r\n\r\n");
- }
- void EraseWhiteCard(char *v1)
- {
- int cardIndex = 0;
- cardIndex = atoi(v1);
- if(cardIndex < 1 || cardIndex > 10)
- {
- printf("\r\n White Card Index Fail\r\n\r\n");
- return;
- }
- printf("\r\n Erase White Card Index = %d", cardIndex);
- memset((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], 0x00, 32);
- ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
- printf("\r\n\r\n");
- }
- void ShowChargerLimit(void)
- {
- int limitPower = -1;
- char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
- unsigned char inUsingCnt = 0;
- printf("\r\nCharger Limit");
- printf("\r\n System Psu Cnt: %2d", ShmPsuData->SystemPresentPsuQuantity);
- printf("\r\n Charger Max ChargingProfile Power: %d kW", ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1 ?
- (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000);
- printf("\r\n Max Total Current: %d A, Max Total Power: %d kW, Total Energy: %d kW, Total Duration %d",
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent, ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy, ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
- printf("\r\n\r\n Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur");
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- inUsingCnt = 0;
- for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[j].Role == _GROLE_MASTER)
- {
- inUsingCnt += ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity;
- }
- }
- // Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur
- // 1 0 CHAdeMO 00 0000 V 0000 A 0000 / 0000 / 0000 kW 0000 / 0000 A
- // Gun 1 Enable, Type: CCS, Psu Cnt: 00, Max Physical Vol: 0000 V, Cur: 0000 A, Max Config Pow: 0000 kW, Cur: 0000 A
- printf("\r\n %d %d ", i + 1, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable);
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable)
- {
- printf(" %7s %2d",
- _chargingData[i]->Type <= _Type_GB ? str_gun_type[_chargingData[i]->Type] : "???",
- ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity);
- printf(" %4d V %4d A",
- (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalVoltage / 10),
- (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalCurrent / 10));
- if(ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower != -1)
- {
- limitPower = (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
- if(inUsingCnt > 0)
- {
- limitPower = (limitPower * ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity) / inUsingCnt;
- }
- }
- else
- {
- limitPower = -1;
- }
- printf(" %4d / %4d / %4d kW",
- (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].MaxTotalChargingPower / 10),
- _chargingData[i]->ChargingProfilePower == -1 ? (int)_chargingData[i]->ChargingProfilePower : ((int)_chargingData[i]->ChargingProfilePower / 1000),
- limitPower == -1 ? limitPower : (limitPower / 1000));
- printf(" %4d / %4d A",
- ((int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].MaxTotalChargingCurrent / 10),
- _chargingData[i]->ChargingProfileCurrent == -1 ? (int)_chargingData[i]->ChargingProfileCurrent : ((int)_chargingData[i]->ChargingProfileCurrent / 10));
- }
- }
- printf("\r\n\r\n");
- }
- void SetGunCommand(char *v1, char *v2, char *v3)
- {
- int cmdItem = 0;
- int cmdItemLen = 2;
- int gunID = 0;
- int enable = 0;
- char strGunCmd[32][32] = {"enable", "operative"};
- char strDescription[32][32] = {"Available", "Operative"};
- gunID = atoi(v2);
- enable = atoi(v3);
- if(gunID <= 0 || gunID > CONNECTOR_QUANTITY || enable < 0)
- {
- return;
- }
- for(int i = 0; i < cmdItemLen; i++)
- {
- if(strcmp((char *)&strGunCmd[i][0], v1) == 0)
- {
- cmdItem = i + 1;
- break;
- }
- }
- if(cmdItem != 0)
- {
- switch(cmdItem)
- {
- case 1:
- ShmChargerInfo->Control.GunAvailable[gunID - 1] = enable > 0 ? YES : NO;
- ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
- break;
- case 2:
- _chargingData[gunID - 1]->IsAvailable = enable > 0 ? YES : NO;
- ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
- break;
- }
- printf("Gun cmd [%s] [%s]\n", strDescription[cmdItem - 1], enable ? "Enable" : "Disable");
- }
- else
- {
- printf("Gun cmd %s not found\n", v1);
- for(int i = 0; i < cmdItemLen; i++)
- {
- printf(" [%s] -> %s Test\n", strGunCmd[i], strDescription[i]);
- }
- }
- printf("\r\n");
- }
- void ShowWebSystemInfo(void)
- {
- char *str_led_intensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
- char *str_qr_code_made[] = {STR_QR_DEFAULT, STR_QR_CUSTOMIZED, STR_QR_CHARGEBOXID};
- char *str_rfid_endian[] = {STR_LITTLE_ENDIAN, STR_BIG_ENDIAN};
- printf("\r\n");
- printf("Web [System]\r\n");
- printf(" *System ID: %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
- printf(" *AuthorisationMode[%7s]\r\n",
- ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE ? "Enable" : "Disable");
- printf(" - APP [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAPP > 0 ? "Enable" : "Disable");
- printf(" - QRCode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isQRCode > 0 ? "Enable" : "Disable");
- printf(" - RFID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isRFID > 0 ? "Enable" : "Disable");
- printf(" - EVCCID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID > 0 ? "Enable" : "Disable");
- if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian <= RFID_ENDIAN_BIG)
- {
- printf(" *RfidCardNumEndian [%s]\r\n", str_rfid_endian[ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian]);
- }
- else
- {
- printf(" *RfidCardNumEndian: %d\r\n", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
- }
- if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode <= _QR_MODE_Customized)
- {
- printf(" *QR Code Made [%s]\r\n", str_qr_code_made[ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode]);
- }
- else
- {
- printf(" *QR Code Made: %d\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode);
- }
- if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == _QR_MODE_Customized)
- {
- printf(" - QR Code Content: %s\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
- }
- if(ShmChargerInfo->AuthInfo.QRCodeMode <= _QR_MODE_ChargeBoxId)
- {
- printf(" *QR Code Mode [%s]\r\n", str_qr_code_made[ShmChargerInfo->AuthInfo.QRCodeMode]);
- }
- else
- {
- printf(" *QR Code Mode: %d\r\n", ShmChargerInfo->AuthInfo.QRCodeMode);
- }
- if(ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity <= _LED_INTENSITY_BRIGHTEST)
- {
- printf(" *LED Intensity[%s]\r\n", str_led_intensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
- }
- else
- {
- printf(" *LED Intensity[%d]\r\n", ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity);
- }
- }
- void ShowWebChargingInfo(void)
- {
- printf("\r\n");
- printf("Web [Charging]\r\n");
- printf(" *Max Charging Energy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
- printf(" *Max Charging Power : %4d kW\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
- printf(" *Max Charging Current : %4d A\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
- printf(" *Max Charging Duration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
- printf(" *StopCharging By Button[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton > 0 ? "Enable" : "Disable");
- printf(" *Billing[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.isBilling > 0 ? "Enable" : "Disable");
- printf(" - Currency[%2d]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
- }
- void ShowWebNetworkInfo(void)
- {
- char *str_wifi_mode[] = {"Disable", "Station", "AP Mode"};
- printf("\r\n");
- printf("Web [Network]\r\n");
- printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
- printf(" *DHCP Client[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0 ? "Enable" : "Disable");
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode <= _SYS_WIFI_MODE_AP)
- {
- printf(" *WiFi Mode [%7s]\r\n", str_wifi_mode[ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode]);
- }
- else
- {
- printf(" *WiFi Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
- }
- printf(" - ConnStatus[%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ? "Connected" : "Disconnected");
- printf(" *3G/4G Mode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES ? "Enable" : "Disable");
- printf(" - ConnStatus[%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ? "Connected" : "Disconnected");
- printf(" - APN : %s\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
- printf(" - RSSI: %d dBm\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
- }
- void ShowWebBackendInfo(void)
- {
- char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
- char *str_security_profile[] = {
- "None security",
- "Unsecured Transport with Basic Atuentication",
- "TLS with Basic Authentication",
- "TLS with Client Side Certificates"
- };
- printf("\r\n");
- printf("Web [Backend]\r\n");
- printf(" *Common\r\n");
- printf(" - Backend Timeout : %d s\r\n", ShmSysConfigAndInfo->SysConfig.BackendConnTimeout);
- if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy <= _OFFLINE_POLICY_NO_CHARGING)
- {
- printf(" - Offline Policy : %s\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
- }
- else
- {
- printf(" - Offline Policy : %d\r\n", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
- }
- printf(" - OfflineMaxEnergy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy);
- printf(" - OfflineMaxDuration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration);
- printf(" *OCPP\r\n");
- printf(" - OcppStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES ? "Connected" : "Disconnected");
- printf(" - OcppURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
- printf(" - ChargeBoxId: %s\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
- printf(" - Vendor : %s\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
- if(ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile <= 3)
- {
- printf(" - Security : %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile]);
- }
- else
- {
- printf(" - Security : %d\r\n", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
- }
- printf(" - MaintainStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus == YES ? "Connected" : "Disconnected");
- printf(" - MaintainURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
- if(ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile <= 3)
- {
- printf(" - MaintainSecurity: %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile]);
- }
- else
- {
- printf(" - MaintainSecurity: %d\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile);
- }
- printf(" *TTIA[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES ? "Enable" : "Disable");
- if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES)
- {
- printf(" - ServerAddress: %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
- printf(" - ServerPort : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
- printf(" - BusVenderId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
- printf(" - Provider : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
- printf(" - CompanyNo : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
- printf(" - ChargeBoxId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
- printf(" - EVSEStation : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
- }
- }
- void ShowWebAllInfo(void)
- {
- ShowWebSystemInfo();
- ShowWebChargingInfo();
- ShowWebNetworkInfo();
- ShowWebBackendInfo();
- }
- void ShowWebInfo(char *v1)
- {
- bool find = false;
- int showItem = 0;
- int itemLen = 5;
- char strItem[32][32] = {"system", "charging", "network", "backend", "all"};
- void *actionList[32] = {&ShowWebSystemInfo, &ShowWebChargingInfo, &ShowWebNetworkInfo, &ShowWebBackendInfo, &ShowWebAllInfo};
- void (*ItemAction)();
- for(showItem = 0; showItem < itemLen; showItem++)
- {
- if(strcmp((char *)&strItem[showItem][0], v1) == 0)
- {
- find = true;
- break;
- }
- }
- if(find)
- {
- ItemAction = actionList[showItem];
- ItemAction();
- }
- else
- {
- printf("\r\n");
- printf ("Input cmd fail ------ web [cmd]\r\n");
- for(int i = 0; i < itemLen; i++)
- {
- printf(" [cmd] %s\r\n", (char *)&strItem[i][0]);
- }
- }
- printf("\r\n");
- }
- // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXX.X kWh, IdTag [XXXXXXXXXXXXXXXX] Transaction [0]
- // Gun 1 ( CCS ) IdTag: XXXXXXXXXXXXXXXX, Soc: XXX %, Energy: XXXX.X kWh
- // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW
- // Output: XXXX V, XXXX A, Limit: XXXX A, XXXX kW
- void ShowGunInfo(int gun)
- {
- char *str_gun_type[] = {"CHAdeMO", " CCS ", " GBT "};
- printf(" Gun %d (%s) Soc: %3d %s, Energy: %7.1f kWh, IdTag [%16s] Transaction [%d], TotalCost: %.2f\r\n",
- gun + 1,
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
- _chargingData[gun]->EvBatterySoc, "%",
- _chargingData[gun]->PresentChargedEnergy,
- _chargingData[gun]->StartUserId,
- ShmChargerInfo->UserTransaction[gun].TransactionId,
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost);
- //printf(" Gun %d (%s) IdTag [%16s] Soc: %3d %s, Energy: %4.1f kWh\r\n",
- // i + 1,
- // ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable ? str_gun_type[_chargingData[i]->Type] : "Disable",
- // _chargingData[i]->StartUserId,
- // _chargingData[i]->EvBatterySoc, "%",
- // _chargingData[i]->PresentChargedEnergy);
- printf(" (%2d) (%s) Target: %4d V, %4d A, Cap: %4d A, %4d kW\r\n",
- _chargingData[gun]->SystemStatus,
- _chargingData[gun]->ConnectorPlugIn ? "O" : "X",
- (int)_chargingData[gun]->EvBatterytargetVoltage,
- (int)_chargingData[gun]->EvBatterytargetCurrent,
- (int)(_chargingData[gun]->AvailableChargingCurrent / 10),
- (int)(_chargingData[gun]->AvailableChargingPower / 10));
- printf(" Output: %4d V, %4d A, Limit: %4d A, %4d kW\r\n",
- (int)(_chargingData[gun]->PresentChargingVoltage),
- (int)(_chargingData[gun]->PresentChargingCurrent),
- (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityCurrent / 10),
- (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityPower / 10));
- }
- void ShowInfo(char *inputCmd, unsigned int opt)
- {
- bool keepRun = false;
- bool reflash = false;
- int time = 0;
- struct timespec _Loop_time;
- if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
- {
- keepRun = true;
- }
- do
- {
- time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
- if(time >= 1000)
- {
- if(reflash)
- {
- ConsoleReflash(CONNECTOR_QUANTITY, 4);
- }
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- printf("\r\n");
- ShowGunInfo(i);
- }
- GetClockTime(&_Loop_time);
- if((opt & OPTION_REFLASH) > 0)
- {
- reflash = true;
- }
- }
- if(keepRun)
- {
- keepRun = IsLoopStopCmd() ? false : true;
- usleep(10000);
- }
- }while(keepRun);
- printf("\r\n");
- }
- int main(void)
- {
- char newString[32][32];
- char inputString[128], normalCmd[128], mainCmd[128], subCmd[128], multiCmd[128];
- int cmdCnt = 0, parseCnt = 0;
- unsigned int option = 0;
- if(InitShareMemory() == FAIL)
- {
- printf ("InitShareMemory = FAIL \n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
- }
- sleep(5);
- return 0;
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if (!FindChargingInfoData(i, &_chargingData[0]))
- {
- return 0;
- }
- }
- // clean command
- memset(mainCmd, 0x00, sizeof(mainCmd));
- memset(subCmd, 0x00, sizeof(subCmd));
- for(int i = 0; i < 32; i++)
- {
- memset(&newString[i], 0x00, 32);
- }
- for(;;)
- {
- memset(inputString, 0x00, sizeof(inputString));
- memset(normalCmd, 0x00, sizeof(normalCmd));
- get_char(inputString);
- cmdCnt = InputStringNormalize(inputString, normalCmd, &option);
- if(cmdCnt > 0)
- {
- // clean command
- memset(mainCmd, 0x00, sizeof(mainCmd));
- memset(subCmd, 0x00, sizeof(subCmd));
- for(int i = 0; i < 32; i++)
- {
- memset(&newString[i], 0x00, 32);
- }
- //printf("CmdCnt: %d\r\n", cmdCnt);
- //printf("Input: %s", inputString);
- //printf("Normalize: %s\r\n", normalCmd);
- //printf("option: %08X\r\n", option);
- MainAndSubCommandParsing(normalCmd, mainCmd, subCmd);
- //printf("MainCmd: %s\r\n", mainCmd);
- //printf("SubCmd: %s\r\n", subCmd);
- parseCnt = 0;
- strcpy(multiCmd, normalCmd);
- do
- {
- MainAndSubCommandParsing(multiCmd, &newString[parseCnt][0], &newString[parseCnt + 1][0]);
- strcpy(multiCmd, &newString[parseCnt + 1][0]);
- //printf("MultiCmd Parse %d\r\n", parseCnt + 1);
- //printf("MainCmd: %s\r\n", &newString[parseCnt][0]);
- //printf("SubCmd: %s\r\n", &newString[parseCnt + 1][0]);
- parseCnt++;
- }while(parseCnt < cmdCnt - 1);
- //printf("\r\n");
- //for(int i = 0; i < cmdCnt; i++)
- //{
- // printf("MultiCmd %d: [%s]\r\n", i + 1, &newString[i][0]);
- //}
- }
- else
- {
- usleep(100000);
- continue;
- }
- if(strcmp(newString[0], "state") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- continue;
- // 槍狀態
- RunStatusProc(newString[1], newString[2]);
- }
- else if(strcmp(newString[0], "card") == 0)
- {
- // 刷卡狀態
- RunCardProc(newString[1], newString[2]);
- }
- else if(strcmp(newString[0], "gun") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- continue;
- // 插槍狀態
- RunGunPlugitProc(newString[1], newString[2]);
- }
- else if(strcmp(newString[0], "lock") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- continue;
- // 插槍狀態
- GetGunLockStatusProc(newString[1], newString[2]);
- }
- else if(strcmp(newString[0], "sysid") == 0)
- {
- // 測試 sys id
- SetSystemIDProc();
- }
- else if(strcmp(newString[0], "self") == 0)
- {
- // CSU 自我檢測狀態
- RunSelfProc(newString[1]);
- }
- else if(strcmp(newString[0], "ver") == 0)
- {
- //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- // continue;
- // 取 FW 版號
- //GetFwVerProc(newString[1]);
- ShowFwVer();
- }
- else if (strcmp(newString[0], "update") == 0)
- {
- // 更新
- FwUpdateFlagProc(newString[1]);
- }
- else if (strcmp(newString[0], "ac") == 0)
- {
- // AC contactor 狀態
- CheckAcStatus(newString[1]);
- }
- else if (strcmp(newString[0], "cable") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- continue;
- // cable check pass
- SetCableChkStatus(newString[1], newString[2]);
- }
- else if (strcmp(newString[0], "pow") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- continue;
- // cable check pass
- SetPowerValue(newString[1], newString[2]);
- }
- else if (strcmp(newString[0], "model") == 0)
- {
- GetSystemInfo();
- }
- else if(strcmp(newString[0], "fan") == 0)
- {
- // 設定風扇速度
- SetFanSpeed(newString[1]);
- }
- else if(strcmp(newString[0], "speed") == 0)
- {
- // 取得風扇速度
- GetFanSpeed();
- }
- else if(strcmp(newString[0], "debug") == 0)
- {
- // 設定 debug mode
- SetDebugMode(newString[1]);
- }
- else if (strcmp(newString[0], "gfd") == 0)
- {
- // 設定盲沖使用 GFD 功能
- SetGFDMode(newString[1]);
- }
- else if(strcmp(mainCmd, "temp") == 0)
- {
- // 取得溫度
- GetTemperature(subCmd, option);
- }
- else if(strcmp(mainCmd, "acin") == 0)
- {
- // 取得三向輸入電壓
- GetInputVol(subCmd, option);
- }
- else if(strcmp(newString[0], "psu") == 0)
- {
- //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- printf ("PSU : Param fail..Please retry again......\n");
- continue;
- }
- // 取得 PSU 資訊
- GetPsuInformation(newString[1], newString[2], newString[3]);
- }
- else if (strcmp(newString[0], "cap") == 0)
- {
- GetConnectorCapInfo(newString[1]);
- }
- else if(strcmp(newString[0], "error") == 0)
- {
- CreateOneError(newString[1]);
- }
- else if (strcmp(newString[0], "auth") == 0)
- {
- GetAuthorizeFlag(newString[1]);
- }
- else if (strcmp(newString[0], "id") == 0)
- {
- GetOrClearId(newString[1]);
- }
- #if 0
- else if(strcmp(newString[0], "strchg") == 0)
- {
- //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
- strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
- {
- printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
- continue;
- }
- // 槍狀態
- RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
- }
- else if(strcmp(newString[0], "str2chg") == 0)
- {
- //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
- strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
- strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
- strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
- {
- printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
- continue;
- }
- // 槍狀態
- RunUnconditionalCharge(newString[1], newString[2], newString[3], newString[4]);
- }
- #endif
- else if(strcmp(newString[0], "wiring") == 0)
- {
- if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
- strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
- {
- SetWiringInfo(newString[1], newString[2]);
- }
- ShowWiringInfo();
- }
- else if(strcmp(newString[0], "cwiring") == 0)
- {
- CleanWiringInfo();
- }
- else if(strcmp(newString[0], "reset") == 0)
- {
- SetSystemSoftRest();
- }
- else if(strcmp(newString[0], "reboot") == 0)
- {
- SetSystemHardReboot();
- }
- else if(strcmp(newString[0], "sgroup") == 0)
- {
- if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- ShowGroupingInfo();
- continue;
- }
- RunSimplePsuGrouping(newString[1], newString[2]);
- }
- else if(strcmp(newString[0], "cabinet") == 0)
- {
- ShowCabinetInfo();
- }
- else if(strcmp(newString[0], "tctl") == 0)
- {
- if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
- strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
- {
- printf("Test Control Value = %08X\n",ShmChargerInfo->Control.TestCtrl.CtrlValue);
- printf ("Input cmd fail ------ tctl [tcmd] [value]\n\n");
- continue;
- }
- SetTestControl(newString[1], newString[2]);
- }
- else if(strcmp(newString[0], "group") == 0)
- {
- if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- ShowGroupingInfo();
- continue;
- }
- }
- else if(strcmp(newString[0], "gdmd") == 0)
- {
- ShowGroupingDemand();
- }
- else if(strcmp(newString[0], "gunchg") == 0)
- {
- if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
- strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
- strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
- {
- printf ("Input cmd fail ------ gunchg [gun 1-4] [voltage 0-1000] [current 0-100]\n\n");
- continue;
- }
- SetGunStartCharging(newString[1], newString[2], newString[3]);
- }
- else if(strcmp(newString[0], "gunstp") == 0)
- {
- if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- printf ("Input cmd fail ------ gunstp [gun 1-4]\n\n");
- continue;
- }
- SetGunStopCharging(newString[1]);
- }
- else if(strcmp(newString[0], "gunext") == 0)
- {
- if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- printf ("Input cmd fail ------ gunext [gun 1-4]\n\n");
- continue;
- }
- SetGunExtend(newString[1]);
- }
- else if(strcmp(newString[0], "output") == 0)
- {
- ShowGunOutput();
- }
- else if(strcmp(newString[0], "gio") == 0)
- {
- if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
- strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
- {
- printf ("Input cmd fail ------ gio [io] [on-off 0-1]\n\n");
- continue;
- }
- SetGpio(newString[1], newString[2]);
- }
- else if(strcmp(newString[0], "status") == 0)
- {
- ShowStatus();
- }
- else if(strcmp(newString[0], "whiteR") == 0)
- {
- ShowWhiteCardList();
- }
- else if(strcmp(newString[0], "whiteW") == 0)
- {
- if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
- strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
- {
- printf ("Input cmd fail ------ whiteW [index 1-10] [card id]\n\n");
- continue;
- }
- WriteWhiteCard(newString[1], newString[2]);
- }
- else if(strcmp(newString[0], "whiteE") == 0)
- {
- if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- printf ("Input cmd fail ------ whiteE [index 1-10]\n\n");
- continue;
- }
- EraseWhiteCard(newString[1]);
- }
- else if(strcmp(newString[0], "limit") == 0)
- {
- ShowChargerLimit();
- }
- else if(strcmp(newString[0], "pcmd") == 0)
- {
- }
- /*
- else if(strcmp(newString[0], "dbop") == 0)
- {
- if(DeductDB_Open())
- {
- printf ("Deduct DB Open OK\n\n");
- }
- else
- {
- printf ("Deduct DB Open OK\n\n");
- }
- }
- else if(strcmp(newString[0], "dbup") == 0)
- {
- int gun = 0;
- RecordTransactionInfo deduct;
- if(DB_GetReUploadDeduct(&gun, &deduct) == PASS)
- {
- printf("Get Gun %d, TxId: %d, Result: %d, Donate: %d, ApprovalNo: %s, CardNo: %s, VemData: %s, Amount: %f, IsUpload: %d\r\n",
- gun, deduct.TransactionId, deduct.DeductResult, deduct.IsDonateInvoice, deduct.ApprovalNo, deduct.CardNo, deduct.VemData, deduct.Amount, deduct.IsUpload);
- deduct.IsUpload = YES;
- printf("Set this deduct upload OK, and restore into database\r\n");
- UpdateDeductInfoStatus(gun, &deduct);
- }
- else
- {
- printf("There is no deduct info need to upload\r\n");
- }
- }
- else if(strcmp(newString[0], "dbde") == 0)
- {
- int gun = 0;
- RecordTransactionInfo deduct;
- if(DB_GetReDeductInfo(&gun, &deduct) == PASS)
- {
- printf("Get Gun %d, TxId: %d, Result: %d, Donate: %d, ApprovalNo: %s, CardNo: %s, VemData: %s, Amount: %f, IsUpload: %d\r\n",
- gun, deduct.TransactionId, deduct.DeductResult, deduct.IsDonateInvoice, deduct.ApprovalNo, deduct.CardNo, deduct.VemData, deduct.Amount, deduct.IsUpload);
- deduct.DeductResult = YES;
- printf("Set this deduct result OK, and restore into database\r\n");
- UpdateDeductInfoStatus(gun, &deduct);
- }
- else
- {
- printf("There is no deduct info need to re-deduct\r\n");
- }
- }
- else if(strcmp(newString[0], "db") == 0)
- {
- DB_GetAllDeductInfo();
- }
- */
- else if(strcmp(newString[0], "gcmd") == 0)
- {
- if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
- strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
- strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
- {
- printf ("Input cmd fail ------ gcmd [cmd] [gun] [value]\n\n");
- continue;
- }
- SetGunCommand(newString[1], newString[2], newString[3]);
- }
- else if(strcmp(newString[0], "web") == 0)
- {
- ShowWebInfo(newString[1]);
- }
- else if(strcmp(mainCmd, "info") == 0)
- {
- ShowInfo(subCmd, option);
- }
- else
- {
- printf ("%s\n", msg);
- }
- usleep(100000);
- }
- return 0;
- }
|