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 1 commit
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 Get(string name, int level)
{
return string.IsNullOrEmpty(name) || !All.TryGetValue(name, out Encoder encoder) ? Encoder.GetFromTechLevel(level) : encoder;
}
public static Encoder GetFromTechLevel(int level)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I would write this as GetByName and then in calling code use GetByName(overrride) ?? GetFromTechLevel(level).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright rewrote it so the discrimination is done when the function is called.

{
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 string encoderOverride { get; set; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should match case with the rest of the code. Also I spot an extra whitespace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to match the formatting (although I have no idea what virtual means, it still works fine) and I think I removed the whitespace in question.


public Antenna.Encoder Encoder => Antenna.Encoder.GetFromTechLevel(TechLevelInfo.Level);
public Antenna.Encoder Encoder => Antenna.Encoder.Get(encoderOverride, 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