shmMem.c 31 KB

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