Skip to content

Commit b59454a

Browse files
authored
Remove tx functions
* removed tx rx functions * Added buffered IO support * Updated the readme * Updated version numbers
1 parent ee45212 commit b59454a

43 files changed

Lines changed: 1835 additions & 2693 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,7 @@ Transmit a packet of data with a specific transmit timeout. The transmit control
9393
rfmUsbDevice.Transmit(new List<byte>() { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA }, 1000);
9494
```
9595

96-
## Transmit And Receive
97-
98-
Transmit a packet and wait for a response with the default transmit and receive timeouts.
99-
100-
```csharp
101-
// Transmit data and wait for a response with the default
102-
var response = rfmUsbDevice.TransmitReceive(new List<byte>() { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA });
103-
```
104-
105-
Transmit a packet and wait for a response with the default receive timeouts and a specified transmit timeout.
106-
107-
```csharp
108-
// Transmit data and wait for
109-
var response = rfmUsbDevice.TransmitReceive(new List<byte>() { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA }, 1000);
110-
```
111-
112-
Transmit a packet and wait for a response with a specified transmit and receive timeouts.
113-
114-
```csharp
115-
// Transmit data and wait for
116-
var response = rfmUsbDevice.TransmitReceive(new List<byte>() { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA }, 1000, 1000 );
117-
```
118-
119-
## Irqs
96+
## Interrupts
12097

12198
Set the Dio pin Irq mask.
12299

@@ -150,3 +127,94 @@ if ((rfmUsbDevice.Irq & Irq.PayloadReady) == Irq.PayloadReady)
150127
// Process packet
151128
}
152129
```
130+
131+
## Buffered Read And Writes
132+
133+
The maximum message size supported by direct read and write of the FIFO is limited to 64 bytes. To support message transmission and reception up to a maximum size of X bytes the RfmUsb IO buffer must be used.
134+
135+
### Receive IO Buffer
136+
137+
The steps required to receive a message via the IO buffer.
138+
139+
* Configure the RfmUsb radio
140+
* Set the Dio mapping for **Dio0** to **DioMapping1** to capture the **PayloadReady** Irq
141+
* Set the Dio mapping for **Dio1** to **DioMapping2** to capture the **FifoNotEmpty** Irq
142+
* Setup the **PacketFormat** to either fixed or variable length
143+
* Set **PayloadLength** to 0xFF
144+
* Enable the IO buffer via the **BufferedIoEnable** setting
145+
* Set the radio **Mode** to **RX**
146+
* Wait for the **PayloadReady** Irq
147+
* Read the message bytes to the IO buffer via the **Stream**
148+
149+
```csharp
150+
// Configure the radio
151+
InitialiseRadioOpenThings(SerialPort, BaudRate);
152+
153+
// Attach event handlers
154+
AttachEventHandlers(console);
155+
156+
// Enable DIO0 to capture payload ready IRQ
157+
rfmUsbDevice.SetDioMapping(Dio.Dio0, DioMapping.DioMapping1);
158+
// Enable DIO1 to capture fifo level IRQ for buffered read
159+
rfmUsbDevice.SetDioMapping(Dio.Dio1, DioMapping.DioMapping2);
160+
// Set the Irq mask
161+
rfmUsbDevice.DioInterruptMask = DioIrq.Dio0 | DioIrq.Dio1;
162+
// Enable the Buffered Io
163+
rfmUsbDevice.BufferedIoEnable = true;
164+
// Set the the payload length to 0xFF
165+
rfmUsbDevice.PayloadLength = 0xFF;
166+
// Set the mode to rx
167+
rfmUsbDevice.Mode = Mode.Rx;
168+
169+
// Wait for Irq signal
170+
SignalSource signalSource = WaitForSignal();
171+
172+
if (signalSource == SignalSource.Irq)
173+
{
174+
if ((rfmUsbDevice.IrqFlags & Rfm69IrqFlags.PayloadReady) == Rfm69IrqFlags.PayloadReady)
175+
{
176+
rfmUsbDevice.Mode = Mode.Standby;
177+
178+
byte[] payload = new byte[rfmUsbDevice.Stream.Length];
179+
180+
// Read the stream
181+
rfmUsbDevice.Stream.Read(payload, 0, payload.Length);
182+
183+
// Process the payload
184+
// .............
185+
```
186+
187+
### Transmit IO Buffer
188+
189+
The steps required to transmit a message via the IO buffer.
190+
191+
* Configure the RfmUsb radio
192+
* Setup the **PacketFormat** to either fixed or variable length
193+
* Enable the IO buffer via the **BufferedIoEnable** setting
194+
* Set the radio **Mode** to **TX**
195+
* Write the message bytes to the IO buffer via the **Stream**
196+
197+
```csharp
198+
// Configure the radio
199+
InitialiseRadioOpenThings(SerialPort, BaudRate);
200+
201+
// Attach event handlers
202+
AttachEventHandlers(console);
203+
204+
// Enable DIO0 to capture payload ready IRQ
205+
rfmUsbDevice.SetDioMapping(Dio.Dio0, DioMapping.DioMapping0);
206+
// Set the Irq mask
207+
rfmUsbDevice.DioInterruptMask = DioIrq.Dio0;
208+
// Enable the Buffered Io
209+
rfmUsbDevice.BufferedIoEnable = true;
210+
// Set the the payload length to 0xFF
211+
rfmUsbDevice.PayloadLength = 0xFF;
212+
// Set the mode to TX
213+
rfmUsbDevice.Mode = Mode.Tx;
214+
215+
// Prepare payload
216+
byte[] payload = new byte[10];
217+
218+
// Write the stream
219+
rfmUsbDevice.Stream.Write(payload, 0, payload.Length);
220+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is used by Code Analysis to maintain SuppressMessage
2+
// attributes that are applied to this project.
3+
// Project-level suppressions either have no target or are given
4+
// a specific target and scoped to a namespace, type, member, etc.
5+
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
[assembly: SuppressMessage("Naming", "VSSpell001:Spell Check", Justification = "<Pending>", Scope = "namespace", Target = "~N:RfmUsb.Net.IntTests")]

RfmUsb.Net.IntTests/Rfm69Tests.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
* SOFTWARE.
2323
*/
2424

25+
26+
// Ignore Spelling: Lna Bw Aes Rssi Dagc Dcc Dio Fei Irq Initalise
27+
2528
using FluentAssertions;
2629
using Microsoft.Extensions.DependencyInjection;
2730
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -35,7 +38,7 @@ public class Rfm69Tests : RfmTestCommon
3538

3639
public Rfm69Tests()
3740
{
38-
_rfm69 = _serviceProvider.GetService<IRfm69>();
41+
_rfm69 = _serviceProvider.GetService<IRfm69>() ?? throw new NullReferenceException($"Unable to resolve {nameof(IRfm69)}");
3942
RfmBase = _rfm69;
4043
}
4144

@@ -131,7 +134,7 @@ public void TestDccFreqAfc(DccFreq expected)
131134
[DataRow(DioIrq.Dio3)]
132135
[DataRow(DioIrq.Dio4)]
133136
[DataRow(DioIrq.Dio5)]
134-
public void TestDioInterrupMask(DioIrq expected)
137+
public void TestDioInterruptMask(DioIrq expected)
135138
{
136139
TestAssignedValue(expected, () => _rfm69.DioInterruptMask, (v) => _rfm69.DioInterruptMask = v);
137140
}
@@ -269,15 +272,15 @@ public void TestIntermediateMode(IntermediateMode expected)
269272
}
270273

271274
[TestMethod]
272-
public void TestListenCoefficentIdle()
275+
public void TestListenCoefficientIdle()
273276
{
274-
TestRange(() => _rfm69.ListenCoefficentIdle, (v) => _rfm69.ListenCoefficentIdle = v);
277+
TestRange(() => _rfm69.ListenCoefficientIdle, (v) => _rfm69.ListenCoefficientIdle = v);
275278
}
276279

277280
[TestMethod]
278-
public void TestListenCoefficentRx()
281+
public void TestListenCoefficientRx()
279282
{
280-
TestRange(() => _rfm69.ListenCoefficentRx, (v) => _rfm69.ListenCoefficentRx = v);
283+
TestRange(() => _rfm69.ListenCoefficientRx, (v) => _rfm69.ListenCoefficientRx = v);
281284
}
282285

283286
[TestMethod]
@@ -367,7 +370,7 @@ public void TestSequencer()
367370
[TestMethod]
368371
public void TestSetAesKey()
369372
{
370-
_rfm69.Sync = new List<byte> { 0xAA, 0x55, 0xAA, 0x55 };
373+
_rfm69.SetAesKey(new List<byte> { 0xAA, 0x55, 0xAA, 0x55 });
371374
}
372375

373376
[TestMethod]

RfmUsb.Net.IntTests/Rfm9xFskTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class Rfm9xFskTests : RfmTestCommon
3535

3636
public Rfm9xFskTests()
3737
{
38-
_rfm9x = _serviceProvider.GetService<IRfm9x>();
38+
_rfm9x = _serviceProvider.GetService<IRfm9x>() ?? throw new NullReferenceException($"Unable to resolve {nameof(IRfm9x)}");
3939
RfmBase = _rfm9x;
4040
}
4141

@@ -325,7 +325,7 @@ public void TestPreambleDetectorSize(PreambleDetectorSize expected)
325325
[TestMethod]
326326
public void TestPreambleDetectorTotal()
327327
{
328-
TestRange<byte>(() => _rfm9x.PreambleDetectorTotalerance, (v) => _rfm9x.PreambleDetectorTotalerance = v, 0, 0x0F);
328+
TestRange<byte>(() => _rfm9x.PreambleDetectorTolerance, (v) => _rfm9x.PreambleDetectorTolerance = v, 0, 0x0F);
329329
}
330330

331331
[TestMethod]

RfmUsb.Net.IntTests/Rfm9xLoraTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class Rfm9xLoraTests : RfmTestBase
3535

3636
public Rfm9xLoraTests()
3737
{
38-
_rfm9x = _serviceProvider.GetService<IRfm9x>();
38+
_rfm9x = _serviceProvider.GetService<IRfm9x>() ?? throw new NullReferenceException($"Unable to resolve {nameof(IRfm9x)}");
3939
RfmBase = _rfm9x;
4040
}
4141

RfmUsb.Net.IntTests/RfmTestBase.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using Microsoft.Extensions.Configuration;
2727
using Microsoft.Extensions.DependencyInjection;
2828
using Microsoft.VisualStudio.TestTools.UnitTesting;
29+
using RfmUsb.Net.Exceptions;
2930
using RfmUsb.Net.Ports;
3031
using Serilog;
3132
using Serilog.Core;
@@ -68,6 +69,67 @@ public RfmTestBase()
6869

6970
public TestContext TestContext { get; set; }
7071

72+
[TestMethod]
73+
public void TestReadStreamDisabled()
74+
{
75+
// Arrange
76+
var bytes = new byte[1];
77+
78+
RfmBase.BufferedIoEnable = false;
79+
80+
// Act
81+
Action action = () => RfmBase.Stream.Read(bytes);
82+
83+
// Assert
84+
action.Should().Throw<RfmUsbBufferedIoNotEnabledException>();
85+
}
86+
87+
[TestMethod]
88+
public void TestReadStreamEnabled()
89+
{
90+
// Arrange
91+
var bytes = new byte[10];
92+
93+
RfmBase.BufferedIoEnable = true;
94+
95+
// Act
96+
RfmBase.Stream.Read(bytes);
97+
}
98+
99+
[TestMethod]
100+
public void TestWriteStreamDisabled()
101+
{
102+
// Arrange
103+
var bytes = new byte[1];
104+
var rand = new Random();
105+
106+
rand.NextBytes(bytes);
107+
108+
RfmBase.BufferedIoEnable = false;
109+
110+
// Act
111+
Action action = () => RfmBase.Stream.Write(bytes);
112+
113+
// Assert
114+
action.Should().Throw<RfmUsbBufferedIoNotEnabledException>();
115+
}
116+
117+
[TestMethod]
118+
[Ignore]
119+
public void TestWriteStreamEnabled()
120+
{
121+
// Arrange
122+
var bytes = new byte[100];
123+
var rand = new Random();
124+
125+
rand.NextBytes(bytes);
126+
127+
RfmBase.BufferedIoEnable = true;
128+
129+
// Act
130+
RfmBase.Stream.Write(bytes);
131+
}
132+
71133
internal static IEnumerable<byte> RandomSequence()
72134
{
73135
Random r = new Random();

RfmUsb.Net.IntTests/RfmTestCommon.cs

Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
using FluentAssertions;
2626
using Microsoft.VisualStudio.TestTools.UnitTesting;
27-
using RfmUsb.Net.Exceptions;
2827

2928
namespace RfmUsb.Net.IntTests
3029
{
@@ -69,6 +68,12 @@ public void TestBroadcastAddress()
6968
TestRange(() => RfmBase.BroadcastAddress, (v) => RfmBase.BroadcastAddress = v);
7069
}
7170

71+
[TestMethod]
72+
public void TestBufferedIoEnable()
73+
{
74+
TestRangeBool(() => RfmBase.BufferedIoEnable, (v) => RfmBase.BufferedIoEnable = v);
75+
}
76+
7277
[TestMethod]
7378
public void TestCrcAutoClearOff()
7479
{
@@ -348,6 +353,7 @@ public void TestSerialNumber()
348353
{
349354
Read(() => RfmBase.SerialNumber);
350355
}
356+
351357
[TestMethod]
352358
public void TestSync()
353359
{
@@ -376,71 +382,6 @@ public void TestTemperatureValue()
376382
}
377383

378384
[TestMethod]
379-
[Ignore]
380-
public void TestTransmit()
381-
{
382-
RfmBase.Transmit(new List<byte>() { 0x00, 0x01, 0x02 });
383-
}
384-
385-
[TestMethod]
386-
[Ignore]
387-
public void TestTransmitReceive()
388-
{
389-
Action action = () => RfmBase.TransmitReceive(new List<byte>() { 0x00, 0x01, 0x02 });
390-
391-
action
392-
.Should()
393-
.Throw<RfmUsbTransmitException>()
394-
.WithMessage("Packet transmission failed: [TX Timeout]");
395-
}
396-
397-
[TestMethod]
398-
[Ignore]
399-
public void TestTransmitReceiveTxRxTimeout()
400-
{
401-
Action action = () => RfmBase.TransmitReceive(new List<byte>() { 0x00, 0x01, 0x02 }, 1000, 1000);
402-
403-
action
404-
.Should()
405-
.Throw<RfmUsbTransmitException>()
406-
.WithMessage("Packet transmission failed: [TX Timeout]");
407-
}
408-
409-
[TestMethod]
410-
[Ignore]
411-
public void TestTransmitReceiveTxTimeout()
412-
{
413-
Action action = () => RfmBase.TransmitReceive(new List<byte>() { 0x00, 0x01, 0x02 }, 1000);
414-
415-
action
416-
.Should()
417-
.Throw<RfmUsbTransmitException>()
418-
.WithMessage("Packet transmission failed: [TX Timeout]");
419-
}
420-
421-
[TestMethod]
422-
[Ignore]
423-
public void TestTransmitWithCountAndInterval()
424-
{
425-
RfmBase.Transmit(new List<byte>() { 0x00, 0x01, 0x02 }, 1, 100);
426-
}
427-
428-
[TestMethod]
429-
[Ignore]
430-
public void TestTransmitWithCountAndIntervalAndTimeout()
431-
{
432-
RfmBase.Transmit(new List<byte>() { 0x00, 0x01, 0x02 }, 1, 100, 1000);
433-
}
434-
435-
[TestMethod]
436-
[Ignore]
437-
public void TestTransmitWithTxCount()
438-
{
439-
RfmBase.Transmit(new List<byte>() { 0x00, 0x01, 0x02 }, 1);
440-
}
441-
442-
[TestMethod]
443-
[Ignore]
444385
public void TestTxStartCondition()
445386
{
446387
TestRangeBool(() => RfmBase.TxStartCondition, (v) => RfmBase.TxStartCondition = v);

0 commit comments

Comments
 (0)