Skip to content

Commit

Permalink
Work on configration management (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Apr 12, 2018
1 parent a5d321c commit 2e2043d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public partial class DeviceConfiguration
/// <summary>
/// Wireless network configuration marker
/// </summary>
public static string MarkerConfigurationWirelessNetwork_v1 = "WN1\0";
public static string MarkerConfigurationWireless80211Network_v1 = "WN1\0";

/// <summary>
/// Wireless AP configuration marker
/// </summary>
public static string MarkerConfigurationWirelessAP_v1 = "AP1\0";
public static string MarkerConfigurationWireless80211AP_v1 = "AP1\0";

/////////////////////////////////////////////////////////////

Expand All @@ -52,12 +52,12 @@ public NetworkConfigurationProperties[] NetworkConfigurations
set { _networkConfigurations = value; }
}

private NetworkWirelessConfigurationProperties[] _networkWirelessConfigurations;
private NetworkWireless80211ConfigurationProperties[] _networkWirelessConfigurations;

/// <summary>
/// Collection of <see cref="NetworkWirelessConfigurationProperties"/> blocks in a target device.
/// Collection of <see cref="NetworkWireless80211ConfigurationProperties"/> blocks in a target device.
/// </summary>
public NetworkWirelessConfigurationProperties[] NetworkWirelessConfigurations
public NetworkWireless80211ConfigurationProperties[] NetworkWirelessConfigurations
{
get
{
Expand All @@ -72,13 +72,13 @@ public NetworkWirelessConfigurationProperties[] NetworkWirelessConfigurations

public DeviceConfiguration()
: this(new NetworkConfigurationProperties[0],
new NetworkWirelessConfigurationProperties[0])
new NetworkWireless80211ConfigurationProperties[0])
{
}

public DeviceConfiguration(
NetworkConfigurationProperties[] networkConfiguratons,
NetworkWirelessConfigurationProperties[] networkWirelessConfiguratons
NetworkWireless80211ConfigurationProperties[] networkWirelessConfiguratons
)
{
_networkConfigurations = networkConfiguratons;
Expand All @@ -91,7 +91,7 @@ public static explicit operator DeviceConfigurationBase(DeviceConfiguration valu
return new DeviceConfigurationBase()
{
NetworkConfigurations = value.NetworkConfigurations.Select(i => (NetworkConfigurationBase)i).ToArray(),
NetworkWirelessConfigurations = value.NetworkWirelessConfigurations.Select(i => (NetworkWirelessConfigurationBase)i).ToArray()
NetworkWirelessConfigurations = value.NetworkWirelessConfigurations.Select(i => (NetworkWireless80211ConfigurationBase)i).ToArray()
};
}

Expand Down Expand Up @@ -212,14 +212,14 @@ public static explicit operator NetworkConfigurationBase(NetworkConfigurationPro

}

public class NetworkWirelessConfigurationProperties : NetworkWirelessConfigurationPropertiesBase
public class NetworkWireless80211ConfigurationProperties : NetworkWireless80211ConfigurationPropertiesBase
{
public NetworkWirelessConfigurationProperties()
public NetworkWireless80211ConfigurationProperties()
{

}

public NetworkWirelessConfigurationProperties(
public NetworkWireless80211ConfigurationProperties(
byte[] macAddress,
uint ipv4Address,
uint ipv4NetMask,
Expand Down Expand Up @@ -263,11 +263,11 @@ public NetworkWirelessConfigurationProperties(
}

// operator to allow cast_ing a NetworkWirelessConfigurationProperties object to NetworkConfigurationBase
public static explicit operator NetworkWirelessConfigurationBase(NetworkWirelessConfigurationProperties value)
public static explicit operator NetworkWireless80211ConfigurationBase(NetworkWireless80211ConfigurationProperties value)
{
var networkWirelessConfig = new NetworkWirelessConfigurationBase()
var networkWirelessConfig = new NetworkWireless80211ConfigurationBase()
{
Marker = Encoding.UTF8.GetBytes(MarkerConfigurationNetwork_v1),
Marker = Encoding.UTF8.GetBytes(MarkerConfigurationWireless80211Network_v1),

MacAddress = value.MacAddress,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class DeviceConfigurationBase
{
public NetworkConfigurationBase[] NetworkConfigurations;

public NetworkWirelessConfigurationBase[] NetworkWirelessConfigurations { get; internal set; }
public NetworkWireless80211ConfigurationBase[] NetworkWirelessConfigurations { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace nanoFramework.Tools.Debugger
{
public class NetworkWirelessConfigurationBase : NetworkConfigurationBase
public class NetworkWireless80211ConfigurationBase : NetworkConfigurationBase
{
/// <summary>
/// Type of authentication used on the wireless network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace nanoFramework.Tools.Debugger
{
public class NetworkWirelessConfigurationPropertiesBase : NetworkConfigurationPropertiesBase
public class NetworkWireless80211ConfigurationPropertiesBase : NetworkConfigurationPropertiesBase
{
public AuthenticationType Authentication { get; set; }
public EncryptionType Encryption { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void PrepareForDeserialize(int size, byte[] data, Converter converter)
}
}

public class NetworkWirelessConfiguration : NetworkWirelessConfigurationBase, IConverter
public class NetworkWirelessConfiguration : NetworkWireless80211ConfigurationBase, IConverter
{
public NetworkWirelessConfiguration()
{
Expand Down Expand Up @@ -340,6 +340,7 @@ public void PrepareForDeserialize(int size, byte[] data, Converter converter)
public class Monitor_UpdateConfiguration
{
public uint Configuration;
public uint ConfigurationBlockIndex;
public uint Length = 0;
public byte[] Data = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3198,11 +3198,11 @@ public DeviceConfiguration.NetworkConfigurationProperties[] GetAllNetworkConfigu
return networkConfigurations.ToArray();
}

public DeviceConfiguration.NetworkWirelessConfigurationProperties[] GetAllNetworkWirelessConfigurations()
public DeviceConfiguration.NetworkWireless80211ConfigurationProperties[] GetAllNetworkWirelessConfigurations()
{
List<DeviceConfiguration.NetworkWirelessConfigurationProperties> networkWirelessConfigurations = new List<DeviceConfiguration.NetworkWirelessConfigurationProperties>();
List<DeviceConfiguration.NetworkWireless80211ConfigurationProperties> networkWirelessConfigurations = new List<DeviceConfiguration.NetworkWireless80211ConfigurationProperties>();

DeviceConfiguration.NetworkWirelessConfigurationProperties config = null;
DeviceConfiguration.NetworkWireless80211ConfigurationProperties config = null;
uint index = 0;

do
Expand Down Expand Up @@ -3255,15 +3255,15 @@ public DeviceConfiguration.NetworkConfigurationProperties GetNetworkConfiguraton
return networkConfigProperties;
}

public DeviceConfiguration.NetworkWirelessConfigurationProperties GetNetworkWirelessConfiguratonProperties(uint configurationBlockIndex)
public DeviceConfiguration.NetworkWireless80211ConfigurationProperties GetNetworkWirelessConfiguratonProperties(uint configurationBlockIndex)
{
Debug.WriteLine("NetworkWirelessConfiguratonProperties");

IncomingMessage reply = GetDeviceConfiguration((uint)DeviceConfiguration.DeviceConfigurationOption.WirelessNetwork, configurationBlockIndex);

Commands.Monitor_QueryConfiguration.NetworkWirelessConfiguration networkWirelessConfiguration = new Commands.Monitor_QueryConfiguration.NetworkWirelessConfiguration();

DeviceConfiguration.NetworkWirelessConfigurationProperties networkWirelessConfigProperties = new DeviceConfiguration.NetworkWirelessConfigurationProperties();
DeviceConfiguration.NetworkWireless80211ConfigurationProperties networkWirelessConfigProperties = new DeviceConfiguration.NetworkWireless80211ConfigurationProperties();

if (reply != null)
{
Expand All @@ -3280,7 +3280,7 @@ public DeviceConfiguration.NetworkWirelessConfigurationProperties GetNetworkWire
networkWirelessConfiguration.StartupAddressMode = (byte)AddressMode.Invalid;
}

networkWirelessConfigProperties = new DeviceConfiguration.NetworkWirelessConfigurationProperties(
networkWirelessConfigProperties = new DeviceConfiguration.NetworkWireless80211ConfigurationProperties(
networkWirelessConfiguration.MacAddress, networkWirelessConfiguration.IPv4Address,
networkWirelessConfiguration.IPv4NetMask, networkWirelessConfiguration.IPv4GatewayAddress,
networkWirelessConfiguration.IPv4DNSAddress1, networkWirelessConfiguration.IPv4DNSAddress2,
Expand Down Expand Up @@ -3403,23 +3403,22 @@ public bool UpdateDeviceConfiguration<T>(T configuration, uint configurationBloc
// Create cancellation token source
CancellationTokenSource cts = new CancellationTokenSource();

// update the network class
var oldConfiguration = GetDeviceConfiguration(cts.Token);
// get the current configuration from the device
var currentConfiguration = GetDeviceConfiguration(cts.Token);

if (oldConfiguration != null)
if (currentConfiguration != null)
{
// get the configuration
// now update the specific configuration block
if (configuration.GetType().Equals(typeof(DeviceConfiguration.NetworkConfigurationProperties)))
{
oldConfiguration.NetworkConfigurations[configurationBlockIndex] = configuration as DeviceConfiguration.NetworkConfigurationProperties;
currentConfiguration.NetworkConfigurations[configurationBlockIndex] = configuration as DeviceConfiguration.NetworkConfigurationProperties;
}
else if (configuration.GetType().Equals(typeof(DeviceConfiguration.NetworkWirelessConfigurationProperties)))
else if (configuration.GetType().Equals(typeof(DeviceConfiguration.NetworkWireless80211ConfigurationProperties)))
{
oldConfiguration.NetworkWirelessConfigurations[configurationBlockIndex] = configuration as DeviceConfiguration.NetworkWirelessConfigurationProperties;
currentConfiguration.NetworkWirelessConfigurations[configurationBlockIndex] = configuration as DeviceConfiguration.NetworkWireless80211ConfigurationProperties;
}

if(UpdateDeviceConfiguration(oldConfiguration))
if(UpdateDeviceConfiguration(currentConfiguration))
{
// done here
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<Compile Include="$(MSBuildThisFileDirectory)DeviceConfiguration\DeviceConfigurationOption.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DeviceConfiguration\DeviceConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DeviceConfiguration\DeviceConfigurationBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DeviceConfiguration\NetworkWirelessConfigurationPropertiesBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DeviceConfiguration\NetworkWirelessConfigurationBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DeviceConfiguration\NetworkWireless80211ConfigurationPropertiesBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DeviceConfiguration\NetworkWireless80211ConfigurationBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DeviceConfiguration\NetworkConfigurationPropertiesBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DeviceConfiguration\NetworkConfigurationBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)EndPoint.cs" />
Expand Down

0 comments on commit 2e2043d

Please sign in to comment.