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