shmMem.c 29 KB

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