This commit is contained in:
Roland Drabesch
2025-09-01 12:50:32 +02:00
26 changed files with 531 additions and 91 deletions
@@ -127,6 +127,7 @@
if (addresses.Any(x => x == 0 || x == address))
{
task.SirtId = this.Id;
var bytes = this.tasks
.AddOrUpdate(address, addr => task, (addr, oldTask) => task)
.Start();
@@ -20,12 +20,14 @@
public const byte LEN_IX = 8;
public const byte DATA_IX = 9;
public const byte AKN_ANS = 0x12;
public const byte ACKN_ANSW = 0x12;
public const byte FROM_AIR = 0x11;
public const byte LAT = 0x01;
public const byte BUP = 0x00;
public const byte DEBUG = 0x0B;
public const byte SEMI = 0x08;
public const byte ENC_KEY_LEN = 16;
}
}
@@ -93,7 +93,7 @@
public DateTimeOffset Timestamp { get; set; } = DateTimeOffset.UtcNow;
public override string ToString()
=> $"{this.Timestamp}|{this.SirtId}|{this.Frequency}|{BitConverter.ToString(this.GetBytes())}";
=> $"{this.Timestamp:yyyy-MM-ddTHH:mm:ssZ}|{this.SirtId}|{this.Frequency}|{BitConverter.ToString(this.GetBytes())}";
public byte[] GetBytes()
{
@@ -13,7 +13,7 @@
public override void Push(SIRTMessage response)
{
if (response.Command == SIRTConstants.AKN_ANS)
if (response.Command == SIRTConstants.ACKN_ANSW)
{
this.Payload = response.Payload;
@@ -12,7 +12,7 @@
public override void Push(SIRTMessage response)
{
if (response.Command == SIRTConstants.AKN_ANS && response.P1 == 0)
if (response.Command == SIRTConstants.ACKN_ANSW && response.P1 == 0)
{
this.Payload = response.Payload;
@@ -15,7 +15,7 @@
public override void Push(SIRTMessage response)
{
if (response.Command == SIRTConstants.AKN_ANS)
if (response.Command == SIRTConstants.ACKN_ANSW)
{
this.Payload = response.Payload;
@@ -14,25 +14,24 @@
private event Action<SIRTMessage> SEMIReceived;
private event Action<SIRTMessage> UnknownReceived;
public event Action<SIRTMessage> MessageSent;
public event Action<SIRTMessage> MessageReceived;
public bool IsEncrypted { get; set; }
public byte[] EncryptionKey { get; set; }
public WritePamTask()
{
this.request.Command = SIRTConstants.W_PAM;
this.p811 = this.request.P1;
this.AKNReceived += OnAKNReceived;
//this.BUPReceived += OnBUPReceived;
//this.LATReceived += OnLATReceived;
//this.DEBUGReceived += OnDEBUGReceived;
//this.SEMIReceived += OnSEMIReceived;
//this.UnknownReceived += OnUnknownReceived;
}
protected virtual void OnAKNReceived(SIRTMessage akn)
{
this.request.Command = SIRTConstants.W_PAM;
this.MessageSent += this.OnMessageSent;
this.AKNReceived += this.OnAKNReceived;
this.BUPReceived += this.OnBUPReceived;
this.LATReceived += this.OnLATReceived;
this.DEBUGReceived += this.OnDEBUGReceived;
this.SEMIReceived += this.OnSEMIReceived;
this.UnknownReceived += this.OnUnknownReceived;
}
public bool WakeUpModul
@@ -87,8 +86,11 @@
public override void Push(SIRTMessage response)
{
if (response.Command == SIRTConstants.AKN_ANS)
this.AnyTelegramReceived = true;
if (response.Command == SIRTConstants.ACKN_ANSW) // status of the modul, ping
{
this.DecriptResponse(response);
this.AKNReceived?.Invoke(response);
}
else if (response.Command == SIRTConstants.FROM_AIR)
@@ -98,48 +100,106 @@
if (payload != null && payload.Length > 0)
{
var type = payload[0];
var crc = payload.GetCrc();
this.IsEncrypted = crc != default(ushort);
if (this.IsEncrypted)
{
response.Payload = payload.DecryptResponse(this.EncryptionKey);
}
if (type == SIRTConstants.BUP)
if (type == SIRTConstants.BUP) // just bubble up message
{
this.DecriptResponse(response, payload);
this.BUPReceived?.Invoke(response);
}
else if (type == SIRTConstants.LAT)
else if (type == SIRTConstants.LAT) // module ready for receiving commands
{
this.DecriptResponse(response, payload);
this.LATReceived?.Invoke(response);
}
else if (type == SIRTConstants.DEBUG)
else if (type == SIRTConstants.DEBUG) // received only on specific commands
{
this.DecriptResponse(response, payload);
this.DEBUGReceived?.Invoke(response);
}
else if (type == SIRTConstants.SEMI)
else if (type == SIRTConstants.SEMI) // always the last answer of the command
{
this.DecriptResponse(response, payload);
this.SEMIReceived?.Invoke(response);
}
else
{
this.DecriptResponse(response, payload);
this.UnknownReceived?.Invoke(response);
}
}
else
{
this.DecriptResponse(response, payload);
this.UnknownReceived?.Invoke(response);
}
}
else
{
this.DecriptResponse(response);
this.UnknownReceived?.Invoke(response);
}
this.MessageReceived?.Invoke(response);
}
public override byte[] Start()
{
this.MessageSent?.Invoke(this.request);
var message = new SIRTMessage
{
Direction = this.request.Direction,
Command = this.request.Command,
P1 = this.request.P1,
P2 = this.request.P2,
Address = this.request.Address,
Payload = this.EncryptRequest(),
Frequency = this.Frequency,
SirtId = this.SirtId,
};
this.MessageSent?.Invoke(message);
this.SetRunning();
return message.GetBytes();
}
protected virtual void OnMessageSent(SIRTMessage request)
{
}
protected virtual void OnAKNReceived(SIRTMessage akn)
{
}
protected virtual void OnBUPReceived(SIRTMessage bup)
{
}
protected virtual void OnLATReceived(SIRTMessage lat)
{
}
protected virtual void OnDEBUGReceived(SIRTMessage debug)
{
}
protected virtual void OnSEMIReceived(SIRTMessage semi)
{
this.SetCompleted();
}
protected virtual void OnUnknownReceived(SIRTMessage unknown)
{
}
private byte[] EncryptRequest()
{
var requestPayload = this.request.Payload;
var payloadLength = requestPayload.Length;
@@ -152,19 +212,29 @@
payload = payload.EncryptRequest(this.EncryptionKey, this.RequestAddress);
}
this.SetRunning();
return payload;
}
return new SIRTMessage
private void DecriptResponse(SIRTMessage response, params byte[] payload)
{
if (payload == null || payload.Length == 0)
{
Direction = this.request.Direction,
Command = this.request.Command,
P1 = this.request.P1,
P2 = this.request.P2,
Address = this.request.Address,
Payload = payload,
Frequency = this.Frequency,
payload = response.Payload;
}
}.GetBytes();
this.IsEncrypted = payload.GetCrc() != default(ushort);
if (this.IsEncrypted)
{
if (this.EncryptionKey != null && this.EncryptionKey.Length == SIRTConstants.ENC_KEY_LEN)
{
response.Payload = payload.DecryptResponse(this.EncryptionKey);
}
else
{
this.SetCancelled();
}
}
}
private void SetP811(Action<P811> p811Setter)
@@ -17,7 +17,7 @@
public override void Push(SIRTMessage response)
{
if (response.Command == SIRTConstants.AKN_ANS)
if (response.Command == SIRTConstants.ACKN_ANSW)
{
this.SetCompleted();
}
@@ -1 +1 @@
b03dfbada453427a2bb1275645a5f1b525f29900
89102b0142e574de38a9f47d370f3334e5e6c268
@@ -114,7 +114,6 @@
public override void Push(SIRTMessage response)
{
this.MessageReceived?.Invoke(response);
this.AnyTelegramReceived = true;
if (this.State == SIRTTaskState.Cancelled)
@@ -229,7 +228,7 @@
response.Payload = data;
}
}
else if (response.Command == SIRTConstants.AKN_ANS)
else if (response.Command == SIRTConstants.ACKN_ANSW)
{
this.P12 = new P12(response.P1);
this.Label = "AKN";
@@ -248,6 +247,8 @@
this.MessageReceived?.Invoke(response);
}
public override string ToString() => BitConverter.ToString(this.request);
public static implicit operator byte[] (EregisterTask task)
=> task?.payload ?? Array.Empty<byte>();
}
@@ -220,6 +220,7 @@
public byte ActivationByThreshold { get; set; }
[CompareProperty]
public ushort OMS_Interval { get; set; }
public uint DisplayVolume { get; set; }