Skip to content

Commit efecae4

Browse files
committed
Changes for review
1 parent 996fce1 commit efecae4

11 files changed

+151
-67
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ document language: [English](README.md) | [简体中文](README.zh-cn.md)
1313
|:-|---|---|
1414
| nanoFramework.Networking.Thread | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.Networking.Thread/_apis/build/status/nanoFramework.Networking.Thread?repoName=nanoframework%2FnanoFramework.Networking.Thread&branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.Networking.Thread/_build/latest?definitionId=85&repoName=nanoframework%2FnanoFramework.Networking.Thread&branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.Networking.Thread.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.Networking.Thread/) |
1515

16-
1716
# nanoFramework.Networking.Thread
17+
1818
.NET nanoFramework library for working with OpenThread networking.
1919

2020
The OpenThread network is based on IPV6 and requires a firmware which has IPV6 and Thread enabled.
@@ -38,22 +38,21 @@ document language: [English](README.md) | [简体中文](README.zh-cn.md)
3838

3939
This can be one of the types.
4040

41-
- Router
42-
- End device
43-
- Sleepy end device
41+
- Router
42+
- End device
43+
- Sleepy end device
4444

4545
The **Router** and **End device** are for a powered devices.
4646
The **End device** will stay in the **child** role and won't ever be promoted to a router.
4747
The **Router** type will start with the child role and be promoted to the **router** or **leader** roles as required.
4848

49-
The **Sleepy end device** are for battery operated devices and don't stay connected to
50-
the mesh network to save on battery. It will regularly poll its connected router for any messages. Routers connected
49+
The **Sleepy end device** are for battery operated devices and don't stay connected to
50+
the mesh network to save on battery. It will regularly poll its connected router for any messages. Routers connected
5151
to a sleepy end device will store and forward messages.
5252

5353
The devices can take on a number of roles as already mentioned.
5454
These are child, Router or Leader.
5555

56-
5756
### Devices with a built-in 802.15.4 radio
5857

5958
Creating openThread object for a device with a built-in 802.15.4 radio.
@@ -76,7 +75,6 @@ This code creates the stack using the network processor connected by UART on dev
7675
OpenThread ot = OpenThread.CreateThreadWithUartRadio(ThreadDeviceType.Router, 1);
7776
```
7877

79-
8078
#### Connected via a SPI port.**
8179

8280
Create the openThread object specifying the SPI port connected to the co-processor.
@@ -118,7 +116,6 @@ If not it will wait about 2 minutes and create a new network using credentials i
118116
Monitor the state change events to know when the device has attached to the mesh network.
119117
See later section on events raised by the OpenThread class.
120118

121-
122119
## Joining a existing network using the commissioner.
123120

124121
To attach a device to an existing network where the network credentials are unknown.
@@ -157,6 +154,7 @@ ot.OnConsoleOutputAvailable += Ot_OnConsoleOutputAvailable;
157154
```
158155

159156
### OnStatusChanged
157+
160158
This event is fired when the state of the Thread stack changes.
161159
The main states that need to be monitored are the Detached and Attached events.
162160
There will also be events for network interface up/down, an IPV6 address has been assigned and when the stack has been started or stopped.
@@ -181,6 +179,7 @@ private static void Ot_OnStatusChanged(OpenThread sender, OpenThreadStateChangeE
181179
```
182180

183181
### OnRoleChanged
182+
184183
This event is fired when the role of the device changes.
185184

186185
The role can be one of the following:
@@ -193,7 +192,6 @@ The role can be one of the following:
193192
| Router | The device is a router and has 0 or more child devices. |
194193
| Leader | The device is a router that has been promoted to leader. |
195194

196-
197195
### OnConsoleOutputAvailable
198196

199197
This event is fired when unsolicited messages are received on Command Line Interface (CLI).
@@ -234,7 +232,6 @@ For examples on using sockets for communication see the Thread sockets samples
234232
As the OpenThread is based on an IP networking it also supports communication via TCP/IP. All the
235233
normal methods of communicating with TCP/IP will work.
236234

237-
238235
## OpenThread CLI interface.
239236

240237
The OpenThread library has a large number of different APIs.
@@ -255,6 +252,7 @@ This will send a command to the CLI and wait for all strings returned until a 'd
255252
These strings will be returned directly by the command excluding the 'done' message.
256253

257254
CLI command to return all the IPV6 addresses assigned to the interface.
255+
258256
```c#
259257
string[] results = ot.CommandLineInputAndWaitResponse("ipaddr");
260258
```

Tests/DataSetTests/nano.runsettings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<nanoFrameworkAdapter>
1111
<Logging>None</Logging> <!--Set to the desired level of logging for Unit Test execution. Possible values are: None, Detailed, Verbose, Error. -->
1212
<IsRealHardware>False</IsRealHardware><!--Set to true to run tests on real hardware. -->
13-
<RealHardwarePort>COM3</RealHardwarePort><!--Specify the COM port to use to connect to a nanoDevice. If none is specified, a device detection is performed and the 1st available one will be used. -->
13+
<RealHardwarePort></RealHardwarePort><!--Specify the COM port to use to connect to a nanoDevice. If none is specified, a device detection is performed and the 1st available one will be used. -->
1414
<CLRVersion></CLRVersion><!--Specify the nanoCLR version to use. If not specified, the latest available will be used. -->
1515
<PathToLocalCLRInstance></PathToLocalCLRInstance><!--Specify the path to a local nanoCLR instance. If not specified, the default one installed with nanoclr CLR witll be used. -->
1616
</nanoFrameworkAdapter>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
using nanoFramework.Runtime.Events;
7+
8+
namespace nanoFramework.Networking.Thread
9+
{
10+
// <summary>
11+
/// Event arguments for the OnConsoleOutputAvailable Event.
12+
/// </summary>
13+
public class OpenThreadConsoleOutputAvailableArgs : BaseEvent
14+
{
15+
private string[] _consoleLines;
16+
17+
/// <summary>
18+
/// Constructor.
19+
/// </summary>
20+
public OpenThreadConsoleOutputAvailableArgs() : base()
21+
{
22+
_consoleLines = new string[0];
23+
}
24+
25+
/// <summary>
26+
/// Currently available console lines. 0 or more strings.
27+
/// </summary>
28+
public string[] consoleLines { get => _consoleLines; set => _consoleLines = value; }
29+
}
30+
}

nanoFramework.Networking.Thread/OpenThreadDataset.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class OpenThreadDataset
2424
/// Used to flags properties in use.
2525
/// </summary>
2626
[Flags]
27-
enum componentInUseFlags
27+
private enum componentInUseFlags
2828
{
2929
None = 0,
3030
channel = 1,
@@ -45,7 +45,7 @@ public OpenThreadDataset()
4545
}
4646

4747
/// <summary>
48-
/// Get or Set the Thread Network Key.
48+
/// Get or set the Thread Network Key.
4949
/// Must be a byte[8].
5050
/// </summary>
5151
/// <remarks>
@@ -61,6 +61,7 @@ public byte[] NetworkKey
6161
{
6262
throw new ArgumentException();
6363
}
64+
6465
_networkKey = value;
6566
_inUseFlags |= componentInUseFlags.networkKey;
6667
}

nanoFramework.Networking.Thread/OpenThreadEventListener.cs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,6 @@ enum OpenThreadEventType
1919
JoinerComplete
2020
};
2121

22-
/// <summary>
23-
/// This class represents the event arguments for OnStatusChanged.
24-
/// </summary>
25-
public class OpenThreadStateChangeEventArgs : BaseEvent
26-
{
27-
/// <summary>
28-
/// Current state of OpenThread stack.
29-
/// </summary>
30-
public int currentState;
31-
}
32-
33-
/// <summary>
34-
/// This class represents the event arguments for OnRoleChanged.
35-
/// </summary>
36-
public class OpenThreadRoleChangeEventArgs : BaseEvent
37-
{
38-
/// <summary>
39-
/// The previous thread device role before current change.
40-
/// </summary>
41-
public ThreadDeviceRole previousRole;
42-
43-
/// <summary>
44-
/// Current role of device.
45-
/// </summary>
46-
public ThreadDeviceRole currentRole;
47-
}
48-
49-
/// <summary>
50-
/// Event arguments for the OnConsoleOutputAvailable Event.
51-
/// </summary>
52-
public class OpenThreadConsoleOutputAvailableArgs : BaseEvent
53-
{
54-
/// <summary>
55-
/// Currently available console lines. 0 or more strings.
56-
/// </summary>
57-
public string[] consoleLines;
58-
}
59-
60-
internal class OpenThreadJoinerStartCompleteEventArgs : BaseEvent
61-
{
62-
/// <summary>
63-
/// Joiner start error or 0
64-
/// </summary>
65-
public int error;
66-
}
67-
6822
internal class OpenThreadEventListener : IEventProcessor, IEventListener
6923
{
7024
// Reference to current open thread object for passing events.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
using nanoFramework.Runtime.Events;
7+
8+
namespace nanoFramework.Networking.Thread
9+
{
10+
internal class OpenThreadJoinerStartCompleteEventArgs : BaseEvent
11+
{
12+
private int _error;
13+
14+
internal OpenThreadJoinerStartCompleteEventArgs() : base()
15+
{
16+
_error = 0;
17+
}
18+
19+
/// <summary>
20+
/// Joiner start error or 0 if successful.
21+
/// </summary>
22+
public int error { get => _error; set => value = _error; }
23+
}
24+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
using nanoFramework.Runtime.Events;
7+
8+
namespace nanoFramework.Networking.Thread
9+
{
10+
/// <summary>
11+
/// This class represents the event arguments for OnRoleChanged.
12+
/// </summary>
13+
public class OpenThreadRoleChangeEventArgs : BaseEvent
14+
{
15+
private ThreadDeviceRole _previousRole;
16+
private ThreadDeviceRole _currentRole;
17+
18+
/// <summary>
19+
/// Constructor.
20+
/// </summary>
21+
public OpenThreadRoleChangeEventArgs() : base()
22+
{
23+
}
24+
25+
/// <summary>
26+
/// The previous thread device role before current change.
27+
/// </summary>
28+
public ThreadDeviceRole previousRole { get => _previousRole; set => _previousRole = value; }
29+
30+
/// <summary>
31+
/// Current role of device.
32+
/// </summary>
33+
public ThreadDeviceRole currentRole { get => _currentRole; set => _currentRole = value; }
34+
}
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
//
3+
// Copyright (c) .NET Foundation and Contributors
4+
// See LICENSE file in the project root for full license information.
5+
//
6+
7+
using nanoFramework.Runtime.Events;
8+
9+
namespace nanoFramework.Networking.Thread
10+
{
11+
/// <summary>
12+
/// This class represents the event arguments for OnStatusChanged.
13+
/// </summary>
14+
public class OpenThreadStateChangeEventArgs : BaseEvent
15+
{
16+
private int _currentState;
17+
18+
/// <summary>
19+
/// Constructor.
20+
/// </summary>
21+
public OpenThreadStateChangeEventArgs() : base()
22+
{
23+
}
24+
25+
/// <summary>
26+
/// Current state of OpenThread stack.
27+
/// </summary>
28+
public int currentState { get => _currentState; set => _currentState = value; }
29+
}
30+
}

nanoFramework.Networking.Thread/ThreadDeviceState.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,36 @@ public enum ThreadDeviceState
1414
/// <summary>
1515
/// Thread network stack has started.
1616
/// </summary>
17-
OPENTHREAD_EVENT_START = 0,
17+
Start = 0,
18+
1819
/// <summary>
1920
/// Thread network stack has stopped.
2021
/// </summary>
21-
OPENTHREAD_EVENT_STOP = 1,
22+
Stop = 1,
23+
2224
/// <summary>
2325
/// Thread detached from any mesh network.
2426
/// </summary>
25-
OPENTHREAD_EVENT_DETACHED = 2,
27+
Detached = 2,
28+
2629
/// <summary>
2730
/// THread attached to mesh network.
2831
/// </summary>
29-
OPENTHREAD_EVENT_ATTACHED = 3,
32+
Attached = 3,
33+
3034
/// <summary>
3135
/// Network interface is up.
3236
/// </summary>
33-
OPENTHREAD_EVENT_IF_UP = 5,
37+
InterfaceUp = 5,
38+
3439
/// <summary>
3540
/// Network interface is down.
3641
/// </summary>
37-
OPENTHREAD_EVENT_IF_DOWN = 6,
42+
InterfaceDown = 6,
43+
3844
/// <summary>
3945
/// Network interface received IPV6 address.
4046
/// </summary>
41-
OPENTHREAD_EVENT_GOT_IP6 = 7,
47+
GotIpv6 = 7,
4248
}
4349
}

nanoFramework.Networking.Thread/ThreadRadioConnection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ public enum RadioConnection
1616
/// Connected via a native radio which is part of SOC.
1717
/// </summary>
1818
Native,
19+
1920
/// <summary>
2021
/// Connected via a UART port.
2122
/// </summary>
2223
Uart,
24+
2325
/// <summary>
2426
/// Connected via a SPI bus.
2527
/// </summary>

0 commit comments

Comments
 (0)