shmMem.c 30 KB

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