Эх сурвалжийг харах

[Improve][Add][AW-CCS][main.c]
2022-08-18 / EASON YANG
Action:
1. Improve: Start charging session if parentIdtag samse as reservation request.
2. Added: Support OCPP 1.6 singnature update firmware function.

File:
1. main.c
Action 1
Action 2

FIRMWARE VERSION: B0.62.XX.XXXX.PX

8009 2 жил өмнө
parent
commit
de2a480bf9

+ 77 - 35
EVSE/Projects/AW-CCS/Apps/main.c

@@ -557,7 +557,7 @@ uint8_t ocpp_get_update_firmware_req()
 
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
-		result = ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq;
+		result = ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq || ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq;
 	}
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
@@ -717,6 +717,9 @@ void ocpp_set_auth_req(uint8_t status, ...)
 {
 	va_list args;
 
+	if(status == ON)
+		ocpp_set_auth_conf(OFF);
+
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->SpMsg.bits.AuthorizeReq != status)
@@ -807,49 +810,46 @@ uint8_t ocpp_get_auth_result(uint8_t isValidParent, ...)
 			case SYS_MODE_AUTHORIZING:
 				if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 				{
-					if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0))
+					if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId == -1) && (strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0)) ||
+						((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId != -1) && ((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) && (strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (char*)ShmOCPP16Data->ReserveNow[gun_index].ParentIdTag)==0))))
 						result = PASS;
 				}
 				else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 				{
-					if((strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Accepted")==0) &&
-					   (strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value) != 0))
+					if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId == -1) && ((strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Accepted")==0) && (strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value) != 0))) ||
+					   ((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId != -1) && ((strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Accepted")==0) && (strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char*)ShmOCPP20Data->ReserveNow[gun_index].groupIdToken.idToken)==0))))
 						result = PASS;
 				}
-
 				break;
 			case SYS_MODE_CHARGING:
 			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) ||
 						(strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value) == 0)))
 						result = PASS;
 				}
-
+				break;
+			case SYS_MODE_RESERVATION:
+				if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+				{
+					if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) && 
+					   (strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (char*)ShmOCPP16Data->ReserveNow[gun_index].ParentIdTag)==0))
+						result = PASS;
+				}
+				else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+				{
+					if((strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Accepted")==0) && 
+					   (strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char*)ShmOCPP20Data->ReserveNow[gun_index].groupIdToken.idToken)==0))
+						result = PASS;
+				}
 				break;
 			default:
 				break;
@@ -4893,7 +4893,7 @@ void checkRemoteUpgradeStatus()
 			ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = OFF;
 			ShmCharger->isUpdateSuccess = NO;
 		}
-		else if(strcmp((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded")==0)
+		else if((strcmp((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded")==0))
 		{
 			DEBUG_INFO("Firmware remote upgrading...\n");
 			sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
@@ -4920,6 +4920,32 @@ void checkRemoteUpgradeStatus()
 				DEBUG_INFO("Remote update unsuccess...\n");
 			}
 		}
+		else if((strcmp((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified")==0))
+		{
+			DEBUG_INFO("Signature firmware remote upgrading...\n");
+			ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
+			sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Installing");
+			sleep(1);
+			ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = ON;
+			ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = OFF;
+
+			if(upgrade_check() == PASS)
+			{
+				if(ShmStatusCodeData->InfoCode.InfoEvents.bits.CsuFimrwareUpdateFail == ON)
+					ShmStatusCodeData->InfoCode.InfoEvents.bits.CsuFimrwareUpdateFail = OFF;
+
+				ShmCharger->isUpdateSuccess = YES;
+				DEBUG_INFO("Remote update success.\n");
+			}
+			else
+			{
+				if(ShmStatusCodeData->InfoCode.InfoEvents.bits.CsuFimrwareUpdateFail == OFF)
+					ShmStatusCodeData->InfoCode.InfoEvents.bits.CsuFimrwareUpdateFail = ON;
+
+				ShmCharger->isUpdateSuccess = NO;
+				DEBUG_INFO("Remote update fail.\n");
+			}
+		}
 		else
 		{}
 	}
@@ -4931,7 +4957,7 @@ void checkRemoteUpgradeStatus()
 			ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = OFF;
 			ShmCharger->isUpdateSuccess = NO;
 		}
-		else if(strcmp((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "Downloaded")==0)
+		else if((strcmp((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "Downloaded")==0))
 		{
 			DEBUG_INFO("Firmware remote upgrading...\n");
 			sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
@@ -5084,7 +5110,6 @@ void checkRfidAuthrize()
 					memcpy(lastIdtag, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
 					memcpy(ShmSysConfigAndInfo->SysConfig.UserId, bufferRFID, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
 					refreshStartTimer(&startTime[0][TMR_IDX_AUTH]);
-					ocpp_set_auth_conf(OFF);
 					ocpp_set_auth_req(ON, "ISO14443");
 					setLedMotion(0,LED_ACTION_AUTHED);
 					ShmCharger->isAuthrizing = TRUE;
@@ -6111,7 +6136,7 @@ int main(void)
 								{
 									if(ocpp_get_auth_conf())
 									{
-										if(ocpp_get_auth_result(gun_index))
+										if(ocpp_get_auth_result(YES, gun_index))
 										{
 											memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
 											DEBUG_INFO("[START_METHOD_BACKEND] StartUserId : %s \n",ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId);
@@ -6141,7 +6166,11 @@ int main(void)
 											setSpeaker(ON,SPEAKER_INTERVAL_3COUNT);
 											setLedMotion(gun_index,LED_ACTION_RFID_FAIL);
 											sleep(3);
-											setChargerMode(gun_index, SYS_MODE_IDLE);
+
+											if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId == -1)
+												setChargerMode(gun_index, SYS_MODE_IDLE);
+											else
+												setChargerMode(gun_index, SYS_MODE_RESERVATION);
 										}
 
 										ocpp_set_auth_conf(OFF);
@@ -6172,7 +6201,7 @@ int main(void)
 								   (!ocpp_get_connection_status() && ((ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE) || (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_NOCHARGE))) ||
 								   (!ocpp_get_connection_status() && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_LOCALLIST) && (getDiffSecNow(startTime[0][TMR_IDX_AUTH]) > 2)))
 								{
-									if(ocpp_get_auth_result(gun_index) ||
+									if(ocpp_get_auth_result(YES, gun_index) ||
 									  (!ocpp_get_connection_status() && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)) ||
 									  (!ocpp_get_connection_status() && (isValidLocalWhiteCard() == PASS) && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_LOCALLIST)))
 									{
@@ -6646,7 +6675,6 @@ int main(void)
 						refreshStartTimer(&startTime[gun_index][TMR_IDX_REFRESH_CHARGING_INFO]);
 						refreshStartTimer(&startTime[gun_index][TMR_IDX_PROFILE_PREPARE]);
 						refreshStartTimer(&startTime[gun_index][TMR_IDX_PWN_CHANGE]);
-						ocpp_set_auth_req(OFF);
 						ocpp_reset_smartcharging_profileId(gun_index);
 						ocpp_set_profile_req(gun_index, ON);
 						ShmCharger->gun_info[gun_index].isChargerStopByCondition = NO;
@@ -7200,11 +7228,21 @@ int main(void)
 						{
 							if(ShmCharger->isUpdateSuccess == YES)
 							{
-								sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
-								ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
+								if((strcmp((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing")==0))
+								{
+									sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
+									ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
+								}
+								else if((strcmp((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Installing")==0))
+								{
+									ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
+									sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Installed");
+									ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = ON;
+								}
 
 								sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
 								ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
+
 								DEBUG_WARN("Firmware upgrade success.\n");
 
 								sleep(5);
@@ -7254,7 +7292,8 @@ int main(void)
 						{
 							if((ShmCharger->gun_info[gun_index].rfidReq == ON))
 							{
-								if(ocpp_compare_reserve_id_with_user(gun_index))
+								if(ocpp_compare_reserve_id_with_user(gun_index) ||
+								   ocpp_get_auth_result(YES, gun_index))
 								{
 									DEBUG_INFO("Start Method in reservation : RFID...\n");
 									DEBUG_INFO("Start request User Id : %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
@@ -7264,22 +7303,25 @@ int main(void)
 								}
 								else
 								{
-									DEBUG_INFO("It's not reserve user id.\n");
+									setLedMotion(gun_index,LED_ACTION_IDLE);
 									ShmCharger->gun_info[gun_index].resultAuthorization = DEFAULT_RFID;
+									DEBUG_INFO("It's not reserve user id.\n");
 								}
 
 								ShmCharger->gun_info[gun_index].rfidReq = OFF;
 							}
 							else if(ocpp_get_remotestart(gun_index))
 							{
-								if(ocpp_compare_reserve_id_with_remote_user(gun_index))
+								if(ocpp_compare_reserve_id_with_remote_user(gun_index) || ocpp_isAuthorizeRemoteStart())
 								{
 									DEBUG_INFO("Start Method in reservation: BACKEND...\n");
 									ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod = START_METHOD_BACKEND;
 									ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartIdType = IdTokenType_Central;
+									if(ocpp_isAuthorizeRemoteStart())
+										ocpp_copy_userid_from_remotestart(gun_index);
 									setChargerMode(gun_index, SYS_MODE_AUTHORIZING);
 								}
-								ocpp_set_remotestop(gun_index, OFF);
+								ocpp_set_remotestart(gun_index, OFF);
 							}
 						}
 					}