Browse Source

2021-04-08 / Eason Yang
Action
1. Added : chechStopReason() more stop reasons for ocpp 1.6 and ocpp 2.0
2. Added : checkReset() when the system received reset command from central system, the system mode needs to change to Booting mode.
3. Rename : Version
4. Replace : checkStopReason() replace into Terminating mode. If relay is off, the systen should send stop reason to central system

File
1. main.c
Action 1
Action 2
Action 3
Action 4

Version : V0.68.XX.XXXX.XX

8009 4 years ago
parent
commit
fa550216a9
1 changed files with 66 additions and 33 deletions
  1. 66 33
      EVSE/Projects/AW-Regular/Apps/main.c

+ 66 - 33
EVSE/Projects/AW-Regular/Apps/main.c

@@ -677,22 +677,28 @@ uint8_t ocpp_get_starttransaction_result(uint8_t gun_index)
 
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
-		if((strcmp((char*)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Blocked")==0) ||
-		   (strcmp((char*)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Expired")==0) ||
-		   (strcmp((char*)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid")==0))
-			result = NO;
+		if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE"))
+		{
+			if((strcmp((char*)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Blocked")==0) ||
+			   (strcmp((char*)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Expired")==0) ||
+			   (strcmp((char*)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid")==0))
+				result = NO;
+		}
 	}
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
-		if((strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "Blocked")==0) ||
-		   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "Expired")==0) ||
-		   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "Invalid")==0) ||
-		   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "NoCredit")==0) ||
-		   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "NotAllowedTypeEVSE")==0) ||
-		   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "NotAtThisLocation")==0) ||
-		   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "NotAtThisTime")==0) ||
-		   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "Unknown")==0))
-			result = NO;
+		if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE"))
+		{			
+			if((strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "Blocked")==0) ||
+			   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "Expired")==0) ||
+			   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "Invalid")==0) ||
+			   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "NoCredit")==0) ||
+			   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "NotAllowedTypeEVSE")==0) ||
+			   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "NotAtThisLocation")==0) ||
+			   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "NotAtThisTime")==0) ||
+			   (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, "Unknown")==0))
+				result = NO;
+		}
 	}
 
 	return result;
@@ -1690,7 +1696,7 @@ void InitEthernet()
 		{
 			if(isRouteFail())
 			{
-				DEBUG_ERROR("eth0 not in route, restart eth0.\n");
+				//DEBUG_ERROR("eth0 not in route, restart eth0.\n");
 				system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
 
 				if((ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient==0))
@@ -2050,7 +2056,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, "V0.67.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.68.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -2978,6 +2984,8 @@ void checkReset()
 				ShmOCPP16Data->MsMsg.bits.ResetConf = ON;
 
 				DEBUG_INFO("%s reset request by OCPP.\n", ShmOCPP16Data->Reset.Type);
+				for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
+					setChargerMode(gun_index, SYS_MODE_BOOTING)
 				if(strcmp((char*)ShmOCPP16Data->Reset.Type, "Hard") == 0)
 				{
 					system("sync");
@@ -3007,6 +3015,8 @@ void checkReset()
 				ShmOCPP20Data->MsMsg.bits.ResetConf = ON;
 
 				DEBUG_INFO("%s reset request by OCPP.\n", ShmOCPP20Data->Reset.type);
+				for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
+					setChargerMode(gun_index, SYS_MODE_BOOTING)
 				if(strcmp((char*)ShmOCPP20Data->Reset.type, "Immediate") == 0)
 				{
 
@@ -3233,24 +3243,32 @@ void checkStopReason(uint8_t gun_index)
 {
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
-		if(ShmOCPP16Data->MsMsg.bits.ResetReq)
+		if(!ocpp_get_starttransaction_result(gun_index))
+		{
+			sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "DeAuthorized");
+		}
+		else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)
+		{
+			sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EmergencyStop");
+		}
+		else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
+		{
+			sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+		}
+		else 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)
+		else if(ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)
 		{
-			sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+			sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Remote");
 		}
 		else if(ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor == ON)
 		{
@@ -3268,24 +3286,40 @@ void checkStopReason(uint8_t gun_index)
 	}
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
-		if(ShmOCPP20Data->MsMsg.bits.ResetReq)
+		if(!ocpp_get_starttransaction_result(gun_index))
 		{
-			if(strcmp((char*)ShmOCPP20Data->Reset.type, "Hard")==0)
-				sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "HardReset");
-			else
-				sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "SoftReset");
+			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "DeAuthorized");
 		}
-		else if(ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq)
+		else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)
 		{
-			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "Remote");
+			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "EmergencyStop");
+		}
+		else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
+		{
+			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "EVDisconnected");
+		}
+		else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)
+		{
+			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "GroundFault");
+		}
+		else if(ShmOCPP20Data->MsMsg.bits.ResetReq)
+		{
+			if(strcmp((char*)ShmOCPP20Data->Reset.type, "Immediate")==0)
+				sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "ImmediateReset");
+			else
+				sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "OnIdle");
 		}
 		else if(ShmCharger->gun_info[gun_index].rfidReq || ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop)
 		{
 			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "Local");
 		}
-		else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
+		else if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT))
 		{
-			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "EVDisconnected");
+			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "OvercurrentFault");
+		}
+		else if(ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq)
+		{
+			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "Remote");
 		}
 		else if(ShmCharger->gun_info[ShmOCPP20Data->UnlockConnector[gun_index].connectorId-1].isUnlockerConnetor == ON)
 		{
@@ -4236,6 +4270,7 @@ int main(void)
 						// If relay is off, the system should change to complete mode
 						if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
 						{
+							checkStopReason(gun_index);
 							setChargerMode(gun_index, SYS_MODE_COMPLETE);
 						}
 					}
@@ -4398,8 +4433,6 @@ int main(void)
 						sleep(3);
 					}
 
-					checkStopReason(gun_index);
-
 					ShmCharger->gun_info[gun_index].rfidReq = OFF;
 					ShmCharger->gun_info[gun_index].isAuthPassEnd = OFF;
 					ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;