123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944 |
- /*
- * 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"
- typedef unsigned char byte;
- #define PASS 1
- #define FAIL -1
- #define EQUAL 0
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define NO_DEFINE 255
- #define DEFAULT_AC_INDEX 2
- #define YES 1
- #define NO 0
- #define AUTORUN_STEP1_TIME_START 140 // Minutes
- #define AUTORUN_STEP1_TIME_END 150
- #define AUTORUN_STEP2_TIME_START 210
- #define AUTORUN_STEP2_TIME_END 410
- #define AUTORUN_END_TIME 480
- #define AUTORUN_CYCLE_COUNT 30
- #define TTY_PATH "/dev/tty"
- #define STTY_US "stty raw -echo -F "
- #define STTY_DEF "stty -raw echo -F "
- byte _curAutoRunCount = 0;
- byte _usingAutoRun = 0;
- struct timeval _autoTime;
- struct timeb startChargingTime;
- struct timeb endChargingTime;
- int _presentChargingTimeBuf;
- int chargingTime;
- //struct timeval _printf_time;
- 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;
- struct DcCommonInformation *ShmDcCommonData;
- struct OCPP16Data *ShmOCPP16Data;
- struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_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";
- 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;
- }
- }
- 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;
- }
- //initial ShmStatusCodeData
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- 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;
- }
- }
- 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(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmOCPP16Data = 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(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
- {
- result = FAIL;
- }
- else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- result = FAIL;
- }
- return result;
- }
- unsigned long GetTimeoutValue(struct timeval _sour_time)
- {
- struct timeval _end_time;
- gettimeofday(&_end_time, NULL);
- return (_end_time.tv_sec - _sour_time.tv_sec);
- }
- void PrintConnectorState(byte state)
- {
- switch(state)
- {
- case SYS_MODE_BOOTING: printf("Status = Booting.... \n"); break;
- case SYS_MODE_IDLE: printf("Status = Idle \n"); break;
- case SYS_MODE_AUTHORIZING: printf("Status = Authorized \n"); break;
- case SYS_MODE_MODE_REASSIGN_CHECK: printf("Status = check to change to balance mode \n"); break;
- case SYS_MODE_REASSIGN: printf("Status = Waiting to change the balance mode \n"); break;
- case SYS_MODE_PREPARING: printf("Status = Preparing \n"); break;
- case SYS_MODE_PREPARE_FOR_EV: printf("Status = Waiting for EV side (slac...) \n"); break;
- case SYS_MODE_PREPARE_FOR_EVSE : printf ( "Status = Waiting for GFD \n" ); break;
- case SYS_MODE_CHARGING : printf ( "Status = Charging \n" ); break;
- case SYS_MODE_TERMINATING : printf ( "Status = Terminating \n" ); break;
- case SYS_MODE_COMPLETE : printf ( "Status = Complete \n" ); break;
- case SYS_MODE_ALARM : printf ( "Status = Alarm \n" ); break;
- case SYS_MODE_FAULT : printf ( "Status = Fault \n" ); break;
- case SYS_MODE_RESERVATION : printf ( "Status = Reserved \n" ); break;
- case SYS_MODE_MAINTAIN : printf ( "Status = Maintain \n" ); break;
- case SYS_MODE_CCS_PRECHARGE_STEP0 : printf ( "Status = Precahrge Start \n" ); break;
- case SYS_MODE_CCS_PRECHARGE_STEP1 : printf ( "Status = Precharge End \n" ); break;
- case SYS_MODE_UPDATE : printf ( "Status = Updating .... \n" ); break;
- }
- }
- void PrintChargingMode(byte mode)
- {
- switch(mode)
- {
- case _MAIN_CHARGING_MODE_MAX: printf("Charging mode = Max \n"); break;
- case _MAIN_CHARGING_MODE_AVER: printf("Charging mode = Balance \n"); break;
- }
- }
- void PrintLcmPageName(byte page)
- {
- switch(page)
- {
- case _LCM_INIT: printf ( "LCM Page = Init \n" ); break;
- case _LCM_IDLE: printf ( "LCM Page = Idle \n" ); break;
- case _LCM_WAIT_FOR_PLUG: printf ( "LCM Page = Waiting for plug \n" ); break;
- case _LCM_PRE_CHARGE: printf ( "LCM Page = Precharge \n" ); break;
- case _LCM_CHARGING: printf ( "LCM Page = Charging \n" ); break;
- case _LCM_COMPLETE: printf ( "LCM Page = Complete \n" ); break;
- case _LCM_FIX: printf ( "LCM Page = Fix \n" ); break;
- case _LCM_EMC: printf ( "LCM Page = EMC \n" ); break;
- }
- }
- void PrintAcCpStatus(byte cp)
- {
- switch(cp)
- {
- case AC_SYS_A: printf ( "AC CpStatus = State A \n" ); break;
- case AC_SYS_B: printf ( "AC CpStatus = State B \n" ); break;
- case AC_SYS_C: printf ( "AC CpStatus = State C \n" ); break;
- case AC_SYS_F: printf ( "AC CpStatus = State F \n" ); break;
- }
- }
- void RunStatusProc(char *v1, char *v2)
- {
- if (strcmp(v1, "ac") == 0)
- {
- if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
- {
- printf("FindChargingInfoData (AC) false \n");
- }
- PrintConnectorState(ac_chargingInfo[0]->SystemStatus);
- PrintAcCpStatus(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
- PrintConnectorState(_chargingData[_index]->SystemStatus);
- PrintChargingMode(ShmSysConfigAndInfo->SysInfo.MainChargingMode);
- PrintLcmPageName(ShmSysConfigAndInfo->SysInfo.PageIndex);
- printf ("SystemTimeoutFlag = %d\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag );
- printf ("SOC = %d \n", _chargingData[_index]->EvBatterySoc);
- printf ("Maximum battery Voltage = %f \n", _chargingData[_index]->EvBatteryMaxVoltage);
- printf("maxTemp = %d, temp-I = %d, temp-II = %d \n",
- _chargingData[_index]->ConnectorTemp - 60,
- ShmDcCommonData->ConnectorTemp1[_index] - 60,
- ShmDcCommonData->ConnectorTemp2[_index] - 60);
- printf ("index = %x, Available = %d \n", _index, _chargingData[_index]->IsAvailable);
- }
- 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);
- }
- }
- printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
- printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
- }
- 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 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)
- {
- int _index = atoi(v1);
- if (_index == 0)
- printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
- else if (_index == 1)
- printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
- }
- else if (strcmp(v1, "rb") == 0)
- {
- printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
- }
- 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);
- }
- else if (strcmp(v1, "ac") == 0)
- {
- if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
- {
- printf("FindChargingInfoData (AC) false \n");
- }
- printf("AC Version = %s \n", ac_chargingInfo[0]->version);
- }
- else if (strcmp(v1, "all") == 0)
- {
- printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
- printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
- printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
- printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
- printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
- printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
- printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
- if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
- {
- printf("FindChargingInfoData (AC) false \n");
- }
- printf("AC Version = %s \n", ac_chargingInfo[0]->version);
- printf("LcmHwRev = %s \n", ShmSysConfigAndInfo->SysInfo.LcmHwRev);
- }
- }
- void CreateOneError()
- {
- for (byte i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
- {
- printf("(%d). %s \n", i, &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
- }
- }
- 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 GetRelayStatus(char *v1)
- {
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf("FindChargingInfoData error\n");
- return;
- }
- printf("RelayK1K2Status = %d \n", _chargingData[_index]->RelayK1K2Status);
- printf("RelayKPK2Status = %d \n", _chargingData[_index]->RelayKPK2Status);
- }
- void GetSOC(char *v1)
- {
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf("FindChargingInfoData error\n");
- return;
- }
- printf("Soc = %d \n", _chargingData[_index]->EvBatterySoc);
- }
- void FwUpdateFlagProc()
- {
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
- }
- void CheckAcStatus(char *v1)
- {
- if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
- {
- printf("AC 1Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
- printf("AC 2Status = %d \n", ShmPrimaryMcuData->InputDet.bits.AcContactorDetec);
- printf("AC 3Status = %d \n", ShmDcCommonData->psuKeepCommunication);
- printf("AC EmergencyButton = %d \n", ShmPrimaryMcuData->InputDet.bits.EmergencyButton);
- printf("AC acContactSwitch = %d \n", ShmDcCommonData->acContactSwitch);
- }
- else
- ShmSysConfigAndInfo->SysInfo.AcContactorStatus = atoi(v1);
- }
- 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 SetChargingInfoCCID(char *v1, char* v2)
- {
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- memcpy(_chargingData[_index]->EVCCID, v2, strlen(v2));
- _chargingData[_index]->EVCCID[strlen(v2)] = '\0';
- }
- void GetGunTemp(char *v1)
- {
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- printf("Gun_%d, maxTemp = %d, temp 1 = %d, temp 2 = %d \n",
- _index,
- _chargingData[_index]->ConnectorTemp - 60,
- ShmDcCommonData->ConnectorTemp1[_index] - 60,
- ShmDcCommonData->ConnectorTemp2[_index] - 60);
- }
- void GetOffered(char *v1)
- {
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- printf("Gun_%d, PowerOffered = %f, CurrentOffered = %f \n",
- _index,
- _chargingData[_index]->PowerOffered,
- _chargingData[_index]->CurrentOffered);
- }
- void GetEvStatus(char *v1)
- {
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- if (_chargingData[_index]->Type == _Type_Chademo)
- printf ("Chademo status= %d \n", ShmCHAdeMOData->evse[_chargingData[_index]->type_index].EvboardStatus);
- else if (_chargingData[_index]->Type == _Type_CCS)
- printf ("CCS status= %d \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].PresentMsgFlowStatus);
- else if (_chargingData[_index]->Type == _Type_GB)
- printf ("GBT status = %d \n", ShmGBTData->evse[_chargingData[_index]->type_index].EvboardStatus);
- }
- void GetDcMeterInfor(char *v1)
- {
- int _index = atoi(v1);
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- printf("Index = %d, LinkStatus = %d presetVoltage = %f, presentCurrent = %f, presentPower = %f, totlizeImportEnergy = %f, totlizeExportEnergy = %f \n",
- _index,
- ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].LinkStatus,
- ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presetVoltage,
- ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presentCurrent,
- ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presentPower,
- ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy,
- ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeExportEnergy);
- }
- void GetPowerValue()
- {
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (!FindChargingInfoData(index, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- printf ("index = %d, PresentChargingPower = %f \n", index, _chargingData[index]->PresentChargingPower);
- }
- }
- void GetSystemInfo()
- {
- printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
- printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
- printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
- printf ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d \n",
- ShmPsuData->SystemAvailablePower / 10,
- ShmPsuData->SystemAvailableCurrent / 10
- );
- printf ("Config : ChargingPower = %d, ChargingCurrent = %d \n",
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
- }
- 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 ShowSysInformation()
- {
- if (!ShmSysConfigAndInfo->SysConfig.ShowInformation)
- ShmSysConfigAndInfo->SysConfig.ShowInformation = 0x01;
- else
- ShmSysConfigAndInfo->SysConfig.ShowInformation = 0x00;
- printf("Show inform = %d \n", ShmSysConfigAndInfo->SysConfig.ShowInformation);
- }
- void GetFanSpeed()
- {
- 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;
- }
- void GetPsuTemp()
- {
- char _ex_maxTemp = 0;
- char _cr_maxTemp = 0;
- for (byte index = 0; index < ShmPsuData->GroupCount; index++)
- {
- _ex_maxTemp = 0;
- _cr_maxTemp = 0;
- for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
- {
- if (ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp > _ex_maxTemp)
- _ex_maxTemp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
- if (ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1 > _cr_maxTemp)
- _cr_maxTemp = ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1;
- }
- printf("D.D. Temp = %d ------ Env Temp = %d \n", _ex_maxTemp, _cr_maxTemp);
- }
- }
- 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);
- }
- for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (!FindChargingInfoData(i, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- continue;
- }
- printf("From RB : Group Index = %d, OutputV = %f \n",
- i, _chargingData[i]->FireChargingVoltage);
- }
- }
- 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;
- }
- }
- else if (strcmp(v1, "force") == 0)
- {
- ShmPsuData->Work_Step = _ALATON_MODE;
- byte id = atof(v2);
- ShmDcCommonData->for_alston_test_1 = id;
- }
- 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 AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
- {
- float _Voltage[2];
- float _Current[2];
- _Voltage[0] = atof(g1_vol);
- _Current[0] = atof(g1_cur);
- _Voltage[1] = atof(g2_vol);
- _Current[1] = atof(g2_cur);
- printf ("g1_vol = %f, g1_cur = %f pow1 = %f (KW) \n", _Voltage[0], _Current[0], (_Voltage[0] * _Current[0]) / 1000);
- printf ("g2_vol = %f, g2_cur = %f pow2 = %f (KW) \n", _Voltage[1], _Current[1], (_Voltage[1] * _Current[1]) / 1000);
- if(_Voltage[0] > 1000 || _Voltage[0] < 50 ||
- _Voltage[1] > 1000 || _Voltage[1] < 50)
- {
- printf ("Input Voltage over range\n");
- return;
- }
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (!FindChargingInfoData(_index, &_chargingData[0]))
- {
- printf("AverageCharging : FindChargingInfoData false \n");
- return;
- }
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[_index]->Type = 9;
- }
- sleep(1);
- system("killall Module_EvComm");
- unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
- bool isComplete[2] = {false, false};
- while(1)
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- switch(_chargingData[gun_index]->SystemStatus)
- {
- case SYS_MODE_IDLE:
- {
- if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
- {
- PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
- printf ("[AverageCharging (%d) - SYS_MODE_IDLE] \n", gun_index);
- }
- ShmDcCommonData->StartToChargingFlag[gun_index] = 0x01;
- _chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARING;
- }
- break;
- case SYS_MODE_PREPARING:
- {
- if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
- {
- PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
- printf ("[AverageCharging (%d) - S_PREPARNIN] \n", gun_index);
- //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
- printf ("wait find module\n");
- }
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
- //清除 main timeout 機制
- _chargingData[gun_index]->TimeoutFlag = 0;
- }
- break;
- case SYS_MODE_PREPARE_FOR_EV:
- {
- if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
- {
- PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
- printf ("[AverageCharging (%d) - SYS_MODE_PREPARE_FOR_EV] \n", gun_index);
- printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[gun_index] * 10, _Current[gun_index] * 10);
- }
- //清除 main timeout 機制
- _chargingData[gun_index]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[gun_index]->Type = 9;
- //充電電壓電流
- _chargingData[gun_index]->EvBatterySoc = 50;
- _chargingData[gun_index]->EvBatterytargetVoltage = 500;
- _chargingData[gun_index]->EvBatterytargetCurrent = 2;
- _chargingData[gun_index]->AvailableChargingCurrent = 1000;
- //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
- //確定模組己升壓完成
- //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
- // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
- {
- printf ("Preparing Done = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
- //EV done
- _chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
- }
- }
- break;
- case SYS_MODE_PREPARE_FOR_EVSE:
- {
- if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
- {
- PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
- printf ("[AverageCharging (%d) - SYS_MODE_PREPARE_FOR_EVSE]\n", gun_index);
- }
- //printf ("tar vol = %d \n", _Voltage);
- //printf ("tar cur = %d \n", _Current);
- //清除 main timeout 機制
- _chargingData[gun_index]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[gun_index]->Type = 9;
- //充電電壓電流
- _chargingData[gun_index]->EvBatterySoc = 50;
- _chargingData[gun_index]->EvBatterytargetVoltage = 500;
- _chargingData[gun_index]->EvBatterytargetCurrent = 2;
- _chargingData[gun_index]->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[gun_index]->GroundFaultStatus == 0x01 ||
- _chargingData[gun_index]->GroundFaultStatus == 0x03)
- {
- printf ("First Ground Fault State (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
- printf ("Wait K1K2 = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
- sleep(5);
- //EV done
- _chargingData[gun_index]->SystemStatus = SYS_MODE_CHARGING;
- }
- else if (_chargingData[gun_index]->GroundFaultStatus > 0x02)
- {
- printf ("First Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
- _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
- }
- }
- break;
- case SYS_MODE_CHARGING:
- {
- if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
- {
- PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
- //充電電壓電流
- _chargingData[gun_index]->EvBatterytargetVoltage = _Voltage[gun_index];
- _chargingData[gun_index]->EvBatterytargetCurrent = _Current[gun_index];
- _chargingData[gun_index]->EvBatterySoc = 50;
- _chargingData[gun_index]->AvailableChargingCurrent = 1000;
- printf ("[AverageCharging (%d) - SYS_MODE_CHARGING]\n", gun_index);
- }
- //ev task do this
- _chargingData[gun_index]->PresentChargingPower =
- ((float)((_chargingData[gun_index]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
- if (_chargingData[gun_index]->GroundFaultStatus == 0x02)
- {
- printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
- _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
- }
- }
- break;
- case SYS_MODE_TERMINATING:
- {
- if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
- {
- PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
- printf ("[AverageCharging (%d) - SYS_MODE_TERMINATING] \n", gun_index);
- //無阻塞偵測 keybaord 結束
- system(STTY_DEF TTY_PATH);
- }
- sleep(3);
- _chargingData[gun_index]->SystemStatus = SYS_MODE_COMPLETE;
- }
- break;
- case SYS_MODE_COMPLETE:
- {
- if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
- {
- PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
- printf ("[AverageCharging (%d) - SYS_MODE_COMPLETE] \n", gun_index);
- }
- _chargingData[gun_index]->PresentChargingPower = 0;
- isComplete[gun_index] = true;
- sleep(3);
- }
- break;
- }
- }
- if (isComplete[0] == true && isComplete[1] == true)
- return;
- 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)
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- ShmDcCommonData->StartToChargingFlag[gun_index] = 0x00;
- _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
- }
- printf("stop \n\r");
- }
- usleep(100000);
- }
- }
- int DiffTimeb(struct timeb ST, struct timeb ET)
- {
- //return milli-second
- unsigned int StartTime,StopTime;
- StartTime=(unsigned int)ST.time;
- StopTime=(unsigned int)ET.time;
- //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
- return (StopTime-StartTime);
- }
- void CalcPresentChargedDuration(byte gun_index)
- {
- int _diffTime = 0;
- ftime(&endChargingTime);
- _diffTime = DiffTimeb(startChargingTime, endChargingTime);
- // below 0 or over 5 sec is abnormal
- if (_diffTime < 0 ||
- _diffTime > _chargingData[gun_index]->PresentChargedDuration + 5)
- {
- _presentChargingTimeBuf = _chargingData[gun_index]->PresentChargedDuration;
- ftime(&startChargingTime);
- }
- else
- _chargingData[gun_index]->PresentChargedDuration = _presentChargingTimeBuf + _diffTime;
- }
- void CalcPresentChargingPower(byte _index)
- {
- if (chargingTime == 0 ||
- chargingTime > _chargingData [_index]->PresentChargedDuration)
- {
- chargingTime = _chargingData [_index]->PresentChargedDuration;
- }
- else
- {
- int passTime = _chargingData [_index]->PresentChargedDuration - chargingTime;
- if (passTime > 0)
- {
- float changingPow = (_chargingData [_index]->PresentChargingPower) * passTime / 3600;
- _chargingData [_index]->PresentChargedEnergy += changingPow;
- chargingTime = _chargingData [_index]->PresentChargedDuration;
- }
- }
- }
- void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
- {
- int _GunIndex;
- float _Voltage;
- float _Current;
- if (strcmp(v1, "auto") == EQUAL)
- {
- _usingAutoRun = 0x01;
- _GunIndex = atoi(v2);
- _Voltage = 500;
- _Current = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 1000) / _Voltage;
- }
- else
- {
- _usingAutoRun = 0x00;
- _GunIndex = atoi(v1);
- _Voltage = atof(v2);
- _Current = atof(v3);
- }
- unsigned char PreviousSystemStatus = 0xff;
- if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- return;
- }
- printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _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;
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
- sleep(1);
- //kill ev task
- system("killall Module_EvComm");
- //_Voltage = (_Voltage * 10);
- //_Current = (_Current * 10);
- //system(STTY_US TTY_PATH);
- while(true)
- {
- //fix gun 1
- switch(_chargingData[_GunIndex]->SystemStatus)
- {
- case SYS_MODE_IDLE:
- {
- if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
- printf ("[UnconditionalCharge - SYS_MODE_IDLE]\n");
- }
- chargingTime = 0;
- ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x01;
- _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARING;
- }
- break;
- case SYS_MODE_PREPARING:
- {
- if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[_GunIndex]->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[_GunIndex]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[_GunIndex]->Type = 9;
- }
- break;
- case SYS_MODE_PREPARE_FOR_EV:
- {
- if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
- printf ("[UnconditionalCharge - SYS_MODE_PREPARE_FOR_EV]\n");
- printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
- }
- //清除 main timeout 機制
- _chargingData[_GunIndex]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[_GunIndex]->Type = 9;
- //充電電壓電流
- _chargingData[_GunIndex]->EvBatterySoc = 50;
- _chargingData[_GunIndex]->EvBatterytargetVoltage = 500;
- _chargingData[_GunIndex]->EvBatterytargetCurrent = 2;
- _chargingData[_GunIndex]->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[_GunIndex]->PresentChargingVoltage);
- //EV done
- _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
- }
- }
- break;
- case SYS_MODE_PREPARE_FOR_EVSE:
- {
- if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
- printf ("[UnconditionalCharge - SYS_MODE_PREPARE_FOR_EVSE]\n");
- }
- //printf ("tar vol = %d \n", _Voltage);
- //printf ("tar cur = %d \n", _Current);
- //清除 main timeout 機制
- _chargingData[_GunIndex]->TimeoutFlag = 0;
- //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
- _chargingData[_GunIndex]->Type = 9;
- //充電電壓電流
- _chargingData[_GunIndex]->EvBatterySoc = 50;
- _chargingData[_GunIndex]->EvBatterytargetVoltage = 500;
- _chargingData[_GunIndex]->EvBatterytargetCurrent = 2;
- _chargingData[_GunIndex]->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 )
- //確定模組己升壓完成
- //#define GFD_WAIT 0
- //#define GFD_PASS 1
- //#define GFD_FAIL 2
- //#define GFD_WARNING 3
- if(_chargingData[_GunIndex]->GroundFaultStatus == 0x01 ||
- _chargingData[_GunIndex]->GroundFaultStatus == 0x03)
- {
- printf ("First Ground Fault State (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
- printf ("Wait K1K2 = %f \n", _chargingData[_GunIndex]->PresentChargingVoltage);
- sleep(5);
- //EV done
- _chargingData[_GunIndex]->SystemStatus = SYS_MODE_CHARGING;
- }
- else if (_chargingData[_GunIndex]->GroundFaultStatus > 0x02)
- {
- printf ("First Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
- _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
- }
- }
- break;
- case SYS_MODE_CHARGING:
- {
- if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
- if (_usingAutoRun == 0x00)
- {
- //充電電壓電流
- _chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
- _chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
- }
- else
- {
- _curAutoRunCount = 0;
- gettimeofday(&_autoTime, NULL);
- }
- _chargingData[_GunIndex]->EvBatterySoc = 50;
- _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
- ftime(&startChargingTime);
- //gettimeofday(&_printf_time, NULL);
- printf ("[UnconditionalCharge - SYS_MODE_CHARGING]\n");
- }
- CalcPresentChargedDuration(_GunIndex);
- if (_usingAutoRun == 0x01)
- {
- if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
- ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60))
- {
- _chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
- _chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
- }
- else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60)
- {
- _curAutoRunCount++;
- if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT)
- _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
- else
- gettimeofday(&_autoTime, NULL);
- }
- else
- {
- _chargingData[_GunIndex]->EvBatterytargetVoltage = 0;
- _chargingData[_GunIndex]->EvBatterytargetCurrent = 0;
- }
- }
- // printf("out : vol = %f, cur = %f \n",
- // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
- // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
- //ev task do this
- _chargingData[_GunIndex]->PresentChargingPower =
- ((float)((_chargingData[_GunIndex]->PresentChargingVoltage) * (_chargingData[_GunIndex]->PresentChargingCurrent)) / 1000);
- CalcPresentChargingPower(_GunIndex);
- if (_chargingData[_GunIndex]->GroundFaultStatus == 0x02){
- printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
- _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
- }
- // if (GetTimeoutValue(_printf_time) >= 3)
- // {
- // printf("PresentChargedEnergy = %.3f \n", _chargingData [_GunIndex]->PresentChargedEnergy);
- // gettimeofday(&_printf_time, NULL);
- // }
- }
- break;
- case SYS_MODE_TERMINATING:
- {
- if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
- system("/root/Module_EvComm &");
- printf ("[UnconditionalCharge - SYS_MODE_TERMINATING]\n");
- //無阻塞偵測 keybaord 結束
- system(STTY_DEF TTY_PATH);
- }
- sleep(3);
- _chargingData[_GunIndex]->SystemStatus = SYS_MODE_COMPLETE;
- return;
- }
- break;
- case SYS_MODE_COMPLETE:
- {
- if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
- {
- PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
- printf ("[UnconditionalCharge - SYS_MODE_COMPLETE]\n");
- }
- _chargingData[_GunIndex]->PresentChargingPower = 0;
- 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[_GunIndex]->EvBatterytargetVoltage = _vol;
- _chargingData[_GunIndex]->EvBatterytargetCurrent = _cur;
- }
- else if (strcmp(newString[0], "c") == 0)
- {
- printf("stop \n\r");
- ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x00;
- _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
- }
- usleep(100000);
- }
- }
- int main(void)
- {
- if(InitShareMemory() == FAIL)
- {
- printf ("InitShareMemory = FAIL \n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
- }
- sleep(5);
- return 0;
- }
- for(;;)
- {
- char word[128];
- char newString[7][10];
- 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 || strcmp(newString[0], "st") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- continue;
- // 槍狀態
- printf("=========================== \n");
- RunStatusProc(newString[1], newString[2]);
- printf("=========================== \n");
- }
- 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]);
- }
- 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)
- {
- // get output power
- GetPowerValue();
- }
- 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], "show") == 0)
- {
- ShowSysInformation();
- }
- 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)
- {
- // 取得 PSU 溫度
- GetPsuTemp();
- }
- 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();
- }
- else if (strcmp(newString[0], "auth") == 0)
- {
- GetAuthorizeFlag(newString[1]);
- }
- else if (strcmp(newString[0], "relay") == 0)
- {
- GetRelayStatus(newString[1]);
- }
- else if (strcmp(newString[0], "ccid") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
- strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
- {
- printf ("Input ccid fail.\n");
- continue;
- }
- SetChargingInfoCCID(newString[1], newString[2]);
- }
- else if (strcmp(newString[0], "guntemp") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- printf ("Input guntemp fail.\n");
- continue;
- }
- GetGunTemp(newString[1]);
- }
- else if (strcmp(newString[0], "offer") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- printf ("offer fail.\n");
- continue;
- }
- GetOffered(newString[1]);
- }
- else if (strcmp(newString[0], "evstate") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- printf ("evstate fail.\n");
- continue;
- }
- GetEvStatus(newString[1]);
- }
- else if (strcmp(newString[0], "meter") == 0)
- {
- // DC meter infor
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- printf ("meter cmd fail.\n");
- continue;
- }
- GetDcMeterInfor(newString[1]);
- }
- else if (strcmp(newString[0], "soc") == 0)
- {
- GetSOC(newString[1]);
- }
- else if (strcmp(newString[0], "run") == 0)
- {
- if (ShmDcCommonData->_isAutoRunTest == YES)
- ShmDcCommonData->_isAutoRunTest = NO;
- else
- ShmDcCommonData->_isAutoRunTest = YES;
- printf ("_isAutoRunTest = %d \n", ShmDcCommonData->_isAutoRunTest);
- }
- else if (strcmp(newString[0], "test") == 0)
- {
- if (!FindChargingInfoData(1, &_chargingData[0]))
- {
- printf("FindChargingInfoData error\n");
- }
- // Test Command
- ShmPsuData->PsuGroup[0].GroupErrorFlag.bits.PsuFailure = YES;
- ShmPsuData->PsuStopChargeFlag = YES;
- ShmDcCommonData->_isPsuErrorOccur = YES;
- // ShmDcCommonData->Customer_SwipToChargingByTime += 10;
- // printf("Charging Time = %u \n", ShmDcCommonData->Customer_SwipToChargingByTime);
- }
- else if (strcmp(newString[0], "ocpp") == 0)
- {
- if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if (strlen ( (char *) ShmOCPP16Data->ConfigurationTable.CoreProfile [ConfigurationVersion].ItemData ) > 0)
- {
- printf ( "OCPP Version. = %s",
- ShmOCPP16Data->ConfigurationTable.CoreProfile [ConfigurationVersion].ItemData );
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- else if(strcmp(newString[0], "strchg") == 0)
- {
- //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
- if (strcmp(newString[1], "auto") == 0)
- {
- newString[3][0] = 0;
- }
- else 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], "avechg") == 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 ------ avechg\n");
- continue;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount < 2 ||
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == 1)
- {
- printf ("Sorry, This is single gun system. \n");
- continue;
- }
- AverageCharging(newString[1], newString[2], newString[3], newString[4]);
- }
- else
- printf ("%s\n", msg);
- usleep(100000);
- }
- return 0;
- }
|