shmMem.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <stdbool.h>
  6. #include <unistd.h>
  7. #include <sys/ipc.h>
  8. #include <sys/shm.h>
  9. #include "../Define/define.h"
  10. //#include "../AudiCust.h"
  11. #include "../SelectGun/SelectGun.h"
  12. #include "../common.h"
  13. #include "../Log/log.h"
  14. #include "../Config.h"
  15. #include "shmMem.h"
  16. //------------------------------------------------------------------------------
  17. static struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
  18. //static struct SysInfoData *ShmSysInfoData = NULL;
  19. //static struct SysConfigData *ShmSysConfigData = NULL;
  20. //static struct WARNING_CODE_INFO *SysWarningInfo = NULL;
  21. static struct StatusCodeData *ShmStatusCodeData = NULL;
  22. //static struct AlarmCodeData *ShmAlarmCodeData = NULL;
  23. //static struct FaultCodeData *ShmFaultCodeData = NULL;
  24. //static struct InfoCodeData *ShmInfoCodeData = NULL;
  25. static struct PsuData *ShmPsuData = NULL;
  26. static struct CHAdeMOData *ShmCHAdeMOData = NULL;
  27. static struct GBTData *ShmGBTData = NULL;
  28. static struct CcsData *ShmCcsData = NULL;
  29. static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
  30. static struct FanModuleData *ShmFanModuleData = NULL;
  31. static struct RelayModuleData *ShmRelayModuleData = NULL;
  32. static struct LedModuleData *ShmLedModuleData = NULL;
  33. static struct OCPP16Data *ShmOCPP16Data = NULL;
  34. static struct OCPP20Data* ShmOCPP20Data = NULL;
  35. static SelectGunInfo *ShmSelectGunInfo = NULL;
  36. static DcCommonInfo *ShmDcCommonData = NULL;
  37. static struct ChargingInfoData *DcChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY] = {NULL};
  38. static struct ChargingInfoData *AcChargingData[AC_QUANTITY] = {NULL};
  39. static GunIndexInfo gGunIndexInfo = {0};
  40. //struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  41. //struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  42. //struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  43. //struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  44. //struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
  45. //struct FaultCodeData *pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
  46. //struct PsuData *ShmPsuData = (struct PsuData *)GetShmPsuData();
  47. //struct CHAdeMOData *ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  48. //struct GBTData *ShmGBTData = (struct GBTData *)GetShmGBTData();
  49. //struct CcsData *ShmCcsData = (struct CcsData *)GetShmCcsData();
  50. //struct PrimaryMcuData *ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  51. //struct FanModuleData *ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  52. //struct RelayModuleData *ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  53. //struct LedModuleData *ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
  54. //struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  55. //SelectGunInfo *ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  56. //DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  57. //struct ChargingInfoData *pDcChargingInfo = NULL;
  58. //struct ChargingInfoData *pAcChargingInfo = NULL;
  59. //------------------------------------------------------------------------------
  60. void *GetGunIndexInfo(void)
  61. {
  62. return &gGunIndexInfo;
  63. }
  64. #if 0
  65. static int findChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
  66. {
  67. uint8_t i = 0;
  68. for (i = 0; i < CHAdeMO_QUANTITY; i++) {
  69. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[i].Index == target) {
  70. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[i];
  71. return PASS;
  72. }
  73. }
  74. for (i = 0; i < CCS_QUANTITY; i++) {
  75. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[i].Index == target) {
  76. log_info("Index = %d, %d", target, ShmSysConfigAndInfo->SysInfo.CcsChargingData[i].Index);
  77. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[i];
  78. return PASS;
  79. }
  80. }
  81. for (i = 0; i < GB_QUANTITY; i++) {
  82. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[i].Index == target) {
  83. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[i];
  84. return PASS;
  85. }
  86. }
  87. return FAIL;
  88. }
  89. void MappingChargingInfoData(void) //DS60-120 add
  90. {
  91. bool isPass = true;
  92. uint8_t i = 0;
  93. while (isPass) {
  94. for (i = 0; i < 2; i++) {
  95. if (!findChargingInfoData(i, &DcChargingData[0])) {
  96. log_error("Find ChargingInfoData failed");
  97. isPass = false;
  98. break;
  99. }
  100. }
  101. sleep(1);
  102. }
  103. }
  104. #endif //0
  105. void SetAcChargingInfoData(uint8_t index, struct ChargingInfoData *chargingInfoIndex)
  106. {
  107. AcChargingData[index] = chargingInfoIndex;
  108. }
  109. void *GetAcChargingInfoData(uint8_t index)
  110. {
  111. return AcChargingData[index];
  112. }
  113. void SetDcChargingInfoData(uint8_t index, struct ChargingInfoData *chargingInfoIndex)
  114. {
  115. DcChargingData[index] = chargingInfoIndex;
  116. }
  117. void *GetDcChargingInfoData(uint8_t index)
  118. {
  119. return DcChargingData[index];
  120. }
  121. void *GetShmSysWarningInfo(void)
  122. {
  123. if (ShmSysConfigAndInfo == NULL) {
  124. return NULL;
  125. }
  126. return &ShmSysConfigAndInfo->SysWarningInfo;
  127. }
  128. void *GetShmSysConfigData(void)
  129. {
  130. if (ShmSysConfigAndInfo == NULL) {
  131. return NULL;
  132. }
  133. return &ShmSysConfigAndInfo->SysConfig;
  134. }
  135. void *GetShmSysInfoData(void)
  136. {
  137. if (ShmSysConfigAndInfo == NULL) {
  138. return NULL;
  139. }
  140. return &ShmSysConfigAndInfo->SysInfo;
  141. }
  142. void *GetShmSysConfigAndInfo(void)
  143. {
  144. if (ShmSysConfigAndInfo == NULL) {
  145. return NULL;
  146. }
  147. return ShmSysConfigAndInfo;
  148. }
  149. void *GetShmInfoCodeData(void)
  150. {
  151. if (ShmStatusCodeData == NULL) {
  152. return NULL;
  153. }
  154. return &ShmStatusCodeData->InfoCode;
  155. }
  156. void *GetShmFaultCodeData(void)
  157. {
  158. if (ShmStatusCodeData == NULL) {
  159. return NULL;
  160. }
  161. return &ShmStatusCodeData->FaultCode;
  162. }
  163. void *GetShmAlarmCodeData(void)
  164. {
  165. if (ShmStatusCodeData == NULL) {
  166. return NULL;
  167. }
  168. return &ShmStatusCodeData->AlarmCode;
  169. }
  170. void *GetShmStatusCodeData(void)
  171. {
  172. if (ShmStatusCodeData == NULL) {
  173. return NULL;
  174. }
  175. return ShmStatusCodeData;
  176. }
  177. void *GetShmPsuData(void)
  178. {
  179. if (ShmPsuData == NULL) {
  180. return NULL;
  181. }
  182. return ShmPsuData;
  183. }
  184. void *GetShmCHAdeMOData(void)
  185. {
  186. if (ShmCHAdeMOData == NULL) {
  187. return NULL;
  188. }
  189. return ShmCHAdeMOData;
  190. }
  191. void *GetShmGBTData(void)
  192. {
  193. if (ShmGBTData == NULL) {
  194. return NULL;
  195. }
  196. return ShmGBTData;
  197. }
  198. void *GetShmCcsData(void)
  199. {
  200. if (ShmCcsData == NULL) {
  201. return NULL;
  202. }
  203. return ShmCcsData;
  204. }
  205. void *GetShmPrimaryMcuData(void)
  206. {
  207. if (ShmPrimaryMcuData == NULL) {
  208. return NULL;
  209. }
  210. return ShmPrimaryMcuData;
  211. }
  212. void *GetShmFanModuleData(void)
  213. {
  214. if (ShmFanModuleData == NULL) {
  215. return NULL;
  216. }
  217. return ShmFanModuleData;
  218. }
  219. void *GetShmRelayModuleData(void)
  220. {
  221. if (ShmRelayModuleData == NULL) {
  222. return NULL;
  223. }
  224. return ShmRelayModuleData;
  225. }
  226. void *GetShmLedModuleData(void)
  227. {
  228. if (ShmLedModuleData == NULL) {
  229. return NULL;
  230. }
  231. return ShmLedModuleData;
  232. }
  233. void *GetShmOCPP16Data(void)
  234. {
  235. if (ShmOCPP16Data == NULL) {
  236. return NULL;
  237. }
  238. return ShmOCPP16Data;
  239. }
  240. void* GetShmOCPP20Data(void)
  241. {
  242. if (ShmOCPP20Data == NULL) {
  243. return NULL;
  244. }
  245. return ShmOCPP20Data;
  246. }
  247. void *GetShmSelectGunInfo(void)
  248. {
  249. if (ShmSelectGunInfo == NULL) {
  250. return NULL;
  251. }
  252. return ShmSelectGunInfo;
  253. }
  254. void *GetShmDcCommonData(void)
  255. {
  256. if (ShmDcCommonData == NULL) {
  257. return NULL;
  258. }
  259. return ShmDcCommonData;
  260. }
  261. //------------------------------------------------------------------------------
  262. static void initialGunIndexToUnUse(void)
  263. {
  264. uint8_t index = 0;
  265. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  266. for (index = 0; index < CHAdeMO_QUANTITY; index++) {
  267. pSysInfo->ChademoChargingData[index].Index = NO_DEFINE;
  268. }
  269. for (index = 0; index < CCS_QUANTITY; index++) {
  270. pSysInfo->CcsChargingData[index].Index = NO_DEFINE;
  271. }
  272. for (index = 0; index < GB_QUANTITY; index++) {
  273. pSysInfo->GbChargingData[index].Index = NO_DEFINE;
  274. }
  275. for (index = 0; index < AC_QUANTITY; index++) {
  276. pSysInfo->AcChargingData[index].Index = NO_DEFINE;
  277. }
  278. }
  279. void InitialShareMemoryInfo(void)
  280. {
  281. FILE *fp = NULL;
  282. char cmd[512] = {0};
  283. char buf[512] = {0};
  284. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  285. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  286. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  287. //SysConfig init
  288. sprintf((char *)pSysConfig->TelecomInterface.TelcomApn, "Internet");
  289. sprintf((char *)pSysConfig->TelecomInterface.TelcomChapPapId, " ");
  290. sprintf((char *)pSysConfig->TelecomInterface.TelcomChapPapPwd, " ");
  291. pSysConfig->TotalConnectorCount = 0;
  292. pSysConfig->AcConnectorCount = 0;
  293. memcpy(pSysInfo->CsuBootLoadFwRev,
  294. pSysConfig->CsuBootLoadFwRev,
  295. ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev));
  296. strcpy((char *) pSysConfig->UserId, "");
  297. pSysConfig->QRCodeMadeMode = NO; //DS60-120 add
  298. pSysConfig->SwitchDebugFlag = NO;
  299. pSysConfig->AlwaysGfdFlag = NO;
  300. //SysInfo init
  301. pSysInfo->FactoryConfiguration = 0;
  302. pSysInfo->InputVoltageR = 0;
  303. pSysInfo->InputVoltageS = 0;
  304. pSysInfo->InputVoltageT = 0;
  305. pSysInfo->SystemFanRotaSpeed = 0;
  306. pSysInfo->PsuFanRotaSpeed = 0;
  307. pSysInfo->AuxPower5V = 0;
  308. pSysInfo->AuxPower12V = 0;
  309. pSysInfo->AuxPower24V = 0;
  310. pSysInfo->AuxPower48V = 0;
  311. sprintf((char *)pSysInfo->CsuHwRev, "REV:5.0");
  312. sprintf(cmd, "/bin/uname -r");
  313. fp = popen(cmd, "r");
  314. if (fp == NULL) {
  315. sprintf((char *)pSysInfo->CsuKernelFwRev, "Unknown version");
  316. } else {
  317. while (fgets(buf, sizeof(buf), fp) != NULL) {
  318. strcpy((char *)pSysInfo->CsuKernelFwRev, buf);
  319. }
  320. }
  321. // 雙槍 CCS + Chademo
  322. //getFirmwareVersion();
  323. //sprintf((char *) pSysInfo->CsuRootFsFwRev, fwVersion);
  324. sprintf((char *) pSysInfo->CsuPrimFwRev, " ");
  325. sprintf((char *)pSysInfo->LcmHwRev, " ");
  326. sprintf((char *)pSysInfo->LcmFwRev, " ");
  327. sprintf((char *)pSysInfo->PsuHwRev, " ");
  328. sprintf((char *)pSysInfo->PsuPrimFwRev, " ");
  329. sprintf((char *)pSysInfo->PsuSecFwRev, " ");
  330. sprintf((char *)pSysInfo->AuxPwrHwRev, " ");
  331. sprintf((char *)pSysInfo->AuxPwrFwRev, " ");
  332. sprintf((char *)pSysInfo->FanModuleHwRev, " ");
  333. sprintf((char *)pSysInfo->FanModuleFwRev, " ");
  334. sprintf((char *)pSysInfo->RelayModuleHwRev, " ");
  335. sprintf((char *)pSysInfo->RelayModuleFwRev, " ");
  336. sprintf((char *)pSysInfo->TelcomModemFwRev, " ");
  337. pSysInfo->SystemAmbientTemp = 0;
  338. pSysInfo->SystemCriticalTemp = 0;
  339. pSysInfo->PsuAmbientTemp = 0;
  340. pSysInfo->CcsConnectorTemp = 0;
  341. pSysInfo->InternetConn = 0;
  342. pSysInfo->OcppConnStatus = 0;
  343. pSysInfo->OrderCharging = NO_DEFINE;
  344. memset(pSysInfo->FanModuleFwRev, 0, ARRAY_SIZE(pSysInfo->FanModuleFwRev));
  345. memset(pSysInfo->RelayModuleFwRev, 0, ARRAY_SIZE(pSysInfo->RelayModuleFwRev));
  346. pSysInfo->SystemPage = _PAGE_IDLE;
  347. pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
  348. pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
  349. pSysInfo->CurGunSelectedByAc = NO_DEFINE;
  350. pSysInfo->BootingStatus = BOOTTING; //DS60-120 add
  351. //other board init
  352. ShmPrimaryMcuData->SelfTest_Comp = NO;
  353. ShmRelayModuleData->SelfTest_Comp = NO;
  354. ShmFanModuleData->SelfTest_Comp = NO;
  355. ShmLedModuleData->SelfTest_Comp = NO;
  356. ShmFanModuleData->TestFanSpeed = 0;
  357. //status code init
  358. pAlarmCode->AlarmEvents.bits.RelayboardStestFail = NO;
  359. pAlarmCode->AlarmEvents.bits.FanboardStestFail = NO;
  360. pAlarmCode->AlarmEvents.bits.PrimaryStestFail = NO;
  361. pAlarmCode->AlarmEvents.bits.LedboardStestFail = NO; //DS60-120 Add
  362. pAlarmCode->AlarmEvents.bits.ChademoboardStestFail = NO;
  363. pAlarmCode->AlarmEvents.bits.CCSboardStestFail = NO;
  364. pAlarmCode->AlarmEvents.bits.AcContactStestFail = NO;
  365. pAlarmCode->AlarmEvents.bits.PsuModuleStestFail = NO;
  366. pAlarmCode->AlarmEvents.bits.PsuDipSwitchStestFail = NO; //DS60-120 Add
  367. pAlarmCode->AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
  368. pAlarmCode->AlarmEvents.bits.PsuNoResource = NO;
  369. pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = NO;
  370. initialGunIndexToUnUse();//DS60-120 add
  371. //ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0;
  372. //ShmDcCommonData->psuKeepCommunication = NO;
  373. //ShmDcCommonData->acContactSwitch = NO;
  374. ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0;
  375. ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0;
  376. ShmDcCommonData->TestTemperature = NO;
  377. //ShmDcCommonData->LcmFwVersion = 0;
  378. }
  379. int InitSelectGunShmMem(void)
  380. {
  381. int MeterSMId = FAIL;
  382. #if !defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox && !defined DD360UCar
  383. return;
  384. #endif //!defined DD360Tcci && !defined DD360Audi && !defined DD360ComBox
  385. if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
  386. return FAIL;
  387. } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  388. return FAIL;
  389. }
  390. return PASS;
  391. }
  392. int InitCommonShmMem(void)
  393. {
  394. int MeterSMId = FAIL;
  395. if ((MeterSMId = shmget(ShmCommonKey, sizeof(DcCommonInfo), IPC_CREAT | 0777)) < 0) {
  396. return FAIL;
  397. } else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  398. return FAIL;
  399. }
  400. return PASS;
  401. }
  402. //int InitCSUMeterShmMem(void)
  403. //{
  404. // int MeterSMId = FAIL;
  405. //
  406. // if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0) {
  407. // return FAIL;
  408. // } else if ((ShmCsuMeterInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  409. // return FAIL;
  410. // }
  411. //
  412. // return PASS;
  413. //}
  414. int InitOCPPShmMem(void)
  415. {
  416. int MeterSMId = FAIL;
  417. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0) {
  418. log_info("Get OCPP share memory error");
  419. return FAIL;
  420. } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  421. log_info("Create OCPP share memory error");
  422. return FAIL;
  423. }
  424. return PASS;
  425. }
  426. int InitOCPP20ShmMem(void)
  427. {
  428. int MeterSMId = FAIL;
  429. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0) {
  430. log_info("Get OCPP20 share memory error");
  431. return FAIL;
  432. } else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void*)-1) {
  433. log_info("Create OCPP20 share memory error");
  434. return FAIL;
  435. }
  436. return PASS;
  437. }
  438. int InitLEDShmMem(void)
  439. {
  440. int MeterSMId = FAIL;
  441. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0) {
  442. return FAIL;
  443. } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  444. return FAIL;
  445. }
  446. return PASS;
  447. }
  448. int InitRelayShmMem(void)
  449. {
  450. int MeterSMId = FAIL;
  451. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0) {
  452. return FAIL;
  453. } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  454. return FAIL;
  455. }
  456. return PASS;
  457. }
  458. int InitFanShmMem(void)
  459. {
  460. int MeterSMId = FAIL;
  461. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0) {
  462. return FAIL;
  463. } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  464. return FAIL;
  465. }
  466. return PASS;
  467. }
  468. int InitPrimaryShmMem(void)
  469. {
  470. int MeterSMId = FAIL;
  471. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0) {
  472. return FAIL;
  473. } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  474. return FAIL;
  475. }
  476. return PASS;
  477. }
  478. int InitCCSShmMem(void)
  479. {
  480. int MeterSMId = FAIL;
  481. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0) {
  482. return FAIL;
  483. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  484. return FAIL;
  485. }
  486. return PASS;
  487. }
  488. int InitGBShmMem(void)
  489. {
  490. int MeterSMId = FAIL;
  491. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0) {
  492. return FAIL;
  493. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  494. return FAIL;
  495. }
  496. return PASS;
  497. }
  498. int InitCHADeMoShmMem(void)
  499. {
  500. int MeterSMId = FAIL;
  501. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0) {
  502. return FAIL;
  503. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  504. return FAIL;
  505. }
  506. return PASS;
  507. }
  508. int InitPSUDataShmMem(void)
  509. {
  510. int MeterSMId = FAIL;
  511. //creat ShmPsuData
  512. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0) {
  513. return FAIL;
  514. } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  515. return FAIL;
  516. }
  517. return PASS;
  518. }
  519. int InitStatusCodeShmMem(void)
  520. {
  521. int MeterSMId = FAIL;
  522. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0) {
  523. return FAIL;
  524. } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  525. return FAIL;
  526. }
  527. return PASS;
  528. }
  529. int InitSysConfigAndInfoShmMem(void)
  530. {
  531. int MeterSMId = FAIL;
  532. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0) {
  533. printf("1 InitSysConfigAndInfoShmMem");
  534. return FAIL;
  535. } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  536. printf("2 InitSysConfigAndInfoShmMem");
  537. return FAIL;
  538. }
  539. return PASS;
  540. }
  541. void ClearAllShmMemParameter(void)
  542. {
  543. uint8_t i = 0;
  544. memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  545. memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
  546. memset(ShmPsuData, 0, sizeof(struct PsuData));
  547. if (CHAdeMO_QUANTITY > 0) {
  548. memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
  549. }
  550. if (GB_QUANTITY > 0) {
  551. memset(ShmGBTData, 0, sizeof(struct GBTData));
  552. }
  553. if (CCS_QUANTITY > 0) {
  554. memset(ShmCcsData, 0, sizeof(struct CcsData));
  555. }
  556. memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
  557. memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
  558. memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
  559. memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
  560. //memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
  561. //memset(ShmCsuMeterInfo, 0, sizeof(struct MeterInformation));
  562. memset(ShmDcCommonData, 0, sizeof(DcCommonInfo));
  563. #if defined DD360Tcci || defined DD360Audi || defined DD360ComBox || defined DD360UCar
  564. memset(ShmSelectGunInfo, 0, sizeof(SelectGunInfo));
  565. for (i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
  566. ShmSelectGunInfo->PricesInfo[i].Balance = FAIL_BALANCE_PRICES;
  567. }
  568. #endif //defined DD360Tcci || defined DD360Audi || defined DD360ComBox
  569. }
  570. static void setAcGunTiggerStatus(void)
  571. {
  572. struct ChargingInfoData *pAcChargingInfo = NULL;
  573. if (gGunIndexInfo.AcGunIndex == 0) {
  574. return;
  575. }
  576. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(gGunIndexInfo.AcGunIndex);
  577. pAcChargingInfo->schedule.isTriggerStart = NO; //DS60-120 add
  578. pAcChargingInfo->schedule.isTriggerStop = NO; //DS60-120 add
  579. }
  580. static int findAcChargingInfoData(uint8_t gunIndex)
  581. {
  582. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  583. //acChargingData[gunIndex] = &pSysInfo->AcChargingData[0];
  584. SetAcChargingInfoData(gunIndex, &pSysInfo->AcChargingData[0]);
  585. return PASS;
  586. }
  587. static int findDcChargingInfoData(uint8_t gunIndex)
  588. {
  589. uint8_t i = 0;
  590. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  591. //printf("Chademo count = %d\n", gGunIndexInfo.ChademoIndex);
  592. for (i = 0; i < gGunIndexInfo.DcGunIndex; i++) {
  593. if (pSysInfo->ChademoChargingData[i].Index == gunIndex) {
  594. //printf("chademo index = %d, %d\n", pSysInfo->ChademoChargingData[i].Index, gunIndex);
  595. //dcChargingData[gunIndex] = &pSysInfo->ChademoChargingData[i];
  596. SetDcChargingInfoData(pSysInfo->ChademoChargingData[i].Index, &pSysInfo->ChademoChargingData[i]);
  597. return PASS;
  598. }
  599. }
  600. //printf("ccs count = %d\n", gGunIndexInfo.CcsIndex);
  601. for (i = 0; i < gGunIndexInfo.DcGunIndex; i++) {
  602. if (pSysInfo->CcsChargingData[i].Index == gunIndex) {
  603. //printf("ccs index = %d, %d\n", pSysInfo->CcsChargingData[i].Index, gunIndex);
  604. //dcChargingData[gunIndex] = (struct ChargingInfoData *)&pSysInfo->CcsChargingData[i];
  605. SetDcChargingInfoData(pSysInfo->CcsChargingData[i].Index, &pSysInfo->CcsChargingData[i]);
  606. return PASS;
  607. }
  608. }
  609. for (i = 0; i < gGunIndexInfo.DcGunIndex; i++) {
  610. if (pSysInfo->GbChargingData[i].Index == gunIndex) {
  611. //dcChargingData[gunIndex] = &pSysInfo->GbChargingData[i];
  612. SetDcChargingInfoData(pSysInfo->GbChargingData[i].Index, &pSysInfo->GbChargingData[i]);
  613. return PASS;
  614. }
  615. }
  616. return FAIL;
  617. }
  618. static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots,char *whichtask)
  619. {
  620. bool result = true;
  621. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  622. struct ChargingInfoData *pDcChargingInfo = NULL;
  623. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(gGunIndexInfo.AcGunIndex);
  624. struct CcsData *pCcsData = (struct CcsData *)GetShmCcsData();
  625. switch (typeValue) {
  626. // AC Gun Type -------------------------------------------------------------
  627. case '0': // none
  628. break;
  629. case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
  630. break;
  631. case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
  632. break;
  633. case '3': // IEC 62196-2 Type 2 Plug
  634. case '4': // IEC 62196-2 Type 2 Socket
  635. if (AC_QUANTITY > gGunIndexInfo.AcIndex) {
  636. pAcChargingInfo = (struct ChargingInfoData *)&pSysInfo->AcChargingData[gGunIndexInfo.AcIndex];
  637. // AC 固定 index
  638. pAcChargingInfo->Index = 0;
  639. pAcChargingInfo->ReservationId = -1;
  640. pAcChargingInfo->SystemStatus = S_IDLE;
  641. pAcChargingInfo->Type = _Type_AC;
  642. pAcChargingInfo->schedule.isTriggerStart = NO; //DS60-120 add
  643. pAcChargingInfo->schedule.isTriggerStop = NO; //DS60-120 add
  644. //if( strcmp(whichtask,"CSU task") == EQUAL )
  645. {
  646. gGunIndexInfo.AcIndex++;
  647. gGunIndexInfo.AcGunIndex++;
  648. pAcChargingInfo->IsAvailable = YES;
  649. }
  650. } else {
  651. result = false;
  652. }
  653. break;
  654. case '5': // GB/T AC Plug
  655. break;
  656. case '6': // GB/T AC Socket
  657. break;
  658. case '7': // CCS2 AC plug
  659. break;
  660. case '8': // Type E Socket
  661. break;
  662. //DC Gun Type --------------------------------------------------------------
  663. case 'J': // CHAdeMO
  664. case 'K': // CHAdeMO 200A
  665. if (CHAdeMO_QUANTITY > gGunIndexInfo.ChademoIndex) {
  666. pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->ChademoChargingData[gGunIndexInfo.ChademoIndex];
  667. pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
  668. pDcChargingInfo->ReservationId = -1;
  669. pDcChargingInfo->slotsIndex = slots;
  670. //pDcChargingInfo->SystemStatus = S_BOOTING;
  671. //pDcChargingInfo->SystemStatus = S_IDLE;
  672. pDcChargingInfo->Type = _Type_Chademo;
  673. pDcChargingInfo->type_index = gGunIndexInfo.ChademoIndex;
  674. setAcGunTiggerStatus();
  675. //if( strcmp(whichtask,"CSU task") == EQUAL )
  676. {
  677. pDcChargingInfo->IsAvailable = YES;
  678. gGunIndexInfo.ChademoIndex++;
  679. gGunIndexInfo.DcGunIndex++;
  680. }
  681. } else {
  682. result = false;
  683. }
  684. break;
  685. case 'V': // Liquid CCS1 combo
  686. case 'F': // Liquid CCS2 combo
  687. case 'T': // Rema CCS1
  688. case 'D': // Rema CCS2
  689. case 'U': // CCS1 combo
  690. case 'E': // CCS2 combo
  691. case 'M': // 80A CCS2
  692. case 'N': // 80A CCS1
  693. case 'P': // 急電弓
  694. if (CCS_QUANTITY > gGunIndexInfo.CcsIndex) {
  695. pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->CcsChargingData[gGunIndexInfo.CcsIndex];
  696. pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
  697. pDcChargingInfo->ReservationId = -1;
  698. pDcChargingInfo->slotsIndex = slots;
  699. //pDcChargingInfo->SystemStatus = S_BOOTING;
  700. pDcChargingInfo->Type = _Type_CCS_2;
  701. pDcChargingInfo->type_index = gGunIndexInfo.CcsIndex;
  702. setAcGunTiggerStatus();
  703. // 現階段預設為走 DIN70121
  704. pCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
  705. //if( strcmp(whichtask,"CSU task") == EQUAL )
  706. {
  707. pDcChargingInfo->IsAvailable = YES;
  708. gGunIndexInfo.CcsIndex++;
  709. gGunIndexInfo.DcGunIndex++;
  710. }
  711. if(typeValue == 'P') {
  712. pDcChargingInfo->PantographFlag = YES;
  713. } else if (typeValue == 'V') {
  714. pDcChargingInfo->CCSGunType = _TYPE_CCS1_Liquid;
  715. } else if (typeValue == 'F') {
  716. pDcChargingInfo->CCSGunType = _TYPE_CCS2_Liquid;
  717. } else if (typeValue == 'T' || typeValue == 'U' || typeValue == 'N') {
  718. pDcChargingInfo->CCSGunType = _TYPE_CCS1_Natural;
  719. } else if (typeValue == 'D' || typeValue == 'E' || typeValue == 'M') {
  720. pDcChargingInfo->CCSGunType = _TYPE_CCS2_Natural;
  721. } else
  722. pDcChargingInfo->CCSGunType = _TYPE_CCS_NONE;
  723. } else {
  724. result = false;
  725. }
  726. break;
  727. case 'G': // GBT DC
  728. case 'B': // GBT YG PT100
  729. if (GB_QUANTITY > gGunIndexInfo.GbIndex) {
  730. pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->GbChargingData[gGunIndexInfo.GbIndex];
  731. pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
  732. pDcChargingInfo->ReservationId = -1;
  733. pDcChargingInfo->slotsIndex = slots;
  734. //pDcChargingInfo->SystemStatus = S_BOOTING;
  735. pDcChargingInfo->Type = _Type_GB;
  736. pDcChargingInfo->type_index = gGunIndexInfo.GbIndex;
  737. setAcGunTiggerStatus();
  738. //if( strcmp(whichtask,"CSU task") == EQUAL )
  739. {
  740. pDcChargingInfo->IsAvailable = YES;
  741. gGunIndexInfo.GbIndex++;
  742. gGunIndexInfo.DcGunIndex++;
  743. }
  744. } else {
  745. result = false;
  746. }
  747. break;
  748. //case 'D': // GBT DC x 2
  749. // break;
  750. //default:
  751. // result = false;
  752. // break;
  753. }
  754. return result;
  755. }
  756. bool MappingGunChargingInfo(char *whichTask)
  757. {
  758. bool result = true;
  759. uint8_t typeIndex = 0;
  760. uint8_t slots = 1;
  761. uint8_t gunIndex = 0;
  762. struct SysConfigData *pSysConfig = NULL;
  763. //struct ChargingInfoData *pDcChargingInfo = NULL;
  764. struct ChargingInfoData *pAcChargingInfo = NULL;
  765. if (ShmSysConfigAndInfo == NULL) {
  766. log_error("ShmSysConfigAndInfo failed");
  767. return false;
  768. }
  769. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  770. if (strlen((char *)pSysConfig->ModelName) < 9) {
  771. log_error("Module name length < 9 get %s", (char *)pSysConfig->ModelName);
  772. return false;
  773. }
  774. ShmDcCommonData->ChillerValve.MultiChillerGun = 0;
  775. //printf("1 CheckConnectorTypeStatus\n");
  776. for (typeIndex = 7; typeIndex <= 9; typeIndex++) {
  777. if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots, whichTask)) {
  778. log_error("%s add gun info failed", whichTask);
  779. return false;
  780. }
  781. //確認有幾把水冷槍
  782. if (strncmp((char *)&pSysConfig->ModelName[typeIndex], "V", 1) == 0 ||
  783. strncmp((char *)&pSysConfig->ModelName[typeIndex], "F", 1) == 0
  784. ) {
  785. ShmDcCommonData->ChillerValve.MultiChillerGun++; //水冷槍數
  786. }
  787. slots++;
  788. }
  789. if (ShmDcCommonData->ChillerValve.MultiChillerGun != 0) {
  790. ShmDcCommonData->ChillerValve.MultiChillerGun |= 0x80; //有水冷槍標記
  791. if (strncmp(whichTask, "CSU Task", 8) == EQUAL) {
  792. log_info("get chiller gun = %x, chiller gun count = %d",
  793. (ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7,
  794. ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F);
  795. }
  796. }
  797. // AC index 接在 DC 後面
  798. //if (AC_QUANTITY > 0) {
  799. if (gGunIndexInfo.AcIndex > 0) { //DS60-120 add
  800. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  801. pAcChargingInfo->Index += gGunIndexInfo.DcGunIndex;
  802. }
  803. pSysConfig->TotalConnectorCount = gGunIndexInfo.DcGunIndex;
  804. pSysConfig->AcConnectorCount = gGunIndexInfo.AcGunIndex;
  805. if (strcmp(whichTask, "CSU Task") == 0) {
  806. log_info("DC connector Quality = %d, AC connector Quality = %d",
  807. pSysConfig->TotalConnectorCount,
  808. pSysConfig->AcConnectorCount);
  809. }
  810. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  811. findDcChargingInfoData(gunIndex);
  812. }
  813. findAcChargingInfoData(gunIndex);
  814. //log_info("Type 0~3 = CHAdeMO, CCS, GB, AC");
  815. if (pSysConfig->TotalConnectorCount == 0 && pSysConfig->AcConnectorCount == 0) {
  816. log_error("DC %d or AC %d connector failed",
  817. pSysConfig->TotalConnectorCount,
  818. pSysConfig->AcConnectorCount);
  819. result = false;
  820. }
  821. return result;
  822. }
  823. int CreateAllCsuShareMemory(void)
  824. {
  825. int ret = FAIL;
  826. if ((ret = InitSysConfigAndInfoShmMem()) == FAIL) {
  827. return ret;
  828. }
  829. if ((ret = InitStatusCodeShmMem()) == FAIL) {
  830. return ret;
  831. }
  832. if ((ret = InitPSUDataShmMem()) == FAIL) {
  833. return ret;
  834. }
  835. if (CHAdeMO_QUANTITY > 0) {
  836. if ((ret = InitCHADeMoShmMem()) == FAIL) {
  837. return ret;
  838. }
  839. }
  840. if (GB_QUANTITY > 0) {
  841. if ((ret = InitGBShmMem()) == FAIL) {
  842. return ret;
  843. }
  844. }
  845. //creat ShmCcsData
  846. if (CCS_QUANTITY > 0) {
  847. if ((ret = InitCCSShmMem()) == FAIL) {
  848. return ret;
  849. }
  850. }
  851. if ((ret = InitPrimaryShmMem()) == FAIL) {
  852. return ret;
  853. }
  854. if ((ret = InitFanShmMem()) == FAIL) {
  855. return ret;
  856. }
  857. if ((ret = InitRelayShmMem()) == FAIL) {
  858. return ret;
  859. }
  860. if ((ret = InitLEDShmMem()) == FAIL) {
  861. return ret;
  862. }
  863. if ((ret = InitOCPPShmMem()) == FAIL) {
  864. return ret;
  865. }
  866. if ((ret = InitOCPP20ShmMem()) == FAIL) {
  867. return ret;
  868. }
  869. if ((ret = InitSelectGunShmMem()) == FAIL) {
  870. return ret;
  871. }
  872. if ((ret = InitSelectGunShmMem()) == FAIL) {
  873. return ret;
  874. }
  875. if ((ret = InitCommonShmMem()) == FAIL) {
  876. return ret;
  877. }
  878. //ClearAllShmMemParameter();
  879. //MappingChargingInfoData();
  880. //initialShareMemoryParameter();
  881. //initialGunIndexToUnUse();
  882. sleep(1);
  883. return PASS;
  884. }