shmMem.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  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. } else {
  760. result = false;
  761. }
  762. break;
  763. case 'G': // GBT DC
  764. if (GB_QUANTITY > gGunIndexInfo.GbIndex) {
  765. pDcChargingInfo = (struct ChargingInfoData *)&pSysInfo->GbChargingData[gGunIndexInfo.GbIndex];
  766. pDcChargingInfo->Index = gGunIndexInfo.DcGunIndex;
  767. pDcChargingInfo->ReservationId = -1;
  768. pDcChargingInfo->slotsIndex = slots;
  769. pDcChargingInfo->SystemStatus = S_BOOTING;
  770. pDcChargingInfo->Type = _Type_GB;
  771. pDcChargingInfo->type_index = gGunIndexInfo.GbIndex;
  772. pDcChargingInfo->IsAvailable = YES;
  773. setAcGunTiggerStatus();
  774. gGunIndexInfo.GbIndex++;
  775. gGunIndexInfo.DcGunIndex++;
  776. } else {
  777. result = false;
  778. }
  779. break;
  780. //case 'D': // GBT DC x 2
  781. // break;
  782. //default:
  783. // result = false;
  784. // break;
  785. }
  786. return result;
  787. }
  788. bool MappingGunChargingInfo(char *whichTask)
  789. {
  790. bool result = true;
  791. uint8_t typeIndex = 0;
  792. uint8_t slots = 1;
  793. uint8_t gunIndex = 0;
  794. struct SysConfigData *pSysConfig = NULL;
  795. //struct ChargingInfoData *pDcChargingInfo = NULL;
  796. struct ChargingInfoData *pAcChargingInfo = NULL;
  797. if (ShmSysConfigAndInfo == NULL) {
  798. log_error("ShmSysConfigAndInfo failed\r\n");
  799. return false;
  800. }
  801. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  802. if (strlen((char *)pSysConfig->ModelName) < 9) {
  803. log_error("Module name length < 9 get %s\r\n", (char *)pSysConfig->ModelName);
  804. return false;
  805. }
  806. ShmDcCommonData->ChillerValve.MultiChillerGun = 0;
  807. //printf("1 CheckConnectorTypeStatus\r\n");
  808. for (typeIndex = 7; typeIndex <= 9; typeIndex++) {
  809. if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots)) {
  810. log_error("%s add gun info failed\r\n", whichTask);
  811. return false;
  812. }
  813. //確認有幾把水冷槍
  814. if (strncmp((char *)&pSysConfig->ModelName[typeIndex], "V", 1) == 0 ||
  815. strncmp((char *)&pSysConfig->ModelName[typeIndex], "F", 1) == 0
  816. ) {
  817. ShmDcCommonData->ChillerValve.MultiChillerGun++; //水冷槍數
  818. }
  819. slots++;
  820. }
  821. if (ShmDcCommonData->ChillerValve.MultiChillerGun != 0) {
  822. ShmDcCommonData->ChillerValve.MultiChillerGun |= 0x80; //有水冷槍標記
  823. if (strncmp(whichTask, "CSU Task", 8) == EQUAL) {
  824. log_info("get chiller gun = %x, chiller gun count = %d\r\n",
  825. (ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7,
  826. ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F);
  827. }
  828. }
  829. // AC index 接在 DC 後面
  830. //if (AC_QUANTITY > 0) {
  831. if (gGunIndexInfo.AcIndex > 0) { //DS60-120 add
  832. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  833. pAcChargingInfo->Index += gGunIndexInfo.DcGunIndex;
  834. }
  835. pSysConfig->TotalConnectorCount = gGunIndexInfo.DcGunIndex;
  836. pSysConfig->AcConnectorCount = gGunIndexInfo.AcGunIndex;
  837. if (strcmp(whichTask, "CSU Task") == 0) {
  838. log_info("DC connector Quality = %d, AC connector Quality = %d",
  839. pSysConfig->TotalConnectorCount,
  840. pSysConfig->AcConnectorCount);
  841. }
  842. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  843. findDcChargingInfoData(gunIndex);
  844. }
  845. findAcChargingInfoData(gunIndex);
  846. //log_info("Type 0~3 = CHAdeMO, CCS, GB, AC");
  847. if (pSysConfig->TotalConnectorCount == 0 && pSysConfig->AcConnectorCount == 0) {
  848. log_error("DC %d or AC %d connector failed\r\n",
  849. pSysConfig->TotalConnectorCount,
  850. pSysConfig->AcConnectorCount);
  851. result = false;
  852. }
  853. return result;
  854. }
  855. int CreateAllCsuShareMemory(void)
  856. {
  857. int ret = FAIL;
  858. if ((ret = InitSysConfigAndInfoShmMem()) == FAIL) {
  859. return ret;
  860. }
  861. if ((ret = InitStatusCodeShmMem()) == FAIL) {
  862. return ret;
  863. }
  864. if ((ret = InitPSUDataShmMem()) == FAIL) {
  865. return ret;
  866. }
  867. if (CHAdeMO_QUANTITY > 0) {
  868. if ((ret = InitCHADeMoShmMem()) == FAIL) {
  869. return ret;
  870. }
  871. }
  872. if (GB_QUANTITY > 0) {
  873. if ((ret = InitGBShmMem()) == FAIL) {
  874. return ret;
  875. }
  876. }
  877. //creat ShmCcsData
  878. if (CCS_QUANTITY > 0) {
  879. if ((ret = InitCCSShmMem()) == FAIL) {
  880. return ret;
  881. }
  882. }
  883. if ((ret = InitPrimaryShmMem()) == FAIL) {
  884. return ret;
  885. }
  886. if ((ret = InitFanShmMem()) == FAIL) {
  887. return ret;
  888. }
  889. if ((ret = InitRelayShmMem()) == FAIL) {
  890. return ret;
  891. }
  892. if ((ret = InitLEDShmMem()) == FAIL) {
  893. return ret;
  894. }
  895. if ((ret = InitOCPPShmMem()) == FAIL) {
  896. return ret;
  897. }
  898. if ((ret = InitSelectGunShmMem()) == FAIL) {
  899. return ret;
  900. }
  901. if ((ret = InitSelectGunShmMem()) == FAIL) {
  902. return ret;
  903. }
  904. if ((ret = InitCommonShmMem()) == FAIL) {
  905. return ret;
  906. }
  907. //ClearAllShmMemParameter();
  908. //MappingChargingInfoData();
  909. //initialShareMemoryParameter();
  910. //initialGunIndexToUnUse();
  911. sleep(1);
  912. return PASS;
  913. }