|
@@ -0,0 +1,1111 @@
|
|
|
+#include <sys/time.h>
|
|
|
+#include <sys/timeb.h>
|
|
|
+#include <sys/types.h>
|
|
|
+#include <sys/stat.h>
|
|
|
+#include <sys/types.h>
|
|
|
+#include <sys/ioctl.h>
|
|
|
+#include <sys/socket.h>
|
|
|
+#include <sys/ipc.h>
|
|
|
+#include <sys/shm.h>
|
|
|
+#include <sys/shm.h>
|
|
|
+#include <sys/mman.h>
|
|
|
+#include <linux/can.h>
|
|
|
+#include <linux/can/raw.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 "../../define.h"
|
|
|
+#include "Module_EvComm.h"
|
|
|
+
|
|
|
+#define Debug
|
|
|
+#define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
|
|
|
+#define PASS 1
|
|
|
+#define FAIL -1
|
|
|
+#define START 1
|
|
|
+#define STOP 0
|
|
|
+#define YES 1
|
|
|
+#define NO 0
|
|
|
+#define DEMO 0
|
|
|
+
|
|
|
+struct SysConfigAndInfo *ShmSysConfigAndInfo;
|
|
|
+struct StatusCodeData *ShmStatusCodeData;
|
|
|
+struct FanModuleData *ShmFanModuleData;
|
|
|
+struct CHAdeMOData *ShmCHAdeMOData;
|
|
|
+struct CcsData *ShmCcsData;
|
|
|
+
|
|
|
+byte gun_count = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
|
|
|
+int chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
+
|
|
|
+float maxChargingVol = 6000; // 限制最大充電電壓,如依照模塊則填上 0
|
|
|
+float maxChargingCur = 500; // 限制最大充電電流,如依照模塊則填上 0
|
|
|
+
|
|
|
+// 槍資訊
|
|
|
+struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
+
|
|
|
+struct Ev_Board_Cmd Ev_Cmd={
|
|
|
+ 0,
|
|
|
+ 0x00000200,
|
|
|
+ 0x00000400,
|
|
|
+ 0x00000500,
|
|
|
+ 0x00000600,
|
|
|
+ 0x00000700,
|
|
|
+ 0x00000800,
|
|
|
+ 0x00000900,
|
|
|
+ 0x00000A00,
|
|
|
+ 0x00000C00,
|
|
|
+ 0x00000D00,
|
|
|
+
|
|
|
+ 0x00000E00,
|
|
|
+ 0x00000F00,
|
|
|
+ 0x00001000,
|
|
|
+ 0x00001100,
|
|
|
+
|
|
|
+ 0x00001200,
|
|
|
+ 0x00001500,
|
|
|
+};
|
|
|
+
|
|
|
+unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
|
|
|
+
|
|
|
+// 檢查 Byte 中某個 Bit 的值
|
|
|
+// _byte : 欲改變的 byte
|
|
|
+// _bit : 該 byte 的第幾個 bit
|
|
|
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
|
|
|
+{
|
|
|
+ return ( _byte & mask_table[_bit] ) != 0x00;
|
|
|
+}
|
|
|
+
|
|
|
+// 設定 Byte 中某個 Bit的值
|
|
|
+// _byte : 欲改變的 byte
|
|
|
+// _bit : 該 byte 的第幾個 bit
|
|
|
+// value : 修改的值為 0 or 1
|
|
|
+void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
|
|
|
+{
|
|
|
+ if(value == 1)
|
|
|
+ *_byte |= (1 << _bit);
|
|
|
+ else if (value == 0)
|
|
|
+ *_byte ^= (1 << _bit);
|
|
|
+}
|
|
|
+
|
|
|
+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 StoreLogMsg(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;
|
|
|
+}
|
|
|
+
|
|
|
+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;
|
|
|
+}
|
|
|
+
|
|
|
+//=================================
|
|
|
+// Common routine
|
|
|
+//=================================
|
|
|
+void getTimeString(char *buff)
|
|
|
+{
|
|
|
+ time_t timep;
|
|
|
+ struct tm *p;
|
|
|
+ time(&timep);
|
|
|
+ p=gmtime(&timep);
|
|
|
+
|
|
|
+ sprintf(buff, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
|
|
|
+}
|
|
|
+
|
|
|
+bool CheckUniqNumber(byte value)
|
|
|
+{
|
|
|
+ for (byte index = 0; index < gun_count; index++)
|
|
|
+ {
|
|
|
+ if (_chargingData[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;
|
|
|
+}
|
|
|
+
|
|
|
+//==========================================
|
|
|
+// Init all share memory
|
|
|
+//==========================================
|
|
|
+int InitShareMemory()
|
|
|
+{
|
|
|
+ int result = PASS;
|
|
|
+ int MeterSMId;
|
|
|
+
|
|
|
+ //initial ShmSysConfigAndInfo
|
|
|
+ if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
|
|
|
+ #endif
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
|
|
|
+ #endif
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
+
|
|
|
+ //initial ShmStatusCodeData
|
|
|
+ if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
|
|
|
+ #endif
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
|
|
|
+ #endif
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
+
|
|
|
+ if(CHAdeMO_QUANTITY > 0)
|
|
|
+ {
|
|
|
+ if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR("[shmget ShmCHAdeMOData NG \n");
|
|
|
+ #endif
|
|
|
+ return FAIL;
|
|
|
+ }
|
|
|
+ else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR("shmat ShmCHAdeMOData NG \n");
|
|
|
+ #endif
|
|
|
+ return FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
+ }
|
|
|
+
|
|
|
+ if(CCS_QUANTITY > 0)
|
|
|
+ {
|
|
|
+ if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR("shmget ShmCcsData NG \n");
|
|
|
+ #endif
|
|
|
+ return FAIL;
|
|
|
+ }
|
|
|
+ else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR("shmat ShmCcsData NG \n");
|
|
|
+ #endif
|
|
|
+ return FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+//================================================
|
|
|
+// initial can-bus
|
|
|
+//================================================
|
|
|
+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("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, "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;
|
|
|
+}
|
|
|
+
|
|
|
+//================================================
|
|
|
+//================================================
|
|
|
+// CANBUS receive task
|
|
|
+//================================================
|
|
|
+//================================================
|
|
|
+bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
|
|
|
+{
|
|
|
+ for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
|
|
|
+ {
|
|
|
+ chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (byte index = 0; index < CCS_QUANTITY; index++)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
|
|
|
+ {
|
|
|
+ chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (byte index = 0; index < GB_QUANTITY; index++)
|
|
|
+ {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
|
|
|
+ {
|
|
|
+ chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+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]);
|
|
|
+
|
|
|
+ printf("SetTargetAddr = %d \n", index);
|
|
|
+ SetTargetAddr(target_number, index);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ClearAbnormalStatus_Chadmoe(byte gun_index)
|
|
|
+{
|
|
|
+ int codeValue = 0;
|
|
|
+
|
|
|
+ if (strlen((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index]) == 6)
|
|
|
+ {
|
|
|
+ codeValue = atoi((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index]);
|
|
|
+
|
|
|
+ if (codeValue >= 23700 && codeValue <= 23736)
|
|
|
+ {
|
|
|
+ memcpy(&ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index][0], "", 7);
|
|
|
+ ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = 0x00;
|
|
|
+ ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = 0x00;
|
|
|
+}
|
|
|
+
|
|
|
+void AbnormalStopAnalysis(byte gun_index, byte *errCode)
|
|
|
+{
|
|
|
+ char string[7];
|
|
|
+ sprintf(string, "%d%d%d%d%d%d", *(errCode + 5), *(errCode + 4), *(errCode + 3), *(errCode + 2), *(errCode + 1), *(errCode + 0));
|
|
|
+
|
|
|
+ if (gun_index < gun_count)
|
|
|
+ {
|
|
|
+ if (strlen((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index]) <= 0)
|
|
|
+ {
|
|
|
+ memcpy(&ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index][0], string, 7);
|
|
|
+ ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level = 0x00;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ printf("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
|
|
|
+
|
|
|
+ if (strcmp(string, "023700") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = 0x01;
|
|
|
+ if (strcmp(string, "023701") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail = 0x01;
|
|
|
+ if (strcmp(string, "023702") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = 0x01;
|
|
|
+ if (strcmp(string, "023703") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = 0x01;
|
|
|
+ if (strcmp(string, "023704") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = 0x01;
|
|
|
+ if (strcmp(string, "023705") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = 0x01;
|
|
|
+ if (strcmp(string, "023706") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = 0x01;
|
|
|
+ if (strcmp(string, "023707") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = 0x01;
|
|
|
+ if (strcmp(string, "023708") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = 0x01;
|
|
|
+ if (strcmp(string, "023709") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = 0x01;
|
|
|
+ if (strcmp(string, "023710") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = 0x01;
|
|
|
+ if (strcmp(string, "023711") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = 0x01;
|
|
|
+ if (strcmp(string, "023712") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = 0x01;
|
|
|
+ if (strcmp(string, "023713") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = 0x01;
|
|
|
+ if (strcmp(string, "023714") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = 0x01;
|
|
|
+ if (strcmp(string, "023715") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = 0x01;
|
|
|
+ if (strcmp(string, "023716") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = 0x01;
|
|
|
+ if (strcmp(string, "023717") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = 0x01;
|
|
|
+ if (strcmp(string, "023718") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = 0x01;
|
|
|
+ if (strcmp(string, "023719") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = 0x01;
|
|
|
+ if (strcmp(string, "023720") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = 0x01;
|
|
|
+ if (strcmp(string, "023721") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = 0x01;
|
|
|
+ if (strcmp(string, "023722") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = 0x01;
|
|
|
+ if (strcmp(string, "023723") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = 0x01;
|
|
|
+ if (strcmp(string, "023724") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = 0x01;
|
|
|
+ if (strcmp(string, "023725") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = 0x01;
|
|
|
+ if (strcmp(string, "023726") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = 0x01;
|
|
|
+ if (strcmp(string, "023727") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = 0x01;
|
|
|
+ if (strcmp(string, "023728") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = 0x01;
|
|
|
+ if (strcmp(string, "023729") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = 0x01;
|
|
|
+ if (strcmp(string, "023730") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = 0x01;
|
|
|
+ if (strcmp(string, "023731") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = 0x01;
|
|
|
+ if (strcmp(string, "023732") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = 0x01;
|
|
|
+ if (strcmp(string, "023733") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = 0x01;
|
|
|
+ if (strcmp(string, "023734") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = 0x01;
|
|
|
+ if (strcmp(string, "023735") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = 0x01;
|
|
|
+ if (strcmp(string, "023736") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = 0x01;
|
|
|
+}
|
|
|
+
|
|
|
+void CANReceiver()
|
|
|
+{
|
|
|
+ pid_t canRecPid;
|
|
|
+
|
|
|
+ canRecPid = fork();
|
|
|
+
|
|
|
+ if(canRecPid > 0)
|
|
|
+ {
|
|
|
+ int nbytes;
|
|
|
+ struct can_frame frame;
|
|
|
+ int intCmd;
|
|
|
+ // 槍資訊
|
|
|
+ struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
+ struct timeval _cmd_ack_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
+
|
|
|
+ bool isPass = false;
|
|
|
+ while(!isPass)
|
|
|
+ {
|
|
|
+ isPass = true;
|
|
|
+ for (byte _index = 0; _index < gun_count; _index++)
|
|
|
+ {
|
|
|
+ if (!FindChargingInfoData(_index, &_chargingData[0]))
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
|
|
|
+ isPass = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (byte _index = 0; _index < gun_count; _index++)
|
|
|
+ gettimeofday(&_cmd_ack_timeout[_index], NULL);
|
|
|
+
|
|
|
+ while (1)
|
|
|
+ {
|
|
|
+ memset(&frame, 0, sizeof(struct can_frame));
|
|
|
+ nbytes = read(CanFd, &frame, sizeof(struct can_frame));
|
|
|
+
|
|
|
+ for (byte _index = 0; _index < gun_count; _index++)
|
|
|
+ {
|
|
|
+ if (GetTimeoutValue(_cmd_ack_timeout[_index]) >= 5000000)
|
|
|
+ {
|
|
|
+ // ACK timeout
|
|
|
+ //printf("gun = %x, ack timeout \n", _index);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nbytes > 0)
|
|
|
+ {
|
|
|
+ byte target;
|
|
|
+ byte targetGun = 0x00;
|
|
|
+ intCmd = (int) (frame.can_id & CAN_EFF_MASK);
|
|
|
+
|
|
|
+ if (intCmd == ADDRESS_REQ)
|
|
|
+ {
|
|
|
+ AddrAssignment(frame.data);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
|
|
|
+ target = ((byte) (frame.can_id & 0x000000FF)); // 0x01 or 0x02
|
|
|
+
|
|
|
+ for (byte _index = 0; _index < gun_count; _index++)
|
|
|
+ {
|
|
|
+ if (_chargingData[_index]->Evboard_id == target)
|
|
|
+ {
|
|
|
+ targetGun = _index;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(targetGun < 0 || targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)
|
|
|
+ {
|
|
|
+ printf("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(intCmd == 256)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ gettimeofday(&_cmd_ack_timeout[targetGun], NULL);
|
|
|
+ switch (intCmd)
|
|
|
+ {
|
|
|
+ case NOTIFICATION_EV_STATUS:
|
|
|
+ {
|
|
|
+ _chargingData[targetGun]->ConnectorPlugIn = frame.data[0];
|
|
|
+ _chargingData[targetGun]->PilotVoltage = frame.data[1];
|
|
|
+
|
|
|
+ //printf("index = %d, ConnectorPlugIn = %x, data[0] = %x \n", targetGun, _chargingData[targetGun]->ConnectorPlugIn, frame.data[0]);
|
|
|
+ //printf("ConnectorPlugIn = %x \n", (-120 + frame.data[1]) / 10);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ACK_EV_FW_VERSION:
|
|
|
+ {
|
|
|
+ if (_chargingData[targetGun]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ memcpy(ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version, frame.data, ARRAY_SIZE(frame.data));
|
|
|
+ ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
|
|
|
+ }
|
|
|
+ else if (_chargingData[targetGun]->Type == _Type_CCS)
|
|
|
+ {
|
|
|
+ printf("Get FW HW = %s \n", frame.data);
|
|
|
+ if (ShmCcsData->CommProtocol == 0x01)
|
|
|
+ {
|
|
|
+ memcpy(&ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version, frame.data, ARRAY_SIZE(frame.data));
|
|
|
+ ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ACK_EV_HW_VERSION:
|
|
|
+ {
|
|
|
+ //printf("Get EV HW = %s \n", frame.data);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ACK_GET_OUTPUT_REQ:
|
|
|
+ {
|
|
|
+ _chargingData[targetGun]->EvBatterySoc = frame.data[1];
|
|
|
+ _chargingData[targetGun]->EvBatterytargetVoltage = ((short) frame.data[3] << 8) + (short) frame.data[2];
|
|
|
+ _chargingData[targetGun]->EvBatterytargetCurrent = ((short) frame.data[5] << 8) + (short) frame.data[4];
|
|
|
+ _chargingData[targetGun]->PresentChargedDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
|
|
|
+
|
|
|
+ if (_chargingData[targetGun]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ if (ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
|
|
|
+ {
|
|
|
+ ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
|
|
|
+ ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
|
|
|
+ ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = _chargingData[targetGun]->EvBatterytargetVoltage;
|
|
|
+ ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = _chargingData[targetGun]->EvBatterytargetCurrent;
|
|
|
+ }
|
|
|
+ else if (_chargingData[targetGun]->Type == _Type_CCS)
|
|
|
+ {
|
|
|
+ if(ShmCcsData->CommProtocol == 0x01)
|
|
|
+ {
|
|
|
+ ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //printf("(EvComm) EvBatterytargetVoltage = %f \n", _chargingData[targetGun]->EvBatterytargetVoltage);
|
|
|
+ //printf("(EvComm) EvBatterytargetCurrent = %f \n", _chargingData[targetGun]->EvBatterytargetCurrent);
|
|
|
+ //printf("BatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TargetBatteryVoltage);
|
|
|
+ //printf("CurrentRequest = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].ChargingCurrentRequest);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ACK_GET_EV_BATTERY_INFO:
|
|
|
+ {
|
|
|
+ //_chargingData[target].EvACorDCcharging = frame.data[0];
|
|
|
+ //_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
|
|
|
+ _chargingData[targetGun]->EvBatteryMaxVoltage = ((short) frame.data[4] << 8) + (short) frame.data[3];
|
|
|
+ //_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
|
|
|
+ //_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
|
|
|
+ if (_chargingData[targetGun]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
|
|
|
+ ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].MaxiBatteryVoltage = _chargingData[targetGun]->EvBatteryMaxVoltage;
|
|
|
+
|
|
|
+ //printf("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
|
|
|
+ //printf("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
|
|
|
+ //printf("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
|
|
|
+ }
|
|
|
+ else if (_chargingData[targetGun]->Type == _Type_CCS)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ACK_GET_MISCELLANEOUS_INFO:
|
|
|
+ {
|
|
|
+ if (_chargingData[targetGun]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ _chargingData[targetGun]->GunLocked = frame.data[0];
|
|
|
+ ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
|
|
|
+ ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
|
|
|
+ _chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
|
|
|
+ ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
|
|
|
+ }
|
|
|
+ else if (_chargingData[targetGun]->Type == _Type_CCS)
|
|
|
+ {
|
|
|
+ if (ShmCcsData->CommProtocol == 0x01)
|
|
|
+ {
|
|
|
+ _chargingData[targetGun]->GunLocked = frame.data[0];
|
|
|
+ //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureP = frame.data[1];
|
|
|
+ //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
|
|
|
+ _chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //printf("EvboardStatus = %x \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].EvboardStatus);
|
|
|
+ //printf("ConnectorPlug locked = %x \n", frame.data[0]);
|
|
|
+ //printf("ConnectorTemp 0= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureP);
|
|
|
+ //printf("ConnectorTemp 1= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureN);
|
|
|
+ //printf("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ACK_EVSE_ISOLATION_STATUS: {}
|
|
|
+ break;
|
|
|
+ case ACK_EVSE_PRECHAGE_INFO:
|
|
|
+ {
|
|
|
+ _chargingData[targetGun]->PrechargeStatus = frame.data[0];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case NOTIFICATION_EV_STOP:
|
|
|
+ {
|
|
|
+ // 車端要求停止
|
|
|
+ // frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
|
|
|
+ if (frame.data[0] == 0x02)
|
|
|
+ {
|
|
|
+ //printf("NOTIFICATION_EV_STOP -----------------------------\n");
|
|
|
+ AbnormalStopAnalysis(targetGun, frame.data + 1);
|
|
|
+ }
|
|
|
+ _chargingData[targetGun]->StopChargeFlag = YES;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ printf("EV board = %d, Ack none defined. intCmd = %d \n", targetGun, intCmd);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ usleep(10000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//================================================
|
|
|
+// Main process
|
|
|
+//================================================
|
|
|
+// 檢查 Byte 中某個 Bit 的值
|
|
|
+// _byte : 欲改變的 byte
|
|
|
+// _bit : 該 byte 的第幾個 bit
|
|
|
+unsigned char EvDetectionStatus(unsigned char _byte, unsigned char _bit)
|
|
|
+{
|
|
|
+ return ( _byte & mask_table[_bit] ) != 0x00;
|
|
|
+}
|
|
|
+
|
|
|
+bool IsConnectorPlugIn(struct ChargingInfoData *chargingData)
|
|
|
+{
|
|
|
+ return (chargingData->ConnectorPlugIn == 0x01) ? true : false;
|
|
|
+}
|
|
|
+
|
|
|
+void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
|
|
|
+{
|
|
|
+ float vol1 = 0, cur1 = 0;
|
|
|
+ float vol2 = 0, cur2 = 0;
|
|
|
+
|
|
|
+ //printf("f vol - 0 = %f \n", chargingData_1->FireChargingVoltage);
|
|
|
+ //printf("f cur - 0 = %f \n", chargingData_1->PresentChargingCurrent);
|
|
|
+ //printf("f vol - 1 = %f \n", chargingData_2->FireChargingVoltage);
|
|
|
+ //printf("f cur - 1 = %f \n", chargingData_2->PresentChargingCurrent);
|
|
|
+
|
|
|
+ vol1 = chargingData_1->FireChargingVoltage;
|
|
|
+ cur1 = chargingData_1->PresentChargingCurrent;
|
|
|
+
|
|
|
+ vol2 = chargingData_2->FireChargingVoltage;
|
|
|
+ cur2 = chargingData_2->PresentChargingCurrent;
|
|
|
+
|
|
|
+ SetPresentOutputPower(vol1, cur1, vol2, cur2);
|
|
|
+}
|
|
|
+
|
|
|
+void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
|
|
|
+{
|
|
|
+ float pow1 = 0, cur1 = 0;
|
|
|
+ float pow2 = 0, cur2 = 0;
|
|
|
+ float vol = 0;
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
|
|
|
+ {
|
|
|
+ pow1 = chargingData_1->DeratingChargingPower;
|
|
|
+ cur1 = chargingData_1->DeratingChargingCurrent;
|
|
|
+ printf("Left : To EV D_Power_1 = %f, D_Cur_1 = %f \n", pow1, cur1);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pow1 = chargingData_1->AvailableChargingPower;
|
|
|
+ cur1 = chargingData_1->AvailableChargingCurrent;
|
|
|
+ }
|
|
|
+ vol = chargingData_1->MaximumChargingVoltage;
|
|
|
+ GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
|
|
|
+ {
|
|
|
+ pow2 = chargingData_2->DeratingChargingPower;
|
|
|
+ cur2 = chargingData_2->DeratingChargingCurrent;
|
|
|
+ printf("Right : To EV D_Power_1 = %f, D_Cur_1 = %f \n", pow2, cur2);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pow2 = chargingData_2->AvailableChargingPower;
|
|
|
+ cur2 = chargingData_2->AvailableChargingCurrent;
|
|
|
+ }
|
|
|
+ vol = chargingData_2->MaximumChargingVoltage;
|
|
|
+ GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
|
|
|
+
|
|
|
+ printf("To EV Power_1 = %f, Cur_1 = %f, Power_2 = %f, Cur_2 = %f \n", pow1, cur1, pow2, cur2);
|
|
|
+ SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
|
|
|
+}
|
|
|
+
|
|
|
+void Initialization()
|
|
|
+{
|
|
|
+ bool isPass = false;
|
|
|
+ while(!isPass)
|
|
|
+ {
|
|
|
+ isPass = true;
|
|
|
+ for (byte _index = 0; _index < gun_count; _index++)
|
|
|
+ {
|
|
|
+ if (!FindChargingInfoData(_index, &_chargingData[0]))
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
|
|
|
+ isPass = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void GetMaxVolAndCurMethod(byte index, float *vol, float *cur)
|
|
|
+{
|
|
|
+ if (maxChargingVol != 0 && maxChargingVol <= *vol)
|
|
|
+ *vol = maxChargingVol;
|
|
|
+
|
|
|
+ if (maxChargingCur != 0 && maxChargingCur <= *cur)
|
|
|
+ *cur = maxChargingCur;
|
|
|
+}
|
|
|
+
|
|
|
+void GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
|
|
|
+{
|
|
|
+ if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == 0x01)
|
|
|
+ {
|
|
|
+ // 012251
|
|
|
+ *(reason + 5) = 0;
|
|
|
+ *(reason + 4) = 1;
|
|
|
+ *(reason + 3) = 2;
|
|
|
+ *(reason + 2) = 2;
|
|
|
+ *(reason + 1) = 5;
|
|
|
+ *(reason + 0) = 1;
|
|
|
+ }
|
|
|
+ else if (_chargingData[gunIndex]->Type == _Type_Chademo &&
|
|
|
+ ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == 0x01)
|
|
|
+ {
|
|
|
+ // 011012
|
|
|
+ *(reason + 5) = 0;
|
|
|
+ *(reason + 4) = 1;
|
|
|
+ *(reason + 3) = 1;
|
|
|
+ *(reason + 2) = 0;
|
|
|
+ *(reason + 1) = 1;
|
|
|
+ *(reason + 0) = 2;
|
|
|
+ }
|
|
|
+ else if (_chargingData[gunIndex]->Type == _Type_CCS &&
|
|
|
+ ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == 0x01)
|
|
|
+ {
|
|
|
+ // 011014
|
|
|
+ *(reason + 5) = 0;
|
|
|
+ *(reason + 4) = 1;
|
|
|
+ *(reason + 3) = 1;
|
|
|
+ *(reason + 2) = 0;
|
|
|
+ *(reason + 1) = 1;
|
|
|
+ *(reason + 0) = 4;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int main(int argc, char *argv[])
|
|
|
+{
|
|
|
+ if(InitShareMemory() == FAIL)
|
|
|
+ {
|
|
|
+ #ifdef SystemLogMessage
|
|
|
+ DEBUG_ERROR("InitShareMemory NG\n");
|
|
|
+ #endif
|
|
|
+ if(ShmStatusCodeData != NULL)
|
|
|
+ {
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
|
|
|
+ }
|
|
|
+ sleep(5);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ Initialization();
|
|
|
+ CanFd = InitCanBus();
|
|
|
+ CANReceiver();
|
|
|
+
|
|
|
+ byte priorityLow = 1;
|
|
|
+#if (!DEMO)
|
|
|
+ while(CanFd)
|
|
|
+ {
|
|
|
+ for(byte _index = 0; _index < gun_count; _index++)
|
|
|
+ {
|
|
|
+ if (priorityLow == 1)
|
|
|
+ {
|
|
|
+ // 優先權較低 - 只要有回應即不會再詢問
|
|
|
+ if (_chargingData[_index]->Type == _Type_Chademo &&
|
|
|
+ ShmCHAdeMOData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
|
|
|
+ {
|
|
|
+ GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
|
|
|
+ GetHardwareVersion(_index, _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+ else if (_chargingData[_index]->Type == _Type_CCS)
|
|
|
+ {
|
|
|
+ if (ShmCcsData->CommProtocol == 0x01 &&
|
|
|
+ ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
|
|
|
+ {
|
|
|
+ GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
|
|
|
+ GetHardwareVersion(_index, _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
|
|
|
+ //printf("GetMiscellaneousInfo. index = %d, Eid = %d \n", _index, _chargingData[_index]->Evboard_id);
|
|
|
+ GetMiscellaneousInfo(_index, _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (_chargingData[_index]->SystemStatus)
|
|
|
+ {
|
|
|
+ case S_IDLE:
|
|
|
+ _chargingData[_index]->PresentChargedEnergy = 0;
|
|
|
+ _chargingData[_index]->GroundFaultStatus = GFD_WAIT;
|
|
|
+ _chargingData[_index]->StopChargeFlag = NO;
|
|
|
+ chargingTime[_index] = 0;
|
|
|
+
|
|
|
+ if (_chargingData[_index]->Type == _Type_Chademo)
|
|
|
+ {
|
|
|
+ ClearAbnormalStatus_Chadmoe(_index);
|
|
|
+ }
|
|
|
+ else if (_chargingData[_index]->Type == _Type_CCS)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_PREPARING_FOR_EV:
|
|
|
+ {
|
|
|
+ // 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
|
|
|
+ GetOutputReq(_index, _chargingData[_index]->Evboard_id);
|
|
|
+
|
|
|
+ //printf("PresentChargingVoltage = %f \n", _chargingData[_index]->PresentChargingVoltage);
|
|
|
+ //printf("PresentChargingCurrent = %f \n", _chargingData[_index]->PresentChargingCurrent);
|
|
|
+ //printf("AvailableChargingPower = %f \n", _chargingData[_index]->AvailableChargingPower);
|
|
|
+ //printf("AvailableChargingCurrent = %f \n", _chargingData[_index]->AvailableChargingCurrent);
|
|
|
+ //printf("MaximumChargingVoltage = %f \n", _chargingData[_index]->MaximumChargingVoltage);
|
|
|
+
|
|
|
+ // 設定當前輸出
|
|
|
+ if (gun_count == 1)
|
|
|
+ SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
|
|
|
+ else if (gun_count == 2)
|
|
|
+ SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
|
|
|
+
|
|
|
+ if (priorityLow == 1)
|
|
|
+ {
|
|
|
+ float maxVol, maxCur;
|
|
|
+ // 樁端輸出能力
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
|
|
|
+ {
|
|
|
+ maxVol = _chargingData[_index]->MaximumChargingVoltage;
|
|
|
+ maxCur = _chargingData[_index]->DeratingChargingCurrent;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ maxVol = _chargingData[_index]->MaximumChargingVoltage;
|
|
|
+ maxCur = _chargingData[_index]->AvailableChargingCurrent;
|
|
|
+ }
|
|
|
+ GetMaxVolAndCurMethod(_index, &maxVol, &maxCur);
|
|
|
+
|
|
|
+ printf("To EV Max_Vol = %f, Cap_Cur = %f \n", maxVol, maxCur);
|
|
|
+ SetChargingPermission(_index, START,
|
|
|
+ _chargingData[_index]->AvailableChargingPower,
|
|
|
+ maxCur,
|
|
|
+ maxVol,
|
|
|
+ _chargingData[_index]->Evboard_id);
|
|
|
+
|
|
|
+ // 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
|
|
|
+ GetEvBatteryInfo(_index, _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_PREPARING_FOR_EVSE:
|
|
|
+ case S_CCS_PRECHARGE_ST0:
|
|
|
+ case S_CCS_PRECHARGE_ST1:
|
|
|
+ {
|
|
|
+ // 開始確認車端是否同意開始充電
|
|
|
+ GetOutputReq(_index, _chargingData[_index]->Evboard_id);
|
|
|
+
|
|
|
+ // 設定當前輸出
|
|
|
+ if (gun_count == 1)
|
|
|
+ SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
|
|
|
+ else if (gun_count == 2)
|
|
|
+ SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
|
|
|
+
|
|
|
+ if (priorityLow % 5 == 1)
|
|
|
+ {
|
|
|
+ // 樁端輸出能力改變
|
|
|
+ if (gun_count == 1)
|
|
|
+ SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
|
|
|
+ else if (gun_count == 2)
|
|
|
+ SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 持續通知 Isolation 測試狀態
|
|
|
+ if (priorityLow == 1)
|
|
|
+ {
|
|
|
+ // 拉 500 V 如果在一秒鐘內 GFD 都符合則 PASS
|
|
|
+ if (_chargingData[_index]->PresentChargingVoltage >= 4000)
|
|
|
+ _chargingData[_index]->GroundFaultStatus = GFD_PASS;
|
|
|
+
|
|
|
+ if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
|
|
|
+ {
|
|
|
+ SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_chargingData[_index]->SystemStatus == S_CCS_PRECHARGE_ST0 &&
|
|
|
+ _chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
|
|
|
+ {
|
|
|
+ SetEvsePrechargeInfo(_index, PRECHARGE_PRERELAY_PASS, _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_CHARGING:
|
|
|
+ {
|
|
|
+ // 計算 Power
|
|
|
+ _chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage / 10) * (_chargingData[_index]->PresentChargingCurrent / 10)) / 1000);
|
|
|
+
|
|
|
+ if (chargingTime[_index] == 0)
|
|
|
+ {
|
|
|
+ chargingTime[_index] = _chargingData[_index]->RemainChargingDuration;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int passTime = _chargingData[_index]->RemainChargingDuration - chargingTime[_index];
|
|
|
+
|
|
|
+ if (passTime > 0)
|
|
|
+ {
|
|
|
+ _chargingData[_index]->PresentChargedEnergy += (_chargingData[_index]->PresentChargingPower) * passTime / 3600;
|
|
|
+ chargingTime[_index] = _chargingData[_index]->RemainChargingDuration;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 開始確認車端是否同意開始充電
|
|
|
+ GetOutputReq(_index, _chargingData[_index]->Evboard_id);
|
|
|
+
|
|
|
+ // 設定當前輸出
|
|
|
+ if (gun_count == 1)
|
|
|
+ SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
|
|
|
+ else if (gun_count == 2)
|
|
|
+ SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
|
|
|
+
|
|
|
+ // for test end
|
|
|
+ if (priorityLow % 5 == 0)
|
|
|
+ {
|
|
|
+ // 樁端輸出能力改變
|
|
|
+ if (gun_count == 1)
|
|
|
+ SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
|
|
|
+ else if (gun_count == 2)
|
|
|
+ SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // GFD 失敗再通知
|
|
|
+ if (priorityLow == 1)
|
|
|
+ {
|
|
|
+ if(_chargingData[_index]->GroundFaultStatus == GFD_FAIL)
|
|
|
+ {
|
|
|
+ SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_chargingData[_index]->Type == _Type_CCS &&
|
|
|
+ _chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
|
|
|
+ {
|
|
|
+ SetEvsePrechargeInfo(_index, PRECHARGE_CHARELAY_PASS, _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_TERMINATING:
|
|
|
+ {
|
|
|
+ // 設定當前輸出
|
|
|
+ if (gun_count == 1)
|
|
|
+ SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
|
|
|
+ else if (gun_count == 2)
|
|
|
+ SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
|
|
|
+
|
|
|
+ // 槍鎖還在,則代表是樁端要求的停止
|
|
|
+ if (_chargingData[_index]->GunLocked == START)
|
|
|
+ {
|
|
|
+ byte normalStop = 0x01;
|
|
|
+ byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
+
|
|
|
+ if (strlen((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[_index]) > 0)
|
|
|
+ {
|
|
|
+ normalStop = 0x02;
|
|
|
+ GetStopChargingReasonByEvse(_index, stopReason);
|
|
|
+ }
|
|
|
+
|
|
|
+ EvseStopChargingEvent(normalStop, stopReason, _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+ GetOutputReq(_index, _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case S_COMPLETE:
|
|
|
+ {
|
|
|
+ if (priorityLow == 1)
|
|
|
+ {
|
|
|
+ // 樁端輸出能力
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
|
|
|
+ {
|
|
|
+ SetChargingPermission(_index, STOP,
|
|
|
+ _chargingData[_index]->DeratingChargingPower,
|
|
|
+ _chargingData[_index]->DeratingChargingCurrent,
|
|
|
+ _chargingData[_index]->MaximumChargingVoltage,
|
|
|
+ _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SetChargingPermission(_index, STOP,
|
|
|
+ _chargingData[_index]->AvailableChargingPower,
|
|
|
+ _chargingData[_index]->AvailableChargingCurrent,
|
|
|
+ _chargingData[_index]->MaximumChargingVoltage,
|
|
|
+ _chargingData[_index]->Evboard_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
|
|
|
+ usleep(45000); //EV 小板通訊 (50 ms)
|
|
|
+ }
|
|
|
+#else
|
|
|
+#endif
|
|
|
+ DEBUG_INFO("Module_EvComm : Can-bus port = %d \n", CanFd);
|
|
|
+ return FAIL;
|
|
|
+}
|