12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856 |
- #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 <stdint.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 "./ShareMemory/shmMem.h"
- #include "./Define/define.h"
- #include "./SelectGun/SelectGun.h"
- #include "Config.h"
- #include "./ModuleEvComm/Module_EvComm.h"
- #include "./CSU/main.h"
- #define CMD_KEY_WAIT (1)
- #define CMD_KEY_DONT_WAIT (0)
- #define DEFAULT_AC_INDEX (2)
- #define AUTORUN_STEP1_TIME_START (140)
- #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 "
- uint8_t _curAutoRunCount = 0;
- uint8_t _usingAutoRun = 0;
- struct timeval _autoTime;
- static struct SysConfigData *pSysConfig = NULL;
- static struct SysInfoData *pSysInfo = NULL;
- static struct WARNING_CODE_INFO *pSysWarning = NULL;
- static struct AlarmCodeData *pAlarmCode = NULL;
- static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
- static struct CHAdeMOData *ShmCHAdeMOData = NULL;
- static struct CcsData *ShmCcsData = NULL;
- static struct GBTData *ShmGBTData = NULL;
- static struct FanModuleData *ShmFanModuleData = NULL;
- static struct RelayModuleData *ShmRelayModuleData = NULL;
- static struct LedModuleData *ShmLedModuleData = NULL;
- static struct PsuData *ShmPsuData = NULL;
- static struct OCPP16Data *ShmOCPP16Data = NULL;
- static SelectGunInfo *ShmSelectGunInfo = NULL;
- static DcCommonInfo *ShmDcCommonData = NULL;
- static struct ChargingInfoData *pDcChargingInfo = NULL;
- static struct ChargingInfoData *pAcChargingInfo = NULL;
- static char newString[8][16] = {0};
- static int DiffTimeb(struct timeb ST, struct timeb ET)
- {
-
- unsigned int StartTime, StopTime;
- StartTime = (unsigned int)ST.time;
- StopTime = (unsigned int)ET.time;
- return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
- }
- 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;
-
- if (select(1, &rfds, NULL, NULL, &tv) > 0) {
- fgets(word, 128, stdin);
- }
- }
- static uint8_t helpCmd(void)
- {
- if (strcmp(newString[0], "?") == 0 ||
- strcmp(newString[0], "help") == 0 ||
- strcmp(newString[0], "h") == 0) {
- return YES;
- }
- return NO;
- }
- static uint8_t exitCmd(void)
- {
- if (strcmp(newString[0], "c") == EQUAL ||
- strcmp(newString[0], "C") == EQUAL ||
- strncmp(&newString[0][0], "exit", 4) == EQUAL
- ) {
- return YES;
- }
- return NO;
- }
- static uint8_t readCmdKey(uint8_t state)
- {
- char word[128] = {0};
- int i = 0, j = 0, ctr = 0;
- memset(word, 0, sizeof(word));
- if (state == CMD_KEY_WAIT) {
- fgets(word, sizeof(word), stdin);
- } else if (state == CMD_KEY_DONT_WAIT) {
- get_char(word);
- if (strlen(word) == 0) {
-
- return NO;
- }
- }
- memset(newString, 0, sizeof(newString));
- strcpy(newString[1], "-1");
- strcpy(newString[2], "-1");
- for (i = 0; i <= (strlen(word)); i++) {
- if (word[i] == ' ' ||
- word[i] == '\0' ||
- word[i] == '\r' ||
- word[i] == '\n' ||
- word[i] == 10) {
- newString[ctr][j] = '\0';
- ctr++;
- j = 0;
- } else {
- newString[ctr][j] = word[i];
- j++;
- }
- }
- return YES;
- }
- 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 RunStatusProc(char *v1, char *v2)
- {
- printf("OrderCharging = %d \n", pSysInfo->OrderCharging);
- printf("WaitForPlugit = %d \n", pSysInfo->WaitForPlugit);
- if (strcmp(v1, "ac") == 0) {
- pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-
-
-
- printf("AC Status = %d \n", pAcChargingInfo->ConnectorPlugIn);
- return;
- }
- int _index = atoi(v1);
- if (_index <= 1) {
-
-
-
-
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-
- printf ("index = %x, status = %x (%d) Reservation is :%s\n",
- _index,
- pDcChargingInfo->SystemStatus,
- pDcChargingInfo->IsAvailable,
- ShmDcCommonData->pGunInfo[_index].ReservationStatus ? "trigger" : "expired");
- if (ShmDcCommonData->pGunInfo[_index].ReservationStatus)
- printf("Reservation idTag:%s\n", ShmDcCommonData->pGunInfo[_index].ReservationID);
- printf("SystemTimeoutFlag = %d, PageIndex = %d\n",
- pSysInfo->SystemTimeoutFlag, pSysInfo->PageIndex);
- } else {
-
- pDcChargingInfo->SystemStatus = atoi(v2);
- }
- } else {
-
-
-
- pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
- if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-
- printf ("AC Type, status = %x (%d)\n",
- pAcChargingInfo->SystemStatus,
- pAcChargingInfo->IsAvailable);
- } else {
-
- pAcChargingInfo->SystemStatus = atoi(v2);
- }
- }
- }
- void RunCardProc(char *v1, char *v2)
- {
- if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
- if (pSysInfo->WaitForPlugit) {
- pSysInfo->WaitForPlugit = 0x00;
- printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
- } else {
- pSysInfo->WaitForPlugit = 0x01;
- printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
- }
- } else {
- strcpy((char *)pSysConfig->UserId, "");
- memcpy((char *)pSysConfig->UserId, v1, strlen(v1));
- pSysConfig->UserId[strlen(v1)] = '\0';
- printf("StartUserId = %s \n", pSysConfig->UserId);
- }
- }
- void RunGunPlugitProc(char *v1, char *v2)
- {
- if (strcmp(v1, "ac") == 0) {
-
-
-
- pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
- if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-
- printf("ConnectorPlugIn = %d \n", pAcChargingInfo->ConnectorPlugIn);
- } else {
-
- pAcChargingInfo->ConnectorPlugIn = atoi(v2);
- }
- return;
- }
- int _index = atoi(v1);
-
-
-
-
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-
- printf("index = %x, plug it = %x\n",
- _index,
- pDcChargingInfo->ConnectorPlugIn);
- } else {
-
- pDcChargingInfo->ConnectorPlugIn = atoi(v2);
- }
- }
- void GetGunLockStatusProc(char *v1, char *v2)
- {
- int _index = atoi(v1);
-
-
-
-
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0) {
- pDcChargingInfo->GunLocked = atoi(v2);
- }
- printf("Gun Locked Status = %d \n", pDcChargingInfo->GunLocked);
- }
- void SetSystemIDProc()
- {
- char *systemId = "Alston_Test";
- memcpy(&pSysConfig->SystemId, systemId, strlen(systemId));
- }
- void RunSelfProc()
- {
- printf("self test status = %x\n", pSysInfo->SelfTestSeq);
- }
- void GetFwVerProc(void)
- {
- int _index = 0;
- int isContinue = 1;
- char *usageMsg = "Usage:\n"
- " model\n"
- " 407\n"
- " conn index, ex: conn 0 | 1\n"
- " relay\n"
- " fan\n"
- " dc\n"
- " led\n"
- " ac\n"
- " exit | c | C\n"
- " help | ? | h\n";
- printf("ModelName = %s\r\n", pSysConfig->ModelName);
- printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev);
- printf("DC Main Debug Version = %s \n", ShmDcCommonData->DebugVersion);
- printf("407 FW Version = %s\n", ShmPrimaryMcuData->version);
- printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev);
- printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev);
- printf("Relay Board Version = %s \n", pSysInfo->RelayModuleFwRev);
- printf("FAN Version = %s \n", pSysInfo->FanModuleFwRev);
- printf("LED Version = %s \n", pSysInfo->LedModuleFwRev);
- printf("LCM FW Version = V.%03d \n", ShmDcCommonData->LcmFwVersion);
- printf("Dispenser Network Information checked: IP = % s Netmask = % s, Gateway = % s \n",
- pSysConfig->Eth0Interface.EthIpAddress,
- pSysConfig->Eth0Interface.EthSubmaskAddress,
- pSysConfig->Eth0Interface.EthGatewayAddress);
-
- }
- void CreateOneError(char *v1)
- {
- int value = atoi(v1);
- pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = value;
- pSysConfig->BillingData.isBilling = value;
- }
- void GetAuthorizeFlag(char *v1)
- {
- if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
- printf("AuthorizeFlag = %d \n", pSysInfo->AuthorizeFlag);
- } else {
- pSysInfo->AuthorizeFlag = atoi(v1);
- }
- }
- void GetRelayStatus(char *v1)
- {
- int _index = atoi(v1);
-
-
-
-
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- printf("RelayK1K2Status = %d \n", pDcChargingInfo->RelayK1K2Status);
- printf("RelayKPK2Status = %d \n", pDcChargingInfo->RelayKPK2Status);
- }
- void FwUpdateFlagProc()
- {
- pSysInfo->FirmwareUpdate = 0x01;
- }
- void CheckAcStatus(char *v1)
- {
- if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
- printf("AC Status = %d \n", pSysInfo->AcContactorStatus);
- }
- }
- void SetCableChkStatus(char *v1, char *v2)
- {
- int _index = atoi(v1);
-
-
-
-
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- pDcChargingInfo->GroundFaultStatus = atoi(v2);
- }
- void SetChargingInfoCCID(char *v1, char *v2)
- {
- int _index = atoi(v1);
-
-
-
-
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- memcpy(pDcChargingInfo->EVCCID, v2, 8);
- pDcChargingInfo->EVCCID[8] = '\0';
- }
- void SetPowerValue(char *v1, char *v2)
- {
- int _index = atoi(v1);
- float _Current = atof(v2);
-
-
-
-
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
- if (pDcChargingInfo->Type != 9) {
- return;
- }
- pDcChargingInfo->EvBatterytargetCurrent = _Current;
- }
- void GetSystemInfo()
- {
- printf ("ModelName = %s \n", pSysConfig->ModelName);
- printf ("SerialNumber = %s \n", pSysConfig->SerialNumber);
- printf ("InternetConn = %d \n", pSysInfo->InternetConn);
- printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
- pSysConfig->MaxChargingPower,
- pSysConfig->MaxChargingCurrent);
- pSysConfig->ShowInformation = YES;
- }
- void ChangeGunNum()
- {
- if (pSysInfo->CurGunSelected + 1 < pSysConfig->TotalConnectorCount) {
- pSysInfo->CurGunSelected += 1;
- pSysInfo->CurGunSelectedByAc = NO_DEFINE;
- } else if (pSysConfig->AcConnectorCount > 0 &&
- pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
- pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
- } else {
- pSysInfo->CurGunSelected = 0;
- pSysInfo->CurGunSelectedByAc = NO_DEFINE;
- }
- }
- void GetGunSelectedNum(char *v1)
- {
- if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
- if (AC_QUANTITY > 0 &&
- pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
- printf("connector select changed = AC \n");
- } else {
- printf("connector selected = %d \n", pSysInfo->CurGunSelected);
- }
- } else {
- int _index = atoi(v1);
- if (_index <= 1) {
- pSysInfo->CurGunSelected = _index;
- pSysInfo->CurGunSelectedByAc = NO_DEFINE;
- printf("connector select changed = %d \n", _index);
- } else if (AC_QUANTITY > 0) {
- pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
- printf("connector select changed = AC \n");
- }
- }
- }
- void SetFanSpeed(char *v1)
- {
- int speed = atoi(v1);
- if(ShmDcCommonData->debugflag == YES) {
- ShmFanModuleData->TestFanSpeed = speed;
- printf("Set Fan speed: %d \n",ShmFanModuleData->TestFanSpeed);
- }
- else
- printf("Please open debug mode\n");
- }
- 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);
- ShmDcCommonData->debugflag = mode;
- pSysConfig->ShowInformation = mode;
- printf("Set Debug Mode:%d\n" , ShmDcCommonData->debugflag);
- }
- void SetGFDMode(char *v1)
- {
- int mode = atoi(v1);
- pSysConfig->AlwaysGfdFlag = mode;
- }
- void GetPsuTemp()
- {
- for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
- for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
- printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
- }
- }
- }
- void GetAcInputVol()
- {
- printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
- pSysInfo->InputVoltageR,
- pSysInfo->InputVoltageS,
- pSysInfo->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 (uint8_t 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 < pSysConfig->TotalConnectorCount; i++) {
-
-
-
-
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- printf("Form RB : Group Index = %d, OutputV = %f \n",
- i,
- pDcChargingInfo->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) {
-
-
-
-
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(0);
- pDcChargingInfo->EvBatterytargetVoltage = vol;
- pDcChargingInfo->EvBatterytargetCurrent = cur;
- }
- }
- printf("*************************************************\n");
- }
- void GetConnectorCapInfo(char *v1)
- {
- int _GunIndex = atoi(v1);
-
-
-
-
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
- printf ("Charger Max Current = %d, Max Power = %d \n",
- pSysConfig->MaxChargingCurrent * 10,
- pSysConfig->MaxChargingPower * 10);
- printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
- _GunIndex,
- pDcChargingInfo->RealMaxPower,
- pDcChargingInfo->RealMaxVoltage,
- pDcChargingInfo->RealMaxCurrent);
- }
- static void setConfirmSelGun(uint8_t selGun)
- {
- if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
- ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
-
- } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
- ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
-
- }
- }
- static float ReadAdcVolt(uint8_t AdcChannel)
- {
-
-
-
-
- int fd = -1;
- uint8_t str[64] = { 0 };
- uint8_t AdcValue[8] = { '\0' };
- if (AdcChannel > 7) {
- return -1;
- }
- sprintf((char*)str, "/sys/bus/iio/devices/iio\:device0/in_voltage%d_raw", AdcChannel);
- fd = open((char*)str, O_RDONLY);
- read(fd, AdcValue, 4);
- close(fd);
- return (1.8 * atoi((char*)&AdcValue[0])) / 4095;
-
- }
- static void getChillerTemperature(struct ChargingInfoData* chargingData)
- {
- uint8_t i = 0;
- float adcVoltage = 0.0;
- ChillerTemp pChillerTemp;
- uint8_t maxTemp;
- for (i = 0; i < 4; i++) {
- adcVoltage = 0.0;
- adcVoltage = ReadAdcVolt(i);
- ShmDcCommonData->TempVolt[i] = adcVoltage;
- if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) {
- pChillerTemp.Temp[i] = ((adcVoltage - 0.908) * 500) + 60;
-
- } else if ((adcVoltage <= 1.07) && (adcVoltage > 0.9)) {
- pChillerTemp.Temp[i] = ((adcVoltage - 0.91) * 705.88) + 60;
-
- } else {
- pChillerTemp.Temp[i] = UNDEFINED_TEMP;
- }
- }
- maxTemp = pChillerTemp.Temp[0];
- memcpy((char*)ShmDcCommonData->SystemTemp, (char*)pChillerTemp.Temp, sizeof(ChillerTemp));
- for (i = 1; i < 4; i++) {
- if (pChillerTemp.Temp[i] > pChillerTemp.Temp[i - 1] && pChillerTemp.Temp[i] != UNDEFINED_TEMP) {
- maxTemp = pChillerTemp.Temp[i];
- }
- }
- chargingData->ChillerTemp = maxTemp;
- }
- void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, float* cur)
- {
- for(int i = 0 ; i < 4 ; i++) {
- if (ShmDcCommonData->SystemTemp[i] >= STAGE1_GUN_DERATING_TEMP &&
- ShmDcCommonData->SystemTemp[i] < STAGE2_GUN_DERATING_TEMP &&
- chargingData->deratingByConnOtp.deratingIndex < 1) {
- chargingData->deratingByConnOtp.deratingIndex = 1;
- } else if (ShmDcCommonData->SystemTemp[i] >= STAGE2_GUN_DERATING_TEMP &&
- ShmDcCommonData->SystemTemp[i] != UNDEFINED_TEMP &&
- chargingData->deratingByConnOtp.deratingIndex < 2) {
- chargingData->deratingByConnOtp.deratingIndex = 2;
- }
- }
- if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
- {
- *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
- } else if (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex] != 0)
- {
- if (*cur > (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex]/10)) {
- *cur = chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex]/10;
- }
- }
- }
- void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
- {
- int _GunIndex;
- uint8_t gunIndex = 0;
- uint8_t stopChg = 0;
- uint8_t curGun = 0;
- int isContinue = 1;
- float _Voltage;
- float _Current;
- float deratingPower;
- float deratingCurrent;
- int derating_index = 0;
- uint8_t PreviousSystemStatus[2] = {0xff};
- int idx;
- char *usageMsg = "Usage:\n"
- " strchg <index> <voltage> <current> ex: strchg 0 150 2\n"
- " chg <voltage> <current> ex: chg 500 100\n"
- " c <index> ex: c 0\n"
- " help | ? | h\n"
- "\r\n";
- if (strcmp(v1, "auto") == EQUAL) {
- _usingAutoRun = 0x01;
- _GunIndex = 0;
- _Voltage = 500;
- _Current = (pSysConfig->MaxChargingPower * 1000) / _Voltage;
- } else {
- _usingAutoRun = 0x00;
- _GunIndex = atoi(v1);
- _Voltage = atof(v2);
- _Current = atof(v3);
- }
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
- printf("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
- pSysConfig->MaxChargingPower,
- _Voltage,
- _Current);
- if (_Voltage > 1000 || _Voltage < 50) {
- printf ("Input Voltage over range\n");
- return;
- }
-
- ShmDcCommonData->debugflag = YES;
- system("killall Module_EvComm");
- pSysInfo->CurGunSelected = _GunIndex;
- while (isContinue) {
- curGun = pSysInfo->CurGunSelected;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
- if (!pDcChargingInfo->IsAvailable) {
- printf("Gun%d Not Available\n",curGun);
- break;
- }
-
- switch (pDcChargingInfo->SystemStatus) {
- case S_IDLE:
- if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
- PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
- sleep(3);
- #if defined DD360Audi
- setConfirmSelGun(curGun);
- #endif
- strcpy((char *)pSysConfig->UserId, "AutoStartCharging");
- pDcChargingInfo->ConnectorPlugIn = 1;
- printf ("[UnconditionalCharge - S_IDLE]\n");
- pDcChargingInfo->Type = 9;
- sleep(1);
- }
- if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
- pSysInfo->StartToChargingFlag = 0x01;
- pDcChargingInfo->SystemStatus = S_PREPARNING;
- }
- break;
- case S_PREPARNING:
- if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
- PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
- printf ("[UnconditionalCharge - S_PREPARNIN]\n");
- ShmFanModuleData->TestFanSpeed = 7000;
-
- printf ("wait find module\n");
- }
-
-
-
-
-
-
-
-
-
- pDcChargingInfo->TimeoutFlag = 0;
- pSysInfo->SystemTimeoutFlag = 0;
- pSysInfo->SystemPage = _LCM_NONE;
-
- pDcChargingInfo->Type = 9;
- break;
- case S_PREPARING_FOR_EV:
- if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
- PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
- printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
- printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10);
- }
-
- pDcChargingInfo->TimeoutFlag = 0;
-
- pDcChargingInfo->Type = 9;
-
- pDcChargingInfo->EvBatterySoc = 50;
- pDcChargingInfo->EvBatterytargetVoltage = 500;
- pDcChargingInfo->EvBatterytargetCurrent = 2;
- pDcChargingInfo->AvailableChargingCurrent = 1000;
-
-
-
-
- {
- printf ("Precharge Done = %f \n",
- pDcChargingInfo->PresentChargingVoltage);
-
- pDcChargingInfo->SystemStatus = S_PREPARING_FOR_EVSE;
- }
- break;
- case S_PREPARING_FOR_EVSE:
- if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
- PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
- printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
- strcpy((char *)pSysConfig->UserId, "");
- }
-
-
-
- pDcChargingInfo->TimeoutFlag = 0;
-
- pDcChargingInfo->Type = 9;
-
- pDcChargingInfo->EvBatterySoc = 50;
- pDcChargingInfo->EvBatterytargetVoltage = 500;
- pDcChargingInfo->EvBatterytargetCurrent = 2;
- pDcChargingInfo->AvailableChargingCurrent = 1000;
-
-
-
-
- if (pDcChargingInfo->GroundFaultStatus == 0x01 ||
- pDcChargingInfo->GroundFaultStatus == 0x03) {
- printf ("First Ground Fault State (%d)\n",
- pDcChargingInfo->GroundFaultStatus);
- printf ("Wait K1K2 = %f \n", pDcChargingInfo->PresentChargingVoltage);
- sleep(5);
-
- pDcChargingInfo->SystemStatus = S_CHARGING;
- } else if (pDcChargingInfo->GroundFaultStatus > 0x02) {
- printf ("First Ground Fault check Fail (%d)\n",
- pDcChargingInfo->GroundFaultStatus);
- pDcChargingInfo->SystemStatus = S_TERMINATING;
- }
- break;
- case S_CHARGING:
- if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
- PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
- if (_usingAutoRun == 0x00) {
-
- pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
- pDcChargingInfo->EvBatterytargetCurrent = _Current;
- } else {
- _curAutoRunCount = 0;
- gettimeofday(&_autoTime, NULL);
- }
- pDcChargingInfo->EvBatterySoc = 50;
- pDcChargingInfo->AvailableChargingCurrent = 1000;
- printf ("[UnconditionalCharge - S_CHARGING]\n");
- }
- 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)
- ) {
- pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
- pDcChargingInfo->EvBatterytargetCurrent = _Current;
- } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) {
- _curAutoRunCount++;
- if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
- pDcChargingInfo->SystemStatus = S_TERMINATING;
- } else {
- gettimeofday(&_autoTime, NULL);
- }
- } else {
- pDcChargingInfo->EvBatterytargetVoltage = 0;
- pDcChargingInfo->EvBatterytargetCurrent = 0;
- }
- }
-
- for (idx = 0; idx < pSysConfig->TotalConnectorCount; idx++) {
- struct ChargingInfoData* pInfo = (struct ChargingInfoData*)GetDcChargingInfoData(idx);
- if (!ShmDcCommonData->TestTemperature)
- getChillerTemperature(pInfo);
-
- if ((strncmp((char*)&pSysConfig->ModelName[7 + idx * 2], "V", 1) == 0) ||
- (strncmp((char*)&pSysConfig->ModelName[7 + idx * 2], "F", 1) == 0)) {
- if ((ShmDcCommonData->SystemTemp[idx * 2] <= 70 ||
- ShmDcCommonData->SystemTemp[idx * 2 + 1] <= 70)) {
- if (pInfo->EvBatterytargetCurrent > 250) {
- pInfo->EvBatterytargetCurrent = 250;
- printf("Chiller%d temperature(%d %d) too low limit target Current under 250A\n", idx, ShmDcCommonData->SystemTemp[idx * 2],
- ShmDcCommonData->SystemTemp[idx * 2 + 1]);
- }
- } else if ((ShmDcCommonData->SystemTemp[idx * 2] >= 80 ||
- ShmDcCommonData->SystemTemp[idx * 2 + 1] >= 80) && pInfo->EvBatterytargetCurrent != _Current) {
- pInfo->EvBatterytargetCurrent = _Current;
- printf("Chiller%d temperature(%d %d) recovery target Current set %.2fA\n", idx, ShmDcCommonData->SystemTemp[idx * 2],
- ShmDcCommonData->SystemTemp[idx * 2 + 1], pInfo->EvBatterytargetCurrent);
- }
- if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
- if (pInfo->EvBatterytargetCurrent > 250) {
- pInfo->EvBatterytargetCurrent = 250;
- printf("Chiller alarm limit target Current under 250A\n");
- }
- }
- }
-
- if (pInfo->deratingByConnOtp.isNeedDerating) {
- deratingCurrent = pInfo->EvBatterytargetCurrent;
- deratingPower = pInfo->AvailableChargingPower;
- GetOtpPwrOrCurMethod(pInfo, &deratingPower, &deratingCurrent);
- if (derating_index != pDcChargingInfo->deratingByConnOtp.deratingIndex) {
- printf("Change Derating Index:%d\n", pInfo->deratingByConnOtp.deratingIndex);
- derating_index = pInfo->deratingByConnOtp.deratingIndex;
- }
- if (pInfo->EvBatterytargetCurrent != deratingCurrent ||
- pInfo->AvailableChargingPower != deratingPower) {
- pInfo->EvBatterytargetCurrent = deratingCurrent;
- pInfo->AvailableChargingPower = deratingPower;
- printf("Derating Current:%.3f Power:%.3f\n", pInfo->EvBatterytargetCurrent, pInfo->AvailableChargingPower);
- }
- }
- }
-
- if ((strncmp((char*)&pSysConfig->ModelName[7 + curGun * 2], "V", 1) == 0) ||
- (strncmp((char*)&pSysConfig->ModelName[7 + curGun * 2], "F", 1) == 0)) {
- }
-
- pDcChargingInfo->PresentChargingPower =
- ((float)((pDcChargingInfo->PresentChargingVoltage) *
- (pDcChargingInfo->PresentChargingCurrent)) / 1000);
- if (pDcChargingInfo->GroundFaultStatus == 0x02) {
- printf ("Charging Ground Fault check Fail (%d)\n",
- pDcChargingInfo->GroundFaultStatus);
- pDcChargingInfo->SystemStatus = S_TERMINATING;
- }
- break;
- case S_TERMINATING:
- if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
- PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
- printf ("[UnconditionalCharge - S_TERMINATING]\n");
-
- system(STTY_DEF TTY_PATH);
- }
- sleep(1);
- pDcChargingInfo->ConnectorPlugIn = 0;
- pDcChargingInfo->SystemStatus = S_COMPLETE;
- break;
- case S_COMPLETE:
- if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
- PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
- printf ("[UnconditionalCharge - S_COMPLETE]\n");
- }
- PreviousSystemStatus[curGun] = 0xFF;
- stopChg = 0;
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- if (PreviousSystemStatus[gunIndex] == 0xFF) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
- pDcChargingInfo->IsAvailable ? (pDcChargingInfo->SystemStatus = S_IDLE) : (pDcChargingInfo->SystemStatus = S_MAINTAIN);
-
- } else {
- pSysInfo->CurGunSelected = gunIndex;
- }
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_MAINTAIN) {
- stopChg++;
- }
- }
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
- pDcChargingInfo->PresentChargingPower = 0;
- if (stopChg == pSysConfig->TotalConnectorCount) {
- system("/root/Module_EvComm &");
- ShmFanModuleData->TestFanSpeed = 0;
- ShmDcCommonData->debugflag = NO;
- sleep(3);
- for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
- pDcChargingInfo->IsAvailable ? (pDcChargingInfo->SystemStatus = S_IDLE) : (pDcChargingInfo->SystemStatus = S_MAINTAIN);
- }
- return;
- }
- break;
- }
- if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
- continue;
- }
- if (strcmp(newString[0], "strchg") == 0) {
- if (strcmp(newString[1], "-1") == 0 ||
- strcmp(newString[1], "") == 0 ||
- strcmp(newString[2], "-1") == 0 ||
- strcmp(newString[2], "") == 0
- ) {
- printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
- continue;
- }
- if (atoi(newString[1]) == pSysInfo->CurGunSelected) {
- continue;
- }
- _GunIndex = atoi((char *)newString[1]);
- _Voltage = atof((char *)newString[2]);
- _Current = atof((char *)newString[3]);
- printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
- pSysConfig->MaxChargingPower,
- _Voltage,
- _Current);
- if (_Voltage > 1000 || _Voltage < 50) {
- _Voltage = 200;
- printf ("Input Voltage over range\n");
- continue;
- }
- pSysInfo->CurGunSelected = _GunIndex;
- strcpy((char *)pSysConfig->UserId, "");
- } else if (strcmp(newString[0], "chg") == 0) {
- if (strcmp(newString[1], "-1") == 0) {
- continue;
- }
- if (strcmp(newString[2], "-1") == 0 ||
- strcmp(newString[2], "") == 0) {
- continue;
- }
- if (strcmp(newString[3], "-1") == 0 ||
- strcmp(newString[3], "") == 0) {
- continue;
- }
- _GunIndex = atoi((char *)newString[1]);
- float _vol = atof(newString[2]);
- float _cur = atof(newString[3]);
- if (_cur <= 0 || _cur <= 0) {
- continue;
- }
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
- printf("reset vol = %f, cur = %f \n", _vol, _cur);
- pDcChargingInfo->EvBatterytargetVoltage = _vol;
- pDcChargingInfo->EvBatterytargetCurrent = _cur;
- } else if (strcmp(newString[0], "c") == 0) {
- if (strcmp(newString[1], "-1") == 0 ||
- strcmp(newString[1], "") == 0) {
- printf("argc 1 is error parameter\r\n");
- continue;
- }
- if (atoi((char *)newString[1]) != -1) {
- pSysInfo->CurGunSelected = atoi((char *)newString[1]);
- }
- printf("stop \n\r");
- pSysInfo->StartToChargingFlag = 0x00;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData( pSysInfo->CurGunSelected);
- pDcChargingInfo->SystemStatus = S_TERMINATING;
- } else if (helpCmd() == YES) {
- printf("%s\n", usageMsg);
- }
- usleep(100000);
- }
- }
- int printTimeMsg(const char *fmt, ...)
- {
- char Buf[4096 + 256] = {0};
- char buffer[4096] = {0};
- int rc = -1;
- va_list args;
- struct timeb SeqEndTime;
- struct tm *tm;
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- va_start(args, fmt);
- rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- ftime(&SeqEndTime);
- SeqEndTime.time = time(NULL);
- tm = localtime(&SeqEndTime.time);
- sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
- tm->tm_hour,
- tm->tm_min,
- tm->tm_sec,
- SeqEndTime.millitm,
- buffer);
- printf("%s", Buf);
- return rc;
- }
- static void resdGunAndChillerTemp(void)
- {
- int isContinue = 1;
- uint8_t i = 0;
- uint32_t sleepTime = 500000;
- uint32_t loopTime = 1000;
- struct timeb showTime;
- struct timeb nowTime;
- char *usageMsg = "Usage:\n"
- " t <index>: loop time, ex: t 1\n"
- " exit | c | C: exit test\n"
- " h | help | ?: show usage message\n"
- "\r\n";
- ftime(&showTime);
- while (isContinue) {
- ftime(&nowTime);
- if (DiffTimeb(showTime, nowTime) > loopTime ||
- DiffTimeb(showTime, nowTime) < 0) {
- for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d(%.3f), %3d(%.3f), %3d(%.3f), %3d(%.3f)\r\n",
- i,
- pDcChargingInfo->ConnectorTemp,
- pDcChargingInfo->ChillerTemp,
- ShmDcCommonData->ConnectorTemp[i][0],
- ShmDcCommonData->ConnectorTemp[i][1],
- ShmDcCommonData->SystemTemp[0],
- ShmDcCommonData->TempVolt[0],
- ShmDcCommonData->SystemTemp[1],
- ShmDcCommonData->TempVolt[1],
- ShmDcCommonData->SystemTemp[2],
- ShmDcCommonData->TempVolt[2],
- ShmDcCommonData->SystemTemp[3],
- ShmDcCommonData->TempVolt[3]);
- }
- ftime(&showTime);
- }
- if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
- usleep(sleepTime);
- continue;
- }
- if (strcmp(newString[0], "t") == 0) {
- if (strcmp(newString[1], "-1") == 0 ||
- strcmp(newString[1], "") == 0 ||
- atoi((char *)newString[1]) > 255
- ) {
- printf("argc 1 is error parameter\r\n");
- continue;
- }
- loopTime = ((atoi((char *)newString[1])) * 1000);
- printf("loopTime = %d\r\n", loopTime);
- ftime(&showTime);
- continue;
- } else if (exitCmd() == YES) {
- return;
- } else if (helpCmd() == YES) {
- printf ("%s\n", usageMsg);
- }
- usleep(sleepTime);
- }
- }
- static void writeOTPTemp(void)
- {
- uint8_t _GunIndex = 0;
- int isContinue = 1;
- uint32_t sleepTime = 500000;
- char *usageMsg = "Usage:\n"
- " OTP <temp_recovery> <temp>, ex: OTP 140 150\n"
- " exit | c | C\n"
- " help | ? | h\n"
- "\r\n";
- while (isContinue) {
- if (readCmdKey(CMD_KEY_WAIT) == NO) {
- sleep(sleepTime);
- continue;
- }
- if (helpCmd() == YES) {
- printf ("%s\n", usageMsg);
- continue;
- } else if (exitCmd() == YES) {
- sleep(1);
- return;
- }
- if (strcmp(newString[0], "OTP") != 0) {
- printf("argc 1 is error parameter\r\n");
- continue;
- }
- if (atoi(newString[1]) > 255 ||
- atoi(newString[1]) == -1) {
- printf("Recovey temperature value overflow\r\n");
- continue;
- }
- if (atoi(newString[2]) > 255 ||
- atoi(newString[2]) == -1) {
- printf("Recovey temperature value overflow\r\n");
- continue;
- }
- pSysInfo->OTPTempR = atoi(newString[1]);
- pSysInfo->OTPTemp = atoi(newString[2]);
- printf("OTP Recovery Temp set:%d\n",pSysInfo->OTPTempR);
- printf("OTP Temp set:%d\n",pSysInfo->OTPTemp);
- usleep(sleepTime);
- }
- }
- void writeChillerStatus(char *v1)
- {
- if (ShmDcCommonData->debugflag == YES) {
- ShmDcCommonData->chillerCtrl = atoi(newString[1]);
- if (ShmDcCommonData->chillerCtrl)
- printf("Chiller set on\n");
- else
- printf("Chiller set off\n");
- } else
- printf("Please open Debug mode\n");
- }
- void showNetworkPage(char* v1)
- {
- ShmDcCommonData->showNetPackage = atoi(newString[1]);
- if (ShmDcCommonData->showNetPackage)
- printf("Show Network Package on\n");
- else
- printf("Show Network Package off\n");
- }
- void showCANBUSPage(char* v1)
- {
- ShmDcCommonData->showCanPackage = atoi(newString[1]);
- if (ShmDcCommonData->showCanPackage)
- printf("Show CAN Bus Package on\n");
- else
- printf("Show CAN Bus Package off\n");
- }
- void setSystemTime(char* date,char* time)
- {
- char _setTime[30];
- char cmdBuf[50];
- sprintf(_setTime, "%s %s", date, time);
- printf("Set Timer:%s", _setTime);
- sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
- system((char*)cmdBuf);
- system("hwclock -w -u");
- system("hwclock -s");
- }
- static uint8_t getMaxConnectTemp(uint8_t headTemp1, uint8_t headTemp2)
- {
- uint8_t maxTemp = 0;
- if (headTemp1 > TEMP_BOUNDARY &&
- headTemp2 > TEMP_BOUNDARY) {
- return UNDEFINED_TEMP;
- }
- if (headTemp1 <= TEMP_BOUNDARY) {
- maxTemp = headTemp1;
- }
- if (headTemp2 <= TEMP_BOUNDARY) {
- if (headTemp2 > maxTemp) {
- maxTemp = headTemp2;
- }
- }
- return maxTemp;
- }
- static void writeGunAndChillerTemp(void)
- {
- uint8_t _GunIndex = 0;
- int isContinue = 1;
- uint32_t sleepTime = 500000;
- char *usageMsg = "Usage:\n"
- " conn <index> <temp>, ex: conn 0 150\n"
- " chiller <index> <temp>, ex: chiller 0 150\n"
- " tempR\n"
- " exit | c | C\n"
- " help | ? | h\n"
- "\r\n";
- ShmDcCommonData->TestTemperature = YES;
- while (isContinue) {
- if (readCmdKey(CMD_KEY_WAIT) == NO) {
- sleep(sleepTime);
- continue;
- }
- if (helpCmd() == YES) {
- printf ("%s\n", usageMsg);
- continue;
- } else if (exitCmd() == YES) {
- ShmDcCommonData->TestTemperature = NO;
- sleep(1);
- return;
- } else if (strcmp(newString[0], "tempR") == 0) {
- resdGunAndChillerTemp();
- }
- if ((strcmp(newString[0], "chiller") != 0) &&
- (strcmp(newString[1], "-1") == 0 ||
- strcmp(newString[1], "") == 0)
- ) {
- printf("argc 1 is error parameter\r\n");
- continue;
- }
- if (strcmp(newString[0], "chiller") == 0) {
- if (atoi(newString[2]) > 255 ||
- atoi(newString[2]) == -1 ||
- atoi(newString[3]) > 255 ||
- atoi(newString[3]) == -1 ||
- atoi(newString[4]) > 255 ||
- atoi(newString[4]) == -1 ||
- atoi(newString[5]) > 255 ||
- atoi(newString[5]) == -1) {
- printf("temperature value overflow\r\n");
- continue;
- }
- } else {
- if (atoi(newString[2]) > 255 ||
- atoi(newString[2]) == -1) {
- printf("temperature value overflow\r\n");
- continue;
- }
- }
- _GunIndex = atoi((char *)newString[1]);
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
- if (_GunIndex >= pSysConfig->TotalConnectorCount) {
- printf("gun index over total connector\r\n");
- continue;
- }
- if (strcmp(newString[0], "chiller") == 0) {
- if (ShmDcCommonData->pGunInfo[_GunIndex].withChiller) {
- ShmDcCommonData->SystemTemp[0] = atoi(newString[2]);
- ShmDcCommonData->SystemTemp[1] = atoi(newString[3]);
- ShmDcCommonData->SystemTemp[2] = atoi(newString[4]);
- ShmDcCommonData->SystemTemp[3] = atoi(newString[5]);
- for(int i = 0 ; i < pSysConfig->TotalConnectorCount ; i++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- if (!ShmDcCommonData->pGunInfo[i].withChiller)
- continue;
- if (i == LEFT_GUN_NUM) {
- pDcChargingInfo->ChillerTemp = getMaxConnectTemp(ShmDcCommonData->SystemTemp[0],ShmDcCommonData->SystemTemp[1]);
- } else {
- pDcChargingInfo->ChillerTemp = getMaxConnectTemp(ShmDcCommonData->SystemTemp[2],ShmDcCommonData->SystemTemp[3]);
- }
- printf("set %d chiller temperature = %d\r\n",
- i,
- pDcChargingInfo->ChillerTemp);
- }
-
-
- } else {
- printf("This Gun without Chiller\r\n");
- }
- } else if (strcmp(newString[0], "conn") == 0) {
- pDcChargingInfo->ConnectorTemp = atoi(newString[2]);
- printf("set %d connector temp = %d\r\n",
- _GunIndex,
- pDcChargingInfo->ConnectorTemp);
- }
- usleep(sleepTime);
- }
- }
- void setledcolor(int on_off)
- {
- if (on_off)
- ShmDcCommonData->pTest.ledflag = TRUE;
- else {
- ShmDcCommonData->pTest.ledflag = FALSE;
- return;
- }
- int isContinue = 1;
- uint32_t sleepTime = 500000;
- uint32_t color_value;
- char* usageMsg = "Usage:\n"
- " r 0~100\n"
- " g 0~100\n"
- " b 0~100\n"
- " exit | c | C\n"
- " help | ? | h\n"
- "\r\n";
- while (isContinue) {
- if (readCmdKey(CMD_KEY_WAIT) == NO) {
- sleep(sleepTime);
- continue;
- }
- if (helpCmd() == YES) {
- printf("%s\n", usageMsg);
- continue;
- } else if (exitCmd() == YES) {
- ShmDcCommonData->pTest.ledflag = FALSE;
- return;
- }
- if ((strcmp(newString[0], "r") != 0) &&
- (strcmp(newString[1], "-1") == 0 ||
- strcmp(newString[1], "") == 0)
- ) {
- printf("argc 1 is error parameter\r\n");
- continue;
- }
- if ((strcmp(newString[0], "g") != 0) &&
- (strcmp(newString[1], "-1") == 0 ||
- strcmp(newString[1], "") == 0)
- ) {
- printf("argc 1 is error parameter\r\n");
- continue;
- }
- if ((strcmp(newString[0], "b") != 0) &&
- (strcmp(newString[1], "-1") == 0 ||
- strcmp(newString[1], "") == 0)
- ) {
- printf("argc 1 is error parameter\r\n");
- continue;
- }
- if (atoi(newString[1]) < 0 || atoi(newString[1]) > 100) {
- printf("argc 1 is error parameter range is 0~100\r\n");
- continue;
- }
- if (strcmp(newString[0], "r") == EQUAL &&
- atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) {
- pSysConfig->LedInfo.Red[0] = atoi(newString[1]);
- } else {
- }
- if (strcmp(newString[0], "g") == EQUAL &&
- atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) {
- pSysConfig->LedInfo.Green[0] = atoi(newString[1]);
- }
- if (strcmp(newString[0], "b") == EQUAL &&
- atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) {
- pSysConfig->LedInfo.Blue[0] = atoi(newString[1]);
- }
- printf("Color set red[%d] green[%d] blue[%d]\n", pSysConfig->LedInfo.Red[0], pSysConfig->LedInfo.Green[0], pSysConfig->LedInfo.Blue[0]);
- usleep(sleepTime);
- }
- ShmDcCommonData->pTest.ledflag = FALSE;
- }
- void ShowPowerConsumption(char* v1)
- {
- printf("Dispenser Gun0 PowerConsumption:%.4f\n", ShmDcCommonData->pGunInfo[0].PowerConsumption);
- printf("Dispenser Gun1 PowerConsumption:%.4f\n", ShmDcCommonData->pGunInfo[1].PowerConsumption);
- }
- int main(void)
- {
- uint8_t _GunIndex = 0;
- int isContinue = 1;
- char *usageMsg = "Usage:\n"
- " state <index> : get gun state\n"
- " card : scanning card (x)\n"
- " gun <index> : get gun plugit state\n"
- " lock <index> : get gun locked state\n"
- " sysid : test system ID\n"
- " self : self test state (x)\n"
- " ver| v | -v : version of board (407 or relay or other)\n"
- " update : update firmware\n"
- " ac : get ac relay state (x) \n"
- " cable <index> <state> : set ground fault state\n"
- " pow <index> <power> : set power value\n"
- " model : get system information\n"
- " temp : get PSU temperature\n"
- " fan <speed> : set fan board speed\n"
- " strchg <auto> : auto test charging\n"
- " strchg <index> <voltage <current> : select gun test charging\n"
- " tempW : write connector header and Chiller temperature\r\n"
- " tempR : print connector header and chiller temperature\r\n"
- " OTP : Write OTP temperature\r\n"
- " netdump : show network package\r\n"
- " candump : show can package\r\n"
- " powerconsumption : Show Power Consumption\n"
- " led : set led color\n"
- "\r\n";
- if (CreateAllCsuShareMemory() == FAIL) {
- printf("create share memory error\r\n");
- return FAIL;
- }
- MappingGunChargingInfo("ReadCmdline Task");
- pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
- pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
- ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
- ShmGBTData = (struct GBTData *)GetShmGBTData();
- ShmCcsData = (struct CcsData *)GetShmCcsData();
- ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
- ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
- ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
- ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
- ShmPsuData = (struct PsuData *)GetShmPsuData();
- ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
- ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
- ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
- while (isContinue) {
- if (readCmdKey(CMD_KEY_WAIT) == NO) {
- continue;
- }
- if (strcmp(newString[0], "state") == 0) {
- if (strcmp(newString[1], "-1") == 0 ||
- strcmp(newString[1], "") == 0) {
- continue;
- }
-
- RunStatusProc(newString[1], newString[2]);
- } else if (strcmp(newString[0], "card") == 0) {
-
- RunCardProc(newString[1], newString[2]);
- } else if (strcmp(newString[0], "gun") == 0) {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
- continue;
- }
-
- RunGunPlugitProc(newString[1], newString[2]);
- } else if (strcmp(newString[0], "lock") == 0) {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
- continue;
- }
-
- GetGunLockStatusProc(newString[1], newString[2]);
- } else if (strcmp(newString[0], "sysid") == 0) {
-
- SetSystemIDProc();
- } else if (strcmp(newString[0], "self") == 0) {
-
- RunSelfProc(newString[1]);
- } else if (strcmp(newString[0], "ver") == 0 ||
- strcmp(newString[0], "v") == 0 ||
- strcmp(newString[0], "-v") == 0) {
-
-
-
-
- GetFwVerProc();
- } else if (strcmp(newString[0], "update") == 0) {
-
- FwUpdateFlagProc(newString[1]);
- } else if (strcmp(newString[0], "ac") == 0) {
-
- CheckAcStatus(newString[1]);
- } else if (strcmp(newString[0], "cable") == 0) {
- if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
- continue;
- }
-
- SetCableChkStatus(newString[1], newString[2]);
- } else if (strcmp(newString[0], "pow") == 0) {
- if (strcmp(newString[1], "-1") == 0 ||
- strcmp(newString[1], "") == 0) {
- continue;
- }
-
- SetPowerValue(newString[1], newString[2]);
- } else if (strcmp(newString[0], "model") == 0) {
- GetSystemInfo();
- } else if (strcmp(newString[0], "select") == 0) {
-
- GetGunSelectedNum(newString[1]);
- } else if (strcmp(newString[0], "change") == 0) {
-
- ChangeGunNum();
- } else if (strcmp(newString[0], "fan") == 0) {
-
- SetFanSpeed(newString[1]);
- } else if (strcmp(newString[0], "speed") == 0) {
-
- GetFanSpeed();
- } else if (strcmp(newString[0], "debug") == 0) {
-
- SetDebugMode(newString[1]);
- } else if (strcmp(newString[0], "gfd") == 0) {
-
- SetGFDMode(newString[1]);
- } else if (strcmp(newString[0], "temp") == 0) {
-
- 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;
- }
-
- GetPsuInformation(newString[1], newString[2], newString[3]);
- } else if (strcmp(newString[0], "cap") == 0) {
- GetConnectorCapInfo(newString[1]);
- } else if (strcmp(newString[0], "error") == 0) {
- CreateOneError(newString[1]);
- } else if (strcmp(newString[0], "auth") == 0) {
- GetAuthorizeFlag(newString[1]);
- } else if (strcmp(newString[0], "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], "strchg") == 0) {
-
- if (strcmp(newString[1], "auto") == 0) {
- newString[2][0] = 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], "tempW") == 0) {
- writeGunAndChillerTemp();
- } else if (strcmp(newString[0], "tempR") == 0) {
- resdGunAndChillerTemp();
- } else if (strcmp(newString[0], "OTP") == 0) {
- writeOTPTemp();
- } else if (strcmp(newString[0], "netdump") == 0) {
- showNetworkPage(newString[1]);
- } else if (strcmp(newString[0], "candump") == 0) {
- showCANBUSPage(newString[1]);
- } else if (strcmp(newString[0], "time") == 0) {
- setSystemTime(newString[1], newString[2]);
- } else if (strcmp(newString[0], "powerconsumption") == 0) {
- ShowPowerConsumption(newString[1]);
- } else if (strcmp(newString[0], "led") == 0) {
- setledcolor(newString[1]);
- } else if (strcmp(newString[0], "btnl") == 0) {
- ShmPrimaryMcuData->InputDet.bits.Button1 = BTN_PRESS;
- sleep(1);
- ShmPrimaryMcuData->InputDet.bits.Button1 = BTN_RELEASE;
- } else if (strcmp(newString[0], "btnr") == 0) {
- ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_PRESS;
- sleep(1);
- ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_RELEASE;
- } else if (strcmp(newString[0], "DcMeter") == 0) {
- } else {
- printf("%s\n", usageMsg);
- }
- sleep(1);
- }
- return 0;
- }
|