|
@@ -1,2800 +1,3769 @@
|
|
|
-#include <sys/types.h>
|
|
|
-#include <sys/stat.h>
|
|
|
-#include <sys/time.h>
|
|
|
-#include <sys/timeb.h>
|
|
|
-#include <sys/types.h>
|
|
|
-#include <sys/ioctl.h>
|
|
|
-#include <sys/socket.h>
|
|
|
-#include <sys/ipc.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 "../../define.h"
|
|
|
-#include "Config.h"
|
|
|
-#include <stdbool.h>
|
|
|
-#include <dirent.h>
|
|
|
-#include "timeout.h"
|
|
|
-
|
|
|
-#define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
|
|
|
-#define PASS 1
|
|
|
-#define FAIL -1
|
|
|
-#define BUFFER_SIZE 128
|
|
|
-#define YES 1
|
|
|
-#define NO 0
|
|
|
-#define NORMAL 0
|
|
|
-#define ABNORMAL 1
|
|
|
-#define EQUAL 0
|
|
|
-#define BTN_RELEASE 0
|
|
|
-#define BTN_PRESS 1
|
|
|
-#define MAX_BUF 64
|
|
|
-#define SYSFS_GPIO_DIR "/sys/class/gpio"
|
|
|
-#define UPGRADE_FAN 0x02
|
|
|
-#define UPGRADE_RB 0x03
|
|
|
-#define UPGRADE_PRI 0x04
|
|
|
-
|
|
|
-bool IsAuthorizingMode();
|
|
|
-void ClearAuthorizedFlag();
|
|
|
-bool isDetectPlugin();
|
|
|
-void ClearDetectPluginFlag();
|
|
|
-int mystrcmp(unsigned char *p1, unsigned char *p2);
|
|
|
-
|
|
|
-unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
|
|
|
-void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
|
|
|
-void ChargingTerminalProcess(byte gunIndex);
|
|
|
-void ChkPrimaryStatus();
|
|
|
-void StartSystemTimeoutDet(unsigned char flag);
|
|
|
-void StopSystemTimeoutDet();
|
|
|
-void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
|
|
|
-void StopGunInfoTimeoutDet(unsigned char gunIndex);
|
|
|
-
|
|
|
-struct SysConfigAndInfo *ShmSysConfigAndInfo;
|
|
|
-struct StatusCodeData *ShmStatusCodeData;
|
|
|
-struct PsuData *ShmPsuData;
|
|
|
-struct CHAdeMOData *ShmCHAdeMOData;
|
|
|
-struct CcsData *ShmCcsData;
|
|
|
-struct PrimaryMcuData *ShmPrimaryMcuData;
|
|
|
-struct FanModuleData *ShmFanModuleData;
|
|
|
-struct RelayModuleData *ShmRelayModuleData;
|
|
|
-struct OCPP16Data *ShmOCPP16Data;
|
|
|
-
|
|
|
-struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
-struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
-struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
-
|
|
|
-byte _gunCount = 0;
|
|
|
-
|
|
|
-byte _gunIndex = 0;
|
|
|
-byte _chademoIndex = 0;
|
|
|
-byte _ccsIndex = 0;
|
|
|
-byte _gb_Index = 0;
|
|
|
-byte bd0_1_status = 0;
|
|
|
-byte bd0_2_status = 0;
|
|
|
-byte bd1_1_status = 0;
|
|
|
-byte bd1_2_status = 0;
|
|
|
-
|
|
|
-bool isCardScan = false;
|
|
|
-
|
|
|
-int rfidFd = -1;
|
|
|
-char* rfidPortName = "/dev/ttyS2";
|
|
|
-byte autoReturnTimeoutFlag = 0x00;
|
|
|
-int whileLoopTime = 10000;
|
|
|
-unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
|
|
|
-
|
|
|
-int StoreLogMsg_1(const char *fmt, ...);
|
|
|
-
|
|
|
-#define DEBUG_INFO_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
|
-#define DEBUG_WARN_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
|
-#define DEBUG_ERROR_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-int InitCanBus()
|
|
|
-{
|
|
|
- int s0,nbytes;
|
|
|
- struct timeval tv;
|
|
|
- struct ifreq ifr0;
|
|
|
- struct sockaddr_can addr0;
|
|
|
-
|
|
|
- system("/sbin/ip link set can0 down");
|
|
|
- system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
|
|
|
- system("/sbin/ip link set can0 up");
|
|
|
-
|
|
|
- s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
|
|
-
|
|
|
- tv.tv_sec = 0;
|
|
|
- tv.tv_usec = 10000;
|
|
|
- if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("Set SO_RCVTIMEO NG");
|
|
|
- #endif
|
|
|
- }
|
|
|
- nbytes=40960;
|
|
|
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("Set SO_RCVBUF NG");
|
|
|
- #endif
|
|
|
- }
|
|
|
- nbytes=40960;
|
|
|
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("Set SO_SNDBUF NG");
|
|
|
- #endif
|
|
|
- }
|
|
|
-
|
|
|
- strcpy(ifr0.ifr_name, "can0" );
|
|
|
- ioctl(s0, SIOCGIFINDEX, &ifr0);
|
|
|
- addr0.can_family = AF_CAN;
|
|
|
- addr0.can_ifindex = ifr0.ifr_ifindex;
|
|
|
- bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
|
|
|
- return s0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-char *_priPortName = "/dev/ttyS1";
|
|
|
-char *_485PortName = "/dev/ttyS5";
|
|
|
-
|
|
|
-int InitComPort(byte target)
|
|
|
-{
|
|
|
- int fd;
|
|
|
- struct termios tios;
|
|
|
-
|
|
|
- if (target == UPGRADE_PRI)
|
|
|
- fd = open(_priPortName, O_RDWR);
|
|
|
- else if (target == UPGRADE_FAN || target == UPGRADE_RB)
|
|
|
- fd = open(_485PortName, O_RDWR);
|
|
|
-
|
|
|
- if(fd<=0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("open 407 Communication port NG \n");
|
|
|
- #endif
|
|
|
- return -1;
|
|
|
- }
|
|
|
- ioctl (fd, TCGETS, &tios);
|
|
|
- tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
|
|
|
- tios.c_lflag = 0;
|
|
|
- tios.c_iflag = 0;
|
|
|
- tios.c_oflag = 0;
|
|
|
- tios.c_cc[VMIN]=0;
|
|
|
- tios.c_cc[VTIME]=(unsigned char)1;
|
|
|
- tios.c_lflag=0;
|
|
|
- tcflush(fd, TCIFLUSH);
|
|
|
- ioctl (fd, TCSETS, &tios);
|
|
|
-
|
|
|
- return fd;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-int mystrcmp(unsigned char *p1, unsigned char *p2)
|
|
|
-{
|
|
|
- while(*p1==*p2)
|
|
|
- {
|
|
|
- if(*p1=='\0' || *p2=='\0')
|
|
|
- break;
|
|
|
- p1++;
|
|
|
- p2++;
|
|
|
- }
|
|
|
- if(*p1=='\0' && *p2=='\0')
|
|
|
- return(PASS);
|
|
|
- else
|
|
|
- return(FAIL);
|
|
|
-}
|
|
|
-
|
|
|
-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);
|
|
|
-}
|
|
|
-
|
|
|
-int StoreLogMsg_1(const char *fmt, ...)
|
|
|
-{
|
|
|
- char Buf[4096+256];
|
|
|
- char buffer[4096];
|
|
|
- time_t CurrentTime;
|
|
|
- struct tm *tm;
|
|
|
- va_list args;
|
|
|
-
|
|
|
- va_start(args, fmt);
|
|
|
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
|
|
|
- va_end(args);
|
|
|
-
|
|
|
- memset(Buf,0,sizeof(Buf));
|
|
|
- CurrentTime = time(NULL);
|
|
|
- tm=localtime(&CurrentTime);
|
|
|
- sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
|
|
|
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
|
|
|
- buffer,
|
|
|
- tm->tm_year+1900,tm->tm_mon+1);
|
|
|
- system(Buf);
|
|
|
-
|
|
|
- return rc;
|
|
|
-}
|
|
|
-
|
|
|
-unsigned long GetTimeoutValue(struct timeval _sour_time)
|
|
|
-{
|
|
|
- struct timeval _end_time;
|
|
|
- gettimeofday(&_end_time, NULL);
|
|
|
-
|
|
|
- return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
|
|
|
-}
|
|
|
-
|
|
|
-void setChargerMode(byte gun_index, byte mode)
|
|
|
-{
|
|
|
- chargingInfo[gun_index]->SystemStatus = mode;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-int isInterfaceUp(const char *interface)
|
|
|
-{
|
|
|
- int result = FAIL;
|
|
|
-
|
|
|
- FILE *fp;
|
|
|
- char cmd[256];
|
|
|
- char buf[512];
|
|
|
-
|
|
|
- strcpy(cmd, "ifconfig");
|
|
|
- fp = popen(cmd, "r");
|
|
|
- if(fp != NULL)
|
|
|
- {
|
|
|
- while(fgets(buf, sizeof(buf), fp) != NULL)
|
|
|
- {
|
|
|
- if(strstr(buf, interface) > 0)
|
|
|
- {
|
|
|
- result = PASS;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- pclose(fp);
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-int CreateShareMemory()
|
|
|
-{
|
|
|
- int MeterSMId;
|
|
|
-
|
|
|
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
|
|
|
-
|
|
|
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmStatusCodeData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmStatusCodeData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
|
|
|
-
|
|
|
-
|
|
|
- if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPsuData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPsuData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- memset(ShmPsuData, 0, sizeof(struct PsuData));
|
|
|
-
|
|
|
- if(CHAdeMO_QUANTITY > 0)
|
|
|
- {
|
|
|
- if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCHAdeMOData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCHAdeMOData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if(CCS_QUANTITY > 0)
|
|
|
- {
|
|
|
- if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCcsData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCcsData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- memset(ShmCcsData, 0, sizeof(struct CcsData));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPrimaryMcuData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
|
|
|
-
|
|
|
-
|
|
|
- if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmFanModuleData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmFanModuleData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
|
|
|
-
|
|
|
-
|
|
|
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmRelayModuleData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmRelayModuleData NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
|
|
|
-
|
|
|
-
|
|
|
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmOCPP16Data NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmOCPP16Data NG \n");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void ChangeLcmByIndex(byte page_index)
|
|
|
-{
|
|
|
- if (ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level != 2 ||
|
|
|
- page_index == _LCM_COMPLETE || page_index == _LCM_FIX)
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void InitGPIO()
|
|
|
-{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- system("echo 22 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio22/direction");
|
|
|
-
|
|
|
- system("echo 23 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio23/direction");
|
|
|
-
|
|
|
- system("echo 26 > /sys/class/gpio/export");
|
|
|
- system("echo \"out\" > /sys/class/gpio/gpio26/direction");
|
|
|
- system("echo 1 > /sys/class/gpio/gpio26/value");
|
|
|
-
|
|
|
- system("echo 27 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio27/direction");
|
|
|
-
|
|
|
- system("echo 29 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio29/direction");
|
|
|
-
|
|
|
- system("echo 19 > /sys/class/gpio/export");
|
|
|
- system("echo \"out\" > /sys/class/gpio/gpio19/direction");
|
|
|
- system("echo 0 > /sys/class/gpio/gpio19/value");
|
|
|
-
|
|
|
- system("echo 20 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio20/direction");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- system("echo 44 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio44/direction");
|
|
|
-
|
|
|
- system("echo 45 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio45/direction");
|
|
|
-
|
|
|
- system("echo 46 > /sys/class/gpio/export");
|
|
|
- system("echo \"out\" > /sys/class/gpio/gpio46/direction");
|
|
|
- system("echo 0 > /sys/class/gpio/gpio46/value");
|
|
|
-
|
|
|
- system("echo 47 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio47/direction");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- system("echo 89 > /sys/class/gpio/export");
|
|
|
- system("echo \"out\" > /sys/class/gpio/gpio89/direction");
|
|
|
- system("echo 1 > /sys/class/gpio/gpio89/value");
|
|
|
-
|
|
|
- system("echo 87 > /sys/class/gpio/export");
|
|
|
- system("echo \"out\" > /sys/class/gpio/gpio87/direction");
|
|
|
- system("echo 0 > /sys/class/gpio/gpio87/value");
|
|
|
-
|
|
|
- system("echo 88 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio88/direction");
|
|
|
-
|
|
|
- system("echo 86 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio86/direction");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- system("echo 111 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio111/direction");
|
|
|
-
|
|
|
- system("echo 114 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio114/direction");
|
|
|
-
|
|
|
- system("echo 113 > /sys/class/gpio/export");
|
|
|
- system("echo \"in\" > /sys/class/gpio/gpio113/direction");
|
|
|
-
|
|
|
- system("echo 110 > /sys/class/gpio/export");
|
|
|
- system("echo \"out\" > /sys/class/gpio/gpio110/direction");
|
|
|
- system("echo 0 > /sys/class/gpio/gpio110/value");
|
|
|
-
|
|
|
- system("echo 115 > /sys/class/gpio/export");
|
|
|
- system("echo \"out\" > /sys/class/gpio/gpio115/direction");
|
|
|
- system("echo 0 > /sys/class/gpio/gpio115/value");
|
|
|
-
|
|
|
- system("echo 112 > /sys/class/gpio/export");
|
|
|
- system("echo \"out\" > /sys/class/gpio/gpio112/direction");
|
|
|
- system("echo 0 > /sys/class/gpio/gpio112/value");
|
|
|
-
|
|
|
- system("echo 116 > /sys/class/gpio/export");
|
|
|
- system("echo \"out\" > /sys/class/gpio/gpio116/direction");
|
|
|
- system("echo 0 > /sys/class/gpio/gpio116/value");
|
|
|
-#ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]InitGPIO: Initial GPIO OK");
|
|
|
-#endif
|
|
|
-}
|
|
|
-
|
|
|
-int LoadSysConfigAndInfo(struct SysConfigData *ptr)
|
|
|
-{
|
|
|
- int fd,wrd;
|
|
|
- struct SysConfigData *buf;
|
|
|
- byte *PtrBuf;
|
|
|
- unsigned int ChkSum, ChkSumOrg;
|
|
|
-
|
|
|
- if ((buf = malloc(sizeof(struct SysConfigData))) == NULL)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo:malloc buffer NG,rebooting..");
|
|
|
- #endif
|
|
|
- if (ShmStatusCodeData != NULL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
|
|
|
- }
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- }
|
|
|
- memset(buf, 0, sizeof(struct SysConfigData));
|
|
|
-
|
|
|
- fd = open("/dev/mtdblock10", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- free(buf);
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo:open mtdblock10 NG,rebooting..");
|
|
|
- #endif
|
|
|
- if (ShmStatusCodeData != NULL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
|
|
|
- }
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- }
|
|
|
- wrd = read(fd, buf, sizeof(struct SysConfigData));
|
|
|
- close(fd);
|
|
|
- if (wrd != (sizeof(struct SysConfigData)))
|
|
|
- {
|
|
|
- free(buf);
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo: read SysConfigData data NG,rebooting..");
|
|
|
- #endif
|
|
|
- if (ShmStatusCodeData != NULL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
|
|
|
- }
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- }
|
|
|
- PtrBuf = (byte *) buf;
|
|
|
- ChkSum = 0;
|
|
|
- for (wrd = 0; wrd < (sizeof(struct SysConfigData) - 4); wrd++)
|
|
|
- {
|
|
|
- ChkSum += PtrBuf[wrd];
|
|
|
- }
|
|
|
- ChkSumOrg = buf->Checksum;
|
|
|
-
|
|
|
- if (ChkSum != ChkSumOrg)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo: Primary SysConfigData checksum NG, read backup");
|
|
|
- #endif
|
|
|
- fd = open("/dev/mtdblock11", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- free(buf);
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo: open mtdblock11 (backup) NG,rebooting..");
|
|
|
- #endif
|
|
|
- if (ShmStatusCodeData != NULL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
|
|
|
- }
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- }
|
|
|
- memset(buf, 0, sizeof(struct SysConfigData));
|
|
|
- wrd = read(fd, buf, sizeof(struct SysConfigData));
|
|
|
- close(fd);
|
|
|
- if (wrd != sizeof(struct SysConfigData))
|
|
|
- {
|
|
|
- free(buf);
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo: read backup SysConfigData data NG,rebooting..");
|
|
|
- #endif
|
|
|
- if (ShmStatusCodeData != NULL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
|
|
|
- }
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- }
|
|
|
- PtrBuf = (byte *) buf;
|
|
|
- ChkSum = 0;
|
|
|
- for (wrd = 0; wrd < (sizeof(struct SysConfigData) - 4); wrd++)
|
|
|
- {
|
|
|
- ChkSum += PtrBuf[wrd];
|
|
|
- }
|
|
|
- ChkSumOrg = buf->Checksum;
|
|
|
- if (ChkSum != ChkSumOrg)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo: backup SysConfigData checksum NG, read Factory default");
|
|
|
- #endif
|
|
|
- fd = open("/dev/mtdblock12", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- free(buf);
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo: open mtdblock12 (Factory default) NG,rebooting..");
|
|
|
- #endif
|
|
|
- if (ShmStatusCodeData != NULL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
|
|
|
- }
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- }
|
|
|
- memset(buf, 0, sizeof(struct SysConfigData));
|
|
|
- wrd = read(fd, buf, sizeof(struct SysConfigData));
|
|
|
- close(fd);
|
|
|
- if (wrd != sizeof(struct SysConfigData))
|
|
|
- {
|
|
|
- free(buf);
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo: read factory default SysConfigData data NG,rebooting..");
|
|
|
- #endif
|
|
|
- if (ShmStatusCodeData != NULL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
|
|
|
- }
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- }
|
|
|
- PtrBuf = (byte *) buf;
|
|
|
- ChkSum = 0;
|
|
|
- for (wrd = 0; wrd < (sizeof(struct SysConfigData) - 4); wrd++)
|
|
|
- {
|
|
|
- ChkSum += PtrBuf[wrd];
|
|
|
- }
|
|
|
- ChkSumOrg = buf->Checksum;
|
|
|
- if (ChkSum != ChkSumOrg)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo: factory default SysConfigData checksum NG, restore factory default");
|
|
|
- #endif
|
|
|
- goto DefaultShm;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- memcpy((struct SysConfigData *) ptr, (struct SysConfigData *) buf, sizeof(struct SysConfigData));
|
|
|
- free(buf);
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]LoadSysConfigAndInfo: Load SysConfigData OK");
|
|
|
- #endif
|
|
|
- return 1;
|
|
|
-
|
|
|
- DefaultShm: system("cd /root;./FactoryConfig");
|
|
|
- system("sync");
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- return FAIL;
|
|
|
-}
|
|
|
-
|
|
|
-void InitEthernet()
|
|
|
-{
|
|
|
- char tmpbuf[256];
|
|
|
-
|
|
|
- system("echo 1 > /sys/class/gpio/gpio110/value");
|
|
|
- sleep(2);
|
|
|
-
|
|
|
- return;
|
|
|
- memset(tmpbuf,0,256);
|
|
|
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
|
|
|
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
|
|
|
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
|
|
|
- system(tmpbuf);
|
|
|
- memset(tmpbuf,0,256);
|
|
|
- sprintf(tmpbuf,"route add default gw %s eth0 ",
|
|
|
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
|
|
|
- system(tmpbuf);
|
|
|
-
|
|
|
-
|
|
|
- memset(tmpbuf,0,256);
|
|
|
- sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up",
|
|
|
- ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
|
|
|
- ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
|
|
|
- system(tmpbuf);
|
|
|
-
|
|
|
-
|
|
|
- system("killall udhcpc");
|
|
|
- system("rm -rf /etc/resolv.conf");
|
|
|
- system("echo nameserver 8.8.8.8 > /etc/resolv.conf");
|
|
|
- system("echo nameserver 180.76.76.76 > /etc/resolv.conf");
|
|
|
- if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient==0)
|
|
|
- system("/sbin/udhcpc -i eth0 -s /root/simple.script > /dev/null &");
|
|
|
-
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]InitEthernet: Initial Ethernet OK");
|
|
|
- #endif
|
|
|
-}
|
|
|
-
|
|
|
-int InitialRfidPort()
|
|
|
-{
|
|
|
- int uartO2 = open(rfidPortName, O_RDWR);
|
|
|
- struct termios tios;
|
|
|
-
|
|
|
- if (uartO2 != FAIL)
|
|
|
- {
|
|
|
- ioctl (uartO2, TCGETS, &tios);
|
|
|
- tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
|
|
|
- tios.c_lflag = 0;
|
|
|
- tios.c_iflag = 0;
|
|
|
- tios.c_oflag = 0;
|
|
|
- tios.c_cc[VMIN] = 0;
|
|
|
- tios.c_cc[VTIME] = (unsigned char) 1;
|
|
|
- tios.c_lflag = 0;
|
|
|
- tcflush(uartO2, TCIFLUSH);
|
|
|
- ioctl(uartO2, TCSETS, &tios);
|
|
|
- }
|
|
|
-
|
|
|
- if (uartO2 < 0)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
|
|
|
- }
|
|
|
-
|
|
|
- return uartO2;
|
|
|
-}
|
|
|
-
|
|
|
-int Initialization()
|
|
|
-{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy = _OFFLINE_POLICY_FREE_CHARGING;
|
|
|
- sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
|
|
|
- sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
|
|
|
- sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
|
|
|
-
|
|
|
-
|
|
|
- ClearAuthorizedFlag();
|
|
|
-
|
|
|
- ClearDetectPluginFlag();
|
|
|
-
|
|
|
-
|
|
|
- rfidFd = InitialRfidPort();
|
|
|
-
|
|
|
- memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
|
|
|
- memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
|
|
|
- ShmPrimaryMcuData->SelfTest_Comp = NO;
|
|
|
- ShmRelayModuleData->SelfTest_Comp = NO;
|
|
|
- ShmFanModuleData->SelfTest_Comp = NO;
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
|
|
|
-
|
|
|
- for (byte count = 0; count < _gunCount; count++)
|
|
|
- {
|
|
|
- if (chargingInfo[count]->Type == _Type_Chademo)
|
|
|
- {
|
|
|
- ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
|
|
|
- }
|
|
|
- else if (chargingInfo[count]->Type == _Type_CCS)
|
|
|
- {
|
|
|
- if (ShmCcsData->CommProtocol == 0x01)
|
|
|
- {
|
|
|
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- #ifdef SystemLogMessage
|
|
|
- printf("Initialization OK \n");
|
|
|
- #endif
|
|
|
-
|
|
|
- return PASS;
|
|
|
-}
|
|
|
-
|
|
|
-void SelfTestRun()
|
|
|
-{
|
|
|
- bool evInitFlag = false;
|
|
|
-
|
|
|
- StartSystemTimeoutDet(Timeout_SelftestChk);
|
|
|
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
|
|
|
- while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
|
|
|
- {
|
|
|
- ChkPrimaryStatus();
|
|
|
- if (ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level == 2)
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (_gunCount > 0)
|
|
|
- {
|
|
|
- if (ShmPsuData->Work_Step == _NO_WORKING)
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- switch(ShmSysConfigAndInfo->SysInfo.SelfTestSeq)
|
|
|
- {
|
|
|
- case _STEST_VERSION:
|
|
|
- {
|
|
|
-
|
|
|
- if (strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
|
|
|
- ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
|
|
|
- {
|
|
|
-
|
|
|
- ShmRelayModuleData->SelfTest_Comp = YES;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
|
|
|
- ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
|
|
|
- {
|
|
|
-
|
|
|
- ShmFanModuleData->SelfTest_Comp = YES;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (strlen((char *)ShmPrimaryMcuData->version) != 0 ||
|
|
|
- ShmPrimaryMcuData->version[0] != '\0')
|
|
|
- {
|
|
|
-
|
|
|
- ShmPrimaryMcuData->SelfTest_Comp = YES;
|
|
|
- }
|
|
|
-
|
|
|
- if (!evInitFlag)
|
|
|
- {
|
|
|
- evInitFlag = YES;
|
|
|
- for (byte index = 0; index < _gunCount; index++)
|
|
|
- {
|
|
|
- if (chargingInfo[index]->Type == _Type_Chademo)
|
|
|
- {
|
|
|
- if (strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
|
|
|
- ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
|
|
|
- {
|
|
|
-
|
|
|
- ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- printf("chademo fw lose...... \n");
|
|
|
- evInitFlag = NO;
|
|
|
- }
|
|
|
- }
|
|
|
- else if (chargingInfo[index]->Type == _Type_CCS)
|
|
|
- {
|
|
|
- if (ShmCcsData->CommProtocol == 0x01)
|
|
|
- {
|
|
|
- if (strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
|
|
|
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
|
|
|
- {
|
|
|
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp = YES;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- printf("ccs fw lose \n");
|
|
|
- evInitFlag = NO;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (ShmRelayModuleData->SelfTest_Comp && ShmFanModuleData->SelfTest_Comp && ShmPrimaryMcuData->SelfTest_Comp && evInitFlag)
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case _STEST_AC_CONTACTOR:
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
|
|
|
- printf("Communication board pass. \n");
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case _STEST_PSU_DETECT:
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- if (ShmPsuData->Work_Step == _TEST_POWER_STEP || ShmPsuData->Work_Step == _TEST_COMPLETE)
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case _STEST_PSU_CAP:
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- if (ShmPsuData->Work_Step == _TEST_COMPLETE)
|
|
|
- {
|
|
|
- sleep(1);
|
|
|
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
|
|
|
- ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- break;
|
|
|
-
|
|
|
- usleep(100000);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-int SpawnTask()
|
|
|
-{
|
|
|
- system("/root/Module_EventLogging &");
|
|
|
- system("/root/Module_PrimaryComm &");
|
|
|
- system("/root/Module_EvComm &");
|
|
|
- system("/root/Module_LcmControl &");
|
|
|
- system("/root/Module_InternalComm &");
|
|
|
- system("/root/Module_PsuComm &");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return PASS;
|
|
|
-}
|
|
|
-
|
|
|
-int StoreUsrConfigData(struct SysConfigData *UsrData)
|
|
|
-{
|
|
|
- int fd,wrd;
|
|
|
- unsigned int i, Chk;
|
|
|
- byte *ptr;
|
|
|
-
|
|
|
- Chk = 0;
|
|
|
- ptr = (byte *) UsrData;
|
|
|
- for (i = 0; i < sizeof(struct SysConfigData) - 4; i++)
|
|
|
- {
|
|
|
- Chk += *(ptr + i);
|
|
|
- }
|
|
|
- UsrData->Checksum = Chk;
|
|
|
-
|
|
|
- fd = open("/dev/mtdblock10", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]StoreUsrConfigData: open /dev/mtdblock10 NG");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- wrd = write(fd, UsrData, sizeof(struct SysConfigData));
|
|
|
- close(fd);
|
|
|
- if (wrd != (sizeof(struct SysConfigData)))
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]StoreUsrConfigData: write /dev/mtdblock10 NG");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- fd = open("/dev/mtdblock11", O_RDWR);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]StoreUsrConfigData: open /dev/mtdblock11(backup) NG");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- wrd = write(fd, UsrData, sizeof(struct SysConfigData));
|
|
|
- close(fd);
|
|
|
- if (wrd != (sizeof(struct SysConfigData)))
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("[main]StoreUsrConfigData: write /dev/mtdblock11(backup) NG");
|
|
|
- #endif
|
|
|
- return 0;
|
|
|
- }
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-bool isEvBoardStopChargeFlag(byte gunIndex)
|
|
|
-{
|
|
|
- return chargingInfo[gunIndex]->StopChargeFlag;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-bool isEvGunLocked_chademo(byte gunIndex)
|
|
|
-{
|
|
|
- return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
|
|
|
-}
|
|
|
-
|
|
|
-bool isEvContactorWelding_chademo(byte gunIndex)
|
|
|
-{
|
|
|
- return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
|
|
|
-}
|
|
|
-
|
|
|
-bool isEvStopReq_chademo(byte gunIndex)
|
|
|
-{
|
|
|
- return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
|
|
|
-}
|
|
|
-
|
|
|
-bool isEvStopCharging_chademo(byte gunIndex)
|
|
|
-{
|
|
|
- if (isEvGunLocked_chademo(gunIndex) == NO)
|
|
|
- {
|
|
|
-
|
|
|
- printf("gun locked none. \n");
|
|
|
- return YES;
|
|
|
- }
|
|
|
-
|
|
|
- return NO;
|
|
|
-}
|
|
|
-
|
|
|
-byte isPrechargeStatus_chademo(byte gunIndex)
|
|
|
-{
|
|
|
- byte result = 0x00;
|
|
|
-
|
|
|
- result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-bool isEvGunLocked_ccs(byte gunIndex)
|
|
|
-{
|
|
|
- return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
|
|
|
-}
|
|
|
-
|
|
|
-byte isPrechargeStatus_ccs(byte gunIndex)
|
|
|
-{
|
|
|
- byte result = 0x00;
|
|
|
-
|
|
|
- if (ShmCcsData->CommProtocol == 0x01)
|
|
|
- {
|
|
|
- result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-bool isEvStopCharging_ccs(byte gunIndex)
|
|
|
-{
|
|
|
- if (isEvGunLocked_ccs(gunIndex) == NO)
|
|
|
- {
|
|
|
-
|
|
|
- printf("gun locked none. \n");
|
|
|
- return YES;
|
|
|
- }
|
|
|
-
|
|
|
- return NO;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void _AutoReturnTimeout()
|
|
|
-{
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
|
|
|
- {
|
|
|
- ClearDetectPluginFlag();
|
|
|
- }
|
|
|
-
|
|
|
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-void _SelfTestTimeout()
|
|
|
-{
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
|
|
|
- {
|
|
|
- for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
- {
|
|
|
- setChargerMode(gun_index, MODE_ALARM);
|
|
|
- }
|
|
|
- ShmPsuData->Work_Step = _NO_WORKING;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void _AuthorizedTimeout()
|
|
|
-{
|
|
|
- if(IsAuthorizingMode())
|
|
|
- {
|
|
|
- printf("_AuthorizedTimeout \n");
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
|
|
|
-
|
|
|
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
- ClearAuthorizedFlag();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void _DetectPlugInTimeout()
|
|
|
-{
|
|
|
- if(isDetectPlugin())
|
|
|
- {
|
|
|
- printf("_DetectPlugInTimeout \n");
|
|
|
- ClearDetectPluginFlag();
|
|
|
- }
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
|
|
|
-}
|
|
|
-
|
|
|
-void _DetectEvChargingEnableTimeout(byte gunIndex)
|
|
|
-{
|
|
|
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
|
|
|
- {
|
|
|
- if(!isEvGunLocked_chademo(gunIndex))
|
|
|
- {
|
|
|
- printf("_DetectEvChargingEnableTimeout (chademo) \n");
|
|
|
- ChargingTerminalProcess(gunIndex);
|
|
|
- _AutoReturnTimeout();
|
|
|
- }
|
|
|
- }
|
|
|
- else if (chargingInfo[gunIndex]->Type == _Type_CCS)
|
|
|
- {
|
|
|
- if(!isEvGunLocked_ccs(gunIndex))
|
|
|
- {
|
|
|
- printf("_DetectEvChargingEnableTimeout (ccs) \n");
|
|
|
- ChargingTerminalProcess(gunIndex);
|
|
|
- _AutoReturnTimeout();
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void _DetectEvseChargingEnableTimeout(byte gunIndex)
|
|
|
-{
|
|
|
- printf("_DetectEvseChargingEnableTimeout (GFD timeout) \n");
|
|
|
- if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
|
|
|
- {
|
|
|
- setChargerMode(gunIndex, MODE_IDLE);
|
|
|
- _AutoReturnTimeout();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void _PrepareTimeout(byte gunIndex)
|
|
|
-{
|
|
|
- printf("_PrechargeTimeout \n");
|
|
|
- setChargerMode(gunIndex, MODE_IDLE);
|
|
|
- _AutoReturnTimeout();
|
|
|
-}
|
|
|
-
|
|
|
-void _CompleteTimeout(byte gunIndex)
|
|
|
-{
|
|
|
- printf("_CompleteTimeout ====> %d \n", gunIndex);
|
|
|
- setChargerMode(gunIndex, MODE_IDLE);
|
|
|
-}
|
|
|
-
|
|
|
-void _CcsPrechargeTimeout(byte gunIndex)
|
|
|
-{
|
|
|
- printf("_CcsPrechargeTimeout \n");
|
|
|
- setChargerMode(gunIndex, MODE_IDLE);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-bool canStartCharging()
|
|
|
-{
|
|
|
- char buf2[16] = "";
|
|
|
- memset(buf2, 0, ARRAY_SIZE(buf2));
|
|
|
-
|
|
|
- for (byte index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++)
|
|
|
- {
|
|
|
- sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
|
|
|
- }
|
|
|
- sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
|
|
|
-
|
|
|
-
|
|
|
- if(strstr(buf2, "Accepted") != 0)
|
|
|
- return true;
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
-}
|
|
|
-
|
|
|
-void AuthorizingStart()
|
|
|
-{
|
|
|
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
|
|
|
-}
|
|
|
-
|
|
|
-void ClearAuthorizedFlag()
|
|
|
-{
|
|
|
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = NO;
|
|
|
- ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
|
|
|
-}
|
|
|
-
|
|
|
-bool isAuthorizedComplete()
|
|
|
-{
|
|
|
- if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == NO)
|
|
|
- return false;
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-bool IsAuthorizingMode()
|
|
|
-{
|
|
|
- if(ShmOCPP16Data->SpMsg.bits.AuthorizeReq == NO)
|
|
|
- return false;
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-byte GetCardNumber()
|
|
|
-{
|
|
|
- byte card_number[16];
|
|
|
-
|
|
|
- if(getRequestCardSN(rfidFd, 0, card_number))
|
|
|
- {
|
|
|
- printf("get card number \n");
|
|
|
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0)
|
|
|
- {
|
|
|
-
|
|
|
- byte len = card_number[0];
|
|
|
- char buf2[32] = "";
|
|
|
-
|
|
|
- memcpy(buf2, (card_number + 1), len);
|
|
|
- memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x0, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
|
|
|
- for (byte index = 0; index < len; index++)
|
|
|
- {
|
|
|
- sprintf((char *)ShmSysConfigAndInfo->SysConfig.UserId + (index * 2), "%02X", buf2[index]);
|
|
|
- }
|
|
|
-
|
|
|
- printf("card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
|
|
|
- return PASS;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return FAIL;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void ClearDetectPluginFlag()
|
|
|
-{
|
|
|
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
|
|
|
-}
|
|
|
-
|
|
|
-void DetectPluginStart()
|
|
|
-{
|
|
|
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
|
|
|
-}
|
|
|
-
|
|
|
-bool isDetectPlugin()
|
|
|
-{
|
|
|
- if(ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES)
|
|
|
- return YES;
|
|
|
-
|
|
|
- return NO;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void ChargingTerminalProcess(byte gunIndex)
|
|
|
-{
|
|
|
- setChargerMode(gunIndex, MODE_TERMINATING);
|
|
|
-}
|
|
|
-
|
|
|
-void StopChargingProcessByString(byte level, byte gun_index, char *string)
|
|
|
-{
|
|
|
- if (strlen((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index]) == 0 ||
|
|
|
- level > ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level)
|
|
|
- {
|
|
|
- memcpy(&ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index][0], string, 7);
|
|
|
- ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level = level;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void ReleaseChargingProcessByString(byte gun_index, char *code)
|
|
|
-{
|
|
|
- memcpy(&ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index][0], "", 7);
|
|
|
- ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level = 0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-void EmcOccureByString(byte index, char *code)
|
|
|
-{
|
|
|
- bool isStopCharger = false;
|
|
|
- if (strncmp(code, "012251", 6) == 0 || strncmp(code, "012252", 6) == 0 ||
|
|
|
- strncmp(code, "012237", 6) == 0 || strncmp(code, "012238", 6) == 0)
|
|
|
- {
|
|
|
- isStopCharger = true;
|
|
|
- }
|
|
|
-
|
|
|
- if (isStopCharger)
|
|
|
- {
|
|
|
- for (byte gun = 0; gun < _gunCount; gun++)
|
|
|
- {
|
|
|
- if ((chargingInfo[gun]->SystemStatus > S_IDLE && chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
|
|
|
- (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
|
|
|
- {
|
|
|
- ChargingTerminalProcess(gun);
|
|
|
- }
|
|
|
-
|
|
|
- StopChargingProcessByString(2, gun, code);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
|
|
|
- (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
|
|
|
- {
|
|
|
- ChargingTerminalProcess(index);
|
|
|
- }
|
|
|
-
|
|
|
- StopChargingProcessByString(2, index, code);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void ReleaseEmsOccureByString(byte index, char *code)
|
|
|
-{
|
|
|
- bool isReleaseCharger = false;
|
|
|
- bool isTrigger = false;
|
|
|
- if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
|
|
|
- {
|
|
|
- isTrigger = true;
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
|
|
|
- isReleaseCharger = true;
|
|
|
- }
|
|
|
- else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
|
|
|
- {
|
|
|
- isTrigger = true;
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
|
|
|
- isReleaseCharger = true;
|
|
|
- }
|
|
|
- else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
|
|
|
- {
|
|
|
- isTrigger = true;
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
|
|
|
- isReleaseCharger = true;
|
|
|
- }
|
|
|
- else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
|
|
|
- {
|
|
|
- isTrigger = true;
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
|
|
|
- isReleaseCharger = true;
|
|
|
- }
|
|
|
- else if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
|
|
|
- {
|
|
|
- isTrigger = true;
|
|
|
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
|
|
|
- }
|
|
|
-
|
|
|
- if (isTrigger)
|
|
|
- {
|
|
|
- if (isReleaseCharger)
|
|
|
- {
|
|
|
- for (byte gun = 0; gun < _gunCount; gun++)
|
|
|
- {
|
|
|
- ReleaseChargingProcessByString(gun, code);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ReleaseChargingProcessByString(index, code);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-bool leftBtnPush = false;
|
|
|
-bool rightBtnPush = false;
|
|
|
-
|
|
|
-void ChkPrimaryStatus()
|
|
|
-{
|
|
|
- if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
|
|
|
- EmcOccureByString(0, "012251");
|
|
|
- }
|
|
|
- else
|
|
|
- ReleaseEmsOccureByString(0, "012251");
|
|
|
-
|
|
|
- if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
|
|
|
- EmcOccureByString(0, "012238");
|
|
|
- }
|
|
|
- else
|
|
|
- ReleaseEmsOccureByString(0, "012238");
|
|
|
-
|
|
|
- if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
|
|
|
- EmcOccureByString(0, "012237");
|
|
|
- }
|
|
|
- else
|
|
|
- ReleaseEmsOccureByString(0, "012237");
|
|
|
-
|
|
|
- if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
|
|
|
- EmcOccureByString(0, "012252");
|
|
|
- }
|
|
|
- else
|
|
|
- ReleaseEmsOccureByString(0, "012252");
|
|
|
-
|
|
|
- if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush)
|
|
|
- {
|
|
|
- if(!leftBtnPush)
|
|
|
- {
|
|
|
- printf("left btn down............................... \n");
|
|
|
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
|
|
|
- switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
|
|
|
- {
|
|
|
- case S_IDLE:
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_CHARGING:
|
|
|
- {
|
|
|
-
|
|
|
- printf("To Stop = %d --------- \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
|
|
|
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = 9;
|
|
|
-
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_COMPLETE:
|
|
|
- {
|
|
|
-
|
|
|
- printf("Back to IDLE = %d --------- \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
|
|
|
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = 1;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- leftBtnPush = true;
|
|
|
-
|
|
|
- }
|
|
|
- else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE)
|
|
|
- {
|
|
|
- if(leftBtnPush)
|
|
|
- printf("left btn up............................... \n");
|
|
|
- leftBtnPush = false;
|
|
|
- }
|
|
|
-
|
|
|
- if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush)
|
|
|
- {
|
|
|
- if(!rightBtnPush)
|
|
|
- {
|
|
|
- printf("right btn down............................... \n");
|
|
|
- if (_gunCount > 1)
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 1;
|
|
|
- switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
|
|
|
- {
|
|
|
- case S_IDLE:
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_CHARGING:
|
|
|
- {
|
|
|
-
|
|
|
- printf("To Stop = %d --------- \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
|
|
|
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = 9;
|
|
|
-
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_COMPLETE:
|
|
|
- {
|
|
|
-
|
|
|
- printf("Back to IDLE = %d --------- \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
|
|
|
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = 1;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- rightBtnPush = true;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE)
|
|
|
- {
|
|
|
- if(rightBtnPush)
|
|
|
- printf("right btn up............................... \n");
|
|
|
- rightBtnPush = false;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void CheckErrorOccurStatus(byte index)
|
|
|
-{
|
|
|
-
|
|
|
- if (chargingInfo[index]->Type == _Type_Chademo)
|
|
|
- {
|
|
|
- if (ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
|
|
|
- EmcOccureByString(index, "023730");
|
|
|
- else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES)
|
|
|
- EmcOccureByString(index, "011012");
|
|
|
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
|
|
|
- EmcOccureByString(index, "012234");
|
|
|
- }
|
|
|
- else if (chargingInfo[index]->Type == _Type_CCS)
|
|
|
- {
|
|
|
- if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES)
|
|
|
- EmcOccureByString(index, "011014");
|
|
|
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
|
|
|
- EmcOccureByString(index, "012235");
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-int gpio_get_value(unsigned int gpio, unsigned int *value)
|
|
|
-{
|
|
|
- int fd;
|
|
|
- char buf[MAX_BUF];
|
|
|
- char ch;
|
|
|
-
|
|
|
- snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
|
|
|
-
|
|
|
- fd = open(buf, O_RDONLY);
|
|
|
- if (fd < 0) {
|
|
|
- perror("gpio/get-value");
|
|
|
- return fd;
|
|
|
- }
|
|
|
-
|
|
|
- read(fd, &ch, 1);
|
|
|
-
|
|
|
- if (ch != '0') {
|
|
|
- *value = 1;
|
|
|
- } else {
|
|
|
- *value = 0;
|
|
|
- }
|
|
|
-
|
|
|
- close(fd);
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-void CheckGunTypeFromHw()
|
|
|
-{
|
|
|
- int pinIn[4] = { 22, 23, 44, 45 };
|
|
|
- unsigned int gpioValue = 0;
|
|
|
-
|
|
|
- for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
|
|
|
- gpio_get_value(pinIn[i], &gpioValue);
|
|
|
- {
|
|
|
- switch (pinIn[i])
|
|
|
- {
|
|
|
- case 22:
|
|
|
- bd1_1_status = gpioValue;
|
|
|
- break;
|
|
|
- case 23:
|
|
|
- bd1_2_status = gpioValue;
|
|
|
- break;
|
|
|
- case 44:
|
|
|
- bd0_1_status = gpioValue;
|
|
|
- break;
|
|
|
- case 45:
|
|
|
- bd0_2_status = gpioValue;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void CheckGpioInStatus()
|
|
|
-{
|
|
|
- int pinIn[2] = { 27, 47 };
|
|
|
- unsigned int gpioValue = 0;
|
|
|
-
|
|
|
- for (int i = 0; i < ARRAY_SIZE(pinIn); i++)
|
|
|
- {
|
|
|
- gpio_get_value(pinIn[i], &gpioValue);
|
|
|
- if (gpioValue == 0x01)
|
|
|
- {
|
|
|
- switch(pinIn[i])
|
|
|
- {
|
|
|
-
|
|
|
- case 27:
|
|
|
- {
|
|
|
- for(int i = 0; i < _gunCount; i++)
|
|
|
- {
|
|
|
- if (chargingInfo[i]->slotsIndex == 1)
|
|
|
- {
|
|
|
- if (chargingInfo[i]->Type == _Type_Chademo)
|
|
|
- EmcOccureByString(i, "023730");
|
|
|
- else if (chargingInfo[i]->Type == _Type_CCS)
|
|
|
- EmcOccureByString(i, "013627");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case 47:
|
|
|
- {
|
|
|
- for(int i = 0; i < _gunCount; i++)
|
|
|
- {
|
|
|
- if (chargingInfo[i]->slotsIndex == 3)
|
|
|
- {
|
|
|
- if (chargingInfo[i]->Type == _Type_Chademo)
|
|
|
- EmcOccureByString(i, "023730");
|
|
|
- else if (chargingInfo[i]->Type == _Type_CCS)
|
|
|
- EmcOccureByString(i, "013627");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- switch (pinIn[i])
|
|
|
- {
|
|
|
-
|
|
|
- case 27:
|
|
|
- {
|
|
|
- for(int i = 0; i < _gunCount; i++)
|
|
|
- {
|
|
|
- if (chargingInfo[i]->slotsIndex == 1)
|
|
|
- {
|
|
|
- if (chargingInfo[i]->Type == _Type_Chademo)
|
|
|
- ReleaseEmsOccureByString(i, "023730");
|
|
|
- else if (chargingInfo[i]->Type == _Type_CCS)
|
|
|
- ReleaseEmsOccureByString(i, "013627");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case 47:
|
|
|
- {
|
|
|
-
|
|
|
- for (int i = 0; i < _gunCount; i++)
|
|
|
- {
|
|
|
- if (chargingInfo[i]->slotsIndex == 3)
|
|
|
- {
|
|
|
- if (chargingInfo[i]->Type == _Type_Chademo)
|
|
|
- ReleaseEmsOccureByString(i, "023730");
|
|
|
- else if (chargingInfo[i]->Type == _Type_CCS)
|
|
|
- ReleaseEmsOccureByString(i, "013627");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
|
|
|
-{
|
|
|
- return ( _byte & mask_table[_bit] ) != 0x00;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
|
|
|
-{
|
|
|
- if(value == 1)
|
|
|
- *_byte |= (1 << _bit);
|
|
|
- else if (value == 0)
|
|
|
- *_byte ^= (1 << _bit);
|
|
|
-}
|
|
|
-
|
|
|
-void UserScanFunction()
|
|
|
-{
|
|
|
- bool idleReq = false;
|
|
|
- unsigned char stopReq = 255;
|
|
|
-
|
|
|
-
|
|
|
- if(!IsAuthorizingMode())
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- for (byte i = 0; i < _gunCount; i++)
|
|
|
- {
|
|
|
-
|
|
|
- if (chargingInfo[i]->SystemStatus == S_CHARGING)
|
|
|
- {
|
|
|
- stopReq = i;
|
|
|
- }
|
|
|
- else if (chargingInfo[i]->SystemStatus == S_IDLE)
|
|
|
- {
|
|
|
- idleReq = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (idleReq || stopReq < _gunCount)
|
|
|
- {
|
|
|
-
|
|
|
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0)
|
|
|
- {
|
|
|
- if (stopReq < _gunCount)
|
|
|
- {
|
|
|
- char value[32];
|
|
|
-
|
|
|
- memcpy(value, (unsigned char *)chargingInfo[stopReq]->CardNumber, ARRAY_SIZE(chargingInfo[stopReq]->CardNumber));
|
|
|
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
|
|
|
- {
|
|
|
- ChargingTerminalProcess(stopReq);
|
|
|
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (idleReq)
|
|
|
- {
|
|
|
-
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
|
|
|
-
|
|
|
- AuthorizingStart();
|
|
|
-
|
|
|
- StartSystemTimeoutDet(Timeout_Authorizing);
|
|
|
- autoReturnTimeoutFlag = NO;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- if (isAuthorizedComplete() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
|
|
|
- {
|
|
|
- StopSystemTimeoutDet();
|
|
|
-
|
|
|
- if(canStartCharging() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
|
|
|
- {
|
|
|
-
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
|
|
|
-
|
|
|
- DetectPluginStart();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
|
|
|
- }
|
|
|
- ClearAuthorizedFlag();
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-unsigned char isModeChange(unsigned char gun_index)
|
|
|
-{
|
|
|
- unsigned char result = NO;
|
|
|
-
|
|
|
- if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
|
|
|
- {
|
|
|
- result = YES;
|
|
|
- chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-void ScannerCardProcess()
|
|
|
-{
|
|
|
- if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level == 0)
|
|
|
- {
|
|
|
- isCardScan = true;
|
|
|
-
|
|
|
- UserScanFunction();
|
|
|
- }
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL)
|
|
|
- {
|
|
|
- StartSystemTimeoutDet(Timeout_VerifyFail);
|
|
|
- isCardScan = false;
|
|
|
- }
|
|
|
- else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
|
|
|
- {
|
|
|
- StartSystemTimeoutDet(Timeout_VerifyComp);
|
|
|
- }
|
|
|
- else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
|
|
|
- {
|
|
|
- StartSystemTimeoutDet(Timeout_WaitPlug);
|
|
|
- }
|
|
|
- else
|
|
|
- isCardScan = false;
|
|
|
-}
|
|
|
-
|
|
|
-void AddGunInfoByConnector(byte typeValue, byte slots)
|
|
|
-{
|
|
|
- switch (typeValue)
|
|
|
- {
|
|
|
- case '0':
|
|
|
- break;
|
|
|
- case '1':
|
|
|
- break;
|
|
|
- case '2':
|
|
|
- break;
|
|
|
- case '3':
|
|
|
- break;
|
|
|
- case '4':
|
|
|
- break;
|
|
|
- case '5':
|
|
|
- break;
|
|
|
- case '6':
|
|
|
- break;
|
|
|
- case 'J':
|
|
|
- {
|
|
|
- if (CHAdeMO_QUANTITY > _chademoIndex)
|
|
|
- {
|
|
|
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
|
|
|
-
|
|
|
- chargingInfo[_gunIndex]->Index = _gunIndex;
|
|
|
- chargingInfo[_gunIndex]->slotsIndex = slots;
|
|
|
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
|
|
|
- chargingInfo[_gunIndex]->Type = _Type_Chademo;
|
|
|
- chargingInfo[_gunIndex]->type_index = _chademoIndex;
|
|
|
- _chademoIndex++;
|
|
|
- _gunIndex++;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case 'U':
|
|
|
- break;
|
|
|
- case 'E':
|
|
|
- {
|
|
|
- if (CCS_QUANTITY > _ccsIndex)
|
|
|
- {
|
|
|
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
|
|
|
-
|
|
|
- chargingInfo[_gunIndex]->Index = _gunIndex;
|
|
|
- chargingInfo[_gunIndex]->slotsIndex = slots;
|
|
|
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
|
|
|
- chargingInfo[_gunIndex]->Type = _Type_CCS;
|
|
|
- chargingInfo[_gunIndex]->type_index = _ccsIndex;
|
|
|
-
|
|
|
- ShmCcsData->CommProtocol = 0x01;
|
|
|
- _ccsIndex++;
|
|
|
- _gunIndex++;
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case 'G':
|
|
|
- break;
|
|
|
- case 'D':
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-bool CheckConnectorTypeStatus()
|
|
|
-{
|
|
|
- bool result = true;
|
|
|
-
|
|
|
- printf("bd0_1_status = %d, bd0_2_status = %d, bd1_1_status = %d, bd1_2_status = %d \n",
|
|
|
- bd0_1_status, bd0_2_status, bd1_1_status, bd1_2_status);
|
|
|
- if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9)
|
|
|
- {
|
|
|
- byte slots = 1;
|
|
|
- for (byte typeIndex = 7; typeIndex <= 9; typeIndex++)
|
|
|
- {
|
|
|
- AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots);
|
|
|
- slots++;
|
|
|
- }
|
|
|
-
|
|
|
- _gunCount = _gunIndex;
|
|
|
- printf("_gunCount = %d \n", _gunCount);
|
|
|
- if (_gunCount == 0)
|
|
|
- result = false;
|
|
|
-
|
|
|
-
|
|
|
- for (byte gunIndex = 0; gunIndex < _gunCount; gunIndex++)
|
|
|
- {
|
|
|
- if (bd0_1_status == 0 && bd0_2_status == 1)
|
|
|
- {
|
|
|
-
|
|
|
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
|
|
|
- {
|
|
|
- chargingInfo[gunIndex]->Evboard_id = 0x01;
|
|
|
- }
|
|
|
- }
|
|
|
- else if (bd0_1_status == 1 && bd0_2_status == 0)
|
|
|
- {
|
|
|
-
|
|
|
- if (chargingInfo[gunIndex]->Type == _Type_CCS)
|
|
|
- {
|
|
|
- chargingInfo[gunIndex]->Evboard_id = 0x01;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (bd1_1_status == 0 && bd1_2_status == 1)
|
|
|
- {
|
|
|
-
|
|
|
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
|
|
|
- {
|
|
|
- chargingInfo[gunIndex]->Evboard_id = 0x02;
|
|
|
- }
|
|
|
-
|
|
|
- if (_gunCount == 1)
|
|
|
- chargingInfo[gunIndex]->Evboard_id = 0x01;
|
|
|
- }
|
|
|
- else if (bd1_1_status == 1 && bd1_2_status == 0)
|
|
|
- {
|
|
|
-
|
|
|
- if (chargingInfo[gunIndex]->Type == _Type_CCS)
|
|
|
- {
|
|
|
- chargingInfo[gunIndex]->Evboard_id = 0x02;
|
|
|
- }
|
|
|
-
|
|
|
- if (_gunCount == 1)
|
|
|
- chargingInfo[gunIndex]->Evboard_id = 0x01;
|
|
|
- }
|
|
|
-
|
|
|
- printf("index = %d, Type = %d, Evboard_id = %d \n", gunIndex, chargingInfo[gunIndex]->Type, chargingInfo[gunIndex]->Evboard_id);
|
|
|
- if (chargingInfo[gunIndex]->Evboard_id == 0x00)
|
|
|
- result = false;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- result = false;
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-void KillTask()
|
|
|
-{
|
|
|
- ChangeLcmByIndex(_LCM_FIX);
|
|
|
- system("killall Module_EventLogging");
|
|
|
- system("killall Module_PrimaryComm");
|
|
|
- system("killall Module_EvComm");
|
|
|
- system("killall Module_LcmControl");
|
|
|
- system("killall Module_InternalComm");
|
|
|
- system("killall Module_PsuComm");
|
|
|
-}
|
|
|
-
|
|
|
-char CheckUpdateProcess()
|
|
|
-{
|
|
|
- DIR *d;
|
|
|
- struct dirent *dir;
|
|
|
- d = opendir("/mnt/");
|
|
|
-
|
|
|
- if (d)
|
|
|
- {
|
|
|
- long int MaxLen=48*1024*1024, ImageLen = 0;
|
|
|
- while ((dir = readdir(d)) != NULL)
|
|
|
- {
|
|
|
- char *new_str;
|
|
|
- new_str = malloc(strlen("/mnt/")+strlen(dir->d_name)+1);
|
|
|
- new_str[0] = '\0';
|
|
|
- strcat(new_str, "/mnt/");
|
|
|
- strcat(new_str, dir->d_name);
|
|
|
- int fd = open(new_str, O_RDONLY);
|
|
|
- if (fd < 0)
|
|
|
- {
|
|
|
- return FAIL;
|
|
|
- }
|
|
|
-
|
|
|
- unsigned char *ptr = malloc(MaxLen);
|
|
|
- memset(ptr, 0xFF, MaxLen);
|
|
|
-
|
|
|
- ImageLen = read(fd, ptr, MaxLen);
|
|
|
-
|
|
|
- if (ImageLen > 20)
|
|
|
- {
|
|
|
- unsigned int Type = (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19]));
|
|
|
- printf("Typed...%x \r\n", Type);
|
|
|
-
|
|
|
- switch (Type)
|
|
|
- {
|
|
|
- case 0x10000001:
|
|
|
- case 0x10000002:
|
|
|
- case 0x10000003:
|
|
|
- case 0x10000004:
|
|
|
- case 0x10000005:
|
|
|
- {
|
|
|
- if (Upgrade_Flash(Type, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
|
|
|
- return PASS;
|
|
|
- else
|
|
|
- return FAIL;
|
|
|
- }
|
|
|
- break;
|
|
|
- case 0x10000006:
|
|
|
- case 0x1000000D:
|
|
|
- case 0x1000000E:
|
|
|
- {
|
|
|
-
|
|
|
- byte target = 0x00;
|
|
|
-
|
|
|
- if (Type == 0x10000006)
|
|
|
- target = UPGRADE_PRI;
|
|
|
- else if (Type == 0x1000000D)
|
|
|
- target = UPGRADE_RB;
|
|
|
- else if (Type == 0x1000000E)
|
|
|
- target = UPGRADE_FAN;
|
|
|
-
|
|
|
- int fd = InitComPort(target);
|
|
|
-
|
|
|
- if (Upgrade_UART(fd, Type, target, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
|
|
|
- return PASS;
|
|
|
- else
|
|
|
- return FAIL;
|
|
|
-
|
|
|
- close(fd);
|
|
|
- }
|
|
|
- break;
|
|
|
- case 0x10000007:
|
|
|
- case 0x10000008:
|
|
|
- case 0x10000009:
|
|
|
- case 0x1000000A:
|
|
|
- case 0x1000000B:
|
|
|
- case 0x1000000C:
|
|
|
- {
|
|
|
-
|
|
|
- for(byte index = 0; index < _gunCount; index++)
|
|
|
- {
|
|
|
- if (chargingInfo[index]->Type == _Type_Chademo)
|
|
|
- {
|
|
|
- int CanFd = InitCanBus();
|
|
|
- if (CanFd > 0)
|
|
|
- {
|
|
|
- if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
|
|
|
- {
|
|
|
- printf("Upgrad OK. \n");
|
|
|
- return PASS;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- printf("Upgrad Fail. \n");
|
|
|
- return FAIL;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- printf("Upgrad FD fail. \n");
|
|
|
- return FAIL;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- free(new_str);
|
|
|
- free(ptr);
|
|
|
- }
|
|
|
- }
|
|
|
- free(dir);
|
|
|
- closedir(d);
|
|
|
- return FAIL;
|
|
|
-}
|
|
|
-
|
|
|
-void CreateRfidFork()
|
|
|
-{
|
|
|
- pid_t rfidRecPid;
|
|
|
-
|
|
|
- rfidRecPid = fork();
|
|
|
- if (rfidRecPid == 0)
|
|
|
- {
|
|
|
- while(true)
|
|
|
- {
|
|
|
-
|
|
|
- GetCardNumber();
|
|
|
- usleep(100000);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void StartSystemTimeoutDet(unsigned char flag)
|
|
|
-{
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag)
|
|
|
- {
|
|
|
- gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
|
|
|
- }
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
|
|
|
-}
|
|
|
-
|
|
|
-void StopSystemTimeoutDet()
|
|
|
-{
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
|
|
|
-}
|
|
|
-
|
|
|
-void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
|
|
|
-{
|
|
|
- if (gunIndex < _gunCount)
|
|
|
- {
|
|
|
- if (chargingInfo[gunIndex]->TimeoutFlag != flag)
|
|
|
- {
|
|
|
- gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
|
|
|
- }
|
|
|
- chargingInfo[gunIndex]->TimeoutFlag = flag;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void StopGunInfoTimeoutDet(unsigned char gunIndex)
|
|
|
-{
|
|
|
- if (gunIndex < _gunCount)
|
|
|
- {
|
|
|
- chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void CreateTimeoutFork()
|
|
|
-{
|
|
|
- pid_t timeoutPid;
|
|
|
-
|
|
|
- timeoutPid = fork();
|
|
|
- if (timeoutPid == 0)
|
|
|
- {
|
|
|
- while(true)
|
|
|
- {
|
|
|
-
|
|
|
- switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
|
|
|
- {
|
|
|
- case Timeout_SelftestChk:
|
|
|
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 60000000)
|
|
|
- {
|
|
|
- _SelfTestTimeout();
|
|
|
- StopSystemTimeoutDet();
|
|
|
- }
|
|
|
- break;
|
|
|
- case Timeout_Authorizing:
|
|
|
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 60000000)
|
|
|
- {
|
|
|
- _AuthorizedTimeout();
|
|
|
- StopSystemTimeoutDet();
|
|
|
- }
|
|
|
- break;
|
|
|
- case Timeout_VerifyFail:
|
|
|
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 3000000)
|
|
|
- {
|
|
|
- _AutoReturnTimeout();
|
|
|
- StopSystemTimeoutDet();
|
|
|
- }
|
|
|
- break;
|
|
|
- case Timeout_VerifyComp:
|
|
|
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 3000000)
|
|
|
- {
|
|
|
- _AutoReturnTimeout();
|
|
|
- StopSystemTimeoutDet();
|
|
|
- }
|
|
|
- break;
|
|
|
- case Timeout_WaitPlug:
|
|
|
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 40000000)
|
|
|
- {
|
|
|
- _DetectPlugInTimeout();
|
|
|
- StopSystemTimeoutDet();
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
- {
|
|
|
- switch(chargingInfo[gun_index]->TimeoutFlag)
|
|
|
- {
|
|
|
- case Timeout_Preparing:
|
|
|
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 30000000)
|
|
|
- {
|
|
|
- _PrepareTimeout(gun_index);
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- }
|
|
|
- break;
|
|
|
- case Timeout_EvChargingDet:
|
|
|
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 120000000)
|
|
|
- {
|
|
|
- _DetectEvChargingEnableTimeout(gun_index);
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- }
|
|
|
- break;
|
|
|
- case Timeout_EvseChargingDet:
|
|
|
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 60000000)
|
|
|
- {
|
|
|
- _DetectEvseChargingEnableTimeout(gun_index);
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- }
|
|
|
- break;
|
|
|
- case Timeout_WaitforCompleteDet:
|
|
|
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
|
|
|
- {
|
|
|
- _CompleteTimeout(gun_index);
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- }
|
|
|
- break;
|
|
|
- case Timeout_ForCcsPrechargeDet:
|
|
|
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 60000000)
|
|
|
- {
|
|
|
- _CcsPrechargeTimeout(gun_index);
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- usleep(100000);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-int main(void)
|
|
|
-{
|
|
|
- InitGPIO();
|
|
|
- InitEthernet();
|
|
|
- sleep(1);
|
|
|
- system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
|
|
|
- sleep(1);
|
|
|
- system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if(CreateShareMemory() == 0)
|
|
|
- {
|
|
|
- #ifdef SystemLogMessage
|
|
|
- DEBUG_ERROR_MSG("CreatShareMemory NG \n");
|
|
|
- #endif
|
|
|
- if(ShmStatusCodeData!=NULL)
|
|
|
- {
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
|
|
|
- }
|
|
|
- return 0;
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- }
|
|
|
-
|
|
|
- printf("\n");
|
|
|
- printf("CheckGunTypeFromHw....... \n");
|
|
|
- CheckGunTypeFromHw();
|
|
|
- char *moduleName = "DSYE601E00T2PH";
|
|
|
- memcpy(&ShmSysConfigAndInfo->SysConfig.ModelName, moduleName, strlen(moduleName));
|
|
|
-
|
|
|
- if (!CheckConnectorTypeStatus())
|
|
|
- {
|
|
|
-
|
|
|
- printf("Module Name & HW info none match. \n");
|
|
|
- DEBUG_ERROR_MSG("Module Name & HW info none match. \n");
|
|
|
- sleep(5);
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- printf("Module Name & HW info correct. Initialize.......\n");
|
|
|
- Initialization();
|
|
|
- printf("Spawn all Task. \n");
|
|
|
- SpawnTask();
|
|
|
-
|
|
|
- ChangeLcmByIndex(_LCM_INIT);
|
|
|
- CreateTimeoutFork();
|
|
|
- printf("Self test. \n");
|
|
|
- SelfTestRun();
|
|
|
- StopSystemTimeoutDet();
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL)
|
|
|
- {
|
|
|
- for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
- {
|
|
|
- setChargerMode(gun_index, MODE_ALARM);
|
|
|
- }
|
|
|
- ChangeLcmByIndex(_LCM_FIX);
|
|
|
- return FAIL;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
- {
|
|
|
- setChargerMode(gun_index, MODE_IDLE);
|
|
|
- }
|
|
|
- }
|
|
|
- ChangeLcmByIndex(_LCM_IDLE);
|
|
|
- sleep(1);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- CreateRfidFork();
|
|
|
-
|
|
|
- printf("Main Loop. \n");
|
|
|
- for (;;)
|
|
|
- {
|
|
|
- ChkPrimaryStatus();
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_IDLE)
|
|
|
- {
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
|
|
|
- {
|
|
|
- KillTask();
|
|
|
- if (CheckUpdateProcess() == PASS)
|
|
|
- {
|
|
|
- printf("update complete. \n");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- printf("update fail. \n");
|
|
|
- }
|
|
|
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
|
|
|
- sleep(5);
|
|
|
- system("reboot -f");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- ScannerCardProcess();
|
|
|
-
|
|
|
- for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
- {
|
|
|
- CheckGpioInStatus();
|
|
|
- CheckErrorOccurStatus(gun_index);
|
|
|
-
|
|
|
- switch(chargingInfo[gun_index]->SystemStatus)
|
|
|
- {
|
|
|
- case S_IDLE:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf("S_IDLE================================== %x \n", gun_index);
|
|
|
- chargingInfo[gun_index]->RemainChargingDuration = 0;
|
|
|
- chargingInfo[gun_index]->PresentChargedEnergy = 0;
|
|
|
- }
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level == 2)
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
|
|
|
- ClearDetectPluginFlag();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- if(isDetectPlugin())
|
|
|
- {
|
|
|
-
|
|
|
- if (chargingInfo[gun_index]->ConnectorPlugIn == YES)
|
|
|
- {
|
|
|
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = gun_index;
|
|
|
- strcpy((char *)chargingInfo[gun_index]->CardNumber, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
|
|
|
-
|
|
|
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
|
|
|
- ClearDetectPluginFlag();
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
|
|
|
- }
|
|
|
- else if (!isCardScan)
|
|
|
- {
|
|
|
-
|
|
|
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_REASSIGN_CHECK:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf("S_REASSIGN_CHECK================================== %x \n", gun_index);
|
|
|
- StopSystemTimeoutDet();
|
|
|
- }
|
|
|
-
|
|
|
- bool isRessign = false;
|
|
|
- if (_gunCount > 1)
|
|
|
- {
|
|
|
- for (byte index = 0; index < _gunCount; index++)
|
|
|
- {
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
|
|
|
- chargingInfo[index]->SystemStatus >= S_PREPARNING)
|
|
|
- {
|
|
|
- printf("=============Smart Charging============= Step 1 \n");
|
|
|
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE;
|
|
|
- isRessign = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (isRessign)
|
|
|
- setChargerMode(gun_index, MODE_REASSIGN);
|
|
|
- else
|
|
|
- setChargerMode(gun_index, MODE_PRECHARGE);
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_REASSIGN:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf("S_REASSIGN================================== %x \n", gun_index);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
|
|
|
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_MAIN)
|
|
|
- setChargerMode(gun_index, MODE_PRECHARGE);
|
|
|
- else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY &&
|
|
|
- ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
|
|
|
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_MAIN;
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_PREPARNING:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf("S_PREPARNING================================== %x \n", gun_index);
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
|
|
|
- }
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
|
|
|
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (((ShmPsuData->SystemPresentPsuQuantity > 0 &&
|
|
|
- ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity > 0 &&
|
|
|
- ShmPsuData->PsuGroup[gun_index].GroupAvailablePower > 10) &&
|
|
|
- chargingInfo[gun_index]->AvailableChargingPower > 10))
|
|
|
- {
|
|
|
- setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
|
|
|
- }
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_PREPARING_FOR_EV:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf("S_PREPARING_FOR_EV================================== %x \n", gun_index);
|
|
|
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
|
|
|
- }
|
|
|
-
|
|
|
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
|
|
|
- {
|
|
|
-
|
|
|
- if (isEvGunLocked_chademo(gun_index) == YES)
|
|
|
- {
|
|
|
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
|
|
|
- }
|
|
|
- }
|
|
|
- else if (chargingInfo[gun_index]->Type == _Type_CCS)
|
|
|
- {
|
|
|
-
|
|
|
- if (isEvGunLocked_ccs(gun_index) == YES)
|
|
|
- {
|
|
|
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (isEvBoardStopChargeFlag(gun_index) == YES)
|
|
|
- {
|
|
|
-
|
|
|
- ChargingTerminalProcess(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_PREPARING_FOR_EVSE:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf("S_PREPARING_FOR_EVSE================================== %x \n", gun_index);
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
|
|
|
- }
|
|
|
-
|
|
|
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
|
|
|
- {
|
|
|
-
|
|
|
- if (isPrechargeStatus_chademo(gun_index) > 5 && isPrechargeStatus_chademo(gun_index) < 8)
|
|
|
- {
|
|
|
-
|
|
|
- setChargerMode(gun_index, MODE_CHARGING);
|
|
|
- }
|
|
|
- }
|
|
|
- else if (chargingInfo[gun_index]->Type == _Type_CCS)
|
|
|
- {
|
|
|
-
|
|
|
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS)
|
|
|
- {
|
|
|
- setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (isEvBoardStopChargeFlag(gun_index) == YES)
|
|
|
- {
|
|
|
-
|
|
|
- ChargingTerminalProcess(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_CHARGING:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf("S_CHARGING================================== %x \n", gun_index);
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- ftime(&startChargingTime[gun_index]);
|
|
|
- }
|
|
|
-
|
|
|
- ftime(&endChargingTime[gun_index]);
|
|
|
- chargingInfo[gun_index]->RemainChargingDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
|
|
|
-
|
|
|
- if (isEvBoardStopChargeFlag(gun_index) == YES ||
|
|
|
- chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
|
|
|
- {
|
|
|
-
|
|
|
- ChargingTerminalProcess(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_TERMINATING:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf ("terminating......................... %x \n", gun_index);
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
|
|
|
- {
|
|
|
-
|
|
|
- if (isEvStopCharging_chademo(gun_index) == YES)
|
|
|
- {
|
|
|
- setChargerMode(gun_index, MODE_COMPLETE);
|
|
|
- }
|
|
|
- }
|
|
|
- else if (chargingInfo[gun_index]->Type == _Type_CCS)
|
|
|
- {
|
|
|
-
|
|
|
- if (isEvStopCharging_ccs(gun_index) == YES)
|
|
|
- {
|
|
|
- setChargerMode(gun_index, MODE_COMPLETE);
|
|
|
- }
|
|
|
- }
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
|
|
|
-
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_COMPLETE:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf ("complete......................... %x \n", gun_index);
|
|
|
- ftime(&endChargingTime[gun_index]);
|
|
|
- if (chargingInfo[gun_index]->RemainChargingDuration != 0)
|
|
|
- chargingInfo[gun_index]->RemainChargingDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
|
|
|
-
|
|
|
- strcpy((char *)chargingInfo[gun_index]->CardNumber, "");
|
|
|
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- StartGunInfoTimeoutDet(gun_index, Timeout_WaitforCompleteDet);
|
|
|
- }
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
|
|
|
- }
|
|
|
- break;
|
|
|
- case S_CCS_PRECHARGE_ST0:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf("CCS Precharge Processing 1....................%x \n", gun_index);
|
|
|
- StopGunInfoTimeoutDet(gun_index);
|
|
|
- StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
|
|
|
- }
|
|
|
-
|
|
|
- if (isEvBoardStopChargeFlag(gun_index) == YES)
|
|
|
- {
|
|
|
-
|
|
|
- ChargingTerminalProcess(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40)
|
|
|
- {
|
|
|
- if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
|
|
|
-
|
|
|
- {
|
|
|
- printf("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
|
|
|
- chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
|
|
|
- }
|
|
|
- }
|
|
|
- else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46)
|
|
|
- {
|
|
|
- setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
- }
|
|
|
- case S_CCS_PRECHARGE_ST1:
|
|
|
- {
|
|
|
- if (isModeChange(gun_index))
|
|
|
- {
|
|
|
- printf("CCS Precharge Processing 2....................%x \n", gun_index);
|
|
|
- }
|
|
|
-
|
|
|
- if (isEvBoardStopChargeFlag(gun_index) == YES)
|
|
|
- {
|
|
|
-
|
|
|
- ChargingTerminalProcess(gun_index);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (chargingInfo[gun_index]->RelayK1K2Status == YES)
|
|
|
- {
|
|
|
- chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
|
|
|
- setChargerMode(gun_index, MODE_CHARGING);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE)
|
|
|
- ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
|
|
|
- else
|
|
|
- ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
|
|
|
-
|
|
|
- usleep(whileLoopTime);
|
|
|
- }
|
|
|
-
|
|
|
- return FAIL;
|
|
|
-}
|
|
|
+#include <sys/types.h>
|
|
|
+#include <sys/stat.h>
|
|
|
+#include <sys/time.h>
|
|
|
+#include <sys/timeb.h>
|
|
|
+#include <sys/types.h>
|
|
|
+#include <sys/ioctl.h>
|
|
|
+#include <sys/socket.h>
|
|
|
+#include <sys/ipc.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 <stdint.h>
|
|
|
+#include <time.h>
|
|
|
+#include <ctype.h>
|
|
|
+#include <ifaddrs.h>
|
|
|
+#include <math.h>
|
|
|
+#include "../../define.h"
|
|
|
+#include "Config.h"
|
|
|
+#include <stdbool.h>
|
|
|
+#include <dirent.h>
|
|
|
+#include "timeout.h"
|
|
|
+
|
|
|
+#define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
|
|
|
+#define PASS 1
|
|
|
+#define FAIL -1
|
|
|
+#define BUFFER_SIZE 128
|
|
|
+#define YES 1
|
|
|
+#define NO 0
|
|
|
+#define NORMAL 0
|
|
|
+#define ABNORMAL 1
|
|
|
+#define EQUAL 0
|
|
|
+#define BTN_RELEASE 0
|
|
|
+#define BTN_PRESS 1
|
|
|
+#define MAX_BUF 64
|
|
|
+#define MtdBlockSize 0x600000
|
|
|
+#define SYSFS_GPIO_DIR "/sys/class/gpio"
|
|
|
+#define UPGRADE_FAN 0x02
|
|
|
+#define UPGRADE_RB 0x03
|
|
|
+#define UPGRADE_PRI 0x04
|
|
|
+
|
|
|
+char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
|
|
|
+unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
|
|
|
+int whileLoopTime = 10000;
|
|
|
+int wtdFd = -1;
|
|
|
+
|
|
|
+bool IsAuthorizingMode();
|
|
|
+void ClearAuthorizedFlag();
|
|
|
+bool isDetectPlugin();
|
|
|
+void ClearDetectPluginFlag();
|
|
|
+int mystrcmp(unsigned char *p1, unsigned char *p2);
|
|
|
+
|
|
|
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
|
|
|
+void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
|
|
|
+void ChargingTerminalProcess(byte gunIndex);
|
|
|
+void ChkPrimaryStatus();
|
|
|
+void StartSystemTimeoutDet(unsigned char flag);
|
|
|
+void StopSystemTimeoutDet();
|
|
|
+void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
|
|
|
+void StopGunInfoTimeoutDet(unsigned char gunIndex);
|
|
|
+int StoreLogMsg_1(const char *fmt, ...);
|
|
|
+unsigned long GetTimeoutValue(struct timeval _sour_time);
|
|
|
+void gpio_set_value(unsigned int gpio, unsigned int value);
|
|
|
+void PRINTF_FUNC(char *string, ...);
|
|
|
+
|
|
|
+#define DEBUG_INFO_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
|
+#define DEBUG_WARN_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
|
+#define DEBUG_ERROR_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
|
+
|
|
|
+struct SysConfigAndInfo *ShmSysConfigAndInfo;
|
|
|
+struct StatusCodeData *ShmStatusCodeData;
|
|
|
+struct PsuData *ShmPsuData;
|
|
|
+struct CHAdeMOData *ShmCHAdeMOData;
|
|
|
+struct CcsData *ShmCcsData;
|
|
|
+struct PrimaryMcuData *ShmPrimaryMcuData;
|
|
|
+struct FanModuleData *ShmFanModuleData;
|
|
|
+struct RelayModuleData *ShmRelayModuleData;
|
|
|
+struct OCPP16Data *ShmOCPP16Data;
|
|
|
+
|
|
|
+struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
+struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
+struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
+
|
|
|
+byte _gunCount = 0;
|
|
|
+
|
|
|
+byte _gunIndex = 0;
|
|
|
+byte _chademoIndex = 0;
|
|
|
+byte _ccsIndex = 0;
|
|
|
+byte _gb_Index = 0;
|
|
|
+byte bd0_1_status = 0;
|
|
|
+byte bd0_2_status = 0;
|
|
|
+byte bd1_1_status = 0;
|
|
|
+byte bd1_2_status = 0;
|
|
|
+
|
|
|
+bool isCardScan = false;
|
|
|
+
|
|
|
+int rfidFd = -1;
|
|
|
+char* rfidPortName = "/dev/ttyS2";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+int InitCanBus()
|
|
|
+{
|
|
|
+ int s0,nbytes;
|
|
|
+ struct timeval tv;
|
|
|
+ struct ifreq ifr0;
|
|
|
+ struct sockaddr_can addr0;
|
|
|
+
|
|
|
+ system("/sbin/ip link set can0 down");
|
|
|
+ system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
|
|
|
+ system("/sbin/ip link set can0 up");
|
|
|
+
|
|
|
+ s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
|
|
+
|
|
|
+ tv.tv_sec = 0;
|
|
|
+ tv.tv_usec = 10000;
|
|
|
+ if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("Set SO_RCVTIMEO NG");
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ nbytes=40960;
|
|
|
+ if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("Set SO_RCVBUF NG");
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ nbytes=40960;
|
|
|
+ if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("Set SO_SNDBUF NG");
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+
|
|
|
+ strcpy(ifr0.ifr_name, "can0" );
|
|
|
+ ioctl(s0, SIOCGIFINDEX, &ifr0);
|
|
|
+ addr0.can_family = AF_CAN;
|
|
|
+ addr0.can_ifindex = ifr0.ifr_ifindex;
|
|
|
+ bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
|
|
|
+ return s0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+char *_priPortName = "/dev/ttyS1";
|
|
|
+char *_485PortName = "/dev/ttyS5";
|
|
|
+
|
|
|
+int InitComPort(byte target)
|
|
|
+{
|
|
|
+ int fd;
|
|
|
+ struct termios tios;
|
|
|
+
|
|
|
+ if(target == UPGRADE_PRI)
|
|
|
+ fd = open(_priPortName, O_RDWR);
|
|
|
+ else if (target == UPGRADE_FAN || target == UPGRADE_RB)
|
|
|
+ fd = open(_485PortName, O_RDWR);
|
|
|
+
|
|
|
+ if(fd<=0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("open 407 Communication port NG \n");
|
|
|
+ #endif
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ ioctl (fd, TCGETS, &tios);
|
|
|
+ tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
|
|
|
+ tios.c_lflag = 0;
|
|
|
+ tios.c_iflag = 0;
|
|
|
+ tios.c_oflag = 0;
|
|
|
+ tios.c_cc[VMIN]=0;
|
|
|
+ tios.c_cc[VTIME]=(unsigned char)1;
|
|
|
+ tios.c_lflag=0;
|
|
|
+ tcflush(fd, TCIFLUSH);
|
|
|
+ ioctl (fd, TCSETS, &tios);
|
|
|
+
|
|
|
+ return fd;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+int InitWatchDog()
|
|
|
+{
|
|
|
+ int fd;
|
|
|
+ system("/usr/bin/fuser -k /dev/watchdog");
|
|
|
+ sleep(1);
|
|
|
+ system("echo V > /dev/watchdog");
|
|
|
+ sleep(1);
|
|
|
+ fd=open("/dev/watchdog", O_RDWR);
|
|
|
+
|
|
|
+ if(fd<=0)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("System watch dog initial fail.\r\n");
|
|
|
+ }
|
|
|
+ return fd;
|
|
|
+}
|
|
|
+
|
|
|
+int StoreLogMsg_1(const char *fmt, ...)
|
|
|
+{
|
|
|
+ char Buf[4096+256];
|
|
|
+ char buffer[4096];
|
|
|
+ time_t CurrentTime;
|
|
|
+ struct tm *tm;
|
|
|
+ va_list args;
|
|
|
+
|
|
|
+ va_start(args, fmt);
|
|
|
+ int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
|
|
|
+ va_end(args);
|
|
|
+
|
|
|
+ memset(Buf,0,sizeof(Buf));
|
|
|
+ CurrentTime = time(NULL);
|
|
|
+ tm=localtime(&CurrentTime);
|
|
|
+ sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
|
|
|
+ tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
|
|
|
+ buffer,
|
|
|
+ tm->tm_year+1900,tm->tm_mon+1);
|
|
|
+ system(Buf);
|
|
|
+
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+unsigned long GetTimeoutValue(struct timeval _sour_time)
|
|
|
+{
|
|
|
+ struct timeval _end_time;
|
|
|
+ gettimeofday(&_end_time, NULL);
|
|
|
+
|
|
|
+ return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
|
|
|
+}
|
|
|
+
|
|
|
+int mystrcmp(unsigned char *p1, unsigned char *p2)
|
|
|
+{
|
|
|
+ while(*p1==*p2)
|
|
|
+ {
|
|
|
+ if(*p1=='\0' || *p2=='\0')
|
|
|
+ break;
|
|
|
+ p1++;
|
|
|
+ p2++;
|
|
|
+ }
|
|
|
+ if(*p1=='\0' && *p2=='\0')
|
|
|
+ return(PASS);
|
|
|
+ else
|
|
|
+ return(FAIL);
|
|
|
+}
|
|
|
+
|
|
|
+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);
|
|
|
+}
|
|
|
+
|
|
|
+bool CheckTimeOut(struct timeb ST)
|
|
|
+{
|
|
|
+ struct timeb ET;
|
|
|
+ unsigned int StartTime, StopTime;
|
|
|
+
|
|
|
+ ftime(&ET);
|
|
|
+ StartTime = (unsigned int) ST.time;
|
|
|
+ StopTime = (unsigned int) ET.time;
|
|
|
+ return (StopTime > StartTime)? YES : NO;
|
|
|
+}
|
|
|
+
|
|
|
+void setChargerMode(byte gun_index, byte mode)
|
|
|
+{
|
|
|
+ chargingInfo[gun_index]->SystemStatus = mode;
|
|
|
+}
|
|
|
+
|
|
|
+void PRINTF_FUNC(char *string, ...)
|
|
|
+{
|
|
|
+ if (DEBUG)
|
|
|
+ {
|
|
|
+ va_list args;
|
|
|
+ char buffer[4096];
|
|
|
+
|
|
|
+ va_start(args, string);
|
|
|
+ vsnprintf(buffer, sizeof(buffer), string, args);
|
|
|
+ va_end(args);
|
|
|
+ printf("%s \n", buffer);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+int isInterfaceUp(const char *interface)
|
|
|
+{
|
|
|
+ int result = FAIL;
|
|
|
+
|
|
|
+ FILE *fp;
|
|
|
+ char cmd[256];
|
|
|
+ char buf[512];
|
|
|
+
|
|
|
+ strcpy(cmd, "ifconfig");
|
|
|
+ fp = popen(cmd, "r");
|
|
|
+ if(fp != NULL)
|
|
|
+ {
|
|
|
+ while(fgets(buf, sizeof(buf), fp) != NULL)
|
|
|
+ {
|
|
|
+ if(strstr(buf, interface) > 0)
|
|
|
+ {
|
|
|
+ result = PASS;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pclose(fp);
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+int CreateShareMemory()
|
|
|
+{
|
|
|
+ int MeterSMId;
|
|
|
+
|
|
|
+ if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
|
|
|
+
|
|
|
+ if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmStatusCodeData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmStatusCodeData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
|
|
|
+
|
|
|
+
|
|
|
+ if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPsuData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPsuData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ memset(ShmPsuData, 0, sizeof(struct PsuData));
|
|
|
+
|
|
|
+ if(CHAdeMO_QUANTITY > 0)
|
|
|
+ {
|
|
|
+ if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCHAdeMOData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCHAdeMOData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(CCS_QUANTITY > 0)
|
|
|
+ {
|
|
|
+ if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCcsData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCcsData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ memset(ShmCcsData, 0, sizeof(struct CcsData));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPrimaryMcuData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
|
|
|
+
|
|
|
+
|
|
|
+ if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmFanModuleData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmFanModuleData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
|
|
|
+
|
|
|
+
|
|
|
+ if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmRelayModuleData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmRelayModuleData NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
|
|
|
+
|
|
|
+
|
|
|
+ if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmOCPP16Data NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmOCPP16Data NG \n");
|
|
|
+ #endif
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void ChangeLcmByIndex(byte page_index)
|
|
|
+{
|
|
|
+ if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
|
|
|
+ page_index == _LCM_COMPLETE || page_index == _LCM_FIX)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void InitGPIO()
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ system("echo 22 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio22/direction");
|
|
|
+
|
|
|
+ system("echo 23 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio23/direction");
|
|
|
+
|
|
|
+ system("echo 26 > /sys/class/gpio/export");
|
|
|
+ system("echo \"out\" > /sys/class/gpio/gpio26/direction");
|
|
|
+ system("echo 1 > /sys/class/gpio/gpio26/value");
|
|
|
+
|
|
|
+ system("echo 27 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio27/direction");
|
|
|
+
|
|
|
+ system("echo 29 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio29/direction");
|
|
|
+
|
|
|
+ system("echo 19 > /sys/class/gpio/export");
|
|
|
+ system("echo \"out\" > /sys/class/gpio/gpio19/direction");
|
|
|
+ system("echo 1 > /sys/class/gpio/gpio19/value");
|
|
|
+
|
|
|
+ system("echo 20 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio20/direction");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ system("echo 44 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio44/direction");
|
|
|
+
|
|
|
+ system("echo 45 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio45/direction");
|
|
|
+
|
|
|
+ system("echo 46 > /sys/class/gpio/export");
|
|
|
+ system("echo \"out\" > /sys/class/gpio/gpio46/direction");
|
|
|
+ system("echo 0 > /sys/class/gpio/gpio46/value");
|
|
|
+
|
|
|
+ system("echo 47 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio47/direction");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ system("echo 89 > /sys/class/gpio/export");
|
|
|
+ system("echo \"out\" > /sys/class/gpio/gpio89/direction");
|
|
|
+ system("echo 1 > /sys/class/gpio/gpio89/value");
|
|
|
+
|
|
|
+ system("echo 87 > /sys/class/gpio/export");
|
|
|
+ system("echo \"out\" > /sys/class/gpio/gpio87/direction");
|
|
|
+ system("echo 0 > /sys/class/gpio/gpio87/value");
|
|
|
+
|
|
|
+ system("echo 88 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio88/direction");
|
|
|
+
|
|
|
+ system("echo 86 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio86/direction");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ system("echo 111 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio111/direction");
|
|
|
+
|
|
|
+ system("echo 114 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio114/direction");
|
|
|
+
|
|
|
+ system("echo 113 > /sys/class/gpio/export");
|
|
|
+ system("echo \"in\" > /sys/class/gpio/gpio113/direction");
|
|
|
+
|
|
|
+ system("echo 110 > /sys/class/gpio/export");
|
|
|
+ system("echo \"out\" > /sys/class/gpio/gpio110/direction");
|
|
|
+ system("echo 0 > /sys/class/gpio/gpio110/value");
|
|
|
+
|
|
|
+ system("echo 115 > /sys/class/gpio/export");
|
|
|
+ system("echo \"out\" > /sys/class/gpio/gpio115/direction");
|
|
|
+ system("echo 0 > /sys/class/gpio/gpio115/value");
|
|
|
+
|
|
|
+ system("echo 112 > /sys/class/gpio/export");
|
|
|
+ system("echo \"out\" > /sys/class/gpio/gpio112/direction");
|
|
|
+ system("echo 1 > /sys/class/gpio/gpio112/value");
|
|
|
+
|
|
|
+ system("echo 116 > /sys/class/gpio/export");
|
|
|
+ system("echo \"out\" > /sys/class/gpio/gpio116/direction");
|
|
|
+ system("echo 0 > /sys/class/gpio/gpio116/value");
|
|
|
+#ifdef SystemLogMessage
|
|
|
+ DEBUG_INFO_MSG("[main]InitGPIO: Initial GPIO OK");
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+int LoadSysConfigAndInfo(struct SysConfigData *ptr)
|
|
|
+{
|
|
|
+ int fd,wrd;
|
|
|
+ unsigned char *buf;
|
|
|
+ unsigned int ChkSum,ChkSumOrg;
|
|
|
+
|
|
|
+ if((buf=malloc(MtdBlockSize))==NULL)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("malloc buffer NG,rebooting..\r\n");
|
|
|
+ if(ShmStatusCodeData!=NULL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
|
|
|
+ }
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+ memset(buf, 0, MtdBlockSize);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ fd = open("/dev/mtdblock10", O_RDWR);
|
|
|
+ if (fd < 0)
|
|
|
+ {
|
|
|
+ free(buf);
|
|
|
+ DEBUG_ERROR_MSG("open mtdblock10 NG,rebooting..\r\n");
|
|
|
+ if(ShmStatusCodeData!=NULL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
|
|
|
+ }
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+
|
|
|
+ wrd=read(fd, buf, MtdBlockSize);
|
|
|
+ close(fd);
|
|
|
+ if(wrd<MtdBlockSize)
|
|
|
+ {
|
|
|
+ free(buf);
|
|
|
+ DEBUG_ERROR_MSG("read SysConfigData data NG,rebooting..\r\n");
|
|
|
+ if(ShmStatusCodeData!=NULL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
|
|
|
+ }
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+ ChkSum=0;
|
|
|
+ for(wrd=0;wrd<MtdBlockSize-4;wrd++)
|
|
|
+ {
|
|
|
+ ChkSum+=buf[wrd];
|
|
|
+ }
|
|
|
+ memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(ChkSum!=ChkSumOrg)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("Primary SysConfigData checksum NG, read backup\r\n");
|
|
|
+ fd = open("/dev/mtdblock11", O_RDWR);
|
|
|
+ if (fd < 0)
|
|
|
+ {
|
|
|
+ free(buf);
|
|
|
+ DEBUG_ERROR_MSG("open mtdblock11 (backup) NG,rebooting..\r\n");
|
|
|
+ if(ShmStatusCodeData!=NULL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
|
|
|
+ }
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(buf, 0, MtdBlockSize);
|
|
|
+ wrd=read(fd, buf,MtdBlockSize);
|
|
|
+ close(fd);
|
|
|
+ if(wrd<MtdBlockSize)
|
|
|
+ {
|
|
|
+ free(buf);
|
|
|
+ DEBUG_ERROR_MSG("read backup SysConfigData data NG,rebooting..\r\n");
|
|
|
+ if(ShmStatusCodeData!=NULL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
|
|
|
+ }
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+ ChkSum=0;
|
|
|
+ for(wrd=0;wrd<MtdBlockSize-4;wrd++)
|
|
|
+ {
|
|
|
+ ChkSum+=buf[wrd];
|
|
|
+ }
|
|
|
+ memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(ChkSum!=ChkSumOrg)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("backup SysConfigData checksum NG, read Factory default\r\n");
|
|
|
+ fd = open("/dev/mtdblock12", O_RDWR);
|
|
|
+ if (fd < 0)
|
|
|
+ {
|
|
|
+ free(buf);
|
|
|
+ DEBUG_ERROR_MSG("open mtdblock12 (Factory default) NG,rebooting..\r\n");
|
|
|
+ if(ShmStatusCodeData!=NULL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
|
|
|
+ }
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+ memset(buf, 0, MtdBlockSize);
|
|
|
+ wrd=read(fd, buf,MtdBlockSize);
|
|
|
+ close(fd);
|
|
|
+ if(wrd<MtdBlockSize)
|
|
|
+ {
|
|
|
+ free(buf);
|
|
|
+ DEBUG_ERROR_MSG("read factory default SysConfigData data NG,rebooting..\r\n");
|
|
|
+ if(ShmStatusCodeData!=NULL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
|
|
|
+ }
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+ ChkSum=0;
|
|
|
+ for(wrd=0;wrd<MtdBlockSize-4;wrd++)
|
|
|
+ {
|
|
|
+ ChkSum+=buf[wrd];
|
|
|
+ }
|
|
|
+ memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
|
|
|
+ if(ChkSum!=ChkSumOrg)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("factory default SysConfigData checksum NG, restore factory default\r\n");
|
|
|
+ free(buf);
|
|
|
+ system("cd /root;./FactoryConfig -m");
|
|
|
+ system("sync");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+
|
|
|
+ return FAIL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ memcpy((struct SysConfigData *)ptr,buf,sizeof(struct SysConfigData));
|
|
|
+ free(buf);
|
|
|
+ DEBUG_INFO_MSG("Load SysConfigData OK\r\n");
|
|
|
+ return PASS;
|
|
|
+}
|
|
|
+
|
|
|
+int isReachableInternet()
|
|
|
+{
|
|
|
+ int result = FAIL;
|
|
|
+ FILE *fp;
|
|
|
+ char cmd[256];
|
|
|
+ char buf[512];
|
|
|
+
|
|
|
+
|
|
|
+ for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
|
|
|
+ {
|
|
|
+ strcpy(cmd, "ping -c 1 -w 3 ");
|
|
|
+ strcat(cmd, valid_Internet[idx]);
|
|
|
+ fp = popen(cmd, "r");
|
|
|
+ if(fp != NULL)
|
|
|
+ {
|
|
|
+ while(fgets(buf, sizeof(buf), fp) != NULL)
|
|
|
+ {
|
|
|
+ if(strstr(buf, "transmitted") > 0)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ if(strstr(buf,"100%") != NULL)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result = PASS;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pclose(fp);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+void InitEthernet()
|
|
|
+{
|
|
|
+ char tmpbuf[256];
|
|
|
+
|
|
|
+ system("echo 1 > /sys/class/gpio/gpio110/value");
|
|
|
+ sleep(2);
|
|
|
+
|
|
|
+ memset(tmpbuf,0,256);
|
|
|
+ sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
|
|
|
+ ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
|
|
|
+ ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
|
|
|
+ system(tmpbuf);
|
|
|
+ memset(tmpbuf,0,256);
|
|
|
+ sprintf(tmpbuf,"route add default gw %s eth0 ",
|
|
|
+ ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
|
|
|
+ system(tmpbuf);
|
|
|
+
|
|
|
+
|
|
|
+ memset(tmpbuf,0,256);
|
|
|
+ sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up",
|
|
|
+ ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
|
|
|
+ ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
|
|
|
+ system(tmpbuf);
|
|
|
+
|
|
|
+
|
|
|
+ system("killall udhcpc");
|
|
|
+ system("rm -rf /etc/resolv.conf");
|
|
|
+ system("echo nameserver 8.8.8.8 > /etc/resolv.conf");
|
|
|
+ system("echo nameserver 180.76.76.76 > /etc/resolv.conf");
|
|
|
+
|
|
|
+ if(ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthDhcpClient == 0)
|
|
|
+ system("/sbin/udhcpc -i eth0 -s /root/dhcp_script/eth0.script > /dev/null &");
|
|
|
+
|
|
|
+ pid_t pid = fork();
|
|
|
+ uint8_t cnt_pingDNS_Fail;
|
|
|
+
|
|
|
+ if(pid == 0)
|
|
|
+ {
|
|
|
+ for(;;)
|
|
|
+ {
|
|
|
+ if(isReachableInternet() == PASS)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.InternetConn = YES;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet= NO;
|
|
|
+ cnt_pingDNS_Fail = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(++cnt_pingDNS_Fail > 3)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.InternetConn = NO;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet= YES;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sleep(5);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_INFO_MSG("[main]InitEthernet: Initial Ethernet OK");
|
|
|
+ #endif
|
|
|
+}
|
|
|
+
|
|
|
+int InitialRfidPort()
|
|
|
+{
|
|
|
+ int uartO2 = open(rfidPortName, O_RDWR);
|
|
|
+ struct termios tios;
|
|
|
+
|
|
|
+ if (uartO2 != FAIL)
|
|
|
+ {
|
|
|
+ ioctl (uartO2, TCGETS, &tios);
|
|
|
+ tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
|
|
|
+ tios.c_lflag = 0;
|
|
|
+ tios.c_iflag = 0;
|
|
|
+ tios.c_oflag = 0;
|
|
|
+ tios.c_cc[VMIN] = 0;
|
|
|
+ tios.c_cc[VTIME] = (unsigned char) 1;
|
|
|
+ tios.c_lflag = 0;
|
|
|
+ tcflush(uartO2, TCIFLUSH);
|
|
|
+ ioctl(uartO2, TCSETS, &tios);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (uartO2 < 0)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return uartO2;
|
|
|
+}
|
|
|
+
|
|
|
+void InitialShareMemoryInfo()
|
|
|
+{
|
|
|
+ FILE *fp;
|
|
|
+ char cmd[512];
|
|
|
+ char buf[512];
|
|
|
+
|
|
|
+ sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.01.04.20.01.00");
|
|
|
+
|
|
|
+ sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
|
|
|
+ sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
|
|
|
+ sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
|
|
|
+
|
|
|
+ ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
|
|
|
+
|
|
|
+ sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
|
|
|
+ memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
|
|
|
+
|
|
|
+ sprintf(cmd, "/bin/uname -r");
|
|
|
+ fp = popen(cmd, "r");
|
|
|
+ if(fp == NULL)
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
|
|
|
+ else
|
|
|
+ {
|
|
|
+ while(fgets(buf, sizeof(buf), fp) != NULL)
|
|
|
+ {
|
|
|
+ strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.01.44.0030");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
|
|
|
+
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.OrderCharging = FAIL;
|
|
|
+
|
|
|
+ strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
|
|
|
+
|
|
|
+ memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
|
|
|
+ memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
|
|
|
+ ShmPrimaryMcuData->SelfTest_Comp = NO;
|
|
|
+ ShmRelayModuleData->SelfTest_Comp = NO;
|
|
|
+ ShmFanModuleData->SelfTest_Comp = NO;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
|
|
|
+
|
|
|
+ ShmFanModuleData->TestFanSpeed = 0;
|
|
|
+
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
|
|
|
+}
|
|
|
+
|
|
|
+int Initialization()
|
|
|
+{
|
|
|
+
|
|
|
+ ClearAuthorizedFlag();
|
|
|
+
|
|
|
+ ClearDetectPluginFlag();
|
|
|
+
|
|
|
+
|
|
|
+ rfidFd = InitialRfidPort();
|
|
|
+
|
|
|
+ int pinOut[2] = { 115, 116 };
|
|
|
+ for (byte count = 0; count < _gunCount; count++)
|
|
|
+ {
|
|
|
+ if (chargingInfo[count]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ gpio_set_value(pinOut[count], 0x01);
|
|
|
+ ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
|
|
|
+ }
|
|
|
+ else if (chargingInfo[count]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+ if (ShmCcsData->CommProtocol == 0x01)
|
|
|
+ {
|
|
|
+ if (_gunCount == 1)
|
|
|
+ gpio_set_value(pinOut[1], 0x00);
|
|
|
+ else
|
|
|
+ gpio_set_value(pinOut[count], 0x00);
|
|
|
+ ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
|
|
|
+ }
|
|
|
+
|
|
|
+ PRINTF_FUNC("Initialization OK \n");
|
|
|
+ return PASS;
|
|
|
+}
|
|
|
+
|
|
|
+bool InitialSystemDefaultConfig()
|
|
|
+{
|
|
|
+ bool result = true;
|
|
|
+
|
|
|
+ LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
|
|
|
+ InitGPIO();
|
|
|
+
|
|
|
+ if (DEBUG == NO)
|
|
|
+ {
|
|
|
+ wtdFd = InitWatchDog();
|
|
|
+
|
|
|
+ if (wtdFd < 0)
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ system("echo 1 > /sys/class/gpio/gpio110/value");
|
|
|
+ sleep(3);
|
|
|
+ system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
|
|
|
+ sleep(1);
|
|
|
+ system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up");
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+void DisplaySelfTestFailReason()
|
|
|
+{
|
|
|
+
|
|
|
+ if (ShmRelayModuleData->SelfTest_Comp == NO)
|
|
|
+ { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = YES; }
|
|
|
+ if (ShmFanModuleData->SelfTest_Comp == NO)
|
|
|
+ { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = YES; }
|
|
|
+ if (ShmPrimaryMcuData->SelfTest_Comp == NO)
|
|
|
+ { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = YES; }
|
|
|
+ for (byte index = 0; index < _gunCount; index++)
|
|
|
+ {
|
|
|
+ if (chargingInfo[index]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
|
|
|
+ { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = YES; }
|
|
|
+ }
|
|
|
+ else if (chargingInfo[index]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+ if (ShmCcsData->CommProtocol == 0x01)
|
|
|
+ {
|
|
|
+ if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
|
|
|
+ { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = YES; }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
|
|
|
+ {
|
|
|
+
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = YES;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = YES;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void SelfTestRun()
|
|
|
+{
|
|
|
+ bool evInitFlag = false;
|
|
|
+
|
|
|
+ StartSystemTimeoutDet(Timeout_SelftestChk);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
|
|
|
+ while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
|
|
|
+ {
|
|
|
+ ChkPrimaryStatus();
|
|
|
+ if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_gunCount > 0)
|
|
|
+ {
|
|
|
+ if (ShmPsuData->Work_Step == _NO_WORKING ||
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch(ShmSysConfigAndInfo->SysInfo.SelfTestSeq)
|
|
|
+ {
|
|
|
+ case _STEST_VERSION:
|
|
|
+ {
|
|
|
+ if (strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
|
|
|
+ ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
|
|
|
+ {
|
|
|
+
|
|
|
+ ShmRelayModuleData->SelfTest_Comp = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
|
|
|
+ ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
|
|
|
+ {
|
|
|
+
|
|
|
+ ShmFanModuleData->SelfTest_Comp = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strlen((char *)ShmPrimaryMcuData->version) != 0 ||
|
|
|
+ ShmPrimaryMcuData->version[0] != '\0')
|
|
|
+ {
|
|
|
+
|
|
|
+ ShmPrimaryMcuData->SelfTest_Comp = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!evInitFlag)
|
|
|
+ {
|
|
|
+ evInitFlag = YES;
|
|
|
+ for (byte index = 0; index < _gunCount; index++)
|
|
|
+ {
|
|
|
+ if (chargingInfo[index]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ if (strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
|
|
|
+ ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
|
|
|
+ {
|
|
|
+
|
|
|
+ ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ evInitFlag = NO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (chargingInfo[index]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+ if (ShmCcsData->CommProtocol == 0x01)
|
|
|
+ {
|
|
|
+ if (strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
|
|
|
+ ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
|
|
|
+ {
|
|
|
+
|
|
|
+ ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp = YES;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ evInitFlag = NO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmFanModuleData->SelfTest_Comp &&
|
|
|
+ ShmRelayModuleData->SelfTest_Comp &&
|
|
|
+ ShmPrimaryMcuData->SelfTest_Comp &&
|
|
|
+ evInitFlag)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case _STEST_AC_CONTACTOR:
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
|
|
|
+ PRINTF_FUNC("Communication board pass. \n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case _STEST_PSU_DETECT:
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ if (ShmPsuData->Work_Step == _TEST_POWER_STEP || ShmPsuData->Work_Step == _TEST_COMPLETE)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case _STEST_PSU_CAP:
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ if (ShmPsuData->Work_Step == _TEST_COMPLETE)
|
|
|
+ {
|
|
|
+ sleep(1);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ break;
|
|
|
+
|
|
|
+ usleep(100000);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int SpawnTask()
|
|
|
+{
|
|
|
+ system("/root/Module_EventLogging &");
|
|
|
+ system("/root/Module_PrimaryComm &");
|
|
|
+ system("/root/Module_EvComm &");
|
|
|
+ system("/root/Module_LcmControl &");
|
|
|
+ system("/root/Module_InternalComm &");
|
|
|
+ system("/root/Module_PsuComm &");
|
|
|
+ system("/root/OcppBackend &");
|
|
|
+
|
|
|
+ if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
|
|
|
+ {
|
|
|
+ system("/root/Module_4g &");
|
|
|
+ }
|
|
|
+ else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
|
|
|
+ {
|
|
|
+ system("/root/Module_Wifi &");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return PASS;
|
|
|
+}
|
|
|
+
|
|
|
+int StoreUsrConfigData(struct SysConfigData *UsrData)
|
|
|
+{
|
|
|
+ int result = PASS;
|
|
|
+ int fd,wrd;
|
|
|
+ unsigned int i,Chk;
|
|
|
+ unsigned char *ptr, *BufTmp;
|
|
|
+
|
|
|
+ Chk=0;
|
|
|
+ ptr=(unsigned char *)UsrData;
|
|
|
+ if((BufTmp = malloc(MtdBlockSize)) != NULL)
|
|
|
+ {
|
|
|
+ memset(BufTmp, 0, MtdBlockSize);
|
|
|
+ memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
|
|
|
+ for(i=0; i<MtdBlockSize-4; i++)
|
|
|
+ Chk+=*(ptr+i);
|
|
|
+
|
|
|
+ memcpy(BufTmp + MtdBlockSize-4, &Chk, 4);
|
|
|
+ fd = open("/dev/mtdblock10", O_RDWR);
|
|
|
+ if (fd > 0)
|
|
|
+ {
|
|
|
+ wrd=write(fd, BufTmp, MtdBlockSize);
|
|
|
+ close(fd);
|
|
|
+ if(wrd >= MtdBlockSize)
|
|
|
+ {
|
|
|
+ fd = open("/dev/mtdblock11", O_RDWR);
|
|
|
+ if (fd > 0)
|
|
|
+ {
|
|
|
+ wrd=write(fd, BufTmp, MtdBlockSize);
|
|
|
+ close(fd);
|
|
|
+ if(wrd < MtdBlockSize)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("write /dev/mtdblock11(backup) NG\r\n");
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("open /dev/mtdblock11(backup) NG\r\n");
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("write /dev/mtdblock10 NG\r\n");
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("open /dev/mtdblock10 NG\r\n");
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("alloc BlockSize NG\r\n");
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(BufTmp != NULL)
|
|
|
+ free(BufTmp);
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+bool isEvBoardStopChargeFlag(byte gunIndex)
|
|
|
+{
|
|
|
+ return chargingInfo[gunIndex]->StopChargeFlag;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void ClearDetectPluginFlag()
|
|
|
+{
|
|
|
+ ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
|
|
|
+}
|
|
|
+
|
|
|
+void DetectPluginStart()
|
|
|
+{
|
|
|
+ ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
|
|
|
+}
|
|
|
+
|
|
|
+bool isDetectPlugin()
|
|
|
+{
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES)
|
|
|
+ return YES;
|
|
|
+
|
|
|
+ return NO;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+bool isEvGunLocked_chademo(byte gunIndex)
|
|
|
+{
|
|
|
+ return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
|
|
|
+}
|
|
|
+
|
|
|
+bool isEvContactorWelding_chademo(byte gunIndex)
|
|
|
+{
|
|
|
+ return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
|
|
|
+}
|
|
|
+
|
|
|
+bool isEvStopReq_chademo(byte gunIndex)
|
|
|
+{
|
|
|
+ return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
|
|
|
+}
|
|
|
+
|
|
|
+bool isEvStopCharging_chademo(byte gunIndex)
|
|
|
+{
|
|
|
+ if (isEvGunLocked_chademo(gunIndex) == NO)
|
|
|
+ {
|
|
|
+
|
|
|
+ PRINTF_FUNC("gun locked none. \n");
|
|
|
+ return YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ return NO;
|
|
|
+}
|
|
|
+
|
|
|
+byte isPrechargeStatus_chademo(byte gunIndex)
|
|
|
+{
|
|
|
+ byte result = 0x00;
|
|
|
+
|
|
|
+ result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+bool isEvGunLocked_ccs(byte gunIndex)
|
|
|
+{
|
|
|
+ return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
|
|
|
+}
|
|
|
+
|
|
|
+byte isPrechargeStatus_ccs(byte gunIndex)
|
|
|
+{
|
|
|
+ byte result = 0x00;
|
|
|
+
|
|
|
+ if (ShmCcsData->CommProtocol == 0x01)
|
|
|
+ {
|
|
|
+ result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+bool isEvStopCharging_ccs(byte gunIndex)
|
|
|
+{
|
|
|
+ if (isEvGunLocked_ccs(gunIndex) == NO)
|
|
|
+ {
|
|
|
+
|
|
|
+ PRINTF_FUNC("gun locked none. \n");
|
|
|
+ return YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ return NO;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void DisplayChargingInfo()
|
|
|
+{
|
|
|
+ for (byte i = _gunCount - 1; i >= 0; i--)
|
|
|
+ {
|
|
|
+ if (chargingInfo[i]->SystemStatus != S_IDLE)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.CurGunSelected = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
|
|
|
+}
|
|
|
+
|
|
|
+void _AutoReturnTimeout()
|
|
|
+{
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
|
|
|
+ {
|
|
|
+ ClearDetectPluginFlag();
|
|
|
+ }
|
|
|
+ else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
|
|
|
+ {
|
|
|
+ DetectPluginStart();
|
|
|
+ }
|
|
|
+
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void _SelfTestTimeout()
|
|
|
+{
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
|
|
|
+ {
|
|
|
+ for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, MODE_ALARM);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ShmPsuData->Work_Step = _NO_WORKING;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
|
|
|
+ PRINTF_FUNC("Self test timeout. \n");
|
|
|
+}
|
|
|
+
|
|
|
+void _AuthorizedTimeout()
|
|
|
+{
|
|
|
+ if(IsAuthorizingMode())
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("_AuthorizedTimeout \n");
|
|
|
+ isCardScan = false;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
|
|
|
+
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ ClearAuthorizedFlag();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void _DetectPlugInTimeout()
|
|
|
+{
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ PRINTF_FUNC("_DetectPlugInTimeout \n");
|
|
|
+ ClearDetectPluginFlag();
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
|
|
|
+}
|
|
|
+
|
|
|
+void _DetectEvChargingEnableTimeout(byte gunIndex)
|
|
|
+{
|
|
|
+ if (chargingInfo[gunIndex]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ if(!isEvGunLocked_chademo(gunIndex))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("_DetectEvChargingEnableTimeout (chademo) \n");
|
|
|
+ ChargingTerminalProcess(gunIndex);
|
|
|
+ _AutoReturnTimeout();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+ if(!isEvGunLocked_ccs(gunIndex))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("_DetectEvChargingEnableTimeout (ccs) \n");
|
|
|
+ ChargingTerminalProcess(gunIndex);
|
|
|
+ _AutoReturnTimeout();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void _DetectEvseChargingEnableTimeout(byte gunIndex)
|
|
|
+{
|
|
|
+ PRINTF_FUNC("_DetectEvseChargingEnableTimeout (GFD timeout) \n");
|
|
|
+
|
|
|
+ {
|
|
|
+ setChargerMode(gunIndex, MODE_IDLE);
|
|
|
+ _AutoReturnTimeout();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void _PrepareTimeout(byte gunIndex)
|
|
|
+{
|
|
|
+ PRINTF_FUNC("_PrechargeTimeout \n");
|
|
|
+ setChargerMode(gunIndex, MODE_IDLE);
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
|
|
|
+ _AutoReturnTimeout();
|
|
|
+}
|
|
|
+
|
|
|
+void _CompleteTimeout(byte gunIndex)
|
|
|
+{
|
|
|
+ PRINTF_FUNC("_CompleteTimeout ====> %d \n", gunIndex);
|
|
|
+ setChargerMode(gunIndex, MODE_IDLE);
|
|
|
+}
|
|
|
+
|
|
|
+void _CcsPrechargeTimeout(byte gunIndex)
|
|
|
+{
|
|
|
+ PRINTF_FUNC("_CcsPrechargeTimeout \n");
|
|
|
+ setChargerMode(gunIndex, MODE_IDLE);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+bool canStartCharging()
|
|
|
+{
|
|
|
+ char buf2[16] = "";
|
|
|
+ memset(buf2, 0, ARRAY_SIZE(buf2));
|
|
|
+
|
|
|
+ for (byte index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++)
|
|
|
+ {
|
|
|
+ sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
|
|
|
+ }
|
|
|
+ sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
|
|
|
+
|
|
|
+
|
|
|
+ if(strcmp(buf2, "Accepted") == EQUAL)
|
|
|
+ return true;
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+void AuthorizingStart()
|
|
|
+{
|
|
|
+ ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
|
|
|
+}
|
|
|
+
|
|
|
+void ClearAuthorizedFlag()
|
|
|
+{
|
|
|
+ ShmOCPP16Data->SpMsg.bits.AuthorizeReq = NO;
|
|
|
+ ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
|
|
|
+}
|
|
|
+
|
|
|
+bool isAuthorizedComplete()
|
|
|
+{
|
|
|
+ if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == NO)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool IsAuthorizingMode()
|
|
|
+{
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void RecordAlarmCode(char *code)
|
|
|
+{
|
|
|
+ if (strcmp(code, "012234") == 0) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
|
|
|
+ if (strcmp(code, "012235") == 0) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
|
|
|
+}
|
|
|
+
|
|
|
+void ReleaseAlarmCode(byte gunIndex)
|
|
|
+{
|
|
|
+ if (chargingInfo[gunIndex]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
|
|
|
+ }
|
|
|
+ else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void ChargingTerminalProcess(byte gunIndex)
|
|
|
+{
|
|
|
+ setChargerMode(gunIndex, MODE_TERMINATING);
|
|
|
+}
|
|
|
+
|
|
|
+void StopChargingProcessByString(byte level, byte gun_index, char *string)
|
|
|
+{
|
|
|
+ if (level > ShmSysConfigAndInfo->SysWarningInfo.Level)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysWarningInfo.Level = level;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ReleaseChargingProcessByString(byte level, char *code)
|
|
|
+{
|
|
|
+ if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level)
|
|
|
+ ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void BoardErrOccurByString(byte index, char *code)
|
|
|
+{
|
|
|
+ byte level = 1;
|
|
|
+ if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
|
|
|
+ (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
|
|
|
+ {
|
|
|
+ ChargingTerminalProcess(index);
|
|
|
+ }
|
|
|
+
|
|
|
+ StopChargingProcessByString(level, index, code);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void EmcOccureByString(char *code)
|
|
|
+{
|
|
|
+ byte level = 2;
|
|
|
+
|
|
|
+
|
|
|
+ if (strncmp(code, "012251", 6) == 0 || strncmp(code, "012252", 6) == 0 ||
|
|
|
+ strncmp(code, "012237", 6) == 0 || strncmp(code, "012238", 6) == 0)
|
|
|
+ {
|
|
|
+ for (byte gun = 0; gun < _gunCount; gun++)
|
|
|
+ {
|
|
|
+ if ((chargingInfo[gun]->SystemStatus > S_IDLE && chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
|
|
|
+ (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
|
|
|
+ {
|
|
|
+ ChargingTerminalProcess(gun);
|
|
|
+ }
|
|
|
+
|
|
|
+ StopChargingProcessByString(level, gun, code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ReleaseBoardErrOccurByString(byte index, char *code)
|
|
|
+{
|
|
|
+ bool isTrigger = false;
|
|
|
+ byte level = 1;
|
|
|
+
|
|
|
+ if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
|
|
|
+ {
|
|
|
+ isTrigger = true;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isTrigger)
|
|
|
+ {
|
|
|
+ ReleaseChargingProcessByString(level, code);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ReleaseEmsOccureByString(byte index, char *code)
|
|
|
+{
|
|
|
+ bool isTrigger = false;
|
|
|
+ byte level = 2;
|
|
|
+
|
|
|
+ if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
|
|
|
+ {
|
|
|
+ isTrigger = true;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
|
|
|
+ }
|
|
|
+ else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
|
|
|
+ {
|
|
|
+ isTrigger = true;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
|
|
|
+ }
|
|
|
+ else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
|
|
|
+ {
|
|
|
+ isTrigger = true;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
|
|
|
+ }
|
|
|
+ else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
|
|
|
+ {
|
|
|
+ isTrigger = true;
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isTrigger)
|
|
|
+ {
|
|
|
+ ReleaseChargingProcessByString(level, code);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+bool leftBtnPush = false;
|
|
|
+bool rightBtnPush = false;
|
|
|
+
|
|
|
+void ChkPrimaryStatus()
|
|
|
+{
|
|
|
+ if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
|
|
|
+ EmcOccureByString("012251");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ ReleaseEmsOccureByString(0, "012251");
|
|
|
+
|
|
|
+ if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
|
|
|
+ EmcOccureByString("012238");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ ReleaseEmsOccureByString(0, "012238");
|
|
|
+
|
|
|
+ if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
|
|
|
+ EmcOccureByString("012237");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ ReleaseEmsOccureByString(0, "012237");
|
|
|
+
|
|
|
+ if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
|
|
|
+ EmcOccureByString("012252");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ ReleaseEmsOccureByString(0, "012252");
|
|
|
+
|
|
|
+ if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush)
|
|
|
+ {
|
|
|
+ if(!leftBtnPush)
|
|
|
+ {
|
|
|
+ leftBtnPush = true;
|
|
|
+ PRINTF_FUNC("left btn down............................... \n");
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < _gunCount)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
|
|
|
+ else
|
|
|
+ ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE)
|
|
|
+ {
|
|
|
+ if(leftBtnPush)
|
|
|
+ {
|
|
|
+ leftBtnPush = false;
|
|
|
+ PRINTF_FUNC("left btn up............................... \n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush)
|
|
|
+ {
|
|
|
+ if(!rightBtnPush)
|
|
|
+ {
|
|
|
+ rightBtnPush = true;
|
|
|
+ PRINTF_FUNC("right btn down............................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
|
|
|
+ if (_gunCount > 1)
|
|
|
+ {
|
|
|
+ switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
|
|
|
+ {
|
|
|
+ case S_IDLE:
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_PREPARNING:
|
|
|
+ case S_PREPARING_FOR_EV:
|
|
|
+ case S_PREPARING_FOR_EVSE:
|
|
|
+ case S_CCS_PRECHARGE_ST0:
|
|
|
+ case S_CCS_PRECHARGE_ST1:
|
|
|
+ case S_CHARGING:
|
|
|
+ {
|
|
|
+
|
|
|
+ ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_COMPLETE:
|
|
|
+ {
|
|
|
+
|
|
|
+ PRINTF_FUNC("right btn down.................S_COMPLETE \n");
|
|
|
+ chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_IDLE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE)
|
|
|
+ {
|
|
|
+ if(rightBtnPush)
|
|
|
+ {
|
|
|
+ rightBtnPush = false;
|
|
|
+ PRINTF_FUNC("right btn up............................... \n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void CheckErrorOccurStatus(byte index)
|
|
|
+{
|
|
|
+
|
|
|
+ if (chargingInfo[index]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES)
|
|
|
+ BoardErrOccurByString(index, "011012");
|
|
|
+ else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
|
|
|
+ BoardErrOccurByString(index, "012234");
|
|
|
+ }
|
|
|
+ else if (chargingInfo[index]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+ if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES)
|
|
|
+ BoardErrOccurByString(index, "011014");
|
|
|
+ else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
|
|
|
+ BoardErrOccurByString(index, "012235");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void gpio_set_value(unsigned int gpio, unsigned int value)
|
|
|
+{
|
|
|
+ int fd;
|
|
|
+ char buf[MAX_BUF];
|
|
|
+
|
|
|
+ snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
|
|
|
+ fd = open(buf, O_WRONLY);
|
|
|
+ if (fd < 0)
|
|
|
+ {
|
|
|
+ perror("gpio/set-value");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (value)
|
|
|
+ write(fd, "1", 2);
|
|
|
+ else
|
|
|
+ write(fd, "0", 2);
|
|
|
+
|
|
|
+ close(fd);
|
|
|
+}
|
|
|
+
|
|
|
+int gpio_get_value(unsigned int gpio, unsigned int *value)
|
|
|
+{
|
|
|
+ int fd;
|
|
|
+ char buf[MAX_BUF];
|
|
|
+ char ch;
|
|
|
+
|
|
|
+ snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
|
|
|
+
|
|
|
+ fd = open(buf, O_RDONLY);
|
|
|
+ if (fd < 0) {
|
|
|
+ perror("gpio/get-value");
|
|
|
+ return fd;
|
|
|
+ }
|
|
|
+
|
|
|
+ read(fd, &ch, 1);
|
|
|
+
|
|
|
+ if (ch != '0') {
|
|
|
+ *value = 1;
|
|
|
+ } else {
|
|
|
+ *value = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ close(fd);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+void CheckGunTypeFromHw()
|
|
|
+{
|
|
|
+ int pinIn[4] = { 22, 23, 44, 45 };
|
|
|
+ unsigned int gpioValue = 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
|
|
|
+ gpio_get_value(pinIn[i], &gpioValue);
|
|
|
+ {
|
|
|
+ switch (pinIn[i])
|
|
|
+ {
|
|
|
+ case 22:
|
|
|
+ bd1_1_status = gpioValue;
|
|
|
+ break;
|
|
|
+ case 23:
|
|
|
+ bd1_2_status = gpioValue;
|
|
|
+ break;
|
|
|
+ case 44:
|
|
|
+ bd0_1_status = gpioValue;
|
|
|
+ break;
|
|
|
+ case 45:
|
|
|
+ bd0_2_status = gpioValue;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CheckGpioInStatus()
|
|
|
+{
|
|
|
+ int pinIn[2] = { 27, 47 };
|
|
|
+ unsigned int gpioValue = 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < ARRAY_SIZE(pinIn); i++)
|
|
|
+ {
|
|
|
+ gpio_get_value(pinIn[i], &gpioValue);
|
|
|
+ if (gpioValue == 0x01)
|
|
|
+ {
|
|
|
+ switch(pinIn[i])
|
|
|
+ {
|
|
|
+
|
|
|
+ case 47:
|
|
|
+ {
|
|
|
+ for(int i = 0; i < _gunCount; i++)
|
|
|
+ {
|
|
|
+ if (chargingInfo[i]->slotsIndex == 1)
|
|
|
+ {
|
|
|
+ if (chargingInfo[i]->Type == _Type_Chademo)
|
|
|
+ BoardErrOccurByString(i, "023730");
|
|
|
+ else if (chargingInfo[i]->Type == _Type_CCS_2)
|
|
|
+ BoardErrOccurByString(i, "013627");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 27:
|
|
|
+ {
|
|
|
+ for(int i = 0; i < _gunCount; i++)
|
|
|
+ {
|
|
|
+ if (chargingInfo[i]->slotsIndex == 3)
|
|
|
+ {
|
|
|
+ if (chargingInfo[i]->Type == _Type_Chademo)
|
|
|
+ BoardErrOccurByString(i, "023730");
|
|
|
+ else if (chargingInfo[i]->Type == _Type_CCS_2)
|
|
|
+ BoardErrOccurByString(i, "013627");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ switch (pinIn[i])
|
|
|
+ {
|
|
|
+
|
|
|
+ case 47:
|
|
|
+ {
|
|
|
+ for(int i = 0; i < _gunCount; i++)
|
|
|
+ {
|
|
|
+ if (chargingInfo[i]->slotsIndex == 1)
|
|
|
+ {
|
|
|
+ if (chargingInfo[i]->Type == _Type_Chademo)
|
|
|
+ ReleaseEmsOccureByString(i, "023730");
|
|
|
+ else if (chargingInfo[i]->Type == _Type_CCS_2)
|
|
|
+ ReleaseEmsOccureByString(i, "013627");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 27:
|
|
|
+ {
|
|
|
+ for (int i = 0; i < _gunCount; i++)
|
|
|
+ {
|
|
|
+ if (chargingInfo[i]->slotsIndex == 3)
|
|
|
+ {
|
|
|
+ if (chargingInfo[i]->Type == _Type_Chademo)
|
|
|
+ ReleaseEmsOccureByString(i, "023730");
|
|
|
+ else if (chargingInfo[i]->Type == _Type_CCS_2)
|
|
|
+ ReleaseEmsOccureByString(i, "013627");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
|
|
|
+{
|
|
|
+ return ( _byte & mask_table[_bit] ) != 0x00;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
|
|
|
+{
|
|
|
+ if(value == 1)
|
|
|
+ *_byte |= (1 << _bit);
|
|
|
+ else if (value == 0)
|
|
|
+ *_byte ^= (1 << _bit);
|
|
|
+}
|
|
|
+
|
|
|
+void UserScanFunction()
|
|
|
+{
|
|
|
+ bool idleReq = false;
|
|
|
+ unsigned char stopReq = 255;
|
|
|
+
|
|
|
+
|
|
|
+ if(!IsAuthorizingMode())
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (byte i = 0; i < _gunCount; i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ if ((chargingInfo[i]->SystemStatus >= S_AUTHORIZING && chargingInfo[i]->SystemStatus <= S_PREPARNING) ||
|
|
|
+ (chargingInfo[i]->SystemStatus >= S_TERMINATING && chargingInfo[i]->SystemStatus < S_COMPLETE))
|
|
|
+ {
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (chargingInfo[i]->SystemStatus == S_CHARGING)
|
|
|
+ {
|
|
|
+ stopReq = i;
|
|
|
+ }
|
|
|
+ else if (chargingInfo[i]->SystemStatus == S_IDLE && chargingInfo[i]->IsAvailable == YES)
|
|
|
+ {
|
|
|
+ idleReq = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0)
|
|
|
+ {
|
|
|
+ if (stopReq < _gunCount &&
|
|
|
+ chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING)
|
|
|
+ {
|
|
|
+ char value[32];
|
|
|
+
|
|
|
+ PRINTF_FUNC("stop charging \n");
|
|
|
+ PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected,
|
|
|
+ chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
|
|
|
+ memcpy(value, (unsigned char *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
|
|
|
+ ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
|
|
|
+ if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
|
|
|
+ {
|
|
|
+ ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
|
|
|
+ }
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ }
|
|
|
+ else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_COMPLETE)
|
|
|
+ {
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ }
|
|
|
+ else if (idleReq)
|
|
|
+ {
|
|
|
+ if (_gunCount > 1 && stopReq != 255 && ONE_CONNECTOR_USE == YES)
|
|
|
+ {
|
|
|
+ idleReq = false;
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("// LCM => Authorizing \n");
|
|
|
+
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
|
|
|
+
|
|
|
+ AuthorizingStart();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+unsigned char isModeChange(unsigned char gun_index)
|
|
|
+{
|
|
|
+ unsigned char result = NO;
|
|
|
+
|
|
|
+ if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
|
|
|
+ {
|
|
|
+ result = YES;
|
|
|
+ chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+void ScannerCardProcess()
|
|
|
+{
|
|
|
+ if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level == 0 &&
|
|
|
+ ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_OCPP)
|
|
|
+ {
|
|
|
+ isCardScan = true;
|
|
|
+
|
|
|
+ UserScanFunction();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING)
|
|
|
+ {
|
|
|
+ StartSystemTimeoutDet(Timeout_Authorizing);
|
|
|
+
|
|
|
+
|
|
|
+ if (isAuthorizedComplete() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
|
|
|
+ {
|
|
|
+ StopSystemTimeoutDet();
|
|
|
+
|
|
|
+ if(canStartCharging() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
|
|
|
+ {
|
|
|
+
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
|
|
|
+ }
|
|
|
+ ClearAuthorizedFlag();
|
|
|
+ }
|
|
|
+ else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
|
|
|
+ {
|
|
|
+
|
|
|
+ for (int i = 0; i < 10; i++)
|
|
|
+ {
|
|
|
+ if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
|
|
|
+ {
|
|
|
+ if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
|
|
|
+ ClearAuthorizedFlag();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL)
|
|
|
+ {
|
|
|
+ StartSystemTimeoutDet(Timeout_VerifyFail);
|
|
|
+ isCardScan = false;
|
|
|
+ }
|
|
|
+ else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
|
|
|
+ {
|
|
|
+ StartSystemTimeoutDet(Timeout_VerifyComp);
|
|
|
+ }
|
|
|
+ else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
|
|
|
+ {
|
|
|
+ StartSystemTimeoutDet(Timeout_WaitPlug);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ isCardScan = false;
|
|
|
+}
|
|
|
+
|
|
|
+void AddGunInfoByConnector(byte typeValue, byte slots)
|
|
|
+{
|
|
|
+ switch (typeValue)
|
|
|
+ {
|
|
|
+ case '0':
|
|
|
+ break;
|
|
|
+ case '1':
|
|
|
+ break;
|
|
|
+ case '2':
|
|
|
+ break;
|
|
|
+ case '3':
|
|
|
+ break;
|
|
|
+ case '4':
|
|
|
+ break;
|
|
|
+ case '5':
|
|
|
+ break;
|
|
|
+ case '6':
|
|
|
+ break;
|
|
|
+ case 'J':
|
|
|
+ {
|
|
|
+ if (CHAdeMO_QUANTITY > _chademoIndex)
|
|
|
+ {
|
|
|
+ chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
|
|
|
+
|
|
|
+ chargingInfo[_gunIndex]->Index = _gunIndex;
|
|
|
+ chargingInfo[_gunIndex]->slotsIndex = slots;
|
|
|
+ chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
|
|
|
+ chargingInfo[_gunIndex]->Type = _Type_Chademo;
|
|
|
+ chargingInfo[_gunIndex]->type_index = _chademoIndex;
|
|
|
+ chargingInfo[_gunIndex]->IsAvailable = YES;
|
|
|
+ _chademoIndex++;
|
|
|
+ _gunIndex++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'U':
|
|
|
+ break;
|
|
|
+ case 'E':
|
|
|
+ {
|
|
|
+ if (CCS_QUANTITY > _ccsIndex)
|
|
|
+ {
|
|
|
+ chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
|
|
|
+
|
|
|
+ chargingInfo[_gunIndex]->Index = _gunIndex;
|
|
|
+ chargingInfo[_gunIndex]->slotsIndex = slots;
|
|
|
+ chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
|
|
|
+ chargingInfo[_gunIndex]->Type = _Type_CCS_2;
|
|
|
+ chargingInfo[_gunIndex]->type_index = _ccsIndex;
|
|
|
+ chargingInfo[_gunIndex]->IsAvailable = YES;
|
|
|
+
|
|
|
+ ShmCcsData->CommProtocol = 0x01;
|
|
|
+ _ccsIndex++;
|
|
|
+ _gunIndex++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'G':
|
|
|
+ break;
|
|
|
+ case 'D':
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool CheckConnectorTypeStatus()
|
|
|
+{
|
|
|
+ bool result = true;
|
|
|
+
|
|
|
+ PRINTF_FUNC("bd0_1_status = %d, bd0_2_status = %d, bd1_1_status = %d, bd1_2_status = %d \n",
|
|
|
+ bd0_1_status, bd0_2_status, bd1_1_status, bd1_2_status);
|
|
|
+ if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9)
|
|
|
+ {
|
|
|
+ byte slots = 1;
|
|
|
+ for (byte typeIndex = 7; typeIndex <= 9; typeIndex++)
|
|
|
+ {
|
|
|
+ AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots);
|
|
|
+ slots++;
|
|
|
+ }
|
|
|
+
|
|
|
+ _gunCount = _gunIndex;
|
|
|
+ PRINTF_FUNC("_gunCount = %d \n", _gunCount);
|
|
|
+ if (_gunCount == 0)
|
|
|
+ result = false;
|
|
|
+
|
|
|
+
|
|
|
+ for (byte gunIndex = 0; gunIndex < _gunCount; gunIndex++)
|
|
|
+ {
|
|
|
+ if (bd0_1_status == 0 && bd0_2_status == 1)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (chargingInfo[gunIndex]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ chargingInfo[gunIndex]->Evboard_id = 0x01;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (bd0_1_status == 1 && bd0_2_status == 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+ chargingInfo[gunIndex]->Evboard_id = 0x01;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bd1_1_status == 0 && bd1_2_status == 1)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (chargingInfo[gunIndex]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ chargingInfo[gunIndex]->Evboard_id = 0x02;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_gunCount == 1)
|
|
|
+ chargingInfo[gunIndex]->Evboard_id = 0x01;
|
|
|
+ }
|
|
|
+ else if (bd1_1_status == 1 && bd1_2_status == 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+ chargingInfo[gunIndex]->Evboard_id = 0x02;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_gunCount == 1)
|
|
|
+ chargingInfo[gunIndex]->Evboard_id = 0x01;
|
|
|
+ }
|
|
|
+
|
|
|
+ PRINTF_FUNC("index = %d, Type = %d, Evboard_id = %d \n", gunIndex, chargingInfo[gunIndex]->Type, chargingInfo[gunIndex]->Evboard_id);
|
|
|
+ if (chargingInfo[gunIndex]->Evboard_id == 0x00)
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+void KillTask()
|
|
|
+{
|
|
|
+ ChangeLcmByIndex(_LCM_FIX);
|
|
|
+ system("killall Module_EventLogging");
|
|
|
+ system("killall Module_PrimaryComm");
|
|
|
+ system("killall Module_EvComm");
|
|
|
+ system("killall Module_LcmControl");
|
|
|
+ system("killall Module_InternalComm");
|
|
|
+ system("killall Module_PsuComm");
|
|
|
+}
|
|
|
+
|
|
|
+char CheckUpdateProcess()
|
|
|
+{
|
|
|
+ DIR *d;
|
|
|
+ struct dirent *dir;
|
|
|
+ d = opendir("/mnt/");
|
|
|
+
|
|
|
+ if (d)
|
|
|
+ {
|
|
|
+ long int MaxLen=48*1024*1024, ImageLen = 0;
|
|
|
+ while ((dir = readdir(d)) != NULL)
|
|
|
+ {
|
|
|
+ char *new_str;
|
|
|
+ new_str = malloc(strlen("/mnt/")+strlen(dir->d_name)+1);
|
|
|
+ new_str[0] = '\0';
|
|
|
+ strcat(new_str, "/mnt/");
|
|
|
+ strcat(new_str, dir->d_name);
|
|
|
+ int fd = open(new_str, O_RDONLY);
|
|
|
+ if (fd < 0)
|
|
|
+ {
|
|
|
+ return FAIL;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned char *ptr = malloc(MaxLen);
|
|
|
+ memset(ptr, 0xFF, MaxLen);
|
|
|
+
|
|
|
+ ImageLen = read(fd, ptr, MaxLen);
|
|
|
+
|
|
|
+ if (ImageLen > 20)
|
|
|
+ {
|
|
|
+ unsigned int Type = (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19]));
|
|
|
+ PRINTF_FUNC("Typed...%x \r\n", Type);
|
|
|
+
|
|
|
+ switch (Type)
|
|
|
+ {
|
|
|
+ case 0x10000001:
|
|
|
+ case 0x10000002:
|
|
|
+ case 0x10000003:
|
|
|
+ case 0x10000004:
|
|
|
+ case 0x10000005:
|
|
|
+ {
|
|
|
+ if (Upgrade_Flash(Type, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
|
|
|
+ return PASS;
|
|
|
+ else
|
|
|
+ return FAIL;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x10000006:
|
|
|
+ case 0x1000000D:
|
|
|
+ case 0x1000000E:
|
|
|
+ {
|
|
|
+
|
|
|
+ byte target = 0x00;
|
|
|
+
|
|
|
+ if (Type == 0x10000006)
|
|
|
+ target = UPGRADE_PRI;
|
|
|
+ else if (Type == 0x1000000D)
|
|
|
+ target = UPGRADE_RB;
|
|
|
+ else if (Type == 0x1000000E)
|
|
|
+ target = UPGRADE_FAN;
|
|
|
+
|
|
|
+ int fd = InitComPort(target);
|
|
|
+
|
|
|
+ if (Upgrade_UART(fd, Type, target, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
|
|
|
+ return PASS;
|
|
|
+ else
|
|
|
+ return FAIL;
|
|
|
+
|
|
|
+ close(fd);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x10000007:
|
|
|
+ case 0x10000008:
|
|
|
+ case 0x10000009:
|
|
|
+ case 0x1000000A:
|
|
|
+ case 0x1000000B:
|
|
|
+ case 0x1000000C:
|
|
|
+ {
|
|
|
+
|
|
|
+ bool isPass = true;
|
|
|
+ int CanFd = InitCanBus();
|
|
|
+
|
|
|
+ if (CanFd > 0)
|
|
|
+ {
|
|
|
+ for(byte index = 0; index < _gunCount; index++)
|
|
|
+ {
|
|
|
+ if (!isPass)
|
|
|
+ break;
|
|
|
+
|
|
|
+ if (Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) != PASS)
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("Upgrad Fail. \n");
|
|
|
+ isPass = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ((Type == 0x10000007 || Type == 0x10000008 || Type == 0x10000009 || Type == 0x1000000A) &&
|
|
|
+ chargingInfo[index]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+ if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, ShmSysConfigAndInfo->SysConfig.ModelName) != PASS)
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("Upgrad Fail. \n");
|
|
|
+ isPass = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("Upgrad FD fail. \n");
|
|
|
+ isPass = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return isPass;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ free(new_str);
|
|
|
+ free(ptr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ free(dir);
|
|
|
+ closedir(d);
|
|
|
+ return FAIL;
|
|
|
+}
|
|
|
+
|
|
|
+void CreateRfidFork()
|
|
|
+{
|
|
|
+ pid_t rfidRecPid;
|
|
|
+
|
|
|
+ rfidRecPid = fork();
|
|
|
+ if (rfidRecPid == 0)
|
|
|
+ {
|
|
|
+ while(true)
|
|
|
+ {
|
|
|
+
|
|
|
+ RFID rfid;
|
|
|
+ if(getRequestCardSN(rfidFd, 0, &rfid))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("Get Card.. \n");
|
|
|
+ if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE)
|
|
|
+ {
|
|
|
+ switch (rfid.snType)
|
|
|
+ {
|
|
|
+ case RFID_SN_TYPE_6BYTE:
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
|
|
|
+ "%02X%02X%02X%02X%02X%02X",
|
|
|
+ rfid.currentCard[0], rfid.currentCard[1],
|
|
|
+ rfid.currentCard[2], rfid.currentCard[3],
|
|
|
+ rfid.currentCard[4], rfid.currentCard[5]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_7BYTE:
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
|
|
|
+ "%02X%02X%02X%02X%02X%02X%02X",
|
|
|
+ rfid.currentCard[0], rfid.currentCard[1],
|
|
|
+ rfid.currentCard[2], rfid.currentCard[3],
|
|
|
+ rfid.currentCard[4], rfid.currentCard[5],
|
|
|
+ rfid.currentCard[6]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_10BYTE:
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
|
|
|
+ "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
|
|
|
+ rfid.currentCard[0], rfid.currentCard[1],
|
|
|
+ rfid.currentCard[2], rfid.currentCard[3],
|
|
|
+ rfid.currentCard[4], rfid.currentCard[5],
|
|
|
+ rfid.currentCard[6], rfid.currentCard[7],
|
|
|
+ rfid.currentCard[8], rfid.currentCard[9]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_4BYTE:
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
|
|
|
+ "%02X%02X%02X%02X",
|
|
|
+ rfid.currentCard[0], rfid.currentCard[1],
|
|
|
+ rfid.currentCard[2], rfid.currentCard[3]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG)
|
|
|
+ {
|
|
|
+ switch (rfid.snType)
|
|
|
+ {
|
|
|
+ case RFID_SN_TYPE_6BYTE:
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
|
|
|
+ "%02X%02X%02X%02X%02X%02X",
|
|
|
+ rfid.currentCard[5], rfid.currentCard[4],
|
|
|
+ rfid.currentCard[3], rfid.currentCard[2],
|
|
|
+ rfid.currentCard[1], rfid.currentCard[0]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_7BYTE:
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
|
|
|
+ "%02X%02X%02X%02X%02X%02X%02X",
|
|
|
+ rfid.currentCard[6], rfid.currentCard[5],
|
|
|
+ rfid.currentCard[4], rfid.currentCard[3],
|
|
|
+ rfid.currentCard[2], rfid.currentCard[1],
|
|
|
+ rfid.currentCard[0]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_10BYTE:
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
|
|
|
+ "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
|
|
|
+ rfid.currentCard[9], rfid.currentCard[8],
|
|
|
+ rfid.currentCard[7], rfid.currentCard[6],
|
|
|
+ rfid.currentCard[5], rfid.currentCard[4],
|
|
|
+ rfid.currentCard[3], rfid.currentCard[2],
|
|
|
+ rfid.currentCard[1], rfid.currentCard[0]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_4BYTE:
|
|
|
+ sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
|
|
|
+ "%02X%02X%02X%02X",
|
|
|
+ rfid.currentCard[3], rfid.currentCard[2],
|
|
|
+ rfid.currentCard[1], rfid.currentCard[0]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PRINTF_FUNC("card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sleep(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void StartSystemTimeoutDet(unsigned char flag)
|
|
|
+{
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag)
|
|
|
+ {
|
|
|
+ gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
|
|
|
+ }
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
|
|
|
+}
|
|
|
+
|
|
|
+void StopSystemTimeoutDet()
|
|
|
+{
|
|
|
+ gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
|
|
|
+}
|
|
|
+
|
|
|
+void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
|
|
|
+{
|
|
|
+ if (gunIndex < _gunCount)
|
|
|
+ {
|
|
|
+ if (chargingInfo[gunIndex]->TimeoutFlag != flag)
|
|
|
+ {
|
|
|
+ gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
|
|
|
+ }
|
|
|
+ chargingInfo[gunIndex]->TimeoutFlag = flag;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void StopGunInfoTimeoutDet(unsigned char gunIndex)
|
|
|
+{
|
|
|
+ if (gunIndex < _gunCount)
|
|
|
+ {
|
|
|
+ chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CreateTimeoutFork()
|
|
|
+{
|
|
|
+ pid_t timeoutPid;
|
|
|
+
|
|
|
+ timeoutPid = fork();
|
|
|
+ if (timeoutPid == 0)
|
|
|
+ {
|
|
|
+ while(true)
|
|
|
+ {
|
|
|
+
|
|
|
+ switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
|
|
|
+ {
|
|
|
+ case Timeout_SelftestChk:
|
|
|
+ if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 40000000)
|
|
|
+ {
|
|
|
+ _SelfTestTimeout();
|
|
|
+ StopSystemTimeoutDet();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Timeout_Authorizing:
|
|
|
+ if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 50000000)
|
|
|
+ {
|
|
|
+ _AuthorizedTimeout();
|
|
|
+ StopSystemTimeoutDet();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Timeout_VerifyFail:
|
|
|
+ if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 3000000)
|
|
|
+ {
|
|
|
+ _AutoReturnTimeout();
|
|
|
+ StopSystemTimeoutDet();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Timeout_VerifyComp:
|
|
|
+ if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 3000000)
|
|
|
+ {
|
|
|
+ _AutoReturnTimeout();
|
|
|
+ StopSystemTimeoutDet();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Timeout_WaitPlug:
|
|
|
+ if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 40000000)
|
|
|
+ {
|
|
|
+ _DetectPlugInTimeout();
|
|
|
+ StopSystemTimeoutDet();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Timeout_ReturnToChargingGunDet:
|
|
|
+ {
|
|
|
+ if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 10000000)
|
|
|
+ {
|
|
|
+ DisplayChargingInfo();
|
|
|
+ StopSystemTimeoutDet();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
+ {
|
|
|
+ switch(chargingInfo[gun_index]->TimeoutFlag)
|
|
|
+ {
|
|
|
+ case Timeout_Preparing:
|
|
|
+ if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 40000000)
|
|
|
+ {
|
|
|
+ _PrepareTimeout(gun_index);
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Timeout_EvChargingDet:
|
|
|
+ if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 120000000)
|
|
|
+ {
|
|
|
+ _DetectEvChargingEnableTimeout(gun_index);
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Timeout_EvseChargingDet:
|
|
|
+ if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 60000000)
|
|
|
+ {
|
|
|
+ _DetectEvseChargingEnableTimeout(gun_index);
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Timeout_WaitforCompleteDet:
|
|
|
+ if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
|
|
|
+ {
|
|
|
+ _CompleteTimeout(gun_index);
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Timeout_ForCcsPrechargeDet:
|
|
|
+ if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 60000000)
|
|
|
+ {
|
|
|
+ _CcsPrechargeTimeout(gun_index);
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ usleep(100000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void GetSystemTime()
|
|
|
+{
|
|
|
+ struct timeb csuTime;
|
|
|
+ struct tm *tmCSU;
|
|
|
+
|
|
|
+ ftime(&csuTime);
|
|
|
+ tmCSU = localtime(&csuTime.time);
|
|
|
+ PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
|
|
|
+ tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
|
|
|
+ tmCSU->tm_sec);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void CheckFactoryConfigFunction()
|
|
|
+{
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
|
|
|
+ {
|
|
|
+ system("cd /root;./FactoryConfig -m");
|
|
|
+ system("sync");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CheckFwUpdateFunction()
|
|
|
+{
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
|
|
|
+ {
|
|
|
+ DEBUG_INFO_MSG("ftp : update start. \n");
|
|
|
+ KillTask();
|
|
|
+ if (CheckUpdateProcess() == PASS)
|
|
|
+ DEBUG_INFO_MSG("ftp : update complete. \n");
|
|
|
+ else
|
|
|
+ DEBUG_INFO_MSG("ftp : update fail. \n");
|
|
|
+
|
|
|
+ ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+ else if(ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES)
|
|
|
+ {
|
|
|
+ ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
|
|
|
+ }
|
|
|
+ else if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL)
|
|
|
+ {
|
|
|
+ DEBUG_INFO_MSG("Backend : update start. \n");
|
|
|
+ strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
|
|
|
+ strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
|
|
|
+ KillTask();
|
|
|
+
|
|
|
+ if (CheckUpdateProcess() == PASS)
|
|
|
+ {
|
|
|
+ DEBUG_INFO_MSG("Backend : update complete. \n");
|
|
|
+ strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
|
|
|
+ strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DEBUG_INFO_MSG("Backend : update fail. \n");
|
|
|
+ strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
|
|
|
+ strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
|
|
|
+ }
|
|
|
+
|
|
|
+ ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+ else if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "DownloadFailed") == EQUAL)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("Backend to download file fail. \n");
|
|
|
+ strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
|
|
|
+ strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
|
|
|
+ ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+int isReservationExpired(unsigned char gun_index)
|
|
|
+{
|
|
|
+ int result = NO;
|
|
|
+ struct tm expiredDate;
|
|
|
+ struct timeb expiredTime;
|
|
|
+
|
|
|
+ if (sscanf((char*) ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,
|
|
|
+ "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
|
|
|
+ &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
|
|
|
+ &expiredDate.tm_min, &expiredDate.tm_sec) == 6)
|
|
|
+ {
|
|
|
+ expiredDate.tm_year -= 1900;
|
|
|
+ expiredDate.tm_mon -= 1;
|
|
|
+
|
|
|
+ expiredTime.time = mktime(&expiredDate);
|
|
|
+ if (!CheckTimeOut(expiredTime))
|
|
|
+ {
|
|
|
+ result = YES;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void CheckOcppStatus()
|
|
|
+{
|
|
|
+ if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.OcppConnStatus = YES;
|
|
|
+ ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES)
|
|
|
+ {
|
|
|
+ ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
|
|
|
+ if(strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
|
|
|
+ sleep(3);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+ else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
|
|
|
+ sleep(3);
|
|
|
+ KillTask();
|
|
|
+ system("/usr/bin/run_evse_restart.sh");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void OcppStartTransation(byte gunIndex)
|
|
|
+{
|
|
|
+ if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
|
|
|
+ strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
|
|
|
+ else
|
|
|
+ strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
|
|
|
+
|
|
|
+ PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
|
|
|
+ ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
|
|
|
+}
|
|
|
+
|
|
|
+void OcppStopTransation(byte gunIndex)
|
|
|
+{
|
|
|
+ if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
|
|
|
+ strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
|
|
|
+ else
|
|
|
+ strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
|
|
|
+
|
|
|
+ PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
|
|
|
+ ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
|
|
|
+}
|
|
|
+
|
|
|
+bool OcppRemoteStop(byte gunIndex)
|
|
|
+{
|
|
|
+ bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
|
|
|
+ if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES)
|
|
|
+ ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+void OcppRemoteStartChk()
|
|
|
+{
|
|
|
+ if(!isDetectPlugin())
|
|
|
+ {
|
|
|
+ for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
+ {
|
|
|
+ if ((chargingInfo[gun_index]->SystemStatus == S_IDLE || chargingInfo[gun_index]->SystemStatus == S_RESERVATION)&&
|
|
|
+ ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq == YES)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
|
|
|
+ ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = NO;
|
|
|
+ DetectPluginStart();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ChkOcppStatus(byte gunIndex)
|
|
|
+{
|
|
|
+ if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
|
|
|
+ ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES)
|
|
|
+ {
|
|
|
+ ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
|
|
|
+ if (isReservationExpired(gunIndex))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
|
|
|
+ DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
|
|
|
+ chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
|
|
|
+ chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
|
|
|
+ ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES)
|
|
|
+ {
|
|
|
+ ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
|
|
|
+ if (isReservationExpired(gunIndex))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
|
|
|
+ DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
|
|
|
+ chargingInfo[gunIndex]->ReservationId = 0;
|
|
|
+ chargingInfo[gunIndex]->SystemStatus = S_IDLE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES)
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
|
|
|
+ DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
|
|
|
+ ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
|
|
|
+ if(strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL)
|
|
|
+ chargingInfo[gunIndex]->IsAvailable = YES;
|
|
|
+ else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL)
|
|
|
+ chargingInfo[gunIndex]->IsAvailable = NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool CheckBackendChargingTimeout(byte gunIndex)
|
|
|
+{
|
|
|
+ bool result = false;
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_OCPP)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0)
|
|
|
+ {
|
|
|
+ if (chargingInfo[gunIndex]->RemainChargingDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60))
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_FREE)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0)
|
|
|
+ {
|
|
|
+ if (chargingInfo[gunIndex]->RemainChargingDuration >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60))
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+bool CheckBackendChargingEnergy(byte gunIndex)
|
|
|
+{
|
|
|
+ bool result = false;
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_OCPP)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0)
|
|
|
+ {
|
|
|
+ if (chargingInfo[gunIndex]->PresentChargedEnergy >= ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_FREE)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0)
|
|
|
+ {
|
|
|
+ if (chargingInfo[gunIndex]->PresentChargedEnergy >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy))
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void AddPlugInTimes(byte gunIndex)
|
|
|
+{
|
|
|
+ if (chargingInfo[gunIndex]->Type == _Type_Chademo)
|
|
|
+ ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
|
|
|
+ else if(chargingInfo[gunIndex]->Type == _Type_CCS_2)
|
|
|
+ ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
|
|
|
+ else if(chargingInfo[gunIndex]->Type == _Type_GB)
|
|
|
+ ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
|
|
|
+}
|
|
|
+
|
|
|
+void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
|
|
|
+{
|
|
|
+ char cmdBuf[32];
|
|
|
+ struct timeb csuTime;
|
|
|
+ struct tm *tmCSU;
|
|
|
+
|
|
|
+ ftime(&csuTime);
|
|
|
+ tmCSU = localtime(&csuTime.time);
|
|
|
+
|
|
|
+ sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
|
|
|
+ tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
|
|
|
+ tmCSU->tm_sec);
|
|
|
+ if (isStart)
|
|
|
+ strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
|
|
|
+ else
|
|
|
+ strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
|
|
|
+}
|
|
|
+
|
|
|
+void zipLogFiles()
|
|
|
+{
|
|
|
+ const char* logPath = "/Storage/SystemLog";
|
|
|
+
|
|
|
+ DIR* pDir = opendir(logPath);
|
|
|
+ if (pDir != NULL)
|
|
|
+ {
|
|
|
+ struct timeb csuTime;
|
|
|
+ struct tm *tmCSU;
|
|
|
+
|
|
|
+ ftime(&csuTime);
|
|
|
+ tmCSU = localtime(&csuTime.time);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ struct dirent* pEntry = NULL;
|
|
|
+ while ((pEntry = readdir(pDir)) != NULL)
|
|
|
+ {
|
|
|
+ if (strcmp(pEntry->d_name, ".") != 0 &&
|
|
|
+ strcmp(pEntry->d_name, "..") != 0 &&
|
|
|
+ strncmp(pEntry->d_name, "[", 1) == 0 &&
|
|
|
+ strstr(pEntry->d_name, "tar") < 0)
|
|
|
+ {
|
|
|
+ char yearC[5];
|
|
|
+ unsigned short year = 0;
|
|
|
+ char monthC[3];
|
|
|
+ unsigned short month = 0;
|
|
|
+
|
|
|
+ yearC[4] = '\0';
|
|
|
+ strncpy(yearC, pEntry->d_name + 1, 4);
|
|
|
+ monthC[2] = '\0';
|
|
|
+ strncpy(monthC, pEntry->d_name + 6, 2);
|
|
|
+
|
|
|
+ year = atoi(yearC);
|
|
|
+ month = atoi(monthC);
|
|
|
+
|
|
|
+ if (year != 0)
|
|
|
+ {
|
|
|
+ if (year < tmCSU->tm_year + 1900 ||
|
|
|
+ (year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1))
|
|
|
+ {
|
|
|
+ DEBUG_INFO_MSG("tar file name : %s \n", pEntry->d_name);
|
|
|
+ char file[256];
|
|
|
+
|
|
|
+ memset(file, 0x00, sizeof(file));
|
|
|
+ strcat(file, "tar zcvf ");
|
|
|
+ strcat(file, logPath);
|
|
|
+ strncat(file, "/", 1);
|
|
|
+ strcat(file, pEntry->d_name);
|
|
|
+ strcat(file, ".tar");
|
|
|
+ strncat(file, " ", 1);
|
|
|
+ strcat(file, logPath);
|
|
|
+ strncat(file, "/", 1);
|
|
|
+ strcat(file, pEntry->d_name);
|
|
|
+ PRINTF_FUNC("zip = %s \n", file);
|
|
|
+ system(file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ closedir(pDir);
|
|
|
+}
|
|
|
+
|
|
|
+void StopProcessing()
|
|
|
+{
|
|
|
+ for (;;)
|
|
|
+ sleep(5);
|
|
|
+}
|
|
|
+
|
|
|
+int main(void)
|
|
|
+{
|
|
|
+ if(CreateShareMemory() == 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR_MSG("CreatShareMemory NG \n");
|
|
|
+ #endif
|
|
|
+ if(ShmStatusCodeData!=NULL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ sleep(5);
|
|
|
+ system("reboot -f");
|
|
|
+ }
|
|
|
+
|
|
|
+ PRINTF_FUNC("\n"); PRINTF_FUNC("Initial SystemConfig and Info.......\n");
|
|
|
+ if (!InitialSystemDefaultConfig())
|
|
|
+ {
|
|
|
+ DEBUG_ERROR_MSG("InitialSystemDefaultConfig NG \n");
|
|
|
+ StopProcessing();
|
|
|
+ }
|
|
|
+
|
|
|
+ PRINTF_FUNC("CheckConnectorTypeStatus. \n");
|
|
|
+ CheckGunTypeFromHw();
|
|
|
+ PRINTF_FUNC("InitialShareMemoryInfo & Initialization. \n");
|
|
|
+ InitialShareMemoryInfo();
|
|
|
+ PRINTF_FUNC("CheckConnectorTypeStatus. \n");
|
|
|
+ ChangeLcmByIndex(_LCM_INIT);
|
|
|
+ if (!CheckConnectorTypeStatus())
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
|
|
|
+ ChangeLcmByIndex(_LCM_FIX);
|
|
|
+
|
|
|
+ PRINTF_FUNC("Module Name & HW info none match. \n");
|
|
|
+ DEBUG_ERROR_MSG("Module Name & HW info none match. \n");
|
|
|
+ sleep(3);
|
|
|
+ KillTask();
|
|
|
+ StopProcessing();
|
|
|
+ }
|
|
|
+ Initialization();
|
|
|
+ ShmSysConfigAndInfo->SysInfo.InternetConn = 1;
|
|
|
+ PRINTF_FUNC("Spawn all Task. \n");
|
|
|
+ SpawnTask();
|
|
|
+ PRINTF_FUNC("Module Name & HW info correct. Initialize.......\n");
|
|
|
+ CreateTimeoutFork();
|
|
|
+ PRINTF_FUNC("Self test. \n");
|
|
|
+ SelfTestRun();
|
|
|
+ StopSystemTimeoutDet();
|
|
|
+
|
|
|
+ PRINTF_FUNC("SelfTestSeq = %d, Work_Step = %d \n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq, ShmPsuData->Work_Step);
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
|
|
|
+ ShmPsuData->Work_Step == _NO_WORKING)
|
|
|
+ {
|
|
|
+ DisplaySelfTestFailReason();
|
|
|
+ for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, MODE_ALARM);
|
|
|
+ }
|
|
|
+ ChangeLcmByIndex(_LCM_FIX);
|
|
|
+ StopProcessing();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, MODE_IDLE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ChangeLcmByIndex(_LCM_IDLE);
|
|
|
+ sleep(1);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ CreateRfidFork();
|
|
|
+
|
|
|
+ PRINTF_FUNC("Main Loop. \n");
|
|
|
+ for (;;)
|
|
|
+ {
|
|
|
+ CheckOcppStatus();
|
|
|
+ ChkPrimaryStatus();
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_IDLE &&
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_ReturnToChargingGunDet)
|
|
|
+ {
|
|
|
+ CheckFactoryConfigFunction();
|
|
|
+
|
|
|
+ CheckFwUpdateFunction();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ OcppRemoteStartChk();
|
|
|
+
|
|
|
+ ScannerCardProcess();
|
|
|
+ for (byte gun_index = 0; gun_index < _gunCount; gun_index++)
|
|
|
+ {
|
|
|
+ CheckGpioInStatus();
|
|
|
+ CheckErrorOccurStatus(gun_index);
|
|
|
+ ChkOcppStatus(gun_index);
|
|
|
+
|
|
|
+
|
|
|
+ switch(chargingInfo[gun_index]->SystemStatus)
|
|
|
+ {
|
|
|
+ case S_IDLE:
|
|
|
+ case S_RESERVATION:
|
|
|
+ {
|
|
|
+ if (chargingInfo[gun_index]->SystemStatus == S_IDLE &&
|
|
|
+ isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("S_IDLE================================== %x \n", gun_index);
|
|
|
+ chargingInfo[gun_index]->RemainChargingDuration = 0;
|
|
|
+ chargingInfo[gun_index]->PresentChargedEnergy = 0;
|
|
|
+ }
|
|
|
+ else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION &&
|
|
|
+ isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("S_RESERVATION....................%x \n", gun_index);
|
|
|
+ ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
|
|
|
+ {
|
|
|
+ if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
|
|
|
+ }
|
|
|
+ ClearDetectPluginFlag();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ if(isDetectPlugin())
|
|
|
+ {
|
|
|
+
|
|
|
+ if ((ShmSysConfigAndInfo->SysInfo.OrderCharging != FAIL &&
|
|
|
+ ShmSysConfigAndInfo->SysInfo.OrderCharging < _gunCount))
|
|
|
+ {
|
|
|
+ if (chargingInfo[(unsigned char)ShmSysConfigAndInfo->SysInfo.OrderCharging]->ConnectorPlugIn == YES &&
|
|
|
+ chargingInfo[gun_index]->IsAvailable)
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("-----------------1----------------- %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.CurGunSelected = ShmSysConfigAndInfo->SysInfo.OrderCharging;
|
|
|
+ AddPlugInTimes(ShmSysConfigAndInfo->SysInfo.OrderCharging);
|
|
|
+ setChargerMode(ShmSysConfigAndInfo->SysInfo.OrderCharging, MODE_REASSIGN_CHECK);
|
|
|
+ ClearDetectPluginFlag();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable &&
|
|
|
+ chargingInfo[gun_index]->SystemStatus == S_IDLE)
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("-----------------2----------------- \n");
|
|
|
+ ShmSysConfigAndInfo->SysInfo.CurGunSelected = gun_index;
|
|
|
+ AddPlugInTimes(gun_index);
|
|
|
+ strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
|
|
|
+ PRINTF_FUNC("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+
|
|
|
+ setChargerMode(gun_index, MODE_REASSIGN_CHECK);
|
|
|
+ ClearDetectPluginFlag();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isCardScan)
|
|
|
+ {
|
|
|
+
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION)
|
|
|
+ {
|
|
|
+ if (!isReservationExpired(gun_index))
|
|
|
+ {
|
|
|
+ chargingInfo[gun_index]->SystemStatus = S_IDLE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_FREE &&
|
|
|
+ (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("-----------------3----------------- \n");
|
|
|
+ ShmSysConfigAndInfo->SysInfo.CurGunSelected = gun_index;
|
|
|
+ AddPlugInTimes(gun_index);
|
|
|
+ setChargerMode(gun_index, MODE_REASSIGN_CHECK);
|
|
|
+ ClearDetectPluginFlag();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
|
|
|
+
|
|
|
+ if (_gunCount > 1 &&
|
|
|
+ ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
|
|
|
+ ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
|
|
|
+ ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
|
|
|
+ ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG)
|
|
|
+ {
|
|
|
+ for (byte count = 0; count < _gunCount; count++)
|
|
|
+ {
|
|
|
+ if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected &&
|
|
|
+ ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
|
|
|
+ (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1)))
|
|
|
+ {
|
|
|
+ StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ReleaseAlarmCode(gun_index);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_REASSIGN_CHECK:
|
|
|
+ {
|
|
|
+ if (isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("S_REASSIGN_CHECK================================== %x \n", gun_index);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.OrderCharging != FAIL)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.OrderCharging = FAIL;
|
|
|
+ StopSystemTimeoutDet();
|
|
|
+ }
|
|
|
+
|
|
|
+ bool isRessign = false;
|
|
|
+ if (_gunCount > 1)
|
|
|
+ {
|
|
|
+ for (byte index = 0; index < _gunCount; index++)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
|
|
|
+ chargingInfo[index]->SystemStatus >= S_PREPARNING)
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("=============Smart Charging============= Step 1 \n");
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE;
|
|
|
+ isRessign = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isRessign)
|
|
|
+ setChargerMode(gun_index, MODE_REASSIGN);
|
|
|
+ else
|
|
|
+ setChargerMode(gun_index, MODE_PRECHARGE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_REASSIGN:
|
|
|
+ {
|
|
|
+ if (isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("S_REASSIGN================================== %x \n", gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
|
|
|
+ setChargerMode(gun_index, MODE_PRECHARGE);
|
|
|
+ else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY &&
|
|
|
+ ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("=============Smart Charging : _REASSIGNED_COMP============= Step 6 \n");
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
|
|
|
+ }
|
|
|
+
|
|
|
+ PRINTF_FUNC("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_PREPARNING:
|
|
|
+ {
|
|
|
+ if (isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("S_PREPARNING================================== %x \n", gun_index);
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (((ShmPsuData->SystemPresentPsuQuantity > 0 &&
|
|
|
+ ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity > 0 &&
|
|
|
+ ShmPsuData->PsuGroup[gun_index].GroupAvailablePower > 10) &&
|
|
|
+ chargingInfo[gun_index]->AvailableChargingPower > 10))
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isEvBoardStopChargeFlag(gun_index) == YES ||
|
|
|
+ OcppRemoteStop(gun_index) == YES)
|
|
|
+ {
|
|
|
+
|
|
|
+ ChargingTerminalProcess(gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_PREPARING_FOR_EV:
|
|
|
+ {
|
|
|
+ if (isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("S_PREPARING_FOR_EV================================== %x \n", gun_index);
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chargingInfo[gun_index]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (isEvGunLocked_chademo(gun_index) == YES)
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (isEvGunLocked_ccs(gun_index) == YES)
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isEvBoardStopChargeFlag(gun_index) == YES ||
|
|
|
+ OcppRemoteStop(gun_index) == YES)
|
|
|
+ {
|
|
|
+
|
|
|
+ ChargingTerminalProcess(gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_PREPARING_FOR_EVSE:
|
|
|
+ {
|
|
|
+ if (isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("S_PREPARING_FOR_EVSE================================== %x \n", gun_index);
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chargingInfo[gun_index]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (isPrechargeStatus_chademo(gun_index) > 5 && isPrechargeStatus_chademo(gun_index) < 8)
|
|
|
+ {
|
|
|
+
|
|
|
+ setChargerMode(gun_index, MODE_CHARGING);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
|
|
|
+ {
|
|
|
+
|
|
|
+ RecordAlarmCode("012234");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS)
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
|
|
|
+ {
|
|
|
+
|
|
|
+ RecordAlarmCode("012235");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isEvBoardStopChargeFlag(gun_index) == YES ||
|
|
|
+ chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL ||
|
|
|
+ OcppRemoteStop(gun_index) == YES)
|
|
|
+ {
|
|
|
+
|
|
|
+ ChargingTerminalProcess(gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_CHARGING:
|
|
|
+ {
|
|
|
+ if (isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("S_CHARGING================================== %x \n", gun_index);
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ ftime(&startChargingTime[gun_index]);
|
|
|
+ ChangeStartOrStopDateTime(YES, gun_index);
|
|
|
+ OcppStartTransation(gun_index);
|
|
|
+ }
|
|
|
+ ftime(&endChargingTime[gun_index]);
|
|
|
+ chargingInfo[gun_index]->RemainChargingDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
|
|
|
+
|
|
|
+ if (chargingInfo[gun_index]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
|
|
|
+ {
|
|
|
+
|
|
|
+ RecordAlarmCode("012234");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+ if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
|
|
|
+ {
|
|
|
+
|
|
|
+ RecordAlarmCode("012235");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isEvBoardStopChargeFlag(gun_index) ||
|
|
|
+ chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL ||
|
|
|
+ OcppRemoteStop(gun_index) ||
|
|
|
+ CheckBackendChargingTimeout(gun_index) ||
|
|
|
+ CheckBackendChargingEnergy(gun_index))
|
|
|
+ {
|
|
|
+
|
|
|
+ ChargingTerminalProcess(gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_TERMINATING:
|
|
|
+ {
|
|
|
+ if (isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC ("terminating......................... %x \n", gun_index);
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chargingInfo[gun_index]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (isEvStopCharging_chademo(gun_index) == YES ||
|
|
|
+ isPrechargeStatus_chademo(gun_index) <= 0)
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, MODE_COMPLETE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (isEvStopCharging_ccs(gun_index) == YES)
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, MODE_COMPLETE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_COMPLETE:
|
|
|
+ {
|
|
|
+ if (isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC ("complete......................... %x \n", gun_index);
|
|
|
+ OcppStopTransation(gun_index);
|
|
|
+ ftime(&endChargingTime[gun_index]);
|
|
|
+ if (chargingInfo[gun_index]->RemainChargingDuration != 0)
|
|
|
+ chargingInfo[gun_index]->RemainChargingDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ ChangeStartOrStopDateTime(NO, gun_index);
|
|
|
+
|
|
|
+ if (_gunCount == 1 || (_gunCount > 1 && ONE_CONNECTOR_USE == YES))
|
|
|
+ StartGunInfoTimeoutDet(gun_index, Timeout_WaitforCompleteDet);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_CCS_PRECHARGE_ST0:
|
|
|
+ {
|
|
|
+ if (isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("CCS Precharge Processing 1....................%x \n", gun_index);
|
|
|
+ StopGunInfoTimeoutDet(gun_index);
|
|
|
+ StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
|
|
|
+ {
|
|
|
+
|
|
|
+ RecordAlarmCode("012235");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isEvBoardStopChargeFlag(gun_index) == YES ||
|
|
|
+ chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
|
|
|
+ {
|
|
|
+
|
|
|
+ ChargingTerminalProcess(gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40)
|
|
|
+ {
|
|
|
+ if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
|
|
|
+
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
|
|
|
+ chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46)
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case S_CCS_PRECHARGE_ST1:
|
|
|
+ {
|
|
|
+ if (isModeChange(gun_index))
|
|
|
+ {
|
|
|
+ PRINTF_FUNC("CCS Precharge Processing 2....................%x \n", gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
|
|
|
+ {
|
|
|
+
|
|
|
+ RecordAlarmCode("012235");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isEvBoardStopChargeFlag(gun_index) == YES ||
|
|
|
+ chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
|
|
|
+ {
|
|
|
+
|
|
|
+ ChargingTerminalProcess(gun_index);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (chargingInfo[gun_index]->RelayK1K2Status == YES)
|
|
|
+ {
|
|
|
+ chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
|
|
|
+ setChargerMode(gun_index, MODE_CHARGING);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE)
|
|
|
+ {
|
|
|
+ ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ write(wtdFd, "a", 1);
|
|
|
+ usleep(whileLoopTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ return FAIL;
|
|
|
+}
|