Skip to content

Commit

Permalink
added storage info
Browse files Browse the repository at this point in the history
  • Loading branch information
ctacke committed Oct 18, 2023
1 parent 0516194 commit 58b4dcd
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 157 deletions.
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!;
}
56 changes: 55 additions & 1 deletion source/implementations/f7/Meadow.F7/F7PlatformOS.Storage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
namespace Meadow;
using Meadow.Devices;
using System.IO;
using System.Linq;

namespace Meadow;


public partial class F7PlatformOS : IPlatformOS
{
/// <summary>
/// Meadow F7-specific storage information
/// </summary>
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)
};
}
}

/// <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

0 comments on commit 58b4dcd

Please sign in to comment.