Explorar o código

2021-10-14 / Eason Yang
Action:
1. Improve: Replace free(ptr) on upgrade_check() function.
2. Improve: Delay seconds for AC_WALLMONT_CONTROLLER upgrade.
3. Improve: Protection for get target current at the beginning.
4. Improve: Set PWM request on the system is on preparing mode, also CP states are B and C jump to Charging mode.
5. Improve: Complete mode needs to uplug charging gun for back to Idle mode.
6. Added: Hardware / Software reset logic for complete mode.
7. Improve : Replace config primary MCU duty print out log to high priority polling.

File:
1. main.c
Action 1
Action 2
Action 3
Action 4
Action 5
Action 6

2. Module_InternalComm.c
Action 7

Firmware version: V0.69.XX.XXXX.XX

8009 %!s(int64=3) %!d(string=hai) anos
pai
achega
888d73ba45

+ 9 - 4
EVSE/Projects/AW-Regular/Apps/Module_InternalComm.c

@@ -2200,6 +2200,14 @@ int main(void)
 						DEBUG_INFO("MCU-%d get ble central id : %s\n", gun_index, ShmCharger->gun_info[gun_index].bleLoginCentralId.id);
 					}
 
+					//===============================
+					// Config primary MCU duty
+					//===============================
+					DEBUG_INFO("==================================================\n");
+					DEBUG_INFO("========== High priority polling : Case 9 ========\n");
+					DEBUG_INFO("==================================================\n");
+					DEBUG_INFO("MCU-%d set cp pwn duty : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
+
 					usleep(100000);
 				}
 
@@ -2571,10 +2579,7 @@ int main(void)
 					}
 					else if(stepIndex == 9)
 					{
-						DEBUG_INFO("==================================================\n");
-						DEBUG_INFO("======== Normal priority polling : Case 9 ========\n");
-						DEBUG_INFO("==================================================\n");
-						DEBUG_INFO("MCU-%d set cp pwn duty : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
+
 					}
 					else if(stepIndex == 11)
 					{

+ 54 - 22
EVSE/Projects/AW-Regular/Apps/main.c

@@ -2413,6 +2413,7 @@ int upgrade_check()
 
 					ShmCharger->fwUpgradeInfo.fwType = ((ptr[0x13]<<0) | (ptr[0x12]<<8) | (ptr[0x11]<<16) | (ptr[0x10]<<24));
 					substr(ShmCharger->fwUpgradeInfo.modelName, (char *)ptr, 0, 0x10);
+					free(ptr);
 					DEBUG_INFO("New firmware type: %X\n", ShmCharger->fwUpgradeInfo.fwType);
 					DEBUG_INFO("New firmware model name: %s, %s\n", ShmCharger->fwUpgradeInfo.modelName, ShmSysConfigAndInfo->SysConfig.ModelName);
 
@@ -2464,6 +2465,7 @@ int upgrade_check()
 							case AC_WALLMOUNT_CONTROLLER:
 								for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
 									ShmCharger->gun_info[gun_index].mcuFlag.isMcuUpgradeReq = ON;
+								sleep(10);
 								break;
 							default:
 								result = FAIL;
@@ -2478,8 +2480,6 @@ int upgrade_check()
 						result = FAIL;
 						DEBUG_ERROR("Model name and Firmware type error.\n");
 					}
-
-					free(ptr);
 				}
 				else
 				{
@@ -3535,7 +3535,7 @@ void checkStopReason(uint8_t gun_index)
 		{
 			sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Other");
 		}
-		DEBUG_INFO("Gun-%d : StopReason [ %s ]...\n.",gun_index,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
+		DEBUG_INFO("Gun-%d : StopReason [ %s ]...\n",gun_index,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
 
 		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0);
 		ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = ON;
@@ -3597,7 +3597,7 @@ void checkStopReason(uint8_t gun_index)
 		{
 			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "Other");
 		}
-		DEBUG_INFO("Gun-%d : StopReason [ %s ]...\n.", gun_index, ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason);
+		DEBUG_INFO("Gun-%d : StopReason [ %s ]...\n", gun_index, ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason);
 
 		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0);
 		ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
@@ -4045,12 +4045,34 @@ int main(void)
 						if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
 						{
 							ShmCharger->gun_info[gun_index].targetCurrent = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
-							ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
+							if((6 <= ShmCharger->gun_info[gun_index].targetCurrent))
+							{
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
+							}
+							else if((1 <= ShmCharger->gun_info[gun_index].targetCurrent) && (ShmCharger->gun_info[gun_index].targetCurrent < 6))
+							{
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = 6;
+							}
+							else
+							{
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = 100;
+							}
 						}
 						else
 						{
 							ShmCharger->gun_info[gun_index].targetCurrent = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
-							ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
+							if((6 <= ShmCharger->gun_info[gun_index].targetCurrent))
+							{
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
+							}
+							else if((1 <= ShmCharger->gun_info[gun_index].targetCurrent) && (ShmCharger->gun_info[gun_index].targetCurrent < 6))
+							{
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = 6;
+							}
+							else
+							{
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = 100;
+							}
 						}
 						ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
 
@@ -4198,12 +4220,14 @@ int main(void)
 					}
 
 					// If control pilot detect Bx, skip watch dog time out.
+					/*
 					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C))
 					{
 						setRequest(gun_index,ON);
 						ftime(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
 						ShmCharger->gun_info[gun_index].isGunPlugged = YES;
 					}
+					*/
 
 					// Unplug charging gun to Idle mode
 					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A) && (ShmCharger->gun_info[gun_index].isGunPlugged == YES))
@@ -4234,12 +4258,16 @@ int main(void)
 							setChargerMode(gun_index, SYS_MODE_IDLE);
 						}
 					}
-					else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C))
+					else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C))
 					{
+						setRequest(gun_index,ON);
+						ftime(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
+						ShmCharger->gun_info[gun_index].isGunPlugged = YES;
+						
 						// Set relay on when the system is state C
-						setRelay(gun_index,ON);
-						if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
-						{
+						//setRelay(gun_index,ON);
+						//if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
+						//{
 							ocpp_set_unlocker_req(gun_index, OFF);
 							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
 							getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime);
@@ -4250,7 +4278,7 @@ int main(void)
 							ocpp_set_starttransaction_req(gun_index, ON);
 
 							setChargerMode(gun_index, SYS_MODE_CHARGING);
-						}
+						//}
 					}
 
 					break;
@@ -4619,7 +4647,7 @@ int main(void)
 					   ocpp_get_unlocker_req(gun_index) ||
 					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].schedule.isTriggerStop == ON))
 					{
-						if(((ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON) || (ShmCharger->gun_info[gun_index].isChargerStopByCondition == YES)) && (ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current != 100))
+						if((ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON) || (ShmCharger->gun_info[gun_index].isChargerStopByCondition == YES))
 						{
 							if(((ShmCharger->gun_info[gun_index].rfidReq == ON) && isMatchStartUser(gun_index)) ||
 							   (ShmCharger->gun_info[gun_index].isAuthPassEnd))
@@ -4637,7 +4665,6 @@ int main(void)
 						ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
 						setLedMotion(gun_index, LED_ACTION_STOP);
 						checkStopReason(gun_index);
-						sleep(6);
 						setChargerMode(gun_index, SYS_MODE_COMPLETE);
 						
 						/*
@@ -4881,6 +4908,7 @@ int main(void)
 						   !(!ocpp_get_connection_status() && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy != OFF_POLICY_NOCHARGE) && ((ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0) ? (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration*60)) : (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60)))) &&
 						   !(!ocpp_get_connection_status() && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy != OFF_POLICY_NOCHARGE) && ((ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0) ? (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy)) : (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)))))
 						{
+							sleep(1);
 							setChargerMode(gun_index, SYS_MODE_CHARGING);
 						}
 					}
@@ -4889,19 +4917,23 @@ int main(void)
 					if(isModeChange(gun_index))
 					{
 						setLedMotion(gun_index, LED_ACTION_STOP);
+						sleep(6);
 						setRequest(gun_index, OFF);
 						setRelay(gun_index, OFF);
-						sleep(3);
+						sleep(2);
 					}
+					
+					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A) || ocpp_get_reset_req())
+					{
+						ShmCharger->gun_info[gun_index].rfidReq = OFF;
+						ShmCharger->gun_info[gun_index].isAuthPassEnd = OFF;
+						ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;
+						ocpp_set_remotestop(gun_index, OFF);
+						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].schedule.isTriggerStop = OFF;
 
-					ShmCharger->gun_info[gun_index].rfidReq = OFF;
-					ShmCharger->gun_info[gun_index].isAuthPassEnd = OFF;
-					ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;
-					ocpp_set_remotestop(gun_index, OFF);
-					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].schedule.isTriggerStop = OFF;
-
-					DB_Insert_Record(localDb, gun_index);
-					setChargerMode(gun_index, SYS_MODE_IDLE);
+						DB_Insert_Record(localDb, gun_index);
+						setChargerMode(gun_index, SYS_MODE_IDLE);
+					}
 
 					break;
 				case SYS_MODE_ALARM: