e-register reset on AKN

This commit is contained in:
Stoyan Zlatev 2025-04-29 11:24:33 +02:00
parent bbcbbbd449
commit d5b6e033e4
14 changed files with 88 additions and 97 deletions

View File

@ -166,47 +166,40 @@
public override string ToString()
{
var x = new StringBuilder();
if (this.BufFull)
{
x.AppendLine(nameof(this.BufFull));
return nameof(this.BufFull);
}
if (this.OsBusy)
else if (this.OsBusy)
{
x.AppendLine(nameof(this.OsBusy));
return nameof(this.OsBusy);
}
if (this.WrongCRC)
else if (this.WrongCRC)
{
x.AppendLine(nameof(this.WrongCRC));
return nameof(this.WrongCRC);
}
if (this.CmdNotExecuted)
else if (this.CmdNotExecuted)
{
x.AppendLine(nameof(this.CmdNotExecuted));
return nameof(this.CmdNotExecuted);
}
if (this.CmdUnknown)
else if (this.CmdUnknown)
{
x.AppendLine(nameof(this.CmdUnknown));
return nameof(this.CmdUnknown);
}
if (this.NoEntry)
else if (this.NoEntry)
{
x.AppendLine(nameof(this.NoEntry));
return nameof(this.NoEntry);
}
if (this.ByteUnknown)
else if (this.ByteUnknown)
{
x.AppendLine(nameof(this.ByteUnknown));
return nameof(this.ByteUnknown);
}
if (this.WildCardAddr)
else if (this.WildCardAddr)
{
x.AppendLine(nameof(this.WildCardAddr));
return nameof(this.WildCardAddr);
}
if (x.Length > 0)
{
return x.ToString().Trim();
}
return default(string);
return "AKN";
}
public static implicit operator byte(P12 p11)

View File

@ -114,44 +114,28 @@
/// Checks if the given task can be sent then replaces existing SIRTTask (if any) and starts the new one.
/// </summary>
public bool Start(SIRTTask task)
{
var address = task.RequestAddress;
var addresses = this.pampool.Values.AsEnumerable();
var canStart = this.pampool.Count < 5 || addresses.Any(x => x == 0 || x == address);
SIRTLogger.LogMessage($"{this.PortName}|{this.pampool.Count} addresses in pam pool: {string.Join(", ", address)}");
SIRTLogger.LogMessage($"{this.PortName}|Can start task: {canStart}");
if (canStart)
{
var newTask = this.tasks.AddOrUpdate(
key: address,
addValueFactory: addr => task,
updateValueFactory: (addr, oldTask) =>
{
this.DeleteFromPamPool(oldTask);
return task;
});
var bytes = newTask.Start();
this.sirtStream.Write(bytes);
SIRTLogger.LogMessage($"{this.PortName}|RX: {BitConverter.ToString(bytes)}");
}
return canStart;
}
public void Write(SIRTTask task)
{
if (task.Frequency == this.Frequency)
{
task.Timestamp = DateTimeOffset.UtcNow;
task.SirtId = this.Id;
var bytes = task.Start();
var address = task.RequestAddress;
var addresses = this.pampool.Values.AsEnumerable();
this.sirtStream.Write(bytes);
SIRTLogger.LogMessage($"{this.PortName}|TX: {BitConverter.ToString(bytes)}");
if (this.pampool.Count < 5 || addresses.Any(x => x == 0 || x == address))
{
var newTask = this.tasks.AddOrUpdate(
key: address,
addValueFactory: addr => task,
updateValueFactory: (addr, oldTask) => task);
var bytes = newTask.Start();
this.sirtStream.Write(bytes);
SIRTLogger.LogMessage($"{this.PortName}|TX: {BitConverter.ToString(bytes)}");
return true;
}
}
return false;
}
private void LogContinuationError(Task task)

View File

@ -20,7 +20,7 @@
public const byte LEN_IX = 8;
public const byte DATA_IX = 9;
public static byte ACKN_ANSW = 0x12;
public static byte AKN_ANS = 0x12;
public static byte FROM_AIR = 0x11;
public static byte LAT = 0x01;

View File

@ -11,6 +11,6 @@
}
public override void Push(SIRTMessage _)
=> this.Complete();
=> this.SetCompleted();
}
}

View File

@ -13,7 +13,7 @@
public override void Push(SIRTMessage response)
{
if (response.Command == SIRTConstants.ACKN_ANSW)
if (response.Command == SIRTConstants.AKN_ANS)
{
this.Payload = response.Payload;
@ -22,7 +22,7 @@
this.SirtId = BitConverter.ToString(this.Payload);
this.Frequency = this.SirtId[10] == '0' ? 868 : 433;
this.Complete();
this.SetCompleted();
}
}
}

View File

@ -12,11 +12,11 @@
public override void Push(SIRTMessage response)
{
if (response.Command == SIRTConstants.ACKN_ANSW && response.P1 == 0)
if (response.Command == SIRTConstants.AKN_ANS && response.P1 == 0)
{
this.Payload = response.Payload;
this.Complete();
this.SetCompleted();
}
}
}

View File

@ -15,11 +15,11 @@
public override void Push(SIRTMessage response)
{
if (response.Command == SIRTConstants.ACKN_ANSW)
if (response.Command == SIRTConstants.AKN_ANS)
{
this.Payload = response.Payload;
this.Complete();
this.SetCompleted();
}
}
}

View File

@ -60,23 +60,31 @@
public int Timeout { get; set; } = 10_000;
public void Cancel()
public abstract void Push(SIRTMessage response);
public void SetCancelled()
{
this.awaiter.Set();
this.State = SIRTTaskState.Cancelled;
}
public void Complete()
public void SetCompleted()
{
this.awaiter.Set();
this.State = SIRTTaskState.Completed;
}
public abstract void Push(SIRTMessage response);
public void SetPending()
{
this.awaiter.Set();
this.awaiter.Reset();
public void Running()
this.State = SIRTTaskState.Pending;
}
public void SetRunning()
{
this.State = SIRTTaskState.Running;
this.awaiter.Reset();

View File

@ -73,7 +73,7 @@
{
if (response.Length > 0 && response.Payload[0] == SIRTConstants.SEMI)
{
this.Complete();
this.SetCompleted();
}
}
}

View File

@ -17,9 +17,9 @@
public override void Push(SIRTMessage response)
{
if (response.Command == SIRTConstants.ACKN_ANSW)
if (response.Command == SIRTConstants.AKN_ANS)
{
this.Complete();
this.SetCompleted();
}
}
}

View File

@ -113,16 +113,16 @@
this.history.Push(task);
task.Wait();
//if (firstTask && !task.AnyTelegramReceived)
//{
// _ = MessageBox.Show($"Das Rechenwerk an Ep: {task.SlotNr} mit Funkadresse: {task.RequestAddress}|{task.ResponseAddress} sendet nicht. "
// + $"Überprüfen Sie, ob alle SIRT's sind und oder die Funkfrequenz von dem Rechenwerk ist nicht verwechselt."
// , "Achtung"
// , MessageBoxButtons.OK);
// stopProgramming = true;
// break;
//}
// if (firstTask && !task.AnyTelegramReceived)
// {
// _ = MessageBox.Show($"Das Rechenwerk an Ep: {task.SlotNr} mit Funkadresse: {task.RequestAddress}|{task.ResponseAddress} sendet nicht. "
// + $"Überprüfen Sie, ob alle SIRT's sind und oder die Funkfrequenz von dem Rechenwerk ist nicht verwechselt."
// , "Achtung"
// , MessageBoxButtons.OK);
// stopProgramming = true;
// break;
// }
if (task.ErrorMessage != null)
{
@ -131,7 +131,7 @@
if (result == DialogResult.No)
{
task.Cancel();
task.SetCancelled();
stopProgramming = true;
break;
@ -146,12 +146,12 @@
break;
}
//if (task.FactoryState == FactoryState.Shipment && !this.runningTasks.IsEmpty)
//{
// lastTask.Label = "GESCHLOSSEN";
// lastTask.NotifyChanged();
// break;
//}
// if (task.FactoryState == FactoryState.Shipment && !this.runningTasks.IsEmpty)
// {
// lastTask.Label = "GESCHLOSSEN";
// lastTask.NotifyChanged();
// break;
// }
if (task.State == SIRTTaskState.Completed)
{
@ -206,7 +206,7 @@
}
else if (task.State == SIRTTaskState.Cancelled)
{
eregisterTask.Cancel();
eregisterTask.SetCancelled();
}
eregisterTask.RequestAddress = task.RequestAddress;

View File

@ -16,7 +16,7 @@
public EregisterTask(int frequency)
{
this.Timeout = 5_000;
this.Timeout = 15_000;
this.Frequency = frequency;
this.RSSI = new RSSI(0, frequency);
this.Label = nameof(SIRTTaskState.Pending);
@ -87,7 +87,7 @@
this.DEBUGMessage = default(DEBUG);
this.SEMIMessage = default(SEMI);
this.Running();
this.SetRunning();
return new SIRTMessage
{
@ -199,7 +199,7 @@
}
else
{
this.Complete();
this.SetCompleted();
}
}
else
@ -208,7 +208,7 @@
{
this.countFailures = 0;
this.Cancel();
this.SetCancelled();
}
}
}
@ -218,10 +218,16 @@
}
}
}
else if (response.Command == SIRTConstants.ACKN_ANSW)
else if (response.Command == SIRTConstants.AKN_ANS)
{
this.P12 = new P12(response.P1);
this.Label = this.P12.ToString() ?? "ACKN";
this.Label = "AKN";
if (this.Label != "AKN")
{
this.awaiter.Set();
this.awaiter.Reset();
}
}
else
{

View File

@ -29,7 +29,7 @@
case nameof(SIRTConstants.LAT): brush = warning; break;
case nameof(SIRTConstants.DEBUG): brush = info; break;
case nameof(PAMStatus.OK): brush = success; break;
case "ACKN": brush = warning; break;
case "AKN": brush = warning; break;
default: brush = error; break;
}
}

View File

@ -24,7 +24,7 @@
case nameof(SIRTConstants.LAT): brush = Brushes.DarkOrange; break;
case nameof(SIRTConstants.DEBUG): brush = Brushes.DarkBlue; break;
case nameof(PAMStatus.OK): brush = Brushes.DarkGreen; break;
case "ACKN": brush = Brushes.DarkOrange; break;
case "AKN": brush = Brushes.DarkOrange; break;
default: brush = Brushes.DarkRed; break;
}
}