Skip to content

Commit

Permalink
Merge pull request #240 from WildernessLabs/develop
Browse files Browse the repository at this point in the history
RC2
  • Loading branch information
adrianstevens authored Dec 31, 2022
2 parents 770e80a + 6798991 commit 9c518f3
Show file tree
Hide file tree
Showing 41 changed files with 1,203 additions and 536 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ jobs:
path: Meadow.Units
ref: develop

- name: Checkout Meadow.Logging side-by-side
uses: actions/checkout@v2
- name: Checkout Meadow.Logging
uses: actions/checkout@v3
with:
repository: WildernessLabs/Meadow.Logging
path: Meadow.Logging
ref: develop

- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nuget-f7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Set VERSION variable from tag
run: echo "VERSION=0.90.0" >> $GITHUB_ENV
run: echo "VERSION=0.92.5" >> $GITHUB_ENV

- name: Build Meadow.F7
run: dotnet build -c Release source/Meadow.F7/Meadow.F7.csproj /p:Version=${VERSION}
Expand Down
5 changes: 5 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ resources:
type: github
endpoint: WildernessLabs
name: WildernessLabs/Meadow.Units
- repository: MeadowLogging
type: github
endpoint: WildernessLabs
name: WildernessLabs/Meadow.Logging

trigger:
- main
Expand All @@ -39,6 +43,7 @@ stages:
- checkout: self
- checkout: MeadowContracts
- checkout: MeadowUnits
- checkout: MeadowLogging
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
displayName: Use_Nugets
Expand Down
18 changes: 9 additions & 9 deletions source/Meadow.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Units.Tests", "..\..
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Unit.Tests", "Tests\Core.Unit.Tests\Core.Unit.Tests.csproj", "{93DFC566-A413-4039-A0C1-90A42A356386}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Logging", "..\..\Meadow.Logging\lib\Meadow.Logging.csproj", "{AB2ED826-2E09-42F5-9106-BDB956984385}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Update", "Meadow.Update\Meadow.Update.csproj", "{91A73126-30FF-4A8E-BFC6-750053BD51D5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet", "..\..\MQTTnet\Source\MQTTnet\MQTTnet.csproj", "{7E26CCF1-DDB2-4A49-93AA-08F2612A47A8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Logging", "..\..\Meadow.Logging\Source\Meadow.Logging\lib\Meadow.Logging.csproj", "{BC491B8D-D6EF-4AE6-B11D-1A117B6A350D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Core|Any CPU = Core|Any CPU
Expand Down Expand Up @@ -76,12 +76,6 @@ Global
{93DFC566-A413-4039-A0C1-90A42A356386}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93DFC566-A413-4039-A0C1-90A42A356386}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93DFC566-A413-4039-A0C1-90A42A356386}.Release|Any CPU.Build.0 = Release|Any CPU
{AB2ED826-2E09-42F5-9106-BDB956984385}.Core|Any CPU.ActiveCfg = Debug|Any CPU
{AB2ED826-2E09-42F5-9106-BDB956984385}.Core|Any CPU.Build.0 = Debug|Any CPU
{AB2ED826-2E09-42F5-9106-BDB956984385}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB2ED826-2E09-42F5-9106-BDB956984385}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB2ED826-2E09-42F5-9106-BDB956984385}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB2ED826-2E09-42F5-9106-BDB956984385}.Release|Any CPU.Build.0 = Release|Any CPU
{91A73126-30FF-4A8E-BFC6-750053BD51D5}.Core|Any CPU.ActiveCfg = Debug|Any CPU
{91A73126-30FF-4A8E-BFC6-750053BD51D5}.Core|Any CPU.Build.0 = Debug|Any CPU
{91A73126-30FF-4A8E-BFC6-750053BD51D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -94,6 +88,12 @@ Global
{7E26CCF1-DDB2-4A49-93AA-08F2612A47A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E26CCF1-DDB2-4A49-93AA-08F2612A47A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E26CCF1-DDB2-4A49-93AA-08F2612A47A8}.Release|Any CPU.Build.0 = Release|Any CPU
{BC491B8D-D6EF-4AE6-B11D-1A117B6A350D}.Core|Any CPU.ActiveCfg = Debug|Any CPU
{BC491B8D-D6EF-4AE6-B11D-1A117B6A350D}.Core|Any CPU.Build.0 = Debug|Any CPU
{BC491B8D-D6EF-4AE6-B11D-1A117B6A350D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC491B8D-D6EF-4AE6-B11D-1A117B6A350D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC491B8D-D6EF-4AE6-B11D-1A117B6A350D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC491B8D-D6EF-4AE6-B11D-1A117B6A350D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -103,8 +103,8 @@ Global
{08343570-1C97-429D-A0C9-6A9822412028} = {E5D88D38-57E0-46E0-913A-0CCE91826F18}
{A3467CEB-5392-4166-93AF-C0A1C20DF0F8} = {7BCFC6D6-228E-4C93-8145-EAD121AA8587}
{93DFC566-A413-4039-A0C1-90A42A356386} = {7BCFC6D6-228E-4C93-8145-EAD121AA8587}
{AB2ED826-2E09-42F5-9106-BDB956984385} = {E5D88D38-57E0-46E0-913A-0CCE91826F18}
{7E26CCF1-DDB2-4A49-93AA-08F2612A47A8} = {E5D88D38-57E0-46E0-913A-0CCE91826F18}
{BC491B8D-D6EF-4AE6-B11D-1A117B6A350D} = {E5D88D38-57E0-46E0-913A-0CCE91826F18}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {346406ED-19A9-40FB-A3F7-14139F44C0C8}
Expand Down
1 change: 0 additions & 1 deletion source/Meadow.Core/Bases/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ protected App()
Device = MeadowOS.CurrentDevice as D; // 'D' is guaranteed to be initialized and the same type
Abort = MeadowOS.AppAbort.Token;

Resolver.Services.Add<IMeadowDevice>(Device);
Resolver.Services.Add<IApp>(this);
}

Expand Down
2 changes: 1 addition & 1 deletion source/Meadow.Core/Configuration/ILifecycleSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public interface ILifecycleSettings
{
bool RestartOnAppFailure => true;
bool RestartOnAppFailure => false;
int AppFailureRestartDelaySeconds => 5;
}
}
2 changes: 1 addition & 1 deletion source/Meadow.Core/Configuration/LifecycleSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
internal class LifecycleSettings : ConfigurableObject, ILifecycleSettings
{
public bool RestartOnAppFailure => GetConfiguredBool(nameof(RestartOnAppFailure), true);
public bool RestartOnAppFailure => GetConfiguredBool(nameof(RestartOnAppFailure), false);
public int AppFailureRestartDelaySeconds => GetConfiguredInt(nameof(AppFailureRestartDelaySeconds), 5);
}
}
78 changes: 78 additions & 0 deletions source/Meadow.Core/Exceptions/NetworkException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;

namespace Meadow
{
/// <summary>
/// A general Network exception
/// </summary>
public class NetworkException : Exception
{
public int StatusCode { get; }

/// <summary>
/// Creates a NetworkException instance
/// </summary>
public NetworkException()
{
}

/// <summary>
/// Creates a NetworkException instance
/// </summary>
/// <param name="message"></param>
/// <param name="statusCode"></param>
public NetworkException(string message, int statusCode)
: base(message)
{
StatusCode = statusCode;
}

/// <summary>
/// Creates a NetworkException instance
/// </summary>
/// <param name="statusCode"></param>
public NetworkException(int statusCode)
{
StatusCode = statusCode;
}

/// <summary>
/// Creates a NetworkException instance
/// </summary>
/// <param name="message"></param>
public NetworkException(string message)
: base(message)
{
}
}

/// <summary>
/// An exception indicating a requested network was not found
/// </summary>
public class NetworkNotFoundException : NetworkException
{
/// <summary>
/// Creates a NetworkNotFoundException instance
/// </summary>
/// <param name="message"></param>
public NetworkNotFoundException(string message)
: base(message)
{
}
}

/// <summary>
/// An exception indicating a network authentication failure
/// </summary>
public class NetworkAuthenticationException : NetworkException
{
/// <summary>
/// Creates a NetworkAuthenticationException instance
/// </summary>
/// <param name="message"></param>
public NetworkAuthenticationException(string message)
: base(message)
{
}
}
}
67 changes: 62 additions & 5 deletions source/Meadow.Core/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Linq;

namespace Meadow
{
Expand Down Expand Up @@ -56,22 +56,26 @@ static public int FirstIndexOf<TSource>(this IEnumerable<TSource> source, TSourc

if (firstMatch == null) return -1;

for (int i = 0; i < totalLength; i++) {
for (int i = 0; i < totalLength; i++)
{
// is this the right equality?
if ((firstMatch.Equals(source.ElementAt(i))) // begin match?
&&
(totalLength - i >= patternLength) // can match exist?
) {
)
{
TSource[] matchTest = new TSource[patternLength];
// copy the potential match into the matchTest array.
// can't use .Skip() and .Take() because it will actually
// enumerate over stuff and can have side effects
for (int x = 0; x < patternLength; x++) {
for (int x = 0; x < patternLength; x++)
{
matchTest[x] = source.ElementAt(i + x);
}
// if the pattern pulled from source matches our search pattern
// then the pattern exists.
if (matchTest.SequenceEqual(pattern)) {
if (matchTest.SequenceEqual(pattern))
{
return i;
}
}
Expand Down Expand Up @@ -127,5 +131,58 @@ static public int Map(this int souceValue, int sourceMin, int sourceMax, int tar
{
return (souceValue - sourceMin) / (sourceMax - sourceMin) * (targetMax - targetMin) + targetMin;
}

public static void Fire(this Delegate handler, params object[] args)
{
if (handler == null) return;
foreach (var d in handler.GetInvocationList())
{
try
{
d.DynamicInvoke(args);
}
catch (Exception ex)
{
Resolver.Log.Error($"Event handler threw {ex.GetType().Name}: {ex.Message}");
}
}
}

public static void Fire(this EventHandler h, object sender)
{
Fire(h, sender, EventArgs.Empty);
}

public static void Fire(this EventHandler handler, object sender, EventArgs args)
{
if (handler == null) return;
foreach (var d in handler.GetInvocationList())
{
try
{
d.DynamicInvoke(sender, args);
}
catch (Exception ex)
{
Resolver.Log.Error($"Event handler threw {ex.GetType().Name}: {ex.Message}");
}
}
}

public static void Fire<T>(this EventHandler<T> handler, object sender, T args) where T : EventArgs
{
if (handler == null) return;
foreach (var d in handler.GetInvocationList())
{
try
{
d.DynamicInvoke(sender, args);
}
catch (Exception ex)
{
Resolver.Log.Error($"Event handler threw {ex.GetType().Name}: {ex.Message}");
}
}
}
}
}
24 changes: 24 additions & 0 deletions source/Meadow.Core/Hardware/AnalogInputPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ public class AnalogInputPort : AnalogInputPortBase, IObservable<IChangeResult<Vo
// only one ADC across the entire processor can be read at one time. This is the sync object for that.
static readonly object _analogSyncRoot = new object();

/// <summary>
/// The default sampling interval for the Input (40ms)
/// </summary>
public static readonly TimeSpan DefaultSampleInterval = TimeSpan.FromMilliseconds(40);
/// <summary>
/// The default reference votlage for the Input (3.3V)
/// </summary>
public static readonly Voltage DefaultReferenceVoltage = new Voltage(3.3, Voltage.UnitType.Volts);

protected IMeadowIOController IOController { get; }
Expand Down Expand Up @@ -84,6 +90,13 @@ protected AnalogInputPort(
}
}

/// <summary>
/// Creates an AnalogInputPort given the povided parameters
/// </summary>
/// <param name="pin"></param>
/// <param name="ioController"></param>
/// <param name="sampleCount"></param>
/// <returns></returns>
public static AnalogInputPort From(
IPin pin,
IMeadowIOController ioController,
Expand All @@ -92,6 +105,17 @@ public static AnalogInputPort From(
return From(pin, ioController, sampleCount, DefaultSampleInterval, DefaultReferenceVoltage);
}

/// <summary>
/// Creates an AnalogInputPort given the povided parameters
/// </summary>
/// <param name="pin"></param>
/// <param name="ioController"></param>
/// <param name="sampleCount"></param>
/// <param name="sampleInterval"></param>
/// <param name="referenceVoltage"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="Exception"></exception>
public static AnalogInputPort From(
IPin pin,
IMeadowIOController ioController,
Expand Down
Loading

0 comments on commit 9c518f3

Please sign in to comment.