From 23f66f7fc18fb91de20f586ebaa14bf6b5d2de3a Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Thu, 18 Nov 2021 11:02:35 +0100
Subject: [PATCH] allow reading adas parameters from file also in declaration
 mode

---
 .../Models/Declaration/DeclarationData.cs     | 48 +++++++++++++++++++
 .../Resources/Declaration/ADASParameters.json | 13 +++++
 VectoCore/VectoCore/VectoCore.csproj          |  4 +-
 3 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 VectoCore/VectoCore/Resources/Declaration/ADASParameters.json

diff --git a/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs b/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs
index d70ddc3f18..161230a59a 100644
--- a/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs
+++ b/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs
@@ -34,6 +34,7 @@ using System.Collections.Generic;
 using System.Data;
 using System.IO;
 using System.Linq;
+using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using TUGraz.VectoCommon.BusAuxiliaries;
 using TUGraz.VectoCommon.Exceptions;
@@ -345,6 +346,25 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 		public static class Driver
 		{
+			internal static JObject adasParams;
+
+			static Driver()
+			{
+				ReadAdasConfig();
+			}
+
+			// TODO: MQ 2019-11-26 remove, once the parameters are fixed! make fields above read-only or const
+			internal static void ReadAdasConfig()
+			{
+				var expectedFile = @"Declaration\ADASParameters.json";
+				if (!File.Exists(expectedFile)) {
+					return;
+				}
+				using (var reader = File.OpenText(expectedFile)) {
+					adasParams = (JObject)(JToken.ReadFrom(new JsonTextReader(reader)).GetEx(JsonKeys.JsonBody));
+				}
+			}
+
 			public static class LookAhead
 			{
 				public const bool Enabled = true;
@@ -380,6 +400,34 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 			public static class PCC
 			{
+				// TODO: MQ 2019-11-26 remove, once the parameters are fixed! make fields above read-only or const
+				static PCC()
+				{
+					ReadAdasConfig();
+					if (adasParams == null) {
+						return;
+					}
+
+					if (adasParams["PCCEnableSpeed"] != null) {
+						PCCEnableSpeed = adasParams.GetEx<double>("PCCEnableSpeed").KMPHtoMeterPerSecond();
+					}
+					if (adasParams["MinSpeed"] != null) {
+						MinSpeed = adasParams.GetEx<double>("MinSpeed").KMPHtoMeterPerSecond();
+					}
+					if (adasParams["PreviewDistanceUseCase1"] != null) {
+						PreviewDistanceUseCase1 = adasParams.GetEx<double>("PreviewDistanceUseCase1").SI<Meter>();
+					}
+					if (adasParams["PreviewDistanceUseCase2"] != null) {
+						PreviewDistanceUseCase2 = adasParams.GetEx<double>("PreviewDistanceUseCase2").SI<Meter>();
+					}
+					if (adasParams["Underspeed"] != null) {
+						Underspeed = adasParams.GetEx<double>("Underspeed").KMPHtoMeterPerSecond();
+					}
+					if (adasParams["OverspeedUseCase3"] != null) {
+						OverspeedUseCase3 = adasParams.GetEx<double>("OverspeedUseCase3").KMPHtoMeterPerSecond();
+					}
+				}
+
 				public static readonly MeterPerSecond PCCEnableSpeed = 80.KMPHtoMeterPerSecond();
 				public static readonly MeterPerSecond MinSpeed = 50.KMPHtoMeterPerSecond();
 				public static readonly Meter PreviewDistanceUseCase1 = 1500.SI<Meter>();
diff --git a/VectoCore/VectoCore/Resources/Declaration/ADASParameters.json b/VectoCore/VectoCore/Resources/Declaration/ADASParameters.json
new file mode 100644
index 0000000000..eb2cc06757
--- /dev/null
+++ b/VectoCore/VectoCore/Resources/Declaration/ADASParameters.json
@@ -0,0 +1,13 @@
+{
+"Header": {
+  "FileVersion": 1 
+},
+  "Body": {
+    "PCCEnableSpeed": 80,
+    "MinSpeed": 50,
+    "PreviewDistanceUseCase1": 1500,
+    "PreviewDistanceUseCase2": 1000,
+    "Underspeed": 8,
+    "OverspeedUseCase3": 5 
+  }
+}
\ No newline at end of file
diff --git a/VectoCore/VectoCore/VectoCore.csproj b/VectoCore/VectoCore/VectoCore.csproj
index 19d580ea71..b10a02208b 100644
--- a/VectoCore/VectoCore/VectoCore.csproj
+++ b/VectoCore/VectoCore/VectoCore.csproj
@@ -76,7 +76,8 @@
     <DebugType>pdbonly</DebugType>
     <Optimize>true</Optimize>
     <OutputPath>bin\Release\</OutputPath>
-    <DefineConstants>CERTIFICATION_RELEASE</DefineConstants>
+    <DefineConstants>
+    </DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
@@ -822,6 +823,7 @@
     <EmbeddedResource Include="Resources\Declaration\VAUXBus\SP-AxleFactor.csv" />
     <EmbeddedResource Include="Resources\Declaration\VAUXBus\SP-Axles_Bus.csv" />
     <EmbeddedResource Include="Resources\Declaration\VAUXBus\SP-Factors_Bus.csv" />
+    <None Include="Resources\Declaration\ADASParameters.json" />
     <None Include="Resources\Declaration\EffShiftParameters.vtcu" />
     <None Include="Utils\VectoVersionCore.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
-- 
GitLab