-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for setting COM and NAV frequencies (#17)
- Issue #15 fixed by adding support for setting COM frequencies, including 3 decimals, through the RadioManager. - Added event ids for frequencies - Updated and added some method signatures - Integration tests for RadioManager - Simple utility class for BCD handling.
- Loading branch information
1 parent
f858e49
commit 7cb8f8a
Showing
19 changed files
with
830 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/CTrue.FsConnect.Managers.Test/AircraftManagersIntegrationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
|
||
namespace CTrue.FsConnect.Managers.Test | ||
{ | ||
/// <summary> | ||
/// World manager integration tests. | ||
/// </summary> | ||
/// <remarks> | ||
/// Load MSFS and an aircraft before running. | ||
/// Observe that the time changes in the simulator. | ||
/// </remarks> | ||
[TestFixture(Explicit = true)] | ||
public class AircraftManagersIntegrationTests | ||
{ | ||
[Test] | ||
public void GetAircraftData() | ||
{ | ||
// Arrange | ||
AutoResetEvent resetEvent = new AutoResetEvent(false); | ||
int errorCount = 0; | ||
|
||
FsConnect fsConnect = new FsConnect(); | ||
fsConnect.ConnectionChanged += (sender, b) => | ||
{ | ||
if (b) resetEvent.Set(); | ||
}; | ||
fsConnect.FsError += (sender, args) => | ||
{ | ||
errorCount++; | ||
Console.WriteLine($"Error: {args.ExceptionDescription}"); | ||
}; | ||
|
||
fsConnect.Connect("AircraftManagersIntegrationTests", 0); | ||
|
||
bool res = resetEvent.WaitOne(2000); | ||
if(!res) Assert.Fail("Not connected to MSFS within timeout"); | ||
|
||
var defId = fsConnect.RegisterDataDefinition<AircraftInfo>(); | ||
|
||
AircraftManager<AircraftInfo> aircraftManager = new AircraftManager<AircraftInfo>(fsConnect, defId); | ||
|
||
// Act | ||
var info = aircraftManager.Get(); | ||
|
||
// Assert | ||
Assert.That(errorCount, Is.Zero); | ||
Assert.That(info.Title, Is.Not.Empty); | ||
Assert.That(info.Latitude, Is.Not.EqualTo(0)); | ||
Assert.That(info.Longitude, Is.Not.EqualTo(0)); | ||
} | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] | ||
public struct AircraftInfo | ||
{ | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] | ||
public String Title; | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] | ||
public String Category; | ||
[SimVar(NameId = FsSimVar.PlaneLatitude, UnitId = FsUnit.Radian)] | ||
public double Latitude; | ||
[SimVar(NameId = FsSimVar.PlaneLongitude, UnitId = FsUnit.Radian)] | ||
public double Longitude; | ||
[SimVar(NameId = FsSimVar.PlaneAltitudeAboveGround, UnitId = FsUnit.Feet)] | ||
public double AltitudeAboveGround; | ||
[SimVar(NameId = FsSimVar.PlaneAltitude, UnitId = FsUnit.Feet)] | ||
public double Altitude; | ||
[SimVar(NameId = FsSimVar.PlaneHeadingDegreesTrue, UnitId = FsUnit.Degree)] | ||
public double Heading; | ||
[SimVar(NameId = FsSimVar.AirspeedTrue, UnitId = FsUnit.Knot)] | ||
public double Speed; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using System; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
|
||
namespace CTrue.FsConnect.Managers.Test | ||
{ | ||
/// <summary> | ||
/// Radio manager integration tests. | ||
/// </summary> | ||
/// <remarks> | ||
/// Load MSFS and an aircraft before running. | ||
/// </remarks> | ||
[TestFixture(Explicit = true)] | ||
public class RadioManagerTests | ||
{ | ||
private FsConnect _fsConnect; | ||
private RadioManager _manager; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
AutoResetEvent resetEvent = new AutoResetEvent(false); | ||
|
||
_fsConnect = new FsConnect(); | ||
_fsConnect.ConnectionChanged += (sender, b) => | ||
{ | ||
if (b) resetEvent.Set(); | ||
}; | ||
_fsConnect.FsError += (sender, args) => | ||
{ | ||
Assert.Fail($"MSFS Error: {args.ExceptionDescription}"); | ||
}; | ||
|
||
_fsConnect.Connect("RadioManagerIntegrationTest", 0); | ||
|
||
bool res = resetEvent.WaitOne(2000); | ||
if (!res) Assert.Fail("Not connected to MSFS within timeout"); | ||
|
||
_manager = new RadioManager(_fsConnect); | ||
} | ||
|
||
[Test] | ||
public void SetCom1StandbyFrequency() | ||
{ | ||
// Arrange | ||
double freq = 124.774d; | ||
|
||
// Act | ||
_manager.SetCom1StandbyFrequency(freq); | ||
|
||
// Assert | ||
_manager.Update(); | ||
Assert.That(_manager.Com1StandbyFrequency, Is.EqualTo(freq)); | ||
} | ||
|
||
[Test] | ||
public void SetCom1ActiveFrequency() | ||
{ | ||
// Arrange | ||
double freq = 124.774d; | ||
|
||
// Act | ||
_manager.SetCom1ActiveFrequency(freq); | ||
|
||
// Assert | ||
_manager.Update(); | ||
Assert.That(_manager.Com1ActiveFrequency, Is.EqualTo(freq)); | ||
} | ||
|
||
[Test] | ||
public void SetCom2StandbyFrequency() | ||
{ | ||
// Arrange | ||
double freq = 124.774d; | ||
|
||
// Act | ||
_manager.SetCom2StandbyFrequency(freq); | ||
|
||
// Assert | ||
_manager.Update(); | ||
Assert.That(_manager.Com2StandbyFrequency, Is.EqualTo(freq)); | ||
} | ||
|
||
[Test] | ||
public void SetCom2ActiveFrequency() | ||
{ | ||
// Arrange | ||
double freq = 124.773d; | ||
|
||
// Act | ||
_manager.SetCom2ActiveFrequency(freq); | ||
|
||
// Assert | ||
_manager.Update(); | ||
Assert.That(_manager.Com2ActiveFrequency, Is.EqualTo(freq)); | ||
} | ||
|
||
[Test] | ||
public void SwapCom1() | ||
{ | ||
// Arrange | ||
double freq = 124.773d; | ||
_manager.SetCom1StandbyFrequency(freq); | ||
_manager.SetCom1ActiveFrequency(125.000d); | ||
|
||
// Act | ||
_manager.Com1Swap(); | ||
|
||
// Assert | ||
_manager.Update(); | ||
Assert.That(_manager.Com1ActiveFrequency, Is.EqualTo(freq)); | ||
} | ||
|
||
[Test] | ||
public void SwapCom2() | ||
{ | ||
// Arrange | ||
double freq = 124.773d; | ||
_manager.SetCom2StandbyFrequency(freq); | ||
_manager.SetCom2ActiveFrequency(125.000d); | ||
|
||
// Act | ||
_manager.Com2Swap(); | ||
|
||
// Assert | ||
_manager.Update(); | ||
Assert.That(_manager.Com2ActiveFrequency, Is.EqualTo(freq)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.