From 4badc534a375efd430fa5b44da6ba0a5069f5a0f Mon Sep 17 00:00:00 2001 From: Dominique Louis Date: Thu, 28 Sep 2023 12:10:41 +0100 Subject: [PATCH] Format device info out, to what we have now. --- Source/v2/Meadow.Hcom/DeviceInfo.cs | 72 +++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/Source/v2/Meadow.Hcom/DeviceInfo.cs b/Source/v2/Meadow.Hcom/DeviceInfo.cs index b25809c5..8109db97 100644 --- a/Source/v2/Meadow.Hcom/DeviceInfo.cs +++ b/Source/v2/Meadow.Hcom/DeviceInfo.cs @@ -12,28 +12,82 @@ internal DeviceInfo(Dictionary properties) } public string this[string propname] => Properties[propname]; + public string Product => this["Product"]; + public string Model => this["Model"]; + public string ProcessorType => this["ProcessorType"]; + public string CoprocessorType => this["CoprocessorType"]; public string OsVersion => this["OSVersion"]; public string CoprocessorOsVersion => this["CoprocessorVersion"]; - public string RuntimeVersion => this["MonoVersion"]; - public string Model => this["Model"]; + public string ProcessorId => this["ProcessorId"]; public string HardwareVersion => this["Hardware"]; public string DeviceName => this["DeviceName"]; - public string ProcessorType => this["ProcessorType"]; - public string UniqueID => this["ProcessorId"]; + public string RuntimeVersion => this["MonoVersion"]; public string SerialNumber => this["SerialNo"]; - public string CoprocessorType => this["CoprocessorType"]; public string MacAddress => this["WiFiMAC"]; + public string SoftAPMacAddress => this["SoftAPMac"]; + + /// + /// String representation of an unknown MAC address. + /// + private const string UNKNOWN_MAC_ADDRESS = "00:00:00:00:00:00"; public override string ToString() { - var info = new StringBuilder(); + var deviceInfo = new StringBuilder(); + + if (Product.Contains(" by Wilderness Labs")) + { + deviceInfo.AppendLine(Product); + } + else + { + deviceInfo.AppendLine($"{Product} by Wilderness Labs"); + } + + deviceInfo.AppendLine("Board Information "); + deviceInfo.AppendLine($" Model: {Model}"); + deviceInfo.AppendLine($" Hardware version: {HardwareVersion}"); + deviceInfo.AppendLine($" Device name: {DeviceName}"); + deviceInfo.AppendLine(); + deviceInfo.AppendLine($"Hardware Information "); + deviceInfo.AppendLine($" Processor type: {ProcessorType}"); + deviceInfo.AppendLine($" ID: {ProcessorId}"); + deviceInfo.AppendLine($" Serial number: {SerialNumber}"); + deviceInfo.AppendLine($" Coprocessor type: {CoprocessorType}"); - foreach (var prop in Properties) + string macAddresses = string.Empty; + int macCount = 0; + if (!string.IsNullOrEmpty(MacAddress) && MacAddress != UNKNOWN_MAC_ADDRESS) { - info.AppendLine($"{prop.Key}: {prop.Value}"); + macCount++; + macAddresses += $" WiFi: {MacAddress}{Environment.NewLine}"; } + if (!string.IsNullOrEmpty(SoftAPMacAddress) && SoftAPMacAddress != UNKNOWN_MAC_ADDRESS) + { + macCount++; + macAddresses += $" AP: {SoftAPMacAddress}{Environment.NewLine}"; + } + if (macCount > 0) + { + if (macCount > 1) + { + deviceInfo.AppendLine(" MAC Addresses - " ); + } + else + { + deviceInfo.AppendLine(" MAC Address - " ); + } + deviceInfo.AppendLine($"{macAddresses}"); + } + + deviceInfo.AppendLine(); + deviceInfo.AppendLine($"Firmware Versions "); + deviceInfo.AppendLine($" OS: {OsVersion}"); + deviceInfo.AppendLine($" Mono: {RuntimeVersion}"); + deviceInfo.AppendLine($" Coprocessor: {CoprocessorOsVersion}"); + deviceInfo.AppendLine($" Protocol: {Protocol.HCOM_PROTOCOL_HCOM_VERSION_NUMBER}"); - return info.ToString(); + return deviceInfo.ToString(); } } } \ No newline at end of file