123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192 |
- /*
- * 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 PASS 1
- #define FAIL -1
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define NO_DEFINE 255
- #define DEFAULT_AC_INDEX 2
- #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;
- PsuGroupCollectionData *ShmGroupCollection;
- 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(result == PASS)
- {
- ShmPsuPosition = &ShmChargerInfo->PsuPosition;
- ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
- ShmGroupCollection = &ShmChargerInfo->PsuGrouping.GroupCollection[0];
- }
- return result;
- }
- 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, MaxChargingCurrent = %d",
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
- printf("\r\n\r\n");
- }
- void ChangeGunNum()
- {
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- }
- else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
- else
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- }
- }
- void GetGunSelectedNum(char *v1)
- {
- if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
- {
- if (AC_QUANTITY > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
- {
- printf("connector select changed = AC \n");
- }
- else
- printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- else
- {
- int _index = atoi(v1);
- if (_index <= 1)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- printf("connector select changed = %d \n", _index);
- }
- else if (AC_QUANTITY > 0)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
- printf("connector select changed = AC \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;
- }
- // Gun Temp Chiller PSU 0 PSU 1 PSU 2 ...
- // 1 XXX XXX XXX XXX XXX XXX
- void GetTemperature(char *v1)
- {
- bool show = false;
- char strGunTemp[16], strChillerTemp[16];
- if(strcmp(v1, "c") == 0)
- {
- printf("\r\n Get c Parameter");
- show = true;
- }
- do
- {
- printf("\r\n Gun Temp Chiller PSU 0 PSU 1 PSU 2 ...");
- 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("\r\n %d %s %s ", i + 1, strGunTemp, strChillerTemp);
- for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
- {
- printf(" %3d ", ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp);
- }
- }
- printf("\r\n");
- if(show)
- {
- sleep(1);
- }
- }while(show);
- }
- void GetAcInputVol()
- {
- printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
- ShmSysConfigAndInfo->SysInfo.InputVoltageR,
- ShmSysConfigAndInfo->SysInfo.InputVoltageS,
- ShmSysConfigAndInfo->SysInfo.InputVoltageT);
- }
- 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);
- }
- 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);
- }
- }
- 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(ShmGroupCollection[group].Role != role)
- {
- //printf("\r\nSet Group %d Role = %d", group, role);
- }
- ShmGroupCollection[group].Role = role;
- }
- }
- void SetGroupToIdle(byte group)
- {
- if(group < GENERAL_GUN_QUANTITY)
- {
- SetGroupRole(group, _GROLE_IDLE);
- ShmGroupCollection[group].Partner.Quantity = 0;
- memset(ShmGroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmGroupCollection[group].Partner.Member));
- ShmGroupCollection[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);
- ShmGroupCollection[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);
- ShmGroupCollection[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(ShmGroupCollection[target].Role != _GROLE_MASTER)
- {
- return;
- }
- if(ShmGroupCollection[group].Role != _GROLE_IDLE &&
- ShmGroupCollection[group].Role != _GROLE_WAIT_IDLE &&
- ShmGroupCollection[group].Role != _GROLE_PRECHARGE_READY)
- {
- return;
- }
- SetGroupToSlave(group, target);
- ShmGroupCollection[target].Partner.Member[ShmGroupCollection[target].Partner.Quantity++] = group;
- ParallelConfig = ShmGroupCollection[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, ShmGroupCollection[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 < ShmGroupCollection[target].Partner.Quantity; i++)
- {
- if(group == ShmGroupCollection[target].Partner.Member[i])
- {
- ShmGroupCollection[target].Partner.Member[i] = 0;
- location = i;
- find = true;
- break;
- }
- }
- if(find)
- {
- for(int i = location + 1; i < ShmGroupCollection[target].Partner.Quantity; i++)
- {
- slave = ShmGroupCollection[target].Partner.Member[i];
- ShmGroupCollection[target].Partner.Member[i] = 0;
- ShmGroupCollection[target].Partner.Member[i - 1] = slave;
- }
- ShmGroupCollection[target].Partner.Quantity--;
- SetGroupToIdle(group);
- ParallelConfig = ShmGroupCollection[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, ShmGroupCollection[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, ShmGroupCollection[target].Role,
- ShmGroupCollection[target].Partner.Quantity, ShmGroupCollection[target].TargetGroup);
- for(int j = 0; j < 3; j++)
- {
- if(ShmGroupCollection[target].Role == 1 && j < ShmGroupCollection[target].Partner.Quantity)
- {
- printf("[%02X] ", ShmGroupCollection[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(ShmGroupCollection[group].Role != _GROLE_SLAVE)
- {
- return;
- }
- master = ShmGroupCollection[group].TargetGroup - 1;
- quantity = ShmGroupCollection[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 == ShmGroupCollection[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[ShmGroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
- {
- if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
- {
- total++;
- //printf("\r\n Find Other Group %02X In The Same Direction", ShmGroupCollection[master].Partner.Member[i]);
- }
- }
- if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
- {
- if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
- {
- total++;
- //printf("\r\n Find Other Group %02X In The Same Direction", ShmGroupCollection[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, ShmGroupCollection[master].Partner.Member, ARRAY_SIZE(ShmGroupCollection[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 = ShmGroupCollection[master].Location - 1;
- for(int i = location; i >= 0; i--)
- {
- if(partner.Quantity >= quantity)
- {
- break;
- }
- slave = ShmPsuGrouping->Layout[i];
- if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
- {
- //printf("\r\n Find Group %02X From Left", slave);
- partner.Member[partner.Quantity++] = slave;
- }
- else
- {
- if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmGroupCollection[slave].TargetGroup - 1))
- {
- continue;
- }
- break;
- }
- }
- // search from right
- location = ShmGroupCollection[master].Location + 1;
- for(int i = location; i < 4; i++)
- {
- if(partner.Quantity >= quantity)
- {
- break;
- }
- slave = ShmPsuGrouping->Layout[i];
- if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
- {
- //printf("\r\n Find Group %02X From Right", slave);
- partner.Member[partner.Quantity++] = slave;
- }
- else
- {
- if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmGroupCollection[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 = ShmGroupCollection[group].Location - 1;
- for(int i = location; i >= 0; i--)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
- {
- available++;
- }
- else
- {
- if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
- {
- continue;
- }
- break;
- }
- }
- // search from right
- location = ShmGroupCollection[group].Location + 1;
- for(int i = location; i < 4; i++)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
- {
- available++;
- }
- else
- {
- if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[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 = ShmGroupCollection[group].Location - 1;
- for(int i = location; i >= 0; i--)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmGroupCollection[slave].Role == _GROLE_SLAVE)
- {
- target = ShmGroupCollection[slave].TargetGroup - 1;
- if((ShmGroupCollection[target].Partner.Quantity + 1) > total)
- {
- share = (ShmGroupCollection[target].Partner.Quantity + 1 - total) / 2;
- }
- //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmGroupCollection[target].Partner.Quantity, share);
- break;
- }
- else
- {
- break;
- }
- }
- if(share == 0)
- {
- // search from right
- location = ShmGroupCollection[group].Location + 1;
- for(int i = location; i < 4; i++)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmGroupCollection[slave].Role == _GROLE_SLAVE)
- {
- target = ShmGroupCollection[slave].TargetGroup - 1;
- if((ShmGroupCollection[target].Partner.Quantity + 1) > total)
- {
- share = (ShmGroupCollection[target].Partner.Quantity + 1 - total) / 2;
- }
- //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmGroupCollection[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(ShmGroupCollection[group].Role == _GROLE_SLAVE)
- {
- return;
- }
- if(ShmGroupCollection[group].Role != _GROLE_IDLE && ShmGroupCollection[group].Role != _GROLE_MASTER)
- {
- return;
- }
- if(ShmGroupCollection[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 = ShmGroupCollection[group].Location - 1;
- for(int i = location; i >= 0; i--)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
- {
- //printf("\r\n Find %02X From Left", slave);
- AddGroupCollection(slave, group);
- }
- else
- {
- if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
- {
- continue;
- }
- break;
- }
- }
- // search from right
- location = ShmGroupCollection[group].Location + 1;
- for(int i = location; i < 4; i++)
- {
- slave = ShmPsuGrouping->Layout[i];
- if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
- {
- //printf("\r\n Find %02X From Right", slave);
- AddGroupCollection(slave, group);
- }
- else
- {
- if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
- {
- continue;
- }
- break;
- }
- }
- #endif
- }
- void PsuGroupStopCharging(byte group)
- {
- int total = 0;
- if(ShmGroupCollection[group].Role != _GROLE_MASTER)
- {
- return;
- }
- total = ShmGroupCollection[group].Partner.Quantity;
- if(total > 0)
- {
- unsigned char collection[GENERAL_GUN_QUANTITY];
- //printf("\r\n There are %d Group Need To Stop:", ShmGroupCollection[group].Partner.Quantity);
- memcpy(collection, ShmGroupCollection[group].Partner.Member, ARRAY_SIZE(ShmGroupCollection[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(ShmGroupCollection[group].Role == _GROLE_SLAVE)
- {
- //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
- PsuGroupSwitchToIdle(group);
- }
- SimplePsuGroupStartCharging(group);
- }
- if(charging == 0)
- {
- if(ShmGroupCollection[group].Role == _GROLE_MASTER)
- {
- PsuGroupStopCharging(group);
- }
- if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
- {
- PsuGroupSwitchToIdle(group);
- }
- }
- ShowGroupingInfo();
- }
- }
- void ShowCabinetInfo(void)
- {
- int ipAddress = 0;
- printf("\r\nPower Cabinet Charging Mode = %d, ReAssignedFlag = %d, Psu Work Step = %d",
- ShmSysConfigAndInfo->SysInfo.MainChargingMode, ShmSysConfigAndInfo->SysInfo.ReAssignedFlag, ShmPsuData->Work_Step);
- printf("\r\n Dispenser: %d / %d, Connector: %d / %d",
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- printf("\r\n Connector[%d] Index: %2X, Status = %2d , %s", 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("\r\n 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", 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("\r\n - Connector[%d] Gun %d, %s", j, gun, _chargingData[gun - 1]->ConnectorPlugIn ? "Plugged" : "Unplugged");
- }
- }
- else
- {
- printf(", No Information");
- }
- }
- printf("\r\n\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(ShmGroupCollection[target].TargetGroup != 0)
- {
- k1k2 = _chargingData[ShmGroupCollection[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, ShmGroupCollection[target].Role, ShmGroupCollection[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(ShmGroupCollection[target].TargetGroup == target + 1)
- {
- printf(" %3d.%02d", (ShmGroupCollection[target].GunLoading / 100), (ShmGroupCollection[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(ShmGroupCollection[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(ShmGroupCollection[gun - 1].Role == _GROLE_SLAVE)
- {
- printf("\r\nSet Group [%02X] Stop", gun - 1);
- ShmGroupCollection[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(ShmGroupCollection[gun - 1].Role == _GROLE_SLAVE)
- {
- printf("\r\nSet Group [%02X] Stop", gun - 1);
- ShmGroupCollection[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 && ShmGroupCollection[gun - 1].Role == _GROLE_MASTER)
- {
- printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
- ShmGroupCollection[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)
- {
- for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
- {
- printf("\r\nGun %d Status = %d, Available = %d", i + 1, _chargingData[i]->SystemStatus, _chargingData[i]->IsAvailable);
- printf("\r\nAlarmCode");
- printf("\r\n Connector = %6s, EvConn = %6s, Remote = %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");
- }
- printf("\r\n");
- 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");
- }
- int main(void)
- {
- 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;
- }
- }
- /*
- memset(&ShmGroupCollection[0], 0x00, sizeof(PsuGroupCollectionData));
- memset(&ShmGroupCollection[1], 0x00, sizeof(PsuGroupCollectionData));
- memset(&ShmGroupCollection[2], 0x00, sizeof(PsuGroupCollectionData));
- memset(&ShmGroupCollection[3], 0x00, sizeof(PsuGroupCollectionData));
- ShmGroupCollection[0].Index = 0;
- ShmGroupCollection[1].Index = 1;
- ShmGroupCollection[2].Index = 2;
- ShmGroupCollection[3].Index = 3;
- ShmGroupCollection[0].Location = 0;
- ShmGroupCollection[1].Location = 3;
- ShmGroupCollection[2].Location = 1;
- ShmGroupCollection[3].Location = 2;
- */
- for(;;)
- {
- char word[128];
- char newString[7][32];
- int i,j,ctr;
- fgets(word, sizeof(word), stdin);
- 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], "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], "select") == 0)
- {
- // 取得 / 設定 當前選的槍號
- GetGunSelectedNum(newString[1]);
- }
- else if(strcmp(newString[0], "change") == 0)
- {
- // 模擬按鈕改變選槍
- ChangeGunNum();
- }
- 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(newString[0], "temp") == 0)
- {
- // 取得溫度
- GetTemperature(newString[1]);
- }
- else if(strcmp(newString[0], "acin") == 0)
- {
- // 取得三向輸入電壓
- GetAcInputVol();
- }
- 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
- printf ("%s\n", msg);
- usleep(100000);
- }
- return 0;
- }
|