瀏覽代碼

2020-06-09 /Edward Lien

Actions:
1.update SYS_MODE_PREPARING routine & HLC communication timeout change 100% PWM duty will wait CCS task allows.

Files:
1. As follow commit history

Image version: D0.11.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
Edward Lien 4 年之前
父節點
當前提交
19bb0ce6e7

+ 741 - 183
EVSE/Projects/AW-CCS/Apps/main.c

@@ -38,6 +38,8 @@
 #define MtdBlockSize 					0x600000
 
 #define DB_FILE							"/Storage/ChargeLog/localCgargingRecord.db"
+
+#define AC_INPUT_PHASE					3
 //==========================
 // Declare method
 //==========================
@@ -1150,6 +1152,24 @@ unsigned char isModeChange(unsigned char gun_index)
 	return result;
 }
 
+unsigned char isCCSMode(unsigned char gun_index, unsigned char mode)
+{
+	return ((ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress == mode)?YES:NO);
+}
+
+unsigned char isCCSModeChange(unsigned char gun_index)
+{
+	unsigned char result = NO;
+
+	if(!isMode(gun_index, ShmCharger->gun_info[gun_index].PreviousEVChargeProgress))
+	{
+		result = YES;
+
+		ShmCharger->gun_info[gun_index].PreviousEVChargeProgress = ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress;
+	}
+
+	return result;
+}
 //===============================================
 // Get firmware version
 //===============================================
@@ -1182,7 +1202,7 @@ void get_firmware_version(unsigned char gun_index)
 	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.10.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.11.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -2295,7 +2315,7 @@ int main(void)
 						else
 							setChargerMode(gun_index, SYS_MODE_IDLE);
 						
-						ShmSysConfigAndInfo->SysConfig.AcPhaseCount = 3;
+						ShmSysConfigAndInfo->SysConfig.AcPhaseCount = AC_INPUT_PHASE;
 					}
 
 					break;
@@ -2510,140 +2530,232 @@ int main(void)
 					if(isModeChange(gun_index))
 					{
 						ftime(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
-
-						// Set CCS 5% PWM duty
-						ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_5;
-						ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
-						ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_DUTY_5;
-						
+						setLedMotion(gun_index,LED_ACTION_AUTHED);
+						ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_DUTY_5;	
 					}
 					
-					switch(ShmCharger->gun_info[gun_index].ccsHandshakeState)
+					// 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))
 					{
-						case HANDSHAKE_DUTY_5:
-							if(ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty == OFF)
-							{						
+						ftime(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
+						ShmCharger->gun_info[gun_index].isGunPlugged = YES;
+
+						switch(ShmCharger->gun_info[gun_index].ccsHandshakeState)
+						{
+							case HANDSHAKE_DUTY_5:
 								setRequest(gun_index, ON);
 								setLedMotion(gun_index,LED_ACTION_CONNECTED);	
-								DEBUG_INFO("Set Request On.\r\n");
-								//2 secs timeout
-								ftime(&startTime[gun_index][TMR_IDX_CCS_HANDSHAKE]);
-								ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_CCS;	
-							}						
-							break;
-						case HANDSHAKE_CCS:
-							//CCS handshake timeout
-							if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_CCS_HANDSHAKE]) > TIMEOUT_SPEC_CCS_HANDSHAKE)
-							{
+								DEBUG_INFO("Set Request On.\r\n");							
 								
-								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_CP_STAT_E;
-								ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;						
-								ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_CP_STATE_E;
-								ShmCharger->gun_info[gun_index].chargingMode = CHARGING_MODE_BS;
-								DEBUG_INFO("CCS 2 secs handshake timeout.\r\n");
-							}							
-							break;	
-						case HANDSHAKE_CP_STATE_E:
-							if(ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty == OFF)
-							{	
-								DEBUG_INFO("Change to CP STATE E for 4 secs.\r\n");
-								//CP STATE E for 4 secs
-								sleep(4);
+								// Set CCS 5% PWM duty
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_5;
+								ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_DUTY_5_CHECK;	
+								ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
+								break;
+							case HANDSHAKE_DUTY_5_CHECK:
+								if(ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty == OFF)
+								{						
+									//2 secs timeout
+									ftime(&startTime[gun_index][TMR_IDX_CCS_HANDSHAKE]);
+									ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_CCS;
+									//Let CCS task start to negotiate
+									ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = ON;	
+								}						
+								break;
+							case HANDSHAKE_CCS:
+								//CCS handshake timeout
+								if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_CCS_HANDSHAKE]) > TIMEOUT_SPEC_CCS_HANDSHAKE)
+								{
+									
+									ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_CP_STAT_E;
+									ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;						
+									ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_CP_STATE_E;
+									ShmCharger->gun_info[gun_index].chargingMode = CHARGING_MODE_BS;
+									DEBUG_INFO("CCS 2 secs handshake timeout.\r\n");
+								}	
 								
-								//restore normal CP PWM duty
-								// Determine max charging current to MCU
-								DEBUG_INFO("Determine max charging current to MCU.\r\n");
-								if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
+								//CCS status check
+								if(ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus > 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);
-									if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
-									{
-										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);
-										ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
-									}
+									ShmCharger->gun_info[gun_index].chargingMode = CHARGING_MODE_HLC;
+									DEBUG_INFO("Enter HLC Mode charging.\r\n");										
+									ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_HLC_MODE;
+								}
+								
+								// Use RFID card to stop handshaking
+								if((ShmCharger->gun_info[gun_index].rfidReq == ON) && isMatchStartUser(gun_index))
+								{
+									DEBUG_INFO("Use RFID card to stop handshaking.\r\n");
+									setSpeaker(ON,SPEAKER_SHORT);
+									setChargerMode(gun_index, SYS_MODE_IDLE);
+									
 								}
 								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);
-									if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
+									ShmCharger->gun_info[gun_index].rfidReq = OFF;
+								}							
+								break;	
+							case HANDSHAKE_CP_STATE_E:
+								if(ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty == OFF)
+								{	
+									DEBUG_INFO("Change to CP STATE E for 4 secs.\r\n");
+									//CP STATE E for 4 secs
+									sleep(4);
+									
+									//restore normal CP PWM duty
+									// Determine max charging current to MCU
+									DEBUG_INFO("Determine max charging current to MCU.\r\n");
+									if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
 									{
-										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);
-										ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
+										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);
+										if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
+										{
+											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);
+											ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
+										}
 									}
-								}
-								ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;						
-								ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_SET_MAX_CURRENT;
-							}						
-							break;
-						case HANDSHAKE_SET_MAX_CURRENT:
-							if(ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty == OFF)
-							{			
-								//refresh 180 secs timeout
-								ftime(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
-								ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_NORMAL_CP;
-								DEBUG_INFO("Refresh handshake 180 secs timeout.\r\n");								
-							}						
-							break;	
-						case HANDSHAKE_NORMAL_CP:
-							// If control pilot detect Bx, skip watch dog time out.
-							if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)
-							{
-								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))
-							{
-								DEBUG_INFO("Charging gun is plugged before.\r\n");
-								setChargerMode(gun_index, SYS_MODE_IDLE);
-							}
-
-							// Use RFID card to stop handshaking
-							if((ShmCharger->gun_info[gun_index].rfidReq == ON) && isMatchStartUser(gun_index))
-							{
-								DEBUG_INFO("Use RFID card to stop handshaking.\r\n");
-								setSpeaker(ON,SPEAKER_SHORT);
-								setChargerMode(gun_index, SYS_MODE_IDLE);
-							}
-							else
-							{
-								ShmCharger->gun_info[gun_index].rfidReq = OFF;
-							}
-
-							if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > ShmCharger->timeoutSpec.Present_Timeout_Spec)
-							{
-								setLedMotion(gun_index, LED_ACTION_HANDSHAKE_FAIL);
+									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);
+										if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
+										{
+											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);
+											ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;
+										}
+									}
+									ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;						
+									ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_SET_MAX_CURRENT;
+								}						
+								break;
+							case HANDSHAKE_SET_MAX_CURRENT:
+								if(ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty == OFF)
+								{			
+									//refresh 180 secs timeout
+									ftime(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
+									DEBUG_INFO("Refresh handshake 180 secs timeout.\r\n");	
+									ShmCharger->gun_info[gun_index].ccsHandshakeState = HANDSHAKE_BS_MODE;
+									DEBUG_INFO("Enter BS Mode charging.\r\n");		
+
+									setRelay(gun_index,ON);
+								}						
+								break;	
+							case HANDSHAKE_BS_MODE:
+								if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > ShmCharger->timeoutSpec.Present_Timeout_Spec)
+								{
+									setLedMotion(gun_index, LED_ACTION_HANDSHAKE_FAIL);
 
-								if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > (ShmCharger->timeoutSpec.Present_Timeout_Spec+5000))
+									if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > (ShmCharger->timeoutSpec.Present_Timeout_Spec+5000))
+									{
+										DEBUG_INFO("Handshaking timeout...\r\n");
+										setChargerMode(gun_index, SYS_MODE_IDLE);
+									}
+								}
+								else if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
 								{
-									DEBUG_INFO("Handshaking timeout...\r\n");
-									setChargerMode(gun_index, SYS_MODE_IDLE);
+									ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor = OFF;
+									ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
+									getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime);
+									ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start = ShmCharger->gun_info[gun_index].powerConsumption.power_consumption;
+									ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
+									memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
+
+									memcpy((char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StartTransaction[gun_index].IdTag));
+									
+									ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = ON;
+
+									setChargerMode(gun_index, SYS_MODE_CHARGING);
+								}						
+								break;		
+							case HANDSHAKE_HLC_MODE:	
+								if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > ShmCharger->timeoutSpec.Present_Timeout_Spec)
+								{
+									setLedMotion(gun_index, LED_ACTION_HANDSHAKE_FAIL);
+
+									if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > (ShmCharger->timeoutSpec.Present_Timeout_Spec+5000))
+									{
+										DEBUG_INFO("Handshaking timeout...\r\n");
+										//Cancel CCS task negotiating
+										ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;	
+										ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;	
+						
+#ifdef	CCS_SIMULATION_DATA				
+										ShmCharger->gun_info[gun_index].acCcsInfo.SetCPPWMDuty = CCS_PWM_DUTY_100;						
+#endif	//CCS_SIMULATION_DATA
+									}
 								}
-							}
-							else if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
-							{
-								ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor = OFF;
-								ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
-								getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime);
-								ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start = ShmCharger->gun_info[gun_index].powerConsumption.power_consumption;
-								ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
-								memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
+								else if(ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress == HLC_START_MODE)
+								{
+									setRelay(gun_index,ON);
+									ShmCharger->gun_info[gun_index].isCCSStartTransation = ON;
+								}	
+									
+								if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON) &&
+									(ShmCharger->gun_info[gun_index].isCCSStartTransation == ON))
+								{
+									ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor = OFF;
+									ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
+									getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime);
+									ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start = ShmCharger->gun_info[gun_index].powerConsumption.power_consumption;
+									ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
+									memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
+
+									memcpy((char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StartTransaction[gun_index].IdTag));
+									
+									ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = ON;
+									
+									ShmCharger->gun_info[gun_index].isCCSStartTransation = OFF;
+									
+									setChargerMode(gun_index, SYS_MODE_CHARGING);
+								}															
+								break;
+							default:
+								break;
+						}						
+					}
 
-								memcpy((char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StartTransaction[gun_index].IdTag));
-								
-								ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = ON;
-								
-								setRelay(gun_index,ON);
+					// Unplug charging gun to Idle mode
+					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A) && (ShmCharger->gun_info[gun_index].isGunPlugged == YES))
+					{
+						DEBUG_INFO("Charging gun is plugged before.\r\n");
+						//setChargerMode(gun_index, SYS_MODE_IDLE);
+						
+						//Cancel CCS task negotiating
+						ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;	
+						ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;	
+						
+#ifdef	CCS_SIMULATION_DATA				
+						ShmCharger->gun_info[gun_index].acCcsInfo.SetCPPWMDuty = CCS_PWM_DUTY_100;						
+#endif	//CCS_SIMULATION_DATA
+					}
 
-								setChargerMode(gun_index, SYS_MODE_CHARGING);
-							}						
-							break;		
-						case HANDSHAKE_NORMAL_CCS:
-							
-							break;
-						default:
-							break;
+					// Use RFID card to stop handshaking
+					if((ShmCharger->gun_info[gun_index].rfidReq == ON) && isMatchStartUser(gun_index))
+					{
+						DEBUG_INFO("Use RFID card to stop handshaking.\r\n");
+						setSpeaker(ON,SPEAKER_SHORT);
+						//setChargerMode(gun_index, SYS_MODE_IDLE);
+						
+						//Cancel CCS task negotiating
+						ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;	
+						ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;	
+						
+#ifdef	CCS_SIMULATION_DATA				
+						ShmCharger->gun_info[gun_index].acCcsInfo.SetCPPWMDuty = CCS_PWM_DUTY_100;						
+#endif	//CCS_SIMULATION_DATA
+					}
+					else
+					{
+						ShmCharger->gun_info[gun_index].rfidReq = OFF;
+					}
+					
+					if((ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty == ON) && ShmCharger->gun_info[gun_index].acCcsInfo.SetCPPWMDuty == CCS_PWM_DUTY_100)
+					{
+						ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_100;
+						ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;	
+						ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = OFF;
+						
+						setChargerMode(gun_index, SYS_MODE_IDLE);
 					}
 					break;
 				case SYS_MODE_CHARGING:
@@ -2873,85 +2985,316 @@ int main(void)
 							}						
 							break;
 						case CHARGING_MODE_HLC:
-							
-							break;
-						default:
-							break;
-					}
-					break;
-				case SYS_MODE_TERMINATING:
-					if(isModeChange(gun_index))
-					{
-						if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration != 0)
-						{
-							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
-						}
+							if((ShmCharger->gun_info[gun_index].rfidReq == ON) ||
+							   (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop == ON) ||
+							   (ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq == ON)||
+							   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState != CP_STATE_C) ||
+							   (ShmOCPP16Data->MsMsg.bits.ResetReq) ||
+							   (ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor == ON) ||
+							   (ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress == HLC_STOP_MODE) ||
+							   (ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress == HLC_RENEGOTIATE_MODE) ||
+							   (ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress == HLC_STANDBY_MODE))
+							{
+								//Cancel CCS task negotiating
+								ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission = OFF;	
+								setRelay(gun_index,OFF);
+								ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;	
+						
+#ifdef	CCS_SIMULATION_DATA				
+								ShmCharger->gun_info[gun_index].acCcsInfo.SetCPPWMDuty = CCS_PWM_DUTY_100;						
+#endif	//CCS_SIMULATION_DATA	
+							}
+							else
+							{
+								setLedMotion(gun_index,LED_ACTION_CHARGING);
+								ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
+								ftime(&endChargingTime[gun_index]);
+								ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
+								ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = ((float)(ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start))/100;
 
-						if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
-						{
-							setLedMotion(gun_index, LED_ACTION_STOP);
-						}
-						else
-						{}
+								// Response StartTransactionConf
+								if(ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == ON)
+								{
+									ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = OFF;
+								}
 
-						getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
-					}
-					switch(ShmCharger->gun_info[gun_index].chargingMode)
-					{
-						case CHARGING_MODE_BS:
-								// If RFID SN different with start user, it need to authorize ID
-								if((ShmCharger->gun_info[gun_index].rfidReq == ON) && !isMatchStartUser(gun_index))
+								// Charging profile preparation
+								if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_PROFILE_PREPARE]) > TIMEOUT_SPEC_PROFILE_PREPARE)
 								{
-									if((DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH) && !ShmOCPP16Data->SpMsg.bits.AuthorizeReq)
+									if(!ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf)
 									{
-										// Request authorization
-										ftime(&startTime[gun_index][TMR_IDX_AUTH]);
-										memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
-										if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
+										ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = ON;
+										ftime(&startTime[gun_index][TMR_IDX_PROFILE_PREPARE]);
+									}
+									else
+									{
+										ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = OFF;
+									}
+								}
+
+								// Checking profile id > 0 and current time is between charging profile validFrom & validTo
+								if((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId>0) &&
+								   (((strlen((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ValidFrom)>0) && (strlen((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ValidTo)>0)) ? isProfileValid(gun_index) : ON))
+								{
+									// Debug information
+									if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_LOGPPRINTOUT]) > TIMEOUT_SPEC_LOGPPRINTOUT)
+									{
+										DEBUG_INFO("Profile ID found: %d\r\n", ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId);
+										DEBUG_INFO("Valid from: %s\r\n", ShmOCPP16Data->SmartChargingProfile[gun_index].ValidFrom);
+										DEBUG_INFO("Valid to: %s\r\n", ShmOCPP16Data->SmartChargingProfile[gun_index].ValidTo);
+										DEBUG_INFO("Start schedule: %s\r\n", ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.StartSchedule);
+										DEBUG_INFO("Profile kind: %s\r\n", ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileKind);
+										DEBUG_INFO("RecurrencyKind: %s\r\n", ShmOCPP16Data->SmartChargingProfile[gun_index].RecurrencyKind);
+										DEBUG_INFO("Profile purpose: %s\r\n", ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfilePurpose);
+										DEBUG_INFO("Transaction ID: %d\r\n", ShmOCPP16Data->SmartChargingProfile[gun_index].TransactionId);
+										DEBUG_INFO("ChargingRateUnit: %s\r\n", ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit);
+									}
+
+									// Checking profile kind
+									if((mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileKind, "Absolute") == PASS))
+									{
+										// Absolute profile
+										if(((mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfilePurpose, "TxProfile") == PASS) && (ShmOCPP16Data->SmartChargingProfile[gun_index].TransactionId == ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId)) ||
+											(mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfilePurpose, "TxProfile") == FAIL))
 										{
-											// Big endian
-											switch(rfid.snType)
+											// Checking limitation
+											for(uint8_t idx_period=0;idx_period<ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod);idx_period++)
 											{
-												case RFID_SN_TYPE_6BYTE:
-													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
-													break;
-												case RFID_SN_TYPE_7BYTE:
-													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
-													break;
-												case RFID_SN_TYPE_10BYTE:
-													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7], rfid.currentCard[8], rfid.currentCard[9]);
-													break;
-												case RFID_SN_TYPE_4BYTE:
-												default:
-													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3]);
+												if((getScheduleStart(gun_index) > ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod) &&
+												   (((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod == 0) && (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit != 0)) || (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod != 0)))
+												{
+													ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/220:ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
+													DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\r\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
+												}
+												else
 													break;
 											}
 										}
-										else
+									}
+									else if((mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileKind, "Relative") == PASS))
+									{
+										// Relative profile
+										if(((mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfilePurpose, "TxProfile") == PASS) && (ShmOCPP16Data->SmartChargingProfile[gun_index].TransactionId == ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId)) ||
+											(mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfilePurpose, "TxProfile") == FAIL))
 										{
-											// Little endian
-											switch(rfid.snType)
+											// Checking limitation
+											for(uint8_t idx_period=0;idx_period<ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod);idx_period++)
 											{
-												case RFID_SN_TYPE_6BYTE:
-													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
-													break;
-												case RFID_SN_TYPE_7BYTE:
-													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
-													break;
-												case RFID_SN_TYPE_10BYTE:
-													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[9], rfid.currentCard[8], rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
-													break;
-												case RFID_SN_TYPE_4BYTE:
-												default:
-													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+												if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration > ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod) &&
+												   (((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod == 0) && (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit != 0)) || (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod != 0)))
+												{
+													ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/220:ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
+													DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\r\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
+												}
+												else
 													break;
 											}
 										}
-										DEBUG_INFO("End request User Id : %s\r\n", ShmSysConfigAndInfo->SysConfig.UserId);
-										DEBUG_INFO("Start method : %d...\r\n ", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod);
-
-
-										if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID)
+									}
+									else
+									{
+										// Recurring profile
+										if(((mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfilePurpose, "TxProfile") == PASS) && (ShmOCPP16Data->SmartChargingProfile[gun_index].TransactionId == ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId)) ||
+											(mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfilePurpose, "TxProfile") == FAIL))
+										{
+											if((mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].RecurrencyKind, "Daily") == PASS))
+											{
+												// Checking limitation
+												for(uint8_t idx_period=0;idx_period<ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod);idx_period++)
+												{
+													if((getStartSinceToday() > ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod) &&
+													   (((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod == 0) && (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit != 0)) || (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod != 0)))
+													{
+														ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/220:ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
+														DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\r\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
+													}
+													else
+														break;
+												}
+											}
+											else
+											{
+												// Checking limitation
+												for(uint8_t idx_period=0;idx_period<ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod);idx_period++)
+												{
+													if((getStartSinceWeek() > ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod) &&
+													   (((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod == 0) && (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit != 0)) || (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod != 0)))
+													{
+														ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/220:ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
+														DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\r\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
+													}
+													else
+														break;
+												}
+											}
+										}
+									}
+								}
+
+								// Determine max charging current to MCU
+								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);
+									if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
+									{
+										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);
+										ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
+									}
+								}
+								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);
+									if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
+									{
+										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);
+										ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
+									}
+								}
+
+								// Debug information
+								if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_LOGPPRINTOUT]) > TIMEOUT_SPEC_LOGPPRINTOUT)
+								{
+									DEBUG_INFO("=======================================================================\r\n");
+									DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent: %d \r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
+									DEBUG_INFO("ShmCharger->gun_info[%d].primaryMcuCp_Pwn_Duty.max_current: %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
+									DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent: %d\r\n", gun_index, ShmCharger->gun_info[gun_index].targetCurrent);
+									DEBUG_INFO("=======================================================================\r\n");
+									ftime(&startTime[gun_index][TMR_IDX_LOGPPRINTOUT]);
+								}
+
+								if(ShmOCPP16Data->OcppConnStatus)
+								{
+									// On-line max condition check
+									if((ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60)))
+									{
+										setChargerMode(gun_index, SYS_MODE_TERMINATING);
+										DEBUG_INFO("Connector-%d charging duration(%d) already over max duration(%d) in second.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration, (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60));
+									}
+									else if((ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)))
+									{
+										setChargerMode(gun_index, SYS_MODE_TERMINATING);
+										DEBUG_INFO("Connector-%d charging energy(%.2f) already over max energy(%.2f) in KWH.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy, ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy));
+									}
+									else
+									{
+										setRequest(gun_index, ON);
+									}
+								}
+								else
+								{
+
+									// Off-line max condition check
+									if((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) ||
+									   ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE) && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy != OFF_POLICY_NOCHARGE)))
+									{
+										if(((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))))
+										{
+											setChargerMode(gun_index, SYS_MODE_TERMINATING);
+											DEBUG_INFO("Connector-%d charging duration(%d) already over off-line max duration(%d) in second.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration, (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60));
+										}
+										else if(((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))))
+										{
+											setChargerMode(gun_index, SYS_MODE_TERMINATING);
+											DEBUG_INFO("Connector-%d charging energy(%.2f) already over off-line max energy(%.2f) in KWH.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy, ((float)ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy));
+										}
+										else
+										{
+											setRequest(gun_index, ON);
+										}
+									}
+									else
+									{
+										setRequest(gun_index, OFF);
+										DEBUG_INFO("Connector-%d can not charging in off line\r\n", gun_index);
+									}
+								}
+							}
+							if((ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty == ON) && ShmCharger->gun_info[gun_index].acCcsInfo.SetCPPWMDuty == CCS_PWM_DUTY_100)
+							{
+								ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = CCS_PWM_DUTY_100;
+								ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = ON;	
+								ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = OFF;
+								
+								setChargerMode(gun_index, SYS_MODE_TERMINATING);
+							}								
+							break;
+						default:
+							break;
+					}
+					break;
+				case SYS_MODE_TERMINATING:
+					if(isModeChange(gun_index))
+					{
+						if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration != 0)
+						{
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
+						}
+
+						if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
+						{
+							setLedMotion(gun_index, LED_ACTION_STOP);
+						}
+						else
+						{}
+
+						getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
+					}
+					switch(ShmCharger->gun_info[gun_index].chargingMode)
+					{
+						case CHARGING_MODE_BS:
+								// If RFID SN different with start user, it need to authorize ID
+								if((ShmCharger->gun_info[gun_index].rfidReq == ON) && !isMatchStartUser(gun_index))
+								{
+									if((DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH) && !ShmOCPP16Data->SpMsg.bits.AuthorizeReq)
+									{
+										// Request authorization
+										ftime(&startTime[gun_index][TMR_IDX_AUTH]);
+										memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
+										if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
+										{
+											// Big endian
+											switch(rfid.snType)
+											{
+												case RFID_SN_TYPE_6BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
+													break;
+												case RFID_SN_TYPE_7BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
+													break;
+												case RFID_SN_TYPE_10BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7], rfid.currentCard[8], rfid.currentCard[9]);
+													break;
+												case RFID_SN_TYPE_4BYTE:
+												default:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3]);
+													break;
+											}
+										}
+										else
+										{
+											// Little endian
+											switch(rfid.snType)
+											{
+												case RFID_SN_TYPE_6BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+													break;
+												case RFID_SN_TYPE_7BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+													break;
+												case RFID_SN_TYPE_10BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[9], rfid.currentCard[8], rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+													break;
+												case RFID_SN_TYPE_4BYTE:
+												default:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+													break;
+											}
+										}
+										DEBUG_INFO("End request User Id : %s\r\n", ShmSysConfigAndInfo->SysConfig.UserId);
+										DEBUG_INFO("Start method : %d...\r\n ", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod);
+
+
+										if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID)
 										{
 											switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
 											{
@@ -3075,6 +3418,180 @@ int main(void)
 								}
 								break;
 						case CHARGING_MODE_HLC:
+								// If RFID SN different with start user, it need to authorize ID
+								if((ShmCharger->gun_info[gun_index].rfidReq == ON) && !isMatchStartUser(gun_index))
+								{
+									if((DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH) && !ShmOCPP16Data->SpMsg.bits.AuthorizeReq)
+									{
+										// Request authorization
+										ftime(&startTime[gun_index][TMR_IDX_AUTH]);
+										memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
+										if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
+										{
+											// Big endian
+											switch(rfid.snType)
+											{
+												case RFID_SN_TYPE_6BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
+													break;
+												case RFID_SN_TYPE_7BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
+													break;
+												case RFID_SN_TYPE_10BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7], rfid.currentCard[8], rfid.currentCard[9]);
+													break;
+												case RFID_SN_TYPE_4BYTE:
+												default:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3]);
+													break;
+											}
+										}
+										else
+										{
+											// Little endian
+											switch(rfid.snType)
+											{
+												case RFID_SN_TYPE_6BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+													break;
+												case RFID_SN_TYPE_7BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+													break;
+												case RFID_SN_TYPE_10BYTE:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[9], rfid.currentCard[8], rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+													break;
+												case RFID_SN_TYPE_4BYTE:
+												default:
+													sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+													break;
+											}
+										}
+										DEBUG_INFO("End request User Id : %s\r\n", ShmSysConfigAndInfo->SysConfig.UserId);
+										DEBUG_INFO("Start method : %d...\r\n ", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod);
+
+
+										if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID)
+										{
+											switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
+											{
+												case AUTH_MODE_ENABLE:
+													if(ShmOCPP16Data->OcppConnStatus)
+													{
+														// On line
+														ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
+													}
+													else
+													{
+														// Off line
+														switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
+														{
+															case OFF_POLICY_LOCALLIST:
+																ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
+																break;
+															case OFF_POLICY_PH_RFID:
+																break;
+															case OFF_POLICY_FREE:
+																break;
+															case OFF_POLICY_NOCHARGE:
+															default:
+																break;
+														}
+													}
+													break;
+												case AUTH_MODE_DISABLE:
+												default:
+													break;
+											}
+										}
+										else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_BACKEND)
+										{
+											ShmCharger->gun_info[gun_index].rfidReq = OFF;
+											DEBUG_INFO("Need to match with start method : START_METHOD_BACKEND...\r\n");
+											setChargerMode(gun_index, SYS_MODE_CHARGING);
+										}
+										else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_BLE)
+										{
+											ShmCharger->gun_info[gun_index].rfidReq = OFF;
+											DEBUG_INFO("Need to match with start method : START_METHOD_BLE...\r\n");
+											setChargerMode(gun_index, SYS_MODE_CHARGING);
+										}
+										else
+										{}
+
+									}
+									else
+									{
+										if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
+										  (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) ||
+										  (!ShmOCPP16Data->OcppConnStatus&&(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)))
+										{
+											if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) ||
+											   (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) ||
+											   (!ShmOCPP16Data->OcppConnStatus&&(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)))
+											{
+												ShmCharger->gun_info[gun_index].isAuthPassEnd = ON;
+											}
+											else
+											{
+												ShmCharger->gun_info[gun_index].rfidReq = OFF;
+
+												DEBUG_INFO("Authorize fail.\r\n");
+												setSpeaker(ON,SPEAKER_INTERVAL_3COUNT);
+												setLedMotion(gun_index,LED_ACTION_RFID_FAIL);
+												sleep(3);
+											}
+
+											ShmOCPP16Data->SpMsg.bits.AuthorizeConf = OFF;
+										}
+									}
+								}
+
+								// End authorize pass
+								if(((ShmCharger->gun_info[gun_index].rfidReq == ON) && isMatchStartUser(gun_index)) ||
+								   (ShmCharger->gun_info[gun_index].isAuthPassEnd) ||
+								   (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop == ON) ||
+								   (ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq == ON) ||
+								   ((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A) && (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE") == 0)) ||
+								   (ShmOCPP16Data->MsMsg.bits.ResetReq) ||
+								   (ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor == ON))
+								{
+									if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON)
+									{
+										if(((ShmCharger->gun_info[gun_index].rfidReq == ON) && isMatchStartUser(gun_index)) ||
+										   (ShmCharger->gun_info[gun_index].isAuthPassEnd))
+										{
+											DEBUG_INFO("Authorize pass.\r\n");
+											setSpeaker(ON,SPEAKER_SHORT);
+											setLedMotion(gun_index,LED_ACTION_RFID_PASS);
+											sleep(3);
+										}
+									}
+									else
+									{}
+
+									setRequest(gun_index, OFF);
+									setLedMotion(gun_index, LED_ACTION_STOP);
+
+									if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
+									{
+										setChargerMode(gun_index, SYS_MODE_COMPLETE);
+									}
+								}
+								else
+								{
+									if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C) &&
+									   (ShmCharger->gun_info[gun_index].rfidReq != ON) &&
+									   (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop != ON)  &&
+									   (ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq != ON) &&
+									   !ShmOCPP16Data->MsMsg.bits.ResetReq &&
+									   !(ShmOCPP16Data->OcppConnStatus && (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60))) &&
+									   !(ShmOCPP16Data->OcppConnStatus && (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy))) &&
+									   !(!ShmOCPP16Data->OcppConnStatus && (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)))) &&
+									   !(!ShmOCPP16Data->OcppConnStatus && (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)))))
+									{
+										setChargerMode(gun_index, SYS_MODE_CHARGING);
+									}
+								}						
 								break;
 						default:
 								break;
@@ -3132,6 +3649,47 @@ int main(void)
 								setChargerMode(gun_index, SYS_MODE_IDLE);
 								break;
 						case CHARGING_MODE_HLC:
+								if(ShmOCPP16Data->MsMsg.bits.ResetReq)
+								{
+									if(strcmp((char*)ShmOCPP16Data->Reset.Type, "Hard")==0)
+										sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "HardReset");
+									else
+										sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "SoftReset");
+								}
+								else if(ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)
+								{
+									sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Remote");
+								}
+								else if(ShmCharger->gun_info[gun_index].rfidReq || ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop)
+								{
+									sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
+								}
+								else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
+								{
+									sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+								}
+								else if(ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor == ON)
+								{
+									sprintf((char*)ShmOCPP16Data->StopTransaction[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].StopReason, "UnlockCommand");
+								}
+								else
+								{
+									sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Other");
+								}
+
+								DEBUG_INFO("Gun-%d : StopReason [ %s ]...\r\n.",gun_index,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
+
+								memcpy((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].IdTag));
+								ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
+								ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = ON;
+
+								ShmCharger->gun_info[gun_index].rfidReq = OFF;
+								ShmCharger->gun_info[gun_index].isAuthPassEnd = OFF;
+								ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;
+								ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = OFF;
+
+								DB_Insert_Record(localDb, gun_index);
+								setChargerMode(gun_index, SYS_MODE_IDLE);						
 								break;
 						default:
 								break;

+ 16 - 5
EVSE/Projects/AW-CCS/Apps/main.h

@@ -144,21 +144,28 @@
 //=================================
 //CCS related define
 //=================================
+#define CCS_SIMULATION_DATA
+
 #define CCS_PWM_DUTY_CP_STAT_E			0			
 #define CCS_PWM_DUTY_5					5
 #define CCS_PWM_DUTY_100				100
 
 
 #define HANDSHAKE_DUTY_5				1
-#define HANDSHAKE_CCS					2
-#define HANDSHAKE_CP_STATE_E			3
-#define HANDSHAKE_SET_MAX_CURRENT		4
-#define HANDSHAKE_NORMAL_CP				5
-#define HANDSHAKE_NORMAL_CCS			6
+#define HANDSHAKE_DUTY_5_CHECK			2
+#define HANDSHAKE_CCS					3
+#define HANDSHAKE_CP_STATE_E			4
+#define HANDSHAKE_SET_MAX_CURRENT		5
+#define HANDSHAKE_BS_MODE				6
+#define HANDSHAKE_HLC_MODE				7
 
 #define	CHARGING_MODE_BS				0
 #define	CHARGING_MODE_HLC				1
 
+#define	HLC_STOP_MODE					0
+#define	HLC_START_MODE					1
+#define	HLC_RENEGOTIATE_MODE			2
+#define	HLC_STANDBY_MODE				3
 
 #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
@@ -539,6 +546,7 @@ typedef struct CCS_INFO
 													9: H  (<12V)*/
 	float		CPPositiveVoltage;				/*uint: 1V*/
 	float		CPNegativeVoltage;				/*uint: 1V*/
+	uint32_t	CCSSocketCount;				/*unit: 1*/
 	uint16_t 	ChargingPermission:1;				/*0x00: Not ready yet, stay in idle mode or go into terminating process.
 												  0x01: start charging process*/
 	uint16_t 	ConnectorLockerStatus:1;			/*0x00: released
@@ -587,6 +595,7 @@ typedef struct GUN_INFO
 	Set_Led_Brightness								setLedBrightness;
 	Ac_Ccs_Info										acCcsInfo;
 	uint8_t											ccsHandshakeState;
+	uint8_t											PreviousEVChargeProgress;	
 	uint8_t											chargingMode;
 	uint16_t										targetCurrent;
 	uint16_t										isAuthPassEnd:1;
@@ -597,6 +606,8 @@ typedef struct GUN_INFO
 	uint16_t										isSetLedBrightness:1;
 	uint16_t										isUnlockerConnetor:1;
 	uint16_t										isOperactive:1;
+	uint16_t										isCCSWaitChangeDuty:1;
+	uint16_t										isCCSStartTransation:1;
 }Gun_Info;
 
 struct Charger

二進制
EVSE/Projects/AW-CCS/Images/FactoryDefaultConfig.bin


二進制
EVSE/Projects/AW-CCS/Images/ramdisk.gz