mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 12:44:58 +00:00
Merge pull request #433 from PepperDash/feature/add-runtime-ip-info-to-global
Add runtime IP info to global
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.Reflection;
|
using Crestron.SimplSharp.Reflection;
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ namespace PepperDash.Essentials.Core.Config
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>,
|
||||||
/// The OS Version of the processor (Firmware Version)
|
/// The OS Version of the processor (Firmware Version)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("osVersion")]
|
[JsonProperty("osVersion")]
|
||||||
@@ -92,5 +92,18 @@ namespace PepperDash.Essentials.Core.Config
|
|||||||
// return Crestron.SimplSharp.CrestronEnvironment.OSVersion.Firmware;
|
// return Crestron.SimplSharp.CrestronEnvironment.OSVersion.Firmware;
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The information gathered by the processor at runtime about it's NICs and their IP addresses.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("ipInfo")]
|
||||||
|
public Dictionary<short, EthernetAdapterInfo> IpInfo
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Global.EthernetAdapterInfoCollection;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Core
|
||||||
|
{
|
||||||
|
public class EthernetAdapterInfo
|
||||||
|
{
|
||||||
|
public EthernetAdapterType Type { get; set; }
|
||||||
|
public bool DhcpIsOn { get; set; }
|
||||||
|
public string Hostname { get; set; }
|
||||||
|
public string MacAddress { get; set; }
|
||||||
|
public string IpAddress { get; set; }
|
||||||
|
public string Subnet { get; set; }
|
||||||
|
public string Gateway { get; set; }
|
||||||
|
public string Dns1 { get; set; }
|
||||||
|
public string Dns2 { get; set; }
|
||||||
|
public string Dns3 { get; set; }
|
||||||
|
public string Domain { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Crestron.SimplSharp.CrestronDataStore;
|
using Crestron.SimplSharp.CrestronDataStore;
|
||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharpPro;
|
||||||
@@ -21,6 +22,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
public static LicenseManager LicenseManager { get; set; }
|
public static LicenseManager LicenseManager { get; set; }
|
||||||
|
|
||||||
|
public static Dictionary<short, EthernetAdapterInfo> EthernetAdapterInfoCollection {get; private set;}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The file path prefix to the folder containing configuration files
|
/// The file path prefix to the folder containing configuration files
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -160,6 +163,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static Global()
|
static Global()
|
||||||
{
|
{
|
||||||
// Fire up CrestronDataStoreStatic
|
// Fire up CrestronDataStoreStatic
|
||||||
@@ -169,7 +174,87 @@ namespace PepperDash.Essentials.Core
|
|||||||
CrestronConsole.PrintLine("Error starting CrestronDataStoreStatic: {0}", err);
|
CrestronConsole.PrintLine("Error starting CrestronDataStoreStatic: {0}", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetEthernetInformation();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Populates EthernetInformationCollection
|
||||||
|
/// </summary>
|
||||||
|
static void GetEthernetInformation()
|
||||||
|
{
|
||||||
|
|
||||||
|
EthernetAdapterInfoCollection = new Dictionary<short, EthernetAdapterInfo>();
|
||||||
|
|
||||||
|
EthernetAdapterType adapterType = EthernetAdapterType.EthernetUnknownAdapter;
|
||||||
|
|
||||||
|
List<EthernetAdapterType> adapters = new List<EthernetAdapterType>()
|
||||||
|
{ EthernetAdapterType.EthernetLANAdapter, EthernetAdapterType.EthernetLAN2Adapter, EthernetAdapterType.EthernetCSAdapter, EthernetAdapterType.EthernetWIFIAdapter };
|
||||||
|
|
||||||
|
foreach (var adapter in adapters)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
adapterType = EthernetAdapterType.EthernetLANAdapter;
|
||||||
|
|
||||||
|
var adapterId = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(adapterType);
|
||||||
|
|
||||||
|
var adapterInfo = GetEthernetAdapterProperties(adapterId, adapterType);
|
||||||
|
|
||||||
|
EthernetAdapterInfoCollection.Add(adapterId, adapterInfo);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (e is System.ArgumentException)
|
||||||
|
{
|
||||||
|
Debug.Console(1, "Error: {0} not present", adapterType);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(1, "Error: {0}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static EthernetAdapterInfo GetEthernetAdapterProperties(short adapterId, EthernetAdapterType adapterType)
|
||||||
|
{
|
||||||
|
EthernetAdapterInfo adapterInfo = new EthernetAdapterInfo();
|
||||||
|
|
||||||
|
adapterInfo.Type = adapterType;
|
||||||
|
adapterInfo.DhcpIsOn = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, adapterId) == "on" ? true : false;
|
||||||
|
adapterInfo.Hostname = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, adapterId);
|
||||||
|
adapterInfo.MacAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, adapterId);
|
||||||
|
adapterInfo.IpAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, adapterId);
|
||||||
|
adapterInfo.Subnet = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK, adapterId);
|
||||||
|
adapterInfo.Gateway = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_ROUTER, adapterId);
|
||||||
|
adapterInfo.Domain = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, adapterId);
|
||||||
|
|
||||||
|
string dns = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DNS_SERVER, adapterId);
|
||||||
|
if (dns.Contains(","))
|
||||||
|
{
|
||||||
|
string[] dnsList = dns.Split(',');
|
||||||
|
for (var i = 0; i < dnsList.Length; i++)
|
||||||
|
{
|
||||||
|
if (i == 0)
|
||||||
|
adapterInfo.Dns1 = !string.IsNullOrEmpty(dnsList[0]) ? dnsList[0] : "0.0.0.0";
|
||||||
|
if (i == 1)
|
||||||
|
adapterInfo.Dns2 = !string.IsNullOrEmpty(dnsList[1]) ? dnsList[1] : "0.0.0.0";
|
||||||
|
if (i == 2)
|
||||||
|
adapterInfo.Dns3 = !string.IsNullOrEmpty(dnsList[2]) ? dnsList[2] : "0.0.0.0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
adapterInfo.Dns1 = !string.IsNullOrEmpty(dns) ? dns : "0.0.0.0";
|
||||||
|
adapterInfo.Dns2 = "0.0.0.0";
|
||||||
|
adapterInfo.Dns3 = "0.0.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
return adapterInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,6 +224,7 @@
|
|||||||
<Compile Include="Fusion\FusionRviDataClasses.cs" />
|
<Compile Include="Fusion\FusionRviDataClasses.cs" />
|
||||||
<Compile Include="Gateways\CenRfgwController.cs" />
|
<Compile Include="Gateways\CenRfgwController.cs" />
|
||||||
<Compile Include="Gateways\EssentialsRfGatewayConfig.cs" />
|
<Compile Include="Gateways\EssentialsRfGatewayConfig.cs" />
|
||||||
|
<Compile Include="Global\EthernetAdapterInfo.cs" />
|
||||||
<Compile Include="Queues\ComsMessage.cs" />
|
<Compile Include="Queues\ComsMessage.cs" />
|
||||||
<Compile Include="Queues\ProcessStringMessage.cs" />
|
<Compile Include="Queues\ProcessStringMessage.cs" />
|
||||||
<Compile Include="Queues\GenericQueue.cs" />
|
<Compile Include="Queues\GenericQueue.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user