shmMem.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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->TestTemperature = NO;
  450. //ShmDcCommonData->LcmFwVersion = 0;
  451. }
  452. int InitSelectGunShmMem(void)
  453. {
  454. int MeterSMId = FAIL;
  455. #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  456. return;
  457. #endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
  458. if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
  459. return FAIL;
  460. } else if ((ShmSelectGunInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  461. return FAIL;
  462. }
  463. return PASS;
  464. }
  465. int InitCommonShmMem(void)
  466. {
  467. int MeterSMId = FAIL;
  468. if ((MeterSMId = shmget(ShmCommonKey, sizeof(DcCommonInfo), IPC_CREAT | 0777)) < 0) {
  469. return FAIL;
  470. } else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  471. return FAIL;
  472. }
  473. return PASS;
  474. }
  475. //int InitCSUMeterShmMem(void)
  476. //{
  477. // int MeterSMId = FAIL;
  478. //
  479. // if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0) {
  480. // return FAIL;
  481. // } else if ((ShmCsuMeterInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  482. // return FAIL;
  483. // }
  484. //
  485. // return PASS;
  486. //}
  487. int InitOCPPShmMem(void)
  488. {
  489. int MeterSMId = FAIL;
  490. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0) {
  491. log_info("Get OCPP share memory error\r\n");
  492. return FAIL;
  493. } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  494. log_info("Create OCPP share memory error\r\n");
  495. return FAIL;
  496. }
  497. return PASS;
  498. }
  499. int InitLEDShmMem(void)
  500. {
  501. int MeterSMId = FAIL;
  502. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0) {
  503. return FAIL;
  504. } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  505. return FAIL;
  506. }
  507. return PASS;
  508. }
  509. int InitRelayShmMem(void)
  510. {
  511. int MeterSMId = FAIL;
  512. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0) {
  513. return FAIL;
  514. } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  515. return FAIL;
  516. }
  517. return PASS;
  518. }
  519. int InitFanShmMem(void)
  520. {
  521. int MeterSMId = FAIL;
  522. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0) {
  523. return FAIL;
  524. } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  525. return FAIL;
  526. }
  527. return PASS;
  528. }
  529. int InitPrimaryShmMem(void)
  530. {
  531. int MeterSMId = FAIL;
  532. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0) {
  533. return FAIL;
  534. } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  535. return FAIL;
  536. }
  537. return PASS;
  538. }
  539. int InitCCSShmMem(void)
  540. {
  541. int MeterSMId = FAIL;
  542. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0) {
  543. return FAIL;
  544. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  545. return FAIL;
  546. }
  547. return PASS;
  548. }
  549. int InitGBShmMem(void)
  550. {
  551. int MeterSMId = FAIL;
  552. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0) {
  553. return FAIL;
  554. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  555. return FAIL;
  556. }
  557. return PASS;
  558. }
  559. int InitCHADeMoShmMem(void)
  560. {
  561. int MeterSMId = FAIL;
  562. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0) {
  563. return FAIL;
  564. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  565. return FAIL;
  566. }
  567. return PASS;
  568. }
  569. int InitPSUDataShmMem(void)
  570. {
  571. int MeterSMId = FAIL;
  572. //creat ShmPsuData
  573. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0) {
  574. return FAIL;
  575. } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  576. return FAIL;
  577. }
  578. return PASS;
  579. }
  580. int InitStatusCodeShmMem(void)
  581. {
  582. int MeterSMId = FAIL;
  583. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0) {
  584. return FAIL;
  585. } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  586. return FAIL;
  587. }
  588. return PASS;
  589. }
  590. int InitSysConfigAndInfoShmMem(void)
  591. {
  592. int MeterSMId = FAIL;
  593. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0) {
  594. printf("1 InitSysConfigAndInfoShmMem\r\n");
  595. return FAIL;
  596. } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  597. printf("2 InitSysConfigAndInfoShmMem\r\n");
  598. return FAIL;
  599. }
  600. return PASS;
  601. }
  602. void ClearAllShmMemParameter(void)
  603. {
  604. uint8_t i = 0;
  605. memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  606. memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
  607. memset(ShmPsuData, 0, sizeof(struct PsuData));
  608. if (CHAdeMO_QUANTITY > 0) {
  609. memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
  610. }
  611. if (GB_QUANTITY > 0) {
  612. memset(ShmGBTData, 0, sizeof(struct GBTData));
  613. }
  614. if (CCS_QUANTITY > 0) {
  615. memset(ShmCcsData, 0, sizeof(struct CcsData));
  616. }
  617. memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
  618. memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
  619. memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
  620. memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
  621. //memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
  622. //memset(ShmCsuMeterInfo, 0, sizeof(struct MeterInformation));
  623. memset(ShmDcCommonData, 0, sizeof(DcCommonInfo));
  624. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  625. memset(ShmSelectGunInfo, 0, sizeof(SelectGunInfo));
  626. for (i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
  627. ShmSelectGunInfo->PricesInfo[i].Balance = FAIL_BALANCE_PRICES;
  628. }
  629. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  630. }
  631. static void setAcGunTiggerStatus(void)
  632. {
  633. struct ChargingInfoData *pAcChargingInfo = NULL;
  634. if (gGunIndexInfo.AcGunIndex == 0) {
  635. return;
  636. }
  637. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(gGunIndexInfo.AcGunIndex);
  638. pAcChargingInfo->schedule.isTriggerStart = NO; //DS60-120 add
  639. pAcChargingInfo->schedule.isTriggerStop = NO; //DS60-120 add
  640. }
  641. static int findAcChargingInfoData(uint8_t gunIndex)
  642. {
  643. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  644. //acChargingData[gunIndex] = &pSysInfo->AcChargingData[0];
  645. SetAcChargingInfoData(gunIndex, &pSysInfo->AcChargingData[0]);
  646. return PASS;
  647. }
  648. static int findDcChargingInfoData(uint8_t gunIndex)
  649. {
  650. uint8_t i = 0;
  651. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  652. //printf("Chademo count = %d\r\n", gGunIndexInfo.ChademoIndex);
  653. for (i = 0; i < gGunIndexInfo.DcGunIndex; i++) {
  654. if (pSysInfo->ChademoChargingData[i].Index == gunIndex) {
  655. //printf("chademo index = %d, %d\r\n", pSysInfo->ChademoChargingData[i].Index, gunIndex);
  656. //dcChargingData[gunIndex] = &pSysInfo->ChademoChargingData[i];
  657. SetDcChargingInfoData(pSysInfo->ChademoChargingData[i].Index, &pSysInfo->ChademoChargingData[i]);
  658. return PASS;
  659. }
  660. }
  661. //printf("ccs count = %d\r\n", gGunIndexInfo.CcsIndex);
  662. for (i = 0; i < gGunIndexInfo.DcGunIndex; i++) {
  663. if (pSysInfo->CcsChargingData[i].Index == gunIndex) {
  664. //printf("ccs index = %d, %d\r\n", pSysInfo->CcsChargingData[i].Index, gunIndex);
  665. //dcChargingData[gunIndex] = (struct ChargingInfoData *)&pSysInfo->CcsChargingData[i];
  666. SetDcChargingInfoData(pSysInfo->CcsChargingData[i].Index, &pSysInfo->CcsChargingData[i]);
  667. return PASS;
  668. }
  669. }
  670. for (i = 0; i < gGunIndexInfo.DcGunIndex; i++) {
  671. if (pSysInfo->GbChargingData[i].Index == gunIndex) {
  672. //dcChargingData[gunIndex] = &pSysInfo->GbChargingData[i];
  673. SetDcChargingInfoData(pSysInfo->GbChargingData[i].Index, &pSysInfo->GbChargingData[i]);
  674. return PASS;
  675. }
  676. }
  677. return FAIL;
  678. }
  679. static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
  680. {
  681. bool result = true;
  682. struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  683. struct ChargingInfoData *pDcChargingInfo = NULL;
  684. struct ChargingInfoData *pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(gGunIndexInfo.AcGunIndex);
  685. struct CcsData *pCcsData = (struct CcsData *)GetShmCcsData();
  686. switch (typeValue) {
  687. // AC Gun Type -------------------------------------------------------------
  688. case '0': // none
  689. break;
  690. case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
  691. break;
  692. case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
  693. break;
  694. case '3': // IEC 62196-2 Type 2 Plug
  695. case '4': // IEC 62196-2 Type 2 Socket
  696. if (AC_QUANTITY > gGunIndexInfo.AcIndex) {
  697. pAcChargingInfo = (struct ChargingInfoData *)&pSysInfo->AcChargingData[gGunIndexInfo.AcIndex];
  698. // AC 固定 index
  699. pAcChargingInfo->Index = 0;
  700. pAcChargingInfo->ReservationId = -1;
  701. pAcChargingInfo->SystemStatus = S_IDLE;
  702. pAcChargingInfo->Type = _Type_AC;
  703. pAcChargingInfo->IsAvailable = YES;
  704. pAcChargingInfo->schedule.isTriggerStart = NO; //DS60-120 add
  705. pAcChargingInfo->schedule.isTriggerStop = NO; //DS60-120 add
  706. gGunIndexInfo.AcIndex++;
  707. gGunIndexInfo.AcGunIndex++;
  708. } else {
  709. result = false;
  710. }
  711. break;
  712. case '5': // GB/T AC Plug
  713. break;
  714. case '6': // GB/T AC Socket
  715. break;
  716. //DC Gun Type --------------------------------------------------------------
  717. case 'J': // CHAdeMO
  718. case 'K': // CHAdeMO 200A
  719. if (CHAdeMO_QUANTITY > gGunIndexInfo.ChademoIndex) {
  720. pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->ChademoChargingData[gGunIndexInfo.ChademoIndex];
  721. pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
  722. pDcChargingInfo->ReservationId = -1;
  723. pDcChargingInfo->slotsIndex = slots;
  724. pDcChargingInfo->SystemStatus = S_BOOTING;
  725. pDcChargingInfo->Type = _Type_Chademo;
  726. pDcChargingInfo->type_index = gGunIndexInfo.ChademoIndex;
  727. pDcChargingInfo->IsAvailable = YES;
  728. setAcGunTiggerStatus();
  729. gGunIndexInfo.ChademoIndex++;
  730. gGunIndexInfo.DcGunIndex++;
  731. } else {
  732. result = false;
  733. }
  734. break;
  735. case 'T': // Rema CCS1
  736. case 'D': // Rema CCS2
  737. case 'U': // CCS1 combo
  738. case 'E': // CCS2 combo
  739. case 'V': // Liquid CCS1 combo
  740. case 'F': // Liquid CCS2 combo
  741. case 'M': // 80A CCS2
  742. case 'N': // 80A CCS1
  743. case 'P': // Phoenix CCS2 500A 水冷
  744. case 'R': // Phoenix CCS1 500A 水冷
  745. if (CCS_QUANTITY > gGunIndexInfo.CcsIndex) {
  746. pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->CcsChargingData[gGunIndexInfo.CcsIndex];
  747. pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
  748. pDcChargingInfo->ReservationId = -1;
  749. pDcChargingInfo->slotsIndex = slots;
  750. pDcChargingInfo->SystemStatus = S_BOOTING;
  751. pDcChargingInfo->Type = _Type_CCS_2;
  752. pDcChargingInfo->type_index = gGunIndexInfo.CcsIndex;
  753. pDcChargingInfo->IsAvailable = YES;
  754. setAcGunTiggerStatus();
  755. // 現階段預設為走 DIN70121
  756. pCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
  757. gGunIndexInfo.CcsIndex++;
  758. gGunIndexInfo.DcGunIndex++;
  759. if(typeValue == 'P')
  760. {
  761. pDcChargingInfo->PantographFlag = YES;
  762. }
  763. } else {
  764. result = false;
  765. }
  766. break;
  767. case 'G': // GBT DC
  768. if (GB_QUANTITY > gGunIndexInfo.GbIndex) {
  769. pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->GbChargingData[gGunIndexInfo.GbIndex];
  770. pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
  771. pDcChargingInfo->ReservationId = -1;
  772. pDcChargingInfo->slotsIndex = slots;
  773. pDcChargingInfo->SystemStatus = S_BOOTING;
  774. pDcChargingInfo->Type = _Type_GB;
  775. pDcChargingInfo->type_index = gGunIndexInfo.GbIndex;
  776. pDcChargingInfo->IsAvailable = YES;
  777. setAcGunTiggerStatus();
  778. gGunIndexInfo.GbIndex++;
  779. gGunIndexInfo.DcGunIndex++;
  780. } else {
  781. result = false;
  782. }
  783. break;
  784. //case 'D': // GBT DC x 2
  785. // break;
  786. //default:
  787. // result = false;
  788. // break;
  789. }
  790. return result;
  791. }
  792. bool MappingGunChargingInfo(char *whichTask)
  793. {
  794. bool result = true;
  795. uint8_t typeIndex = 0;
  796. uint8_t slots = 1;
  797. uint8_t gunIndex = 0;
  798. struct SysConfigData *pSysConfig = NULL;
  799. //struct ChargingInfoData *pDcChargingInfo = NULL;
  800. struct ChargingInfoData *pAcChargingInfo = NULL;
  801. if (ShmSysConfigAndInfo == NULL) {
  802. log_error("ShmSysConfigAndInfo failed\r\n");
  803. return false;
  804. }
  805. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  806. if (strlen((char *)pSysConfig->ModelName) < 9) {
  807. log_error("Module name length < 9 get %s\r\n", (char *)pSysConfig->ModelName);
  808. return false;
  809. }
  810. ShmDcCommonData->ChillerValve.MultiChillerGun = 0;
  811. //printf("1 CheckConnectorTypeStatus\r\n");
  812. for (typeIndex = 7; typeIndex <= 9; typeIndex++) {
  813. if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots)) {
  814. log_error("%s add gun info failed\r\n", whichTask);
  815. return false;
  816. }
  817. //確認有幾把水冷槍
  818. if (strncmp((char *)&pSysConfig->ModelName[typeIndex], "V", 1) == 0 ||
  819. strncmp((char *)&pSysConfig->ModelName[typeIndex], "F", 1) == 0
  820. ) {
  821. ShmDcCommonData->ChillerValve.MultiChillerGun++; //水冷槍數
  822. }
  823. slots++;
  824. }
  825. if (ShmDcCommonData->ChillerValve.MultiChillerGun != 0) {
  826. ShmDcCommonData->ChillerValve.MultiChillerGun |= 0x80; //有水冷槍標記
  827. if (strncmp(whichTask, "CSU Task", 8) == EQUAL) {
  828. log_info("get chiller gun = %x, chiller gun count = %d\r\n",
  829. (ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7,
  830. ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F);
  831. }
  832. }
  833. // AC index 接在 DC 後面
  834. //if (AC_QUANTITY > 0) {
  835. if (gGunIndexInfo.AcIndex > 0) { //DS60-120 add
  836. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  837. pAcChargingInfo->Index += gGunIndexInfo.DcGunIndex;
  838. }
  839. pSysConfig->TotalConnectorCount = gGunIndexInfo.DcGunIndex;
  840. pSysConfig->AcConnectorCount = gGunIndexInfo.AcGunIndex;
  841. if (strcmp(whichTask, "CSU Task") == 0) {
  842. log_info("DC connector Quality = %d, AC connector Quality = %d",
  843. pSysConfig->TotalConnectorCount,
  844. pSysConfig->AcConnectorCount);
  845. }
  846. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  847. findDcChargingInfoData(gunIndex);
  848. }
  849. findAcChargingInfoData(gunIndex);
  850. //log_info("Type 0~3 = CHAdeMO, CCS, GB, AC");
  851. if (pSysConfig->TotalConnectorCount == 0 && pSysConfig->AcConnectorCount == 0) {
  852. log_error("DC %d or AC %d connector failed\r\n",
  853. pSysConfig->TotalConnectorCount,
  854. pSysConfig->AcConnectorCount);
  855. result = false;
  856. }
  857. return result;
  858. }
  859. int CreateAllCsuShareMemory(void)
  860. {
  861. int ret = FAIL;
  862. if ((ret = InitSysConfigAndInfoShmMem()) == FAIL) {
  863. return ret;
  864. }
  865. if ((ret = InitStatusCodeShmMem()) == FAIL) {
  866. return ret;
  867. }
  868. if ((ret = InitPSUDataShmMem()) == FAIL) {
  869. return ret;
  870. }
  871. if (CHAdeMO_QUANTITY > 0) {
  872. if ((ret = InitCHADeMoShmMem()) == FAIL) {
  873. return ret;
  874. }
  875. }
  876. if (GB_QUANTITY > 0) {
  877. if ((ret = InitGBShmMem()) == FAIL) {
  878. return ret;
  879. }
  880. }
  881. //creat ShmCcsData
  882. if (CCS_QUANTITY > 0) {
  883. if ((ret = InitCCSShmMem()) == FAIL) {
  884. return ret;
  885. }
  886. }
  887. if ((ret = InitPrimaryShmMem()) == FAIL) {
  888. return ret;
  889. }
  890. if ((ret = InitFanShmMem()) == FAIL) {
  891. return ret;
  892. }
  893. if ((ret = InitRelayShmMem()) == FAIL) {
  894. return ret;
  895. }
  896. if ((ret = InitLEDShmMem()) == FAIL) {
  897. return ret;
  898. }
  899. if ((ret = InitOCPPShmMem()) == FAIL) {
  900. return ret;
  901. }
  902. if ((ret = InitSelectGunShmMem()) == FAIL) {
  903. return ret;
  904. }
  905. if ((ret = InitSelectGunShmMem()) == FAIL) {
  906. return ret;
  907. }
  908. if ((ret = InitCommonShmMem()) == FAIL) {
  909. return ret;
  910. }
  911. //ClearAllShmMemParameter();
  912. //MappingChargingInfoData();
  913. //initialShareMemoryParameter();
  914. //initialGunIndexToUnUse();
  915. sleep(1);
  916. return PASS;
  917. }