Pārlūkot izejas kodu

2021-05-03 / Eason Yang
Action
1. Added : Debug print for checking parentIdTag content. ocpp_get_auth_result().
2. Improve : If use different RFID card between start charging and stop charging. The system should fill in correct idTag information to the central system. checkStopReason().

File
1. main.c
Action 1
Action 2

Version : V0.68.XX.XXXX.XX

8009 3 gadi atpakaļ
vecāks
revīzija
228182bf5a
1 mainītis faili ar 45 papildinājumiem un 8 dzēšanām
  1. 45 8
      EVSE/Projects/AW-ChargeLab/Apps/main.c

+ 45 - 8
EVSE/Projects/AW-ChargeLab/Apps/main.c

@@ -574,21 +574,36 @@ uint8_t ocpp_get_auth_result(uint8_t gun_index)
 		case SYS_MODE_TERMINATING:
 			if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 			{
+				DEBUG_INFO("==========================================\n");
+				DEBUG_INFO("=== OCPP GETTING AUTHORIZE RESULT 1.6 ====\n");
+				DEBUG_INFO("==========================================\n");
+				DEBUG_INFO("Authorize.ResponseIdTagInfo.ParentIdTag : %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
+				DEBUG_INFO("StartTransaction[%d].ResponseIdTagInfo.ParentIdTag : %s \n", gun_index ,ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
+
 				if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) &&
 				   (strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (char*)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag)==0))
 					result = PASS;
 			}
 			else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 			{
+				DEBUG_INFO("==========================================\n");
+				DEBUG_INFO("=== OCPP GETTING AUTHORIZE RESULT 2.0 ====\n");
+				DEBUG_INFO("==========================================\n");
+				DEBUG_INFO("Authorize.Response_idTokenInfo.groupIdToken.idToken : %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken);
+				DEBUG_INFO("TransactionEvent[%d].Response_idTokenInfo.groupIdToken.idToken : %s \n", gun_index, ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.groupIdToken.idToken);
+
 				if((strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Accepted")==0) &&
 				   (strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.groupIdToken.idToken)==0))
 					result = PASS;
 			}
 
 			break;
-
+		default:
+			break;
 	}
 
+	DEBUG_INFO("Authorize result : %s \n", ((result == PASS)?"Pass":"Fail"));
+
 	return result;
 }
 
@@ -711,7 +726,7 @@ uint8_t ocpp_get_starttransaction_result(uint8_t gun_index)
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		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) ||
@@ -2903,7 +2918,7 @@ void checkTask()
 				ShmOCPP16Data->procDogTime =  time((time_t*)NULL);
 				system("pkill OcppBackend");
 			}
-			
+
 			if(system("pidof -s OcppBackend > /dev/null") != 0)
 			{
 				DEBUG_INFO("OcppBackend not running, restart it.\n");
@@ -2918,7 +2933,7 @@ void checkTask()
 				ShmOCPP20Data->procDogTime =  time((time_t*)NULL);
 				system("pkill OcppBackend20");
 			}
-			
+
 			if(system("pidof -s OcppBackend20 > /dev/null") != 0)
 			{
 				DEBUG_INFO("OcppBackend20 not running, restart it.\n");
@@ -3266,6 +3281,7 @@ void checkStopReason(uint8_t gun_index)
 {
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
+		memset(ShmOCPP16Data->StopTransaction[gun_index].IdTag, 0x00, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].IdTag));
 		if(!ocpp_get_starttransaction_result(gun_index))
 		{
 			sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "DeAuthorized");
@@ -3288,6 +3304,17 @@ void checkStopReason(uint8_t gun_index)
 		else if(ShmCharger->gun_info[gun_index].rfidReq || ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop)
 		{
 			sprintf((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
+
+			if(!isMatchStartUser(gun_index))
+			{
+				memcpy((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].IdTag));
+			}
+			else
+			{
+				memcpy((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].IdTag));
+			}
+
+			DEBUG_INFO("Gun-%d [ IdTag ] : %s \n", gun_index, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
 		}
 		else if(ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)
 		{
@@ -3303,12 +3330,12 @@ void checkStopReason(uint8_t gun_index)
 		}
 		DEBUG_INFO("Gun-%d : StopReason [ %s ]...\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.0);
 		ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = ON;
 	}
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
+		memset(ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
 		if(!ocpp_get_starttransaction_result(gun_index))
 		{
 			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "DeAuthorized");
@@ -3335,6 +3362,17 @@ void checkStopReason(uint8_t gun_index)
 		else if(ShmCharger->gun_info[gun_index].rfidReq || ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop)
 		{
 			sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "Local");
+
+			if(!isMatchStartUser(gun_index))
+			{
+				memcpy((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, (char*)ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
+			}
+			else
+			{
+				memcpy((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId));
+			}
+
+			DEBUG_INFO("Gun-%d [ idToken ] : %s \n", gun_index, ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken);
 		}
 		else if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT))
 		{
@@ -3354,7 +3392,6 @@ void checkStopReason(uint8_t gun_index)
 		}
 		DEBUG_INFO("Gun-%d : StopReason [ %s ]...\n.", gun_index, ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason);
 
-		memcpy((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId));
 		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0);
 		ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
 	}
@@ -3656,7 +3693,7 @@ int main(void)
 						// Set max current to rating current
 						ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
 						
-						// Default Ethernet / Wifi / 4G to 1:disconnected 
+						// Default Ethernet / Wifi / 4G to 1:disconnected
 						ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = ON;
 						ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi = ON;
 						ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi = ON;
@@ -4574,7 +4611,7 @@ int main(void)
 								sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
 								ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
 								DEBUG_WARN("Firmware upgrade fail.\n");
-								
+
 								sleep(5);
 								system("rm -rvf /mnt/* ");
 								close(wtdFd);