Skip to content

Commit

Permalink
Update bios communicator library to support string inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
charliefoxtwo committed Oct 12, 2023
1 parent a7b1c3a commit 5a39e39
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 71 deletions.
4 changes: 2 additions & 2 deletions Configuration/Configuration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion TouchDcsConsole/TouchDcsConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="NReco.Logging.File" Version="1.1.5" />
<PackageReference Include="NReco.Logging.File" Version="1.1.7" />
</ItemGroup>

</Project>
21 changes: 20 additions & 1 deletion TouchDcsTest/Resources/BiosConfigurations/ButtonTests.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@
"type":"integer"
}
]
},
"SetStringInput":{
"category":"Button",
"control_type":"radio",
"description":"UHF Radio Frequency",
"identifier":"SetStringInput",
"inputs":[
{
"description":"Set the frequency of the radio",
"interface":"set_string"
}
],
"outputs":[
{
"description":"Get the frequency of the radio",
"max_length":7,
"type":"string"
}
]
}
}
}
}
6 changes: 3 additions & 3 deletions TouchDcsTest/TouchDcsTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
</ItemGroup>

<ItemGroup>
Expand Down
115 changes: 64 additions & 51 deletions TouchDcsTest/TranslatorTests/FromOscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,68 @@
using NUnit.Framework;
using TouchDcsTest.TranslatorTests.Keys;

namespace TouchDcsTest.TranslatorTests
namespace TouchDcsTest.TranslatorTests;

public class FromOscTests : TranslatorTestBase
{
public class FromOscTests : TranslatorTestBase
{
public FromOscTests() : base("ButtonTests") { }

[Theory]
[TestCase(0)]
[TestCase(1)]
[TestCase(65535)]
[TestCase(-1)]
public void Button_FromOsc(int value)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.SetStateButton, value);
}

[TestCase(InputFixedStep.Increment, 1)]
[TestCase(InputFixedStep.Decrement, -1)]
public void Button_FromOsc_FixedStepRotary_IntIn(string expected, int valueIn)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepRotary, expected, valueIn);
}

[TestCase(0)]
[TestCase(2)]
public void Button_FromOsc_SetStateRotary(int value)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.SetStateRotary, value);
}

[TestCase(InputFixedStep.Increment)]
[TestCase(InputFixedStep.Decrement)]
public void Button_FromOsc_FixedStepSetStateRotary_StringIn(string value)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepSetStateRotary, value);
}

[TestCase(1)]
[TestCase(-1)]
public void Button_FromOsc_FixedStepSetStateRotary_IntIn(int value)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepSetStateRotary, value);
}

[TestCase("+3200", InputFixedStep.Increment)]
[TestCase("-3200", InputFixedStep.Decrement)]
public void Button_FromOsc_VariableStepRotary(string expected, string valueIn)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.VariableStepRotary, expected, valueIn);
}
}
}
public FromOscTests() : base("ButtonTests") { }

[Theory]
[TestCase(0)]
[TestCase(1)]
[TestCase(65535)]
[TestCase(-1)]
public void Button_FromOsc(int value)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.SetStateButton, value);
}

[TestCase(InputFixedStep.Increment, 1)]
[TestCase(InputFixedStep.Decrement, -1)]
public void Button_FromOsc_FixedStepRotary_IntIn(string expected, int valueIn)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepRotary, expected, valueIn);
}

[TestCase(0)]
[TestCase(2)]
public void Button_FromOsc_SetStateRotary(int value)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.SetStateRotary, value);
}

[TestCase(InputFixedStep.Increment)]
[TestCase(InputFixedStep.Decrement)]
public void Button_FromOsc_FixedStepSetStateRotary_StringIn(string value)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepSetStateRotary, value);
}

[TestCase(1)]
[TestCase(-1)]
public void Button_FromOsc_FixedStepSetStateRotary_IntIn(int value)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.FixedStepSetStateRotary, value);
}

[TestCase("+3200", InputFixedStep.Increment)]
[TestCase("-3200", InputFixedStep.Decrement)]
public void Button_FromOsc_VariableStepRotary(string expected, string valueIn)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.VariableStepRotary, expected, valueIn);
}

[TestCase("TOGGLE")]
public void String_FromOsc_ToggleAction(string expected)
{
// set state button has a toggle input
BiosVerifier.Exactly(ButtonTranslatorKeys.SetStateButton, expected, expected);
}

[TestCase("123.450")]
[TestCase("foo bar")]
public void String_FromOsc_SetString(string expected)
{
BiosVerifier.Exactly(ButtonTranslatorKeys.SetStringInput, expected, expected);
}
}
20 changes: 10 additions & 10 deletions TouchDcsTest/TranslatorTests/Keys/ButtonTranslatorKeys.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace TouchDcsTest.TranslatorTests.Keys
namespace TouchDcsTest.TranslatorTests.Keys;

public static class ButtonTranslatorKeys
{
public static class ButtonTranslatorKeys
{
public const string SetStateButton = "SetStateButton";
public const string FixedStepRotary = "FixedStepRotary";
public const string SetStateRotary = "SetStateRotary";
public const string FixedStepSetStateRotary = "FixedStepSetStateRotary";
public const string VariableStepRotary = "VariableStepRotary";
}
}
public const string SetStateButton = "SetStateButton";
public const string FixedStepRotary = "FixedStepRotary";
public const string SetStateRotary = "SetStateRotary";
public const string FixedStepSetStateRotary = "FixedStepSetStateRotary";
public const string VariableStepRotary = "VariableStepRotary";
public const string SetStringInput = "SetStringInput";
}
10 changes: 8 additions & 2 deletions TouchDcsWorker/BiosOscTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public void FromOsc<T>(string ipAddress, string address, T data)
var setStateInput = inputs.OfType<InputSetState>().FirstOrDefault();
var fixedStepInput = inputs.OfType<InputFixedStep>().FirstOrDefault();
var variableStepInput = inputs.OfType<InputVariableStep>().FirstOrDefault();
var actionInput = inputs.OfType<InputAction>().FirstOrDefault();
var setStringInput = inputs.OfType<InputSetString>().FirstOrDefault();
if (setStateInput != null && floatData.HasValue)
{
_biosSender.Send(address, floatData.Value.ToString());
Expand Down Expand Up @@ -171,9 +173,13 @@ public void FromOsc<T>(string ipAddress, string address, T data)
var stringifiedAmount = $"{(amount < 0 ? string.Empty : "+")}{amount}";
_biosSender.Send(address, stringifiedAmount);
}
else if ((actionInput is not null || setStringInput is not null) && stringData is not null)
{
_biosSender.Send(address, stringData);
}
else
{
_log.LogError("input type {{set_state}} not found for control {Address}", address);
_log.LogError("no supported input found for control {Address}", address);
}
}

Expand Down Expand Up @@ -230,4 +236,4 @@ public record BiosInfo<T>(List<T> BiosData);
public class BiosCodeInfo<T> : Dictionary<string, BiosInfo<T>> { }

public sealed record OscMessage(string Address, object Data);
}
}
2 changes: 1 addition & 1 deletion TouchDcsWorker/TouchDcsWorker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
<PackageReference Include="DcsBios.Communicator" Version="4.0.0" />
<PackageReference Include="DcsBios.Communicator" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 5a39e39

Please sign in to comment.