Skip to content

Commit

Permalink
Reorganize LoRaDeviceModelBase and LoRaDeviceModel models
Browse files Browse the repository at this point in the history
  • Loading branch information
audserraCGI committed Jul 25, 2022
1 parent a5641a8 commit 9389b98
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 171 deletions.
48 changes: 24 additions & 24 deletions src/AzureIoTHub.Portal/Server/Mappers/LoRaDeviceModelMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ public LoRaDeviceModel CreateDeviceModel(TableEntity entity)
SensorDecoder = entity[nameof(LoRaDeviceModel.SensorDecoder)]?.ToString(),
SupportLoRaFeatures = true,
UseOTAA = bool.Parse(entity[nameof(LoRaDeviceModel.UseOTAA)]?.ToString() ?? "true"),
PreferredWindow = int.TryParse(entity[nameof(LoRaDeviceModelBase.PreferredWindow)]?.ToString(), out var intResult) ? intResult : 1,
Supports32BitFCnt = bool.TryParse(entity[nameof(LoRaDeviceModelBase.Supports32BitFCnt)]?.ToString(), out var boolResult) ? boolResult : null,
ABPRelaxMode = bool.TryParse(entity[nameof(LoRaDeviceModelBase.ABPRelaxMode)]?.ToString(), out boolResult) ? boolResult : null,
KeepAliveTimeout = int.TryParse(entity[nameof(LoRaDeviceModelBase.KeepAliveTimeout)]?.ToString(), out intResult) ? intResult : null,
Deduplication = Enum.TryParse<DeduplicationMode>(entity[nameof(LoRaDeviceModelBase.Deduplication)]?.ToString(), out var deduplication) ? deduplication : DeduplicationMode.None,
Downlink = bool.TryParse(entity[nameof(LoRaDeviceModelBase.Downlink)]?.ToString(), out boolResult) ? boolResult : null,
FCntDownStart = int.TryParse(entity[nameof(LoRaDeviceModelBase.FCntDownStart)]?.ToString(), out intResult) ? intResult : null,
FCntResetCounter = int.TryParse(entity[nameof(LoRaDeviceModelBase.FCntResetCounter)]?.ToString(), out intResult) ? intResult : null,
FCntUpStart = int.TryParse(entity[nameof(LoRaDeviceModelBase.FCntUpStart)]?.ToString(), out intResult) ? intResult : null,
RX1DROffset = int.TryParse(entity[nameof(LoRaDeviceModelBase.RX1DROffset)]?.ToString(), out intResult) ? intResult : null,
RX2DataRate = int.TryParse(entity[nameof(LoRaDeviceModelBase.RX2DataRate)]?.ToString(), out intResult) ? intResult : null,
RXDelay = int.TryParse(entity[nameof(LoRaDeviceModelBase.RXDelay)]?.ToString(), out intResult) ? intResult : null
PreferredWindow = int.TryParse(entity[nameof(LoRaDeviceModel.PreferredWindow)]?.ToString(), out var intResult) ? intResult : 1,
Supports32BitFCnt = bool.TryParse(entity[nameof(LoRaDeviceModel.Supports32BitFCnt)]?.ToString(), out var boolResult) ? boolResult : null,
ABPRelaxMode = bool.TryParse(entity[nameof(LoRaDeviceModel.ABPRelaxMode)]?.ToString(), out boolResult) ? boolResult : null,
KeepAliveTimeout = int.TryParse(entity[nameof(LoRaDeviceModel.KeepAliveTimeout)]?.ToString(), out intResult) ? intResult : null,
Deduplication = Enum.TryParse<DeduplicationMode>(entity[nameof(LoRaDeviceModel.Deduplication)]?.ToString(), out var deduplication) ? deduplication : DeduplicationMode.None,
Downlink = bool.TryParse(entity[nameof(LoRaDeviceModel.Downlink)]?.ToString(), out boolResult) ? boolResult : null,
FCntDownStart = int.TryParse(entity[nameof(LoRaDeviceModel.FCntDownStart)]?.ToString(), out intResult) ? intResult : null,
FCntResetCounter = int.TryParse(entity[nameof(LoRaDeviceModel.FCntResetCounter)]?.ToString(), out intResult) ? intResult : null,
FCntUpStart = int.TryParse(entity[nameof(LoRaDeviceModel.FCntUpStart)]?.ToString(), out intResult) ? intResult : null,
RX1DROffset = int.TryParse(entity[nameof(LoRaDeviceModel.RX1DROffset)]?.ToString(), out intResult) ? intResult : null,
RX2DataRate = int.TryParse(entity[nameof(LoRaDeviceModel.RX2DataRate)]?.ToString(), out intResult) ? intResult : null,
RXDelay = int.TryParse(entity[nameof(LoRaDeviceModel.RXDelay)]?.ToString(), out intResult) ? intResult : null
};
}

Expand All @@ -79,18 +79,18 @@ public Dictionary<string, object> UpdateTableEntity(TableEntity entity, LoRaDevi
var desiredProperties = new Dictionary<string, object>();

AddOptionnalProperties(entity, nameof(LoRaDeviceModel.SensorDecoder), model.SensorDecoder, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.Supports32BitFCnt), model.Supports32BitFCnt, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.ABPRelaxMode), model.ABPRelaxMode, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.KeepAliveTimeout), model.KeepAliveTimeout, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.PreferredWindow), model.PreferredWindow, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.Downlink), model.Downlink, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.Deduplication), model.Deduplication.ToString(), desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.FCntDownStart), model.FCntDownStart, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.FCntResetCounter), model.FCntResetCounter, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.FCntUpStart), model.FCntUpStart, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.RX1DROffset), model.RX1DROffset, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.RX2DataRate), model.RX2DataRate, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModelBase.RXDelay), model.RXDelay, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.Supports32BitFCnt), model.Supports32BitFCnt, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.ABPRelaxMode), model.ABPRelaxMode, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.KeepAliveTimeout), model.KeepAliveTimeout, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.PreferredWindow), model.PreferredWindow, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.Downlink), model.Downlink, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.Deduplication), model.Deduplication.ToString(), desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.FCntDownStart), model.FCntDownStart, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.FCntResetCounter), model.FCntResetCounter, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.FCntUpStart), model.FCntUpStart, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.RX1DROffset), model.RX1DROffset, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.RX2DataRate), model.RX2DataRate, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceModel.RXDelay), model.RXDelay, desiredProperties);

return desiredProperties;
}
Expand Down
130 changes: 129 additions & 1 deletion src/AzureIoTHub.Portal/Shared/Models/v1.0/LoRaWAN/LoRaDeviceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,135 @@
namespace AzureIoTHub.Portal.Models.v10.LoRaWAN
{
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;

/// <summary>
/// LoRa Device model.
/// </summary>
public class LoRaDeviceModel : LoRaDeviceModelBase
public class LoRaDeviceModel : DeviceModel
{
/// <summary>
/// The LoRa device class.
/// Default is A.
/// </summary>
[DefaultValue(ClassType.A)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public ClassType ClassType { get; set; }

/// <summary>
/// A value indicating whether the device uses OTAA to authenticate to LoRaWAN network. Otherwise ABP.
/// Default is true.
/// </summary>
[DefaultValue(true)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool UseOTAA { get; set; }

/// <summary>
/// The sensor decoder API Url.
/// </summary>
public string SensorDecoder { get; set; }

/// <summary>
/// Allows disabling the downstream (cloud to device) for a device.
/// By default downstream messages are enabled.
/// </summary>
[DefaultValue(true)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool? Downlink { get; set; }

/// <summary>
/// Allows setting the device preferred receive window (RX1 or RX2).
/// The default preferred receive window is 1.
/// </summary>
[DefaultValue(1)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public int PreferredWindow { get; set; }

/// <summary>
/// Allows controlling the handling of duplicate messages received by multiple gateways.
/// The default is Drop.
/// </summary>
[DefaultValue(DeduplicationMode.Drop)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public DeduplicationMode Deduplication { get; set; }

/// <summary>
/// Allows setting an offset between received Datarate and retransmit datarate as specified in the LoRa Specifiations.
/// Valid for OTAA devices.
/// If an invalid value is provided the network server will use default value 0.
/// </summary>
[DefaultValue(0)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public int? RX1DROffset { get; set; }

/// <summary>
/// Allows setting a custom Datarate for second receive windows.
/// Valid for OTAA devices.
/// If an invalid value is provided the network server will use default value 0 (DR0).
/// </summary>
[DefaultValue(0)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public int? RX2DataRate { get; set; }

/// <summary>
/// Allows setting a custom wait time between receiving and transmission as specified in the specification.
/// </summary>
public int? RXDelay { get; set; }

/// <summary>
/// Allows to disable the relax mode when using ABP.
/// By default relaxed mode is enabled.
/// </summary>
[DefaultValue(true)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool? ABPRelaxMode { get; set; }

/// <summary>
/// Allows to explicitly specify a frame counter up start value.
/// If the device joins, this value will be used to validate the first frame and initialize the server state for the device.
/// Default is 0.
/// </summary>
[Range(0, 4294967295)]
[DefaultValue(0)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public int? FCntUpStart { get; set; }

/// <summary>
/// Allows to explicitly specify a frame counter down start value.
/// Default is 0.
/// </summary>
[Range(0, 4294967295)]
[DefaultValue(0)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public int? FCntDownStart { get; set; }

/// <summary>
/// Allows to reset the frame counters to the FCntUpStart/FCntDownStart values respectively.
/// Default is 0.
/// </summary>
[Range(0, 4294967295)]
[DefaultValue(0)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public int? FCntResetCounter { get; set; }

/// <summary>
/// Allow the usage of 32bit counters on your device.
/// </summary>
[DefaultValue(true)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public bool? Supports32BitFCnt { get; set; }

/// <summary>
/// Allows defining a sliding expiration to the connection between the leaf device and IoT/Edge Hub.
/// The default is none, which causes the connection to not be dropped.
/// </summary>
[DefaultValue(null)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public int? KeepAliveTimeout { get; set; }


/// <summary>
/// Initializes a new instance of the <see cref="LoRaDeviceModel"/> class.
/// </summary>
Expand All @@ -31,6 +154,11 @@ public LoRaDeviceModel(DeviceModel from)
/// </summary>
public LoRaDeviceModel()
{
ClassType = ClassType.A;
Downlink = true;
PreferredWindow = 1;
Deduplication = DeduplicationMode.None;
ABPRelaxMode = true;
}
}
}

This file was deleted.

0 comments on commit 9389b98

Please sign in to comment.