Skip to content

Commit 2eb4bf1

Browse files
authored
Merge pull request #95 from WildernessLabs/v2.0.1.2
Release 2.0.1.2
2 parents b84d0b6 + a804843 commit 2eb4bf1

15 files changed

+273
-159
lines changed

Source/Clima_Demo/MeadowApp.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,5 @@ private void OnMeadowSystemError(MeadowSystemErrorInfo error, bool recommendRese
4848
}
4949

5050
forceReset = recommendReset;
51-
52-
// override the reset recommendation
53-
//forceReset = false;
54-
}
55-
56-
private void OnMeadowSystemError(object sender, MeadowSystemErrorInfo e)
57-
{
58-
Resolver.Log.Error($"App has detected a system error: {e.Message}");
59-
60-
if (e is Esp32SystemErrorInfo esp)
61-
{
62-
Resolver.Log.Error($"ESP function: {esp.Function}");
63-
Resolver.Log.Error($"ESP status code: {esp.StatusCode}");
64-
}
65-
66-
if (e.Exception != null)
67-
{
68-
Resolver.Log.Error($"Exception: {e.Exception.Message}");
69-
Resolver.Log.Error($"ErrorNumber: {e.ErrorNumber}");
70-
Resolver.Log.Error($"HResult: {e.Exception.HResult}");
71-
72-
if (e.Exception.InnerException != null)
73-
{
74-
Resolver.Log.Error($"InnerException: {e.Exception.InnerException.Message}");
75-
Resolver.Log.Error($"HResult: {e.Exception.InnerException.HResult}");
76-
}
77-
}
7851
}
7952
}

Source/Meadow.Clima/ClimaAppBase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Meadow.Devices;
44

5+
/// <summary>
6+
/// Base class for Clima applications.
7+
/// </summary>
58
public abstract class ClimaAppBase : App<F7CoreComputeV2, ClimaHardwareProvider, IClimaHardware>
6-
{
7-
}
9+
{ }

Source/Meadow.Clima/ClimaHardwareProvider.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ namespace Meadow.Devices;
1111
/// </summary>
1212
public class ClimaHardwareProvider : IMeadowAppEmbeddedHardwareProvider<IClimaHardware>
1313
{
14+
/// <summary>
15+
/// Initializes a new instance of the ClimaHardwareProvider class.
16+
/// </summary>
1417
public ClimaHardwareProvider()
15-
{
16-
}
18+
{ }
1719

20+
/// <summary>
21+
/// Creates an instance of the Clima hardware.
22+
/// </summary>
23+
/// <returns>An instance of IClimaHardware.</returns>
1824
public static IClimaHardware Create()
1925
{
2026
return new ClimaHardwareProvider()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
namespace Meadow.Devices.Clima.Constants;
22

3+
/// <summary>
4+
/// Enumeration of cloud event IDs.
5+
/// </summary>
36
public enum CloudEventIds
47
{
8+
/// <summary>
9+
/// Event ID for when the device starts.
10+
/// </summary>
511
DeviceStarted = 100,
12+
13+
/// <summary>
14+
/// Event ID for telemetry data.
15+
/// </summary>
616
Telemetry = 110,
17+
18+
/// <summary>
19+
/// Event ID for booting from a crash.
20+
/// </summary>
721
BootFromCrash = 200
822
}

Source/Meadow.Clima/Controllers/CloudController.cs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77

88
namespace Meadow.Devices.Clima.Controllers;
99

10+
/// <summary>
11+
/// Controller for handling cloud-related operations.
12+
/// </summary>
1013
public class CloudController
1114
{
15+
/// <summary>
16+
/// Waits for all data to be sent to the cloud.
17+
/// </summary>
1218
public async Task WaitForDataToSend()
1319
{
1420
// TODO: add a timeout here
@@ -20,27 +26,31 @@ public async Task WaitForDataToSend()
2026
Resolver.Log.Info($"All cloud data has been sent");
2127
}
2228

29+
/// <summary>
30+
/// Logs the application startup after a crash.
31+
/// </summary>
2332
public void LogAppStartupAfterCrash()
2433
{
2534
SendEvent(CloudEventIds.DeviceStarted, $"Device restarted after crash");
2635
}
2736

37+
/// <summary>
38+
/// Logs the application startup with the specified hardware revision.
39+
/// </summary>
40+
/// <param name="hardwareRevision">The hardware revision of the device.</param>
2841
public void LogAppStartup(string hardwareRevision)
2942
{
3043
SendEvent(CloudEventIds.DeviceStarted, $"Device started (hardware {hardwareRevision})");
3144
}
3245

46+
/// <summary>
47+
/// Logs the device information including name and location.
48+
/// </summary>
49+
/// <param name="deviceName">The name of the device.</param>
50+
/// <param name="latitiude">The latitude of the device location.</param>
51+
/// <param name="longitude">The longitude of the device location.</param>
3352
public void LogDeviceInfo(string deviceName, double latitiude, double longitude)
3453
{
35-
// {
36-
// "description": "Clima Boot Telemetry",
37-
// "eventId": 109,
38-
// "timestamp": "2024-05-20T22:25:15.862Z",
39-
// "measurements": {
40-
// "lat": 34.2277472,
41-
// "long": -118.2273136
42-
// }
43-
// }
4454
var cloudEvent = new CloudEvent
4555
{
4656
Description = "Clima Position Telemetry",
@@ -51,19 +61,33 @@ public void LogDeviceInfo(string deviceName, double latitiude, double longitude)
5161
cloudEvent.Measurements.Add("device_name", deviceName);
5262
cloudEvent.Measurements.Add("lat", latitiude);
5363
cloudEvent.Measurements.Add("long", longitude);
54-
64+
5565
SendEvent(cloudEvent);
5666
}
67+
68+
/// <summary>
69+
/// Logs a warning message.
70+
/// </summary>
71+
/// <param name="message">The warning message to log.</param>
5772
public void LogWarning(string message)
5873
{
5974
SendLog(message, "warning");
6075
}
6176

77+
/// <summary>
78+
/// Logs an informational message.
79+
/// </summary>
80+
/// <param name="message">The informational message to log.</param>
6281
public void LogMessage(string message)
6382
{
6483
SendLog(message, "information");
6584
}
6685

86+
/// <summary>
87+
/// Logs telemetry data from sensors and power data.
88+
/// </summary>
89+
/// <param name="sensorData">The sensor data to log.</param>
90+
/// <param name="powerData">The power data to log.</param>
6791
public void LogTelemetry(SensorData sensorData, PowerData powerData)
6892
{
6993
var measurements = sensorData

Source/Meadow.Clima/Controllers/LocationController.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,27 @@
44

55
namespace Meadow.Devices.Clima.Controllers;
66

7+
/// <summary>
8+
/// Controller for handling GNSS location data.
9+
/// </summary>
710
public class LocationController
811
{
9-
private IGnssSensor gnss;
12+
private readonly IGnssSensor? gnss = null;
1013

14+
/// <summary>
15+
/// Gets or sets a value indicating whether to log data.
16+
/// </summary>
1117
public bool LogData { get; set; } = false;
1218

13-
public event EventHandler<GnssPositionInfo> PositionReceived;
19+
/// <summary>
20+
/// Event that is triggered when a GNSS position is received.
21+
/// </summary>
22+
public event EventHandler<GnssPositionInfo>? PositionReceived = null;
1423

24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="LocationController"/> class.
26+
/// </summary>
27+
/// <param name="clima">The Clima hardware interface.</param>
1528
public LocationController(IClimaHardware clima)
1629
{
1730
if (clima.Gnss is { } gnss)
@@ -31,7 +44,7 @@ private void OnGnssDataReceived(object sender, IGnssResult e)
3144
// we only need one position fix - weather stations don't move
3245
Resolver.Log.InfoIf(LogData, $"GNSS Position: lat: [{pi.Position.Latitude}], long: [{pi.Position.Longitude}]");
3346
PositionReceived?.Invoke(this, pi);
34-
gnss.StopUpdating();
47+
gnss?.StopUpdating();
3548
}
3649
}
3750
}

Source/Meadow.Clima/Controllers/NetworkController.cs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,44 @@
55

66
namespace Meadow.Devices.Clima.Controllers;
77

8+
/// <summary>
9+
/// Controller for managing network connections and reporting network status.
10+
/// </summary>
811
public class NetworkController
912
{
13+
/// <summary>
14+
/// Event triggered when the connection state changes.
15+
/// </summary>
1016
public event EventHandler<bool>? ConnectionStateChanged;
17+
18+
/// <summary>
19+
/// Event triggered when the network is down for a specified period.
20+
/// </summary>
1121
public event EventHandler<TimeSpan>? NetworkDown;
1222

1323
private readonly INetworkAdapter networkAdapter;
1424
private DateTimeOffset? lastDown;
15-
private Timer downEventTimer;
16-
17-
public bool IsConnected => networkAdapter.IsConnected;
18-
public TimeSpan DownTime => lastDown == null ? TimeSpan.Zero : DateTime.UtcNow - lastDown.Value;
19-
public TimeSpan DownEventPeriod { get; } = TimeSpan.FromSeconds(30);
20-
25+
private readonly Timer downEventTimer;
26+
27+
/// <summary>
28+
/// Gets a value indicating whether the network is connected.
29+
/// </summary>
30+
public bool IsConnected { get; private set; }
31+
32+
/// <summary>
33+
/// Gets the total time the network has been down.
34+
/// </summary>
35+
public TimeSpan DownTime { get; private set; }
36+
37+
/// <summary>
38+
/// Gets the period for triggering network down events.
39+
/// </summary>
40+
public TimeSpan DownEventPeriod { get; private set; }
41+
42+
/// <summary>
43+
/// Initializes a new instance of the <see cref="NetworkController"/> class.
44+
/// </summary>
45+
/// <param name="networkAdapter">The network adapter</param>
2146
public NetworkController(INetworkAdapter networkAdapter)
2247
{
2348
if (networkAdapter is IWiFiNetworkAdapter wifi)
@@ -38,6 +63,10 @@ public NetworkController(INetworkAdapter networkAdapter)
3863
downEventTimer = new Timer(DownEventTimerProc, null, -1, -1);
3964
}
4065

66+
/// <summary>
67+
/// Connects to the cloud.
68+
/// </summary>
69+
/// <returns>A task representing the asynchronous operation.</returns>
4170
public async Task<bool> ConnectToCloud()
4271
{
4372
if (networkAdapter is IWiFiNetworkAdapter wifi)
@@ -54,6 +83,10 @@ public async Task<bool> ConnectToCloud()
5483
return networkAdapter.IsConnected;
5584
}
5685

86+
/// <summary>
87+
/// Shuts down the network.
88+
/// </summary>
89+
/// <returns>A task representing the asynchronous operation.</returns>
5790
public async Task ShutdownNetwork()
5891
{
5992
if (networkAdapter is IWiFiNetworkAdapter wifi)

0 commit comments

Comments
 (0)