Skip to content

Commit

Permalink
Support for setting COM and NAV frequencies (#17)
Browse files Browse the repository at this point in the history
- 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
TimianHeber authored May 18, 2021
1 parent f858e49 commit 7cb8f8a
Show file tree
Hide file tree
Showing 19 changed files with 830 additions and 15 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,19 @@ worldManager.SetTime(new DateTime(year, month, day, hour, minute, 0));

```

### Radio Manager

The radio manager currently supports setting and getting COM1 and COM2 standby and active frequencies.

```csharp

FsConnect fsConnect = new FsConnect();
fsConnect.Connect("RadioManagerTest", 0);
RadioManager radioManager = new RadioManager(_fsConnect);
radioManager.SetCom1ActiveFrequency(freq);

```

## Community

* Have you find a bug? Do you have an idea for a new feature? ... [open an issue on GitHub](https://github.com/c-true/FsConnect/issues)
Expand All @@ -387,6 +400,10 @@ worldManager.SetTime(new DateTime(year, month, day, hour, minute, 0));

## Change log

## 1.3.2

* Added RadioManager, with support for setting and getting COM1 and COM2 standby and active frequencies.

## 1.3.1

* [Breaking] SimProperty renamed to SimVar, minor other renames.
Expand Down
2 changes: 1 addition & 1 deletion src/CTrue.FsConnect.ExampleConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void Main(string[] args)

do
{
fsConnect.RequestData(Requests.PlaneInfoRequest, planeInfoDefinitionId);
fsConnect.RequestData((int)Requests.PlaneInfoRequest, planeInfoDefinitionId);
cki = Console.ReadKey();
} while (cki.Key != ConsoleKey.Escape);

Expand Down
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;
};
}
130 changes: 130 additions & 0 deletions src/CTrue.FsConnect.Managers.Test/RadioManagerTests.cs
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace CTrue.FsConnect.Managers.Test
/// Observe that the time changes in the simulator.
/// </remarks>
[TestFixture(Explicit = true)]
public class FsConnectManagersIntegrationTests
public class WorldManagerIntegrationTests
{
[Test]
public void SetTime_SetsTimeInMSFS()
Expand All @@ -32,7 +32,7 @@ public void SetTime_SetsTimeInMSFS()
Console.WriteLine($"Error: {args.ExceptionDescription}");
};

fsConnect.Connect("FsConnectManagersIntegrationTest", 0);
fsConnect.Connect("WorldManagerIntegrationTests", 0);

bool res = resetEvent.WaitOne(2000);
if(!res) Assert.Fail("Not connected to MSFS within timeout");
Expand Down
20 changes: 20 additions & 0 deletions src/CTrue.FsConnect.Managers/AircraftManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ public RequestMethod RequestMethod
}
}

/// <summary>
/// Creates an instance of the <see cref="AircraftManager{T}"/> class.
/// </summary>
/// <param name="fsConnect"></param>
public AircraftManager(IFsConnect fsConnect, int defineId)
: this(fsConnect, defineId, fsConnect.GetNextId())
{
}

/// <summary>
/// Creates an instance of the <see cref="AircraftManager{T}"/> class.
/// </summary>
/// <param name="fsConnect"></param>
/// <param name="defineId">The definition used when registering the aircraft information structure.</param>
/// <param name="requestId">The request Id to use when requesting data using the manager.</param>
public AircraftManager(IFsConnect fsConnect, int defineId, int requestId)
: this(fsConnect, (FsConnectEnum)defineId, (FsConnectEnum)requestId)
{
}

/// <summary>
/// Creates an instance of the <see cref="AircraftManager{T}"/> class.
/// </summary>
Expand Down
9 changes: 5 additions & 4 deletions src/CTrue.FsConnect.Managers/CTrue.FsConnect.Managers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
- Aircraft information
- Retrieving sim objects
- Setting world time
- Controlling COM radios
</Description>
<Authors>C-True</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/c-true/FsConnect</RepositoryUrl>
<PackageTags>msfs flight-simulator simconnect</PackageTags>
<Version>1.3.1</Version>
<Version>1.3.2</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageReleaseNotes />
<AssemblyVersion>1.3.1.0</AssemblyVersion>
<FileVersion>1.3.1.0</FileVersion>
<PackageReleaseNotes>Added RadioManager for controlling COM radios.</PackageReleaseNotes>
<AssemblyVersion>1.3.2.0</AssemblyVersion>
<FileVersion>1.3.2.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Loading

0 comments on commit 7cb8f8a

Please sign in to comment.