12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205 |
- #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 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;
- }
|