Skip to content

Commit

Permalink
Allow encoders to be manually defined by ground stations (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Capkirk123 authored Oct 19, 2024
1 parent a470898 commit c839ffa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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

0 comments on commit c839ffa

Please sign in to comment.