e-register manual programming

This commit is contained in:
Stoyan Zlatev
2025-01-24 12:10:40 +01:00
parent 828f8631ec
commit 3edc7df3a9
88 changed files with 1805 additions and 2796 deletions
@@ -1,32 +1,54 @@
namespace Common.Hardware.Ports
{
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public static class SerialDataExtensions
{
private const int ByteSize = 8;
private const int SByteSize = 16;
private const int Int16Size = 16;
private const int UInt16Size = 16;
private const int Int32Size = 32;
private const int UInt32Size = 32;
private const int Int64Size = 64;
private const int UInt64Size = 64;
public static byte[] GetBitsBE(this byte value)
{
var bytes = new byte[8];
var bits = new byte[ByteSize];
for (int i = 7, x = 0; i >= 0; i--, x++)
{
bytes[x] = (byte)((value >> i) % 2);
bits[x] = (byte)((value >> i) & 1);
}
return bytes;
return bits;
}
public static byte[] GetBitsLE(this byte value)
{
var bytes = new byte[8];
var bits = new byte[ByteSize];
for (var i = 0; i < 8; i++)
for (var i = 0; i < ByteSize; i++)
{
bytes[i] = (byte)((value >> i) % 2);
bits[i] = (byte)((value >> i) & 1);
}
return bytes;
return bits;
}
public static byte[] GetBitsLE(this ushort value)
{
var bits = new byte[UInt16Size];
for (var i = 0; i < UInt16Size; i++)
{
bits[i] = (byte)((value >> i) & 1);
}
return bits;
}
public static byte GetByteLE(this byte[] bits)
@@ -38,7 +60,7 @@
var value = default(byte);
for (var i = 0; i < 8; i++)
for (var i = 0; i < ByteSize; i++)
{
value ^= (byte)(bits[i] << i);
}
@@ -417,6 +439,27 @@
return value;
}
public static ushort ToUIint16LEFromBits(this byte[] bits)
{
const int size = 16;
if (bits is null)
{
bits = new byte[size];
}
Array.Resize(ref bits, size);
ushort value = 0;
for (var i = 0; i < size; i++)
{
value ^= (ushort)(bits[i] << i);
}
return value;
}
public static uint ToUInt32LE(this byte[] bytes, int start = 0)
{
var value = default(uint);
@@ -161,23 +161,15 @@
this.processingTask = Task.Factory.StartNew(() =>
{
var manualResetEventSlim = new ManualResetEventSlim();
var addresses = default(ICollection<uint>);
while (!this.cancellationToken.IsCancellationRequested)
{
// addresses = this.GetAddressesInPamPool();
foreach (var tasksQueue in this.tasks.Values.ToArray())
{
if (tasksQueue.TryPeek(out var task) && task.State == SIRTTaskState.Pending)
{
// if (addresses.Count < 5 && !addresses.Any(x => x == task.RequestAddress) && !addresses.Any(x => x == task.ResponseAddress))
{
this.serialPort.Write(task.Start());
this.Logging?.Invoke(task.ToString());
// addresses.Add(task.RequestAddress);
}
this.serialPort.Write(task.Start());
this.Logging?.Invoke(task.ToString());
}
manualResetEventSlim.Wait(100);
@@ -100,14 +100,10 @@
private EregisterProgrammingParameters GetProgrammingParameters()
{
var alarms = new AlarmsMask(this.SEMI.AlarmActiveInformation);
var dataLogContent = new ChangeDataLoggerSettings
{
LogContent = this.SEMI.LogContent
};
var fdrLogContent = new ChangeDataLoggerSettings
{
LogContent = this.SEMI.FixedDateReadingContent
};
var dataLogContent = new ChangeDataLoggerSettings();
dataLogContent.SetLogContent(this.SEMI.LogContent);
var fdrLogContent = new ChangeDataLoggerSettings();
fdrLogContent.SetLogContent(this.SEMI.FixedDateReadingContent);
var parameters = new EregisterProgrammingParameters
{
@@ -207,7 +207,7 @@
if (authLevel != AuthLevel.O)
{
var _bytes = ((long)authLevel).GetBytesLE();
var _bytes = ((ulong)authLevel).GetBytesLE();
Array.Resize(ref bytes, 6);
Array.Copy(_bytes, 0, bytes, 0, 6);
@@ -4,96 +4,106 @@
public class ChangeDataLoggerSettings : Pam
{
private readonly byte[] contentBits = new byte[16];
public ChangeDataLoggerSettings() : base(5, ChangeDataLoggerSettings)
{
}
public ushort TimeInterval { get; set; }
public ushort LogContent { get; set; }
public byte ForwardCounter
public ushort LogContent => this.contentBits.ToUIint16LEFromBits();
public bool ForwardCounter
{
get => (byte)(this.LogContent >> 12 & 1);
set => this.LogContent ^= (ushort)(value << 12);
get => this.contentBits[12] == 1;
set => this.contentBits[12] = (byte)(value ? 1 : 0);
}
public byte TimeOfMinimumFlow
public bool TimeOfMinimumFlow
{
get => (byte)(this.LogContent >> 11 & 1);
set => this.LogContent ^= (ushort)(value << 11);
get => this.contentBits[11] == 1;
set => this.contentBits[11] = (byte)(value ? 1 : 0);
}
public byte MinimumFlow
public bool MinimumFlow
{
get => (byte)(this.LogContent >> 10 & 1);
set => this.LogContent ^= (ushort)(value << 10);
get => this.contentBits[10] == 1;
set => this.contentBits[10] = (byte)(value ? 1 : 0);
}
public byte TimeOfBrokenPipe
public bool TimeOfBrokenPipe
{
get => (byte)(this.LogContent >> 9 & 1);
set => this.LogContent ^= (ushort)(value << 9);
get => this.contentBits[9] == 1;
set => this.contentBits[9] = (byte)(value ? 1 : 0);
}
public byte BrokenPipeFlow
public bool BrokenPipeFlow
{
get => (byte)(this.LogContent >> 8 & 1);
set => this.LogContent ^= (ushort)(value << 8);
get => this.contentBits[8] == 1;
set => this.contentBits[8] = (byte)(value ? 1 : 0);
}
public byte CurrentFlow
public bool CurrentFlow
{
get => (byte)(this.LogContent >> 7 & 1);
set => this.LogContent ^= (ushort)(value << 7);
get => this.contentBits[7] == 1;
set => this.contentBits[7] = (byte)(value ? 1 : 0);
}
public byte TimeOfPeakFlow
public bool TimeOfPeakFlow
{
get => (byte)(this.LogContent >> 6 & 1);
set => this.LogContent ^= (ushort)(value << 6);
get => this.contentBits[6] == 1;
set => this.contentBits[6] = (byte)(value ? 1 : 0);
}
public byte PeakFlow
public bool PeakFlow
{
get => (byte)(this.LogContent >> 5 & 1);
set => this.LogContent ^= (ushort)(value << 5);
get => this.contentBits[5] == 1;
set => this.contentBits[5] = (byte)(value ? 1 : 0);
}
public byte TimeOfMaximumFlow
public bool TimeOfMaximumFlow
{
get => (byte)(this.LogContent >> 4 & 1);
set => this.LogContent ^= (ushort)(value << 4);
get => this.contentBits[4] == 1;
set => this.contentBits[4] = (byte)(value ? 1 : 0);
}
public byte MaximumFlow
public bool MaximumFlow
{
get => (byte)(this.LogContent >> 3 & 1);
set => this.LogContent ^= (ushort)(value << 3);
get => this.contentBits[3] == 1;
set => this.contentBits[3] = (byte)(value ? 1 : 0);
}
public byte BackwardVolume
public bool BackwardVolume
{
get => (byte)(this.LogContent >> 2 & 1);
set => this.LogContent ^= (ushort)(value << 2);
get => this.contentBits[2] == 1;
set => this.contentBits[2] = (byte)(value ? 1 : 0);
}
public byte Counter
public bool Counter
{
get => (byte)(this.LogContent >> 1 & 1);
set => this.LogContent ^= (ushort)(value << 1);
get => this.contentBits[1] == 1;
set => this.contentBits[1] = (byte)(value ? 1 : 0);
}
public byte AlarmState
public bool AlarmState
{
get => (byte)(this.LogContent >> 0 & 1);
set => this.LogContent ^= (ushort)(value << 0);
get => this.contentBits[0] == 1;
set => this.contentBits[0] = (byte)(value ? 1 : 0);
}
public void SetLogContent(ushort value)
=> value.GetBitsLE()
.CopyTo(this.contentBits, 0);
public override byte[] ToByteArray()
{
this.TimeInterval.GetBytesBE().CopyTo(this.bytes, 1);
this.LogContent.GetBytesBE().CopyTo(this.bytes, 3);
this.TimeInterval
.GetBytesBE()
.CopyTo(this.bytes, 1);
this.LogContent
.GetBytesBE()
.CopyTo(this.bytes, 3);
return base.ToByteArray();
}
@@ -4,6 +4,8 @@
public class ChangeFixedDateReadingSettings : Pam
{
private readonly byte[] contentBits = new byte[16];
public ChangeFixedDateReadingSettings() : base(4, ChangeFixedDateReadingSettings)
{
}
@@ -14,88 +16,97 @@
set => this.bytes[1] = value;
}
public ushort LogContent
public ushort LogContent => this.contentBits.ToUIint16LEFromBits();
public bool ForwardCounter
{
get => this.bytes.ToUInt16BE(2);
set => value.GetBytesBE().CopyTo(this.bytes, 2);
get => this.contentBits[12] == 1;
set => this.contentBits[12] = (byte)(value ? 1 : 0);
}
public byte ForwardCounter
public bool TimeOfMinimumFlow
{
get => (byte)(this.LogContent >> 12 & 1);
set => this.LogContent ^= (ushort)(value << 12);
get => this.contentBits[11] == 1;
set => this.contentBits[11] = (byte)(value ? 1 : 0);
}
public byte TimeOfMinimumFlow
public bool MinimumFlow
{
get => (byte)(this.LogContent >> 11 & 1);
set => this.LogContent ^= (ushort)(value << 11);
get => this.contentBits[10] == 1;
set => this.contentBits[10] = (byte)(value ? 1 : 0);
}
public byte MinimumFlow
public bool TimeOfBrokenPipe
{
get => (byte)(this.LogContent >> 10 & 1);
set => this.LogContent ^= (ushort)(value << 10);
get => this.contentBits[9] == 1;
set => this.contentBits[9] = (byte)(value ? 1 : 0);
}
public byte TimeOfBrokenPipe
public bool BrokenPipeFlow
{
get => (byte)(this.LogContent >> 9 & 1);
set => this.LogContent ^= (ushort)(value << 9);
get => this.contentBits[8] == 1;
set => this.contentBits[8] = (byte)(value ? 1 : 0);
}
public byte BrokenPipeFlow
public bool CurrentFlow
{
get => (byte)(this.LogContent >> 8 & 1);
set => this.LogContent ^= (ushort)(value << 8);
get => this.contentBits[7] == 1;
set => this.contentBits[7] = (byte)(value ? 1 : 0);
}
public byte CurrentFlow
public bool TimeOfPeakFlow
{
get => (byte)(this.LogContent >> 7 & 1);
set => this.LogContent ^= (ushort)(value << 7);
get => this.contentBits[6] == 1;
set => this.contentBits[6] = (byte)(value ? 1 : 0);
}
public byte TimeOfPeakFlow
public bool PeakFlow
{
get => (byte)(this.LogContent >> 6 & 1);
set => this.LogContent ^= (ushort)(value << 6);
get => this.contentBits[5] == 1;
set => this.contentBits[5] = (byte)(value ? 1 : 0);
}
public byte PeakFlow
public bool TimeOfMaximumFlow
{
get => (byte)(this.LogContent >> 5 & 1);
set => this.LogContent ^= (ushort)(value << 5);
get => this.contentBits[4] == 1;
set => this.contentBits[4] = (byte)(value ? 1 : 0);
}
public byte TimeOfMaximumFlow
public bool MaximumFlow
{
get => (byte)(this.LogContent >> 4 & 1);
set => this.LogContent ^= (ushort)(value << 4);
get => this.contentBits[3] == 1;
set => this.contentBits[3] = (byte)(value ? 1 : 0);
}
public byte MaximumFlow
public bool BackwardVolume
{
get => (byte)(this.LogContent >> 3 & 1);
set => this.LogContent ^= (ushort)(value << 3);
get => this.contentBits[2] == 1;
set => this.contentBits[2] = (byte)(value ? 1 : 0);
}
public byte BackwardVolume
public bool Counter
{
get => (byte)(this.LogContent >> 2 & 1);
set => this.LogContent ^= (ushort)(value << 2);
get => this.contentBits[1] == 1;
set => this.contentBits[1] = (byte)(value ? 1 : 0);
}
public byte Counter
public bool AlarmState
{
get => (byte)(this.LogContent >> 1 & 1);
set => this.LogContent ^= (ushort)(value << 1);
get => this.contentBits[0] == 1;
set => this.contentBits[0] = (byte)(value ? 1 : 0);
}
public byte AlarmState
public void SetLogContent(ushort value)
=> value.GetBitsLE()
.CopyTo(this.contentBits, 0);
public override byte[] ToByteArray()
{
get => (byte)(this.LogContent >> 0 & 1);
set => this.LogContent ^= (ushort)(value << 0);
this.LogContent
.GetBytesBE()
.CopyTo(this.bytes, 3);
return base.ToByteArray();
}
}
}
@@ -34,7 +34,9 @@
public string HexKey
{
get => BitConverter.ToString(this.Key).Replace("-", string.Empty);
get => BitConverter
.ToString(this.Key)
.Replace("-", string.Empty);
set => this.Key = value.GetEncryptionKey();
}
}
@@ -5,6 +5,8 @@
protected DebugCmd(byte code) : base(3, GetDebug)
=> this.bytes[2] = code;
public override string CmdHex => $"{base.CmdHex}-{this.bytes[2]:X2}";
public static implicit operator byte[](DebugCmd cmd) => cmd.bytes;
/// <summary>
@@ -12,6 +12,8 @@
this.bytes[0] = cmd;
}
public virtual string CmdHex => $"{this.bytes[0]:X2}";
public Pam Append(Pam pam)
{
var appendBytes = pam.ToByteArray();
@@ -123,85 +123,85 @@
public ushort Data_Logging_Period { get; set; }
[CompareProperty]
public byte Data_Logging_Forward_Counter { get; set; }
public bool Data_Logging_Forward_Counter { get; set; }
[CompareProperty]
public byte Data_Logging_Time_Of_Minimum_Flow { get; set; }
public bool Data_Logging_Time_Of_Minimum_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Minimum_Flow { get; set; }
public bool Data_Logging_Minimum_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Time_Of_Broken_Pipe { get; set; }
public bool Data_Logging_Time_Of_Broken_Pipe { get; set; }
[CompareProperty]
public byte Data_Logging_Broken_Pipe_Flow { get; set; }
public bool Data_Logging_Broken_Pipe_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Current_Flow { get; set; }
public bool Data_Logging_Current_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Time_Of_Peak_Flow { get; set; }
public bool Data_Logging_Time_Of_Peak_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Peak_Flow { get; set; }
public bool Data_Logging_Peak_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Time_Of_Maximum_Flow { get; set; }
public bool Data_Logging_Time_Of_Maximum_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Maximum_Flow { get; set; }
public bool Data_Logging_Maximum_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Backward_Volume { get; set; }
public bool Data_Logging_Backward_Volume { get; set; }
[CompareProperty]
public byte Data_Logging_Counter { get; set; }
public bool Data_Logging_Counter { get; set; }
[CompareProperty]
public byte Data_Logging_Alarm_State { get; set; }
public bool Data_Logging_Alarm_State { get; set; }
[CompareProperty]
public byte FDR_Day_Of_Data_Reading { get; set; }
[CompareProperty]
public byte FDR_Forward_Counter { get; set; }
public bool FDR_Forward_Counter { get; set; }
[CompareProperty]
public byte FDR_Time_Of_Minimum_Flow { get; set; }
public bool FDR_Time_Of_Minimum_Flow { get; set; }
[CompareProperty]
public byte FDR_Minimum_Flow { get; set; }
public bool FDR_Minimum_Flow { get; set; }
[CompareProperty]
public byte FDR_Time_Of_Broken_Pipe { get; set; }
public bool FDR_Time_Of_Broken_Pipe { get; set; }
[CompareProperty]
public byte FDR_Broken_Pipe_Flow { get; set; }
public bool FDR_Broken_Pipe_Flow { get; set; }
[CompareProperty]
public byte FDR_Current_Flow { get; set; }
public bool FDR_Current_Flow { get; set; }
[CompareProperty]
public byte FDR_Time_Of_Peak_Flow { get; set; }
public bool FDR_Time_Of_Peak_Flow { get; set; }
[CompareProperty]
public byte FDR_Peak_Flow { get; set; }
public bool FDR_Peak_Flow { get; set; }
[CompareProperty]
public byte FDR_Time_Of_Maximum_Flow { get; set; }
public bool FDR_Time_Of_Maximum_Flow { get; set; }
[CompareProperty]
public byte FDR_Maximum_Flow { get; set; }
public bool FDR_Maximum_Flow { get; set; }
[CompareProperty]
public byte FDR_Backward_Volume { get; set; }
public bool FDR_Backward_Volume { get; set; }
[CompareProperty]
public byte FDR_Counter { get; set; }
public bool FDR_Counter { get; set; }
[CompareProperty]
public byte FDR_Alarm_State { get; set; }
public bool FDR_Alarm_State { get; set; }
public byte PowerLevelHex { get; set; }