1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <string.h>
- #include <stdbool.h>
- #include <unistd.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #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 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;
- }
- //------------------------------------------------------------------------------
- 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;
- }
- }
- 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));
- pSysInfo->SystemPage = _PAGE_IDLE;
- 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 DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
- return;
- #endif //!defined DD360Tcci && !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;
- }
- 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 DD360Tcci || defined DD360Audi || defined DD360ComBox || defined DD360UCar
- memset(ShmSelectGunInfo, 0, sizeof(SelectGunInfo));
- for (i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
- ShmSelectGunInfo->PricesInfo[i].Balance = FAIL_BALANCE_PRICES;
- }
- #endif //defined DD360Tcci || 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;
- case '7': // CCS2 AC plug
- break;
- case '8': // Type E 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;
- }
- //ClearAllShmMemParameter();
- //MappingChargingInfoData();
- //initialShareMemoryParameter();
- //initialGunIndexToUnUse();
- sleep(1);
- return PASS;
- }
|