#include #include #include #include #include #include #include #include #include "Module_RatedCurrent.h" //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ #define PASS (1) #define FAIL (-1) #define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) #define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args) #define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //------------------------------------------------------------------------------ static SymStruct modelTable[] = { { "AC", MODEL_AC }, { "AW", MODEL_AW }, { "AP", MODEL_AP }, { "AX", MODEL_AX }, { "DW", MODEL_DW }, { "DS", MODEL_DS }, { "DM", MODEL_DM }, { "DR", MODEL_DR }, //{ "DM", MODEL_DM }, { "DD", MODEL_DD }, { "DO", MODEL_DO }, { "DQ", MODEL_DQ }, { "DK", MODEL_DK }, { "DX", MODEL_DX }, { "DB", MODEL_DB }, { "DH", MODEL_DH }, { "DL", MODEL_DL } }; static SymStruct regulationTable[] = { {"E", REG_CE}, {"U", REG_UL}, {"G", REG_GB}, {"C", REG_CNS}, {"J", REG_JARI}, {"T", REG_TR25}, {"K", REG_KC}, {"B", REG_B}, {"Z", REG_Z}, {"M", REG_M}, {"P", REG_P}, {"I", REG_I}, {"F", REG_F}, {"L", REG_L}, {"W", REG_W} }; static SymStruct powerTable[] = { {"201", POWER_20W}, {"251", POWER_25W}, {"301", POWER_30W}, {"601", POWER_60W}, {"801", POWER_80W}, {"901", POWER_90W}, {"122", POWER_120W}, {"152", POWER_150W}, {"162", POWER_160W}, {"182", POWER_180W}, {"212", POWER_210W}, {"242", POWER_240W}, {"272", POWER_270W}, {"302", POWER_300W}, {"332", POWER_330W}, {"362", POWER_360W}, {"482", POWER_480W}, {"722", POWER_720W}, }; static SymStruct gunTypeTable[] = { {"0", GUN_TYPE_0}, {"1", GUN_TYPE_1}, {"2", GUN_TYPE_2}, {"3", GUN_TYPE_3}, {"4", GUN_TYPE_4}, {"5", GUN_TYPE_5}, {"6", GUN_TYPE_6}, {"7", GUN_TYPE_7}, {"8", GUN_TYPE_8}, {"J", GUN_TYPE_J}, {"U", GUN_TYPE_U}, {"V", GUN_TYPE_V}, {"E", GUN_TYPE_E}, {"F", GUN_TYPE_F}, {"G", GUN_TYPE_G}, {"T", GUN_TYPE_T}, {"D", GUN_TYPE_D}, {"K", GUN_TYPE_K}, {"M", GUN_TYPE_M}, {"N", GUN_TYPE_N}, {"P", GUN_TYPE_P}, {"R", GUN_TYPE_R}, {"C", GUN_TYPE_C}, {"W", GUN_TYPE_W}, {"B", GUN_TYPE_B}, {"H", GUN_TYPE_H}, {"A", GUN_TYPE_A}, {"L", GUN_TYPE_L}, {"Y", GUN_TYPE_Y}, {"Z", GUN_TYPE_Z}, {"S", GUN_TYPE_S}, {"I", GUN_TYPE_I}, {"Q", GUN_TYPE_Q} }; //------------------------------------------------------------------------------ static int StoreLogMsg(const char *fmt, ...) { char Buf[4096 + 256] = {0}; char buffer[4096] = {0}; int rc = 0; va_list args; struct timeb SeqEndTime; struct tm *tm; va_start(args, fmt); rc = vsnprintf(buffer, sizeof(buffer), fmt, args); va_end(args); ftime(&SeqEndTime); SeqEndTime.time = time(NULL); tm = localtime(&SeqEndTime.time); //if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) { // sprintf(Buf, "%02d:%02d:%02d:%03d - %s", // tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer); // printf("%s \n", Buf); //} else { sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer, tm->tm_year + 1900, tm->tm_mon + 1); system(Buf); //} return rc; } static int keyfromstring(char *key, SymStruct *table, int tableCount) { int i = 0; //int loop = sizeof(table) / sizeof(SymStruct); SymStruct *sym = NULL; for (i = 0; i < tableCount; i++) { sym = (SymStruct *)&table[i]; if (strcmp(sym->key, key) == 0) { //printf("val = %x\r\n", sym->val); return sym->val; } } return BADKEY; } //------------------------------------------------------------------------------ static uint16_t defaultRatedCurrent(uint8_t modelType, uint32_t gunType, int powerKey, int reguKey) { uint16_t ret = RC_0A; if (powerKey == BADKEY) { powerKey = POWER_30W; if (modelType == MODEL_DD || modelType == MODEL_DX) { powerKey = POWER_360W; } } if(powerKey < POWER_30W) { powerKey = POWER_30W; } switch (gunType) { case GUN_TYPE_J: if(powerKey == POWER_30W) ret = RC_60A; else if(powerKey >= POWER_60W) { if(reguKey == REG_JARI) { ret = RC_125A; } else { ret = RC_120A; } } break; case GUN_TYPE_S: ret = RC_200A; break; case GUN_TYPE_U: case GUN_TYPE_E: if(powerKey == POWER_30W) ret = RC_60A; else if(powerKey == POWER_60W) ret = RC_120A; else if(powerKey > POWER_60W) ret = RC_200A; break; case GUN_TYPE_G: case GUN_TYPE_B: if(powerKey == POWER_30W) ret = RC_60A; else if(powerKey == POWER_60W) ret = RC_120A; else if(powerKey > POWER_60W) ret = RC_250A; break; case GUN_TYPE_M: case GUN_TYPE_N: if(powerKey == POWER_30W) ret = RC_80A; else if(powerKey == POWER_60W) ret = RC_120A; else if(powerKey > POWER_60W) ret = RC_200A; break; case GUN_TYPE_K: case GUN_TYPE_W: ret = RC_200A; break; case GUN_TYPE_V: case GUN_TYPE_F: case GUN_TYPE_P: case GUN_TYPE_R: ret = RC_500A; break; case GUN_TYPE_T: case GUN_TYPE_D: ret = RC_300A; break; case GUN_TYPE_H: ret = RC_500A; break; case GUN_TYPE_A: ret = RC_400A; break; case GUN_TYPE_L: ret = RC_80A; break; case GUN_TYPE_Y: case GUN_TYPE_Z: ret = RC_150A; break; case GUN_TYPE_I: case GUN_TYPE_Q: ret = RC_300A; break; case GUN_TYPE_0: ret = RC_0A; break; case GUN_TYPE_1: case GUN_TYPE_2: case GUN_TYPE_3: case GUN_TYPE_4: case GUN_TYPE_5: case GUN_TYPE_6: case GUN_TYPE_7: case GUN_TYPE_8: ret = RC_0A; break; default: log_error("Gun type is not defined: 0x%x\r\n", gunType); ret = RC_0A; break; } return ret; } static uint16_t exchangeRatingCur(uint32_t key) { switch (key) { //60A J case DW_CE_30_J: case DM_CE_30_J: case DW_CE_30_E: case DM_CE_30_E: //60A U case DW_UL_30_U: case DM_UL_30_U: case DW_CNS_30_U: case DM_CNS_30_U: //60A J case DW_UL_30_J: case DM_UL_30_J: case DW_CNS_30_J: case DM_CNS_30_J: //60A G case DM_CNS_30_G: case DS_UL_30_G: return RC_60A; //rating current 60A //80A M case DW_CE_30_M: case DM_CE_30_M: //80A N case DW_UL_30_N: case DM_UL_30_N: case DW_CNS_30_N: case DM_CNS_30_N: return RC_80A; //rating current 80A //120A J case DS_CE_60_J: case DS_CE_90_J: case DS_CE_120_J: case DS_CE_150_J: case DS_CE_180_J: case DS_UL_60_J: case DS_UL_90_J: case DS_UL_120_J: case DS_UL_150_J: case DS_UL_180_J: case DS_CNS_60_J: case DS_CNS_90_J: case DS_CNS_120_J: case DS_CNS_150_J: case DS_CNS_180_J: //120A U case DS_UL_60_U: case DS_CNS_60_U: //120A E case DS_CE_60_E: return RC_120A; //rating current 120A //125A J For JARI / Japan Market case DS_JARI_60_J: case DS_JARI_90_J: case DS_JARI_120_J: case DS_JARI_150_J: case DS_JARI_180_J: return RC_125A; //rating current 125A //200A U case DD_CE_180_U: case DD_CE_360_U: case DS_UL_90_U: case DS_UL_120_U: case DS_UL_150_U: case DS_UL_180_U: case DD_UL_360_U: case DS_CNS_90_U: case DS_CNS_120_U: case DS_CNS_150_U: case DS_CNS_180_U: case DD_CNS_180_U: case DD_CNS_360_U: //200A E case DS_CE_90_E: case DS_CE_120_E: case DS_CE_150_E: case DS_CE_180_E: //200A K case DS_CE_90_K: case DS_CE_120_K: case DS_CE_150_K: case DS_CE_180_K: case DD_CE_180_K: case DD_CE_360_K: case DS_UL_90_K: case DS_UL_120_K: case DS_UL_150_K: case DS_UL_180_K: case DD_UL_180_K: case DD_UL_360_K: return RC_200A; //rating current 200A //250A G case DS_CNS_120_G: return RC_250A; //300A T case DS_CE_90_T: case DS_CE_120_T: case DS_CE_150_T: case DS_CE_180_T: case DD_CE_180_T: case DD_CE_360_T: case DS_UL_90_T: case DS_UL_120_T: case DS_UL_150_T: case DS_UL_180_T: case DD_UL_180_T: case DD_UL_360_T: case DS_CNS_90_T: case DS_CNS_120_T: case DS_CNS_150_T: case DS_CNS_180_T: case DD_CNS_180_T: case DD_CNS_360_T: //300A D case DS_CE_90_D: case DS_CE_120_D: case DS_CE_150_D: case DS_CE_180_D: case DD_CE_180_D: case DD_CE_360_D: case DS_UL_90_D: case DS_UL_120_D: case DS_UL_150_D: case DS_UL_180_D: case DD_UL_180_D: case DD_UL_360_D: case DS_CNS_90_D: case DS_CNS_120_D: case DS_CNS_150_D: case DS_CNS_180_D: case DD_CNS_180_D: case DD_CNS_360_D: return RC_500A; //500A V case DD_CE_180_V: case DD_UL_180_V: case DD_CNS_180_V: case DD_CE_360_V: case DD_UL_360_V: case DD_CNS_360_V: case DO_CE_180_V: case DO_UL_180_V: case DO_CNS_180_V: case DO_CE_360_V: case DO_UL_360_V: case DO_CNS_360_V: //500A F case DD_CE_360_F: case DO_CE_360_F: //P case DD_CE_360_P: case DD_UL_360_R: case DD_CNS_360_R: return RC_500A; //rating current 500A default: return RC_0A; //rating current 200A } } static void exchangeGunTypeAndVolValue(uint8_t key, GunTypeAndVolInfo *gunAndVol) { GunTypeAndVolInfo *pGunAndVol = (GunTypeAndVolInfo *)gunAndVol; switch (key) { case GUN_TYPE_0:// : none case GUN_TYPE_1:// : IEC 62196-2 Type 1/SAE J1772 Plug case GUN_TYPE_2:// : IEC 62196-2 Type 1/SAE J1772 Socket case GUN_TYPE_3:// : IEC 62196-2 Type 2 Plug case GUN_TYPE_4:// : IEC 62196-2 Type 2 Socket case GUN_TYPE_5:// : GB/T AC Plug case GUN_TYPE_6:// : GB/T AC Socket case GUN_TYPE_7:// :CCS2 AC Plug case GUN_TYPE_8:// :Type E socket pGunAndVol->GunType = Gun_Type_AC; pGunAndVol->GunVoltage = VOL_CHADEMO; break; case GUN_TYPE_J:// : CHAdeMO case GUN_TYPE_K: case GUN_TYPE_L: case GUN_TYPE_S: case GUN_TYPE_W:// : CHAdeMO 200A boost 350A pGunAndVol->GunType = Gun_Type_Chademo; pGunAndVol->GunVoltage = VOL_CHADEMO; break; case GUN_TYPE_U:// : Natural cooling CCS1 combo case GUN_TYPE_E:// : Natural cooling CCS2 combo case GUN_TYPE_V:// : Liquid cooling CCS1 combo case GUN_TYPE_F:// : Liquid cooling CCS2 combo case GUN_TYPE_T:// : Rema CCS1 300A case GUN_TYPE_D:// : Rema CCS2 300A case GUN_TYPE_M:// : CCS2 80A case GUN_TYPE_N:// : CCS1 80A case GUN_TYPE_P:// : Phoenix CCS2 500A 水冷 case GUN_TYPE_R:// : Phoenix CCS1 500A 水冷 case GUN_TYPE_Y:// : CCS1 150A case GUN_TYPE_Z:// : CCS2 150A case GUN_TYPE_I:// : CCS1 300A Boost mode case GUN_TYPE_Q:// : CCS2 300A Boost mode pGunAndVol->GunType = Gun_Type_CCS_2; pGunAndVol->GunVoltage = VOL_CCS; break; case GUN_TYPE_G:// : GBT DC case GUN_TYPE_B:// : GBT YG PT1000 case GUN_TYPE_H:// : WOER GBT 500A case GUN_TYPE_A:// : WOER GBT 400A pGunAndVol->GunType = Gun_Type_GB; pGunAndVol->GunVoltage = VOL_GBT; break; } } static int exchangePowerValue(uint8_t key, uint8_t modelKey) { switch (key) { case POWER_20W: return 200; case POWER_25W: return 250; case POWER_30W: return 300; case POWER_60W: return 600; case POWER_80W: return 800; case POWER_90W: return 900; case POWER_120W: return 1200; case POWER_150W: return 1500; case POWER_160W: return 1600; case POWER_180W: return 1800; case POWER_210W: return 2100; case POWER_240W: return 2400; case POWER_270W: return 2700; case POWER_300W: return 3000; case POWER_330W: return 3300; case POWER_360W: return 3600; case POWER_480W: return 4800; case POWER_720W: return 7200; default: if(modelKey != MODEL_DD && modelKey != MODEL_DX) { log_error("Power is not defined\r\n"); } return 0; break; } } /** * [RatedCurrentParsing : Parsing Rating Current] * @param pModuleName [description] * @param pDestStruct [save parameter structure array] * @param parsingCount [parameter structure array count, array 0, 1 for DC Gun, 2 for AC Gun] * @return [return -1 is module name format non match.] */ int RatedCurrentParsing(char *pModuleName, void *pDestStruct) { uint8_t gunTypeIndex = 0; uint8_t modelKey = 0; int reguKey = 0; int powerKey = 0; int gunTypeKey = 0; uint16_t ratingCurVal = 0; int i = 0; uint32_t ret = 0; char model[3] = {'\0'}; char regulation[2] = {'\0'}; char power[4] = {'\0'}; char gunType[2] = {'\0'}; ParsingRatedCur *pParsingInfo = NULL; RateCurInfo *pGunRateCurInfo = NULL; GunTypeAndVolInfo fGunAndVol = {0}; if (pModuleName == NULL || (strlen(pModuleName) <= 0) || pDestStruct == NULL) { log_error("Failed to parse source\r\n"); return FAIL; } pParsingInfo = (ParsingRatedCur *)pDestStruct; strncpy(model, &pModuleName[0], 2); model[2] = '\0'; strncpy(regulation, &pModuleName[3], 1); regulation[1] = '\0'; strncpy(power, &pModuleName[4], 3); power[3] = '\0'; //get modelKey and reguKey modelKey = keyfromstring(&model[0], &modelTable[0], sizeof(modelTable) / sizeof(SymStruct)); reguKey = keyfromstring(®ulation[0], ®ulationTable[0], sizeof(regulationTable) / sizeof(SymStruct)); //get max power value powerKey = keyfromstring(&power[0], &powerTable[0], sizeof(powerTable) / sizeof(SymStruct)); pParsingInfo->Power = exchangePowerValue(powerKey, modelKey); pParsingInfo->GetGunCount = 0; for (i = 0; i < sizeof(pParsingInfo->ParsingInfo) / sizeof(RateCurInfo); i++) { pGunRateCurInfo = (RateCurInfo *)&pParsingInfo->ParsingInfo[pParsingInfo->GetGunCount]; if(pModuleName[8]=='0') { if (i == 0) { gunTypeIndex = DC_ONE; } else if (i == 1) { gunTypeIndex = DC_SEC; } else if (i == 2) { gunTypeIndex = AC_ONE; } } else { if (i == 0) { gunTypeIndex = DC_ONE; } else if (i == 1) { gunTypeIndex = AC_ONE; } else if (i == 2) { gunTypeIndex = DC_SEC; } } strncpy(gunType, &pModuleName[gunTypeIndex], 1); gunType[1] = '\0'; if ((gunTypeKey = keyfromstring(&gunType[0], &gunTypeTable[0], sizeof(gunTypeTable) / sizeof(SymStruct))) == GUN_TYPE_0) { //log_error("Rated Current Parsing the type of gun is none\r\n"); continue; //return FAIL; } ret = 0; ret = ((modelKey << 24) | (reguKey << 16) | (powerKey << 8) | gunTypeKey); ratingCurVal = exchangeRatingCur(ret); if (ratingCurVal == RC_0A) { ratingCurVal = defaultRatedCurrent(modelKey, gunTypeKey, powerKey, reguKey); } memset((uint8_t *)&fGunAndVol, 0, sizeof(GunTypeAndVolInfo)); exchangeGunTypeAndVolValue(gunTypeKey, &fGunAndVol); pGunRateCurInfo->GunType = fGunAndVol.GunType; pGunRateCurInfo->Current = ratingCurVal; pGunRateCurInfo->Voltage = fGunAndVol.GunVoltage; pParsingInfo->GetGunCount++; //log_info("%d GunType = %d, Rating current = %d, Vol = %d, Power = %d\r\n", // i, // pGunRateCurInfo->GunType, // pGunRateCurInfo->Current, // pGunRateCurInfo->Voltage, // pGunRateCurInfo->Power); } // Rated power convert pParsingInfo->ratedPower = (((pModuleName[4]-0x30)*10)+((pModuleName[5]-0x30)*1))*pow(10, (pModuleName[6]-0x30)-1)*1000; return PASS; } //------------------------------------------------------------------------------ //Test function //------------------------------------------------------------------------------ void TestParsingRatingCurrent(void) { uint8_t i = 0; ParsingRatedCur fParsingRateCur = {0}; RatedCurrentParsing("DDYC362V0UE2AD", &fParsingRateCur); log_info("Get gun = %d\r\n", fParsingRateCur.GetGunCount); for (i = 0; i < fParsingRateCur.GetGunCount; i++) { log_info("%d GunType = %d, Rating current = %d, Vol = %d, Power = %d, Rated power: %d\r\n", i, fParsingRateCur.ParsingInfo[i].GunType, fParsingRateCur.ParsingInfo[i].Current, fParsingRateCur.ParsingInfo[i].Voltage, fParsingRateCur.Power, fParsingRateCur.ratedPower); } //log_info("%d GunType = %d, Rating current = %d, Vol = %d, Power = %d\r\n", // 0, // fGunRateCurInfo[0].GunType, // fGunRateCurInfo[0].Current, // fGunRateCurInfo[0].Voltage, // fGunRateCurInfo[0].Power); RatedCurrentParsing("DMYE301E00D2PH", &fParsingRateCur); log_info("Get gun = %d\r\n", fParsingRateCur.GetGunCount); for (i = 0; i < fParsingRateCur.GetGunCount; i++) { log_info("%d GunType = %d, Rating current = %d, Vol = %d, Power = %d\r\n", i, fParsingRateCur.ParsingInfo[i].GunType, fParsingRateCur.ParsingInfo[i].Current, fParsingRateCur.ParsingInfo[i].Voltage, fParsingRateCur.Power); } }