Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions AntPlus.Extensions.Hosting/AntCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public async Task StartScanning()
/// <param name="e">The ANT response.</param>
private void MessageHandler(object? sender, AntResponse e)
{
_logger.LogAntResponse(LogLevel.Trace, e);

// check for a valid payload
if (e.Payload == null || e.Payload.Length < 3)
{
Expand Down
9 changes: 5 additions & 4 deletions AntPlus.Extensions.Hosting/Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
<PackageIcon>PackageLogo.png</PackageIcon>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageReleaseNotes>
Updated NuGet dependencies.
1. Removed ANT response logging due to noise.
2. Updated NuGet dependencies.
</PackageReleaseNotes>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<VersionPrefix>2.0.6</VersionPrefix>
<VersionPrefix>2.0.7</VersionPrefix>
<PackageProjectUrl>https://stephenhidem.github.io/AntPlus</PackageProjectUrl>
<RepositoryUrl>https://github.com/StephenHidem/AntPlus</RepositoryUrl>
<Configurations>Debug;Release</Configurations>
Expand All @@ -41,8 +42,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<PackageReference Include="Microsoft.Maui.Core" Version="10.0.70" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.9" />
<PackageReference Include="Microsoft.Maui.Core" Version="10.0.71" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.300">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public void ParseCTFMessage_SameUpdateEventCountAndTorqueTicks_NoCalculations()
[InlineData(new byte[] { 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x11, 0x22 })]
[InlineData(new byte[] { 0x01, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x11, 0x22 })]
[InlineData(new byte[] { 0x01, 0x10, 0xAC, 0xFF, 0xFF, 0xFF, 0x11, 0x22 })]
[InlineData(new byte[] { 0x02, 0x10, 0xAC, 0xFF, 0xFF, 0xFF, 0x11, 0x22 })]
public void ParseUnknownCTFDefinedId_LogsWarning(byte[] dataPage)
{
// Arrange
Expand All @@ -174,15 +173,15 @@ public void ParseUnknownCTFDefinedId_LogsWarning(byte[] dataPage)
m => m.Log(
LogLevel.Warning,
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("Unknown data page")),
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("Enum value at index")),
null,
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
}

[Theory]
[InlineData(new byte[] { 0x01, 0x10, 0xAC, 0x02, 0xFF, 0xFF, 0xFF, 0xFF }, "Data page type Slope")]
[InlineData(new byte[] { 0x01, 0x10, 0xAC, 0x03, 0xFF, 0xFF, 0xFF, 0xFF }, "Data page type SerialNumber")]
[InlineData(new byte[] { 0x01, 0x10, 0xAC, 0x02, 0xFF, 0xFF, 0xFF, 0xFF }, "Enum value = Slope")]
[InlineData(new byte[] { 0x01, 0x10, 0xAC, 0x03, 0xFF, 0xFF, 0xFF, 0xFF }, "Enum value = SerialNumber")]
public void ParseAcknowledgeMessage_LogsDebugMessage(byte[] dataPage, string message)
{
// Arrange
Expand Down
12 changes: 6 additions & 6 deletions AntPlus/AntDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void TimeoutCallback(object state)
/// <param name="dataPage">The received data page.</param>
public virtual void Parse(byte[] dataPage)
{
_logger.LogDataPage(LogLevel.Trace, dataPage);
_logger.LogDataPage(LogLevel.Trace, dataPage, ChannelId.DeviceNumber);
_ = _timeoutTimer?.Change(_deviceTimeout, Timeout.Infinite);
}

Expand Down Expand Up @@ -179,19 +179,19 @@ public async Task<MessagingReturnCode> SendExtAcknowledgedMessage(byte[] message
/// <param name="dataPage">Raw bytes of the unrecognized data page.</param>
protected virtual void OnUnknownDataPageReceived(byte[] dataPage)
{
_logger.LogUnknownDataPage(dataPage);
_logger.LogUnknownDataPage(dataPage, ChannelId.DeviceNumber);
UnknownDataPageReceived?.Invoke(this, dataPage);
}

/// <summary>
/// Raises the <see cref="UnknownDataPageReceived"/> event with the provided raw data page bytes and includes the data page identifier in the log.
/// Raises the <see cref="UnknownDataPageReceived"/> event with the provided raw data page bytes and includes the data page index in the log.
/// </summary>
/// <typeparam name="TEnum">The enumeration that was being parsed.</typeparam>
/// <param name="unknownDataPageId">The identifier of the unrecognized data page.</param>
/// <param name="pageIndex">The index into the data page containing the unrecognized value.</param>
/// <param name="dataPage">The raw bytes of the unrecognized data page.</param>
protected virtual void OnUnknownDataPageReceived<TEnum>(byte unknownDataPageId, byte[] dataPage) where TEnum : Enum
protected virtual void OnUnknownDataPageReceived<TEnum>(int pageIndex, byte[] dataPage) where TEnum : Enum
{
_logger.LogUnknownDataPage<TEnum>(unknownDataPageId, dataPage);
_logger.LogUnknownDataPage<TEnum>(pageIndex, dataPage, ChannelId.DeviceNumber);
UnknownDataPageReceived?.Invoke(this, dataPage);
}

Expand Down
29 changes: 26 additions & 3 deletions AntPlus/AntDeviceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace SmallEarthTech.AntPlus
/// as this scales the timeout duration based on the broadcast transmission rate of the particular ANT device.
/// The timeout/missed messages will be applied globally to ANT devices created by this collection.
/// </remarks>
public partial class AntDeviceCollection : ObservableCollection<AntDevice>
public sealed partial class AntDeviceCollection : ObservableCollection<AntDevice>, IDisposable
{
/// <summary>
/// The collection lock.
Expand Down Expand Up @@ -81,8 +81,6 @@ public async Task StartScanning()

private void MessageHandler(object? sender, AntResponse e)
{
_logger.LogAntResponse(LogLevel.Trace, e);

// check for a valid payload
if (e.Payload == null || e.Payload.Length < 3)
{
Expand Down Expand Up @@ -190,5 +188,30 @@ private AntDevice CreateAntDevice(AntResponse response)
_ => new UnknownDevice(response.ChannelId, _sendMessageChannel!, _loggerFactory.CreateLogger<UnknownDevice>(), _timeout),
};
}

/// <summary>
/// Disposes the ANT device collection and all ANT devices in the collection. Also disposes ANT channels created by this collection.
/// </summary>
public void Dispose()
{
_logger.LogMethodEntry();

foreach (AntDevice device in this)
{
device.DeviceWentOffline -= DeviceOffline;
device.Dispose();
}
Clear();

if (_channels != null)
{
_channels[0].ChannelResponse -= MessageHandler;
foreach (IAntChannel item in _channels)
{
item.Dispose();
}
_channels = null;
}
}
Comment thread
StephenHidem marked this conversation as resolved.
}
}
13 changes: 7 additions & 6 deletions AntPlus/AntPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<RootNamespace>SmallEarthTech.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<PackageId>SmallEarthTech.$(AssemblyName)</PackageId>
<VersionPrefix>6.2.0</VersionPrefix>
<VersionPrefix>7.0.0</VersionPrefix>
<Title>ANT+ Class Library</Title>
<PackageProjectUrl>https://stephenhidem.github.io/AntPlus</PackageProjectUrl>
<Authors>Stephen Hidem</Authors>
Expand All @@ -23,8 +23,9 @@
<PackageIcon>PackageLogo.png</PackageIcon>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageReleaseNotes>
1. Added UnknownDataPageReceived event to AntDevice class. This allows applications to receive data pages that are not defined in the library. This is useful for receiving custom data pages or data pages that have not yet been added to the library.
2. Updated NuGet dependencies.
1. Breaking change: AntDeviceCollection is now disposable and implements IDisposable. This allows for proper cleanup of resources when the collection is no longer needed. Make sure to dispose of AntDeviceCollection instances to avoid memory leaks.
2. Breaking change: Several public method signatures in LoggerExtensions have been changed to include the DeviceNumber parameter. This change was made to provide more context when working with multiple devices. You will need to update your code to include the DeviceNumber parameter when calling these methods.
3. Updated NuGet dependencies.
</PackageReleaseNotes>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
Expand Down Expand Up @@ -95,9 +96,9 @@

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Options" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.9" />
<PackageReference Include="Microsoft.Extensions.Options" Version="10.0.9" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion AntPlus/CommonDataPages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ private double ParseSubfieldData(SubPage page, short value, ILogger logger)
case SubPage.Invalid:
break;
default:
logger.LogUnknownDataPage<SubPage>((byte)page, dp);
int pageIndex = (dp[2] == (byte)page) ? 2 : 3;
logger.LogUnknownDataPage<SubPage>(pageIndex, dp, 0); // TODO: needs channel ID and device number
break;
}
return retVal;
Expand Down
2 changes: 1 addition & 1 deletion AntPlus/DeviceProfiles/BicyclePower/Calibration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void ParseCalibrationPage(byte[] page)
CustomCalibrationParameters = page.Skip(2).ToArray();
break;
default:
OnUnknownDataPageReceived<CalibrationResponseId>(page[1], page);
OnUnknownDataPageReceived<CalibrationResponseId>(1, page);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,24 @@ private void ParseCalibrationMessage(byte[] dataPage)
switch ((CTFDefinedId)dataPage[3])
{
case CTFDefinedId.Slope:
_logger.LogDataPage<CTFDefinedId>(LogLevel.Debug, dataPage[3], dataPage);
_logger.LogDataPage<CTFDefinedId>(LogLevel.Debug, 3, dataPage);
break;
case CTFDefinedId.SerialNumber:
_logger.LogDataPage<CTFDefinedId>(LogLevel.Debug, dataPage[3], dataPage);
_logger.LogDataPage<CTFDefinedId>(LogLevel.Debug, 3, dataPage);
break;
default:
OnUnknownDataPageReceived<CTFDefinedId>(dataPage[3], dataPage);
OnUnknownDataPageReceived<CTFDefinedId>(3, dataPage);
break;
}
break;
default:
OnUnknownDataPageReceived<CTFDefinedId>(dataPage[2], dataPage);
OnUnknownDataPageReceived<CTFDefinedId>(2, dataPage);
break;
}
}
else
{
OnUnknownDataPageReceived<CalibrationResponseId>(dataPage[1], dataPage);
OnUnknownDataPageReceived<CalibrationResponseId>(1, dataPage);
}
}

Expand Down
2 changes: 1 addition & 1 deletion AntPlus/DeviceProfiles/BicyclePower/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void ParseParameters(byte[] dataPage)
AdvancedCapabilities2 = new AdvCapabilities2(dataPage);
break;
default:
OnUnknownDataPageReceived<SubPage>(dataPage[1], dataPage);
OnUnknownDataPageReceived<SubPage>(1, dataPage);
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions AntPlus/DeviceProfiles/FitnessEquipment/FitnessEquipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ protected void HandleFEState(byte[] dataPage)
}
else
{
OnUnknownDataPageReceived<FEState>(dataPage[7], dataPage);
OnUnknownDataPageReceived<FEState>(7, dataPage);
}
}

Expand Down Expand Up @@ -493,7 +493,7 @@ public async Task<MessagingReturnCode> RequestFECapabilities()
case FitnessEquipmentType.TrainerStationaryBike:
return new TrainerStationaryBike(channelId, antChannel, loggerFactory.CreateLogger<TrainerStationaryBike>(), timeout);
default:
loggerFactory.CreateLogger<FitnessEquipment>().LogUnknownDataPage<FitnessEquipmentType>(dataPage[1], dataPage);
loggerFactory.CreateLogger<FitnessEquipment>().LogUnknownDataPage<FitnessEquipmentType>(1, dataPage, channelId.DeviceNumber);
break;
}
break;
Expand All @@ -514,7 +514,7 @@ public async Task<MessagingReturnCode> RequestFECapabilities()
case DataPage.TrainerTorqueData:
return new TrainerStationaryBike(channelId, antChannel, loggerFactory.CreateLogger<TrainerStationaryBike>(), timeout);
default:
loggerFactory.CreateLogger<FitnessEquipment>().LogUnknownDataPage(dataPage);
loggerFactory.CreateLogger<FitnessEquipment>().LogUnknownDataPage(dataPage, channelId.DeviceNumber);
break;
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion AntPlus/DeviceProfiles/Geocache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public override void Parse(byte[] dataPage)
else { LastVisitTimestamp = null; }
break;
default:
OnUnknownDataPageReceived<DataId>(dataPage[1], dataPage);
OnUnknownDataPageReceived<DataId>(1, dataPage);
break;
}
}
Expand Down
Loading