Module_RatedCurrent.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <stdarg.h>
  6. #include <time.h>
  7. #include <sys/timeb.h>
  8. #include "Module_RatedCurrent.h"
  9. //------------------------------------------------------------------------------
  10. //------------------------------------------------------------------------------
  11. #define PASS (1)
  12. #define FAIL (-1)
  13. #define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  14. #define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  15. #define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  16. //------------------------------------------------------------------------------
  17. static SymStruct modelTable[] = {
  18. { "AC", MODEL_AC },
  19. { "AW", MODEL_AW },
  20. { "AP", MODEL_AP },
  21. { "DW", MODEL_DW },
  22. { "DS", MODEL_DS },
  23. { "DM", MODEL_DM },
  24. { "DR", MODEL_DR },
  25. //{ "DM", MODEL_DM },
  26. { "DD", MODEL_DD },
  27. { "DO", MODEL_DO },
  28. };
  29. static SymStruct regulationTable[] = {
  30. {"E", REG_CE},
  31. {"U", REG_UL},
  32. {"G", REG_GB},
  33. {"C", REG_CNS},
  34. {"J", REG_JARI},
  35. {"T", REG_TR25},
  36. {"K", REG_KC},
  37. {"B", REG_B},
  38. {"Z", REG_Z},
  39. {"M", REG_M},
  40. {"P", REG_P},
  41. {"I", REG_I},
  42. {"F", REG_F},
  43. {"L", REG_L},
  44. };
  45. static SymStruct powerTable[] = {
  46. {"30", POWER_30W},
  47. {"60", POWER_60W},
  48. {"90", POWER_90W},
  49. {"12", POWER_120W},
  50. {"15", POWER_150W},
  51. {"18", POWER_180W},
  52. {"24", POWER_240W},
  53. {"36", POWER_360W},
  54. {"48", POWER_480W},
  55. {"72", POWER_720W},
  56. };
  57. static SymStruct gunTypeTable[] = {
  58. {"0", GUN_TYPE_0},
  59. {"1", GUN_TYPE_1},
  60. {"2", GUN_TYPE_2},
  61. {"3", GUN_TYPE_3},
  62. {"4", GUN_TYPE_4},
  63. {"5", GUN_TYPE_5},
  64. {"6", GUN_TYPE_6},
  65. {"7", GUN_TYPE_7},
  66. {"8", GUN_TYPE_8},
  67. {"J", GUN_TYPE_J},
  68. {"U", GUN_TYPE_U},
  69. {"V", GUN_TYPE_V},
  70. {"E", GUN_TYPE_E},
  71. {"F", GUN_TYPE_F},
  72. {"G", GUN_TYPE_G},
  73. };
  74. //------------------------------------------------------------------------------
  75. static int StoreLogMsg(const char *fmt, ...)
  76. {
  77. char Buf[4096 + 256] = {0};
  78. char buffer[4096] = {0};
  79. int rc = 0;
  80. va_list args;
  81. struct timeb SeqEndTime;
  82. struct tm *tm;
  83. va_start(args, fmt);
  84. rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  85. va_end(args);
  86. ftime(&SeqEndTime);
  87. SeqEndTime.time = time(NULL);
  88. tm = localtime(&SeqEndTime.time);
  89. //if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
  90. // sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
  91. // tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
  92. // printf("%s \n", Buf);
  93. //} else {
  94. sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  95. tm->tm_year + 1900,
  96. tm->tm_mon + 1,
  97. tm->tm_mday,
  98. tm->tm_hour,
  99. tm->tm_min,
  100. tm->tm_sec,
  101. SeqEndTime.millitm,
  102. buffer,
  103. tm->tm_year + 1900,
  104. tm->tm_mon + 1);
  105. system(Buf);
  106. //}
  107. return rc;
  108. }
  109. static int keyfromstring(char *key, SymStruct *table, int tableCount)
  110. {
  111. int i = 0;
  112. //int loop = sizeof(table) / sizeof(SymStruct);
  113. SymStruct *sym = NULL;
  114. for (i = 0; i < tableCount; i++) {
  115. sym = (SymStruct *)&table[i];
  116. if (strcmp(sym->key, key) == 0) {
  117. //printf("val = %x\r\n", sym->val);
  118. return sym->val;
  119. }
  120. }
  121. return BADKEY;
  122. }
  123. //------------------------------------------------------------------------------
  124. static uint16_t exchangeRatingCur(uint32_t key)
  125. {
  126. switch (key) {
  127. //60A J
  128. case DW_CE_30_J:
  129. case DM_CE_30_J:
  130. case DW_CE_30_E:
  131. case DM_CE_30_E:
  132. return RC_60A; //rating current 60A
  133. //65A U
  134. case DW_UL_30_U:
  135. case DM_UL_30_U:
  136. case DW_CNS_30_U:
  137. case DM_CNS_30_U:
  138. return RC_65A;
  139. //80A J
  140. case DW_UL_30_J:
  141. case DM_UL_30_J:
  142. case DW_CNS_30_J:
  143. case DM_CNS_30_J:
  144. //80A G
  145. case DM_CNS_30_G:
  146. case DS_UL_30_G:
  147. //80A M
  148. case DW_CE_30_M:
  149. case DM_CE_30_M:
  150. //80A N
  151. case DW_UL_30_N:
  152. case DM_UL_30_N:
  153. case DW_CNS_30_N:
  154. case DM_CNS_30_N:
  155. return RC_80A; //rating current 80A
  156. //125A J
  157. case DS_CE_60_J:
  158. case DS_CE_90_J:
  159. case DS_CE_120_J:
  160. case DS_CE_150_J:
  161. case DS_CE_180_J:
  162. case DS_UL_60_J:
  163. case DS_UL_90_J:
  164. case DS_UL_120_J:
  165. case DS_UL_150_J:
  166. case DS_UL_180_J:
  167. case DS_CNS_60_J:
  168. case DS_CNS_90_J:
  169. case DS_CNS_120_J:
  170. case DS_CNS_150_J:
  171. case DS_CNS_180_J:
  172. //125A U
  173. case DS_UL_60_U:
  174. case DS_CNS_60_U:
  175. //125A E
  176. case DS_CE_60_E:
  177. return RC_125A; //rating current 125A
  178. //200A U
  179. case DD_CE_180_U:
  180. case DD_CE_360_U:
  181. case DS_UL_90_U:
  182. case DS_UL_120_U:
  183. case DS_UL_150_U:
  184. case DS_UL_180_U:
  185. case DD_UL_360_U:
  186. case DS_CNS_90_U:
  187. case DS_CNS_120_U:
  188. case DS_CNS_150_U:
  189. case DS_CNS_180_U:
  190. case DD_CNS_180_U:
  191. case DD_CNS_360_U:
  192. //200A E
  193. case DS_CE_90_E:
  194. case DS_CE_120_E:
  195. case DS_CE_150_E:
  196. case DS_CE_180_E:
  197. //200A K
  198. case DS_CE_90_K:
  199. case DS_CE_120_K:
  200. case DS_CE_150_K:
  201. case DS_CE_180_K:
  202. case DD_CE_180_K:
  203. case DD_CE_360_K:
  204. case DS_UL_90_K:
  205. case DS_UL_120_K:
  206. case DS_UL_150_K:
  207. case DS_UL_180_K:
  208. case DD_UL_180_K:
  209. case DD_UL_360_K:
  210. return RC_200A; //rating current 200A
  211. //250A G
  212. case DS_CNS_120_G:
  213. return RC_250A;
  214. //300A T
  215. case DS_CE_90_T:
  216. case DS_CE_120_T:
  217. case DS_CE_150_T:
  218. case DS_CE_180_T:
  219. case DD_CE_180_T:
  220. case DD_CE_360_T:
  221. case DS_UL_90_T:
  222. case DS_UL_120_T:
  223. case DS_UL_150_T:
  224. case DS_UL_180_T:
  225. case DD_UL_180_T:
  226. case DD_UL_360_T:
  227. case DS_CNS_90_T:
  228. case DS_CNS_120_T:
  229. case DS_CNS_150_T:
  230. case DS_CNS_180_T:
  231. case DD_CNS_180_T:
  232. case DD_CNS_360_T:
  233. //300A D
  234. case DS_CE_90_D:
  235. case DS_CE_120_D:
  236. case DS_CE_150_D:
  237. case DS_CE_180_D:
  238. case DD_CE_180_D:
  239. case DD_CE_360_D:
  240. case DS_UL_90_D:
  241. case DS_UL_120_D:
  242. case DS_UL_150_D:
  243. case DS_UL_180_D:
  244. case DD_UL_180_D:
  245. case DD_UL_360_D:
  246. case DS_CNS_90_D:
  247. case DS_CNS_120_D:
  248. case DS_CNS_150_D:
  249. case DS_CNS_180_D:
  250. case DD_CNS_180_D:
  251. case DD_CNS_360_D:
  252. return RC_300A;
  253. //500A V
  254. case DD_CE_180_V:
  255. case DD_UL_180_V:
  256. case DD_CNS_180_V:
  257. case DD_CE_360_V:
  258. case DD_UL_360_V:
  259. case DD_CNS_360_V:
  260. case DO_CE_180_V:
  261. case DO_UL_180_V:
  262. case DO_CNS_180_V:
  263. case DO_CE_360_V:
  264. case DO_UL_360_V:
  265. case DO_CNS_360_V:
  266. //500A F
  267. case DD_CE_360_F:
  268. case DO_CE_360_F:
  269. //P
  270. case DD_CE_360_P:
  271. case DD_UL_360_R:
  272. case DD_CNS_360_R:
  273. return RC_500A; //rating current 500A
  274. default:
  275. return RC_0A; //rating current 200A
  276. }
  277. }
  278. static void exchangeGunTypeAndVolValue(uint8_t key, GunTypeAndVolInfo *gunAndVol)
  279. {
  280. GunTypeAndVolInfo *pGunAndVol = (GunTypeAndVolInfo *)gunAndVol;
  281. switch (key) {
  282. case GUN_TYPE_0:// : none
  283. case GUN_TYPE_1:// : IEC 62196-2 Type 1/SAE J1772 Plug
  284. case GUN_TYPE_2:// : IEC 62196-2 Type 1/SAE J1772 Socket
  285. case GUN_TYPE_3:// : IEC 62196-2 Type 2 Plug
  286. case GUN_TYPE_4:// : IEC 62196-2 Type 2 Socket
  287. case GUN_TYPE_5:// : GB/T AC Plug
  288. case GUN_TYPE_6:// : GB/T AC Socket
  289. case GUN_TYPE_7:// :CCS2 AC Plug
  290. pGunAndVol->GunType = Gun_Type_AC;
  291. pGunAndVol->GunVoltage = VOL_CHADEMO;
  292. break;
  293. case GUN_TYPE_8:// :Type E socket
  294. break;
  295. case GUN_TYPE_J:// : CHAdeMO
  296. pGunAndVol->GunType = Gun_Type_Chademo;
  297. pGunAndVol->GunVoltage = VOL_CHADEMO;
  298. break;
  299. case GUN_TYPE_U:// : Natural cooling CCS1 combo
  300. case GUN_TYPE_V:// : Liquid cooling CCS1 combo
  301. case GUN_TYPE_E:// : Natural cooling CCS2 combo
  302. case GUN_TYPE_F:// : Liquid cooling CCS2 combo
  303. pGunAndVol->GunType = Gun_Type_CCS_2;
  304. pGunAndVol->GunVoltage = VOL_CCS;
  305. break;
  306. case GUN_TYPE_G:// : GBT DC
  307. pGunAndVol->GunType = Gun_Type_GB;
  308. pGunAndVol->GunVoltage = VOL_GBT;
  309. break;
  310. }
  311. }
  312. static int exchangePowerValue(uint8_t key)
  313. {
  314. switch (key) {
  315. case POWER_30W:
  316. return 300;
  317. case POWER_60W:
  318. return 600;
  319. case POWER_90W:
  320. return 900;
  321. case POWER_120W:
  322. return 1200;
  323. case POWER_150W:
  324. return 1500;
  325. case POWER_180W:
  326. return 1800;
  327. case POWER_240W:
  328. return 2400;
  329. case POWER_360W:
  330. return 3600;
  331. case POWER_480W:
  332. return 4800;
  333. case POWER_720W:
  334. return 7200;
  335. default:
  336. return 600;
  337. break;
  338. }
  339. }
  340. /**
  341. * [RatedCurrentParsing : Parsing Rating Current]
  342. * @param pModuleName [description]
  343. * @param pDestStruct [save parameter structure array]
  344. * @param parsingCount [parameter structure array count, array 0, 1 for DC Gun, 2 for AC Gun]
  345. * @return [return -1 is module name format non match.]
  346. */
  347. int RatedCurrentParsing(char *pModuleName, void *pDestStruct)
  348. {
  349. uint8_t gunTypeIndex = 0;
  350. uint8_t modelKey = 0;
  351. uint8_t reguKey = 0;
  352. uint8_t powerKey = 0;
  353. uint8_t gunTypeKey = 0;
  354. uint16_t ratingCurVal = 0;
  355. int i = 0;
  356. uint32_t ret = 0;
  357. char model[2] = {'\0'};
  358. char regulation[1] = {'\0'};
  359. char power[2] = {'\0'};
  360. char gunType[1] = {'\0'};
  361. ParsingRatedCur *pParsingInfo = NULL;
  362. GunRateCurInfo *pGunRateCurInfo = NULL;
  363. GunTypeAndVolInfo fGunAndVol = {0};
  364. if (pModuleName == NULL || pDestStruct == NULL) {
  365. log_error("Failed to parse source data\r\n");
  366. return FAIL;
  367. }
  368. pParsingInfo = (ParsingRatedCur *)pDestStruct;
  369. strncpy(model, &pModuleName[0], 2);
  370. model[2] = '\0';
  371. strncpy(regulation, &pModuleName[3], 1);
  372. regulation[1] = '\0';
  373. strncpy(power, &pModuleName[4], 2);
  374. power[2] = '\0';
  375. //get max power value
  376. powerKey = keyfromstring(&power[0], &powerTable[0], sizeof(powerTable) / sizeof(SymStruct));
  377. pParsingInfo->Power = exchangePowerValue(powerKey);
  378. pParsingInfo->GetGunCount = 0;
  379. for (i = 0; i < sizeof(pParsingInfo->ParsingInfo) / sizeof(GunRateCurInfo); i++) {
  380. pGunRateCurInfo = (GunRateCurInfo *)&pParsingInfo->ParsingInfo[pParsingInfo->GetGunCount];
  381. if (i == 0) {
  382. gunTypeIndex = DC_ONE;
  383. } else if (i == 1) {
  384. gunTypeIndex = DC_SEC;
  385. } else if (i == 2) {
  386. gunTypeIndex = AC_ONE;
  387. }
  388. strncpy(gunType, &pModuleName[gunTypeIndex], 1);
  389. gunType[1] = '\0';
  390. modelKey = keyfromstring(&model[0], &modelTable[0], sizeof(modelTable) / sizeof(SymStruct));
  391. reguKey = keyfromstring(&regulation[0], &regulationTable[0], sizeof(regulationTable) / sizeof(SymStruct));
  392. if ((gunTypeKey = keyfromstring(&gunType[0], &gunTypeTable[0], sizeof(gunTypeTable) / sizeof(SymStruct))) == GUN_TYPE_0) {
  393. log_error("Rated Current Parsing the type of gun is none\r\n");
  394. continue;
  395. //return FAIL;
  396. }
  397. ret = 0;
  398. ret = ((modelKey << 24) | (reguKey << 16) | (powerKey << 8) | gunTypeKey);
  399. ratingCurVal = exchangeRatingCur(ret);
  400. if (ratingCurVal == RC_0A) {
  401. log_error("Rated Current Parsing model name format none match\r\n");
  402. return FAIL;
  403. }
  404. memset((uint8_t *)&fGunAndVol, 0, sizeof(GunTypeAndVolInfo));
  405. exchangeGunTypeAndVolValue(gunTypeKey, &fGunAndVol);
  406. pGunRateCurInfo->GunType = fGunAndVol.GunType;
  407. pGunRateCurInfo->Current = ratingCurVal;
  408. pGunRateCurInfo->Voltage = fGunAndVol.GunVoltage;
  409. pParsingInfo->GetGunCount++;
  410. //log_info("%d GunType = %d, Rating current = %d, Vol = %d, Power = %d\r\n",
  411. // i,
  412. // pGunRateCurInfo->GunType,
  413. // pGunRateCurInfo->Current,
  414. // pGunRateCurInfo->Voltage,
  415. // pGunRateCurInfo->Power);
  416. }
  417. return PASS;
  418. }
  419. //------------------------------------------------------------------------------
  420. //Test function
  421. //------------------------------------------------------------------------------
  422. void TestParsingRatingCurrent(void)
  423. {
  424. uint8_t i = 0;
  425. ParsingRatedCur fParsingRateCur = {0};
  426. RatedCurrentParsing("DDYC362V0UE2AD", &fParsingRateCur);
  427. log_info("Get gun = %d\r\n", fParsingRateCur.GetGunCount);
  428. for (i = 0; i < fParsingRateCur.GetGunCount; i++) {
  429. log_info("%d GunType = %d, Rating current = %d, Vol = %d, Power = %d\r\n",
  430. i,
  431. fParsingRateCur.ParsingInfo[i].GunType,
  432. fParsingRateCur.ParsingInfo[i].Current,
  433. fParsingRateCur.ParsingInfo[i].Voltage,
  434. fParsingRateCur.Power);
  435. }
  436. //log_info("%d GunType = %d, Rating current = %d, Vol = %d, Power = %d\r\n",
  437. // 0,
  438. // fGunRateCurInfo[0].GunType,
  439. // fGunRateCurInfo[0].Current,
  440. // fGunRateCurInfo[0].Voltage,
  441. // fGunRateCurInfo[0].Power);
  442. RatedCurrentParsing("DMYE301E00D2PH", &fParsingRateCur);
  443. log_info("Get gun = %d\r\n", fParsingRateCur.GetGunCount);
  444. for (i = 0; i < fParsingRateCur.GetGunCount; i++) {
  445. log_info("%d GunType = %d, Rating current = %d, Vol = %d, Power = %d\r\n",
  446. i,
  447. fParsingRateCur.ParsingInfo[i].GunType,
  448. fParsingRateCur.ParsingInfo[i].Current,
  449. fParsingRateCur.ParsingInfo[i].Voltage,
  450. fParsingRateCur.Power);
  451. }
  452. }