#include #include #include #include #include #include #include #include #include "../Define/define.h" //#include "../AudiCust.h" #include "../SelectGun/SelectGun.h" #include "../common.h" #include "../Log/log.h" #include "../Config.h" #include "shmMem.h" //------------------------------------------------------------------------------ static struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL; //static struct SysInfoData *ShmSysInfoData = NULL; //static struct SysConfigData *ShmSysConfigData = NULL; //static struct WARNING_CODE_INFO *SysWarningInfo = NULL; static struct StatusCodeData *ShmStatusCodeData = NULL; //static struct AlarmCodeData *ShmAlarmCodeData = NULL; //static struct FaultCodeData *ShmFaultCodeData = NULL; //static struct InfoCodeData *ShmInfoCodeData = NULL; static struct PsuData *ShmPsuData = NULL; static struct CHAdeMOData *ShmCHAdeMOData = NULL; static struct GBTData *ShmGBTData = NULL; static struct CcsData *ShmCcsData = NULL; static struct PrimaryMcuData *ShmPrimaryMcuData = NULL; static struct FanModuleData *ShmFanModuleData = NULL; static struct RelayModuleData *ShmRelayModuleData = NULL; static struct LedModuleData *ShmLedModuleData = NULL; static struct OCPP16Data *ShmOCPP16Data = NULL; static struct OCPP20Data* ShmOCPP20Data = NULL; static SelectGunInfo *ShmSelectGunInfo = NULL; static DcCommonInfo *ShmDcCommonData = NULL; static struct MeterInformation *ShmCsuMeterData = NULL; static struct ChargingInfoData *DcChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {NULL}; static struct ChargingInfoData *AcChargingData[AC_QUANTITY] = {NULL}; static GunIndexInfo gGunIndexInfo = {0}; //struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData(); //struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); //struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo(); //struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData(); //struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData(); //struct FaultCodeData *pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData(); //struct PsuData *ShmPsuData = (struct PsuData *)GetShmPsuData(); //struct CHAdeMOData *ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData(); //struct GBTData *ShmGBTData = (struct GBTData *)GetShmGBTData(); //struct CcsData *ShmCcsData = (struct CcsData *)GetShmCcsData(); //struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData(); //struct FanModuleData *ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData(); //struct RelayModuleData *ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData(); //struct LedModuleData *ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData(); //struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data(); //SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo(); //DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData(); //struct ChargingInfoData *pDcChargingInfo = NULL; //struct ChargingInfoData *pAcChargingInfo = NULL; //------------------------------------------------------------------------------ void *GetGunIndexInfo(void) { return &gGunIndexInfo; } #if 0 static int findChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData) { uint8_t i = 0; for (i = 0; i < CHAdeMO_QUANTITY; i++) { if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[i].Index == target) { chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[i]; return PASS; } } for (i = 0; i < CCS_QUANTITY; i++) { if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[i].Index == target) { log_info("Index = %d, %d", target, ShmSysConfigAndInfo->SysInfo.CcsChargingData[i].Index); chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[i]; return PASS; } } for (i = 0; i < GB_QUANTITY; i++) { if (ShmSysConfigAndInfo->SysInfo.GbChargingData[i].Index == target) { chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[i]; return PASS; } } return FAIL; } void MappingChargingInfoData(void) //DS60-120 add { bool isPass = true; uint8_t i = 0; while (isPass) { for (i = 0; i < 2; i++) { if (!findChargingInfoData(i, &DcChargingData[0])) { log_error("Find ChargingInfoData failed"); isPass = false; break; } } sleep(1); } } #endif //0 void SetAcChargingInfoData(uint8_t index, struct ChargingInfoData *chargingInfoIndex) { AcChargingData[index] = chargingInfoIndex; } void *GetAcChargingInfoData(uint8_t index) { return AcChargingData[index]; } void SetDcChargingInfoData(uint8_t index, struct ChargingInfoData *chargingInfoIndex) { DcChargingData[index] = chargingInfoIndex; } void *GetDcChargingInfoData(uint8_t index) { return DcChargingData[index]; } void *GetShmSysWarningInfo(void) { if (ShmSysConfigAndInfo == NULL) { return NULL; } return &ShmSysConfigAndInfo->SysWarningInfo; } void *GetShmSysConfigData(void) { if (ShmSysConfigAndInfo == NULL) { return NULL; } return &ShmSysConfigAndInfo->SysConfig; } void *GetShmSysInfoData(void) { if (ShmSysConfigAndInfo == NULL) { return NULL; } return &ShmSysConfigAndInfo->SysInfo; } void *GetShmSysConfigAndInfo(void) { if (ShmSysConfigAndInfo == NULL) { return NULL; } return ShmSysConfigAndInfo; } void *GetShmInfoCodeData(void) { if (ShmStatusCodeData == NULL) { return NULL; } return &ShmStatusCodeData->InfoCode; } void *GetShmFaultCodeData(void) { if (ShmStatusCodeData == NULL) { return NULL; } return &ShmStatusCodeData->FaultCode; } void *GetShmAlarmCodeData(void) { if (ShmStatusCodeData == NULL) { return NULL; } return &ShmStatusCodeData->AlarmCode; } void *GetShmStatusCodeData(void) { if (ShmStatusCodeData == NULL) { return NULL; } return ShmStatusCodeData; } void *GetShmPsuData(void) { if (ShmPsuData == NULL) { return NULL; } return ShmPsuData; } void *GetShmCHAdeMOData(void) { if (ShmCHAdeMOData == NULL) { return NULL; } return ShmCHAdeMOData; } void *GetShmGBTData(void) { if (ShmGBTData == NULL) { return NULL; } return ShmGBTData; } void *GetShmCcsData(void) { if (ShmCcsData == NULL) { return NULL; } return ShmCcsData; } void *GetShmPrimaryMcuData(void) { if (ShmPrimaryMcuData == NULL) { return NULL; } return ShmPrimaryMcuData; } void *GetShmFanModuleData(void) { if (ShmFanModuleData == NULL) { return NULL; } return ShmFanModuleData; } void *GetShmRelayModuleData(void) { if (ShmRelayModuleData == NULL) { return NULL; } return ShmRelayModuleData; } void *GetShmLedModuleData(void) { if (ShmLedModuleData == NULL) { return NULL; } return ShmLedModuleData; } void *GetShmOCPP16Data(void) { if (ShmOCPP16Data == NULL) { return NULL; } return ShmOCPP16Data; } void* GetShmOCPP20Data(void) { if (ShmOCPP20Data == NULL) { return NULL; } return ShmOCPP20Data; } void *GetShmSelectGunInfo(void) { if (ShmSelectGunInfo == NULL) { return NULL; } return ShmSelectGunInfo; } void *GetShmDcCommonData(void) { if (ShmDcCommonData == NULL) { return NULL; } return ShmDcCommonData; } void *GetShmCsuMeterData(void) { if (ShmCsuMeterData == NULL) { return NULL; } return ShmCsuMeterData; } //------------------------------------------------------------------------------ static void initialGunIndexToUnUse(void) { uint8_t index = 0; struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); for (index = 0; index < CHAdeMO_QUANTITY; index++) { pSysInfo->ChademoChargingData[index].Index = NO_DEFINE; } for (index = 0; index < CCS_QUANTITY; index++) { pSysInfo->CcsChargingData[index].Index = NO_DEFINE; } for (index = 0; index < GB_QUANTITY; index++) { pSysInfo->GbChargingData[index].Index = NO_DEFINE; } for (index = 0; index < AC_QUANTITY; index++) { pSysInfo->AcChargingData[index].Index = NO_DEFINE; } } #if 0 static void getFirmwareVersion(void) { uint8_t count = 0, chademo = 0, ccs = 0, gb = 0; uint8_t index = 0; struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData(); struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); // Get CSU root file system version sprintf((char *)pSysInfo->CsuRootFsFwRev, fwVersion); for (index = 0; index < 3; index++) { if (pSysConfig->ModelName[7 + index] == 'J') { chademo++; count++; } else if (pSysConfig->ModelName[7 + index] == 'G') { gb++; count++; } else if (pSysConfig->ModelName[7 + index] == 'U' || pSysConfig->ModelName[7 + index] == 'V' || pSysConfig->ModelName[7 + index] == 'E') { ccs++; count++; } } if (count == 1) { if (chademo > 0) { pSysInfo->CsuRootFsFwRev[7] = '1'; } else if (ccs > 0) { pSysInfo->CsuRootFsFwRev[7] = '2'; } else if (gb > 0) { pSysInfo->CsuRootFsFwRev[7] = '3'; } } else { if (chademo > 0 && ccs > 0) { pSysInfo->CsuRootFsFwRev[7] = '4'; } else if (chademo > 0 && gb > 0) { pSysInfo->CsuRootFsFwRev[7] = '5'; } else if (ccs > 0 && gb > 0) { pSysInfo->CsuRootFsFwRev[7] = '6'; } } // Get network option from model name switch (pSysConfig->ModelName[10]) { case 'B': case 'U': //Blue tooth pSysInfo->CsuRootFsFwRev[9] = '3'; break; case 'W': // WIFI pSysInfo->CsuRootFsFwRev[9] = '1'; break; case 'T': // 3G/4G pSysInfo->CsuRootFsFwRev[9] = '2'; break; case 'D': //DS60-120 add pSysInfo->CsuRootFsFwRev[9] = '5'; break; default: // LAN pSysInfo->CsuRootFsFwRev[9] = '0'; break; } // Get rating power from model name memcpy(&pSysInfo->CsuRootFsFwRev[10], &pSysConfig->ModelName[4], 0x03); // Get IEC or UL char _buf[3] = {0}; memcpy(_buf, &pSysConfig->ModelName[2], 2); if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL) { pSysInfo->ChargerType = _CHARGER_TYPE_IEC; log_info("IEC model"); } else if (strcmp(_buf, "WU") == EQUAL) { pSysInfo->ChargerType = _CHARGER_TYPE_UL; log_info("UL model"); } } #endif //0 void InitialShareMemoryInfo(void) { FILE *fp = NULL; char cmd[512] = {0}; char buf[512] = {0}; struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData(); struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData(); //SysConfig init sprintf((char *)pSysConfig->TelecomInterface.TelcomApn, "Internet"); sprintf((char *)pSysConfig->TelecomInterface.TelcomChapPapId, " "); sprintf((char *)pSysConfig->TelecomInterface.TelcomChapPapPwd, " "); pSysConfig->TotalConnectorCount = 0; pSysConfig->AcConnectorCount = 0; memcpy(pSysInfo->CsuBootLoadFwRev, pSysConfig->CsuBootLoadFwRev, ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev)); strcpy((char *) pSysConfig->UserId, ""); pSysConfig->QRCodeMadeMode = NO; //DS60-120 add pSysConfig->SwitchDebugFlag = NO; pSysConfig->AlwaysGfdFlag = NO; //SysInfo init pSysInfo->FactoryConfiguration = 0; pSysInfo->InputVoltageR = 0; pSysInfo->InputVoltageS = 0; pSysInfo->InputVoltageT = 0; pSysInfo->SystemFanRotaSpeed = 0; pSysInfo->PsuFanRotaSpeed = 0; pSysInfo->AuxPower5V = 0; pSysInfo->AuxPower12V = 0; pSysInfo->AuxPower24V = 0; pSysInfo->AuxPower48V = 0; sprintf((char *)pSysInfo->CsuHwRev, "REV:5.0"); sprintf(cmd, "/bin/uname -r"); fp = popen(cmd, "r"); if (fp == NULL) { sprintf((char *)pSysInfo->CsuKernelFwRev, "Unknown version"); } else { while (fgets(buf, sizeof(buf), fp) != NULL) { strcpy((char *)pSysInfo->CsuKernelFwRev, buf); } } // 雙槍 CCS + Chademo //getFirmwareVersion(); //sprintf((char *) pSysInfo->CsuRootFsFwRev, fwVersion); sprintf((char *) pSysInfo->CsuPrimFwRev, " "); sprintf((char *)pSysInfo->LcmHwRev, " "); sprintf((char *)pSysInfo->LcmFwRev, " "); sprintf((char *)pSysInfo->PsuHwRev, " "); sprintf((char *)pSysInfo->PsuPrimFwRev, " "); sprintf((char *)pSysInfo->PsuSecFwRev, " "); sprintf((char *)pSysInfo->AuxPwrHwRev, " "); sprintf((char *)pSysInfo->AuxPwrFwRev, " "); sprintf((char *)pSysInfo->FanModuleHwRev, " "); sprintf((char *)pSysInfo->FanModuleFwRev, " "); sprintf((char *)pSysInfo->RelayModuleHwRev, " "); sprintf((char *)pSysInfo->RelayModuleFwRev, " "); sprintf((char *)pSysInfo->TelcomModemFwRev, " "); pSysInfo->SystemAmbientTemp = 0; pSysInfo->SystemCriticalTemp = 0; pSysInfo->PsuAmbientTemp = 0; pSysInfo->CcsConnectorTemp = 0; pSysInfo->InternetConn = 0; pSysInfo->OcppConnStatus = 0; pSysInfo->OrderCharging = NO_DEFINE; memset(pSysInfo->FanModuleFwRev, 0, ARRAY_SIZE(pSysInfo->FanModuleFwRev)); memset(pSysInfo->RelayModuleFwRev, 0, ARRAY_SIZE(pSysInfo->RelayModuleFwRev)); #if defined DD360Audi pSysInfo->SystemPage = _LCM_SELECT_GUN; #else pSysInfo->SystemPage = _LCM_NONE; #endif //defined DD360Audi pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX; pSysInfo->ReAssignedFlag = _REASSIGNED_NONE; pSysInfo->CurGunSelectedByAc = NO_DEFINE; pSysInfo->BootingStatus = BOOTTING; //DS60-120 add //other board init ShmPrimaryMcuData->SelfTest_Comp = NO; ShmRelayModuleData->SelfTest_Comp = NO; ShmFanModuleData->SelfTest_Comp = NO; ShmLedModuleData->SelfTest_Comp = NO; ShmFanModuleData->TestFanSpeed = 0; //status code init pAlarmCode->AlarmEvents.bits.RelayboardStestFail = NO; pAlarmCode->AlarmEvents.bits.FanboardStestFail = NO; pAlarmCode->AlarmEvents.bits.PrimaryStestFail = NO; pAlarmCode->AlarmEvents.bits.LedboardStestFail = NO; //DS60-120 Add pAlarmCode->AlarmEvents.bits.ChademoboardStestFail = NO; pAlarmCode->AlarmEvents.bits.CCSboardStestFail = NO; pAlarmCode->AlarmEvents.bits.AcContactStestFail = NO; pAlarmCode->AlarmEvents.bits.PsuModuleStestFail = NO; pAlarmCode->AlarmEvents.bits.PsuDipSwitchStestFail = NO; //DS60-120 Add pAlarmCode->AlarmEvents.bits.ModelNameNoneMatchStestFail = NO; pAlarmCode->AlarmEvents.bits.PsuNoResource = NO; pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = NO; initialGunIndexToUnUse();//DS60-120 add //ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0; //ShmDcCommonData->psuKeepCommunication = NO; //ShmDcCommonData->acContactSwitch = NO; ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0; ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0; ShmDcCommonData->TestTemperature = NO; //ShmDcCommonData->LcmFwVersion = 0; } int InitSelectGunShmMem(void) { int MeterSMId = FAIL; #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox return; #endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } int InitCommonShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmCommonKey, sizeof(DcCommonInfo), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } //int InitCSUMeterShmMem(void) //{ // int MeterSMId = FAIL; // // if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0) { // return FAIL; // } else if ((ShmCsuMeterInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { // return FAIL; // } // // return PASS; //} int InitOCPPShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0) { log_info("Get OCPP share memory error"); return FAIL; } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { log_info("Create OCPP share memory error"); return FAIL; } return PASS; } int InitOCPP20ShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0) { log_info("Get OCPP20 share memory error"); return FAIL; } else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void*)-1) { log_info("Create OCPP20 share memory error"); return FAIL; } return PASS; } int InitLEDShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } int InitRelayShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } int InitFanShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } int InitPrimaryShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } int InitCCSShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } int InitGBShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } int InitCHADeMoShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } int InitPSUDataShmMem(void) { int MeterSMId = FAIL; //creat ShmPsuData if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } int InitStatusCodeShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0) { return FAIL; } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { return FAIL; } return PASS; } int InitSysConfigAndInfoShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0) { printf("1 InitSysConfigAndInfoShmMem"); return FAIL; } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) { printf("2 InitSysConfigAndInfoShmMem"); return FAIL; } return PASS; } int InitShmCsuMeterShmMem(void) { int MeterSMId = FAIL; if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0) { printf("shmget ShmCsuMeterKey NG \n"); return 0; } else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) -1) { printf("shmat ShmCsuMeterData NG \n"); return 0; } return PASS; } void ClearAllShmMemParameter(void) { uint8_t i = 0; memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo)); memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData)); memset(ShmPsuData, 0, sizeof(struct PsuData)); if (CHAdeMO_QUANTITY > 0) { memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData)); } if (GB_QUANTITY > 0) { memset(ShmGBTData, 0, sizeof(struct GBTData)); } if (CCS_QUANTITY > 0) { memset(ShmCcsData, 0, sizeof(struct CcsData)); } memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData)); memset(ShmFanModuleData, 0, sizeof(struct FanModuleData)); memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData)); memset(ShmLedModuleData, 0, sizeof(struct LedModuleData)); //memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data)); //memset(ShmCsuMeterInfo, 0, sizeof(struct MeterInformation)); memset(ShmDcCommonData, 0, sizeof(DcCommonInfo)); #if defined DD360 || defined DD360Audi || defined DD360ComBox memset(ShmSelectGunInfo, 0, sizeof(SelectGunInfo)); for (i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) { ShmSelectGunInfo->PricesInfo[i].Balance = FAIL_BALANCE_PRICES; } #endif //defined DD360 || defined DD360Audi || defined DD360ComBox } static void setAcGunTiggerStatus(void) { struct ChargingInfoData *pAcChargingInfo = NULL; if (gGunIndexInfo.AcGunIndex == 0) { return; } pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(gGunIndexInfo.AcGunIndex); pAcChargingInfo->schedule.isTriggerStart = NO; //DS60-120 add pAcChargingInfo->schedule.isTriggerStop = NO; //DS60-120 add } static int findAcChargingInfoData(uint8_t gunIndex) { struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); //acChargingData[gunIndex] = &pSysInfo->AcChargingData[0]; SetAcChargingInfoData(gunIndex, &pSysInfo->AcChargingData[0]); return PASS; } static int findDcChargingInfoData(uint8_t gunIndex) { uint8_t i = 0; struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); //printf("Chademo count = %d\n", gGunIndexInfo.ChademoIndex); for (i = 0; i < gGunIndexInfo.DcGunIndex; i++) { if (pSysInfo->ChademoChargingData[i].Index == gunIndex) { //printf("chademo index = %d, %d\n", pSysInfo->ChademoChargingData[i].Index, gunIndex); //dcChargingData[gunIndex] = &pSysInfo->ChademoChargingData[i]; SetDcChargingInfoData(pSysInfo->ChademoChargingData[i].Index, &pSysInfo->ChademoChargingData[i]); return PASS; } } //printf("ccs count = %d\n", gGunIndexInfo.CcsIndex); for (i = 0; i < gGunIndexInfo.DcGunIndex; i++) { if (pSysInfo->CcsChargingData[i].Index == gunIndex) { //printf("ccs index = %d, %d\n", pSysInfo->CcsChargingData[i].Index, gunIndex); //dcChargingData[gunIndex] = (struct ChargingInfoData *)&pSysInfo->CcsChargingData[i]; SetDcChargingInfoData(pSysInfo->CcsChargingData[i].Index, &pSysInfo->CcsChargingData[i]); return PASS; } } for (i = 0; i < gGunIndexInfo.DcGunIndex; i++) { if (pSysInfo->GbChargingData[i].Index == gunIndex) { //dcChargingData[gunIndex] = &pSysInfo->GbChargingData[i]; SetDcChargingInfoData(pSysInfo->GbChargingData[i].Index, &pSysInfo->GbChargingData[i]); return PASS; } } return FAIL; } static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichtask) { bool result = true; struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData(); struct ChargingInfoData *pDcChargingInfo = NULL; struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(gGunIndexInfo.AcGunIndex); struct CcsData *pCcsData = (struct CcsData *)GetShmCcsData(); switch (typeValue) { // AC Gun Type ------------------------------------------------------------- case '0': // none break; case '1': // IEC 62196-2 Type 1/SAE J1772 Plug break; case '2': // IEC 62196-2 Type 1/SAE J1772 Socket break; case '3': // IEC 62196-2 Type 2 Plug case '4': // IEC 62196-2 Type 2 Socket if (AC_QUANTITY > gGunIndexInfo.AcIndex) { pAcChargingInfo = (struct ChargingInfoData *)&pSysInfo->AcChargingData[gGunIndexInfo.AcIndex]; // AC 固定 index pAcChargingInfo->Index = 0; pAcChargingInfo->ReservationId = -1; pAcChargingInfo->SystemStatus = S_IDLE; pAcChargingInfo->Type = _Type_AC; pAcChargingInfo->schedule.isTriggerStart = NO; //DS60-120 add pAcChargingInfo->schedule.isTriggerStop = NO; //DS60-120 add //if( strcmp(whichtask,"CSU task") == EQUAL ) { gGunIndexInfo.AcIndex++; gGunIndexInfo.AcGunIndex++; pAcChargingInfo->IsAvailable = YES; } } else { result = false; } break; case '5': // GB/T AC Plug break; case '6': // GB/T AC Socket break; //DC Gun Type -------------------------------------------------------------- case 'J': // CHAdeMO case 'K': // CHAdeMO 200A if (CHAdeMO_QUANTITY > gGunIndexInfo.ChademoIndex) { pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->ChademoChargingData[gGunIndexInfo.ChademoIndex]; pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex; pDcChargingInfo->ReservationId = -1; pDcChargingInfo->slotsIndex = slots; //pDcChargingInfo->SystemStatus = S_BOOTING; //pDcChargingInfo->SystemStatus = S_IDLE; pDcChargingInfo->Type = _Type_Chademo; pDcChargingInfo->type_index = gGunIndexInfo.ChademoIndex; setAcGunTiggerStatus(); //if( strcmp(whichtask,"CSU task") == EQUAL ) { pDcChargingInfo->IsAvailable = YES; gGunIndexInfo.ChademoIndex++; gGunIndexInfo.DcGunIndex++; } } else { result = false; } break; case 'V': // Liquid CCS1 combo case 'F': // Liquid CCS2 combo case 'T': // Rema CCS1 case 'D': // Rema CCS2 case 'U': // CCS1 combo case 'E': // CCS2 combo case 'M': // 80A CCS2 case 'N': // 80A CCS1 case 'P': // 急電弓 if (CCS_QUANTITY > gGunIndexInfo.CcsIndex) { pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->CcsChargingData[gGunIndexInfo.CcsIndex]; pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex; pDcChargingInfo->ReservationId = -1; pDcChargingInfo->slotsIndex = slots; //pDcChargingInfo->SystemStatus = S_BOOTING; pDcChargingInfo->Type = _Type_CCS_2; pDcChargingInfo->type_index = gGunIndexInfo.CcsIndex; setAcGunTiggerStatus(); // 現階段預設為走 DIN70121 pCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121; //if( strcmp(whichtask,"CSU task") == EQUAL ) { pDcChargingInfo->IsAvailable = YES; gGunIndexInfo.CcsIndex++; gGunIndexInfo.DcGunIndex++; } if(typeValue == 'P') { pDcChargingInfo->PantographFlag = YES; } else if (typeValue == 'V') { pDcChargingInfo->CCSGunType = _TYPE_CCS1_Liquid; } else if (typeValue == 'F') { pDcChargingInfo->CCSGunType = _TYPE_CCS2_Liquid; } else if (typeValue == 'T' || typeValue == 'U' || typeValue == 'N') { pDcChargingInfo->CCSGunType = _TYPE_CCS1_Natural; } else if (typeValue == 'D' || typeValue == 'E' || typeValue == 'M') { pDcChargingInfo->CCSGunType = _TYPE_CCS2_Natural; } else pDcChargingInfo->CCSGunType = _TYPE_CCS_NONE; } else { result = false; } break; case 'G': // GBT DC case 'B': // GBT YG PT100 if (GB_QUANTITY > gGunIndexInfo.GbIndex) { pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->GbChargingData[gGunIndexInfo.GbIndex]; pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex; pDcChargingInfo->ReservationId = -1; pDcChargingInfo->slotsIndex = slots; //pDcChargingInfo->SystemStatus = S_BOOTING; pDcChargingInfo->Type = _Type_GB; pDcChargingInfo->type_index = gGunIndexInfo.GbIndex; setAcGunTiggerStatus(); //if( strcmp(whichtask,"CSU task") == EQUAL ) { pDcChargingInfo->IsAvailable = YES; gGunIndexInfo.GbIndex++; gGunIndexInfo.DcGunIndex++; } } else { result = false; } break; //case 'D': // GBT DC x 2 // break; //default: // result = false; // break; } return result; } bool MappingGunChargingInfo(char *whichTask) { bool result = true; uint8_t typeIndex = 0; uint8_t slots = 1; uint8_t gunIndex = 0; struct SysConfigData *pSysConfig = NULL; //struct ChargingInfoData *pDcChargingInfo = NULL; struct ChargingInfoData *pAcChargingInfo = NULL; if (ShmSysConfigAndInfo == NULL) { log_error("ShmSysConfigAndInfo failed"); return false; } pSysConfig = (struct SysConfigData *)GetShmSysConfigData(); if (strlen((char *)pSysConfig->ModelName) < 9) { log_error("Module name length < 9 get %s", (char *)pSysConfig->ModelName); return false; } ShmDcCommonData->ChillerValve.MultiChillerGun = 0; //printf("1 CheckConnectorTypeStatus\n"); for (typeIndex = 7; typeIndex <= 9; typeIndex++) { if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots, whichTask)) { log_error("%s add gun info failed", whichTask); return false; } //確認有幾把水冷槍 if (strncmp((char *)&pSysConfig->ModelName[typeIndex], "V", 1) == 0 || strncmp((char *)&pSysConfig->ModelName[typeIndex], "F", 1) == 0 ) { ShmDcCommonData->ChillerValve.MultiChillerGun++; //水冷槍數 } slots++; } if (ShmDcCommonData->ChillerValve.MultiChillerGun != 0) { ShmDcCommonData->ChillerValve.MultiChillerGun |= 0x80; //有水冷槍標記 if (strncmp(whichTask, "CSU Task", 8) == EQUAL) { log_info("get chiller gun = %x, chiller gun count = %d", (ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7, ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F); } } // AC index 接在 DC 後面 //if (AC_QUANTITY > 0) { if (gGunIndexInfo.AcIndex > 0) { //DS60-120 add pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0); pAcChargingInfo->Index += gGunIndexInfo.DcGunIndex; } pSysConfig->TotalConnectorCount = gGunIndexInfo.DcGunIndex; pSysConfig->AcConnectorCount = gGunIndexInfo.AcGunIndex; if (strcmp(whichTask, "CSU Task") == 0) { log_info("DC connector Quality = %d, AC connector Quality = %d", pSysConfig->TotalConnectorCount, pSysConfig->AcConnectorCount); } for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) { findDcChargingInfoData(gunIndex); } findAcChargingInfoData(gunIndex); //log_info("Type 0~3 = CHAdeMO, CCS, GB, AC"); if (pSysConfig->TotalConnectorCount == 0 && pSysConfig->AcConnectorCount == 0) { log_error("DC %d or AC %d connector failed", pSysConfig->TotalConnectorCount, pSysConfig->AcConnectorCount); result = false; } return result; } int CreateAllCsuShareMemory(void) { int ret = FAIL; if ((ret = InitSysConfigAndInfoShmMem()) == FAIL) { return ret; } if ((ret = InitStatusCodeShmMem()) == FAIL) { return ret; } if ((ret = InitPSUDataShmMem()) == FAIL) { return ret; } if (CHAdeMO_QUANTITY > 0) { if ((ret = InitCHADeMoShmMem()) == FAIL) { return ret; } } if (GB_QUANTITY > 0) { if ((ret = InitGBShmMem()) == FAIL) { return ret; } } //creat ShmCcsData if (CCS_QUANTITY > 0) { if ((ret = InitCCSShmMem()) == FAIL) { return ret; } } if ((ret = InitPrimaryShmMem()) == FAIL) { return ret; } if ((ret = InitFanShmMem()) == FAIL) { return ret; } if ((ret = InitRelayShmMem()) == FAIL) { return ret; } if ((ret = InitLEDShmMem()) == FAIL) { return ret; } if ((ret = InitOCPPShmMem()) == FAIL) { return ret; } if ((ret = InitOCPP20ShmMem()) == FAIL) { return ret; } if ((ret = InitSelectGunShmMem()) == FAIL) { return ret; } if ((ret = InitSelectGunShmMem()) == FAIL) { return ret; } if ((ret = InitCommonShmMem()) == FAIL) { return ret; } if ((ret = InitShmCsuMeterShmMem()) == FAIL) { return ret; } //ClearAllShmMemParameter(); //MappingChargingInfoData(); //initialShareMemoryParameter(); //initialGunIndexToUnUse(); sleep(1); return PASS; }