diff --git a/source/Meadow.Core/StorageInformation.cs b/source/Meadow.Core/StorageInformation.cs
new file mode 100644
index 00000000..22a826b1
--- /dev/null
+++ b/source/Meadow.Core/StorageInformation.cs
@@ -0,0 +1,18 @@
+using Meadow.Units;
+
+namespace Meadow;
+
+///
+/// Information about available storage devices
+///
+public abstract class StorageInformation : IStorageInformation
+{
+ ///
+ public string Name { get; protected set; } = default!;
+
+ ///
+ public DigitalStorage SpaceAvailable { get; protected set; } = default!;
+
+ ///
+ public DigitalStorage Size { get; protected set; } = default!;
+}
diff --git a/source/implementations/f7/Meadow.F7/F7PlatformOS.Storage.cs b/source/implementations/f7/Meadow.F7/F7PlatformOS.Storage.cs
index aa334c03..82e9b620 100644
--- a/source/implementations/f7/Meadow.F7/F7PlatformOS.Storage.cs
+++ b/source/implementations/f7/Meadow.F7/F7PlatformOS.Storage.cs
@@ -1,10 +1,64 @@
-namespace Meadow;
+using Meadow.Devices;
+using System.IO;
+using System.Linq;
+
+namespace Meadow;
+
public partial class F7PlatformOS : IPlatformOS
{
+ ///
+ /// Meadow F7-specific storage information
+ ///
+ public class F7StorageInformation : StorageInformation
+ {
+ internal static F7StorageInformation Create(IMeadowDevice device)
+ {
+ long totalFlashAvailable;
+ if (device is F7FeatherV1)
+ {
+ totalFlashAvailable = 33_554_432 // 32MB
+ - 3_145_728 // allocation for runtime
+ - 2_097_152; // OtA
+
+ // 16_510_459_314_176.10
+ // 29_686_813_949_952.1MB
+ }
+ else
+ {
+ totalFlashAvailable = 67_108_864 // 64MB
+ - 3_145_728 // allocation for runtime
+ - 2_097_152; // OtA
+
+
+ }
+
+ var spaceConsumed = new DirectoryInfo("/meadow0")
+ .EnumerateFiles("*", SearchOption.AllDirectories)
+ .Sum(file => file.Length);
+
+ return new F7StorageInformation
+ {
+ Name = "Internal Flash",
+ Size = new Units.DigitalStorage(totalFlashAvailable),
+ SpaceAvailable = new Units.DigitalStorage(totalFlashAvailable - spaceConsumed)
+ };
+ }
+ }
+
///
/// Gets the file system information for the platform.
///
public Meadow.IPlatformOS.FileSystemInfo FileSystem { get; private set; } = default!;
+ ///
+ public IStorageInformation[] GetStorageInformation()
+ {
+ // TODO: support external storage for MMC-enabled CCM devices
+
+ return new IStorageInformation[]
+ {
+ F7StorageInformation.Create(Resolver.Device)
+ };
+ }
}
diff --git a/source/implementations/f7/Meadow.F7/F7PlatformOS.cs b/source/implementations/f7/Meadow.F7/F7PlatformOS.cs
index 95e44126..f0887a03 100644
--- a/source/implementations/f7/Meadow.F7/F7PlatformOS.cs
+++ b/source/implementations/f7/Meadow.F7/F7PlatformOS.cs
@@ -87,11 +87,9 @@ public AllocationInfo GetMemoryAllocationInfo()
return Core.Interop.Nuttx.mallinfo();
}
- ///
- /// Retrieves the current processor usage (as a percentage in the range of 0-100)
- ///
- public int ProcessorLoad()
+ ///
+ public int[] GetProcessorUtilization()
{
- return 100 - Core.Interop.Nuttx.meadow_idle_monitor_get_value();
+ return new int[100 - Core.Interop.Nuttx.meadow_idle_monitor_get_value()];
}
}
diff --git a/source/implementations/f7/Meadow.F7/Interop/Interop.clock_gettime.cs b/source/implementations/f7/Meadow.F7/Interop/Interop.clock_gettime.cs
index 4fb4ba99..7a3a5038 100644
--- a/source/implementations/f7/Meadow.F7/Interop/Interop.clock_gettime.cs
+++ b/source/implementations/f7/Meadow.F7/Interop/Interop.clock_gettime.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
namespace Meadow.Core
{
diff --git a/source/implementations/f7/Meadow.F7/Interop/Interop.clock_settime.cs b/source/implementations/f7/Meadow.F7/Interop/Interop.clock_settime.cs
index 4162e4aa..e9073ad3 100644
--- a/source/implementations/f7/Meadow.F7/Interop/Interop.clock_settime.cs
+++ b/source/implementations/f7/Meadow.F7/Interop/Interop.clock_settime.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
namespace Meadow.Core
{
diff --git a/source/implementations/f7/Meadow.F7/Interop/Interop.cs b/source/implementations/f7/Meadow.F7/Interop/Interop.cs
index 45076b2f..98b19f6f 100644
--- a/source/implementations/f7/Meadow.F7/Interop/Interop.cs
+++ b/source/implementations/f7/Meadow.F7/Interop/Interop.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace Meadow.Core
+namespace Meadow.Core
{
internal static partial class Interop
{
diff --git a/source/implementations/f7/Meadow.F7/Interop/Interop.gpio.cs b/source/implementations/f7/Meadow.F7/Interop/Interop.gpio.cs
index 4dbdbc45..3f1d0aaf 100644
--- a/source/implementations/f7/Meadow.F7/Interop/Interop.gpio.cs
+++ b/source/implementations/f7/Meadow.F7/Interop/Interop.gpio.cs
@@ -1,5 +1,4 @@
using System;
-using System.Runtime.InteropServices;
namespace Meadow.Core
{
diff --git a/source/implementations/f7/Meadow.F7/Interop/Interop.ioctl.cs b/source/implementations/f7/Meadow.F7/Interop/Interop.ioctl.cs
index 26e74f59..e30d5b6d 100644
--- a/source/implementations/f7/Meadow.F7/Interop/Interop.ioctl.cs
+++ b/source/implementations/f7/Meadow.F7/Interop/Interop.ioctl.cs
@@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
-using Meadow.Devices.Esp32.MessagePayloads;
namespace Meadow.Core
{
@@ -58,7 +57,7 @@ public enum GpioIoctlFn
[DllImport(LIBRARY_NAME, SetLastError = true)]
public static extern int ioctl(IntPtr fd, UpdIoctlFn request, ref Nuttx.UpdSleepCommand command);
-
+
///
/// Configures the Universal Platform Driver to catch GPIO interrupts
///
diff --git a/source/implementations/f7/Meadow.F7/UPD.cs b/source/implementations/f7/Meadow.F7/UPD.cs
index d380d8bb..4715e4e0 100644
--- a/source/implementations/f7/Meadow.F7/UPD.cs
+++ b/source/implementations/f7/Meadow.F7/UPD.cs
@@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using static Meadow.Core.Interop;
-using Meadow.Devices.Esp32.MessagePayloads;
namespace Meadow.Devices
{
@@ -168,7 +167,7 @@ public static int Ioctl(Nuttx.UpdIoctlFn request, Nuttx.UpdSleepCommand command)
}
return result;
}
-
+
public static int Ioctl(Nuttx.UpdIoctlFn request, ref Nuttx.UpdGpioInterruptConfiguration interruptConfig)
{
@@ -274,7 +273,7 @@ public static int Ioctl(Nuttx.UpdIoctlFn request, ref Nuttx.UpdEsp32Command cmd)
{
var err = GetLastError();
Resolver.Log.Error($"ioctl {request} failed {err}");
- return (int) err;
+ return (int)err;
}
return result;
}
@@ -286,7 +285,7 @@ public static int Ioctl(Nuttx.UpdIoctlFn request, ref Nuttx.UpdEsp32EventDataPay
{
var err = GetLastError();
Resolver.Log.Error($"ioctl {request} failed {err}");
- return (int) err;
+ return (int)err;
}
return result;
}
@@ -298,7 +297,7 @@ public static int Ioctl(Nuttx.UpdIoctlFn request, ref Nuttx.UpdConfigurationValu
{
var err = GetLastError();
Resolver.Log.Error($"ioctl {request} failed {err}");
- return (int) err;
+ return (int)err;
}
return result;
}
diff --git a/source/implementations/linux/Meadow.Linux/PlatformOS/LinuxPlatformOS.cs b/source/implementations/linux/Meadow.Linux/PlatformOS/LinuxPlatformOS.cs
index b3d905da..fdd300a7 100644
--- a/source/implementations/linux/Meadow.Linux/PlatformOS/LinuxPlatformOS.cs
+++ b/source/implementations/linux/Meadow.Linux/PlatformOS/LinuxPlatformOS.cs
@@ -212,4 +212,14 @@ public byte[] AesDecrypt(byte[] encryptedValue, byte[] key, byte[] iv)
}
}
}
+
+ public int[] GetProcessorUtilization()
+ {
+ throw new NotImplementedException();
+ }
+
+ public IStorageInformation[] GetStorageInformation()
+ {
+ throw new NotImplementedException();
+ }
}
diff --git a/source/implementations/simulation/Meadow.Simulation/SimulatedPlatformOS.cs b/source/implementations/simulation/Meadow.Simulation/SimulatedPlatformOS.cs
index 87f57583..2e7766ed 100644
--- a/source/implementations/simulation/Meadow.Simulation/SimulatedPlatformOS.cs
+++ b/source/implementations/simulation/Meadow.Simulation/SimulatedPlatformOS.cs
@@ -156,4 +156,14 @@ public byte[] AesDecrypt(byte[] encryptedValue, byte[] key, byte[] iv)
}
}
}
+
+ public int[] GetProcessorUtilization()
+ {
+ throw new NotImplementedException();
+ }
+
+ public IStorageInformation[] GetStorageInformation()
+ {
+ throw new NotImplementedException();
+ }
}
diff --git a/source/implementations/windows/Meadow.Windows/WindowsPlatformOS.cs b/source/implementations/windows/Meadow.Windows/WindowsPlatformOS.cs
index d576a945..3210a0f4 100644
--- a/source/implementations/windows/Meadow.Windows/WindowsPlatformOS.cs
+++ b/source/implementations/windows/Meadow.Windows/WindowsPlatformOS.cs
@@ -7,95 +7,95 @@
using System.Linq;
using System.Security.Cryptography;
-namespace Meadow
+namespace Meadow;
+
+public class WindowsPlatformOS : IPlatformOS
{
- public class WindowsPlatformOS : IPlatformOS
+ ///
+ /// Event raised before a software reset
+ ///
+ public event PowerTransitionHandler BeforeReset = delegate { };
+ ///
+ /// Event raised before Sleep mode
+ ///
+ public event PowerTransitionHandler BeforeSleep = delegate { };
+ ///
+ /// Event raised after returning from Sleep mode
+ ///
+ public event PowerTransitionHandler AfterWake = delegate { };
+ ///
+ /// Event raised when an external storage device event occurs.
+ ///
+ public event ExternalStorageEventHandler ExternalStorageEvent = delegate { };
+
+ ///
+ /// Gets the OS version.
+ ///
+ /// OS version.
+ public string OSVersion { get; }
+ ///
+ /// Gets the OS build date.
+ ///
+ /// OS build date.
+ public string OSBuildDate { get; }
+ ///
+ /// Get the current .NET runtime version being used to execute the application.
+ ///
+ /// Mono version.
+ public string RuntimeVersion { get; }
+
+ ///
+ /// The command line arguments provided when the Meadow application was launched
+ ///
+ public string[]? LaunchArguments { get; private set; }
+
+ public IPlatformOS.FileSystemInfo FileSystem { get; }
+
+ ///
+ /// Default constructor for the WindowsPlatformOS object.
+ ///
+ internal WindowsPlatformOS()
{
- ///
- /// Event raised before a software reset
- ///
- public event PowerTransitionHandler BeforeReset = delegate { };
- ///
- /// Event raised before Sleep mode
- ///
- public event PowerTransitionHandler BeforeSleep = delegate { };
- ///
- /// Event raised after returning from Sleep mode
- ///
- public event PowerTransitionHandler AfterWake = delegate { };
- ///
- /// Event raised when an external storage device event occurs.
- ///
- public event ExternalStorageEventHandler ExternalStorageEvent = delegate { };
-
- ///
- /// Gets the OS version.
- ///
- /// OS version.
- public string OSVersion { get; }
- ///
- /// Gets the OS build date.
- ///
- /// OS build date.
- public string OSBuildDate { get; }
- ///
- /// Get the current .NET runtime version being used to execute the application.
- ///
- /// Mono version.
- public string RuntimeVersion { get; }
-
- ///
- /// The command line arguments provided when the Meadow application was launched
- ///
- public string[]? LaunchArguments { get; private set; }
-
- public IPlatformOS.FileSystemInfo FileSystem { get; }
-
- ///
- /// Default constructor for the WindowsPlatformOS object.
- ///
- internal WindowsPlatformOS()
- {
- OSVersion = Environment.OSVersion.ToString();
- OSBuildDate = "Unknown";
- RuntimeVersion = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
- FileSystem = new WindowsFileSystemInfo();
- }
+ OSVersion = Environment.OSVersion.ToString();
+ OSBuildDate = "Unknown";
+ RuntimeVersion = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
+ FileSystem = new WindowsFileSystemInfo();
+ }
- ///
- /// Initialize the WindowsPlatformOS instance.
- ///
- ///
- /// The command line arguments provided when the Meadow application was launched
- public void Initialize(DeviceCapabilities capabilities, string[]? args)
- {
- // TODO: deal with capabilities
- }
+ ///
+ /// Initialize the WindowsPlatformOS instance.
+ ///
+ ///
+ /// The command line arguments provided when the Meadow application was launched
+ public void Initialize(DeviceCapabilities capabilities, string[]? args)
+ {
+ // TODO: deal with capabilities
+ }
- ///
- /// Gets the name of all available serial ports on the platform
- ///
- /// A list of available serial port names
- public SerialPortName[] GetSerialPortNames()
- {
- return SerialPort.GetPortNames().Select(n =>
- new SerialPortName(n, n, Resolver.Device))
- .ToArray();
- }
+ ///
+ /// Gets the name of all available serial ports on the platform
+ ///
+ /// A list of available serial port names
+ public SerialPortName[] GetSerialPortNames()
+ {
+ return SerialPort.GetPortNames().Select(n =>
+ new SerialPortName(n, n, Resolver.Device))
+ .ToArray();
+ }
- public Temperature GetCpuTemperature()
- {
- throw new PlatformNotSupportedException();
- }
+ public Temperature GetCpuTemperature()
+ {
+ throw new PlatformNotSupportedException();
+ }
- ///
- /// Sets the platform OS clock
- ///
- ///
- public void SetClock(DateTime dateTime)
- {
- throw new PlatformNotSupportedException();
- }
+ ///
+ /// Sets the platform OS clock
+ ///
+ ///
+ public void SetClock(DateTime dateTime)
+ {
+ throw new PlatformNotSupportedException();
+ }
@@ -104,70 +104,79 @@ public void SetClock(DateTime dateTime)
- // TODO: implement everything below here
+ // TODO: implement everything below here
- public string ReservedPins => string.Empty;
- public IEnumerable ExternalStorage => throw new NotImplementedException();
- public INtpClient NtpClient => throw new NotImplementedException();
- public bool RebootOnUnhandledException => throw new NotImplementedException();
- public uint InitializationTimeout => throw new NotImplementedException();
- public bool AutomaticallyStartNetwork => throw new NotImplementedException();
- public IPlatformOS.NetworkConnectionType SelectedNetwork => throw new NotImplementedException();
- public bool SdStorageSupported => throw new NotImplementedException();
+ public string ReservedPins => string.Empty;
+ public IEnumerable ExternalStorage => throw new NotImplementedException();
+ public INtpClient NtpClient => throw new NotImplementedException();
+ public bool RebootOnUnhandledException => throw new NotImplementedException();
+ public uint InitializationTimeout => throw new NotImplementedException();
+ public bool AutomaticallyStartNetwork => throw new NotImplementedException();
+ public IPlatformOS.NetworkConnectionType SelectedNetwork => throw new NotImplementedException();
+ public bool SdStorageSupported => throw new NotImplementedException();
- public T GetConfigurationValue(IPlatformOS.ConfigurationValues item) where T : struct
- {
- throw new NotImplementedException();
- }
+ public T GetConfigurationValue(IPlatformOS.ConfigurationValues item) where T : struct
+ {
+ throw new NotImplementedException();
+ }
- public void RegisterForSleep(ISleepAwarePeripheral peripheral)
- {
- throw new NotImplementedException();
- }
+ public void RegisterForSleep(ISleepAwarePeripheral peripheral)
+ {
+ throw new NotImplementedException();
+ }
- public void Reset()
- {
- throw new NotImplementedException();
- }
+ public void Reset()
+ {
+ throw new NotImplementedException();
+ }
- public void SetConfigurationValue(IPlatformOS.ConfigurationValues item, T value) where T : struct
- {
- throw new NotImplementedException();
- }
+ public void SetConfigurationValue(IPlatformOS.ConfigurationValues item, T value) where T : struct
+ {
+ throw new NotImplementedException();
+ }
- public void Sleep(TimeSpan duration)
- {
- throw new NotImplementedException();
- }
+ public void Sleep(TimeSpan duration)
+ {
+ throw new NotImplementedException();
+ }
- public byte[] RsaDecrypt(byte[] encryptedValue)
- {
- var rsa = RSA.Create();
- return rsa.Decrypt(encryptedValue, RSAEncryptionPadding.Pkcs1);
- }
+ public byte[] RsaDecrypt(byte[] encryptedValue)
+ {
+ var rsa = RSA.Create();
+ return rsa.Decrypt(encryptedValue, RSAEncryptionPadding.Pkcs1);
+ }
- public byte[] AesDecrypt(byte[] encryptedValue, byte[] key, byte[] iv)
+ public byte[] AesDecrypt(byte[] encryptedValue, byte[] key, byte[] iv)
+ {
+ // Create an Aes object
+ // with the specified key and IV.
+ using (Aes aesAlg = Aes.Create())
{
- // Create an Aes object
- // with the specified key and IV.
- using (Aes aesAlg = Aes.Create())
+ aesAlg.Key = key;
+ aesAlg.IV = iv;
+
+ // Create a decryptor to perform the stream transform.
+ var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
+
+ // Create the streams used for decryption.
+ using (var msDecrypt = new MemoryStream(encryptedValue))
+ using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
- aesAlg.Key = key;
- aesAlg.IV = iv;
-
- // Create a decryptor to perform the stream transform.
- var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
-
- // Create the streams used for decryption.
- using (var msDecrypt = new MemoryStream(encryptedValue))
- using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
- {
- var buffer = new byte[csDecrypt.Length];
- csDecrypt.Read(buffer, 0, buffer.Length);
- return buffer;
- }
+ var buffer = new byte[csDecrypt.Length];
+ csDecrypt.Read(buffer, 0, buffer.Length);
+ return buffer;
}
}
}
+
+ public int[] GetProcessorUtilization()
+ {
+ throw new NotImplementedException();
+ }
+
+ public IStorageInformation[] GetStorageInformation()
+ {
+ throw new NotImplementedException();
+ }
}