Browse Source

2020/02/12 /Eason Yang
1.Change all file. Reason: Synchronize source code from Platform - branch_AC_Eason

8009 5 years ago
parent
commit
da4e0a59f7

+ 40 - 46
EVSE/Projects/AW-Regular/Apps/Module_AlarmDetect.c

@@ -56,8 +56,7 @@ struct{
 	unsigned short int	OT_AMB;
 	unsigned short int	GMI;
 	unsigned short int	Short;
-	unsigned short int	Ac_Leak;
-	unsigned short int	Dc_Leak;
+	unsigned short int	Leakage;
 	unsigned short int	HandShakingTimeout;
 	unsigned short int	EmrgencyBTN;
 	unsigned short int	Relay_Welding;
@@ -159,7 +158,7 @@ int InitShareMemory()
     {}
 
    	//creat ShmStatusCodeData
-   	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
+   	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), IPC_CREAT | 0777)) < 0)
 	{
 
 		DEBUG_ERROR("shmget ShmCharger NG\r\n");
@@ -177,7 +176,7 @@ int InitShareMemory()
 	{}
 
    	//creat ShmOCPP16Data
-	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
 	{
 
 		DEBUG_ERROR("shmget ShmOCPP16Data NG\r\n");
@@ -266,7 +265,7 @@ int main(void)
 					Alarm_Counter[gun_index].OV[0]++;
 				}
 			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE))
+			else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
 			{
 				Alarm_Counter[gun_index].OV[0] = 0;
 				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == ON))
@@ -546,7 +545,7 @@ int main(void)
 
 			//=====================================
 			// CP level fail detection
-			//====================================
+			//=====================================
 			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR)
 			{
 				if(Alarm_Counter[gun_index].CP_LevelFail > FILTER_SPEC)
@@ -575,65 +574,59 @@ int main(void)
 			}
 
 			//=====================================
-			// Current AC leak detection
+			// Current AC/DC leak detection
 			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)
+			if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC) ||
+			   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC))
 			{
-				if(Alarm_Counter[gun_index].Ac_Leak > FILTER_SPEC)
+				if(Alarm_Counter[gun_index].Leakage > FILTER_SPEC)
 				{
 					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF))
 					{
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_AC;
-						DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \r\n");
+
+						if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)
+						{
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_AC;
+							ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = ON;
+							DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \r\n");
+						}
+						else if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)
+						{
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_DC;
+							ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = ON;
+							DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \r\n");
+						}
 					}
 				}
 				else
 				{
-					Alarm_Counter[gun_index].Ac_Leak++;
+					Alarm_Counter[gun_index].Leakage++;
 				}
 			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC))
+			else if((!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)) ||
+					(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)))
 			{
-				Alarm_Counter[gun_index].Ac_Leak = 0;
+				Alarm_Counter[gun_index].Leakage = 0;
 				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON))
 				{
 					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_AC;
-					DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \r\n");
+
+					if(ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage == ON)
+					{
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_AC;
+						ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = OFF;
+						DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \r\n");
+					}
+					else if(ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage == ON)
+					{
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_DC;
+						ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = OFF;
+						DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \r\n");
+					}
 				}
 			}
 
-			//=====================================
-			// Current DC leak detection
-			//=====================================
-//			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)
-//			{
-//				if(Alarm_Counter[gun_index].Dc_Leak > FILTER_SPEC)
-//				{
-//					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF))
-//					{
-//						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
-//						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_DC;
-//						DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \r\n");
-//					}
-//				}
-//				else
-//				{
-//					Alarm_Counter[gun_index].Dc_Leak++;
-//				}
-//			}
-//			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC))
-//			{
-//				Alarm_Counter[gun_index].Dc_Leak = 0;
-//				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON))
-//				{
-//					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
-//					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_DC;
-//					DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \r\n");
-//				}
-//			}
-
 			//=====================================
 			// MCU self test fail detection
 			//=====================================
@@ -1021,6 +1014,7 @@ int main(void)
 			else
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "NoError");
+				memset(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, 0x00, ARRAY_SIZE(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode));
 			}
 
 			//=====================================

+ 3 - 3
EVSE/Projects/AW-Regular/Apps/Module_EventLogging.c

@@ -288,7 +288,7 @@ int main(void)
 		}
 
 		//check Alarm Status
-		for(ByteCount=0;ByteCount<8;ByteCount++)
+		for(ByteCount=0;ByteCount<11;ByteCount++)
 		{
 			if(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount] != ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount])
 			{
@@ -313,7 +313,7 @@ int main(void)
 		}
 
 		//check Info Status
-		for(ByteCount=0;ByteCount<8;ByteCount++)
+		for(ByteCount=0;ByteCount<29;ByteCount++)
 		{
 			if(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount] != ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount])
 			{
@@ -336,7 +336,7 @@ int main(void)
 				}
 			}
 		}
-		
+
 		usleep(100000);
 	}
 

+ 2 - 2
EVSE/Projects/AW-Regular/Apps/Module_FactoryConfig.c

@@ -226,8 +226,8 @@ int main(int argc, char *argv[])
 	// System configuration
 	time_t t = time(NULL);
 	struct tm tm = *localtime(&t);
-	strcpy((char*)SysConfig.ModelName, "AWLU770100W1P0");
-	strcpy((char*)SysConfig.SerialNumber, "D19520001A0");
+	strcpy((char*)SysConfig.ModelName, "AWLU700100W1PH");
+	strcpy((char*)SysConfig.SerialNumber, "D1904A001A0");
 	sprintf((char*)SysConfig.SystemId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
 	sprintf((char*)SysConfig.SystemDateTime, "%d-%d-%d %d:%d:%d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
 	SysConfig.AuthorisationMode = 0;	// 0:PH card	1: OCPP backend		2: PH backend	3: Free Mode

+ 162 - 143
EVSE/Projects/AW-Regular/Apps/Module_InternalComm.c

@@ -264,14 +264,28 @@ int InitComPort()
 	return fd;
 }
 
+void ack_delay(unsigned char cmd)
+{
+	switch(cmd)
+	{
+		case CMD_UPDATE_START:
+		case CMD_UPDATE_END:
+			usleep(300000);
+			break;
+		default:
+			usleep(100000);
+			break;
+	}
+}
+
 int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
 {
 	int len;
-	//sleep(2); //required to make flush work, for some reason
+
 	tcflush(fd,TCIOFLUSH);
 	if(write(fd, cmd, cmd_len) >= cmd_len)
 	{
-		usleep(300000);
+		ack_delay(cmd[3]);
 		len = read(fd, rx, 512);
 	}
 	else
@@ -731,7 +745,7 @@ unsigned char Query_AC_MCU_Status(unsigned char fd, unsigned char targetAddr, Ac
 			Ret_Buf->meter_state = rx[16];
 			Ret_Buf->pp_state = rx[17];
 			Ret_Buf->rating_current = rx[18];
-			Ret_Buf->rotatory_switch = rx[19];
+			Ret_Buf->rotatory_switch = (rx[19] & 0x0F);
 
 			result = PASS;
 		}
@@ -1144,7 +1158,7 @@ unsigned char Config_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Set_Bu
 	tx[6] = ((Set_Buf->year)/1000)+'0';
 	tx[7] = ((Set_Buf->year)/100%10)+'0';
 	tx[8] = ((Set_Buf->year)/10%10)+'0';
-	tx[9] = (Set_Buf->year)%1000+'0';
+	tx[9] = ((Set_Buf->year)%10)+'0';
 	tx[10] = ((Set_Buf->month)/10)+'0';
 	tx[11] = ((Set_Buf->month)%10)+'0';
 	tx[12] = ((Set_Buf->day)/10)+'0';
@@ -1336,7 +1350,7 @@ unsigned char Query_AC_GUN_PLUGIN_TIMES(unsigned char fd, unsigned char targetAd
 	unsigned char chksum = 0x00;
 	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
 
-	if(len > 0)
+	if(len > 6)
 	{
 		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
@@ -1362,7 +1376,7 @@ unsigned char Query_AC_GUN_PLUGIN_TIMES(unsigned char fd, unsigned char targetAd
 unsigned char Config_AC_MaxCurrent_And_CpPwmDuty(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Cp_Pwm_Duty*Set_Buf)
 {
 	unsigned char result = FAIL;
-	unsigned char tx[9];
+	unsigned char tx[8];
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
 
@@ -1370,13 +1384,13 @@ unsigned char Config_AC_MaxCurrent_And_CpPwmDuty(unsigned char fd, unsigned char
 	tx[1] = 0x00;
 	tx[2] = targetAddr;
 	tx[3] = CMD_CONFIG_CURRENT_LINIT;
-	tx[4] = 0x05;
+	tx[4] = 0x01;
 	tx[5] = 0x00;
 	tx[6] = Set_Buf->max_current;
 
 	for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
 			chksum ^= tx[6+idx];
-	tx[8] = chksum;
+	tx[7] = chksum;
 
 	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
 
@@ -1593,76 +1607,6 @@ int main(void)
 	{
 		for(int gun_index=0;gun_index<AC_QUANTITY;gun_index++)
 		{
-			//===============================
-			// Query firmware version
-			//===============================
-			if(ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass != PASS)
-			{
-				if(Query_FW_Ver(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].ver) == PASS)
-				{
-					DEBUG_INFO("MCU-%d get firmware version : %s\r\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
-					memcpy(ShmPrimaryMcuData->version, ShmCharger->gun_info[gun_index].ver.Version_FW, sizeof(ShmPrimaryMcuData->version));
-					ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass = PASS;
-
-					failCount[gun_index] = 0;
-				}
-				else
-				{
-					DEBUG_WARN("MCU-%d get firmware version fail...%d\r\n", gun_index, failCount[gun_index]);
-					if(failCount[gun_index]<1000)
-					{
-						failCount[gun_index]++;
-					}
-				}
-			}
-
-			//===============================
-			// Config primary MCU serial number
-			//===============================
-			if(ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass != PASS)
-			{
-				memcpy(ShmCharger->evseId.serial_number, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmCharger->evseId.serial_number));
-				if(Config_Serial_Number(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
-				{
-					DEBUG_INFO("MCU-%d set serial number : %.12s\r\n",gun_index,ShmCharger->evseId.serial_number);
-					ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass = PASS;
-
-					failCount[gun_index] = 0;
-				}
-				else
-				{
-					DEBUG_WARN("MCU-%d set serial number fail...%d\r\n", gun_index, failCount[gun_index]);
-					if(failCount[gun_index]<1000)
-					{
-						failCount[gun_index]++;
-					}
-				}
-			}
-
-			//===============================
-			// Config primary MCU model name
-			//===============================
-			if(ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass != PASS)
-			{
-				memcpy(ShmCharger->evseId.model_name, ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmCharger->evseId.model_name));
-				if(Config_Model_Name(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
-				{
-					DEBUG_INFO("MCU-%d set model name : %.14s\r\n",gun_index,ShmCharger->evseId.model_name);
-					ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass = PASS;
-
-					failCount[gun_index] = 0;
-				}
-				else
-				{
-					DEBUG_WARN("MCU-%d set model name fail...%d\r\n", gun_index, failCount[gun_index]);
-					if(failCount[gun_index]<1000)
-					{
-						failCount[gun_index]++;
-					}
-				}
-			}
-
-
 			/*
 			 * Polling loop
 			 */
@@ -1671,7 +1615,7 @@ int main(void)
 				/*
 				 * High priority communication
 				 */
-
+				DEBUG_INFO("========== High priority polling ==========\r\n");
 				//===============================
 				// Config primary MCU LED
 				//===============================
@@ -1698,7 +1642,6 @@ int main(void)
 				if(Config_AC_MCU_LEGACY_REQUEST(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1),&ShmCharger->gun_info[gun_index].legacyRequest))
 				{
 					DEBUG_INFO("MCU-%d set relay request : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
-					DEBUG_INFO("========================================\n");
 
 					failCount[gun_index] = 0;
 				}
@@ -1706,7 +1649,9 @@ int main(void)
 				{
 					DEBUG_WARN("MCU-%d set relay request fail...%d\r\n", gun_index, failCount[gun_index]);
 					if(failCount[gun_index]<1000)
+					{
 						failCount[gun_index]++;
+					}
 				}
 
 				//===============================
@@ -1714,20 +1659,17 @@ int main(void)
 				//===============================
 				if(Query_AC_MCU_Status(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuState))
 				{
-					if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus != ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus)
-					{
-						DEBUG_INFO("MCU-%d get Pilot State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
-						DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
-						DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
-						DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
-						DEBUG_INFO("MCU-%d get Locker State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
-						DEBUG_INFO("MCU-%d get Relay State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
-						DEBUG_INFO("MCU-%d get Shutter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
-						DEBUG_INFO("MCU-%d get Meter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
-						DEBUG_INFO("MCU-%d get PP State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
-						DEBUG_INFO("MCU-%d get Rating Current : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
-						DEBUG_INFO("MCU-%d get Rotatory switch : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
-					}
+					DEBUG_INFO("MCU-%d get Pilot State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
+					DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
+					DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
+					DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
+					DEBUG_INFO("MCU-%d get Relay State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
+					DEBUG_INFO("MCU-%d get Rating Current : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
+					DEBUG_INFO("MCU-%d get Rotary switch : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
+					DEBUG_INFO("MCU-%d get Locker State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
+					DEBUG_INFO("MCU-%d get Shutter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
+					DEBUG_INFO("MCU-%d get Meter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
+					DEBUG_INFO("MCU-%d get PP State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
 
 					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState = ShmCharger->gun_info[gun_index].primaryMcuState.cp_state;
 					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotDuty = (ShmCharger->gun_info[gun_index].primaryMcuState.current_limit>51?(unsigned char)((ShmCharger->gun_info[gun_index].primaryMcuState.current_limit/2.5)+64):(unsigned char)(ShmCharger->gun_info[gun_index].primaryMcuState.current_limit/0.6));
@@ -1866,9 +1808,8 @@ int main(void)
 					//================================================
 					// Byte[9]
 					//================================================
-					// Debug print out
-
-					if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus != ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus)
+					// Debug information print out
+					if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode>0))
 					{
 						DEBUG_INFO("MCU-%d get OVP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP);
 						DEBUG_INFO("MCU-%d get UVP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP);
@@ -1908,9 +1849,12 @@ int main(void)
 				//===============================
 				if(Query_Ble_Config(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].bleConfigData))
 				{
-					DEBUG_INFO("MCU-%d get isUserLogin : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isLogin);
-					DEBUG_INFO("MCU-%d get isRequestStartCharger : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart);
-					DEBUG_INFO("MCU-%d get isRequestStopCharger : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop);
+					if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin == ON)
+					{
+						DEBUG_INFO("MCU-%d get isUserLogin : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isLogin);
+						DEBUG_INFO("MCU-%d get isRequestStartCharger : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart);
+						DEBUG_INFO("MCU-%d get isRequestStopCharger : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop);
+					}
 
 					ShmSysConfigAndInfo->SysConfig.Bluetooth.isLogin = ShmCharger->gun_info[gun_index].bleConfigData.isLogin;
 					ShmSysConfigAndInfo->SysConfig.Bluetooth.isRequestStart = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart;
@@ -1949,28 +1893,32 @@ int main(void)
 				//===============================
 				// Config primary MCU reset request
 				//===============================
-				/*
-				if(Config_AC_MCU_RESET_REQUEST(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].mcuResetRequest))
+				if(ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest == ON)
 				{
-					DEBUG_INFO("MCU-%d set MCU reset Request : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest);
+					if(Config_AC_MCU_RESET_REQUEST(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].mcuResetRequest) == PASS)
+					{
+						DEBUG_INFO("MCU-%d set MCU reset Request : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest);
 
-					failCount[gun_index] = 0;
-				}
-				else
-				{
-					DEBUG_WARN("MCU-%d get MCU reset fail...%d\r\n", gun_index, failCount[gun_index]);
-					if(failCount[gun_index]<1000)
+						ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest = OFF;
+
+						failCount[gun_index] = 0;
+					}
+					else
 					{
-						failCount[gun_index]++;
+						DEBUG_WARN("MCU-%d get MCU reset fail...%d\r\n", gun_index, failCount[gun_index]);
+						if(failCount[gun_index]<1000)
+						{
+							failCount[gun_index]++;
+						}
 					}
 				}
-				*/
 			}
 			else
 			{
 				/*
 				 * Normal priority communication
 				 */
+				DEBUG_INFO("========== Normal priority polling ==========\r\n");
 				switch(stepIndex)
 				{
 					case 1:
@@ -2009,7 +1957,9 @@ int main(void)
 						{
 							DEBUG_WARN("MCU-%d get output current fail...%d\r\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
+							{
 								failCount[gun_index]++;
+							}
 						}
 						break;
 					case 5:
@@ -2018,18 +1968,19 @@ int main(void)
 						//===============================
 						if(Query_AC_GUN_PLUGIN_TIMES(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].gunPluginTimes) == PASS)
 						{
-							DEBUG_INFO("MCU-%d get gun plugin times : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
+							DEBUG_INFO("MCU-%d get gun plugin times : %ld\r\n", gun_index, (long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
 
-							ShmSysConfigAndInfo->SysConfig.AcPlugInTimes = (float)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes;
+							ShmSysConfigAndInfo->SysConfig.AcPlugInTimes = ((long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes & 0xFFFF);
 
 							failCount[gun_index] = 0;
 						}
 						else
 						{
-
 							DEBUG_WARN("MCU-%d get gun plugin times fail...%d\r\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
+							{
 								failCount[gun_index]++;
+							}
 						}
 						break;
 					case 7:
@@ -2053,15 +2004,25 @@ int main(void)
 						}
 						break;
 					case 9:
+						//===============================
+						// Config primary set CP PWN duty
+						//===============================
+						if(Config_AC_MaxCurrent_And_CpPwmDuty(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty))
+						{
+							DEBUG_INFO("MCU-%d cp pwn duty : %d\r\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
 
+							failCount[gun_index] = 0;
+						}
+						else
+						{
+							DEBUG_WARN("MCU-%d set cp pwn duty fail...%d\r\n", gun_index, failCount[gun_index]);
+							if(failCount[gun_index]<1000)
+							{
+								failCount[gun_index]++;
+							}
+						}
 						break;
 					case 11:
-
-						break;
-					case 13:
-
-						break;
-					case 15:
 						//===============================
 						// Query RTC
 						//===============================
@@ -2112,7 +2073,7 @@ int main(void)
 									ShmCharger->gun_info[gun_index].rtc.month = tmCSU->tm_mon+1;
 									ShmCharger->gun_info[gun_index].rtc.day = tmCSU->tm_mday;
 									ShmCharger->gun_info[gun_index].rtc.hour = tmCSU->tm_hour;
-									ShmCharger->gun_info[gun_index].rtc.min = tmCSU->tm_hour;
+									ShmCharger->gun_info[gun_index].rtc.min = tmCSU->tm_min;
 									ShmCharger->gun_info[gun_index].rtc.sec = tmCSU->tm_sec;
 									Config_RTC(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].rtc);
 
@@ -2132,10 +2093,12 @@ int main(void)
 						{
 							DEBUG_WARN("MCU-%d get rtc fail...%d\r\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
+							{
 								failCount[gun_index]++;
+							}
 						}
 						break;
-					case 17:
+					case 13:
 						//===============================
 						// Query primary MCU power consumption
 						//===============================
@@ -2149,10 +2112,12 @@ int main(void)
 						{
 							DEBUG_WARN("MCU-%d get power consumption fail...%d\r\n", gun_index, failCount[gun_index]);
 							if(failCount[gun_index]<1000)
+							{
 								failCount[gun_index]++;
+							}
 						}
 						break;
-					case 19:
+					case 15:
 						//===============================
 						// Upgrade MCU
 						//===============================
@@ -2170,35 +2135,90 @@ int main(void)
 							{
 								DEBUG_WARN("MCU-%d upgrade firmware fail...%d\r\n", gun_index, failCount[gun_index]);
 								if(failCount[gun_index]<1000)
+								{
 									failCount[gun_index]++;
+								}
 							}
 
 							sprintf((char*)cmd, "yes|rm %s", ShmCharger->fwUpgradeInfo.location);
 							system((char*)cmd);
 						}
+						break;
+					case 17:
+
+						break;
+					case 19:
+
 						break;
 					case 21:
 						//===============================
-						// Config primary set CP PWN duty
+						// Query firmware version
 						//===============================
-			//			ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = 32;
-			//			if(Config_AC_MaxCurrent_And_CpPwmDuty(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty))
-			//			{
-			//				DEBUG_INFO("MCU-%d cp pwn duty : %d\r\n",gun_index, &ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
-			//			}
-			//			else
-			//			{
-			//				DEBUG_WARN("MCU-%d set cp pwn duty fail...%d\r\n", gun_index, failCount[gun_index]);
-			//				if(failCount[gun_index]<1000)
-			//				{
-			//					failCount[gun_index]++;
-			//				}
-			//			}
-			//
-			//			if(failCount[gun_index]>=1000)
-			//			{
-			//				DEBUG_ERROR("Primary MCU-%d communication fault", gun_index);
-			//			}
+						if(ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass != PASS)
+						{
+							if(Query_FW_Ver(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].ver) == PASS)
+							{
+								DEBUG_INFO("MCU-%d get firmware version : %s\r\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
+								memcpy(ShmPrimaryMcuData->version, ShmCharger->gun_info[gun_index].ver.Version_FW, sizeof(ShmPrimaryMcuData->version));
+								ShmCharger->gun_info[gun_index].mcuFlag.isReadFwVerPass = PASS;
+
+								failCount[gun_index] = 0;
+							}
+							else
+							{
+								DEBUG_WARN("MCU-%d get firmware version fail...%d\r\n", gun_index, failCount[gun_index]);
+								if(failCount[gun_index]<1000)
+								{
+									failCount[gun_index]++;
+								}
+							}
+						}
+
+						//===============================
+						// Config primary MCU serial number
+						//===============================
+						if(ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass != PASS)
+						{
+							memcpy(ShmCharger->evseId.serial_number, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmCharger->evseId.serial_number));
+							if(Config_Serial_Number(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
+							{
+								DEBUG_INFO("MCU-%d set serial number : %.12s\r\n",gun_index,ShmCharger->evseId.serial_number);
+								ShmCharger->gun_info[gun_index].mcuFlag.isSetSerialNumberPass = PASS;
+
+								failCount[gun_index] = 0;
+							}
+							else
+							{
+								DEBUG_WARN("MCU-%d set serial number fail...%d\r\n", gun_index, failCount[gun_index]);
+								if(failCount[gun_index]<1000)
+								{
+									failCount[gun_index]++;
+								}
+							}
+						}
+
+						//===============================
+						// Config primary MCU model name
+						//===============================
+						if(ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass != PASS)
+						{
+							memcpy(ShmCharger->evseId.model_name, ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmCharger->evseId.model_name));
+							if(Config_Model_Name(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->evseId))
+							{
+								DEBUG_INFO("MCU-%d set model name : %.14s\r\n",gun_index,ShmCharger->evseId.model_name);
+								ShmCharger->gun_info[gun_index].mcuFlag.isSetModelNamePass = PASS;
+
+								failCount[gun_index] = 0;
+							}
+							else
+							{
+								DEBUG_WARN("MCU-%d set model name fail...%d\r\n", gun_index, failCount[gun_index]);
+								if(failCount[gun_index]<1000)
+								{
+									failCount[gun_index]++;
+								}
+							}
+						}
 						break;
 					default:
 						stepIndex = 0;
@@ -2228,7 +2248,6 @@ int main(void)
 				}
 			}
 		}
-		usleep(50000);
 	}
 
 	return FAIL;

+ 1 - 3
EVSE/Projects/AW-Regular/Apps/Module_Speaker.c

@@ -83,9 +83,7 @@ int StoreLogMsg(const char *fmt, ...)
 	sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/%04d-%02d_%s_%s_SystemLog",
 			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
 			buffer,
-			tm->tm_year+1900,tm->tm_mon+1,
-			ShmSysConfigAndInfo->SysConfig.ModelName,
-			ShmSysConfigAndInfo->SysConfig.SerialNumber);
+			tm->tm_year+1900,tm->tm_mon+1);
 #ifdef SystemLogMessage
 	system(Buf);
 #endif

+ 252 - 216
EVSE/Projects/AW-Regular/Apps/main.c

@@ -1,6 +1,7 @@
 #include	"define.h"
 #include 	"main.h"
 
+
 //==========================
 // System basic sample constant
 //==========================
@@ -56,6 +57,7 @@ void setSpeaker(unsigned char isOn, unsigned char speaker_mode);
 //==========================
 #define MODULE_EWT		0
 
+int		wtdFd = -1;
 int 	rfidFd = -1;
 char* 	rfidPortName = "/dev/ttyS2";
 RFID 	rfid;
@@ -493,10 +495,26 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
 	return result;
 }
 
-
 //======================================================
 // Peripheral initial
 //======================================================
+int InitWatchDog()
+{
+	int fd;
+
+	system("/usr/bin/fuser -k /dev/watchdog");
+	sleep(1);
+	system("echo V > /dev/watchdog");
+	sleep(1);
+	fd=open("/dev/watchdog", O_RDWR);
+	if(fd<=0)
+	{
+		DEBUG_ERROR("System watch dog initial fail.\r\n");
+	}
+
+	return fd;
+}
+
 void InitGPIO()
 {
 	/*****************0~3, 4 bank, bank x 32+ num*********************/
@@ -644,7 +662,6 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 		//================================================
 		if(ChkSum!=ChkSumOrg)
 		{
-
 			DEBUG_WARN("backup SysConfigData checksum NG, read Factory default\r\n");
 
 			fd = open("/dev/mtdblock12", O_RDWR);
@@ -732,6 +749,7 @@ void InitEthernet()
 		sprintf(tmpbuf,"route add default gw %s eth0 ",
 		ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
 		system(tmpbuf);
+		system("/sbin/ifconfig eth0:1 192.168.201.201 netmask 255.255.255.248 up");
 	}
 
 	if(isInterfaceUp("eth1")==PASS)
@@ -792,6 +810,7 @@ int SpawnTask()
 	system ("pkill Module_AlarmDetect");
 	system ("pkill Module_InternalComm");
 	system ("pkill Module_Speaker");
+	system ("pkill Module_ProduceUtils");
 
 	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
 	{
@@ -807,9 +826,10 @@ int SpawnTask()
 	{
 		system("/root/OcppBackend &");
 	}
-	system("/root/Module_AlarmDetect &");
-	system("/root/Module_InternalComm &");
+	system ("/root/Module_AlarmDetect &");
+	system ("/root/Module_InternalComm &");
 	system ("/root/Module_Speaker &");
+	system ("/root/Module_ProduceUtils &");
 
 	return PASS;
 }
@@ -887,9 +907,14 @@ int Initialization()
 
 	InitEthernet();
 
+	if(DB_Open(localDb) != PASS)
+		result = FAIL;
+
 	rfidFd = InitRfidPort();
 
-	if((DB_Open(localDb) != PASS) || (rfidFd < 0))
+	wtdFd = InitWatchDog();
+
+	if((wtdFd < 0) || (rfidFd < 0))
 		result = FAIL;
 
 	if(result == PASS)
@@ -945,6 +970,12 @@ char* getSystemModeName(unsigned char mode)
 		case SYS_MODE_DEBUG:
 			result = "debug";
 			break;
+		case SYS_MODE_UPDATE:
+			result = "upgrade";
+			break;
+		default:
+			result = "unknown";
+			break;
 	}
 
 	return result;
@@ -1006,7 +1037,7 @@ void get_firmware_version(unsigned char gun_index)
 	}
 
 	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.04.40.0007.PH");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.10.40.0007.PH");
 
 	// Get MCU firmware version
 	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
@@ -1018,6 +1049,7 @@ void get_firmware_version(unsigned char gun_index)
 	DEBUG_INFO("CSU MCU-%2d firmware version: %s\r\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
 }
 
+
 //===============================================
 // Upgrade firmware
 //===============================================
@@ -1243,61 +1275,6 @@ int GetFaultValue()
 	return result;
 }
 
-//===============================================
-// Authorizing Response Status
-//===============================================
-int isAuthorizedPass()
-{
-	int result = FAIL;
-
-	char tmp[16] = "";
-	memset(tmp, 0, ARRAY_SIZE(tmp));
-
-	for(int index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);index++)
-	{
-		sprintf(tmp + (index - 1) * 2, "%02X",ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
-	}
-	sprintf(tmp, "%s",	ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
-
-	DEBUG_INFO("Authorize Response Id TagInfo: %s\r\n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
-
-	if(strstr(tmp, "Accepted") != 0)
-	{
-		result = PASS;
-	}
-	else
-	{}
-
-	return result;
-}
-
-//===============================================
-// BootNotification Response Status
-//===============================================
-int isBootNotificationSignature()
-{
-	int result = FAIL;
-
-	char tmp[16] = "";
-	memset(tmp, 0, ARRAY_SIZE(tmp));
-
-	for(int index = 0; index < strlen((char *)ShmOCPP16Data->BootNotification.ResponseStatus);index++)
-	{
-		sprintf(tmp + (index - 1) * 2, "%02X",ShmOCPP16Data->BootNotification.ResponseStatus[index]);
-	}
-	sprintf(tmp, "%s",ShmOCPP16Data->BootNotification.ResponseStatus);
-
-	DEBUG_INFO("BootNotification Response Status: %s\r\n", ShmOCPP16Data->BootNotification.ResponseStatus);
-	if(strstr(tmp, "Accepted") != 0)
-	{
-		result = PASS;
-	}
-	else
-	{}
-
-	return result;
-}
-
 //===============================================
 // Set led motion
 //===============================================
@@ -1363,7 +1340,7 @@ void setLedMotion(unsigned char gun_index,unsigned char led_mode)
 }
 
 //===============================================
-// Relay on/off request
+// Relay on/off request set
 //===============================================
 void setRelay(unsigned char gun_index,unsigned char isOn)
 {
@@ -1385,6 +1362,14 @@ void setRelay(unsigned char gun_index,unsigned char isOn)
 	}
 }
 
+//===============================================
+// Relay on/off request get
+//===============================================
+int getRelay(unsigned char gun_index)
+{
+	return ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest;
+}
+
 //===============================================
 // Set speaker on/off request
 //===============================================
@@ -1481,15 +1466,21 @@ int isReservationExpired(unsigned char gun_index)
 
 	if(sscanf((char*)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year, &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour, &expiredDate.tm_min, &expiredDate.tm_sec) == 6)
 	{
+		expiredDate.tm_year -= 1900;
+		expiredDate.tm_mon -= 1;
 		expiredTime.time = mktime(&expiredDate);
 
-		if(DiffTimebWithNow(expiredTime)>0)
+		if(DiffTimebWithNow(expiredTime) >= 0)
 		{
 			result = YES;
 		}
 	}
 	else
-		DEBUG_WARN("Expired date parsing error\r\n");
+	{
+		DEBUG_WARN("Expired date parsing error...\r\n");
+		DEBUG_INFO("Date expired...\r\n");
+		result = YES;
+	}
 
 	return result;
 }
@@ -1538,6 +1529,8 @@ int main(void)
 	for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
 	{
 		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus = 0xff;
+		ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch = 0xff;
+		ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest = ON;
 	}
 
 	// Main loop
@@ -1575,7 +1568,7 @@ int main(void)
 			{
 				ShmCharger->isUpdateSuccess = FAIL;
 				for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
-					setChargerMode(gun_index, SYS_MODE_MAINTAIN);
+					setChargerMode(gun_index, SYS_MODE_UPDATE);
 			}
 		}
 
@@ -1620,6 +1613,9 @@ int main(void)
 		//==========================================
 		for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
 		{
+			// Synchronize current rating value from MCU
+			ShmSysConfigAndInfo->SysConfig.RatingCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
+
 			// Assign connector location index for OCPP
 			ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].Index = gun_index;
 
@@ -1714,7 +1710,10 @@ int main(void)
 						DEBUG_INFO("Wifi SSID: %s\r\n",  ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
 						DEBUG_INFO("Wifi password: %s\r\n",  ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
 
-						setChargerMode(gun_index, SYS_MODE_IDLE);
+						if(ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch == 0)
+							setChargerMode(gun_index, SYS_MODE_DEBUG);
+						else
+							setChargerMode(gun_index, SYS_MODE_IDLE);
 					}
 
 					break;
@@ -1729,9 +1728,9 @@ int main(void)
 						ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = OFF;
 						ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = OFF;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode = 0x00;
-						ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
 						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = 0;
 						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
+						ShmCharger->gun_info[gun_index].targetCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
 					}
 
 					if(((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)) ||
@@ -1741,7 +1740,6 @@ int main(void)
 					{
 						// Clean User id & Card Number
 						memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
-						memset(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].CardNumber, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].CardNumber));
 
 						if((ShmCharger->gun_info[gun_index].rfidReq == ON))
 						{
@@ -1788,10 +1786,8 @@ int main(void)
 										break;
 								}
 							}
-							memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].CardNumber, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
 
 							DEBUG_INFO("Start request User Id : %s\r\n", ShmSysConfigAndInfo->SysConfig.UserId);
-							DEBUG_INFO("Card number : %s\r\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].CardNumber);
 						}
 						else if(ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq)
 						{
@@ -1864,7 +1860,7 @@ int main(void)
 
 					if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH)
 					{
-						 // Authorization timeout process.
+						// Authorization timeout process.
 						ShmCharger->gun_info[gun_index].rfidReq = OFF;
 						setChargerMode(gun_index, SYS_MODE_IDLE);
 						DEBUG_WARN("Authorize timeout!\r\n");
@@ -1917,6 +1913,12 @@ int main(void)
 						setRelay(gun_index, ON);
 					}
 
+					// 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]);
+					}
+
 					if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > TIMEOUT_SPEC_HANDSHAKING)
 					{
 						setLedMotion(gun_index, LED_ACTION_HANDSHAKE_FAIL);
@@ -1959,144 +1961,174 @@ int main(void)
 					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState != CP_STATE_C) ||
 					   ShmOCPP16Data->MsMsg.bits.ResetReq)
 					{
-						// If RFID SN different with start user, it need to authorize ID
-						if((ShmCharger->gun_info[gun_index].rfidReq == ON) && !isMatchStartUser(gun_index))
-						{
-							ShmCharger->gun_info[gun_index].rfidReq = OFF;
-							if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH)
-							{
-								// 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);
-
-								if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID)
-								{
-									switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
-									{
-										case AUTH_MODE_BACKEND_OCPP:
-											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_FREE:
-										default:
-											break;
-									}
-								}
-							}
-							else
-							{
-								if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
-								  (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
-								  !ShmOCPP16Data->OcppConnStatus)
-								{
-									if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) ||
-									   (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
-									   (!ShmOCPP16Data->OcppConnStatus&&(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)))
-									{
-										ShmCharger->gun_info[gun_index].isAuthPassEnd = ON;
-										setChargerMode(gun_index, SYS_MODE_TERMINATING);
-									}
-
-									ShmCharger->gun_info[gun_index].rfidReq = OFF;
-									ShmOCPP16Data->SpMsg.bits.AuthorizeConf = OFF;
-								}
-							}
-						}
-						else
-						{
-							setChargerMode(gun_index, SYS_MODE_TERMINATING);
-						}
+						setChargerMode(gun_index, SYS_MODE_TERMINATING);
 					}
 					else
 					{
-						/*
-						 * 	TODO:
-						 * 	1. Update charging cycle information.
-						 * 	2. CP PWM duty dynamic control logic.
-						 */
-						setRelay(gun_index,ON);
 						setLedMotion(gun_index,LED_ACTION_CHARGING);
 						ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ((float)ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0) - ShmOCPP16Data->StartTransaction[gun_index].MeterStart;
 						ftime(&endChargingTime[gun_index]);
-						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
 						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmOCPP16Data->StartTransaction[gun_index].MeterStart)/100.0;
 						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].OutputEnergy = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmOCPP16Data->StartTransaction[gun_index].MeterStart)/100.0;
-						// Charging profile
 
+						/*
+						 * TODO:
+						 * 	1. Query target current from charging profile
+						 */
+						// Checking charging profile target current
+
+						// Determine max charging current to MCU
+						if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
+						{
+							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
+						{
+							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);
+						}
+
+						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);
+
+						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 >= (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy/10.0)))
+						{
+							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, (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy/10.0));
+						}
+						else
+						{
+							setRelay(gun_index, ON);
+						}
 					}
 
 					break;
 				case SYS_MODE_TERMINATING:
 					if(isModeChange(gun_index))
 					{
-						setLedMotion(gun_index,LED_ACTION_STOP);
 						if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration != 0)
 						{
-							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
+						}
+
+						setLedMotion(gun_index, LED_ACTION_STOP);
+						setRelay(gun_index, OFF);
+						getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
+					}
+
+					// 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);
+
+							if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID)
+							{
+								switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
+								{
+									case AUTH_MODE_BACKEND_OCPP:
+										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_FREE:
+									default:
+										break;
+								}
+							}
+						}
+						else
+						{
+							if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
+							  (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
+							  !ShmOCPP16Data->OcppConnStatus)
+							{
+								if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) ||
+								   (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
+								   (!ShmOCPP16Data->OcppConnStatus&&(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)))
+								{
+									ShmCharger->gun_info[gun_index].isAuthPassEnd = ON;
+								}
+								else
+								{
+									ShmCharger->gun_info[gun_index].rfidReq = OFF;
+								}
+
+								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) ||
@@ -2104,14 +2136,11 @@ int main(void)
 					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A) ||
 					   ShmOCPP16Data->MsMsg.bits.ResetReq)
 					{
-						/*
-						 * 	TODO:
-						 * 	1. Record charging history.
-						 */
-						if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON)
-						{
-							setSpeaker(ON,SPEAKER_SHORT);
+						setSpeaker(ON,SPEAKER_SHORT);
+						sleep(5);
 
+						if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
+						{
 							if(ShmOCPP16Data->MsMsg.bits.ResetReq)
 							{
 								if(strcmp((char*)ShmOCPP16Data->Reset.Type, "Hard")==0)
@@ -2140,13 +2169,6 @@ int main(void)
 							ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmCharger->gun_info[gun_index].powerConsumption.power_consumption;
 							ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = ON;
 
-							getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
-						}
-
-						setRelay(gun_index,OFF);
-
-						if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
-						{
 							ShmCharger->gun_info[gun_index].rfidReq = OFF;
 							ShmCharger->gun_info[gun_index].isAuthPassEnd = OFF;
 							ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;
@@ -2158,13 +2180,16 @@ int main(void)
 					}
 					else
 					{
-						 if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C))
-						 {
-							 setChargerMode(gun_index, SYS_MODE_CHARGING);
-						 }
+						if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C) &&
+						   (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop != ON)  &&
+						   (ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq != ON) &&
+						   !ShmOCPP16Data->MsMsg.bits.ResetReq &&
+						   !((ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60))) &&
+						   !((ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy/10.0))))
+						{
+							setChargerMode(gun_index, SYS_MODE_CHARGING);
+						}
 					}
-
-					setLedMotion(gun_index,LED_ACTION_STOP);
 					break;
 				case SYS_MODE_ALARM:
 					if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode == 0))
@@ -2204,6 +2229,13 @@ int main(void)
 						setLedMotion(gun_index,LED_ACTION_MAINTAIN);
 					}
 
+					break;
+				case SYS_MODE_UPDATE:
+					if(isModeChange(gun_index))
+					{
+
+					}
+
 					//======================================
 					// Check local upgrade firmware request
 					//======================================
@@ -2286,8 +2318,14 @@ int main(void)
 						setLedMotion(gun_index,LED_ACTION_MAINTAIN);
 					}
 
-					if(isReservationExpired(gun_index) || ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq)
+					if(isReservationExpired(gun_index))
+					{
+						DEBUG_INFO("Reservation: Time's up...\r\n");
+						setChargerMode(gun_index, SYS_MODE_IDLE);
+					}
+					else if(ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq)
 					{
+						DEBUG_INFO("Reservation: Cancel reservation...\r\n");
 						setChargerMode(gun_index, SYS_MODE_IDLE);
 
 						ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = OFF;
@@ -2308,17 +2346,15 @@ int main(void)
 				case SYS_MODE_DEBUG:
 					if(isModeChange(gun_index))
 					{
-						/*
-						 * TODO:
-						 * 1. LED control depend on relay status
-						 */
+						setLedMotion(gun_index,LED_ACTION_DEBUG);
 					}
-
-					setLedMotion(gun_index,LED_ACTION_DEBUG);
 					break;
 			}
 		}
 
+		// System watch dog reset
+		write(wtdFd, "a", 1);
+
 		usleep(50000);
 	}
 

+ 14 - 10
EVSE/Projects/AW-Regular/Apps/main.h

@@ -41,6 +41,7 @@
 #include	<stdint.h>
 #include	<sqlite3.h>
 
+
 //===================================
 //	Define CP State constant
 //===================================
@@ -322,16 +323,18 @@ typedef struct SYSTEM_ALARM_CODE
 
 typedef struct OTHER_ALARM_CODE
 {
-	unsigned char isMcuSelfTest:1;
-	unsigned char isCurrentShort:1;
-	unsigned char isLeakageModule:1;
-	unsigned char isShutterFail:1;
-	unsigned char isLockerFault:1;
-	unsigned char isRotatorySwitch:1;
-	unsigned char isPowerDrop:1;
-	unsigned char isOverCurrent:1;
-	unsigned char isHandshakingTimeOut:1;
-	unsigned char HandShakingAlarmRequest:1;
+	unsigned long isMcuSelfTest:1;
+	unsigned long isCurrentShort:1;
+	unsigned long isLeakageModule:1;
+	unsigned long isShutterFail:1;
+	unsigned long isLockerFault:1;
+	unsigned long isRotatorySwitch:1;
+	unsigned long isPowerDrop:1;
+	unsigned long isOverCurrent:1;
+	unsigned long isHandshakingTimeOut:1;
+	unsigned long HandShakingAlarmRequest:1;
+	unsigned long isDcLeakage:1;
+	unsigned long isACLeakage:1;
 }Other_Alarm_Code;
 
 typedef struct PILOT_VOLTAGE
@@ -380,6 +383,7 @@ typedef struct GUN_INFO
 	Pilot_Voltage									PilotVoltage;
 	Gun_Plugin_Times								gunPluginTimes;
 	Mcu_Reset_Request								mcuResetRequest;
+	uint16_t										targetCurrent;
 	uint8_t											isAuthPassEnd:1;
 	uint8_t											rfidReq:1;
 }Gun_Info;

BIN
EVSE/Projects/AW-Regular/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/AW-Regular/Images/ramdisk.gz


BIN
EVSE/rootfs/root/Module_4g


BIN
EVSE/rootfs/root/Module_ProduceUtils


BIN
EVSE/rootfs/root/Module_Wifi


BIN
EVSE/rootfs/root/OcppBackend


BIN
EVSE/rootfs/root/WebService


BIN
EVSE/rootfs/root/logPackTools