Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow encoders to be manually defined by ground stations #45

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/RealAntennasProject/Antenna/Encoder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace RealAntennas.Antenna
Expand Down Expand Up @@ -30,6 +31,10 @@ public Encoder(string name, int techLevel, float rate, float minEbN0)

public Encoder BestMatching(in Encoder other) => TechLevel > other.TechLevel ? other : this;
public static Encoder BestMatching(in Encoder a, in Encoder b) => a.BestMatching(b);
public static Encoder GetFromName(string name)
{
return !string.IsNullOrEmpty(name) ? All[name] : null;
}
public static Encoder GetFromTechLevel(int level)
{
Encoder best = null;
Expand Down
6 changes: 5 additions & 1 deletion src/RealAntennasProject/RealAntenna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public class RealAntenna
public virtual double Bandwidth => DataRate; // RF bandwidth required.
public virtual float AMWTemp { get; set; }
public virtual float Beamwidth => Physics.Beamwidth(Gain);
public virtual string EncoderOverride { get; set; }

public Antenna.Encoder Encoder => Antenna.Encoder.GetFromTechLevel(TechLevelInfo.Level);
public Antenna.Encoder Encoder => Antenna.Encoder.GetFromName(EncoderOverride) ?? Antenna.Encoder.GetFromTechLevel(TechLevelInfo.Level);
public virtual float RequiredCI => Encoder.RequiredEbN0;

public ModuleRealAntenna Parent { get; internal set; }
Expand Down Expand Up @@ -96,6 +97,7 @@ public RealAntenna(RealAntenna orig)
Parent = orig.Parent;
ParentNode = orig.ParentNode;
ParentSnapshot = orig.ParentSnapshot;
EncoderOverride = orig.EncoderOverride;
}

public virtual bool Compatible(RealAntenna other) => RFBand == other.RFBand;
Expand All @@ -119,6 +121,7 @@ public virtual void LoadFromConfigNode(ConfigNode config)
Target = Targeting.AntennaTarget.LoadFromConfig(config.GetNode("TARGET"), this);
else if (Shape != AntennaShape.Omni && (ParentNode == null || !ParentNode.isHome) && !(Target?.Validate() == true) && HighLogic.LoadedSceneHasPlanetarium)
Target = Targeting.AntennaTarget.LoadFromConfig(SetDefaultTarget(), this);
EncoderOverride = (config.HasValue("EncoderOverride")) ? config.GetValue("EncoderOverride") : null;
}

public virtual void ProcessUpgrades(float tsLevel, ConfigNode node)
Expand Down Expand Up @@ -147,6 +150,7 @@ public virtual void UpgradeFromConfigNode(ConfigNode config)
if (config.TryGetValue("SymbolRate", ref d)) SymbolRate = d;
if (config.TryGetValue("AMWTemp", ref f)) AMWTemp = f;
if (config.TryGetValue("RFBand", ref s)) RFBand = Antenna.BandInfo.All[s];
if (config.TryGetValue("EncoderOverride", ref s)) EncoderOverride = s;
}

public virtual ConfigNode SetDefaultTarget()
Expand Down
Loading