86 lines
1.9 KiB
C#
86 lines
1.9 KiB
C#
namespace Common.Hardware.Interfaces.Protocols.SIRT
|
|
{
|
|
using Common.Hardware.Interfaces.Ports.SIRT.Messages;
|
|
using Common.Hardware.Interfaces.Protocols.SIRT.Payloads;
|
|
|
|
using System;
|
|
|
|
public class SirtTask
|
|
{
|
|
private static UInt64 taskNr;
|
|
|
|
private readonly SirtMessage request;
|
|
|
|
public SirtTask(SirtMessage request)
|
|
{
|
|
this.request = request;
|
|
this.Nr = ++taskNr;
|
|
}
|
|
|
|
public event Action<SirtTask> Done;
|
|
|
|
public UInt64 Nr { get; }
|
|
|
|
public UInt32 Address => this.request.Address;
|
|
|
|
public Boolean IsRunning { get; private set; }
|
|
|
|
public override Boolean Equals(object other)
|
|
=> other is SirtTask task
|
|
&& task.Address == this.Address;
|
|
|
|
public override Int32 GetHashCode()
|
|
=> (Int32)this.Address;
|
|
|
|
public override String ToString()
|
|
=> this.Address.ToString();
|
|
|
|
internal void Add(Bup bup)
|
|
{
|
|
Console.WriteLine(bup);
|
|
}
|
|
|
|
internal void Add(Lat lat)
|
|
{
|
|
Console.WriteLine(lat);
|
|
}
|
|
|
|
internal void Add(Semi semi)
|
|
{
|
|
this.IsRunning = false;
|
|
|
|
this.Done?.Invoke(this);
|
|
|
|
Console.WriteLine(semi);
|
|
}
|
|
|
|
internal void Add(Debug debug)
|
|
{
|
|
Console.WriteLine(debug);
|
|
}
|
|
|
|
internal void Add(Ack ack)
|
|
{
|
|
Console.WriteLine(ack);
|
|
}
|
|
|
|
internal void Add(Answer answer)
|
|
{
|
|
this.IsRunning = false;
|
|
|
|
this.Done?.Invoke(this);
|
|
|
|
Console.WriteLine(answer);
|
|
}
|
|
|
|
public static implicit operator SirtMessage(SirtTask task)
|
|
{
|
|
task.IsRunning = true;
|
|
|
|
return task.request;
|
|
}
|
|
|
|
public static implicit operator UInt32(SirtTask task)
|
|
=> task.Address;
|
|
}
|
|
} |