Module_RatingCurrent.c 12 KB

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