Browse Source

2022-09-05 / Simon Xue

Simon Xue 2 years ago
parent
commit
6181eb0348

+ 2 - 123
EVSE/Projects/DD360Tcci/Apps/CSU/main.c

@@ -82,8 +82,8 @@ uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V2.19.00.0000.00"; // Phihong version
-char* DebugVersion = "V2.19.00";      // Software debug version
+char *fwVersion = "V2.20.00.0000.00"; // Phihong version
+char* DebugVersion = "V2.20.00";      // Software debug version
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -4044,128 +4044,7 @@ void showversion()
     len += sprintf(&str[len],"==================================== ");
     log_info("%s",str);
 }
-void SetNatural200AGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
-{
-    memset(&deratingByConnOtp->deratingTargetRate[0], 200, sizeof(deratingByConnOtp->deratingTargetRate));
-}
-void SetNatural300AGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
-{
-    deratingByConnOtp->deratingTargetCurrent[0] = 500;
-    deratingByConnOtp->deratingTargetCurrent[1] = 300;
-    deratingByConnOtp->deratingTargetCurrent[2] = 100;
-    deratingByConnOtp->deratingTargetCurrent[3] = 100;
-    deratingByConnOtp->deratingTargetCurrent[4] = 100;
-}
-void SetLiquidCoolGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
-{
-    deratingByConnOtp->deratingTargetCurrent[0] = 500;
-    deratingByConnOtp->deratingTargetCurrent[1] = 400;
-    deratingByConnOtp->deratingTargetCurrent[2] = 300;
-    deratingByConnOtp->deratingTargetCurrent[3] = 300;
-    deratingByConnOtp->deratingTargetCurrent[4] = 300;
-}
-void SetCHAdeMoTypeJOTPValue(uint8_t regulation,struct DERATING_BY_OTP* deratingByConnOtp)
-{
-    if (regulation == 'J') {
-        memset(&deratingByConnOtp->deratingTargetRate[0], 125, sizeof(deratingByConnOtp->deratingTargetRate));
-    } else {
-        memset(&deratingByConnOtp->deratingTargetRate[0], 120, sizeof(deratingByConnOtp->deratingTargetRate));
-    }
-}
-void SetCHAdeMoTypeKOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
-{
-    memset(&deratingByConnOtp->deratingTargetRate[0], 200, sizeof(deratingByConnOtp->deratingTargetRate));
-}
 
-void SetCHAdeMoTypeSJOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
-{
-    deratingByConnOtp->deratingTargetRate[0] = 1;
-    deratingByConnOtp->deratingTargetRate[1] = 0.8;
-}
-
-static void SetGunTypeOTPValue(void)
-{
-    //struct ChargingInfoData* chargingData_2 = NULL;
-    uint8_t Gun1Type = 0;
-    uint8_t Gun2Type = 0;
-    int i;
-    if (pSysConfig->TotalConnectorCount == 1) {
-        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(0);
-        Gun1Type = pSysConfig->ModelName[7];
-        Gun2Type = pSysConfig->ModelName[7];
-
-        switch (Gun1Type) {
-        //CHAdeMo
-        case 'J':
-            SetCHAdeMoTypeJOTPValue(pSysConfig->ModelName[3], &pDcChargingInfo->deratingByConnOtp);
-            break;
-        case 'K':
-            SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
-            break;
-        case 'S':
-            SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
-            break;
-        // 風冷200A以下
-        case 'U':
-        case 'E':
-        case 'M':
-        case 'N':
-            SetNatural200AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
-            break;
-        // 風冷300A
-        case 'T':
-        case 'D':
-            SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
-            break;
-        // 水冷
-        case 'V':
-        case 'F':
-        case 'P':
-        case 'R':
-            SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
-            break;
-        }
-
-    } else if (pSysConfig->TotalConnectorCount == 2) {
-        Gun1Type = pSysConfig->ModelName[7];
-        Gun2Type = pSysConfig->ModelName[9];
-        for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
-            pDcChargingInfo->deratingByConnOtp.isNeedDerating = GUNOTPDERATING;
-            switch (i == 0 ? Gun1Type : Gun2Type) {
-                //CHAdeMo
-            case 'J':
-                SetCHAdeMoTypeJOTPValue(pSysConfig->ModelName[3], &pDcChargingInfo->deratingByConnOtp);
-                break;
-            case 'K':
-                SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
-                break;
-            case 'S':
-                SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
-                break;
-                // 風冷200A以下
-            case 'U':
-            case 'E':
-            case 'M':
-            case 'N':
-                SetNatural200AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
-                break;
-                // 風冷300A
-            case 'T':
-            case 'D':
-                SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
-                break;
-                // 水冷
-            case 'V':
-            case 'F':
-            case 'P':
-            case 'R':
-                SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
-                break;
-            }
-        }
-    }
-}
 
 int main(void)
 {

+ 4 - 2
EVSE/Projects/DD360Tcci/Apps/Config.h

@@ -318,8 +318,8 @@ enum _LINE_STATUS {
     _LINE_PAY_OPERATE,
 };
 enum _DERATING_TEMP {
-    _DERATING_80 = 140,
-    _DERATING_85 = 145,
+    STAGE1_GUN_DERATING_TEMP = 140,
+    STAGE2_GUN_DERATING_TEMP = 145,
 };
 //------------------------------------------------------------------------------
 //struct StructMeter {
@@ -447,6 +447,7 @@ typedef struct StGunInfo {
     char ChargeDuration[32];
     uint8_t withChiller;      //是否有水冷機
     uint8_t WaitForPlugit;    // 等待插槍FLAG
+    uint8_t isParking;        // 是否有佔位費
 } GunInfo;
 
 typedef struct Psu_VersionInfo{
@@ -552,6 +553,7 @@ typedef struct StDcCommonInfo {
 
     RecordTransactionInfo TransactionInfo[2];
     RecordTransactionInfo RedeductBill;
+    RecordTransactionInfo ParkingInfo[2];
     PriceBillInfo PriceBill;
 
     int UnionSettlement;

+ 5 - 5
EVSE/Projects/DD360Tcci/Apps/DataBase/DataBase.c

@@ -498,11 +498,11 @@ int UpdateDeductInfoStatus(int gunIndex, RecordTransactionInfo *deductInfo)
     int result = PASS;
     char *errMsg = NULL;
     char sqlStr[1024] = {0};
-    char vemData[65] = {0};
-    memset(vemData, '\0', 65);
-    strncpy(vemData, (char*)&deductInfo->pCreditCard.VemData,64);
+    char ApprovalNo[10] = {0};
+    memset(ApprovalNo, '\0', 10);
+    strncpy(ApprovalNo, (char*)&deductInfo->pCreditCard.ApprovalNo,10);
 
-    sprintf(sqlStr, "update report_credit_deduct set isUpload = %d , isIntoCharge = %d, amount = %.1f, txId = %d, isDeductResult = %d, Energy = %.4f, lineSn = %d, RedeductTime = %d where vemData = '%s'; ",
+    sprintf(sqlStr, "update report_credit_deduct set isUpload = %d , isIntoCharge = %d, amount = %.1f, txId = %d, isDeductResult = %d, Energy = %.4f, lineSn = %d, RedeductTime = %d where approvalNo = '%s'; ",
                     (int)deductInfo->IsUpload,
                     (int)deductInfo->isIntoCharge,
                     deductInfo->Amount,
@@ -511,7 +511,7 @@ int UpdateDeductInfoStatus(int gunIndex, RecordTransactionInfo *deductInfo)
                     deductInfo->Energy,
                     deductInfo->LineStatus,
                     deductInfo->RedeductTime,
-                    vemData);
+                    ApprovalNo);
 
     //log_info("%s",sqlStr);
 

File diff suppressed because it is too large
+ 531 - 448
EVSE/Projects/DD360Tcci/Apps/Define/define.h


+ 2 - 2
EVSE/Projects/DD360Tcci/Apps/ModuleDoComm/DoComm.c

@@ -1639,7 +1639,7 @@ static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactio
 {
     int ret = PASS;
     if (ShmDcCommonData->DebugFlag &&
-        strcmp((char*)transactionInfo->pCreditCard.VemData ,"") == EQUAL) {
+        strcmp((char*)transactionInfo->pCreditCard.ApprovalNo ,"") == EQUAL) {
         return ret;
     }
 
@@ -2855,7 +2855,7 @@ static int networkCreatePorcess(void)
 
 void CreditCardProcess(int fd,int plugNum,int gunID, RecordTransactionInfo *pInfo)
 {
-    if (pInfo->IsUpload == TRUE || (strcmp((char*)pInfo->pCreditCard.VemData,"") == 0) ||
+    if (pInfo->IsUpload == TRUE || (strcmp((char*)pInfo->pCreditCard.ApprovalNo,"") == 0) ||
         pSysInfo->SystemPage == _PAGE_SENSING || ShmDcCommonData->is_RemoteStart[plugNum])
         return;
     if (ShmDcCommonData->TransactionInfo[plugNum].ConnectorID != 0) {

+ 192 - 66
EVSE/Projects/DD360Tcci/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -37,7 +37,7 @@ static struct GBTData *ShmGBTData = NULL;
 static struct CcsData *ShmCcsData = NULL;
 static DcCommonInfo *ShmDcCommonData = NULL;
 static SelectGunInfo *ShmSelectGunInfo = NULL;
-
+uint8_t deratingIndex[2];
 // 限制最大充電電壓,因應不同 type 槍線來限制
 // Chademo : 500V, 125A,
 // GB : 750, 120A
@@ -140,6 +140,131 @@ int InitCanBus(void)
     return s0;
 }
 
+void SetNatural200AGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    memset(&deratingByConnOtp->deratingTargetRate[0], 200, sizeof(deratingByConnOtp->deratingTargetRate));
+}
+void SetNatural300AGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->deratingTargetCurrent[0] = 500;
+    deratingByConnOtp->deratingTargetCurrent[1] = 300;
+    deratingByConnOtp->deratingTargetCurrent[2] = 100;
+    deratingByConnOtp->deratingTargetCurrent[3] = 100;
+    deratingByConnOtp->deratingTargetCurrent[4] = 100;
+}
+void SetLiquidCoolGunOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->deratingTargetCurrent[0] = 500;
+    deratingByConnOtp->deratingTargetCurrent[1] = 400;
+    deratingByConnOtp->deratingTargetCurrent[2] = 300;
+    deratingByConnOtp->deratingTargetCurrent[3] = 300;
+    deratingByConnOtp->deratingTargetCurrent[4] = 300;
+}
+void SetCHAdeMoTypeJOTPValue(uint8_t regulation, struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    if (regulation == 'J') {
+        memset(&deratingByConnOtp->deratingTargetRate[0], 125, sizeof(deratingByConnOtp->deratingTargetRate));
+    }
+    else {
+        memset(&deratingByConnOtp->deratingTargetRate[0], 120, sizeof(deratingByConnOtp->deratingTargetRate));
+    }
+}
+void SetCHAdeMoTypeKOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    memset(&deratingByConnOtp->deratingTargetRate[0], 200, sizeof(deratingByConnOtp->deratingTargetRate));
+}
+
+void SetCHAdeMoTypeSJOTPValue(struct DERATING_BY_OTP* deratingByConnOtp)
+{
+    deratingByConnOtp->deratingTargetRate[0] = 1;
+    deratingByConnOtp->deratingTargetRate[1] = 0.8;
+}
+
+static void SetGunTypeOTPValue(void)
+{
+    struct ChargingInfoData* pDcChargingInfo = NULL;
+    uint8_t Gun1Type = 0;
+    uint8_t Gun2Type = 0;
+    int i;
+    if (pSysConfig->TotalConnectorCount == 1) {
+        pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(0);
+        Gun1Type = pSysConfig->ModelName[7];
+        Gun2Type = pSysConfig->ModelName[7];
+
+        switch (Gun1Type) {
+            //CHAdeMo
+        case 'J':
+            SetCHAdeMoTypeJOTPValue(pSysConfig->ModelName[3], &pDcChargingInfo->deratingByConnOtp);
+            break;
+        case 'K':
+            SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+        case 'S':
+            SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+            // 風冷200A以下
+        case 'U':
+        case 'E':
+        case 'M':
+        case 'N':
+            SetNatural200AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+            // 風冷300A
+        case 'T':
+        case 'D':
+            SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+            // 水冷
+        case 'V':
+        case 'F':
+        case 'P':
+        case 'R':
+            SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+            break;
+        }
+
+    }
+    else if (pSysConfig->TotalConnectorCount == 2) {
+        Gun1Type = pSysConfig->ModelName[7];
+        Gun2Type = pSysConfig->ModelName[9];
+        for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
+            pDcChargingInfo->deratingByConnOtp.isNeedDerating = GUNOTPDERATING;
+            switch (i == 0 ? Gun1Type : Gun2Type) {
+                //CHAdeMo
+            case 'J':
+                SetCHAdeMoTypeJOTPValue(pSysConfig->ModelName[3], &pDcChargingInfo->deratingByConnOtp);
+                break;
+            case 'K':
+                SetCHAdeMoTypeKOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+            case 'S':
+                SetCHAdeMoTypeSJOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+                // 風冷200A以下
+            case 'U':
+            case 'E':
+            case 'M':
+            case 'N':
+                SetNatural200AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+                // 風冷300A
+            case 'T':
+            case 'D':
+                SetNatural300AGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+                // 水冷
+            case 'V':
+            case 'F':
+            case 'P':
+            case 'R':
+                SetLiquidCoolGunOTPValue(&pDcChargingInfo->deratingByConnOtp);
+                break;
+            }
+        }
+    }
+}
+
 float GetMaxChargingVol(uint8_t index)
 {
     return maxChargingVol[index];
@@ -337,70 +462,44 @@ static void GetMaxVolAndCurMethod(uint8_t index, float *vol, float *cur)
         *cur = pDcChargingInfo->ChargingProfileCurrent;
     }
 }
-void checkEachGunTypeOTP(int gunIndex, uint8_t Type, int derate_idx, struct DERATING_BY_OTP* deratingByConnOtp)
+
+void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, float* cur)
 {
-    struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
-    deratingByConnOtp->deratingIndex = derate_idx;
-    /*
-    log_info("RealMaxCurrent:[%.1f], AvailableChargingCurrent:[%.1f], BatteryTargetCurrent:[%.1f]",
-        pDcChargingInfo->RealMaxCurrent,
-        pDcChargingInfo->AvailableChargingCurrent,
-        pDcChargingInfo->EvBatterytargetCurrent);
-
-    log_info("RealMaxPower:[%.1f], AvailableChargingPower:[%.1f], BatteryTargetPower:[%.1f]",
-        pDcChargingInfo->RealMaxPower,
-        pDcChargingInfo->AvailableChargingPower,
-        pDcChargingInfo->EvBatterytargetVoltage * pDcChargingInfo->EvBatterytargetCurrent);
-    */
-    switch (Type) {
-    case 'S':
-        // Derate by power
-        if (pDcChargingInfo->RealMaxPower > pDcChargingInfo->AvailableChargingPower) {
-            pDcChargingInfo->RealMaxPower = pDcChargingInfo->AvailableChargingPower * deratingByConnOtp->deratingTargetRate[derate_idx];
-            log_info("Max Power derating to %.1f", pDcChargingInfo->RealMaxPower);
-        }
-        break;
-    default:
-        // Derate by current
-        if (pDcChargingInfo->RealMaxCurrent > deratingByConnOtp->deratingTargetCurrent[derate_idx]) {
-            pDcChargingInfo->RealMaxCurrent = deratingByConnOtp->deratingTargetCurrent[derate_idx];
-            log_info("Max Current derating to %.1f", pDcChargingInfo->RealMaxCurrent);
-        }
+    if (((chargingData->ConnectorTemp >= STAGE1_GUN_DERATING_TEMP &&
+        chargingData->ConnectorTemp < STAGE2_GUN_DERATING_TEMP) ||
+        (chargingData->ChillerTemp >= STAGE1_GUN_DERATING_TEMP &&
+            chargingData->ChillerTemp < STAGE2_GUN_DERATING_TEMP)) &&
+        chargingData->deratingByConnOtp.deratingIndex < 1)
+    {
+        chargingData->deratingByConnOtp.deratingIndex = 1;
+    }
+    else if ((chargingData->ConnectorTemp >= STAGE2_GUN_DERATING_TEMP ||
+        chargingData->ChillerTemp >= STAGE2_GUN_DERATING_TEMP) &&
+        chargingData->ConnectorTemp != UNDEFINED_TEMP &&
+        chargingData->ChillerTemp != UNDEFINED_TEMP &&
+        chargingData->deratingByConnOtp.deratingIndex < 2)
+    {
+        chargingData->deratingByConnOtp.deratingIndex = 2;
     }
-}
-static void CheckGunTypeOTP(void)
-{
-    uint8_t GunType = 0;
-    int derate_idx;
-    int i;
 
-    for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-        if (pSysConfig->TotalConnectorCount == 1) {
-            GunType = pSysConfig->ModelName[7];
-        } else if (pSysConfig->TotalConnectorCount == 2) {
-            GunType = (i == 0 ? pSysConfig->ModelName[7] : pSysConfig->ModelName[9]);
-        }
-        struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
-        if (pDcChargingInfo->deratingByConnOtp.isNeedDerating) {
-            if (pDcChargingInfo->ConnectorTemp >= _DERATING_85) {
-                derate_idx = 2;
-            } else if (pDcChargingInfo->ConnectorTemp >= _DERATING_80) {
-                derate_idx = 1;
-            } else {
-                derate_idx = 0;
-            }
-            if (derate_idx != 0) {
-                checkEachGunTypeOTP(i, GunType, derate_idx, &pDcChargingInfo->deratingByConnOtp);
-            }
-        }
+    if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
     }
-}
+    else if (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        if (*cur > chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex])
+            *cur = chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex];
+    }
+}   
+
 static void SetPresentChargingOutputCap(void)
 {
     float pow1 = 0, cur1 = 0;
     float pow2 = 0, cur2 = 0;
     struct ChargingInfoData *chargingData_1 = NULL;
     struct ChargingInfoData *chargingData_2 = NULL;
+    struct PrimaryMcuData* ShmPrimaryMcuData = (struct PrimaryMcuData*)GetShmPrimaryMcuData();
 
     if (pSysConfig->TotalConnectorCount == 1) {
         chargingData_1 = (struct ChargingInfoData *)GetDcChargingInfoData(0);
@@ -438,6 +537,14 @@ static void SetPresentChargingOutputCap(void)
         }
     }
 
+    if (chargingData_1->deratingByConnOtp.isNeedDerating) {
+        GetOtpPwrOrCurMethod(chargingData_1, &pow1, &cur1);
+        if (deratingIndex[0] != chargingData_1->deratingByConnOtp.deratingIndex) {
+            log_info("Gun0 Derating Index Set %d", chargingData_1->deratingByConnOtp.deratingIndex);
+            deratingIndex[0] = chargingData_1->deratingByConnOtp.deratingIndex;
+        }
+    }
+
     pow2 = chargingData_2->AvailableChargingPower;
     cur2 = chargingData_2->AvailableChargingCurrent;
     /*
@@ -462,6 +569,24 @@ static void SetPresentChargingOutputCap(void)
         }
     }
 
+    if (chargingData_2->deratingByConnOtp.isNeedDerating) {
+        GetOtpPwrOrCurMethod(chargingData_2, &pow2, &cur2);
+        if (deratingIndex[1] != chargingData_2->deratingByConnOtp.deratingIndex) {
+            log_info("Gun1 Derating Index Set %d", chargingData_2->deratingByConnOtp.deratingIndex);
+            deratingIndex[1] = chargingData_2->deratingByConnOtp.deratingIndex;
+        }
+    }
+
+    if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
+        if (cur1 > 1500) {
+            log_info("Gun0 chiller alarm set current less than 150A");
+            cur1 = 1500;
+        }
+        if (cur2 > 1500) {
+            log_info("Gun1 chiller alarm set current less than 150A");
+            cur2 = 1500;
+        }
+    }
     //DS60-120 add
     if ((LogInfo[0][EV_LOG_OUTPUT_CAP_POW] <= pow1 - 5 ||
             LogInfo[0][EV_LOG_OUTPUT_CAP_POW] >= pow1 + 5) ||
@@ -473,30 +598,29 @@ static void SetPresentChargingOutputCap(void)
              LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] >= cur2 + 5)
        ) {
         //log_info("----------------------------------------------------- ");
-        log_info("To EV PW_1 = %.1f, Cur_1 = %.1f, Vol_1 = %.1f, PW_2 = %.1f, Cur_2 = %.1f, Vol_2 = %.1f",
-                 pow1 / 10, cur1 / 10, chargingData_1->FireChargingVoltage, pow2 / 10, cur2 / 10, chargingData_2->FireChargingVoltage);
+        log_info("To EV (Real) Power_1 = %.1f, Cur_1 = %.1f, Power_2 = %.1f, Cur_2 = %.1f",
+                 pow1 / 10, cur1 / 10, pow2 / 10, cur2 / 10);
         //log_info("----------------------------------------------------- ");
 
         LogInfo[0][EV_LOG_OUTPUT_CAP_POW] = pow1;
         LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] = cur1;
         LogInfo[1][EV_LOG_OUTPUT_CAP_POW] = pow2;
         LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] = cur2;
-    }
+        chargingData_1->RealMaxCurrent = cur1;
+        chargingData_1->RealMaxPower = pow1;
 
-    chargingData_1->RealMaxCurrent = cur1;
-    chargingData_1->RealMaxPower = pow1;
+        if (pSysConfig->TotalConnectorCount == 2) {
+            chargingData_2->RealMaxCurrent = cur2;
+            chargingData_2->RealMaxPower = pow2;
+        }
+    }
 
     if (pSysConfig->TotalConnectorCount == 2) {
         chargingData_2->RealMaxCurrent = cur2;
         chargingData_2->RealMaxPower = pow2;
     }
 
-    //CheckGunTypeOTP();
-
-    SetPresentOutputCapacity(chargingData_1->RealMaxPower,
-        chargingData_1->RealMaxCurrent,
-        chargingData_2->RealMaxPower,
-        chargingData_2->RealMaxCurrent);
+    SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
 }
 /*
 static uint8_t waitPsuVolwithRealyVol(uint8_t gunIndex)
@@ -794,6 +918,8 @@ int main(int argc, char *argv[])
     
     CANReceiver(CanFd);
 
+    SetGunTypeOTPValue();
+
     rtc = GetRtcInfoForEpoch();
 
     while (isContinue) {

+ 32 - 48
EVSE/Projects/DD360Tcci/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -44,7 +44,7 @@ static struct SysInfoData *pSysInfo = NULL;
 static struct AlarmCodeData *pAlarmCode = NULL;
 static struct FaultCodeData *pFaultCode = NULL;
 static struct PrimaryMcuData *ShmPrimaryMcuData;
-static DcCommonInfo* ShmDcCommonData = NULL;
+static DcCommonInfo *ShmDcCommonData = NULL;
 
 const char *priPortName = "/dev/ttyS1";
 uint8_t gun_count; //DS60-120 add
@@ -84,6 +84,7 @@ void GetInputGpioStatus(int fd)
     }
 
     ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
+    ShmPrimaryMcuData->InputDet.bits.Ac_Drop = ~gpio_in.AC_Drop; // Chiller Alarm ping
 
     if (gpio_in.Emergency_Btn && (EmgBtn_flag != gpio_in.Emergency_Btn))
     {
@@ -139,7 +140,7 @@ void GetInputGpioStatus(int fd)
             Door_count = 0;
             Door_flag = gpio_in.Door_Open;
         }
-    } else {
+    } else { 
         Door_flag = gpio_in.Door_Open;
         Door_count = 0;
     }
@@ -208,77 +209,60 @@ static void checkChillerStatus(Gpio_out *gpio)
         pGpio->AC_Connector = 0x00;
         return;
     }
-
-    for (gunIndex = 0; gunIndex < chillerCount; gunIndex++) {
+    // 設定chiller 開關
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
         if (!ShmDcCommonData->pGunInfo[gunIndex].withChiller)
             continue;
         pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
-        if((pDcChargingInfo->SystemStatus > S_AUTHORIZING && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
-            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
-        {
+        if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
+            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
             pChillerInfo->ChillerSwitch = YES;
             pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-        }
-        else
-        {
-            if(pChillerInfo->ChillerSwitch == YES)
-            {
+        } else {
+            if(pChillerInfo->ChillerSwitch == YES) {
                 //10分鐘後停止
-                if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600)
-                {
+                if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
                     pChillerInfo->ChillerSwitch = NO;
-                    ShmFanModuleData->SetFan1Speed = 0;
                 }
-            }
-            else
-            {
+            } else {
                 pChillerInfo->ChillerSwitch = NO;
                 ShmFanModuleData->SetFan1Speed = 0;
             }
         }
-/*
-        if ((pDcChargingInfo->PresentChargingCurrent) >= 150) { //當前電壓於150A,打開水冷機
-            pChillerInfo->ChillerSwitch = YES;
-            pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-        } else {
-            if (pChillerInfo->ChillerSwitch == YES) {
-                if ((pDcChargingInfo->PresentChargingCurrent) >= 100) { //判斷如果還是大於100A不變動
-                    pChillerInfo->ChillerSwitch = YES;
-                    pChillerInfo->ChillerOnTime = time((time_t *)NULL);
-                } else {
-                    if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) { //5分鐘後停止
-                        pChillerInfo->ChillerSwitch = NO;
-                    } else {
-                        pChillerInfo->ChillerSwitch = YES;
-                    }
-                }
-            } else {
-                pChillerInfo->ChillerSwitch = NO;
-            }
+        // 檢查Chiller溫度點,若小於零下時開啟heater,大於10度時關閉heater
+        if (pDcChargingInfo->ChillerTemp < 60) {
+            pGpio->AC_Breaker = YES;
+        } else if(pDcChargingInfo->ChillerTemp > 70) {
+            pGpio->AC_Breaker = NO;
         }
-*/
+        //log_info("Set Heater %s", pGpio->AC_Breaker ? "ON" : "OFF");
     }
 
     uint8_t _chillerNeedOn = NO;
-    for (gunIndex = 0; gunIndex < chillerCount; gunIndex++)
+    for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
     {
-        pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
-        if(pChillerInfo->ChillerSwitch == YES)
-        {
+        pChillerInfo = (ChillerInfo*)&fChillerInfo[gunIndex];
+        if (pChillerInfo->ChillerSwitch == YES) {
             _chillerNeedOn = YES;
             ShmFanModuleData->SetFan1Speed = 7000;
-
         }
     }
+    /*
+    if (ShmDcCommonData->debugflag == YES)
+        _chillerNeedOn = ShmDcCommonData->chillerCtrl;
+    */
+    if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
+        _chillerNeedOn = NO;
+    }
 
-    if(_chiller.ChillerSwitch != _chillerNeedOn)
-    {
+    if(_chiller.ChillerSwitch != _chillerNeedOn) {
         log_info("Chiller Need Turn %s", _chillerNeedOn == YES ? "ON" : "OFF");
     }
     _chiller.ChillerSwitch = _chillerNeedOn;
     pGpio->AC_Connector = _chiller.ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
+
 }
 
 void SetOutputGpio(int fd, uint8_t outputValue)
@@ -312,7 +296,7 @@ void SetOutputGpio(int fd, uint8_t outputValue)
 
     checkChillerStatus(&gpio);
 
-    gpio.AC_Breaker = 0x00;
+    //gpio.AC_Breaker = 0x00;
 
     Config_Gpio_Output(fd, OP_ADDR_IO_EXTEND, &gpio);
 }
@@ -411,6 +395,7 @@ unsigned long GetClockTimeoutValue(struct timespec _start_time)
 
     return ret;
 }
+
 static bool IsPrimaryProcessNeedPause(void)
 {
     bool _pause = false;
@@ -459,7 +444,7 @@ int main(void)
     pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
     pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
     ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
-    ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
+    ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
 
     Uart1Fd = InitComPort();
     //log_info("407 Port id = %d ", Uart1Fd);
@@ -490,7 +475,6 @@ int main(void)
             sleep(1);
             continue;
         }
-
         if (ShmPrimaryMcuData->SelfTest_Comp != PASS) {
             //log_info("(407) Get Fw and Hw Ver. ");
             GetFwAndHwVersion(Uart1Fd);

+ 131 - 18
EVSE/Projects/DD360Tcci/Apps/ReadCmdline.c

@@ -44,7 +44,7 @@
 #include "Config.h"
 #include "./CSU/main.h"
 #include "./DataBase/DataBase.h"
-
+#include "./ModuleEvComm/Module_EvComm.h"
 //------------------------------------------------------------------------------
 #define CMD_KEY_WAIT                                (1)
 #define CMD_KEY_DONT_WAIT                           (0)
@@ -544,18 +544,7 @@ void GetGunSelectedNum(char *v1)
         }
     }
 }
-void writeChillerStatus(char* v1)
-{
-    if (ShmDcCommonData->DebugFlag == YES) {
-        ShmDcCommonData->chillerCtrl = atoi(newString[1]);
-        if (ShmDcCommonData->chillerCtrl)
-            printf("Chiller set on\n");
-        else
-            printf("Chiller set off\n");
-    }
-    else
-        printf("Please open Debug mode\n");
-}
+
 void writeBackLight(char* v1)
 {
     uint8_t light = atoi(v1);
@@ -764,6 +753,102 @@ static void setConfirmSelGun(uint8_t selGun)
     }
 }
 
+
+static float ReadAdcVolt(uint8_t AdcChannel)
+{
+    //AIN0=CCS GUN Temp 1
+    //AIN1=CCS GUN Temp 2
+    //AIN2=CCS_Proximity/2
+    //AIN3=pilot voltage
+    int fd = -1;
+    uint8_t str[64] = { 0 };
+    uint8_t AdcValue[8] = { '\0' };
+
+    if (AdcChannel > 7) {
+        return -1;
+    }
+
+    sprintf((char*)str, "/sys/bus/iio/devices/iio\:device0/in_voltage%d_raw", AdcChannel);
+    fd = open((char*)str, O_RDONLY);
+    read(fd, AdcValue, 4);
+
+    close(fd);
+
+    return (1.8 * atoi((char*)&AdcValue[0])) / 4095;
+    //return (1.8 * atoi((char *)&AdcValue)) / 4095;
+}
+
+static void getChillerTemperature(struct ChargingInfoData* chargingData)
+{
+    uint8_t i = 0;
+    float adcVoltage = 0.0;
+    ChillerTemp pChillerTemp;
+    uint8_t maxTemp;
+    for (i = 0; i < 4; i++) {
+        adcVoltage = 0.0;
+        adcVoltage = ReadAdcVolt(i);
+        if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) { //0 ~ -40
+            pChillerTemp.Temp[i] = ((adcVoltage - 0.908) * 500) + 60;
+            //log_info("1 adcVoltage = %f", (adcVoltage - 0.9) * 500);
+        } else if ((adcVoltage <= 1.07) && (adcVoltage > 0.9)) {
+            pChillerTemp.Temp[i] = ((adcVoltage - 0.91) * 705.88) + 60;
+            //log_info("2 adcVoltage = %f", (adcVoltage - 0.9) * 500);
+        } else {
+            pChillerTemp.Temp[i] = UNDEFINED_TEMP;
+        }
+    }
+    maxTemp = pChillerTemp.Temp[0];
+    memcpy((char*)ShmDcCommonData->SystemTemp, (char*)pChillerTemp.Temp, sizeof(ChillerTemp));
+    for (i = 1; i < 4; i++) {
+        if (pChillerTemp.Temp[i] > pChillerTemp.Temp[i - 1] && pChillerTemp.Temp[i] != UNDEFINED_TEMP) {
+            maxTemp = pChillerTemp.Temp[i];
+        }
+    }
+    chargingData->ChillerTemp = maxTemp;
+}
+
+void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, float* cur)
+{
+    for(int i = 0 ; i < 4 ; i++) {
+        if (ShmDcCommonData->SystemTemp[i] >= STAGE1_GUN_DERATING_TEMP &&
+            ShmDcCommonData->SystemTemp[i] < STAGE2_GUN_DERATING_TEMP && 
+            chargingData->deratingByConnOtp.deratingIndex < 1) {
+            chargingData->deratingByConnOtp.deratingIndex = 1;
+        } else if (ShmDcCommonData->SystemTemp[i] >= STAGE2_GUN_DERATING_TEMP &&
+            ShmDcCommonData->SystemTemp[i] != UNDEFINED_TEMP &&
+            chargingData->deratingByConnOtp.deratingIndex < 2) {
+            chargingData->deratingByConnOtp.deratingIndex = 2;
+        }
+    }
+    /*
+    if (((chargingData->ConnectorTemp >= STAGE1_GUN_DERATING_TEMP &&
+        chargingData->ConnectorTemp < STAGE2_GUN_DERATING_TEMP) ||
+        (chargingData->ChillerTemp >= STAGE1_GUN_DERATING_TEMP &&
+            chargingData->ChillerTemp < STAGE2_GUN_DERATING_TEMP)) &&
+        chargingData->deratingByConnOtp.deratingIndex < 1)
+    {
+        chargingData->deratingByConnOtp.deratingIndex = 1;
+    } else if ((chargingData->ConnectorTemp >= STAGE2_GUN_DERATING_TEMP ||
+        chargingData->ChillerTemp >= STAGE2_GUN_DERATING_TEMP) &&
+        chargingData->ConnectorTemp != UNDEFINED_TEMP &&
+        chargingData->ChillerTemp != UNDEFINED_TEMP &&
+        chargingData->deratingByConnOtp.deratingIndex < 2)
+    {
+        chargingData->deratingByConnOtp.deratingIndex = 2;
+    }
+    */
+    if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
+    } else if (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex] != 0)
+    {
+        if (*cur > (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex]/10)) {
+            *cur = chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex]/10;
+
+        }
+    }
+}
+
 void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 {
     int _GunIndex;
@@ -773,7 +858,11 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     int isContinue = 1;
     float _Voltage;
     float _Current;
+    float deratingPower;
+    float deratingCurrent;
+    int derating_index = 0;
     uint8_t PreviousSystemStatus[2] = {0xff};
+    int idx;
     char *usageMsg = "Usage:\n"
                      "       strchg <index> <voltage> <current>    ex: strchg 0 150 2\n"
                      "       chg    <voltage> <current>            ex: chg 500 100\n"
@@ -843,7 +932,6 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             break;
 
         case S_PREPARNING:
-            ShmDcCommonData->chillerCtrl = TRUE;
 
             if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
                 PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
@@ -986,6 +1074,33 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 //                      pDcChargingInfo->EvBatterytargetVoltage,
 //                      pDcChargingInfo->EvBatterytargetCurrent);
             //ev task do this
+            for (idx = 0; idx < pSysConfig->TotalConnectorCount; idx++) {
+                struct ChargingInfoData* pInfo = (struct ChargingInfoData*)GetDcChargingInfoData(idx);
+                if (pInfo->deratingByConnOtp.isNeedDerating) {
+                    deratingCurrent = pInfo->EvBatterytargetCurrent;
+                    deratingPower = pInfo->AvailableChargingPower;
+
+                    getChillerTemperature(pInfo);
+                    GetOtpPwrOrCurMethod(pInfo, &deratingPower, &deratingCurrent);
+                    if (derating_index != pDcChargingInfo->deratingByConnOtp.deratingIndex) {
+                        printf("Change Derating Index:%d\n", pInfo->deratingByConnOtp.deratingIndex);
+                        derating_index = pInfo->deratingByConnOtp.deratingIndex;
+                    }
+                    if (pInfo->EvBatterytargetCurrent != deratingCurrent ||
+                        pInfo->AvailableChargingPower != deratingPower) {
+                        pInfo->EvBatterytargetCurrent = deratingCurrent;
+                        pInfo->AvailableChargingPower = deratingPower;
+                        printf("Derating Current:%.3f Power:%.3f\n", pInfo->EvBatterytargetCurrent, pInfo->AvailableChargingPower);
+                    }
+                }
+                if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
+                    if (pInfo->EvBatterytargetCurrent > 1500) {
+                        pInfo->EvBatterytargetCurrent = 1500;
+                        printf("Chiller alarm limit target Current under 150A");
+                    }
+                }
+            } // for
+
             pDcChargingInfo->PresentChargingPower =
                 ((float)((pDcChargingInfo->PresentChargingVoltage) *
                          (pDcChargingInfo->PresentChargingCurrent)) / 1000);
@@ -1036,11 +1151,12 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
             pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
             pDcChargingInfo->PresentChargingPower = 0;
-            ShmDcCommonData->chillerCtrl = FALSE;
 
             if (stopChg == pSysConfig->TotalConnectorCount) {
                 ShmDcCommonData->DebugFlag = FALSE;
                 system("/root/Module_EvComm &");
+                ShmFanModuleData->TestFanSpeed = 0;
+
                 sleep(3);
 
                 for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
@@ -1339,7 +1455,6 @@ int main(void)
                      "       tempR                             : print connector header and chiller temperature\r\n"
     			     "       btnl                              : press left button\n"
     			  	 "       btnr                              : press right button\n"
-                     "       chiller                           : set chiller on/off\n"
                      "       settlement                        : Credit Card UnionSettlement\n"
                      "       rededuct                          : Credit Card rededuct\n"
                      "       preauth                           : Credit Card PreAuth\n"
@@ -1532,8 +1647,6 @@ int main(void)
             ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
         } else if (strcmp(newString[0], "sale") == 0) {
             ShmDcCommonData->PreAuth_Config = _CREDITCARD_SALE;
-        } else if (strcmp(newString[0], "chiller") == 0) { //測試槍頭和水冷機溫度
-            writeChillerStatus(newString[1]);
         } else if (strcmp(newString[0], "tccdev") == 0) { //Open TCC DEV
             writeTccdev();
         } else if (strcmp(newString[0], "lcmtest") == 0) { 

BIN
EVSE/Projects/DD360Tcci/Apps/UnsafetyOutputTask


BIN
EVSE/Projects/DD360Tcci/Images/ramdisk.gz


BIN
EVSE/Projects/DD360Tcci/output/FactoryConfig


BIN
EVSE/Projects/DD360Tcci/output/Module_ChkSysTask


BIN
EVSE/Projects/DD360Tcci/output/Module_DoComm


BIN
EVSE/Projects/DD360Tcci/output/Module_EvComm


BIN
EVSE/Projects/DD360Tcci/output/Module_EventLogging


BIN
EVSE/Projects/DD360Tcci/output/Module_InternalComm


BIN
EVSE/Projects/DD360Tcci/output/Module_LcmControl


BIN
EVSE/Projects/DD360Tcci/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360Tcci/output/Module_UpdateFW


BIN
EVSE/Projects/DD360Tcci/output/ReadCmdline


BIN
EVSE/Projects/DD360Tcci/output/UnsafetyOutputTask


BIN
EVSE/Projects/DD360Tcci/output/main


Some files were not shown because too many files changed in this diff