1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455 |
- /*
- * 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 timespec _autoTime;
- byte ConnectorUsingSeq[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY][4] =
- {{0, 2, 3, 1}, {1, 3, 2, 0}};
- 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 SmartBoxData *ShmSmartBoxData;
- struct MeterInformation *ShmCsuMeterData;
- struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
- bool isLog = false;
- struct timespec _log_time;
- 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";
- #define DEBUG_INFO_MSG(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- int StoreLogMsg(const char *fmt, ...)
- {
- char Buf[4096+256];
- char buffer[4096];
- va_list args;
- struct timeb SeqEndTime;
- struct tm *tm;
- va_start(args, fmt);
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- memset(Buf,0,sizeof(Buf));
- ftime(&SeqEndTime);
- SeqEndTime.time = time(NULL);
- tm=localtime(&SeqEndTime.time);
- sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s_Log",
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
- buffer,
- tm->tm_year+1900,tm->tm_mon+1,
- ShmSysConfigAndInfo->SysConfig.SerialNumber);
- system(Buf);
- return rc;
- }
- void PRINTF_FUNC(char *string, ...)
- {
- va_list args;
- char buffer[4096];
- va_start(args, string);
- vsnprintf(buffer, sizeof(buffer), string, args);
- va_end(args);
- DEBUG_INFO_MSG("%s ", buffer);
- }
- int GetTimeoutValue(struct timespec *startTime)
- {
- struct timespec endTime;
- clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
- return endTime.tv_sec - startTime->tv_sec;
- }
- void GetTimespecFunc(struct timespec *time)
- {
- clock_gettime(CLOCK_MONOTONIC_COARSE, time);
- }
- 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 ( ShmSmartBoxKey, sizeof(struct SmartBoxData), IPC_CREAT | 0777 )) < 0)
- {
- return FAIL;
- }
- else if ((ShmSmartBoxData = shmat ( MeterSMId, NULL, 0 )) == (void *) - 1)
- {
- return 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;
- }
- if ((MeterSMId = shmget ( ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777 )) < 0)
- {
- result = FAIL;
- }
- else if ((ShmCsuMeterData = shmat ( MeterSMId, NULL, 0 )) == (void *) - 1)
- {
- result = FAIL;
- }
- return result;
- }
- 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_NORMAL: printf("Charging mode = Max \n"); break;
- case _MAIN_CHARGING_MODE_BOTH: 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);
- printf ("IdTag = %s, ParentId = %s \n",
- _chargingData[_index]->StartUserId,
- _chargingData[_index]->ParentIdTag);
- }
- 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]);
- memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "", 7);
- }
- }
- 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 LogGunTempandCurrent(char *v1, char* v2)
- {
- int _index = atoi(v1);
- int _waitTime = atoi(v2);
- if(!FindChargingInfoData(_index, &_chargingData [0]))
- {
- printf ( "FindChargingInfoData error\n" );
- return;
- }
- GetTimespecFunc(&_log_time);
- for(;;)
- {
- int time = GetTimeoutValue(&_log_time);
- if (time < 0 || time > _waitTime)
- {
- PRINTF_FUNC("Gun_%d, Temp = %d, outCur = %f \n",
- _index,
- _chargingData[_index]->ConnectorTemp - 60,
- _chargingData[_index]->PresentChargingCurrent);
- PRINTF_FUNC ( "OutputV = %f, OutputC = %f \n",
- _chargingData[_index]->FireChargingVoltage,
- _chargingData[_index]->PresentChargingCurrent);
- GetTimespecFunc(&_log_time);
- }
- }
- }
- 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);
- printf("Index = %d, publicKeyOcmf = %s, transactionOCMF = %s, ActionCmd = %d, OcmpInfoReady = %d \n",
- _index,
- ShmSysConfigAndInfo->SysInfo.DcMeterStatusInfo[_index].publicKeyOcmf,
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[_index].transactionOCMF,
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[_index].ActionCmd,
- ShmSysConfigAndInfo->SysInfo.DcMeterTransactionAction[_index].OcmfInfoReady);
- }
- void GetAcMeterInfor(char *v1)
- {
- int _index = atoi(v1);
- printf ("Index = %d, curMeterValue = %f newMeterValue = %f, isCalculation = %d, _chargingValue = %f, _curTotalCharging = %f \n",
- _index,
- ShmCsuMeterData->_meter[_index].curMeterValue,
- ShmCsuMeterData->_meter[_index].newMeterValue,
- ShmCsuMeterData->_meter[_index].isCalculation,
- ShmCsuMeterData->_meter[_index]._chargingValue,
- ShmCsuMeterData->_meter[_index]._curTotalCharging);
- }
- void GetLocalSharingInfor(char *v1)
- {
- int _index = atoi(v1);
- printf ("Index = %d, isConnectedSharingServer = %d, AvailableShargingCurrent = %d \n",
- _index,
- ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer,
- ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent[_index]);
- }
- 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, ChargingVoltage = %d \n",
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent,
- ShmSysConfigAndInfo->SysConfig.MaxChargingVoltage);
- }
- 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 GetSmartInformation(char *v1, char *v2, char *v3)
- {
- if(strcmp(v1, "fe") == 0)
- {
- int tag = atoi(v2);
- for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (!FindChargingInfoData(i, &_chargingData[0]))
- {
- printf ("FindChargingInfoData error\n");
- continue;
- }
- }
- float needPower = _chargingData[tag]->EvBatterytargetVoltage * _chargingData[tag]->EvBatterytargetCurrent / 100;
- printf("needPower = %.1f (kw), RealRatingPower = %d \n", needPower / 10, _chargingData[tag]->RealRatingPower / 10);
- printf("FetchLoopStep = %d \n", ShmSmartBoxData->Dynamic4Fetch[tag].FetchLoopStep);
- printf("ShareGroup = %d \n", ShmSmartBoxData->Dynamic4Fetch[tag].ShareGroup);
- }
- else if (strcmp(v1, "re") == 0)
- {
- int tag = atoi(v2);
- for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i ++)
- {
- if ( ! FindChargingInfoData ( i, & _chargingData [0] ))
- {
- printf ( "FindChargingInfoData error\n" );
- continue;
- }
- }
- printf("ReleaseGroup = %d \n", ShmSmartBoxData->Dynamic4Release[tag].ReleaseGroup);
- printf("ReleaseLoopStep = %d \n", ShmSmartBoxData->Dynamic4Release[tag].ReleaseLoopStep);
- printf("TargetRelay = %d \n", ShmSmartBoxData->Dynamic4Release[tag].TargetRelay);
- }
- else if (strcmp(v1, "relay") == 0)
- {
- printf("ParallelRelayStatus = [%d] [%d] [%d] \n",
- ShmSmartBoxData->ParallelRelayStatus[0],
- ShmSmartBoxData->ParallelRelayStatus[1],
- ShmSmartBoxData->ParallelRelayStatus[2]);
- printf("RcbParallelStatus = [%d] [%d] [%d] \n",
- ShmSmartBoxData->RcbParallelStatus[0],
- ShmSmartBoxData->RcbParallelStatus[1],
- ShmSmartBoxData->RcbParallelStatus[2]);
- }
- else if (strcmp(v1, "using") == 0)
- {
- for (byte gp = 0; gp < ShmPsuData->GroupCount; gp++)
- {
- if (ShmPsuData->PsuGroup[gp].UsingTarget == GUN_LEFT)
- printf ( "Group_%d IsUsing => Connector - 0 (Vol : %d (0.1V), Cur : %d (0.1A)) \n",
- gp,
- ShmPsuData->PsuGroup[gp].GroupPresentOutputVoltage,
- ShmPsuData->PsuGroup[gp].GroupPresentOutputCurrent);
- else if (ShmPsuData->PsuGroup[gp].UsingTarget == GUN_RIGHT)
- printf ( "Group_%d IsUsing => Connector - 1 (Vol : %d (0.1V), Cur : %d (0.1A)) \n",
- gp,
- ShmPsuData->PsuGroup[gp].GroupPresentOutputVoltage,
- ShmPsuData->PsuGroup[gp].GroupPresentOutputCurrent);
- else
- printf ( "Group_%d IsUsing = IDLE \n", gp);
- }
- for (byte conn = 0; conn < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; conn++)
- {
- if(ShmSmartBoxData->ConnectorStatus[conn].ConnectorStaus == _CONNECTOR_STATUS_NONE)
- printf ( "Gun_%d Status = IDLE \n", conn);
- else if (ShmSmartBoxData->ConnectorStatus[conn].ConnectorStaus == _CONNECTOR_STATUS_WAIT)
- printf ( "Gun_%d Status = WAIT \n", conn);
- else if(ShmSmartBoxData->ConnectorStatus[conn].ConnectorStaus == _CONNECTOR_STATUS_USING)
- printf ( "Gun_%d Status = USING \n", conn);
- }
- }
- else if (strcmp(v1, "info") == 0)
- {
- printf ( "****************************************************************** \n" );
- printf ( "SystemPresentPsuQuantity = %d \n", ShmPsuData->SystemPresentPsuQuantity );
- printf ( "SystemAvailableCurrent = %d (A) \n", ShmPsuData->SystemAvailableCurrent / 10 );
- printf ( "SystemAvailablePower = %d (kw) \n", ShmPsuData->SystemAvailablePower / 10 );
- printf ( "GroupCount = %d \n", ShmPsuData->GroupCount );
- if (ShmDcCommonData->systemType == _SYSTEM_TYPE_SMART)
- printf ("System Type = Smart \n");
- else if (ShmDcCommonData->systemType == _SYSTEM_TYPE_STANDARD)
- printf ("System Type = Standard \n");
- else if (ShmDcCommonData->systemType == _SYSTEM_TYPE_SIMPLE)
- printf ("System Type = WallMount / Moveable \n");
- for (byte conn = 0; conn < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; conn++)
- {
- byte totalUsingGpCount = 0;
- byte totalQuantity = 0;
- unsigned short _targetVol = 0 , _targetCur = 0;
- unsigned short _avaCur = 0 , _avaPow = 0;
- unsigned short _outputVol = 0 , _outputCur = 0;
- unsigned short _ratingPow = 0;
- for (byte gp = 0; gp < ShmSmartBoxData->ConnectorUsingGroupCount[conn]; gp++)
- {
- if (ShmPsuData->PsuGroup[ConnectorUsingSeq[conn][gp]].UsingTarget == GUN_LEFT)
- {
- totalUsingGpCount++;
- byte tarGp = ConnectorUsingSeq[conn][gp];
- totalQuantity += ShmPsuData->PsuGroup[tarGp].GroupPresentPsuQuantity;
- _targetVol = ShmPsuData->PsuGroup[tarGp].GroupTargetOutputVoltage / 10;
- _targetCur += ShmPsuData->PsuGroup[tarGp].GroupTargetOutputCurrent / 10;
- _avaCur += ShmPsuData->PsuGroup[tarGp].GroupAvailableCurrent / 10;
- _avaPow += ShmPsuData->PsuGroup[tarGp].GroupAvailablePower / 10;
- _outputVol = (double)ShmPsuData->PsuGroup[tarGp].GroupPresentOutputVoltage / 10;
- _outputCur += (double)ShmPsuData->PsuGroup[tarGp].GroupPresentOutputCurrent / 10;
- _ratingPow += ShmPsuData->PsuGroup[tarGp].TotalRatingPower;
- }
- }
- if (!FindChargingInfoData (GUN_LEFT, & _chargingData [0]))
- {
- printf ( "FindChargingInfoData error\n" );
- continue;
- }
- if (totalUsingGpCount > 0)
- {
- printf ( "----------------------------------------------------------------- \n" );
- printf ( "Group Index = %d, totalUsingGpCount = %d \n", conn, totalUsingGpCount);
- printf ( "totalQuantity = %d \n", totalQuantity);
- printf ( "_targetVol = %d (V), _targetCur = %d (A), _needPwr = %.1f (kw) \n", _targetVol, _targetCur,
- (_chargingData[GUN_LEFT]->PresentChargingVoltage * _chargingData[GUN_LEFT]->PresentChargingCurrent) / 1000 );
- printf ( "_avaCur = %d (A), _avaPow = %d (kw) \n", _avaCur, _avaPow);
- printf ( "_outputVol = %d (V), _outputCur = %d (A) \n", _outputVol, _outputCur);
- printf ( "_ratingPow = %d (KW) \n", _ratingPow);
- }
- }
- for (byte conn = 0; conn < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; conn ++)
- {
- byte totalUsingGpCount = 0;
- byte totalQuantity = 0;
- unsigned short _targetVol = 0 , _targetCur = 0;
- unsigned short _avaCur = 0 , _avaPow = 0;
- unsigned short _outputVol = 0 , _outputCur = 0;
- unsigned short _ratingPow = 0;
- for (byte gp = 0; gp < ShmSmartBoxData->ConnectorUsingGroupCount [conn]; gp ++)
- {
- if (ShmPsuData->PsuGroup [ConnectorUsingSeq [conn] [gp]].UsingTarget == GUN_RIGHT)
- {
- totalUsingGpCount ++;
- byte tarGp = ConnectorUsingSeq [conn] [gp];
- totalQuantity += ShmPsuData->PsuGroup [tarGp].GroupPresentPsuQuantity;
- _targetVol = ShmPsuData->PsuGroup [tarGp].GroupTargetOutputVoltage / 10;
- _targetCur += ShmPsuData->PsuGroup [tarGp].GroupTargetOutputCurrent / 10;
- _avaCur += ShmPsuData->PsuGroup [tarGp].GroupAvailableCurrent / 10;
- _avaPow += ShmPsuData->PsuGroup [tarGp].GroupAvailablePower / 10;
- _outputVol = (double) ShmPsuData->PsuGroup [tarGp].GroupPresentOutputVoltage / 10;
- _outputCur += (double) ShmPsuData->PsuGroup [tarGp].GroupPresentOutputCurrent / 10;
- _ratingPow += ShmPsuData->PsuGroup [tarGp].TotalRatingPower;
- }
- }
- if (!FindChargingInfoData (GUN_RIGHT, & _chargingData [0]))
- {
- printf ( "FindChargingInfoData error\n" );
- continue;
- }
- if (totalUsingGpCount > 0)
- {
- printf ( "----------------------------------------------------------------- \n" );
- printf ( "Group Index = %d, totalUsingGpCount = %d \n", conn, totalUsingGpCount );
- printf ( "totalQuantity = %d \n", totalQuantity );
- printf ( "_targetVol = %d (V), _targetCur = %d (A), _needPwr = %.1f (kw) \n", _targetVol, _targetCur,
- (_chargingData[GUN_RIGHT]->PresentChargingVoltage * _chargingData[GUN_RIGHT]->PresentChargingCurrent) / 1000 );
- printf ( "_avaCur = %d (A), _avaPow = %d (kw) \n", _avaCur, _avaPow );
- printf ( "_outputVol = %d (V), _outputCur = %d (A) \n", _outputVol, _outputCur );
- printf ( "_ratingPow = %d (KW) \n", _ratingPow );
- }
- }
- printf ( "****************************************************************** \n" );
- GetSmartInformation("using","","");
- GetSmartInformation("relay","","");
- }
- }
- 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(byte group = 0; group < ShmPsuData->GroupCount; group++)
- {
- for (byte psuCount = 0; psuCount < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; psuCount++)
- {
- printf("Group = %d, Psu Index = %d, FwVersion = %s \n",
- group, psuCount,
- ShmPsuData->PsuGroup[group].PsuModule[psuCount].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, "info") == 0)
- {
- int _tgGroup = atoi(v2);
- if (_tgGroup < ShmPsuData->GroupCount)
- {
- printf("**************************************************************************** \n");
- printf("Psu Group = %d \n", _tgGroup);
- printf("GroupTargetOutputVoltage = %d \n", ShmPsuData->PsuGroup[_tgGroup].GroupTargetOutputVoltage);
- printf("GroupTargetOutputCurrent = %d \n", ShmPsuData->PsuGroup[_tgGroup].GroupTargetOutputCurrent);
- printf("GroupAvailableCurrent = %d \n", ShmPsuData->PsuGroup[_tgGroup].GroupAvailableCurrent);
- printf("GroupAvailablePower = %d \n", ShmPsuData->PsuGroup[_tgGroup].GroupAvailablePower);
- printf("GroupPresentOutputVoltage = %d \n", ShmPsuData->PsuGroup[_tgGroup].GroupPresentOutputVoltage);
- printf("GroupPresentOutputCurrent = %d \n", ShmPsuData->PsuGroup[_tgGroup].GroupPresentOutputCurrent);
- printf("GroupPresentOutputPower = %d \n", ShmPsuData->PsuGroup[_tgGroup].GroupPresentOutputPower);
- printf("TotalIAvailableCurrent = %d \n", ShmPsuData->PsuGroup[_tgGroup].TotalIAvailableCurrent);
- 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 Voltage = %d, Max Power = %d \n",
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
- ShmSysConfigAndInfo->SysConfig.MaxChargingVoltage * 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 GetNeedCount(byte *needGroupCount, float P1, float P2)
- {
- byte G1_Need = P1 / 30 + (((int)P1 % 30 > 0) ? 1 : 0);
- byte G2_Need = P2 / 30 + (((int)P2 % 30 > 0) ? 1 : 0);
- // 總群數 >4
- if (G1_Need + G2_Need > 4)
- {
- if (G1_Need > 2)
- G1_Need = 2;
- G2_Need = 4 - G1_Need;
- }
- *needGroupCount = G1_Need;
- *(needGroupCount + 1) = G2_Need;
- }
- void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
- {
- float _Voltage[2];
- float _Current[2];
- byte needGroupCount[2] = {0, 0};
- _Voltage[0] = atof(g1_vol);
- _Current[0] = atof(g1_cur);
- _Voltage[1] = atof(g2_vol);
- _Current[1] = atof(g2_cur);
- printf ("g1_vol = %.1f, g1_cur = %.1f pow1 = %.1f (KW) \n", _Voltage[0], _Current[0], (_Voltage[0] * _Current[0]) / 1000);
- printf ("g2_vol = %.1f, g2_cur = %.1f pow2 = %.1f (KW) \n", _Voltage[1], _Current[1], (_Voltage[1] * _Current[1]) / 1000);
- GetNeedCount(needGroupCount, (_Voltage[0] * _Current[0]) / 1000, (_Voltage[1] * _Current[1]) / 1000);
- printf ("needGroupCount[0] = %d, needGroupCount[1] = %d \n", needGroupCount[0], needGroupCount[1]);
- 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");
- if (ShmDcCommonData->systemType == _SYSTEM_TYPE_STANDARD)
- {
- ShmSmartBoxData->ConnectorUsingGroupCount[gun_index] = 1;
- }
- else if (ShmDcCommonData->systemType == _SYSTEM_TYPE_SMART)
- {
- ShmSmartBoxData->ConnectorUsingGroupCount[gun_index] = needGroupCount[gun_index];
- }
- for (byte aGp = 0; aGp < ShmSmartBoxData->ConnectorUsingGroupCount [gun_index]; aGp ++)
- {
- if (ShmPsuData->PsuGroup [ConnectorUsingSeq [gun_index] [aGp]].GroupPresentPsuQuantity > 0)
- {
- ShmPsuData->PsuGroup [ConnectorUsingSeq [gun_index] [aGp]].IsUsing = YES;
- ShmPsuData->PsuGroup [ConnectorUsingSeq [gun_index] [aGp]].UsingTarget = gun_index;
- }
- }
- ShmSmartBoxData->ConnectorStatus [gun_index].ConnectorStaus = _CONNECTOR_STATUS_USING;
- }
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_BOTH;
- //清除 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 LogPsuTemp()
- {
- 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_FUNC ( "D.D. Temp = %d ------ Env Temp = %d \n", _ex_maxTemp, _cr_maxTemp );
- }
- }
- void LogPsuOutput(byte _GunIndex)
- {
- for (int i = 0; i < ShmPsuData->GroupCount; i ++)
- {
- PRINTF_FUNC ( "Group Index = %d, OutputV = %d, OutputC = %d \n",
- i, ShmPsuData->PsuGroup [i].GroupPresentOutputVoltage,
- ShmPsuData->PsuGroup [i].GroupPresentOutputCurrent );
- }
- if (!FindChargingInfoData(_GunIndex, & _chargingData [0]))
- {
- PRINTF_FUNC("LogPsuOutput FindChargingInfoData error\n");
- return;
- }
- PRINTF_FUNC ( "From RB : Group Index = %d, OutputV = %f \n",
- _GunIndex, _chargingData[_GunIndex]->FireChargingVoltage);
- }
- void LogFanSpeed()
- {
- PRINTF_FUNC("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
- PRINTF_FUNC("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
- PRINTF_FUNC("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
- PRINTF_FUNC("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
- }
- 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;
- }
- //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
- //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
- _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
- sleep(1);
- system("killall Module_EvComm");
- isLog = false;
- GetTimespecFunc(&_log_time);
- 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 : SystemType = %d \n", ShmDcCommonData->systemType);
- if (ShmDcCommonData->systemType == _SYSTEM_TYPE_SIMPLE)
- {
- if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES && _GunIndex == GUN_RIGHT)
- {
- // 直接用到第四個位置~ 第 0 群
- ShmSmartBoxData->ConnectorUsingGroupCount[_GunIndex] = 4;
- }
- else
- ShmSmartBoxData->ConnectorUsingGroupCount[_GunIndex] = 1;
- }
- else if (ShmDcCommonData->systemType == _SYSTEM_TYPE_STANDARD)
- {
- ShmSmartBoxData->ConnectorUsingGroupCount[_GunIndex] = 4;
- }
- else if (ShmDcCommonData->systemType == _SYSTEM_TYPE_SMART)
- {
- ShmSmartBoxData->ConnectorUsingGroupCount[_GunIndex] = 4;
- }
- for (byte aGp = 0; aGp < ShmSmartBoxData->ConnectorUsingGroupCount[_GunIndex]; aGp++)
- {
- if (ShmPsuData->PsuGroup[ConnectorUsingSeq[_GunIndex][aGp]].GroupPresentPsuQuantity > 0)
- {
- ShmPsuData->PsuGroup [ConnectorUsingSeq [_GunIndex] [aGp]].IsUsing = YES;
- ShmPsuData->PsuGroup[ConnectorUsingSeq[_GunIndex][aGp]].UsingTarget = _GunIndex;
- }
- }
- ShmSmartBoxData->ConnectorStatus[_GunIndex].ConnectorStaus = _CONNECTOR_STATUS_USING;
- }
- //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;
- GetTimespecFunc(&_autoTime);
- }
- _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
- GetTimespecFunc(&_autoTime);
- }
- 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;
- }
- int time = GetTimeoutValue(&_log_time);
- if (time < 0 || time > 120)
- {
- if (isLog)
- {
- LogPsuTemp();
- LogPsuOutput(_GunIndex);
- LogFanSpeed();
- }
- GetTimespecFunc(&_log_time);
- }
- 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], "log") == 0)
- {
- isLog = !isLog;
- }
- 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], "smart") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
- {
- printf ("SMART : Param fail..Please retry again......\n");
- continue;
- }
- // 取得 Smart 資訊
- GetSmartInformation(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], "acmeter") == 0)
- {
- // AC meter infor
- if (strcmp ( newString [1], "-1" ) == 0 || strcmp ( newString [1], "" ) == 0)
- {
- printf ( "meter cmd fail.\n" );
- continue;
- }
- GetAcMeterInfor ( newString [1] );
- }
- else if (strcmp(newString[0], "share") == 0)
- {
- // local sharing
- if (strcmp ( newString [1], "-1" ) == 0 || strcmp ( newString [1], "" ) == 0)
- {
- printf ( "local sharing cmd fail.\n" );
- continue;
- }
- GetLocalSharingInfor(newString[1]);
- }
- else if (strcmp(newString[0], "soc") == 0)
- {
- GetSOC(newString[1]);
- }
- else if (strcmp(newString[0], "log") == 0)
- {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
- strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
- {
- printf ("log fail.\n");
- continue;
- }
- LogGunTempandCurrent(newString[1], newString[2]);
- }
- 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], "fetch") == 0)
- {
- byte id = atof(newString[1]);
- ShmDcCommonData->smartFetchRun[id] = YES;
- printf("Fetch [%d] = %d ON \n", id, ShmDcCommonData->smartFetchRun[id]);
- }
- else if (strcmp(newString[0], "release") == 0)
- {
- byte id = atof(newString[1]);
- ShmDcCommonData->smartReleaseRun[id] = YES;
- printf("Release = %d ON \n", ShmDcCommonData->smartReleaseRun[id]);
- }
- else if (strcmp(newString[0], "test") == 0)
- {
- int SOCvalue = atoi(newString[2]);
- if (!FindChargingInfoData(atoi(newString[1]), &_chargingData[0]))
- {
- printf("FindChargingInfoData error\n");
- }
- _chargingData[atoi(newString[1])]->EvBatterySoc = SOCvalue;
- }
- 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;
- }
|