Skip to content

Commit 1387ee5

Browse files
authored
Merge pull request #22 from StephenHidem/NuGet
Merge NuGet branch
2 parents b16759e + 7453229 commit 1387ee5

19 files changed

+168
-71
lines changed

AntPlus.UnitTests/AntDeviceCollectionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public void TestInitialize()
3232

3333
private AntDeviceCollection CreateAntDeviceCollection()
3434
{
35+
IAntChannel[] mockChannels = new IAntChannel[8];
36+
Array.Fill(mockChannels, mockAntChannel.Object);
37+
mockAntRadio.Setup(r => r.InitializeContinuousScanMode()).Returns(mockChannels);
3538
return new AntDeviceCollection(
3639
mockAntRadio.Object,
3740
null,
@@ -42,7 +45,6 @@ private AntDeviceCollection CreateAntDeviceCollection()
4245
public void MultithreadedAdd_Collection_ExpectedCount()
4346
{
4447
// Arrange
45-
mockAntRadio.Setup(r => r.GetChannel(It.IsAny<int>())).Returns(mockAntChannel.Object);
4648
Mock<ILogger<UnknownDevice>> mockLogger = new();
4749
var antDeviceCollection = CreateAntDeviceCollection();
4850
int numberOfDevices = 16;
@@ -73,7 +75,6 @@ public void MultithreadedAdd_Collection_ExpectedCount()
7375
public void MultithreadedRemove_Collection_ExpectedCount()
7476
{
7577
// Arrange
76-
mockAntRadio.Setup(r => r.GetChannel(It.IsAny<int>())).Returns(mockAntChannel.Object);
7778
Mock<ILogger<UnknownDevice>> mockLogger = new();
7879
var antDeviceCollection = CreateAntDeviceCollection();
7980
int numberOfDevices = 16;
@@ -117,7 +118,6 @@ public void ChannelResponseEvent_Collection_ExpectedDeviceInCollection(byte devi
117118
// Arrange
118119
byte[] id = new byte[4] { 1, 0, deviceClass, 0 };
119120
ChannelId cid = new(BitConverter.ToUInt32(id));
120-
mockAntRadio.Setup(r => r.GetChannel(It.IsAny<int>())).Returns(mockAntChannel.Object);
121121
mockAntChannel.SetupAdd(m => m.ChannelResponse += It.IsAny<EventHandler<AntResponse>>());
122122
mockAntChannel.SetupRemove(m => m.ChannelResponse -= It.IsAny<EventHandler<AntResponse>>());
123123
var mockResponse = new MockResponse(cid, new byte[8]);

AntPlus.UnitTests/AntPlus.UnitTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<ProjectReference Include="..\AntPlus\AntPlus.csproj" />
22+
<Folder Include="DeviceProfiles\AssetTracker\" />
2323
</ItemGroup>
2424

2525
<ItemGroup>
26-
<Folder Include="DeviceProfiles\AssetTracker\" />
26+
<ProjectReference Include="..\AntPlus\AntPlus.csproj" />
2727
</ItemGroup>
2828

2929
</Project>

AntPlus/AntDeviceCollection.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ public class AntDeviceCollection : ObservableCollection<AntDevice>
2828
/// </remarks>
2929
public object CollectionLock = new object();
3030

31-
private readonly IAntRadio antRadio;
32-
private int channelNum = 0;
31+
private int channelNum = 1;
3332
private readonly ILoggerFactory _loggerFactory;
3433
private readonly ILogger<AntDeviceCollection> logger;
3534
private readonly ushort timeout;
35+
private readonly IAntChannel[] channels;
3636

37-
/// <summary>Initializes a new instance of the <see cref="AntDeviceCollection" /> class.</summary>
37+
/// <summary>
38+
/// Initializes a new instance of the <see cref="AntDeviceCollection" /> class. The ANT radio is configured
39+
/// for continuous scan mode.
40+
/// </summary>
3841
/// <param name="antRadio">The ANT radio interface.</param>
3942
/// <param name="loggerFactory">Logger factory to generate type specific ILogger from. Can be null.</param>
4043
/// <param name="antDeviceTimeout">ANT device timeout in milliseconds. The default is 2000 milliseconds.</param>
@@ -51,18 +54,12 @@ public class AntDeviceCollection : ObservableCollection<AntDevice>
5154
/// </remarks>
5255
public AntDeviceCollection(IAntRadio antRadio, ILoggerFactory loggerFactory, ushort antDeviceTimeout = 2000)
5356
{
54-
this.antRadio = antRadio;
5557
_loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
5658
logger = _loggerFactory.CreateLogger<AntDeviceCollection>();
5759
logger.LogInformation("Created AntDeviceCollection");
5860
timeout = antDeviceTimeout;
59-
antRadio.GetChannel(0).ChannelResponse += Channel_ChannelResponse;
60-
61-
// assign channels for devices to use for sending messages
62-
for (int i = 1; i < antRadio.NumChannels; i++)
63-
{
64-
_ = antRadio.GetChannel(i).AssignChannel(ChannelType.BaseSlaveReceive, 0, 500);
65-
}
61+
channels = antRadio.InitializeContinuousScanMode();
62+
channels[0].ChannelResponse += Channel_ChannelResponse;
6663
}
6764

6865
private void Channel_ChannelResponse(object sender, AntResponse e)
@@ -114,8 +111,8 @@ private void DeviceOffline(object sender, EventArgs e)
114111

115112
private AntDevice CreateAntDevice(ChannelId channelId)
116113
{
117-
if (++channelNum == antRadio.NumChannels) channelNum = 1;
118-
IAntChannel channel = antRadio.GetChannel(channelNum);
114+
IAntChannel channel = channels[channelNum++];
115+
if (channelNum == channels.Length) { channelNum = 1; }
119116

120117
switch (channelId.DeviceType)
121118
{

AntPlus/AntPlus.csproj

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
<PackageId>SmallEarthTech.$(AssemblyName)</PackageId>
99
<Version>$(AssemblyVersion)</Version>
1010
<Title>ANT+ Class Library</Title>
11-
<PackageProjectUrl>https://github.com/StephenHidem/AntPlus</PackageProjectUrl>
11+
<PackageProjectUrl>http://stephenhidem.github.io/AntPlus</PackageProjectUrl>
1212
<Authors>Stephen Hidem</Authors>
13-
<Copyright>© $(Authors). All rights reserved.</Copyright>
13+
<Copyright>© $(Authors) 2023. All rights reserved.</Copyright>
1414
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1515
<IncludeSymbols>True</IncludeSymbols>
1616
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
17-
<PackageReadmeFile>README.md</PackageReadmeFile>
1817
<PackageTags>ant; ant+; ant plus; smallearthtech</PackageTags>
1918
<Description>Enables applications to interface and acquire data from a variety of ANT+ sensor sources. The primary class is AntPlus and it contains device profiles of ANT+ devices and common data pages.</Description>
2019
<RepositoryUrl>https://github.com/StephenHidem/AntPlus</RepositoryUrl>
@@ -23,6 +22,8 @@
2322
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2423
<AssemblyName>SmallEarthTech.$(MSBuildProjectName)</AssemblyName>
2524
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
25+
<PackageIcon>PackageLogo.png</PackageIcon>
26+
<PackageReadmeFile>readme.md</PackageReadmeFile>
2627
</PropertyGroup>
2728

2829
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
@@ -68,13 +69,6 @@
6869
<EmbeddedResource Include="Images\Unknown.png" />
6970
</ItemGroup>
7071

71-
<ItemGroup>
72-
<None Include="..\README.md">
73-
<Pack>True</Pack>
74-
<PackagePath>\</PackagePath>
75-
</None>
76-
</ItemGroup>
77-
7872
<ItemGroup>
7973
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
8074
</ItemGroup>
@@ -89,4 +83,15 @@
8983
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9084
</PackageReference>
9185
</ItemGroup>
86+
87+
<ItemGroup>
88+
<None Update="PackageLogo.png">
89+
<Pack>True</Pack>
90+
<PackagePath>\</PackagePath>
91+
</None>
92+
<None Update="readme.md">
93+
<Pack>True</Pack>
94+
<PackagePath>\</PackagePath>
95+
</None>
96+
</ItemGroup>
9297
</Project>

AntPlus/PackageLogo.png

73.8 KB
Loading

AntPlus/readme.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Small Earth Technology ANT+ Class Library
2+
Add a reference to this class in your application to interact with ANT+ devices and display sensor data.
3+
##### Supported ANT+ profiles:
4+
- Asset tracker
5+
- Bicycle power
6+
- Bike speed and cadence
7+
- Fitness equipment
8+
- Geocache
9+
- Heart rate monitors
10+
- Muscle oxygen
11+
- Stride based speed and distance
12+
13+
Unknown devices are supported by the UnknownDevice class.

AntRadioInterface/AntRadioInterface.csproj

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
<Authors>Stephen Hidem</Authors>
1010
<Title>ANT+ Radio Interface Class Library</Title>
1111
<Version>$(AssemblyVersion)</Version>
12-
<Copyright>© $(Authors). All rights reserved.</Copyright>
13-
<PackageProjectUrl>https://github.com/StephenHidem/AntPlus</PackageProjectUrl>
14-
<PackageReadmeFile>README.md</PackageReadmeFile>
15-
<PackageTags>ant; ant+; ant plus; smallearthtech</PackageTags>
12+
<Copyright>© $(Authors) 2023. All rights reserved.</Copyright>
13+
<PackageProjectUrl>http://stephenhidem.github.io/AntPlus</PackageProjectUrl>
14+
<PackageTags>ant; ant+; ant plus; dynastream; smallearthtech</PackageTags>
1615
<RepositoryUrl>https://github.com/StephenHidem/AntPlus</RepositoryUrl>
1716
<Description>The AntRadioInterface defines an interface to interact with an ANT radio to send and receive from an ANT device. Use this package to create a concrete implementation of an ANT radio.</Description>
1817
<PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -22,21 +21,20 @@
2221
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2322
<AssemblyName>SmallEarthTech.$(MSBuildProjectName)</AssemblyName>
2423
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
24+
<PackageIcon>PackageLogo.png</PackageIcon>
25+
<PackageReadmeFile>readme.md</PackageReadmeFile>
2526
</PropertyGroup>
2627

2728
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
2829
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
2930
</PropertyGroup>
3031

31-
<ItemGroup>
32-
<Compile Remove="IAntResponse.cs" />
33-
</ItemGroup>
32+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />
33+
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'" />
3435

3536
<ItemGroup>
36-
<None Include="..\README.md">
37-
<Pack>True</Pack>
38-
<PackagePath>\</PackagePath>
39-
</None>
37+
<Compile Remove="IAntResponse.cs" />
4038
</ItemGroup>
4139

4240
<ItemGroup>
@@ -46,4 +44,15 @@
4644
</PackageReference>
4745
</ItemGroup>
4846

47+
<ItemGroup>
48+
<None Update="PackageLogo.png">
49+
<Pack>True</Pack>
50+
<PackagePath>\</PackagePath>
51+
</None>
52+
<None Update="readme.md">
53+
<Pack>True</Pack>
54+
<PackagePath>\</PackagePath>
55+
</None>
56+
</ItemGroup>
57+
4958
</Project>

AntRadioInterface/IAntChannel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ public interface IAntChannel : IDisposable
129129

130130
#region ANT Channel Functions
131131

132+
/// <summary>Gets the channel number.</summary>
133+
/// <returns>ANT channel number.</returns>
134+
byte ChannelNumber { get; }
135+
132136
/// <summary>
133137
/// Returns current channel status.
134138
/// Throws exception on timeout.

AntRadioInterface/IAntRadio.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,40 @@ public interface IAntRadio
138138
{
139139
/// <summary>Occurs when radio response has been received.</summary>
140140
event EventHandler<AntResponse> RadioResponse;
141+
142+
/// <summary>Initializes the ANT radio for continuous scan mode.</summary>
143+
/// <returns>
144+
/// Returns an array of ANT channels. The first element of the array (ANT channel 0) is used for continuous
145+
/// scan mode to receive broadcast messages from ANT master devices. The remaining channels
146+
/// should be configured so messages may be sent to ANT master devices.
147+
/// </returns>
148+
/// <remarks>
149+
/// Implementors typically would perform the following setup -
150+
/// <code>
151+
/// public IAntChannel[] InitializeContinuousScanMode()
152+
/// {
153+
/// IAntChannel[] channels = new IAntChannel[NumChannels];
154+
///
155+
/// // configure channel 0 for continuous scan mode
156+
/// SetNetworkKey(0, new byte[] { 0xB9, 0xA5, 0x21, 0xFB, 0xBD, 0x72, 0xC3, 0x45 });
157+
/// EnableRxExtendedMessages(true);
158+
/// channels[0] = GetChannel(0);
159+
/// channels[0].AssignChannel(ChannelType.BaseSlaveReceive, 0, 500);
160+
/// channels[0].SetChannelID(new ChannelId(0), 500);
161+
/// channels[0].SetChannelFreq(57, 500);
162+
/// OpenRxScanMode();
163+
///
164+
/// // assign channels for devices to use for sending messages
165+
/// for (int i = 1; i &lt; NumChannels; i++)
166+
/// {
167+
/// channels[i] = GetChannel(i);
168+
/// _ = channels[i].AssignChannel(ChannelType.BaseSlaveReceive, 0, 500);
169+
/// }
170+
/// return channels;
171+
/// }
172+
/// </code>
173+
/// </remarks>
174+
IAntChannel[] InitializeContinuousScanMode();
141175
/// <summary>Cancels the transfers.</summary>
142176
/// <param name="cancelWaitTime">The cancel wait time.</param>
143177
void CancelTransfers(int cancelWaitTime);

AntRadioInterface/PackageLogo.png

73.8 KB
Loading

0 commit comments

Comments
 (0)