Browse Source

[New feature][DM30][DW30][OCPP] Add smart charging related function and some OCPP authorize improve section.

2020.06.17 / TC Hsu

Actions: Add CheckSmartChargeProfile() and GetStartScheduleTime() function for OCPP smart charging feature using, it only get the tx profile now, need implement the following limitation feature. Modify some authorize detection to improve OCPP feature.

Image version    : N/A
Image checksum   : N/A

Hardware PWB P/N : N/A
Hardware Version : N/A

Files:

	modified:   EVSE/Projects/DM30/Apps/main.c
	modified:   EVSE/Projects/DW30/Apps/main.c
TC_Hsu 4 năm trước cách đây
mục cha
commit
c8ddac9058
2 tập tin đã thay đổi với 222 bổ sung8 xóa
  1. 111 4
      EVSE/Projects/DM30/Apps/main.c
  2. 111 4
      EVSE/Projects/DW30/Apps/main.c

+ 111 - 4
EVSE/Projects/DM30/Apps/main.c

@@ -74,6 +74,7 @@ bool isDetectPlugin();
 void ClearDetectPluginFlag();
 int mystrcmp(unsigned char *p1, unsigned char *p2);
 
+long long DiffTimebWithNow(struct timeb ST);
 unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
 void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
 void ChargingTerminalProcess(byte gunIndex);
@@ -342,6 +343,19 @@ void PRINTF_FUNC(char *string, ...)
 
     DEBUG_INFO_MSG("%s \n", buffer);
 }
+
+long long DiffTimebWithNow(struct timeb ST)
+{
+    //return milli-second
+    struct timeb ET;
+    long long StartTime,StopTime;
+
+    ftime(&ET);
+    StartTime=(long long)ST.time;
+    StopTime=(long long)ET.time;
+    return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
+}
+
 //==========================================
 // Check interface status
 //==========================================
@@ -2725,17 +2739,22 @@ void UserScanFunction()
     else
     {
         // 透過後臺停止充電的判斷
-        if (isAuthorizedComplete() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+        if (isAuthorizedComplete() ||
+            (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
+             ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
         {
             // 判斷後台回覆狀態
-            if(canStartCharging() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+            if(canStartCharging() ||
+               (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
+                ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
             {
                 if (_authorizeIndex != NO_DEFINE)
                 {
                     // 先找 AC
                     if (_authorizeIndex == DEFAULT_AC_INDEX)
                     {
-                        if (strcmp((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
+                        if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
+                            strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL)
                         {
                             AcChargingTerminalProcess();
                         }
@@ -3742,7 +3761,6 @@ void CheckOcppStatus()
 {
     if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES)
     {
-        ShmSysConfigAndInfo->SysInfo.OcppConnStatus = YES;
         ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
     }
 
@@ -4397,6 +4415,89 @@ void CheckTask()
     }
 }
 
+//==========================================
+// Check Smart Charging Profile
+//==========================================
+int GetStartScheduleTime(unsigned char *time)
+{
+    int result = -1;
+    struct tm tmScheduleStart;
+    struct timeb tbScheduleStart;
+
+    if((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
+    {
+        tmScheduleStart.tm_year -= 1900;
+        tmScheduleStart.tm_mon -= 1;
+        tbScheduleStart.time = mktime(&tmScheduleStart);
+        tbScheduleStart.millitm = 0;
+
+        result = DiffTimebWithNow(tbScheduleStart) / 1000;
+    }
+
+    return result;
+}
+
+void CheckSmartChargeProfile(byte _index)
+{
+    if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO)
+    {
+        if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO)
+            ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
+    }
+    else
+    {
+        // Get Charging Profile
+        ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
+        if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL)
+        {
+            int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
+            byte _startCount = NO_DEFINE;
+            byte _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
+
+            for (byte _count = 0; _count < _maxCount; _count++)
+            {
+                // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
+                if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod &&
+                        ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
+                {
+                    _startCount = _count;
+                }
+            }
+
+            PRINTF_FUNC("_startCount = %d \n", _startCount);
+            if (_startCount < _maxCount)
+            {
+                PRINTF_FUNC("*********Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
+                chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
+                if ((chargingInfo[_index]->EvBatterytargetVoltage * 10) > 0)
+                {
+                    chargingInfo[_index]->ChargingProfileCurrent = chargingInfo[_index]->ChargingProfilePower / (chargingInfo[_index]->EvBatterytargetVoltage * 10);
+                }
+            }
+            else
+            {
+                chargingInfo[_index]->ChargingProfilePower = 0;
+                chargingInfo[_index]->ChargingProfileCurrent = 0;
+            }
+
+            PRINTF_FUNC("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
+            PRINTF_FUNC("ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
+        }
+//
+//      printf("-------------Schedule------------\n");
+//      printf("index = %d \n", _index);
+//      printf("StartSchedule = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
+//      printf("ChargingRateUnit = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
+//      printf("----------SchedulePeriod---------\n");
+//      for (int v = 0; v < 10; v++)
+//      {
+//          printf("StartPeriod = %d \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
+//          printf("Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
+//      }
+//      printf("---------------------------------\n");
+    }
+}
+
 int main(void)
 {
     if(CreateShareMemory() == 0)
@@ -4532,6 +4633,12 @@ int main(void)
         if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000)
         {
             CheckTask();
+            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+            {
+                if (chargingInfo[_index]->SystemStatus == S_CHARGING)
+                    CheckSmartChargeProfile(_index);
+            }
+
             gettimeofday(&_cmdMainPriority_time, NULL);
         }
 

+ 111 - 4
EVSE/Projects/DW30/Apps/main.c

@@ -74,6 +74,7 @@ bool isDetectPlugin();
 void ClearDetectPluginFlag();
 int mystrcmp(unsigned char *p1, unsigned char *p2);
 
+long long DiffTimebWithNow(struct timeb ST);
 unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
 void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
 void ChargingTerminalProcess(byte gunIndex);
@@ -342,6 +343,19 @@ void PRINTF_FUNC(char *string, ...)
 
     DEBUG_INFO_MSG("%s \n", buffer);
 }
+
+long long DiffTimebWithNow(struct timeb ST)
+{
+    //return milli-second
+    struct timeb ET;
+    long long StartTime,StopTime;
+
+    ftime(&ET);
+    StartTime=(long long)ST.time;
+    StopTime=(long long)ET.time;
+    return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
+}
+
 //==========================================
 // Check interface status
 //==========================================
@@ -2725,17 +2739,22 @@ void UserScanFunction()
     else
     {
         // 透過後臺停止充電的判斷
-        if (isAuthorizedComplete() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+        if (isAuthorizedComplete() ||
+            (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
+             ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
         {
             // 判斷後台回覆狀態
-            if(canStartCharging() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+            if(canStartCharging() ||
+               (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
+                ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
             {
                 if (_authorizeIndex != NO_DEFINE)
                 {
                     // 先找 AC
                     if (_authorizeIndex == DEFAULT_AC_INDEX)
                     {
-                        if (strcmp((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
+                        if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
+                            strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL)
                         {
                             AcChargingTerminalProcess();
                         }
@@ -3742,7 +3761,6 @@ void CheckOcppStatus()
 {
     if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES)
     {
-        ShmSysConfigAndInfo->SysInfo.OcppConnStatus = YES;
         ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
     }
 
@@ -4397,6 +4415,89 @@ void CheckTask()
     }
 }
 
+//==========================================
+// Check Smart Charging Profile
+//==========================================
+int GetStartScheduleTime(unsigned char *time)
+{
+    int result = -1;
+    struct tm tmScheduleStart;
+    struct timeb tbScheduleStart;
+
+    if((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
+    {
+        tmScheduleStart.tm_year -= 1900;
+        tmScheduleStart.tm_mon -= 1;
+        tbScheduleStart.time = mktime(&tmScheduleStart);
+        tbScheduleStart.millitm = 0;
+
+        result = DiffTimebWithNow(tbScheduleStart) / 1000;
+    }
+
+    return result;
+}
+
+void CheckSmartChargeProfile(byte _index)
+{
+    if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO)
+    {
+        if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO)
+            ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
+    }
+    else
+    {
+        // Get Charging Profile
+        ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
+        if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL)
+        {
+            int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
+            byte _startCount = NO_DEFINE;
+            byte _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
+
+            for (byte _count = 0; _count < _maxCount; _count++)
+            {
+                // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
+                if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod &&
+                        ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
+                {
+                    _startCount = _count;
+                }
+            }
+
+            PRINTF_FUNC("_startCount = %d \n", _startCount);
+            if (_startCount < _maxCount)
+            {
+                PRINTF_FUNC("*********Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
+                chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
+                if ((chargingInfo[_index]->EvBatterytargetVoltage * 10) > 0)
+                {
+                    chargingInfo[_index]->ChargingProfileCurrent = chargingInfo[_index]->ChargingProfilePower / (chargingInfo[_index]->EvBatterytargetVoltage * 10);
+                }
+            }
+            else
+            {
+                chargingInfo[_index]->ChargingProfilePower = 0;
+                chargingInfo[_index]->ChargingProfileCurrent = 0;
+            }
+
+            PRINTF_FUNC("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
+            PRINTF_FUNC("ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
+        }
+//
+//      printf("-------------Schedule------------\n");
+//      printf("index = %d \n", _index);
+//      printf("StartSchedule = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
+//      printf("ChargingRateUnit = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
+//      printf("----------SchedulePeriod---------\n");
+//      for (int v = 0; v < 10; v++)
+//      {
+//          printf("StartPeriod = %d \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
+//          printf("Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
+//      }
+//      printf("---------------------------------\n");
+    }
+}
+
 int main(void)
 {
     if(CreateShareMemory() == 0)
@@ -4532,6 +4633,12 @@ int main(void)
         if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000)
         {
             CheckTask();
+            for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+            {
+                if (chargingInfo[_index]->SystemStatus == S_CHARGING)
+                    CheckSmartChargeProfile(_index);
+            }
+
             gettimeofday(&_cmdMainPriority_time, NULL);
         }