Files

117 lines
4.9 KiB
C#
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
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}");
}
}
}