Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added storage info #382

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions source/Meadow.Core/StorageInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Meadow.Units;

namespace Meadow;

/// <summary>
/// Information about available storage devices
/// </summary>
public abstract class StorageInformation : IStorageInformation
{
/// <inheritdoc/>
public string Name { get; protected set; } = default!;

/// <inheritdoc/>
public DigitalStorage SpaceAvailable { get; protected set; } = default!;

/// <inheritdoc/>
public DigitalStorage Size { get; protected set; } = default!;
}
52 changes: 51 additions & 1 deletion source/implementations/f7/Meadow.F7/F7PlatformOS.Storage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
namespace Meadow;
using Meadow.Devices;
using System.IO;
using System.Linq;

namespace Meadow;


public partial class F7PlatformOS : IPlatformOS
{
private const long FeatherV1TotalFlash = 33_554_432; // 32MB
private const long FeatherV2TotalFlash = 33_554_432; // 32MB
private const long RuntimeAllocationSize = 3_145_728; // 3MB
private const long OtAAllocationSize = 2_097_152; // 2MB

/// <summary>
/// Meadow F7-specific storage information
/// </summary>
public class F7StorageInformation : StorageInformation
{
internal static F7StorageInformation Create(IMeadowDevice device)
{
long totalFlashAvailable;
if (device is F7FeatherV1)
{
totalFlashAvailable = FeatherV1TotalFlash - RuntimeAllocationSize - OtAAllocationSize;
}
else
{
totalFlashAvailable = FeatherV2TotalFlash - RuntimeAllocationSize - OtAAllocationSize;
}

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)
};
}
}

/// <summary>
/// Gets the file system information for the platform.
/// </summary>
public Meadow.IPlatformOS.FileSystemInfo FileSystem { get; private set; } = default!;

/// <inheritdoc/>
public IStorageInformation[] GetStorageInformation()
{
// TODO: support external storage for MMC-enabled CCM devices

return new IStorageInformation[]
{
F7StorageInformation.Create(Resolver.Device)
};
}
}
8 changes: 3 additions & 5 deletions source/implementations/f7/Meadow.F7/F7PlatformOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ public AllocationInfo GetMemoryAllocationInfo()
return Core.Interop.Nuttx.mallinfo();
}

/// <summary>
/// Retrieves the current processor usage (as a percentage in the range of 0-100)
/// </summary>
public int ProcessorLoad()
/// <inheritdoc/>
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()];
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

namespace Meadow.Core
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

namespace Meadow.Core
{
Expand Down
5 changes: 1 addition & 4 deletions source/implementations/f7/Meadow.F7/Interop/Interop.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Runtime.InteropServices;

namespace Meadow.Core
namespace Meadow.Core
{
internal static partial class Interop
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;

namespace Meadow.Core
{
Expand Down
3 changes: 1 addition & 2 deletions source/implementations/f7/Meadow.F7/Interop/Interop.ioctl.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using Meadow.Devices.Esp32.MessagePayloads;

namespace Meadow.Core
{
Expand Down Expand Up @@ -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);

/// <summary>
/// Configures the Universal Platform Driver to catch GPIO interrupts
/// </summary>
Expand Down
9 changes: 4 additions & 5 deletions source/implementations/f7/Meadow.F7/UPD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using static Meadow.Core.Interop;
using Meadow.Devices.Esp32.MessagePayloads;

namespace Meadow.Devices
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Loading