#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*標準輸入輸出定義*/ #include /*標準函數庫定義*/ #include /*Unix 標準函數定義*/ #include /*檔控制定義*/ #include /*PPSIX 終端控制定義*/ #include /*錯誤號定義*/ #include #include #include #include #include #include #include "Config.h" #include #include "../../define.h" #include #include "VCCU.h" #include "timeout.h" #include "IOComm.h" #include //write, close, usleep, read #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*標準輸入輸出定義*/ #include /*標準函數庫定義*/ #include /*Unix 標準函數定義*/ #include /*檔控制定義*/ #include /*PPSIX 終端控制定義*/ #include /*錯誤號定義*/ #include #include #include #include #include #include #include "Module_EvComm.h" #include #include #include //write, close, usleep, read #include //uart #define Debug #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0])) //#define PASS 1 #define FAIL -1 #define START 1 #define STOP 0 #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 SendDirection 0x08000000 #define FAIL -1 struct SysConfigAndInfo *ShmSysConfigAndInfo; struct StatusCodeData *ShmStatusCodeData; struct CHAdeMOData *ShmCHAdeMOData; struct CcsData *ShmCcsData; struct RelayModuleData *ShmRelayModuleData; //struct ATE *ate; 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]; struct timeb startPlugPresentStatusTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; struct timeb startDutyCyclTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; struct timeb endPlugPresentStatusTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; struct timeb endDutyCyclTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]; //VCCU_ChargeFromVehicle_DATA chargeFromVehicle; pid_t CANReceiverPid; int CanFd; int CanFd2; #define VIN_MAX_VOLTAGE 250 // 大於該值 : OVP #define VIN_MIN_VOLTAGE 170 // 小於該值 : UVP #define VIN_DROP_VOLTAGE 150 // 小於該值 : ac drop //#define SYSFS_GPIO_DIR "/sys/class/gpio" byte gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // for initial index to check EV board type is correct //char *relayRs485PortName = "/dev/ttyS5"; //char* pPortName = "/dev/ttyS3"; //char *priPortName = "/dev/ttyS1"; #define btoa(x) ((x)?"true":"false") long hexToDec(char *source); int getIndexOfSigns(char ch); int whileLoopTime = 200000;//500ms//10000; // 10 ms int targetCurrent_Value = 120;//2; int targetVoltage_Value = 500; int maximumCurrent_value = 200;//10; int maximumVoltage_value = 500; int linkVoltage = 500; int contactorVoltage = 0;//要用電池載的電壓 int maxValue = 950; int gbmaxValue = 750; int _port; #define YES 1 #define NO 0 byte flash = NO; //================================= // Create all share memory //================================= byte normalStop = 0x01; byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte evstaus[5] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; struct Ev_Board_Cmd Ev_Cmd={ 0, 0x00000200, 0x00000400, 0x00000500, 0x00000600, 0x00000700, 0x00000800, 0x00000900, 0x00000A00, 0x00000C00, 0x00000D00, 0x00000E00, 0x00000F00, 0x00001000, 0x00001100, 0x00001200, 0x00001500, }; int CreatShareMemory() { int MeterSMId; //creat ShmSysConfigAndInfo if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0) { #ifdef SystemLogMessage //StoreLogMsg("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n"); #endif return 0; } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef SystemLogMessage //StoreLogMsg("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n"); #endif return 0; } memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo)); //creat ShmCcsData if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0){ #ifdef SystemLogMessage //StoreLogMsg("[main]CreatShareMemory:shmget ShmCcsData NG \n"); #endif return 0; } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1){ #ifdef SystemLogMessage //StoreLogMsg("[main]CreatShareMemory:shmat ShmCcsData NG \n"); #endif return 0; } memset(ShmCcsData, 0, sizeof(struct CcsData)); //creat ShmRelayModuleData if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0) { #ifdef SystemLogMessage //StoreLogMsg("shmget ShmRelayModuleData NG\n"); #endif return 0; } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1) { #ifdef SystemLogMessage //StoreLogMsg("shmat ShmRelayModuleData NG\n"); #endif return 0; } memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData)); return 1; } unsigned long GetTimeoutValue(struct timeval _sour_time); 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 InitCanBus() { int s0, nbytes; struct timeval tv; struct ifreq ifr0; struct sockaddr_can addr0; /* //can0 system("/sbin/ip link set can0 down");//先將interface disable system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100"); system("/sbin/ip link set can0 up"); */ //can1 system("/sbin/ip link set can0 down");//先將interface disable system("/sbin/ip link set can0 type can bitrate 250000 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 //StoreLogMsg("[CsuComm]InitCanBus:Set SO_RCVTIMEO NG"); #endif } nbytes = 40960; if(setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0) { #ifdef SystemLogMessage //StoreLogMsg("[CsuComm]InitCanBus:Set SO_RCVBUF NG"); #endif } nbytes = 40960; if(setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) { #ifdef SystemLogMessage //StoreLogMsg("[CsuComm]InitCanBus:Set SO_SNDBUF NG"); #endif } //strcpy(ifr0.ifr_name, "can0" ); strcpy(ifr0.ifr_name, "can0" ); ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */ addr0.can_family = AF_CAN; addr0.can_ifindex = ifr0.ifr_ifindex; bind(s0, (struct sockaddr *)&addr0, sizeof(addr0)); return s0; } int CHROMAInitCanBus() { int s0,nbytes; struct timeval tv; struct ifreq ifr0; struct sockaddr_can addr0; system("/sbin/ip link set can1 down"); system("/sbin/ip link set can1 type can bitrate 500000 restart-ms 100"); system("/sbin/ip link set can1 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("Set SO_RCVTIMEO NG"); #endif } nbytes=40960; if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0) { #ifdef SystemLogMessage //DEBUG_ERROR("Set SO_RCVBUF NG"); #endif } nbytes=40960; if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) { #ifdef SystemLogMessage //DEBUG_ERROR("Set SO_SNDBUF NG"); #endif } strcpy(ifr0.ifr_name, "can1" ); ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */ addr0.can_family = AF_CAN; addr0.can_ifindex = ifr0.ifr_ifindex; bind(s0, (struct sockaddr *)&addr0, sizeof(addr0)); return s0; } int DiffTimeb(struct timeb ST, struct timeb ET) { //return milli-second unsigned int StartTime,StopTime; StartTime=(unsigned int)ST.time; StopTime=(unsigned int)ET.time; //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm; return (StopTime-StartTime); } void StopGunInfoTimeoutDet(unsigned char gunIndex) { if (gunIndex < gunCount) { chargingInfo[gunIndex]->TimeoutFlag = 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; } } unsigned short MaxValue(unsigned short value1, unsigned short value2) { return value1 >= value2 ? value1 : value2; } unsigned char isATEChange(unsigned char gun_index) { unsigned char result = NO; if(chargingInfo[gun_index]->ATEState != chargingInfo[gun_index]->PreviousATEState) { result = YES; chargingInfo[gun_index]->PreviousATEState = chargingInfo[gun_index]->ATEState; } return result; } 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; } unsigned char checkMode(byte gun_index, byte mode) { unsigned char result = NO; if(chargingInfo[gun_index]->SystemStatus != mode) { result = YES; } return result; } void setChargerMode(byte gun_index, byte mode) { chargingInfo[gun_index]->SystemStatus = mode; } void setATEMode(byte gun_index, byte mode) { chargingInfo[gun_index]->ATEStatus = mode; } void setStatusMode(byte gun_index, byte mode) { chargingInfo[gun_index]->ATEStatus = mode; } unsigned char isStatusChange(unsigned char gun_index) { unsigned char result = NO; if(chargingInfo[gun_index]->ATEStatus != chargingInfo[gun_index]->PreviousATEStatus) { result = YES; chargingInfo[gun_index]->PreviousATEStatus = chargingInfo[gun_index]->ATEStatus; } return result; } //========================================== // Common Function //========================================== int PackageIdCmd(int cmd) { return cmd | 0x80000000; } void SendCmdToEvboard(int canfd, int cmd, byte *data, byte dataLen) { struct can_frame frame; frame.can_id = PackageIdCmd(cmd);//(0x00001000 + cmd) | 0x80000000;//(cmd | 0x80000000); frame.can_dlc = dataLen; memcpy(frame.data, data, sizeof(frame.data)); write(canfd, &frame, sizeof(struct can_frame)); //usleep(2000); } void setBootNotification1(){ byte data[8]; data[0] = 0x02; data[1] = 0x02; data[2] = 0x02; data[3] = 0x02; data[4] = 0x03; data[5] = 0x03; data[6] = 0x03; data[7] = 0x03; SendCmdToEvboard(CanFd2, bn1, data, sizeof(data)); } void setBootNotification2(){ byte data[8]; data[0] = 0x04; data[1] = 0x04; data[2] = 0x04; data[3] = 0x04; data[4] = 0x05; data[5] = 0x05; data[6] = 0x05; data[7] = 0x05; SendCmdToEvboard(CanFd2, bn2, data, sizeof(data)); } void setEVStatus1(byte evstatus){ byte data[1]; data[0] = evstatus; SendCmdToEvboard(CanFd2, EVStatus1, data, sizeof(data)); } void setEVStatus2(byte evstatus){ byte data[1]; data[0] = evstatus; SendCmdToEvboard(CanFd2, EVStatus2, data, sizeof(data)); } void GetFirmwareVersion(byte gun_index, byte toId) { int id = PackageIdCmd(Ev_Cmd.get_firmware_ver + toId); byte data[8]; SendCmdToEvboard(CanFd, id, data, 0); } void GetHardwareVersion(byte gun_index, byte toId) { int id = PackageIdCmd(Ev_Cmd.get_hardware_ver + toId); byte data[8]; SendCmdToEvboard(CanFd, id, data, 0); } void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputCur, short aOutputVol, byte toId) { int id = PackageIdCmd(Ev_Cmd.charging_permission + toId); byte data[8]; data[0] = permissionStatus; data[1] = aOutputPw & 0xff; data[2] = (aOutputPw >> 8) & 0xff; data[3] = aOutputCur & 0xff; data[4] = (aOutputCur >> 8) & 0xff; data[5] = aOutputVol & 0xff; data[6] = (aOutputVol >> 8) & 0xff; data[7] = 0xff; //printf(" ChargingPermission Get-Msg : %08X - %02x %02x %02x %02x %02x %02x %02x %02x\n ",(Ev_Cmd.charging_permission + toId), data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7] ); SendCmdToEvboard(CanFd, id, data, sizeof(data)); } void GetMiscellaneousInfo(byte gun_index, byte toId, short K1K2Status, short soc) { int id = PackageIdCmd(Ev_Cmd.get_miscellaneous_info + toId); byte data[8]; data[0] = 0x01; data[1] = 0x02; data[2] = 0x03; data[3] = 0x04; data[4] = 0x05; data[5] = K1K2Status & 0xff; data[6] = soc & 0xff; data[7] = 0x08; //printf(" Miscellaneous Info Get-Msg : %08X - %02x %02x %02x %02x %02x %02x %02x %02x\n ",Ev_Cmd.get_miscellaneous_info, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7] ); /* data[1] = 0x0001; data[2] = 0x0001; data[3] = 0x10; data[4] = 0x10; */ SendCmdToEvboard(CanFd, id, data, sizeof(data)); } /* void setMisc(byte toId){ float K1K2Status = 0; float soc = 0; K1K2Status = ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status; soc = ShmSysConfigAndInfo->ate.chademo.id0D_req.Soc; GetMiscellaneousInfo(0, toId, K1K2Status, soc); } */ void SetPresentInputPower(short outputVol_b1, short outputCur_b1, byte toId) { int id = PackageIdCmd(Ev_Cmd.present_input_power + toId); byte data[8]; data[0] = outputVol_b1 & 0xff; data[1] = (outputVol_b1 >> 8) & 0xff; data[2] = outputCur_b1 & 0xff; data[3] = (outputCur_b1 >> 8) & 0xff; /* data[4] = outputVol_b2 & 0xff; data[5] = (outputVol_b2 >> 8) & 0xff; data[6] = outputCur_b2 & 0xff; data[7] = (outputCur_b2 >> 8) & 0xff; */ //printf(" PresentInputPower Get-Msg : %08X - %02x %02x %02x %02x %02x %02x %02x %02x\n ",Ev_Cmd.present_input_power, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7] ); SendCmdToEvboard(CanFd, id, data, sizeof(data)); } void SetPresentInputRequirement(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2, byte toId) { int id = PackageIdCmd(Ev_Cmd.present_input_requirement + toId ); byte data[8]; data[0] = aOutputPw_b1 & 0xff; data[1] = (aOutputPw_b1 >> 8) & 0xff; data[2] = aOutputCur_b1 & 0xff; data[3] = (aOutputCur_b1 >> 8) & 0xff; data[4] = aOutputPw_b2 & 0xff; data[5] = (aOutputPw_b2 >> 8) & 0xff; data[6] = aOutputCur_b2 & 0xff; data[7] = 0x01; /* data[6] = aOutputCur_b2 & 0xff; data[7] = (aOutputCur_b2 >> 8) & 0xff; */ //printf(" Present Input Requirement Get-Msg : %08X - %02x %02x %02x %02x %02x %02x %02x %02x\n ",Ev_Cmd.present_input_requirement, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7] ); SendCmdToEvboard(CanFd, id, data, sizeof(data)); } void GetEvseOutputStatus(byte gun_index, byte toId) { int id = PackageIdCmd(Ev_Cmd.get_evse_output_status + toId); byte data[8]; SendCmdToEvboard(CanFd, id, data, 0); } void GetEvseCapacityInfo(byte gun_index, byte toId) { int id = PackageIdCmd(Ev_Cmd.get_evse_capacity_info + toId); byte data[8]; SendCmdToEvboard(CanFd, id, data, 0); } void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId) { int id = PackageIdCmd(Ev_Cmd.evse_stop_charging + toId); byte data[8]; data[0] = stopResult; data[1] = *stopReason; data[2] = *(stopReason + 1); data[3] = *(stopReason + 2); data[4] = *(stopReason + 3); data[5] = *(stopReason + 4); data[6] = *(stopReason + 5); SendCmdToEvboard(CanFd, id, data, sizeof(data)); } void SetIsolationStatus(byte gun_index, byte result, byte toId) { int id = PackageIdCmd(Ev_Cmd.isolation_status + toId); byte data[8]; data[0] = result; SendCmdToEvboard(CanFd, id, data, 1); } void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId) { int id = PackageIdCmd(Ev_Cmd.evse_precharge_info + toId); byte data[8]; data[0] = result; SendCmdToEvboard(CanFd, id, data, 1); } void handleEmulatorFaultStatus(){ setEVStatus2(evstaus[4]); ShmSysConfigAndInfo->ate.Permission = STOP; setStatusMode(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission); ShmSysConfigAndInfo->ate.ATEStatus = 0x00; SetChargingPermission(CCS_QUANTITY, ShmSysConfigAndInfo->ate.Permission, ShmSysConfigAndInfo->ate.TotalBatteryCap, ShmSysConfigAndInfo->ate.MaxBatteryCurrent, ShmSysConfigAndInfo->ate.MaxBatteryVoltage, 1); EvseStopChargingEvent(normalStop, stopReason, 1); } int bitExtracted(byte number, int k, int p) { return (((1 << k) - 1) & (number >> (p - 1))); } unsigned short bitextract(unsigned short value, int begin, int end) { unsigned short mask = (1 << (end - begin)) - 1; return (value >> begin) & mask; } bool CheckUniqNumber(byte value) { for (byte index = 0; index < gunCount; index++) { if (chargingInfo[index]->Evboard_id == value) { struct timeval _end_time; gettimeofday(&_end_time, NULL); unsigned long diff = 1000000 * (_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec; if (diff >= 3000000) { gettimeofday(&_id_assign_time, NULL); return true; } else { return false; } } } gettimeofday(&_id_assign_time, NULL); return true; } void SetTargetAddr(byte *target_number, byte index) { int id = PackageIdCmd(Ev_Cmd.address_assignment + index); //printf("intCmd = %x \n", cmd & CAN_EFF_MASK); //cmd = cmd & CAN_EFF_MASK; byte data[8]; data[0] = *target_number; data[1] = *(target_number + 1); data[2] = *(target_number + 2); data[3] = *(target_number + 3); data[4] = index; SendCmdToEvboard(CanFd2, id, data, sizeof(data)); } void AddrAssignment(byte *data) { byte target_number[8]; byte index = 0x00; memcpy(target_number, data, sizeof(target_number)); index = *(data + 4); if (CheckUniqNumber(index)) { printf("EV board id = %x \n", index); // printf("target_number[0] = %x \n", target_number[0]); // printf("target_number[1] = %x \n", target_number[1]); // printf("target_number[2] = %x \n", target_number[2]); // printf("target_number[3] = %x \n", target_number[3]); // printf("target_number[4] = %x \n", target_number[4]); if (index < 1) return; printf("SetTargetAddr \n"); SetTargetAddr(target_number, index); } } void VCCU_TD(){ byte data[8]; data[0] = 0x00; data[1] = 0x00; data[2] = 0x01; data[3] = 0x01; data[4] = 0x00; data[5] = 0x00; data[6] = 0x42; data[7] = 0x66; SendCmdToEvboard(CanFd, TDId, data, sizeof(data)); } void VCCU_ChargeFromVehicle(int canfd, int linkVoltage, int contactorVoltage, int chargePermission, int isolationMeasurem, int plugLockPermissio, int plugUnlockPermiss, int contactorStatus){ struct VCCU_ChargeFromVehicle obj; obj.VCCU_Vehicle_LinkVoltage= linkVoltage;//500 obj.VCCU_Vehicle_ContactorVoltage = contactorVoltage;//0 obj.DATA.bits.VCCU_Vehicle_ChargePermission = chargePermission;//Not_allowed obj.DATA.bits.VCCU_Vehicle_IsolationMeasurem = isolationMeasurem;//Active obj.DATA.bits.VCCU_Vehicle_PlugLockPermissio = plugLockPermissio;//Allowed//Not_allowed; obj.DATA.bits.VCCU_Vehicle_PlugUnlockPermiss = plugUnlockPermiss;//Not_allowed obj.bits.VCCU_Vehicle_ContactorStatus = contactorStatus;//Open obj.bits.VCCU_Vehicle_StopCharge = 3;//Open obj.bits.VCCU_Vehicle_ChargeSelection = 3;//Open byte* data1; data1 = (byte*) &(*((UWORD *) &obj.VCCU_Vehicle_ContactorVoltage)); byte* data2; data2 = (byte*) &(*((UWORD *) &obj.VCCU_Vehicle_LinkVoltage)); byte data[6]; data[0] = data1[0]; data[1] = data1[1]; data[2] = data2[0]; data[3] = data2[1]; data[4] = *((UBYTE *) &obj.DATA); data[5] = *((UBYTE *) &obj.bits); //printf("%02x %02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4], data[5] ); SendCmdToEvboard(canfd, VCCU_ChargeFromVehicleIds, data, sizeof(data)); } //0x18FF3082 void VCCU_V2G_VehicleStatus(int canfd, int EnergyTra, int EVErrorCode, int EVPowerDeliveryParame, int EVRESSSOC, int EVRESSConditioningFla, int EVRESSConditionin, int EVReady, int BulkChargingCompleteF, int EVCabinConditioningFl, int EVCabinConditioning, int ChargingComplete, int FullSOCFlag, int FullSOC, int BulkSOCFlag, int BulkSOC, int BulkChargingComplete, int BulkChargingCompleteFValue){ struct VCCU_V2G_VehicleStatus obj; obj.DATA4.VCCU_V2G_StateM_EnergyTra_0000 = EnergyTra;//VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended; obj.DATA1.VCCU_V2G_EVErrorCode = EVErrorCode;//0; obj.DATA4.VCCU_V2G_EVPowerDeliveryParame = EVPowerDeliveryParame;//3; obj.VCCU_V2G_EVRESSSOC.value = EVRESSSOC;//0; obj.DATA3.VCCU_V2G_EVRESSConditioningFla = EVRESSConditioningFla;//3; obj.DATA3.VCCU_V2G_EVRESSConditioning = EVRESSConditionin;//3; obj.DATA3.VCCU_V2G_EVReady = EVReady;//3; obj.DATA1.VCCU_V2G_BulkChargingCompleteF = BulkChargingCompleteF;//3; obj.DATA3.VCCU_V2G_EVCabinConditioningFl = EVCabinConditioningFl;//3; obj.DATA2.VCCU_V2G_EVCabinConditioning = EVCabinConditioning;//3; obj.DATA2.VCCU_V2G_ChargingComplete = ChargingComplete;//3; obj.DATA2.VCCU_V2G_FullSOCFlag = FullSOCFlag;//0; obj.VCCU_V2G_FullSOC.value = FullSOC;//3; obj.DATA2.VCCU_V2G_BulkSOCFlag = BulkSOCFlag;//3; obj.VCCU_V2G_BulkSOC.value = BulkSOC;//0; obj.DATA1.VCCU_V2G_BulkChargingComplete = BulkChargingComplete;//3; obj.DATA1.VCCU_V2G_BulkChargingCompleteF = BulkChargingCompleteFValue;//3; byte data[7]; data[0] = *((UBYTE *) &obj.DATA1); data[1] = *((UBYTE *) &obj.DATA2); data[2] = *((UBYTE *) &obj.DATA3); data[3] = *((UBYTE *) &obj.DATA4); data[4] = *((UBYTE *) &obj.VCCU_V2G_BulkSOC); data[5] = *((UBYTE *) &obj.VCCU_V2G_FullSOC); data[6] = *((UBYTE *) &obj.VCCU_V2G_EVRESSSOC); //printf("%02x %02x %02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4], data[5] , data[6]); SendCmdToEvboard(canfd, VCCU_V2G_VehicleStatusIds, data, sizeof(data)); } void VCCU_V2G_EVMaximumVoltageLimit(int VMaximumVoltageLimit, int EVMaximumVoltage_0002, int EVMaximumVoltage_0000, int EVMaximumVoltage_0001, int EVMaximumVoltage_0003){ struct VCCU_V2G_EVMaximumVoltageLimit obj; obj.DATA1.VCCU_V2G_EVMaximumVoltageLimit = VMaximumVoltageLimit;//1 obj.DATA1.VCCU_V2G_EVMaximumVoltage_0002 = EVMaximumVoltage_0002;//5 obj.VCCU_V2G_EVMaximumVoltage_0000.value = EVMaximumVoltage_0000;//520 obj.VCCU_V2G_EVMaximumVoltage_0001.value = EVMaximumVoltage_0001;//1 obj.VCCU_V2G_EVMaximumVoltage_0003.value = EVMaximumVoltage_0003;//0 byte* data1; data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVMaximumVoltage_0000)); byte data[5]; data[0] = *((UBYTE *) &obj.DATA1); data[1] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumVoltage_0003); data[2] = data1[0]; data[3] = data1[1]; data[4] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumVoltage_0001); //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]); SendCmdToEvboard(CanFd, VCCU_V2G_EVMaximumVoltageLimitIds, data, sizeof(data)); } void VCCU_V2G_EVMaximumCurrentLimit(int EVMaximumCurrentLimit, int EVMaximumCurrent_0000, int EVMaximumCurrent_0001, int EVMaximumCurrent_0002, int EVMaximumCurrent_0003){ struct VCCU_V2G_EVMaximumCurrentLimit obj; obj.DATA1.VCCU_V2G_EVMaximumCurrentLimit = EVMaximumCurrentLimit;//1 obj.DATA1.VCCU_V2G_EVMaximumCurrent_0000 = EVMaximumCurrent_0000;//3 obj.VCCU_V2G_EVMaximumCurrent_0001.value = EVMaximumCurrent_0001;//1 obj.VCCU_V2G_EVMaximumCurrent_0002.value = EVMaximumCurrent_0002;//0 obj.VCCU_V2G_EVMaximumCurrent_0003.value = EVMaximumCurrent_0003;//10 byte* data1; data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVMaximumCurrent_0003)); byte data[5]; data[0] = *((UBYTE *) &obj.DATA1); data[1] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumCurrent_0002); data[2] = data1[0]; data[3] = data1[1]; data[4] = *((UBYTE *) &obj.VCCU_V2G_EVMaximumCurrent_0001); //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]); SendCmdToEvboard(CanFd, VCCU_V2G_EVMaximumCurrentLimitIds, data, sizeof(data)); } void VCCU_V2G_EVTargetCurrent(int EVTargetCurrent_Unit, int EVTargetCurrent_Value, int EVTargetCurrent_UnitF, int EVTargetCurrent_Multi){//05 00 00 01 03 struct VCCU_V2G_EVTargetCurrent obj; obj.VCCU_V2G_EVTargetCurrent_Unit.value = EVTargetCurrent_Unit;//3 obj.VCCU_V2G_EVTargetCurrent_Value.value = EVTargetCurrent_Value;//5 obj.VCCU_V2G_EVTargetCurrent_UnitF.value = EVTargetCurrent_UnitF;//1 obj.VCCU_V2G_EVTargetCurrent_Multi.value = EVTargetCurrent_Multi;//0 byte* data1; data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVTargetCurrent_Value)); byte data[5]; data[0] = data1[0]; data[1] = data1[1]; data[2] = *((UBYTE *) &obj.VCCU_V2G_EVTargetCurrent_Multi); data[3] = *((UBYTE *) &obj.VCCU_V2G_EVTargetCurrent_UnitF); data[4] = *((UBYTE *) &obj.VCCU_V2G_EVTargetCurrent_Unit); //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]); SendCmdToEvboard(CanFd, VCCU_V2G_EVTargetCurrentIds, data, sizeof(data)); } void VCCU_V2G_EVTargetVoltage(int EVTargetVoltage_Value, int EVTargetVoltage_Unit, int EVTargetVoltage_UnitF, int EVTargetVoltage_Multi){//C2 01 00 01 05 struct VCCU_V2G_EVTargetVoltage obj; obj.VCCU_V2G_EVTargetVoltage_Value.value = EVTargetVoltage_Value;//450 obj.VCCU_V2G_EVTargetVoltage_Unit.value = EVTargetVoltage_Unit;//5 obj.VCCU_V2G_EVTargetVoltage_UnitF.value = EVTargetVoltage_UnitF;//1 obj.VCCU_V2G_EVTargetVoltage_Multi.value = EVTargetVoltage_Multi;//0 byte* data1; data1 = (byte*) &(*((UWORD *) &obj.VCCU_V2G_EVTargetVoltage_Value)); byte data[5]; data[0] = data1[0]; data[1] = data1[1]; data[2] = *((UBYTE *) &obj.VCCU_V2G_EVTargetVoltage_Multi); data[3] = *((UBYTE *) &obj.VCCU_V2G_EVTargetVoltage_UnitF); data[4] = *((UBYTE *) &obj.VCCU_V2G_EVTargetVoltage_Unit); //printf("%d %02x %02x \n",obj.VCCU_V2G_EVTargetVoltage_Value.value, data[0], data[1]); //printf("%02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4]); SendCmdToEvboard(CanFd, VCCU_V2G_EVTargetVoltageIds, data, sizeof(data)); } void VCCU_Requests(int LED0, int LED1, int LED2, int HighSideOut0, int HighSideOut1, int HighSideOut2, int HighSideOut3, int HighSideOut4, int RTC_TimerRequest, int PlugLock, int RTC_TimerValue, int ControlPilot, int ChargeUnit, int Inlet){ struct VCCU_Requests obj; obj.VCCU_LED0_Request = LED0;//0.0 obj.VCCU_LED1_Request = LED1;//0.0 obj.VCCU_LED2_Request = LED2;//0.0 obj.byte3.VCCU_HighSideOut0_Request = HighSideOut0;//3 obj.byte3.VCCU_HighSideOut1_Request = HighSideOut1;//3 obj.byte3.VCCU_HighSideOut2_Request = HighSideOut2;//3 obj.byte3.VCCU_HighSideOut3_Request = HighSideOut3;//3 obj.byte4.VCCU_HighSideOut4_Request = HighSideOut4;//3 obj.byte4.VCCU_RTC_TimerRequest = RTC_TimerRequest;//3 obj.byte4.VCCU_PlugLock_MotorRequest = PlugLock;//7 obj.VCCU_RTC_TimerValue= RTC_TimerValue;//0 obj.byte6.VCCU_ControlPilot_ChargeModeRe = ControlPilot;//7 obj.byte6.VCCU_ChargeUnit_Request = ChargeUnit;//3 obj.byte6.VCCU_Inlet_MotorRequest = Inlet;//3 byte data[7]; data[0] = *((UBYTE *) &obj.VCCU_LED0_Request); data[1] = *((UBYTE *) &obj.VCCU_LED1_Request); data[2] = *((UBYTE *) &obj.VCCU_LED2_Request); data[3] = *((UBYTE *) &obj.byte3); data[4] = *((UBYTE *) &obj.byte4); data[5] = *((UBYTE *) &obj.VCCU_RTC_TimerValue); data[6] = *((UBYTE *) &obj.byte6); //printf("%02x %02x %02x %02x %02x %02x %02x \n", data[0], data[1], data[2], data[3], data[4], data[5] , data[6]); SendCmdToEvboard(CanFd, VCCU_RequestsIds, data, sizeof(data)); } bool MatedPlugInletUnlocked_Status(){ return (ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_Inlet_ConnectionStatus == VCCU_InletStatus_Connected && //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == ChargeV2G //&& ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_Voltage - 32000 == 9 ); } bool PreCharge_Statue(){ return ((ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PreCharge ) && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateC && //(ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_Voltage.bits.value / 2) == 6 && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Not_requested); } bool status1(){ bool result = false; result = (ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Unlocked ); return result; } bool status2(){ bool result = false; result = ((ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_DutyCycle.bits.value >= 5 && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_DutyCycle.bits.value <= 7) && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Locked && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == EVSEStateB2 && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_DigitalInput_Status == Not_pressed && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_S3Switch_Status == Not_pressed); return result; } bool UnmatedPlug(){ bool result = false; /* printf("VCCU_V2G_StateM_StateMachineSt = %d VCCU_ChargeUnit_State = %d VCCU_ChargeUnit_Mode = %d VCCU_Vehicle_ContactorRequest = %d VCCU_Vehicle_IsolationMea_0000 = %d \n", ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt, ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State, ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode, ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.Data.bits.VCCU_Vehicle_ContactorRequest, ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.Data.bits.VCCU_Vehicle_IsolationMea_0000); */ if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_Initialized && //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Not_connected && //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_Inlet_ConnectionStatus == VCCU_InletStatus_Not_connected && //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked && (ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateA || ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateE || ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB1) && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == VCCU_ChargeUnit_Mode_SNA && //ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_Voltage == 0 && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == ForceOpen && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Requested ){ //TODO result = true; //printf("CCS DC01....................\n"); //VCCU_ChargeFromVehicle(CanFd, 500, 0, Not_allowed, Active, Not_allowed, Not_allowed, Opened); setChargerMode(CCS_QUANTITY, V_UNMATEDPLUG); } return result; } bool MatedPlugInletUnlocked(){ bool result = false; if(MatedPlugInletUnlocked_Status() && chargingInfo[CCS_QUANTITY]->SystemStatus == V_IDLE){//(DC02) Mated Plug - Inlet Unlocked //TODO result = true; //VCCU_ChargeFromVehicle(CanFd, 500, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); setChargerMode(CCS_QUANTITY, V_MATED_PLUG_INLET_UNLOCKED); } return result; } bool InletLocking(){ bool result = false; if(//ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 status1() && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Inlet_MotorStatus_Moving ){//(DC03) Inlet Locking result = true; //printf("CCS DC03....................\n"); /* if(ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected &&//PlugPresent_Status == Connected for >=2s //ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle && //ControlPilot_DutyCycle == valid for >= 2s ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked){ }*/ setChargerMode(CCS_QUANTITY, V_INLETLOCKING); } return result; } bool InletLocked(){ bool result = false; if(MatedPlugInletUnlocked_Status() && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Locked){//DC04) Inlet Locked result = true; /* if(ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Inlet_MotorStatus_Moving){ }*/ setChargerMode(CCS_QUANTITY, V_INLETLOCKED); } return result; } bool DC05_Status(){ return (status1() && status2() && (ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SLAC || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == WaitForIP || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SECCDiscoveryProtocol || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == TLConnection || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SupportedAppProtocol || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == SessionSetup || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == ServiceDiscovery || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == ServiceDetails || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PaymentServiceSelection || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CertificateInstallation || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CertificateUpdate || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PaymentDetails || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PaymentDetails || ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == Authorization ) && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Open); } bool S_SLAC(){ bool result = false; if(MatedPlugInletUnlocked_Status() && DC05_Status()){ result = true; /* if(ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Locked && (ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle >= 5 || ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle <= 7) && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_DigitalInput_Status == Not_pressed && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_S3Switch_Status == Not_pressed&& ShmSysConfigAndInfo->ate.vccu.ptc1.VCCU_PTC1_Temperature < 90){ }*/ setChargerMode(CCS_QUANTITY, V_SLAC); } return result; } bool Definition(){ bool result = false; if(MatedPlugInletUnlocked_Status() && (ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == ChargeParameterDiscovery ) && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Open){ result = true; /* VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, 520, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, 10); */ setChargerMode(CCS_QUANTITY, V_DEFINITION); } return result; } bool S_CableCheck(){ bool result = false; if(MatedPlugInletUnlocked_Status() && (ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CableCheck )){ result = true; //VCCU_ChargeFromVehicle(CanFd, 500, 0, Allowed, Active, Allowed, Not_allowed, Opened); setChargerMode(CCS_QUANTITY, V_CABLECHECK); } return result; } bool Isolation(){ bool result = false; if(MatedPlugInletUnlocked_Status() && PreCharge_Statue()){ result = true; //VCCU_ChargeFromVehicle(CanFd, 500, 0, Allowed, Not_Active, Allowed, Not_allowed, Opened); setChargerMode(CCS_QUANTITY, V_ISOLATION); } return result; } bool S_PreCharge(){ bool result = false; if(PreCharge_Statue()){ //VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Opened); //VCCU_V2G_EVTargetCurrent(U_A, 5, TRUE, 0); setChargerMode(CCS_QUANTITY, V_VOLTAGEDIFFERENCE); } return result; } bool Contactors(){ bool result = false; if( PreCharge_Statue() //&& ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Close ){ result = true; //VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Closed); setChargerMode(CCS_QUANTITY, V_CONTACTORSCLOSED); /* if (GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer) >= 7000000) { ftime(&startChargingTime[CCS_QUANTITY]); chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0; StopGunInfoTimeoutDet(CCS_QUANTITY); StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing); } */ } return result; } bool S_PowerDelivery(){ bool result = false; /* * ((ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PreCharge ) && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateC && //(ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.ControlPilot_Voltage.bits.value / 2) == 6 && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Not_requested) ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_ChargePermission ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.bits.VCCU_Vehicle_ContactorStatus * */ if(ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateC && chargingInfo[CCS_QUANTITY]->SystemStatus == V_CONTACTORSCLOSED && ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PowerDelivery && //ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PreCharge && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Not_requested && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Close ){ result = true; //printf("status CCS PowerDelivery %d %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt, ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest); //VCCU_V2G_EVTargetVoltage(450, U_V, TRUE, 0); setChargerMode(CCS_QUANTITY, V_POWERDELIVERY); } return result; } bool S_CurrentDemand(){ bool result = false; if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == CurrentDemand){//(DC12) Current Demand result = true; //TODO stop setChargerMode(CCS_QUANTITY, V_CURRENTDEMAND); } return result; } bool PowerDeliveryFalse(){ bool result = false; if( chargingInfo[CCS_QUANTITY]->SystemStatus == V_CURRENTDEMAND && ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == PowerDelivery && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest == Open //&& ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State != EVSEStateC ){//(DC13) PowerDelivery result = true; setChargerMode(CCS_QUANTITY, V_POWERDELIVERYFALSE); //printf("CCS POWERDELIVERYFALSE Processing 14 VCCU_V2G_StateM_StateMachineSt = %d VCCU_ChargeUnit_State = %d VCCU_Vehicle_IsolationMea_0000 = %d ....................\n" , ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt, ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State, ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000); } return result; } bool S_WeldingDetection(){ bool result = false; if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == WeldingDetection){//(DC14) Welding Detection result = true; setChargerMode(CCS_QUANTITY, V_DETECTION); } return result; } bool SessionStop(){ bool result = false; if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_SessionStop && ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000 == Requested){//Session Stop result = true; setChargerMode(CCS_QUANTITY, V_SESSION_STOP); } return result; } bool StopCommunicationSession(){ bool result = false; if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_StopCommunicationSession ){//Stop Communication Session result = true; setChargerMode(CCS_QUANTITY, V_STOP_COMMUNICATION_SESSION); } return result; } bool DCFinished(){ bool result = false; if(ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt == StateM_Finished ){//Finished result = true; setChargerMode(CCS_QUANTITY, V_FINISHED); } return result; } bool statusCheck(){ bool result = false; //VCCU_TD(); UnmatedPlug(); MatedPlugInletUnlocked(); InletLocking(); InletLocked(); S_SLAC(); Definition(); S_CableCheck(); Isolation(); S_PreCharge(); Contactors(); S_PowerDelivery(); S_CurrentDemand(); PowerDeliveryFalse(); S_WeldingDetection(); SessionStop(); StopCommunicationSession(); DCFinished(); return result; } bool AcUnmatedPlug(){ bool result = false; if((ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateA || ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateE || ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB1) && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == VCCU_ChargeUnit_Mode_SNA ){ //TODO result = true; setChargerMode(CCS_QUANTITY, V_UNMATEDPLUG); } return result; } bool AcMatedPlugInletUnlocked(){ bool result = false; if( (ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA7.bits.VCCU_Inlet_ConnectionStatus == VCCU_InletStatus_Connected && //ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 && ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_Mode == ChargePwm //&& ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_Voltage - 32000 == 9 ) && chargingInfo[CCS_QUANTITY]->SystemStatus == V_IDLE){//(DC02) Mated Plug - Inlet Unlocked //TODO result = true; //VCCU_ChargeFromVehicle(CanFd, 500, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); setChargerMode(CCS_QUANTITY, V_MATED_PLUG_INLET_UNLOCKED); } return result; } bool acInletLocking(){ bool result = false; if(//ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State == EVSEStateB2 (ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Unlocked && ((chargingInfo[CCS_QUANTITY]->PlugPresentStatusDuration >= 2) && chargingInfo[CCS_QUANTITY]->DutyCycleDuration >= 2)) && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == VCCU_Inlet_MotorStatus_Moving ){//(DC03) Inlet Locking result = true; //printf("CCS DC03....................\n"); /* if(ShmSysConfigAndInfo->ate.vccu.chargeFromVehicle.DATA.bits.VCCU_Vehicle_PlugLockPermissio == Allowed && ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected &&//PlugPresent_Status == Connected for >=2s //ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.VCCU_ControlPilot_DutyCycle && //ControlPilot_DutyCycle == valid for >= 2s ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA5.bits.VCCU_Inlet_MotorStatus == Unlocked){ }*/ setChargerMode(CCS_QUANTITY, V_INLETLOCKING); } return result; } bool acStatusCheck(){ bool result = false; AcUnmatedPlug(); AcMatedPlugInletUnlocked(); return result; } long hexToDec(char *source) { long sum = 0; long t = 1; int i, len; len = strlen(source); for(i=len-1; i>=0; i--) { sum += t * getIndexOfSigns(*(source + i)); t *= 16; } return sum; } int getIndexOfSigns(char ch) { if(ch >= '0' && ch <= '9') { return ch - '0'; } if(ch >= 'A' && ch <='F') { return ch - 'A' + 10; } if(ch >= 'a' && ch <= 'f') { return ch - 'a' + 10; } return -1; } void Initialization(){ char *moduleName = "DMYZ30100J01P0"; memcpy(&ShmSysConfigAndInfo->SysConfig.ModelName, moduleName, strlen(moduleName)); //printf("%s \n", ShmSysConfigAndInfo->SysConfig.ModelName); ShmSysConfigAndInfo->SysInfo.CcsChargingData[CCS_QUANTITY].Index = CCS_QUANTITY; ShmSysConfigAndInfo->SysInfo.CcsChargingData[CCS_QUANTITY].slotsIndex = 1; chargingInfo[CCS_QUANTITY] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[CCS_QUANTITY]; chargingInfo[CCS_QUANTITY]->SystemStatus = V_IDLE; chargingInfo[CCS_QUANTITY]->Type = _Type_CCS; chargingInfo[CCS_QUANTITY]->type_index = CCS_QUANTITY; chargingInfo[CCS_QUANTITY]->Evboard_id = 0x01; ShmSysConfigAndInfo->ate.ATEStatus = 0; // 現階段預設為走 DIN70121 ShmCcsData->CommProtocol = 0x01; //return PASS; } bool CheckConnectorTypeStatus() { bool result = true; return result; } void SpawnTask() { sleep(2); system("/root/Module_InternalComm &"); system("/root/Module_EvComm &"); //return PASS; } void KillTask() { system("killall Module_InternalComm"); system("killall Module_EvComm"); } int main(void){ //Create all share memory //printf("=====Initializing. \n"); //ate = malloc( sizeof(ate) ); if(CreatShareMemory()==0){ #ifdef SystemLogMessage //DEBUG_ERROR("CreatShareMemory NG \n"); #endif if(ShmStatusCodeData!=NULL) { //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1; } return 0; sleep(5); system("reboot -f"); } /* int a=2; int *b; b = &a; printf("%p\n", &a); printf("%d\n", *b); printf("%p\n", b); printf("%p\n", &b); *//* int a = 2; int b = 3; a = a^b; b = a^b; a = a^b; printf("%d %d", a, b); const char *SystemId="0101"; printf("%c %p =====\n", *SystemId, &SystemId); strcpy((char *)&ShmSysConfigAndInfo->SysConfig.SystemId,SystemId); char *SystemIdStr = (char *)&ShmSysConfigAndInfo->SysConfig.SystemId; printf("%s =====\n", SystemIdStr);*/ //SpawnTask(); //KillTask(); KillTask(); ///CanFd = InitCanBus(); //CanFd2 = CHROMAInitCanBus(); Initialization(); SpawnTask(); //CANReceiver(); //CHROMACANReceiver(); //printf ("vccu 1===== CanFd2:%d. \n", CanFd2); //setChargerMode(CCS_QUANTITY, V_IDLE); /* struct timeb tp; unsigned int StartTime,StopTime; //ftime(&tp); ftime(&startChargingTime[CCS_QUANTITY]); // StartTime = (int)startChargingTime[CCS_QUANTITY].time; printf("%u\n", StartTime); sleep(2); ftime(&tp); ftime(&endChargingTime[CCS_QUANTITY]); StopTime = (int)endChargingTime[CCS_QUANTITY].time; printf("%u\n", StopTime); */ /* gpio_set_direction(1, GPIO_DIR_INPUT); gpio_set_direction(2, GPIO_DIR_INPUT); gpio_set_direction(3, GPIO_DIR_INPUT); gpio_write(1, 0); gpio_write(3, 0); gpio_write(3, 1); gpio_write(3, 1); */ /* int pinIn[2] = { 1, 3 }; system("echo 1 > /sys/class/gpio/export"); system("echo \"out\" > /sys/class/gpio/gpio1/direction"); system("echo 1 > /sys/class/gpio/gpio1/value"); system("echo 3 > /sys/class/gpio/export"); system("echo \"out\" > /sys/class/gpio/gpio3/direction"); system("echo 1 > /sys/class/gpio/gpio3/value"); gpio_set_direction(1, GPIO_DIR_OUTPUT); gpio_set_direction(4, GPIO_DIR_OUTPUT); gpio_write(1, 0); gpio_write(4, 0); for (int i = 0; i < ARRAY_SIZE(pinIn); i++) { }*/ //Uart1Fd = Init407ComPort(); //printf("407 Port id = %d \n", Uart1Fd); //int led = gpio_read(3); //printf("led === %d \n", led); //printf("%d %d %d %d %d %d \n", ShmSysConfigAndInfo->ate.targetCurrent_Value, ShmSysConfigAndInfo->ate.targetVoltage_Value, ShmSysConfigAndInfo->ate.maximumCurrent_value, ShmSysConfigAndInfo->ate.maximumVoltage_value, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.contactorVoltage); /* InitRS485DirectionIO(); // Open Uart5 for RB Uart5Fd = InitComPort(); for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++) { outputRelay.relay_event.relay_status[index] = 0x00; } memset(®Relay, 0xFF,sizeof(Relay)); outputRelay.relay_event.bits.AC_Contactor = 0x00; outputRelay.relay_event.bits.CCS_Precharge = 0x00; outputRelay.relay_event.bits.Gun1_P = 0x00; outputRelay.relay_event.bits.Gun1_N = 0x00; outputRelay.relay_event.bits.Gun2_P = 0x00; outputRelay.relay_event.bits.Gun2_N = 0x00; //outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00; //outputRelay.relay_event.bits.Gun1_Parallel_P = 0x01; sleep(1); if(Uart5Fd < 0){ printf ("open port error. \n"); return 0; }*/ //usleep(300000); ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status=0x00; ShmSysConfigAndInfo->ate.chademo.id0D_req.Soc = 50; ShmSysConfigAndInfo->ate.ateMode = 0; ShmSysConfigAndInfo->ate.ATEState = 2;//1:ccs 2:gb /* outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00; outputRelay.relay_event.bits.Gun1_Parallel_P = 0x00; flash = YES; SetOutputGpio(!flash); return 0; */ /**/ //byte priorityLow = 1; /**/ //byte normalStop = 0x01; //byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //byte evstaus[5] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; //PresentInputRequirement /* typedef enum { ESIdle = 0x01; ESPreparing = 0x02; ESCharging = 0x03; ESChargingTerminating = 0x04; ESFault = 0x05; }EmulatorStatus; */ //setStatusMode(CCS_QUANTITY, STOP); //CCS ShmSysConfigAndInfo->ate.targetCurrent_Value = targetCurrent_Value; ShmSysConfigAndInfo->ate.targetVoltage_Value = targetVoltage_Value; ShmSysConfigAndInfo->ate.maximumCurrent_value = maximumCurrent_value; ShmSysConfigAndInfo->ate.maximumVoltage_value = maximumVoltage_value; ShmSysConfigAndInfo->ate.linkVoltage = linkVoltage; ShmSysConfigAndInfo->ate.contactorVoltage = contactorVoltage;//contactorVoltage; //GB //ShmSysConfigAndInfo->ate.PresentBattVoltage = 4700; ShmSysConfigAndInfo->ate.PresentBattVoltage = 4700; ShmSysConfigAndInfo->ate.MinimumChargeCurrent = 20; //ShmSysConfigAndInfo->ate.RequireVoltage = 4800; ShmSysConfigAndInfo->ate.RequireVoltage = 4800; //ShmSysConfigAndInfo->ate.RequireVoltage = 4700; ShmSysConfigAndInfo->ate.RequireCurrent = 600; ShmSysConfigAndInfo->ate.chademoTargetVoltage_Value = 4800; ShmSysConfigAndInfo->ate.chademoTargetCurrent_Value = 30; //ShmSysConfigAndInfo->ate.targetCurrent_Value = 1200; ShmSysConfigAndInfo->ate.Permission = STOP; ShmSysConfigAndInfo->ate.TotalBatteryCap = 1000; //0.1 ShmSysConfigAndInfo->ate.MaxBatteryCurrent = 1200; //0.1 ShmSysConfigAndInfo->ate.MaxBatteryVoltage = 5000; //0.1 ShmSysConfigAndInfo->ate.status = 0; ShmSysConfigAndInfo->ate.chademo.id03.state = 0; ShmSysConfigAndInfo->ate.ATEStatus = 0x00; ShmSysConfigAndInfo->ate.cstatus = 0; ShmSysConfigAndInfo->ate.chademo.PresentChargedDuration = 0; ShmSysConfigAndInfo->ate.chademo.RemainChargingDuration = 0; setStatusMode(CCS_QUANTITY, STOP); if(ShmSysConfigAndInfo->ate.ATEState == 1){ }else if(ShmSysConfigAndInfo->ate.ATEState == 2){ } setATEMode(CCS_QUANTITY, ShmSysConfigAndInfo->ate.ATEState); ftime(&startChargingTime[CCS_QUANTITY]); chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0; StopGunInfoTimeoutDet(CCS_QUANTITY); StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing); // printf("version = ....................\n" ); while(true){ //ShmSysConfigAndInfo->ate.ATEState if(ShmSysConfigAndInfo->ate.ATEState == 1){//VCCU //TODO //ShmSysConfigAndInfo->ate.ateMode = 0; }else if(ShmSysConfigAndInfo->ate.ATEState == 2){//GB //TODO //ShmSysConfigAndInfo->ate.ateMode = 0; }else{//none // init } int state = isATEChange(CCS_QUANTITY); if(state){ //TODO } if(ShmSysConfigAndInfo->ate.ATEState == 1){//VCCU /* ftime(&endChargingTime[CCS_QUANTITY]); chargingInfo[CCS_QUANTITY]->RemainChargingDuration = DiffTimeb(startChargingTime[CCS_QUANTITY], endChargingTime[CCS_QUANTITY]); //GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer); printf("%d %d ....................\n",chargingInfo[CCS_QUANTITY]->RemainChargingDuration, chargingInfo[CCS_QUANTITY]->TimeoutFlag); if (GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer) >= 7000000) { ftime(&startChargingTime[CCS_QUANTITY]); chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0; StopGunInfoTimeoutDet(CCS_QUANTITY); StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing); } */ //setBootNotification1(); // 輸出電壓 //測試value //GetPersentOutputVol(); // 三相輸入電壓 //GetPresentInputVol(); statusCheck(); int status = isModeChange(CCS_QUANTITY); /* * VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); */ /* VCCU_Requests(0, 0, 0, 3, 3, 3, 3, 3, 3, 7, 0, 7, 3, 3);*/ switch(chargingInfo[CCS_QUANTITY]->SystemStatus){ case V_IDLE:{ if (status){ printf("CCS IDLE Processing 1....................\n"); } //setEVStatus1(evstaus[0]); break; } case V_UNMATEDPLUG:{ if (status){ printf("CCS UNMATEDPLUG Processing 2....................\n"); } //setEVStatus1(evstaus[0]); //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Not_allowed, Not_allowed, Opened); break; } case V_MATED_PLUG_INLET_UNLOCKED:{ if (status){ if(ShmSysConfigAndInfo->ate.vccu.inletStatus.DATA2.VCCU_PlugPresent_Status == VCCU_InletStatus_Connected){ } printf("CCS MATED_PLUG_INLET_UNLOCKED Processing 3....................\n"); } //setEVStatus1(evstaus[0]); //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); break; } case V_INLETLOCKING:{ if (status){ printf("CCS INLETLOCKING Processing 4....................\n"); } //setEVStatus1(evstaus[0]); break; } case V_INLETLOCKED:{ if (status){ printf("CCS INLETLOCKED Processing 5....................\n"); } /* setEVStatus1(evstaus[1]); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); */ /* VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); */ break; } case V_SLAC:{ if (status){ printf("CCS SLAC Processing 6....................\n"); } //setEVStatus1(evstaus[1]); //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); /* VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); */ /* VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); */ break; } case V_DEFINITION:{ if (status){ printf("CCS DEFINITION Processing 7....................\n"); } //setEVStatus1(evstaus[1]); /* VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); */ /* VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, 500, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, 10); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); */ /* VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); */ break; } case V_CABLECHECK:{ if (status){ printf("CCS CABLECHECK Processing 8 ....................\n"); } /* setEVStatus1(evstaus[1]); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Allowed, Active, Allowed, Not_allowed, Opened); VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); */ break; } case V_ISOLATION:{ if (status){ printf("CCS ISOLATION Processing 9 %d ....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va ); ftime(&startChargingTime[CCS_QUANTITY]); } /* setEVStatus1(evstaus[1]); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Allowed, Not_Active, Allowed, Not_allowed, Opened); VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); */ break; } case V_VOLTAGEDIFFERENCE:{ if (status){ printf("CCS VOLTAGEDIFFERENCE Processing 10 ....................\n"); ftime(&startChargingTime[CCS_QUANTITY]); chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0; StopGunInfoTimeoutDet(CCS_QUANTITY); StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing); } ftime(&endChargingTime[CCS_QUANTITY]); chargingInfo[CCS_QUANTITY]->RemainChargingDuration = DiffTimeb(startChargingTime[CCS_QUANTITY], endChargingTime[CCS_QUANTITY]); //GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer); //printf("%d %ld ....................\n",chargingInfo[CCS_QUANTITY]->RemainChargingDuration, val); if (GetTimeoutValue(chargingInfo[CCS_QUANTITY]->TimeoutTimer) >= 7000000) { ftime(&startChargingTime[CCS_QUANTITY]); chargingInfo[CCS_QUANTITY]->RemainChargingDuration = 0; StopGunInfoTimeoutDet(CCS_QUANTITY); StartGunInfoTimeoutDet(CCS_QUANTITY, Timeout_Preparing); } /*printf("VCCU_V2G_StateM_StateMachineSt = %d VCCU_ChargeUnit_State = %d VCCU_Vehicle_IsolationMea_0000 = %d VCCU_Vehicle_ContactorRequest = %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_StateM.VCCU_V2G_StateM_StateMachineSt, ShmSysConfigAndInfo->ate.vccu.controlPilotStatus.DATA.bits.VCCU_ChargeUnit_State, ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_IsolationMea_0000, ShmSysConfigAndInfo->ate.vccu.chargeToVehicle.bits.VCCU_Vehicle_ContactorRequest); */ /* setEVStatus1(evstaus[1]); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed); //VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); */ break; } case V_CONTACTORSCLOSED:{ if (status){ printf("CCS CONTACTORSCLOSED Processing 11 %d %d....................\n",ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va, ShmSysConfigAndInfo->ate.linkVoltage ); } /* setEVStatus1(evstaus[1]); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed); VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); */ break; } case V_POWERDELIVERY:{ if (status){ printf("CCS POWERDELIVERY Processing 12 %d %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va, ShmSysConfigAndInfo->ate.linkVoltage ); } //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed); /* if(ShmSysConfigAndInfo->ate.ATEStatus == 0){ VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed); }else{ VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Not_allowed, Not_Active, Allowed, Not_allowed, Opened); } //VCCU_V2G_EVTargetVoltage(400, U_V, TRUE, 0); VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); setEVStatus1(evstaus[1]); */ break; } case V_CURRENTDEMAND:{ if (status){ printf("CCS CURRENTDEMAND Processing 13 %d....................\n", ShmSysConfigAndInfo->ate.vccu.v2g_EVSEPresentVoltage.VCCU_V2G_EVSEPresentVoltage_Va ); printf("maximumVoltage_value = %d Voltage = %d maximumCurrent_value = %d Current = %d....................\n", ShmSysConfigAndInfo->ate.maximumVoltage_value, ShmSysConfigAndInfo->ate.targetVoltage_Value, ShmSysConfigAndInfo->ate.maximumCurrent_value, ShmSysConfigAndInfo->ate.targetCurrent_Value); } //setEVStatus1(evstaus[2]); //printf("targetVoltage_Value= %d targetCurrent_Value =%d maximumVoltage_value = %d maximumCurrent_value = %d linkVoltage = %d \n",ShmSysConfigAndInfo->ate.targetVoltage_Value, ShmSysConfigAndInfo->ate.targetCurrent_Value, ShmSysConfigAndInfo->ate.maximumVoltage_value, ShmSysConfigAndInfo->ate.maximumCurrent_value, ShmSysConfigAndInfo->ate.linkVoltage); /* VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, 500, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, 10); VCCU_V2G_EVTargetVoltage(400, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, 2, TRUE, 0); VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Closed); */ /* VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); */ //VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed); /* if(ShmSysConfigAndInfo->ate.ATEStatus == 0){ //VCCU_ChargeFromVehicle(CanFd, 500, 500, Allowed, Not_Active, Allowed, Not_allowed, Closed); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Allowed, Not_Active, Allowed, Not_allowed, Closed); }else{ //VCCU_ChargeFromVehicle(CanFd, 500, 500, Not_allowed, Not_Active, Allowed, Not_allowed, Closed); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Not_allowed, Not_Active, Allowed, Not_allowed, Closed); } VCCU_V2G_VehicleStatus(CanFd, VCCU_V2G_StateM_EnergyTra_0000_DC_DC_extended, 0, 3, 0, 3, 3, TRUE, 3, 3, 3, 3, 3, 0, 3, 0, 3, 3); VCCU_V2G_EVMaximumVoltageLimit(TRUE, U_V, ShmSysConfigAndInfo->ate.maximumVoltage_value, TRUE, 0); VCCU_V2G_EVMaximumCurrentLimit(TRUE, U_A, TRUE, 0, ShmSysConfigAndInfo->ate.maximumCurrent_value); VCCU_V2G_EVTargetVoltage(ShmSysConfigAndInfo->ate.targetVoltage_Value, U_V, TRUE, 0); VCCU_V2G_EVTargetCurrent(U_A, ShmSysConfigAndInfo->ate.targetCurrent_Value, TRUE, 0); */ break; } case V_POWERDELIVERYFALSE:{ if (status){ printf("CCS POWERDELIVERYFALSE Processing 14....................\n"); } /* setEVStatus1(evstaus[3]); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, ShmSysConfigAndInfo->ate.linkVoltage, Not_allowed, Not_Active, Allowed, Not_allowed, Opened); */ break; } case V_DETECTION:{ if (status){ printf("CCS DETECTION Processing 15....................\n"); } /* setEVStatus1(evstaus[3]); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); */ break; } case V_SESSION_STOP:{ if (status){ printf("CCS SESSION_STOP Processing 16....................\n"); } /* setEVStatus1(evstaus[3]); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); */ break; } case V_STOP_COMMUNICATION_SESSION:{ if (status){ printf("CCS STOP_COMMUNICATION_SESSION Processing 17....................\n"); } /* setEVStatus1(evstaus[3]); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); */ break; } case V_FINISHED:{ if (status){ printf("CCS FINISHED Processing 18....................\n"); } /* setEVStatus1(evstaus[3]); VCCU_ChargeFromVehicle(CanFd, ShmSysConfigAndInfo->ate.linkVoltage, 0, Not_allowed, Active, Allowed, Not_allowed, Opened); */ break; } default:{ break; } } //usleep(100000); usleep(whileLoopTime); }else if(ShmSysConfigAndInfo->ate.ATEState == 2){//GB if(ShmSysConfigAndInfo->ate.status == 0){ }else{ } /* printf("ProximitySignal = %d, state = %d Permission = %d TotalBatteryCap = %d MaxBatteryCurrent = %d MaxBatteryVoltage = %d ATEStatus = %d....................\n", ShmSysConfigAndInfo->ate.chademo.id03.state ,ShmSysConfigAndInfo->ate.Permission, ShmSysConfigAndInfo->ate.chademo.id03.ProximitySignal, ShmSysConfigAndInfo->ate.TotalBatteryCap, ShmSysConfigAndInfo->ate.MaxBatteryCurrent, ShmSysConfigAndInfo->ate.MaxBatteryVoltage, ShmSysConfigAndInfo->ate.ATEStatus); printf("state = %d Permission = %d TotalBatteryCap = %d MaxBatteryCurrent = %d MaxBatteryVoltage = %d ATEStatus = %d K1K2Status = %d PresentBattVoltage = %d RequireVoltage = %d....................\n", ShmSysConfigAndInfo->ate.chademo.id03.state , ShmSysConfigAndInfo->ate.Permission, ShmSysConfigAndInfo->ate.TotalBatteryCap, ShmSysConfigAndInfo->ate.MaxBatteryCurrent, ShmSysConfigAndInfo->ate.MaxBatteryVoltage, ShmSysConfigAndInfo->ate.ATEStatus, ShmSysConfigAndInfo->ate.chademo.id0D_req.K1K2Status, ShmSysConfigAndInfo->ate.PresentBattVoltage, ShmSysConfigAndInfo->ate.RequireVoltage); usleep(whileLoopTime); */ //usleep(whileLoopTime); }else if(ShmSysConfigAndInfo->ate.ATEState == 3){//chademo } } printf("End. \n"); return FAIL; }