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
4 changes: 2 additions & 2 deletions AntPlus.Extensions.Hosting/AntCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ private void MessageHandler(object? sender, AntResponse e)
// re-open the channel in scan mode
if (_antRadio is IAntControl antControl)
{
_logger.LogWarning("Re-opening channel 0 in scan mode.");
_logger.LogWarning(new EventId(1012, "MessageHandler"), "AntRadio #{SerialNumber}: Re-opening channel 0 in scan mode.", _antRadio.SerialNumber);
_ = antControl.OpenRxScanMode();
}
else
{
_logger.LogCritical("IAntControl not implemented. Can't re-open channel 0.");
_logger.LogCritical(new EventId(1013, "MessageHandler"), "AntRadio #{SerialNumber}: IAntControl not implemented. Can't re-open channel 0.", _antRadio.SerialNumber);
}
break;
case MessageId.BroadcastData:
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>
1. Dispose AntDevices when AntCollection is disposed.
</PackageReleaseNotes>
1. Improved logging messages for better debugging and monitoring of ANT+ device interactions.
2. Updated NuGet package dependencies.
</PackageReleaseNotes>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<VersionPrefix>2.0.8</VersionPrefix>
<VersionPrefix>2.0.9</VersionPrefix>
<PackageProjectUrl>https://stephenhidem.github.io/AntPlus</PackageProjectUrl>
<RepositoryUrl>https://github.com/StephenHidem/AntPlus</RepositoryUrl>
<Configurations>Debug;Release</Configurations>
Expand All @@ -42,7 +43,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.9" />
<PackageReference Include="Microsoft.Maui.Core" Version="10.0.71" />
<PackageReference Include="Microsoft.Maui.Core" Version="10.0.80" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.300">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion AntPlus.UnitTests/AntPlus.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.7.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
4 changes: 2 additions & 2 deletions AntPlus/AntDeviceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ private void MessageHandler(object? sender, AntResponse e)
// re-open the channel in scan mode
if (_antRadio is IAntControl antControl)
{
_logger.LogError("Re-opening channel 0 in scan mode.");
_logger.LogError(new EventId(1012, "MessageHandler"), "AntRadio #{SerialNumber}: Re-opening channel 0 in scan mode.", _antRadio.SerialNumber);
_ = antControl.OpenRxScanMode();
}
else
{
_logger.LogCritical("IAntControl not implemented. Can't re-open channel 0.");
_logger.LogCritical(new EventId(1013, "MessageHandler"), "AntRadio #{SerialNumber}: IAntControl not implemented. Can't re-open channel 0.", _antRadio.SerialNumber);
}
break;
case MessageId.BroadcastData:
Expand Down
6 changes: 2 additions & 4 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>7.0.0</VersionPrefix>
<VersionPrefix>7.0.1</VersionPrefix>
<Title>ANT+ Class Library</Title>
<PackageProjectUrl>https://stephenhidem.github.io/AntPlus</PackageProjectUrl>
<Authors>Stephen Hidem</Authors>
Expand All @@ -23,9 +23,7 @@
<PackageIcon>PackageLogo.png</PackageIcon>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageReleaseNotes>
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.
1. Improved logging messages for better debugging and monitoring of ANT+ device interactions.
</PackageReleaseNotes>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
Expand Down
22 changes: 11 additions & 11 deletions AntPlus/Extensions/Logging/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void LogUnknownDataPage(this ILogger logger, byte[] dataPage, uint
s_unknownDataPage(logger, deviceNumber, dataPage[0], BitConverter.ToString(dataPage));
}

[LoggerMessage(EventId = 1000, Level = LogLevel.Warning, Message = "DeviceNumber={DeviceNumber}: Unknown data page# 0x{Page:X2}, Data page = {DataPage}")]
[LoggerMessage(EventId = 1000, EventName = "UnknownDataPage", Level = LogLevel.Warning, Message = "DeviceNumber={DeviceNumber}: Unknown data page# 0x{Page:X2}, Data page = {DataPage}")]
private static partial void s_unknownDataPage(ILogger logger, uint deviceNumber, byte page, string dataPage);

/// <summary>
Expand All @@ -48,7 +48,7 @@ public static void LogUnknownDataPage<TEnum>(this ILogger logger, int pageIndex,
s_unknownDataPageEnum(logger, deviceNumber, pageIndex, typeof(TEnum).Name, BitConverter.ToString(dataPage));
}

[LoggerMessage(EventId = 1001, Level = LogLevel.Warning, Message = "DeviceNumber={DeviceNumber}: Enum value at index {Index} is not defined in {Enum}, Data page = {DataPage}")]
[LoggerMessage(EventId = 1001, EventName = "UnknownDataPageEnum", Level = LogLevel.Warning, Message = "DeviceNumber={DeviceNumber}: Enum value at index {Index} is not defined in {Enum}, Data page = {DataPage}")]
private static partial void s_unknownDataPageEnum(ILogger logger, uint deviceNumber, int index, string @enum, string dataPage);

/// <summary>
Expand All @@ -72,10 +72,10 @@ public static void LogSendAcknowledgedMessage(this ILogger logger, int channelIn
}
}

[LoggerMessage(EventId = 1002, Level = LogLevel.Debug, Message = "{MethodName}: Channel index = {ChannelIndex}, Channel ID = 0x{ChannelId:X8}, Page# 0x{Page:X2}, Data page = {DataPage}")]
[LoggerMessage(EventId = 1002, EventName = "SendAcknowledgedMessage", Level = LogLevel.Debug, Message = "{MethodName}: Channel index = {ChannelIndex}, Channel ID = 0x{ChannelId:X8}, Page# 0x{Page:X2}, Data page = {DataPage}")]
private static partial void s_sendAckMsg(ILogger logger, string methodName, int channelIndex, uint channelId, byte page, string dataPage);

[LoggerMessage(EventId = 1003, Level = LogLevel.Debug, Message = "{MethodName}: Channel index = {ChannelIndex}, Channel ID = 0x{ChannelId:X8}, Page# 0x{Page:X2}, Result = {Result}")]
[LoggerMessage(EventId = 1003, EventName = "SendAcknowledgedMessageResult", Level = LogLevel.Debug, Message = "{MethodName}: Channel index = {ChannelIndex}, Channel ID = 0x{ChannelId:X8}, Page# 0x{Page:X2}, Result = {Result}")]
private static partial void s_sendAckMsgResult(ILogger logger, string methodName, int channelIndex, uint channelId, byte page, MessagingReturnCode result);

/// <summary>
Expand All @@ -88,7 +88,7 @@ public static void LogMethodEntry(this ILogger logger, [CallerMemberName] string
s_logMethodEntry(logger, methodName);
}

[LoggerMessage(EventId = 1004, Level = LogLevel.Debug, Message = "Entering {MethodName}")]
[LoggerMessage(EventId = 1004, EventName = "MethodEntry", Level = LogLevel.Debug, Message = "Entering {MethodName}")]
private static partial void s_logMethodEntry(ILogger logger, string methodName);

/// <summary>
Expand All @@ -103,7 +103,7 @@ public static void LogAntDeviceState(this ILogger logger, AntDevice antDevice, i
s_logAntDeviceState(logger, methodName, antDevice, antDevice.ChannelId.DeviceNumber, antDevice.Offline, timeout);
}

[LoggerMessage(EventId = 1005, Level = LogLevel.Debug, Message = "{MethodName} {AntDevice} Device# {DeviceNumber}, Offline = {Offline}, Timeout = {Timeout}ms")]
[LoggerMessage(EventId = 1005, EventName = "AntDeviceState", Level = LogLevel.Debug, Message = "{MethodName} {AntDevice} Device# {DeviceNumber}, Offline = {Offline}, Timeout = {Timeout}ms")]
private static partial void s_logAntDeviceState(ILogger logger, string methodName, AntDevice antDevice, uint deviceNumber, bool offline, int timeout);

/// <summary>
Expand All @@ -117,7 +117,7 @@ public static void LogAntCollectionChange(this ILogger logger, AntDevice antDevi
s_logAntCollectionChange(logger, methodName, antDevice, antDevice.ChannelId.DeviceNumber);
}

[LoggerMessage(EventId = 1006, Level = LogLevel.Debug, Message = "{MethodName}: {AntDevice} Device# {DeviceNumber}")]
[LoggerMessage(EventId = 1006, EventName = "AntCollectionChange", Level = LogLevel.Debug, Message = "{MethodName}: {AntDevice} Device# {DeviceNumber}")]
private static partial void s_logAntCollectionChange(ILogger logger, string methodName, AntDevice antDevice, uint deviceNumber);

/// <summary>
Expand All @@ -132,7 +132,7 @@ public static void LogUnhandledAntResponse(this ILogger logger, AntResponse antR
s_logUnhandledAntResponse(logger, methodName, antResponse.ChannelNumber, antResponse.ResponseId, payload);
}

[LoggerMessage(EventId = 1011, Level = LogLevel.Warning, Message = "{MethodName}: Unhandled ANT response. Channel# {Channel}, Response ID = {ResponseId}, Payload = {Payload}")]
[LoggerMessage(EventId = 1011, EventName = "UnhandledAntResponse", Level = LogLevel.Warning, Message = "{MethodName}: Unhandled ANT response. Channel# {Channel}, Response ID = {ResponseId}, Payload = {Payload}")]
private static partial void s_logUnhandledAntResponse(ILogger logger, string methodName, byte channel, MessageId responseId, string payload);

/// <summary>
Expand All @@ -147,7 +147,7 @@ public static void LogIgnoredDataPage<TEnum>(this ILogger logger, byte[] dataPag
s_logIgnoredPage(logger, methodName, Enum.GetName(typeof(TEnum), dataPage[0]), BitConverter.ToString(dataPage));
}

[LoggerMessage(EventId = 1008, Level = LogLevel.Warning, Message = "{MethodName}: Ignoring page type {Page}, Data page = {DataPage}. The page was unexpected or not implemented.")]
[LoggerMessage(EventId = 1008, EventName = "IgnoredDataPage", Level = LogLevel.Warning, Message = "{MethodName}: Ignoring page type {Page}, Data page = {DataPage}. The page was unexpected or not implemented.")]
private static partial void s_logIgnoredPage(ILogger logger, string methodName, string? page, string dataPage);

/// <summary>
Expand All @@ -162,7 +162,7 @@ public static void LogDataPage(this ILogger logger, LogLevel level, byte[] dataP
s_logDataPage(logger, level, deviceNumber, BitConverter.ToString(dataPage));
}

[LoggerMessage(EventId = 1009, Message = "DeviceNumber={DeviceNumber}: Data page = {DataPage}")]
[LoggerMessage(EventId = 1009, EventName = "DataPage", Message = "DeviceNumber={DeviceNumber}: Data page = {DataPage}")]
private static partial void s_logDataPage(ILogger logger, LogLevel level, uint deviceNumber, string dataPage);

/// <summary>
Expand All @@ -179,7 +179,7 @@ public static void LogDataPage<TEnum>(this ILogger logger, LogLevel level, int p
s_logDataPage(logger, level, methodName, Enum.ToObject(typeof(TEnum), dataPage[pageIndex])?.ToString(), BitConverter.ToString(dataPage));
}

[LoggerMessage(EventId = 1010, Message = "{MethodName}: Enum value = {EnumValue}, Data page = {DataPage}")]
[LoggerMessage(EventId = 1010, EventName = "DataPageEnum", Message = "{MethodName}: Enum value = {EnumValue}, Data page = {DataPage}")]
private static partial void s_logDataPage(ILogger logger, LogLevel level, string methodName, string? enumValue, string dataPage);
}
}
6 changes: 3 additions & 3 deletions Examples/AntUsbStick/AntChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ internal AntChannel(ANT_Channel channel, ILogger logger)
_antChannel = channel;
channel.channelResponse += OnChannelResponse;
channel.DeviceNotification += OnDeviceNotification;
_logger.LogDebug("Created AntChannel #{Channel}", ChannelNumber);
_logger.LogDebug(new EventId(1001, "ctor"), "Created AntChannel #{Channel}", ChannelNumber);
}

private void OnDeviceNotification(ANT_Device.DeviceNotificationCode notification, object notificationInfo)
{
_logger.LogDebug("Notification: {Notification} Info: {NotificationInfo}", notification, notificationInfo);
_logger.LogDebug(new EventId(1002, "OnDeviceNotification"), "AntChannel #{Channel}: Notification={Notification}, Info={NotificationInfo}", ChannelNumber, notification, notificationInfo);
}

private void OnChannelResponse(ANT_Response response)
Expand Down Expand Up @@ -258,7 +258,7 @@ public void Dispose()
{
if (_antChannel != null)
{
_logger.LogDebug("Disposed AntChannel #{Channel}", ChannelNumber);
_logger.LogDebug(new EventId(1003, "Dispose"), "Disposed AntChannel #{Channel}", ChannelNumber);
_antChannel.channelResponse -= OnChannelResponse;
_antChannel.DeviceNotification -= OnDeviceNotification;
_antChannel.Dispose();
Expand Down
12 changes: 6 additions & 6 deletions Examples/AntUsbStick/AntRadio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public AntRadio(ILogger<AntRadio> logger)
_antDevice = new ANT_Device();
_antDevice.deviceResponse += OnDeviceResponse;
_antDevice.serialError += OnAntDeviceSerialError;
_logger.LogDebug("Created AntRadio #{DeviceNum}", _antDevice.getOpenedUSBDeviceNum());
_logger.LogDebug(new EventId(1004, ".ctor"), "Created AntRadio #{SerialNumber}", SerialNumber);
}

private void OnAntDeviceSerialError(ANT_Device sender, ANT_Device.serialErrorCode error, bool isCritical)
{
_logger.LogError("OnAntDeviceSerialError: Sender: {Sender} Error: {Error} Critical: {IsCritical}", sender, error, isCritical);
_logger.LogError(new EventId(1005, "OnAntDeviceSerialError"), "AntRadio #{SerialNumber}: Error={Error}, Critical={IsCritical}", SerialNumber, error, isCritical);
Comment thread
StephenHidem marked this conversation as resolved.

// if the error is critical, close the device and reinitialize
if (isCritical)
Expand All @@ -57,13 +57,13 @@ private void OnAntDeviceSerialError(ANT_Device sender, ANT_Device.serialErrorCod
_antDevice = new ANT_Device();
_antDevice.deviceResponse += OnDeviceResponse;
_antDevice.serialError += OnAntDeviceSerialError;
_logger.LogWarning("Reinitialized AntRadio #{DeviceNum}", _antDevice.getOpenedUSBDeviceNum());
_logger.LogWarning(new EventId(1006, "OnAntDeviceSerialError"), "Reinitialized AntRadio #{SerialNumber}", SerialNumber);
}
}

private void OnDeviceResponse(ANT_Response response)
{
_logger.LogDebug("OnDeviceResponse: {Channel}, {ResponseId}, {Data}", response.antChannel, (MessageId)response.responseID, BitConverter.ToString(response.messageContents));
_logger.LogDebug(new EventId(1007, "OnDeviceResponse"), "AntRadio #{SerialNumber}: Channel={Channel}, ResponseId={ResponseId}, Data={Data}", SerialNumber, response.antChannel, (MessageId)response.responseID, BitConverter.ToString(response.messageContents));
RadioResponse?.Invoke(this, new UsbAntResponse(response));
}

Expand All @@ -84,7 +84,7 @@ public Task<IAntChannel[]> InitializeContinuousScanMode()
if (_channels == null)
{
// allocate channels for this radio
_logger.LogInformation("Allocating channels for continuous scan mode.");
_logger.LogInformation(new EventId(1008, "InitializeContinuousScanMode"), "AntRadio #{SerialNumber}: Configuring channels for continuous scan mode.", SerialNumber);
_channels = new IAntChannel[NumChannels];

// configure channel 0 for continuous scan mode
Expand Down Expand Up @@ -118,7 +118,7 @@ public void Dispose()
{
if (_antDevice != null)
{
_logger.LogDebug("Disposed AntRadio #{DeviceNum}", _antDevice.getOpenedUSBDeviceNum());
_logger.LogDebug(new EventId(1009, "Dispose"), "Disposed AntRadio #{SerialNumber}", SerialNumber);
_antDevice.deviceResponse -= OnDeviceResponse;
_antDevice.serialError -= OnAntDeviceSerialError;
_antDevice.Dispose();
Expand Down
4 changes: 2 additions & 2 deletions Examples/AntUsbStick/AntUsbStick.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<AssemblyName>SmallEarthTech.$(MSBuildProjectName)</AssemblyName>
<Title>Garmin/Dynastream ANT+ USB Stick Class Library</Title>
<VersionPrefix>4.1.4</VersionPrefix>
<VersionPrefix>4.1.5</VersionPrefix>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">True</GeneratePackageOnBuild>
<Authors>Stephen Hidem</Authors>
<Description>Provides an interface to ANT+ USB sticks available from Garmin/Dynastream. This class is used in the example projects located at the project URL.</Description>
Expand All @@ -22,7 +22,7 @@
<PackageId>$(AssemblyName)</PackageId>
<PackageIcon>PackageLogo.png</PackageIcon>
<PackageReleaseNotes>
1. Updated NuGet dependencies.
1. Improved logging messages for better debugging and monitoring of ANT+ device interactions.
</PackageReleaseNotes>
<Configurations>Debug;Release</Configurations>
<PackageLicenseFile>OSMFEULA.txt</PackageLicenseFile>
Expand Down
6 changes: 3 additions & 3 deletions Examples/MAUI-gRPC/MauiAntGrpcClient/MauiAntGrpcClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@
<PackageReference Include="Google.Protobuf" Version="3.35.1" />
<PackageReference Include="Grpc.Net.Client" Version="2.80.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.9" />
<PackageReference Include="Microsoft.Maui.Controls" Version="10.0.71" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="10.0.71" />
<PackageReference Include="Microsoft.Maui.Controls" Version="10.0.80" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="10.0.80" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.9" />
<PackageReference Include="Microsoft.Maui.Core" Version="10.0.71" />
<PackageReference Include="Microsoft.Maui.Core" Version="10.0.80" />
<PackageReference Include="Serilog" Version="4.3.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.7.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
Expand Down