diff --git a/VECTO/Input Files/Engine.vb b/VECTO/Input Files/Engine.vb index 68a7383b55da3e4374002c8b12ccb3d1c959b9e2..8479cbe155d06d663b623b1153833a514525be20 100644 --- a/VECTO/Input Files/Engine.vb +++ b/VECTO/Input Files/Engine.vb @@ -159,38 +159,7 @@ Public Class Engine Return False End If - Dim json As New JSONWriter - - 'Header - Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) - header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")") - header.Add("Date", Now.ToUniversalTime().ToString("o")) - header.Add("AppVersion", VECTOvers) - header.Add("FileVersion", FormatVersion) - - 'Body - Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) - - body.Add("SavedInDeclMode", Cfg.DeclMode) - - body.Add("ModelName", ModelName) - - body.Add("Displacement", Displacement) - body.Add("IdlingSpeed", IdleSpeed) - body.Add("Inertia", EngineInertia) - - body.Add("FullLoadCurve", _fullLoadCurvePath.PathOrDummy) - - body.Add("FuelMap", _fuelConsumptionMapPath.PathOrDummy) - - body.Add("WHTC-Urban", WHTCUrbanInput) - body.Add("WHTC-Rural", WHTCRuralInput) - body.Add("WHTC-Motorway", WHTCMotorwayInput) - body.Add("ColdHotBalancingFactor", ColdHotBalancingFactorInput) - - json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) - - Return json.WriteFile(_filePath) + Return New JSONFileWriter().SaveEngine(Me, _filePath) End Function diff --git a/VECTO/Input Files/Gearbox.vb b/VECTO/Input Files/Gearbox.vb index 34825a8c406b529cbd5bfd2f1347da0ca797aa76..8e8d83c23c822ddd704023d0d68a612b122091f0 100644 --- a/VECTO/Input Files/Gearbox.vb +++ b/VECTO/Input Files/Gearbox.vb @@ -31,8 +31,6 @@ Public Class Gearbox ITorqueConverterEngineeringInputData, ITorqueConverterDeclarationInputData - Private Const FormatVersion As Short = 6 - Private _myPath As String Private _filePath As String @@ -49,12 +47,12 @@ Public Class Gearbox Public MaxTorque As List(Of String) Public TorqueResv As Double - Public SkipGears As Boolean + 'Public SkipGears As Boolean Public ShiftTime As Double Public TorqueResvStart As Double Public StartSpeed As Double Public StartAcc As Double - Public ShiftInside As Boolean + 'Public ShiftInside As Boolean Public Type As GearboxType @@ -89,12 +87,12 @@ Public Class Gearbox MaxTorque = New List(Of String) TorqueResv = 0 - SkipGears = False + 'SkipGears = False ShiftTime = 0 TorqueResvStart = 0 StartSpeed = 0 StartAcc = 0 - ShiftInside = False + 'ShiftInside = False Type = GearboxType.MT @@ -118,72 +116,7 @@ Public Class Gearbox Return False End If - Dim i As Integer - Dim json As New JSONWriter - - 'Header - Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) - header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")") - header.Add("Date", Now.ToUniversalTime().ToString("o")) - header.Add("AppVersion", VECTOvers) - header.Add("FileVersion", FormatVersion) - - - 'Body - Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) - - body.Add("SavedInDeclMode", Cfg.DeclMode) - - body.Add("ModelName", ModelName) - - body.Add("Inertia", GbxInertia) - body.Add("TracInt", TracIntrSi) - - Dim ls As New List(Of Dictionary(Of String, Object)) - For i = 0 To GearRatios.Count - 1 - Dim gearDict As New Dictionary(Of String, Object) - gearDict.Add("Ratio", GearRatios(i)) - If IsNumeric(GearLossMap(i, True)) Then - gearDict.Add("Efficiency", GearLossmaps(i).PathOrDummy) - Else - gearDict.Add("LossMap", GearLossmaps(i).PathOrDummy) - End If - If i > 0 Then - gearDict.Add("ShiftPolygon", GearshiftFiles(i).PathOrDummy) - gearDict.Add("MaxTorque", MaxTorque(i)) - End If - - ls.Add(gearDict) - Next - body.Add("Gears", ls) - - body.Add("TqReserve", TorqueResv) - body.Add("SkipGears", SkipGears) - body.Add("ShiftTime", ShiftTime) - body.Add("EaryShiftUp", ShiftInside) - - body.Add("StartTqReserve", TorqueResvStart) - body.Add("StartSpeed", StartSpeed) - body.Add("StartAcc", StartAcc) - - body.Add("GearboxType", Type) - - Dim torqueConverterDict As New Dictionary(Of String, Object) - torqueConverterDict.Add("Enabled", TorqueConverterEnabled) - torqueConverterDict.Add("File", _torqueConverterFile.PathOrDummy) - torqueConverterDict.Add("RefRPM", TorqueConverterReferenceRpm) - torqueConverterDict.Add("Inertia", TorqueConverterInertia) - torqueConverterDict.Add("ShiftPolygon", TorqueConverterShiftPolygonFile) - body.Add("TorqueConverter", torqueConverterDict) - - - body.Add("DownshiftAferUpshiftDelay", DownshiftAfterUpshift) - body.Add("UpshiftAfterDownshiftDelay", UpshiftAfterDownshift) - body.Add("UpshiftMinAcceleration", UpshiftMinAcceleration) - - json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) - - Return json.WriteFile(_filePath) + Return JSONFileWriter.Instance.SaveGearbox(Me, _filePath) End Function diff --git a/VECTO/Input Files/VectoJob.vb b/VECTO/Input Files/VectoJob.vb index 6540f6f7daf9b221e70045fdcda75acd8589f755..9670e4db67f9cfa130964d1f06463e11a5fecd7d 100644 --- a/VECTO/Input Files/VectoJob.vb +++ b/VECTO/Input Files/VectoJob.vb @@ -35,8 +35,6 @@ Public Class VectoJob IDeclarationJobInputData, IDriverEngineeringInputData, IDriverDeclarationInputData, IAuxiliariesEngineeringInputData, IAuxiliariesDeclarationInputData - Private Const FormatVersion As Short = 3 - 'AA-TB 'STORES THE Type and version of the chosen or default Auxiliary Type ( Classic/Original or other ) Public AuxiliaryAssembly As String @@ -108,8 +106,6 @@ Public Class VectoJob End Sub Public Function SaveFile() As Boolean - Dim json As New JSONWriter - Dim validationResults As IList(Of ValidationResult) = Validate(If(Cfg.DeclMode, ExecutionMode.Declaration, ExecutionMode.Engineering)) @@ -121,322 +117,9 @@ Public Class VectoJob Return False End If - 'Header - Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { - {"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"}, - {"Date", Now.ToUniversalTime().ToString("o")}, - {"AppVersion", VECTOvers}, - {"FileVersion", FormatVersion}} - - 'Body - Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) - - body.Add("SavedInDeclMode", Cfg.DeclMode) - SavedInDeclMode = Cfg.DeclMode - - 'Main Files - body.Add("VehicleFile", _vehicleFile.PathOrDummy) - body.Add("EngineFile", _engineFile.PathOrDummy) - body.Add("GearboxFile", _gearboxFile.PathOrDummy) - - 'Cycles - If CycleFiles.Count > 0 Then - body.Add("Cycles", CycleFiles.Select(Function(sb) sb.PathOrDummy)) - End If - - 'AA-TB - 'ADVANCED AUXILIARIES - body.Add("AuxiliaryAssembly", AuxiliaryAssembly) - body.Add("AuxiliaryVersion", AuxiliaryVersion) - body.Add("AdvancedAuxiliaryFilePath", AdvancedAuxiliaryFilePath) - - If AuxPaths.Any() Then - body.Add("Aux", AuxPaths.Select(Function(kv) New Dictionary(Of String, Object) From { - {"ID", Trim(UCase(kv.Key))}, - {"Type", kv.Value.Type}, - {"Path", kv.Value.Path.PathOrDummy}, - {"Technology", kv.Value.TechnologyList} - })) - End If - - If Not Cfg.DeclMode Then - body.Add("Padd", AuxPAdd) - End If - body.Add("VACC", _driverAccelerationFile.PathOrDummy) - body.Add("EngineOnlyMode", EngineOnly) - body.Add("StartStop", New Dictionary(Of String, Object) From { - {"Enabled", _startStop}, - {"MaxSpeed", StartStopMaxSpeed}, - {"MinTime", StartStopTime}, - {"Delay", StartStopDelay}}) - body.Add("LAC", New Dictionary(Of String, Object) From { - {"Enabled", LookAheadOn}, - {"PreviewDistanceFactor", LacPreviewFactor}, - {"DF_offset", LacDfOffset}, - {"DF_scaling", LacDfScale}, - {"DF_targetSpeedLookup", LacDfTargetSpeedFile}, - {"Df_velocityDropLookup", LacDfVelocityDropFile}}) - - 'Overspeed / EcoRoll - Dim overspeedDic As Dictionary(Of String, Object) = New Dictionary(Of String, Object) - If EcoRollOn Then - overspeedDic.Add("Mode", "EcoRoll") - ElseIf OverSpeedOn Then - overspeedDic.Add("Mode", "OverSpeed") - Else - overspeedDic.Add("Mode", "Off") - End If - overspeedDic.Add("MinSpeed", VMin) - overspeedDic.Add("OverSpeed", OverSpeed) - overspeedDic.Add("UnderSpeed", UnderSpeed) - body.Add("OverSpeedEcoRoll", overspeedDic) - - json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) - Return json.WriteFile(_sFilePath) + Return JSONFileWriter.Instance.SaveJob(Me, _sFilePath) End Function - 'Public Function ReadFile() As Boolean - ' Const msgSrc = "Main/ReadInp/GEN" - - ' SetDefault() - - ' Dim json As New JSONParser - ' If Not json.ReadFile(_sFilePath) Then Return False - - ' Try - - ' Dim fileVersion As Integer = json.Content.GetEx("Header").GetEx(Of Integer)("FileVersion") - - ' Dim body As JToken = json.Content.GetEx("Body") - - ' If fileVersion > 1 Then - ' SavedInDeclMode = body.GetEx(Of Boolean)("SavedInDeclMode") - ' Else - ' SavedInDeclMode = Cfg.DeclMode - ' End If - - ' If Not body("VehicleFile") Is Nothing Then _ - ' _vehicleFile.Init(_myPath, body.GetEx(Of String)("VehicleFile")) - - ' _engineFile.Init(_myPath, body.GetEx(Of String)("EngineFile")) - - ' If Not body("GearboxFile") Is Nothing Then _ - ' _gearboxFile.Init(_myPath, body.GetEx(Of String)("GearboxFile")) - - ' If Not body("Cycles") Is Nothing Then - ' For Each entry As JToken In body.GetEx("Cycles") - ' Dim subPath = New SubPath - ' subPath.Init(_myPath, entry.Value(Of String)) - ' CycleFiles.Add(subPath) - ' Next - ' End If - - ' 'AA-TB - ' 'ADVANCED AUXILIARIES - ' If Not body("AuxiliaryAssembly") Is Nothing AndAlso - ' Not body("AuxiliaryVersion") Is Nothing Then - - ' AuxiliaryAssembly = body("AuxiliaryAssembly").ToString() - ' AuxiliaryVersion = body("AuxiliaryVersion").ToString() - - ' End If - ' If Not body("AdvancedAuxiliaryFilePath") Is Nothing Then - ' AdvancedAuxiliaryFilePath = body("AdvancedAuxiliaryFilePath").ToString() - ' End If - - - ' If Not body("Aux") Is Nothing Then - ' For Each dic As JToken In body.GetEx("Aux") - - ' Dim auxId As String = UCase(Trim(dic.GetEx(Of String)("ID"))) - - ' If AuxPaths.ContainsKey(auxId) Then - ' WorkerMsg(MessageType.Err, "Multiple definitions of the same auxiliary type (" & auxId & ")!", msgSrc) - ' Return False - ' End If - - ' Dim auxEntry = New AuxEntry - - ' auxEntry.Type = dic.GetEx(Of String)("Type") - ' auxEntry.Path.Init(_myPath, dic.GetEx(Of String)("Path")) - - ' If Not dic("Technology") Is Nothing Then - ' If fileVersion = 2 Then - ' auxEntry.TechnologyList.Add(dic.GetEx(Of String)("Technology")) - ' End If - ' If fileVersion = 3 Then - ' auxEntry.TechnologyList = dic.GetEx("Technology").ToObject(Of List(Of String))() '.FirstOrDefault() - ' End If - ' End If - - ' If (auxId = Constants.AuxiliaryKey.HVAC) Then - ' If auxEntry.TechnologyList.Count > 0 Then ' Not String.IsNullOrWhiteSpace(auxEntry.TechStr) Then - ' auxEntry.TechnologyList.Clear() - ' WorkerMsg(MessageType.Normal, "Aux: Automatically Upgraded HVAC to new format.", msgSrc) - ' End If - ' End If - - ' If auxId = Constants.AuxiliaryKey.ElecSys Then - ' If auxEntry.TechnologyList.Contains("Custom Technology List") OrElse auxEntry.TechnologyList.Count > 0 Then - ' Dim hasTech = False - - ' If Not dic("TechList") Is Nothing Then - ' For Each t In dic("TechList") - ' hasTech = True - ' Next - ' End If - - ' auxEntry.TechnologyList.Clear() - ' If Not hasTech Then - ' auxEntry.TechnologyList.Add("Standard technology") - ' Else - ' auxEntry.TechnologyList.Add("Standard technology - LED headlights, all") - ' End If - ' WorkerMsg(MessageType.Normal, - ' "Aux: Automatically Upgraded Electric System to new format: '" + auxEntry.TechnologyList.FirstOrDefault() + "'", - ' msgSrc) - ' End If - ' End If - - ' If auxId = Constants.AuxiliaryKey.SteerPump Then - ' If _ - ' auxEntry.TechnologyList.Contains("Variable displacement") OrElse - ' auxEntry.TechnologyList.Contains("Hydraulic supported by electric") Then - ' auxEntry.TechnologyList.Clear() - ' WorkerMsg(MessageType.Warn, "Aux: Steering Pump Technology not automatically convertible. Please set new value.", - ' msgSrc) - ' End If - ' End If - - ' If auxId = Constants.AuxiliaryKey.Fan Then - ' If auxEntry.TechnologyList.Contains("Crankshaft mounted - Electronically controlled visco clutch (Default)") Then - ' auxEntry.TechnologyList.Clear() - ' auxEntry.TechnologyList.Add("Crankshaft mounted - Electronically controlled visco clutch") - ' End If - ' If auxEntry.TechnologyList.Contains("Crankshaft mounted - On/Off clutch") Then - ' auxEntry.TechnologyList.Clear() - ' auxEntry.TechnologyList.Add("Crankshaft mounted - On/off clutch") - ' End If - ' If auxEntry.TechnologyList.Contains("Belt driven or driven via transm. - On/Off clutch") Then - ' auxEntry.TechnologyList.Clear() - ' auxEntry.TechnologyList.Add("Belt driven or driven via transm. - On/off clutch") - ' End If - ' End If - - ' If fileVersion = 2 AndAlso auxId = Constants.AuxiliaryKey.PneumSys Then - ' auxEntry.TechnologyList.Clear() - ' WorkerMsg(MessageType.Warn, "Aux: Pneumatic System must be updated. Please set new value.", - ' msgSrc) - ' End If - - ' AuxPaths.Add(auxId, auxEntry) - - ' Next - ' End If - - ' If Not body("VACC") Is Nothing Then - ' _driverAccelerationFile.Init(_myPath, body.GetEx(Of String)("VACC")) - ' End If - - ' EngineOnly = body.GetEx(Of Boolean)("EngineOnlyMode") - - ' If Not body("StartStop") Is Nothing Then - ' Dim startStop As JToken = body.GetEx("StartStop") - ' _startStop = startStop.GetEx(Of Boolean)("Enabled") - ' _startStopMaxSpeed = startStop.GetEx(Of Double)("MaxSpeed") - ' _startStopMinTime = startStop.GetEx(Of Double)("MinTime") - ' StartStopDelay = startStop.GetEx(Of Double)("Delay") - ' Else - ' _startStop = False - ' End If - - ' If Not body("LAC") Is Nothing Then - ' Dim lac = body.GetEx("LAC") - ' LookAheadOn = lac.GetEx(Of Boolean)("Enabled") - ' LacPreviewFactor = If(lac("PreviewDistanceFactor") Is Nothing, 10, lac.GetEx(Of Double)("PreviewDistanceFactor")) - ' LacDfOffset = If(lac("DF_offset") Is Nothing, 2.5, lac.GetEx(Of Double)("DF_offset")) - ' LacDfScale = If(lac("DF_scaling") Is Nothing, 1.5, lac.GetEx(Of Double)("DF_scaling")) - ' LacDfTargetSpeedFile = - ' If(Not lac("DF_targetSpeedLookup") Is Nothing, lac.GetEx(Of String)("DF_targetSpeedLookup"), "") - ' LacDfVelocityDropFile = - ' If(Not lac("Df_velocityDropLookup") Is Nothing, lac.GetEx(Of String)("Df_velocityDropLookup"), "") - ' Else - ' LookAheadOn = False - ' End If - - ' If Not body("OverSpeedEcoRoll") Is Nothing Then - ' Dim dic = body("OverSpeedEcoRoll") - - ' Select Case UCase(dic("Mode").ToString).Trim - ' Case "ECOROLL" - ' OverSpeedOn = False - ' EcoRollOn = True - - ' Case "OVERSPEED" - ' OverSpeedOn = True - ' EcoRollOn = False - - ' Case "OFF" - ' OverSpeedOn = False - ' EcoRollOn = False - - ' Case Else - ' WorkerMsg(MessageType.Err, "Value '" & dic("Mode").ToString() & "' is not valid for OverSpeedEcoRoll/Mode!", - ' msgSrc) - ' Return False - ' End Select - - ' VMin = dic.GetEx(Of Double)("MinSpeed") - ' OverSpeed = dic.GetEx(Of Double)("OverSpeed") - ' If Not dic("UnderSpeed") Is Nothing Then UnderSpeed = dic.GetEx(Of Double)("UnderSpeed") - - ' Else - ' OverSpeedOn = False - ' EcoRollOn = False - ' End If - - - ' Catch ex As Exception - ' WorkerMsg(MessageType.Err, "Failed to read VECTO file! " & ex.Message, msgSrc) - ' Return False - ' End Try - - - ' Return True - 'End Function - - Private Sub SetDefault() - - AuxiliaryAssembly = "CLASSIC" - AuxiliaryVersion = "CLASSIC" - AdvancedAuxiliaryFilePath = String.Empty - - - _startStop = False - StartStopMaxSpeed = 5 - StartStopTime = 5 - StartStopDelay = 0 - - _vehicleFile.Clear() - _engineFile.Clear() - CycleFiles.Clear() - _gearboxFile.Clear() - - _driverAccelerationFile.Clear() - - AuxPaths.Clear() - EngineOnly = False - - VMin = 0 - LookAheadOn = True - OverSpeedOn = False - EcoRollOn = False - OverSpeed = 0 - UnderSpeed = 0 - - SavedInDeclMode = False - End Sub - 'This Sub reads those Input-files that do not have their own class, etc. @@ -974,6 +657,13 @@ Public Class VectoJob Protected Function AuxData() As IList(Of AuxiliaryDataInputData) Dim retVal As List(Of AuxiliaryDataInputData) = New List(Of AuxiliaryDataInputData) + If AuxPAdd > 0 Then + retVal.Add(New AuxiliaryDataInputData() With { + .ID = "ConstantAux", + .AuxiliaryType = AuxiliaryDemandType.Constant, + .ConstantPowerDemand = AuxPAdd.SI(Of Watt)() + }) + End If For Each auxEntry As KeyValuePair(Of String, AuxEntry) In AuxPaths Dim theAuxData As AuxiliaryDataInputData = New AuxiliaryDataInputData() With { .Type = AuxiliaryTypeHelper.Parse(auxEntry.Value.Type), diff --git a/VECTO/Input Files/Vehicle.vb b/VECTO/Input Files/Vehicle.vb index 61d1da961a58b44b7732a29cbf19e00c38400dc3..f43c5b6fde1d853071e0fa37d8e587a488b40a82 100644 --- a/VECTO/Input Files/Vehicle.vb +++ b/VECTO/Input Files/Vehicle.vb @@ -30,7 +30,7 @@ Public Class Vehicle Implements IVehicleEngineeringInputData, IVehicleDeclarationInputData, IRetarderInputData, IPTOTransmissionInputData, IAngledriveInputData 'V2 MassMax is now saved in [t] instead of [kg] - Private Const FormatVersion As Short = 7 + Private _filePath As String Private _path As String @@ -203,55 +203,7 @@ Public Class Vehicle Return False End If - Dim json As New JSONWriter - 'Header - Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { - {"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"}, - {"Date", Now.ToUniversalTime().ToString("o")}, - {"AppVersion", VECTOvers}, - {"FileVersion", FormatVersion}} - - 'Body - Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { - {"SavedInDeclMode", Cfg.DeclMode}, - {"VehCat", VehicleCategory.ToString()}, - {"CurbWeight", Mass}, - {"CurbWeightExtra", MassExtra}, - {"Loading", Loading}, - {"MassMax", MassMax}, - {"CdA", CdA0}, - {"rdyn", DynamicTyreRadius}, - {"CdCorrMode", CrossWindCorrectionMode.GetName()}, - {"CdCorrFile", CrossWindCorrectionFile.PathOrDummy}, - {"Retarder", New Dictionary(Of String, Object) From { - {"Type", RetarderType.GetName()}, - {"Ratio", RetarderRatio}, - {"File", RetarderLossMapFile.PathOrDummy}}}, - {"Angledrive", New Dictionary(Of String, Object) From { - {"Type", AngledriveType.ToString()}, - {"Ratio", AngledriveRatio}, - {"LossMap", AngledriveLossMapFile.PathOrDummy}}}, - {"PTO", New Dictionary(Of String, Object) From { - {"Type", PtoType}, - {"LossMap", PtoLossMap.PathOrDummy}, - {"Cycle", PtoCycle.PathOrDummy}}}, - {"AxleConfig", New Dictionary(Of String, Object) From { - {"Type", AxleConfiguration.GetName()}, - {"Axles", (From axle In Axles Select New Dictionary(Of String, Object) From { - {"Inertia", axle.Inertia}, - {"Wheels", axle.Wheels}, - {"AxleWeightShare", axle.Share}, - {"TwinTyres", axle.TwinTire}, - {"RRCISO", axle.RRC}, - {"FzISO", axle.FzISO} - } - )} - } - } - } - - json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) - Return json.WriteFile(_filePath) + Return JSONFileWriter.Instance.SaveVehicle(Me, Me, Me, Me, _filePath) End Function diff --git a/VECTO/OutputData/JSONWriter.vb b/VECTO/OutputData/JSONWriter.vb new file mode 100644 index 0000000000000000000000000000000000000000..b43ed53f3bdf63697b80a518569bd371695a3459 --- /dev/null +++ b/VECTO/OutputData/JSONWriter.vb @@ -0,0 +1,302 @@ +Imports System.Collections.Generic +Imports System.Linq +Imports Newtonsoft.Json.Linq +Imports TUGraz.VectoCommon.InputData +Imports TUGraz.VectoCommon.Models +Imports TUGraz.VectoCore.InputData.Impl +Imports TUGraz.VectoCore.Models.SimulationComponent.Data + +Public Class JSONFileWriter + Public Const EngineFormatVersion As Short = 3 + + Public Const GearboxFormatVersion As Short = 6 + + Public Const VehicleFormatVersion As Short = 7 + + Private Const VectoJobFormatVersion As Short = 3 + + Private Shared _instance As JSONFileWriter + + Public Shared ReadOnly Property Instance As JSONFileWriter + Get + If _instance Is Nothing Then _instance = New JSONFileWriter() + Return _instance + End Get + End Property + + Public Function SaveEngine(eng As IEngineEngineeringInputData, filename As String) As Boolean + Dim json As New JSONWriter + + 'Header + Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) + header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")") + header.Add("Date", Now.ToUniversalTime().ToString("o")) + header.Add("AppVersion", VECTOvers) + header.Add("FileVersion", EngineFormatVersion) + + 'Body + Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) + + body.Add("SavedInDeclMode", Cfg.DeclMode) + + body.Add("ModelName", eng.ModelName) + + body.Add("Displacement", eng.Displacement.Value()) + body.Add("IdlingSpeed", eng.IdleSpeed.Value()) + body.Add("Inertia", eng.Inertia.Value()) + + body.Add("FullLoadCurve", eng.FullLoadCurve.Source) + + body.Add("FuelMap", eng.FuelConsumptionMap.Source) + + body.Add("WHTC-Urban", eng.WHTCUrban) + body.Add("WHTC-Rural", eng.WHTCRural) + body.Add("WHTC-Motorway", eng.WHTCMotorway) + body.Add("ColdHotBalancingFactor", eng.ColdHotBalancingFactor) + + json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) + + Return json.WriteFile(filename) + End Function + + Public Function SaveGearbox(gbx As IGearboxEngineeringInputData, filename As String) As Boolean + + Dim i As Integer + Dim json As New JSONWriter + + 'Header + Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) + header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")") + header.Add("Date", Now.ToUniversalTime().ToString("o")) + header.Add("AppVersion", VECTOvers) + header.Add("FileVersion", GearboxFormatVersion) + + + 'Body + Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) + + body.Add("SavedInDeclMode", Cfg.DeclMode) + + body.Add("ModelName", gbx.ModelName) + + body.Add("Inertia", gbx.Inertia.Value()) + body.Add("TracInt", gbx.TractionInterruption.Value()) + + Dim ls As New List(Of Dictionary(Of String, Object)) + For Each gear As ITransmissionInputData In gbx.Gears + Dim gearDict As New Dictionary(Of String, Object) + gearDict.Add("Ratio", gear.Ratio) + If gear.LossMap Is Nothing Then + gearDict.Add("Efficiency", gear.Efficiency) + Else + gearDict.Add("LossMap", gear.LossMap.Source) + End If + If i > 0 Then + gearDict.Add("ShiftPolygon", gear.ShiftPolygon.Source) + gearDict.Add("MaxTorque", gear.MaxTorque.Value()) + End If + + ls.Add(gearDict) + Next + body.Add("Gears", ls) + + body.Add("TqReserve", gbx.TorqueReserve) + 'body.Add("SkipGears", gbx.sk) + body.Add("ShiftTime", gbx.ShiftTime.Value()) + 'body.Add("EaryShiftUp", gbx.ShiftInside) + + body.Add("StartTqReserve", gbx.StartTorqueReserve) + body.Add("StartSpeed", gbx.StartSpeed) + body.Add("StartAcc", gbx.StartAcceleration.Value()) + + body.Add("GearboxType", gbx.Type) + + Dim torqueConverter As ITorqueConverterEngineeringInputData = gbx.TorqueConverter + Dim torqueConverterDict As New Dictionary(Of String, Object) + torqueConverterDict.Add("Enabled", Not torqueConverter Is Nothing) + If Not torqueConverter Is Nothing Then + torqueConverterDict.Add("File", torqueConverter.TCData.Source) + torqueConverterDict.Add("RefRPM", torqueConverter.ReferenceRPM.AsRPM) + torqueConverterDict.Add("Inertia", torqueConverter.Inertia.Value()) + torqueConverterDict.Add("ShiftPolygon", torqueConverter.ShiftPolygon.Source) + End If + body.Add("TorqueConverter", torqueConverterDict) + + + body.Add("DownshiftAferUpshiftDelay", gbx.DownshiftAferUpshiftDelay.Value()) + body.Add("UpshiftAfterDownshiftDelay", gbx.UpshiftAfterDownshiftDelay.Value()) + body.Add("UpshiftMinAcceleration", gbx.UpshiftMinAcceleration) + + json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) + + Return json.WriteFile(filename) + End Function + + Public Function SaveVehicle(vehicle As IVehicleEngineeringInputData, retarder As IRetarderInputData, + pto As IPTOTransmissionInputData, angledrive As IAngledriveInputData, filename As String) As Boolean + Dim json As New JSONWriter + 'Header + Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { + {"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"}, + {"Date", Now.ToUniversalTime().ToString("o")}, + {"AppVersion", VECTOvers}, + {"FileVersion", VehicleFormatVersion}} + + 'Body + + + Dim retarderOut As Dictionary(Of String, Object) = New Dictionary(Of String, Object)() + If retarder Is Nothing Then + retarderOut.Add("Type", RetarderType.None.GetName()) + Else + retarderOut.Add("Type", retarder.Type.GetName()) + retarderOut.Add("Ratio", retarder.Ratio) + If Not retarder.LossMap Is Nothing Then + retarderOut.Add("File", retarder.LossMap.Source) + End If + End If + + Dim ptoOut As Dictionary(Of String, Object) = New Dictionary(Of String, Object) + If pto Is Nothing Then + ptoOut.Add("Type", "None") + Else + ptoOut.Add("Type", pto.PTOTransmissionType) + ptoOut.Add("LossMap", pto.PTOLossMap.Source) + ptoOut.Add("Cycle", pto.PTOCycle.Source) + End If + + Dim angledriveOut As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { + {"Type", angledrive.Type.ToString()}, + {"Ratio", angledrive.Ratio}, + {"LossMap", angledrive.LossMap.Source}} + + Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { + {"SavedInDeclMode", Cfg.DeclMode}, + {"VehCat", vehicle.VehicleCategory.ToString()}, + {"CurbWeight", vehicle.CurbWeightChassis.Value()}, + {"CurbWeightExtra", vehicle.CurbWeightExtra}, + {"Loading", vehicle.Loading}, + {"MassMax", vehicle.GrossVehicleMassRating.ConvertTo().Ton.Value()}, + {"CdA", vehicle.AirDragArea.Value()}, + {"rdyn", vehicle.DynamicTyreRadius}, + {"CdCorrMode", vehicle.CrossWindCorrectionMode.GetName()}, + {"CdCorrFile", vehicle.CrosswindCorrectionMap.Source}, + {"Retarder", retarderOut}, + {"Angledrive", angledriveOut}, + {"PTO", ptoOut}, + {"AxleConfig", New Dictionary(Of String, Object) From { + {"Type", vehicle.AxleConfiguration.GetName()}, + {"Axles", (From axle In vehicle.Axles Select New Dictionary(Of String, Object) From { + {"Inertia", axle.Inertia}, + {"Wheels", axle.Wheels}, + {"AxleWeightShare", axle.AxleWeightShare}, + {"TwinTyres", axle.TwinTyres}, + {"RRCISO", axle.RollResistanceCoefficient}, + {"FzISO", axle.TyreTestLoad.Value()} + } + )} + } + } + } + + json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) + Return json.WriteFile(filename) + End Function + + Public Function SaveJob(input As IEngineeringInputDataProvider, filename As String) As Boolean + Dim json As New JSONWriter + + 'Header + Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { + {"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"}, + {"Date", Now.ToUniversalTime().ToString("o")}, + {"AppVersion", VECTOvers}, + {"FileVersion", VectoJobFormatVersion}} + + 'Body + Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) + + body.Add("SavedInDeclMode", Cfg.DeclMode) + 'SavedInDeclMode = Cfg.DeclMode + + Dim job As IEngineeringJobInputData = input.JobInputData() + Dim aux As IAuxiliariesEngineeringInputData = input.AuxiliaryInputData() + Dim driver As IDriverEngineeringInputData = input.DriverInputData + + body.Add("EngineOnlyMode", job.EngineOnlyMode) + + If job.EngineOnlyMode Then + body.Add("EngineFile", input.EngineInputData.Source) + For Each cycle As ICycleData In job.Cycles + body.Add("Cycles", cycle.CycleData.Source) + Next + Return True + End If + + 'Main Files + body.Add("VehicleFile", job.Vehicle.Source) + body.Add("EngineFile", input.EngineInputData.Source) + body.Add("GearboxFile", input.GearboxInputData.Source) + + 'Cycles + For Each cycle As ICycleData In job.Cycles + body.Add("Cycles", cycle.CycleData.Source) + Next + + 'AA-TB + 'ADVANCED AUXILIARIES + body.Add("AuxiliaryAssembly", aux.AuxiliaryAssembly) + body.Add("AuxiliaryVersion", aux.AuxiliaryVersion) + body.Add("AdvancedAuxiliaryFilePath", aux.AdvancedAuxiliaryFilePath) + + Dim pAdd As Double = 0.0 + Dim auxOut As Dictionary(Of String, Object) = New Dictionary(Of String, Object) + For Each auxEntry As IAuxiliaryEngineeringInputData In aux.Auxiliaries + If auxEntry.AuxiliaryType = AuxiliaryDemandType.Constant Then + pAdd += auxEntry.ConstantPowerDemand.Value() + Continue For + End If + Dim engineeringAuxEntry As IAuxiliaryDeclarationInputData = TryCast(auxEntry, IAuxiliaryDeclarationInputData) + If engineeringAuxEntry Is Nothing Then + auxOut.Add("Type", auxEntry.AuxiliaryType.ToString()) + auxOut.Add("Path", auxEntry.DemandMap.Source) + Else + auxOut.Add("ID", auxEntry.ID) + auxOut.Add("Technology", engineeringAuxEntry.Technology) + End If + + Next + + body.Add("Aux", auxOut) + + If Not Cfg.DeclMode Then + body.Add("Padd", pAdd) + End If + body.Add("VACC", driver.AccelerationCurve.Source) + body.Add("StartStop", New Dictionary(Of String, Object) From { + {"Enabled", driver.StartStop.Enabled}, + {"MaxSpeed", driver.StartStop.MaxSpeed.Value()}, + {"MinTime", driver.StartStop.MinTime.Value()}, + {"Delay", driver.StartStop.Delay.Value()}}) + body.Add("LAC", New Dictionary(Of String, Object) From { + {"Enabled", driver.Lookahead.Enabled}, + {"PreviewDistanceFactor", driver.Lookahead.LookaheadDistanceFactor}, + {"DF_offset", driver.Lookahead.CoastingDecisionFactorOffset}, + {"DF_scaling", driver.Lookahead.CoastingDecisionFactorScaling}, + {"DF_targetSpeedLookup", driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup.Source}, + {"Df_velocityDropLookup", driver.Lookahead.CoastingDecisionFactorVelocityDropLookup.Source}}) + + 'Overspeed / EcoRoll + Dim overspeedDic As Dictionary(Of String, Object) = New Dictionary(Of String, Object) + + overspeedDic.Add("Mode", driver.OverSpeedEcoRoll.Mode.ToString()) + + overspeedDic.Add("MinSpeed", driver.OverSpeedEcoRoll.MinSpeed.Value()) + overspeedDic.Add("OverSpeed", driver.OverSpeedEcoRoll.OverSpeed.Value()) + overspeedDic.Add("UnderSpeed", driver.OverSpeedEcoRoll.UnderSpeed.Value()) + body.Add("OverSpeedEcoRoll", overspeedDic) + + json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) + Return json.WriteFile(filename) + End Function +End Class \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index 32d0b55b2218efb71872a39aeeb57f81e063d035..82dfbc07ba23d9ff5298e4ca8438fff5a62003ff 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -587,7 +587,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON var retVal = new List<AuxiliaryDataInputData>(); if (Body["Padd"] != null) { retVal.Add(new AuxiliaryDataInputData() { - ID = "ConstanntAux", + ID = "ConstantAux", AuxiliaryType = AuxiliaryDemandType.Constant, ConstantPowerDemand = Body.GetEx<double>("Padd").SI<Watt>() });