init
This commit is contained in:
278
Common/DTS.CommonCore/Classes/DASFactory/ATDStagger.cs
Normal file
278
Common/DTS.CommonCore/Classes/DASFactory/ATDStagger.cs
Normal file
@@ -0,0 +1,278 @@
|
||||
using DTS.Common.Interface.DASFactory;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
|
||||
namespace DTS.Common.Classes.DASFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// this class attempts to prevent delays in processing commands by controlling how many devices are talked to at once
|
||||
/// testing with python has shown that greatest efficiency on ATD side is by talking to one device on each port at once
|
||||
/// testing on DataPRO side has shown that talking to too many devices simultaneously can cause delays in device communication
|
||||
/// 16237 Add in ATD sequencing/staggering for services
|
||||
/// Add in ATD sequencing/staggering for services
|
||||
/// </summary>
|
||||
//public class ATDStagger
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// this maps from a S6DB to a lookup of port to a sorted list of devices.
|
||||
// /// this allows us to get the next device on a port of a S6DB
|
||||
// /// </summary>
|
||||
// private Dictionary<IDASCommunication, Dictionary<int, List<IDASCommunication>>> _s6DBToPortToDevices =
|
||||
// new Dictionary<IDASCommunication, Dictionary<int, List<IDASCommunication>>>();
|
||||
|
||||
// /// <summary>
|
||||
// /// any das that need to be operated on that aren't attached to a distributor
|
||||
// /// this makes sure we don't lose anybody in the service
|
||||
// /// </summary>
|
||||
// private List<IDASCommunication> _restOfTheDAS = new List<IDASCommunication>();
|
||||
|
||||
// public enum States
|
||||
// {
|
||||
// Waiting, //has not started
|
||||
// Started, //has started but not finished
|
||||
// Finished //has already finished
|
||||
// };
|
||||
|
||||
// /// <summary>
|
||||
// /// constructs a new stagger instance, with given devices [all devices enterring service]
|
||||
// /// and a SQL Command structure (used for querying device layout)
|
||||
// /// </summary>
|
||||
// /// <param name="devices"></param>
|
||||
// /// <param name="cmd"></param>
|
||||
// public ATDStagger(IDASCommunication[] devices, IDbCommand cmd)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// cmd.CommandType = CommandType.Text;
|
||||
// cmd.CommandText = "SELECT [SerialNumber], [PositionOnDistributor], [PositionOnChain], [Port], [ParentDAS] FROM [DataPro].[dbo].[DAS] WHERE [Port] > 0";
|
||||
// var serialToInfo = new Dictionary<string, Tuple<string, int, int, int, string>>();
|
||||
// var parentDASToSerials = new Dictionary<string, List<string>>();
|
||||
|
||||
// //the goal here is to determine S6DB->port->position on chain mapping for all devices in the service
|
||||
// using (var reader = cmd.ExecuteReader())
|
||||
// {
|
||||
// while (reader.Read())
|
||||
// {
|
||||
// var serial = Convert.ToString(reader["SerialNumber"]);
|
||||
// var positionOnDistributor = Convert.ToInt32(reader["PositionOnDistributor"]);
|
||||
// var positionOnChain = Convert.ToInt32(reader["PositionOnChain"]);
|
||||
// var port = Convert.ToInt32(reader["Port"]);
|
||||
// var parentDAS = Convert.ToString(reader["ParentDAS"]);
|
||||
// var tuple = new Tuple<string, int, int, int, string>(serial, positionOnDistributor, positionOnChain, port, parentDAS);
|
||||
// serialToInfo[serial] = tuple;
|
||||
// if (!parentDASToSerials.ContainsKey(parentDAS))
|
||||
// {
|
||||
// parentDASToSerials[parentDAS] = new List<string>();
|
||||
// }
|
||||
// parentDASToSerials[parentDAS].Add(serial);
|
||||
// }
|
||||
// }
|
||||
|
||||
// var serialsDealtWith = new HashSet<string>();
|
||||
// //tool to make it easier to look up a device given a serial number
|
||||
// var dasSerialToIDAS = new Dictionary<string, IDASCommunication>();
|
||||
// foreach (var das in devices)
|
||||
// {
|
||||
// dasSerialToIDAS[das.SerialNumber] = das;
|
||||
// }
|
||||
|
||||
// //tool to make it easier to lookup a S6DB given an ip address
|
||||
// //this is used for associating S6 which aren't stored in the db
|
||||
// //associated to a S6DB, but are connected to one
|
||||
// var ipAddressToS6DB = new Dictionary<string, IDASCommunication>();
|
||||
|
||||
// lock (MyLock)
|
||||
// {
|
||||
// //process every unit which is in the db attached to a S6DB
|
||||
// foreach (var das in devices)
|
||||
// {
|
||||
// //initialize every device enterring the service as currently waiting to start service
|
||||
// _deviceStates[das] = States.Waiting;
|
||||
// //now look for any units attached to this unit (assuming this unit is a S6DB)
|
||||
// if (das.IsSlice6Distributor())
|
||||
// {
|
||||
// //store the ip address to device mapping incase there are units attached but not associated in db
|
||||
// var ip = ((ICommunication) das).ConnectString.Split(new[] {':'})[0];
|
||||
// ipAddressToS6DB[ip] = das;
|
||||
// _s6DBToPortToDevices[das] = new Dictionary<int, List<IDASCommunication>>();
|
||||
// //S6DB normally has 4 ports, but lists them as 2,3,4,5, just for safety I'm doing 1-5
|
||||
// for (int i = 0; i <= 5; i++)
|
||||
// {
|
||||
// _s6DBToPortToDevices[das][i] = new List<IDASCommunication>();
|
||||
// }
|
||||
|
||||
// if (parentDASToSerials.ContainsKey(das.SerialNumber))
|
||||
// {
|
||||
// using (var eSerials = parentDASToSerials[das.SerialNumber].GetEnumerator())
|
||||
// {
|
||||
// while (eSerials.MoveNext())
|
||||
// {
|
||||
// if (dasSerialToIDAS.ContainsKey(eSerials.Current) && serialToInfo.ContainsKey(eSerials.Current))
|
||||
// {
|
||||
// var tuple = serialToInfo[eSerials.Current];
|
||||
// //item 3 is the port, only ports 2-5 are really valid, but here we just check <=5
|
||||
// if (tuple.Item3 <= 5)
|
||||
// {
|
||||
// _s6DBToPortToDevices[das][tuple.Item3]
|
||||
// .Add(dasSerialToIDAS[eSerials.Current]);
|
||||
// serialsDealtWith.Add(eSerials.Current);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// //now every unit which is in the db attached to a distributor has been handled, handle any extra units
|
||||
// //starting with the units attached to any S6DB but not associated in the db, we'll determine those using ip addresses
|
||||
// foreach (var das in devices)
|
||||
// {
|
||||
// if (!serialsDealtWith.Contains(das.SerialNumber))
|
||||
// {
|
||||
// var ip = ((ICommunication) das).ConnectString.Split(new[] {':'})[0];
|
||||
// if (ipAddressToS6DB.ContainsKey(ip))
|
||||
// {
|
||||
// var s6DB = ipAddressToS6DB[ip];
|
||||
// //we don't know what port the devices is on, make it up trying to distribute evenely across ports
|
||||
// //even if we end up talking to 4 devices on one port it'll be better than talking to 26 devices all at once
|
||||
// var insertAt = 0;
|
||||
// var min = int.MaxValue;
|
||||
// for (var i = 2; i <= 5; i++)
|
||||
// {
|
||||
// if (_s6DBToPortToDevices[s6DB][i].Count < min)
|
||||
// {
|
||||
// insertAt = i;
|
||||
// min = _s6DBToPortToDevices[s6DB][i].Count;
|
||||
// }
|
||||
// }
|
||||
// _s6DBToPortToDevices[s6DB][insertAt].Add(das);
|
||||
// serialsDealtWith.Add(das.SerialNumber);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _restOfTheDAS.Add(das);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// APILogger.Log(ex);
|
||||
// }
|
||||
// cmd.Connection.Close();
|
||||
// cmd.Dispose();
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// returns an array of all devices which have started (but not finished)
|
||||
// /// this is used for checking for finished devices
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public IDASCommunication[] GetStartedUnits()
|
||||
// {
|
||||
// lock (MyLock)
|
||||
// {
|
||||
// var any = _deviceStates.Any(device => device.Value == States.Started);
|
||||
// if (!any)
|
||||
// {
|
||||
// return new IDASCommunication[0];
|
||||
// }
|
||||
// return _deviceStates.Where(device => device.Value == States.Started).Select(device => device.Key)
|
||||
// .ToArray();
|
||||
// }
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// returns the next device that should start the service
|
||||
// /// or null if no devices are ready to start
|
||||
// /// we want to run one device on every port on every S6DB, but ideally only 1
|
||||
// /// then when one device is done we can start another
|
||||
// /// </summary>
|
||||
// /// <param name="units">all units in the service</param>
|
||||
// /// <returns></returns>
|
||||
// public IDASCommunication GetNextDevice(IDASCommunication [] units)
|
||||
// {
|
||||
// lock (MyLock)
|
||||
// {
|
||||
// using (var dasEnum = _s6DBToPortToDevices.GetEnumerator())
|
||||
// {
|
||||
// while (dasEnum.MoveNext())
|
||||
// {
|
||||
// var s6DB = dasEnum.Current.Key;
|
||||
// using (var ports = dasEnum.Current.Value.GetEnumerator())
|
||||
// {
|
||||
// while (ports.MoveNext())
|
||||
// {
|
||||
// var devicesOnPort = ports.Current.Value;
|
||||
// if (!devicesOnPort.Any())
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// var started = devicesOnPort.Count(device => _deviceStates[device] == States.Started);
|
||||
// //if there's a started device on this port, don't send from this port
|
||||
// if( started >= 3){ continue; }
|
||||
// var anyWaiting = devicesOnPort.Any(device => _deviceStates[device] == States.Waiting && units.Contains(device));
|
||||
// if( !anyWaiting ){ continue; }
|
||||
// var selected = devicesOnPort.First(device => _deviceStates[device] == States.Waiting && units.Contains(device));
|
||||
// return selected;
|
||||
// }
|
||||
// }
|
||||
// if (units.Contains(s6DB) && _deviceStates[s6DB] == States.Waiting)
|
||||
// {
|
||||
// return s6DB;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// //finally there could be devices in the service which aren't attached to any distributor (USB devices, etc)
|
||||
// //they have to get start too ...
|
||||
// var anyWaitingFromRest = _restOfTheDAS.Any(device => _deviceStates[device] == States.Waiting && units.Contains(device));
|
||||
// if( !anyWaitingFromRest ){ return null; }
|
||||
|
||||
// return _restOfTheDAS.First(device =>_deviceStates[device] == States.Waiting && units.Contains(device));
|
||||
// }
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// holds the device state (waiting/started/finished)
|
||||
// /// </summary>
|
||||
// private Dictionary<IDASCommunication, States> _deviceStates = new Dictionary<IDASCommunication, States>();
|
||||
|
||||
// /// <summary>
|
||||
// /// returns whether all devices are finished or not
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public bool AreAllDevicesFinished()
|
||||
// {
|
||||
// lock (MyLock)
|
||||
// {
|
||||
// return !_deviceStates.Values.Any(state => state != States.Finished);
|
||||
// }
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// lock used to control access to device states/etc
|
||||
// /// </summary>
|
||||
// private static readonly object MyLock = new object();
|
||||
|
||||
// /// <summary>
|
||||
// /// marks a devices as started
|
||||
// /// </summary>
|
||||
// /// <param name="das"></param>
|
||||
// public void MarkDeviceStared(IDASCommunication das)
|
||||
// {
|
||||
// lock(MyLock){ _deviceStates[das] = States.Started;}
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// marks a device as finished
|
||||
// /// </summary>
|
||||
// /// <param name="das"></param>
|
||||
// public void MarkDeviceFinished(IDASCommunication das)
|
||||
// {
|
||||
// lock (MyLock)
|
||||
// {
|
||||
// _deviceStates[das] = States.Finished;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
242
Common/DTS.CommonCore/Classes/DASFactory/TMSNConfig.cs
Normal file
242
Common/DTS.CommonCore/Classes/DASFactory/TMSNConfig.cs
Normal file
@@ -0,0 +1,242 @@
|
||||
using DTS.Common.Enums;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DTS.Common.Classes.DASFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// this class encapsulates/replaces a uint array that was already in use in FWTU and DP
|
||||
/// it adds some named fields and some to and from just to make things a little easier
|
||||
/// </summary>
|
||||
public class TMNSConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// the TMNS config implementation in firmware is just an array of uint32, so here's the same thing internally
|
||||
/// </summary>
|
||||
private uint[] _values;
|
||||
/// <summary>
|
||||
/// the TMNS PCM sub frame id
|
||||
/// </summary>
|
||||
public uint TMNS_PCMSubFrameId
|
||||
{
|
||||
get => GetValue(Fields.TMNS_PCMSubFrameID);
|
||||
set => SetValue(Fields.TMNS_PCMSubFrameID, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// the TMNS message id
|
||||
/// </summary>
|
||||
public uint TMNS_MsgId
|
||||
{
|
||||
get => GetValue(Fields.TMNS_MsgId);
|
||||
set => SetValue(Fields.TMNS_MsgId, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// the TMNS PCM minor per major setting
|
||||
/// </summary>
|
||||
public uint TMNS_PCMMinorPerMajor
|
||||
{
|
||||
get => GetValue(Fields.TMNS_PCMMinorPerMajor);
|
||||
set => SetValue(Fields.TMNS_PCMMinorPerMajor, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// the TMNS TMATs port number setting
|
||||
/// </summary>
|
||||
public uint TMNS_TMATSPortNumber
|
||||
{
|
||||
get => GetValue(Fields.TMNS_TMATSPortNumber);
|
||||
set => SetValue(Fields.TMNS_TMATSPortNumber, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// the IENA UDP source port number
|
||||
/// </summary>
|
||||
public uint IENAUDP_PortNumber
|
||||
{
|
||||
get => GetValue(Fields.IENAUDP_PortNumber);
|
||||
set => SetValue(Fields.IENAUDP_PortNumber, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// reserved field 5
|
||||
/// </summary>
|
||||
public uint TMNS5
|
||||
{
|
||||
get => GetValue(Fields.TMNS5);
|
||||
set => SetValue(Fields.TMNS5, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// reserved field 6
|
||||
/// </summary>
|
||||
public uint TMNS6
|
||||
{
|
||||
get => GetValue(Fields.TMNS6);
|
||||
set => SetValue(Fields.TMNS6, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// reserved field 7
|
||||
/// </summary>
|
||||
public uint TMNS7
|
||||
{
|
||||
get => GetValue(Fields.TMNS7);
|
||||
set => SetValue(Fields.TMNS7, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// all fields in the TMNS config unit array and their order
|
||||
/// </summary>
|
||||
public enum Fields
|
||||
{
|
||||
TMNS_PCMSubFrameID,
|
||||
TMNS_MsgId,
|
||||
TMNS_PCMMinorPerMajor,
|
||||
TMNS_TMATSPortNumber,
|
||||
IENAUDP_PortNumber,
|
||||
TMNS5,
|
||||
TMNS6,
|
||||
TMNS7
|
||||
}
|
||||
/// <summary>
|
||||
/// handles common init from all constructors
|
||||
/// </summary>
|
||||
private void CommonInit()
|
||||
{
|
||||
var fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
||||
_values = new uint[fields.Length];
|
||||
}
|
||||
/// <summary>
|
||||
/// constructor that takes an array of uints in the same order as the TMNS config
|
||||
/// </summary>
|
||||
/// <param name="parameters"></param>
|
||||
public TMNSConfig(uint [] parameters)
|
||||
{
|
||||
CommonInit();
|
||||
if (null == parameters) { return; }
|
||||
for (var i=0; i < parameters.Length && i < _values.Length; i++)
|
||||
{
|
||||
_values[i] = parameters[i];
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// constructor that takes an array of uints comma separated (and allows for enclosing () around whole string)
|
||||
/// </summary>
|
||||
/// <param name="parameters"></param>
|
||||
public TMNSConfig(string parameters)
|
||||
{
|
||||
CommonInit();
|
||||
parameters = parameters.Replace("(", "").Replace(")", "");
|
||||
var tokens = parameters.Split(new[] { ',' });
|
||||
for (var i=0; i < tokens.Length && i < _values.Length; i++)
|
||||
{
|
||||
if( uint.TryParse(tokens[i], out var temp))
|
||||
{
|
||||
_values[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
public TMNSConfig()
|
||||
{
|
||||
CommonInit();
|
||||
}
|
||||
/// <summary>
|
||||
/// sets indicated field to indicated value
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <param name="value"></param>
|
||||
public void SetValue(Fields field, uint value)
|
||||
{
|
||||
_values[(int)field] = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// gets the value from the indicated field
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
public uint GetValue(Fields field) => _values[(int)field];
|
||||
|
||||
public uint [] ToUintArray()
|
||||
{
|
||||
var copy = new uint[_values.Length];
|
||||
_values.CopyTo(copy, 0);
|
||||
return copy;
|
||||
}
|
||||
/// <summary>
|
||||
/// returns a string suitable for storage (x,...n) of the TMNS config
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ToCSVString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("(");
|
||||
for (var i = 0; i < _values.Length; i++)
|
||||
{
|
||||
if( i > 0) { sb.Append(","); }
|
||||
sb.Append(_values[i]);
|
||||
}
|
||||
sb.Append(")");
|
||||
return sb.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// returns true if the profile is a ch10 streaming profile
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsCh10(UDPStreamProfile profile)
|
||||
{
|
||||
switch (profile)
|
||||
{
|
||||
case UDPStreamProfile.CH10_MANUAL_CONFIG:
|
||||
case UDPStreamProfile.CH10_PCM128_MM:
|
||||
case UDPStreamProfile.CH10_ANALOG:
|
||||
case UDPStreamProfile.CH10_PCM_STANDARD:
|
||||
case UDPStreamProfile.CH10_PCM_SUPERCOM:
|
||||
case UDPStreamProfile.CH10_PCM_128BIT_2HDR:
|
||||
case UDPStreamProfile.CH10_ANALOG_2HDR:
|
||||
case UDPStreamProfile.CH10_PCM_STANDARD_2HDR:
|
||||
case UDPStreamProfile.CH10_PCM_SUPERCOM_2HDR:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// returns true if the streaming profile is an IENA profile
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsIENA(UDPStreamProfile profile)
|
||||
{
|
||||
switch (profile)
|
||||
{
|
||||
case UDPStreamProfile.IENA_PTYPE_STREAM: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// returns true if the streaming profile is a TMNS profile
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsTMNS(UDPStreamProfile profile)
|
||||
{
|
||||
switch(profile)
|
||||
{
|
||||
case UDPStreamProfile.TMNS_PCM_STANDARD:
|
||||
case UDPStreamProfile.TMNS_PCM_SUPERCOM:
|
||||
return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// returns true if the streaming profile is a UART profile
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsUART(UDPStreamProfile profile)
|
||||
{
|
||||
switch (profile)
|
||||
{
|
||||
case UDPStreamProfile.UART_STREAM: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
116
Common/DTS.CommonCore/Classes/DASFactory/TemperatureConfig.cs
Normal file
116
Common/DTS.CommonCore/Classes/DASFactory/TemperatureConfig.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using DTS.Common.Enums.DASFactory;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using static DTS.Common.Enums.DASFactory.DFConstantsAndEnums;
|
||||
|
||||
namespace DTS.Common.Classes.DASFactory
|
||||
{
|
||||
public class TemperatureConfig
|
||||
{
|
||||
public ushort LogEnable { get; set; }
|
||||
public ushort LogIntervalSec { get; set; }
|
||||
|
||||
private BitArray _channels = new BitArray(new[] { 0x00, 0x00 });
|
||||
public ushort Channels
|
||||
{
|
||||
get
|
||||
{
|
||||
var bytes = new byte[2];
|
||||
_channels.CopyTo(bytes, 0);
|
||||
return BitConverter.ToUInt16(bytes, 0);
|
||||
}
|
||||
set
|
||||
{
|
||||
var bytes = BitConverter.GetBytes(value);
|
||||
_channels = new BitArray(bytes);
|
||||
}
|
||||
}
|
||||
public const ushort Reserved = 0;
|
||||
public bool MCUTemp
|
||||
{
|
||||
get => _channels.Get((int)TempLogChannelBits.OnBoardTemp);
|
||||
set => _channels.Set((int)TempLogChannelBits.OnBoardTemp, value);
|
||||
}
|
||||
public bool OnBoardHumidity
|
||||
{
|
||||
get => _channels.Get((int)TempLogChannelBits.OnBoardHumidity);
|
||||
set => _channels.Set((int)TempLogChannelBits.OnBoardHumidity, value);
|
||||
}
|
||||
public bool EnvironmentalCh1
|
||||
{
|
||||
get => _channels.Get((int)TempLogChannelBits.EnvironmentalCh1);
|
||||
set => _channels.Set((int)TempLogChannelBits.EnvironmentalCh1, value);
|
||||
}
|
||||
public bool EnvironmentalCh2
|
||||
{
|
||||
get => _channels.Get((int)TempLogChannelBits.EnvironmentalCh2);
|
||||
set => _channels.Set((int)TempLogChannelBits.EnvironmentalCh2, value);
|
||||
}
|
||||
public bool EnvironmentalCh3
|
||||
{
|
||||
get => _channels.Get((int)TempLogChannelBits.EnvironmentalCh3);
|
||||
set => _channels.Set((int)TempLogChannelBits.EnvironmentalCh3, value);
|
||||
}
|
||||
public bool EnvironmentalCh4
|
||||
{
|
||||
get => _channels.Get((int)TempLogChannelBits.EnvironmentalCh4);
|
||||
set => _channels.Set((int)TempLogChannelBits.EnvironmentalCh4, value);
|
||||
}
|
||||
public ushort[] ToUShortArray()
|
||||
{
|
||||
return new[] { LogEnable, LogIntervalSec, Channels, Reserved };
|
||||
}
|
||||
public TemperatureConfig() { }
|
||||
public TemperatureConfig(ushort[] ushortArray)
|
||||
{
|
||||
if (null == ushortArray) { return; }
|
||||
LogEnable = GetUShort(ushortArray, 0);
|
||||
LogIntervalSec = GetUShort(ushortArray, 1);
|
||||
Channels = GetUShort(ushortArray, 2);
|
||||
}
|
||||
private ushort GetUShort(ushort[] ushortArray, int position)
|
||||
{
|
||||
if (ushortArray.Length > position) { return ushortArray[position]; }
|
||||
return 0;
|
||||
}
|
||||
public int[] GetChannelsArray()
|
||||
{
|
||||
var list = new List<int>();
|
||||
for (var i = 0; i < _channels.Length; i++)
|
||||
{
|
||||
if (_channels.Get(i))
|
||||
{
|
||||
list.Add(i);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
public S6DBDiagnosticChannelList[] GetMeasurementChannels()
|
||||
{
|
||||
var list = new List<S6DBDiagnosticChannelList>();
|
||||
if (MCUTemp) { list.Add(S6DBDiagnosticChannelList.DiagMcuTemperature); }
|
||||
if (OnBoardHumidity) { list.Add(S6DBDiagnosticChannelList.DiagEnv_1_Humidity); }
|
||||
if (EnvironmentalCh1) { list.Add(S6DBDiagnosticChannelList.DiagEnv_1_Temperature); }
|
||||
if (EnvironmentalCh2) { list.Add(S6DBDiagnosticChannelList.DiagEnv_2_Temperature); }
|
||||
if (EnvironmentalCh3) { list.Add(S6DBDiagnosticChannelList.DiagEnv_3_Temperature); }
|
||||
if (EnvironmentalCh4) { list.Add(S6DBDiagnosticChannelList.DiagEnv_4_Temperature); }
|
||||
return list.ToArray();
|
||||
}
|
||||
private readonly Dictionary<S6DBDiagnosticChannelList, TempLogChannelBits> _diagChannelToTempLogBit = new Dictionary<S6DBDiagnosticChannelList, TempLogChannelBits>()
|
||||
{
|
||||
{S6DBDiagnosticChannelList.DiagMcuTemperature, TempLogChannelBits.OnBoardTemp },
|
||||
{S6DBDiagnosticChannelList.DiagEnv_1_Humidity, TempLogChannelBits.OnBoardHumidity },
|
||||
{S6DBDiagnosticChannelList.DiagEnv_1_Temperature, TempLogChannelBits.EnvironmentalCh1 },
|
||||
{S6DBDiagnosticChannelList.DiagEnv_2_Temperature, TempLogChannelBits.EnvironmentalCh2 },
|
||||
{S6DBDiagnosticChannelList.DiagEnv_3_Temperature, TempLogChannelBits.EnvironmentalCh3 },
|
||||
{S6DBDiagnosticChannelList.DiagEnv_4_Temperature, TempLogChannelBits.EnvironmentalCh4 }
|
||||
};
|
||||
public TempLogChannelBits GetChannelBitForDiagChannel(S6DBDiagnosticChannelList ch)
|
||||
{
|
||||
if(_diagChannelToTempLogBit.ContainsKey(ch)) { return _diagChannelToTempLogBit[ch]; }
|
||||
throw new NullReferenceException($"Not found: {ch}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user