Skip to content

Commit

Permalink
Reorganize LoRaDeviceBase and LoRaDeviceDetails models (#967)
Browse files Browse the repository at this point in the history
  • Loading branch information
audserraCGI authored Jul 25, 2022
1 parent e38da2e commit a5641a8
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 195 deletions.
24 changes: 12 additions & 12 deletions src/AzureIoTHub.Portal/Server/Mappers/LoRaDeviceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ public LoRaDeviceDetails CreateDeviceDetails(Twin twin, IEnumerable<string> tags
DevAddr = Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.DevAddr)),
AppSKey = Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.AppSKey)),
NwkSKey = Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.NwkSKey)),
Deduplication = Enum.TryParse<DeduplicationMode>(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.Deduplication)), out var deduplication) ? deduplication : DeduplicationMode.None,
PreferredWindow = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.PreferredWindow)), out var preferedWindow) ? preferedWindow : null,
Supports32BitFCnt = bool.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.Supports32BitFCnt)), out var boolResult) ? boolResult : null,
ABPRelaxMode = bool.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.ABPRelaxMode)), out boolResult) ? boolResult : null,
KeepAliveTimeout = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.KeepAliveTimeout)), out var keepAliveTimeout) ? keepAliveTimeout : null,
Downlink = bool.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.Downlink)), out boolResult) ? boolResult : null,
FCntDownStart = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.FCntDownStart)), out var fcntDownStart) ? fcntDownStart : null,
FCntResetCounter = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.FCntResetCounter)), out var fcntResetCounter) ? fcntResetCounter : null,
FCntUpStart = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.FCntUpStart)), out var fcntUpStart) ? fcntUpStart : null,
RX1DROffset = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.RX1DROffset)), out var rx1DataOffset) ? rx1DataOffset : null,
RX2DataRate = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.RX2DataRate)), out var rx2DataRate) ? rx2DataRate : null,
RXDelay = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceBase.RXDelay)), out var rxDelay) ? rxDelay : null,
Deduplication = Enum.TryParse<DeduplicationMode>(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.Deduplication)), out var deduplication) ? deduplication : DeduplicationMode.None,
PreferredWindow = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.PreferredWindow)), out var preferedWindow) ? preferedWindow : null,
Supports32BitFCnt = bool.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.Supports32BitFCnt)), out var boolResult) ? boolResult : null,
ABPRelaxMode = bool.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.ABPRelaxMode)), out boolResult) ? boolResult : null,
KeepAliveTimeout = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.KeepAliveTimeout)), out var keepAliveTimeout) ? keepAliveTimeout : null,
Downlink = bool.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.Downlink)), out boolResult) ? boolResult : null,
FCntDownStart = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.FCntDownStart)), out var fcntDownStart) ? fcntDownStart : null,
FCntResetCounter = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.FCntResetCounter)), out var fcntResetCounter) ? fcntResetCounter : null,
FCntUpStart = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.FCntUpStart)), out var fcntUpStart) ? fcntUpStart : null,
RX1DROffset = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.RX1DROffset)), out var rx1DataOffset) ? rx1DataOffset : null,
RX2DataRate = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.RX2DataRate)), out var rx2DataRate) ? rx2DataRate : null,
RXDelay = int.TryParse(Helpers.DeviceHelper.RetrieveDesiredPropertyValue(twin, nameof(LoRaDeviceDetails.RXDelay)), out var rxDelay) ? rxDelay : null,
DataRate = Helpers.DeviceHelper.RetrieveReportedPropertyValue(twin, nameof(LoRaDeviceDetails.DataRate)),
TxPower = Helpers.DeviceHelper.RetrieveReportedPropertyValue(twin, nameof(LoRaDeviceDetails.TxPower)),
NbRep = Helpers.DeviceHelper.RetrieveReportedPropertyValue(twin, nameof(LoRaDeviceDetails.NbRep)),
Expand Down
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(LoRaDeviceBase.PreferredWindow)]?.ToString(), out var intResult) ? intResult : 1,
Supports32BitFCnt = bool.TryParse(entity[nameof(LoRaDeviceBase.Supports32BitFCnt)]?.ToString(), out var boolResult) ? boolResult : null,
ABPRelaxMode = bool.TryParse(entity[nameof(LoRaDeviceBase.ABPRelaxMode)]?.ToString(), out boolResult) ? boolResult : null,
KeepAliveTimeout = int.TryParse(entity[nameof(LoRaDeviceBase.KeepAliveTimeout)]?.ToString(), out intResult) ? intResult : null,
Deduplication = Enum.TryParse<DeduplicationMode>(entity[nameof(LoRaDeviceBase.Deduplication)]?.ToString(), out var deduplication) ? deduplication : DeduplicationMode.None,
Downlink = bool.TryParse(entity[nameof(LoRaDeviceBase.Downlink)]?.ToString(), out boolResult) ? boolResult : null,
FCntDownStart = int.TryParse(entity[nameof(LoRaDeviceBase.FCntDownStart)]?.ToString(), out intResult) ? intResult : null,
FCntResetCounter = int.TryParse(entity[nameof(LoRaDeviceBase.FCntResetCounter)]?.ToString(), out intResult) ? intResult : null,
FCntUpStart = int.TryParse(entity[nameof(LoRaDeviceBase.FCntUpStart)]?.ToString(), out intResult) ? intResult : null,
RX1DROffset = int.TryParse(entity[nameof(LoRaDeviceBase.RX1DROffset)]?.ToString(), out intResult) ? intResult : null,
RX2DataRate = int.TryParse(entity[nameof(LoRaDeviceBase.RX2DataRate)]?.ToString(), out intResult) ? intResult : null,
RXDelay = int.TryParse(entity[nameof(LoRaDeviceBase.RXDelay)]?.ToString(), out intResult) ? intResult : null
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
};
}

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(LoRaDeviceBase.Supports32BitFCnt), model.Supports32BitFCnt, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.ABPRelaxMode), model.ABPRelaxMode, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.KeepAliveTimeout), model.KeepAliveTimeout, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.PreferredWindow), model.PreferredWindow, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.Downlink), model.Downlink, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.Deduplication), model.Deduplication.ToString(), desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.FCntDownStart), model.FCntDownStart, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.FCntResetCounter), model.FCntResetCounter, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.FCntUpStart), model.FCntUpStart, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.RX1DROffset), model.RX1DROffset, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.RX2DataRate), model.RX2DataRate, desiredProperties);
AddOptionnalProperties(entity, nameof(LoRaDeviceBase.RXDelay), model.RXDelay, 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);

return desiredProperties;
}
Expand Down
158 changes: 0 additions & 158 deletions src/AzureIoTHub.Portal/Shared/Models/v1.0/LoRaWAN/LoRaDeviceBase.cs

This file was deleted.

Loading

0 comments on commit a5641a8

Please sign in to comment.