From cce1d8e204bf4e8cf0d2fc493098a3cdec12b547 Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Mon, 18 Jul 2022 15:54:36 +0200
Subject: [PATCH] Brakes: Implemented IUpdateable

---
 .../Models/SimulationComponent/IBrakes.cs         |  2 +-
 .../SimulationComponent/Impl/ElectricMotor.cs     |  2 +-
 .../Models/SimulationComponent/Impl/Gearbox.cs    |  5 +++--
 .../Strategies/TestPowertrain.cs                  | 15 ++++++++++++++-
 VectoCore/VectoCoreTest/Utils/MockBrakes.cs       | 15 ++++++++++++++-
 .../VectoCoreTest/Utils/MockVehicleContainer.cs   | 10 +++++++++-
 6 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/IBrakes.cs b/VectoCore/VectoCore/Models/SimulationComponent/IBrakes.cs
index 06e5019264..24c9b210d2 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/IBrakes.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/IBrakes.cs
@@ -33,7 +33,7 @@ using TUGraz.VectoCommon.Utils;
 
 namespace TUGraz.VectoCore.Models.SimulationComponent
 {
-	public interface IBrakes
+	public interface IBrakes: IUpdateable
 	{
 		Watt BrakePower { get; set; }
 	}
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs
index be9862dd99..7e4527e1c2 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs
@@ -581,7 +581,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		#region Implementation of IUpdateable
 
 		public bool UpdateFrom(object other) {
-			if (other is ElectricMotor e) {
+			if (other is ElectricMotor e && Position == e.Position) {
 				PreviousState = e.PreviousState.Clone();
 				ElectricPower = e.ElectricPower;
 				ThermalBuffer = e.ThermalBuffer;
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
index 3b0ce5332a..dcc2f7d071 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
@@ -574,10 +574,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				Disengaged = g.Disengaged;
 				DisengageGearbox = g.DisengageGearbox;
 				_nextGear = g.NextGear;
-				Gear = g.Gear;
-
+				
 				if (DataBus.VehicleInfo.VehicleStopped) {
 					Gear = _nextGear;
+				} else {
+					Gear = g.Gear;
 				}
 				
 				return true;
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/TestPowertrain.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/TestPowertrain.cs
index 9f93aba3f9..e198f3a774 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/TestPowertrain.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/TestPowertrain.cs
@@ -118,7 +118,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
 		public void UpdateComponents() => Container.UpdateComponents(RealContainer);
 	}
 
-	public class MockBrakes : VectoSimulationComponent, IBrakes
+	public class MockBrakes : VectoSimulationComponent, IBrakes, IUpdateable
 	{
 		public MockBrakes(IVehicleContainer container) : base(container)
 		{
@@ -144,6 +144,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies
 		public Watt BrakePower { get; set; }
 
 		#endregion
+
+		#region Implementation of IUpdateable
+
+		public bool UpdateFrom(object other) {
+			if (other is IBrakes b) {
+				BrakePower = b.BrakePower;
+				return true;
+			}
+
+			return false;
+		}
+
+		#endregion
 	}
 
 	public class MockDrivingCycle : VectoSimulationComponent, IDrivingCycleInfo
diff --git a/VectoCore/VectoCoreTest/Utils/MockBrakes.cs b/VectoCore/VectoCoreTest/Utils/MockBrakes.cs
index 755580cfda..eba2ca40b3 100644
--- a/VectoCore/VectoCoreTest/Utils/MockBrakes.cs
+++ b/VectoCore/VectoCoreTest/Utils/MockBrakes.cs
@@ -36,7 +36,7 @@ using TUGraz.VectoCore.OutputData;
 
 namespace TUGraz.VectoCore.Tests.Utils
 {
-	public class MockBrakes : VectoSimulationComponent, IBrakes
+	public class MockBrakes : VectoSimulationComponent, IBrakes, IUpdateable
 	{
 		public MockBrakes(IVehicleContainer vehicle) : base(vehicle)
 		{
@@ -48,5 +48,18 @@ namespace TUGraz.VectoCore.Tests.Utils
 		protected override void DoWriteModalResults(Second time, Second simulationInterval, IModalDataContainer container) {}
 
 		protected override void DoCommitSimulationStep(Second time, Second simulationInterval) {}
+
+		#region Implementation of IUpdateable
+
+		public bool UpdateFrom(object other) {
+			if (other is IBrakes b) {
+				BrakePower = b.BrakePower;
+				return true;
+			}
+
+			return false;
+		}
+
+		#endregion
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs b/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs
index 54b0580661..56faff6941 100644
--- a/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs
+++ b/VectoCore/VectoCoreTest/Utils/MockVehicleContainer.cs
@@ -48,7 +48,7 @@ using TUGraz.VectoCore.OutputData;
 namespace TUGraz.VectoCore.Tests.Utils
 {
 		
-	public class MockVehicleContainer : IVehicleContainer, IEngineInfo, IEngineControl, IVehicleInfo, IClutchInfo, IBrakes, IAxlegearInfo, IWheelsInfo, IDriverInfo, IDrivingCycleInfo, IMileageCounter, IGearboxInfo, IGearboxControl, IPowertainInfo
+	public class MockVehicleContainer : IVehicleContainer, IEngineInfo, IEngineControl, IVehicleInfo, IClutchInfo, IBrakes, IAxlegearInfo, IWheelsInfo, IDriverInfo, IDrivingCycleInfo, IMileageCounter, IGearboxInfo, IGearboxControl, IPowertainInfo, IUpdateable
 	{
 		// only CycleData Lookup is set / accessed...
 
@@ -337,5 +337,13 @@ namespace TUGraz.VectoCore.Tests.Utils
 		public VectoSimulationJobType VehicleArchitecutre { get; }
 
 		#endregion
+
+		#region Implementation of IUpdateable
+
+		public bool UpdateFrom(object other) {
+			return false;
+		}
+
+		#endregion
 	}
 }
\ No newline at end of file
-- 
GitLab