eRegister changing the radio address

This commit is contained in:
Stoyan Zlatev 2024-07-16 16:07:17 +02:00
parent 941263d5bd
commit 1ab24c37cd
15 changed files with 445 additions and 411 deletions

View File

@ -40,11 +40,17 @@
public event Action<UInt32[]> PamPoolChanged;
public void AddTask(SIRTTask task)
=> this.tasks
public void Run(SIRTTask task)
{
task.AddressChanged += address => this.tasks
.GetOrAdd(task.Address, new Queue<SIRTTask>())
.Enqueue(task);
this.tasks
.GetOrAdd(task.Address, new Queue<SIRTTask>())
.Enqueue(task);
}
public override void Close()
{
try
@ -91,7 +97,7 @@
manuelResetEventSlim.Set();
};
this.AddTask(activationTask);
this.Run(activationTask);
manuelResetEventSlim.Wait();
manuelResetEventSlim.Reset();
@ -114,7 +120,7 @@
}
};
this.AddTask(identificationTask);
this.Run(identificationTask);
manuelResetEventSlim.Wait();
manuelResetEventSlim.Reset();
@ -230,7 +236,7 @@
awaiter.Set();
};
broadcaster.AddTask(task);
broadcaster.Run(task);
awaiter.Wait(broadcaster.cancellationToken);
awaiter.Reset();
}

View File

@ -7,26 +7,29 @@
public abstract class SIRTTask
{
protected readonly SIRTRequest request;
private readonly UInt32 timeout;
public SIRTTask(SIRTRequest request)
public SIRTTask(SIRTRequest request, UInt32 timeout = 10)
{
this.request = request;
this.timeout = timeout;
this.Type = this.request.message.Cmd;
this.Address = this.request.Address;
}
public event Action<SIRTTask> Done;
public event Action<SIRTTask> Cancelled;
public event Action<UInt32> AddressChanged;
public Byte Type { get; }
public UInt32 Address { get; }
public UInt32 Address { get; protected set; }
public Boolean IsCancelled { get; protected set; }
public Boolean IsDone { get; protected set; }
protected DateTime? Timestamp { get; set; }
public DateTime? Timestamp { get; protected set; }
public Boolean IsRunning { get; internal set; }
@ -100,13 +103,20 @@
this.Done?.Invoke(this);
}
protected void NotifyAddressChanged(UInt32 address)
{
this.Address = address;
this.AddressChanged?.Invoke(address);
}
private void EndAddResponse(Boolean isDone)
{
if (isDone)
{
this.NotifyDone();
}
else if ((DateTime.Now - this.Timestamp.Value).TotalSeconds > 15)
else if ((DateTime.Now - this.Timestamp.Value).TotalSeconds > this.timeout)
{
this.NotifyCancelled();
}

View File

@ -0,0 +1,19 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using Common.Utils.Extensions;
using System;
public class ChangeRadioId : Pam
{
public ChangeRadioId() : base(5, ChangeRadioId)
{
}
public UInt32 Address
{
get => this.bytes.ToUInt32BigEndian(1);
set => value.ToBigEndianBytes().CopyTo(this.bytes, 1);
}
}
}

View File

@ -44,6 +44,7 @@
<Compile Include="ActivationByFlow.cs" />
<Compile Include="AlarmMask.cs" />
<Compile Include="ChangeCustomerText.cs" />
<Compile Include="ChangeRadioId.cs" />
<Compile Include="DecimalPointLocations.cs" />
<Compile Include="EncapsulatedFlexNet.cs" />
<Compile Include="MBusMode.cs" />

View File

@ -0,0 +1,43 @@
namespace Common.Hardware.WaterMeter.eRegister
{
using Common.Hardware.Interfaces.Ports.SIRT.Responses;
using System;
public class ACKN
{
public ACKN(AcknOrAnswerResponse response)
{
this.BufFull = response.BufFull;
this.OsBusy = response.OsBusy;
this.WrongCRC = response.WrongCRC;
this.CmdNotExecuted = response.CmdNotExecuted;
this.CmdUnknown = response.CmdUnknown;
this.NoEntry = response.NoEntry;
this.ByteUnknown = response.ByteUnknown;
this.WildCardAddr = response.WildCardAddr;
this.LastCmd = response.LastCmd;
this.IsValid = response.IsValid;
}
public Boolean BufFull { get; }
public Boolean OsBusy { get; }
public Boolean WrongCRC { get; }
public Boolean CmdNotExecuted { get; }
public Boolean CmdUnknown { get; }
public Boolean NoEntry { get; }
public Boolean ByteUnknown { get; }
public Boolean WildCardAddr { get; }
public String LastCmd { get; }
public Boolean IsValid { get; }
}
}

View File

@ -36,6 +36,9 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\Newtonsoft.Json.13.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -45,14 +48,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ACKN.cs" />
<Compile Include="AppCode.cs" />
<Compile Include="BUP.cs" />
<Compile Include="DEBUG.cs" />
<Compile Include="Epoch20000101.cs" />
<Compile Include="ERegisterEndPoint.cs" />
<Compile Include="ERegisterEndPointsManager.cs" />
<Compile Include="ERegisterEndpointTask.cs" />
<Compile Include="Internal\EndPointManager.cs" />
<Compile Include="EndPoint.cs" />
<Compile Include="LAT.cs" />
<Compile Include="MeterUnits.cs" />
<Compile Include="PAMStatus.cs" />
@ -78,5 +79,8 @@
<Name>Common.Hardware.WaterMeter.eRegister.Features</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,180 +0,0 @@
namespace Common.Hardware.WaterMeter.eRegister
{
using Common.Hardware.WaterMeter.eRegister.Features;
using Common.Hardware.WaterMeter.eRegister.Internal;
using System;
public class ERegisterEndPoint
{
private readonly EndPointManager manager;
private UInt32 address;
internal ERegisterEndPoint(UInt32 address, EndPointManager manager)
{
this.address = address;
this.manager = manager;
}
public UInt32 Address
{
get => this.address;
set
{
this.OldAddress = this.address;
this.address = value;
}
}
public UInt32 OldAddress { get; private set; }
public ERegisterEndpointTask ActivateAlarms(Action<AlarmMask> options)
{
var alarmMask = new SetAlarms();
options(alarmMask);
return this.manager.Send(this.Address, alarmMask);
}
public ERegisterEndpointTask ActivationByFlow(Byte rotationsX10)
=> this.manager.Send(this.Address, new GetDebug
{
Cmd = new ActivationByFlow
{
RotationsX10 = rotationsX10
}
});
public ERegisterEndpointTask ChangeAlarmPersistence(Byte interval)
=> this.manager.Send(this.Address, new AlarmPersistence
{
Interval = interval
});
public ERegisterEndpointTask ChangeBatterySeconds(UInt32 seconds)
=> this.manager.Send(this.Address, new SetBytterySeconds
{
Seconds = seconds
});
public ERegisterEndpointTask ChangeCustomerText(String text)
=> this.manager.Send(this.Address, new ChangeCustomerText
{
Text = text
});
public ERegisterEndpointTask ChangeLATWindowsN(Byte n)
=> this.manager.Send(this.Address, new ChangeLATWindows
{
N = n
});
public ERegisterEndpointTask ChangeMeterType(MeterTypes type)
=> this.manager.Send(this.Address, new GetDebug
{
Cmd = new MeterType
{
Type = type
}
});
public ERegisterEndpointTask ChangeNumberOfDeals(Options n)
=> this.manager.Send(this.Address, new ChangeNumberOfDeals
{
N = n
});
public ERegisterEndpointTask ChangeRebootsCounter(Byte rebootsCount, Byte watchdogCount)
=> this.manager.Send(this.Address, new RebootsCounter
{
Reboot = rebootsCount,
Watchdog = watchdogCount
});
public ERegisterEndpointTask ChangeWakeUp(WakeUpMode mode)
=> this.manager.Send(this.Address, new ChangeWakeUp
{
Mode = mode
});
public ERegisterEndpointTask DeactivateAlarms(Action<AlarmMask> options)
{
var alarmMask = new DeactivateAlarms();
options(alarmMask);
return this.manager.Send(this.Address, alarmMask);
}
public ERegisterEndpointTask GetCustomerDebug()
=> this.manager.Send(this.Address, new CustomerDebug());
public ERegisterEndpointTask ChangeWMBusTransmitionInterval(UInt16 interval)
=> this.manager.Send(this.Address, new WMBusTransmition
{
Interval = interval
});
public ERegisterEndpointTask Reset(ResetMode mode)
=> this.manager.Send(this.Address, new Reset
{
Mode = mode
});
public ERegisterEndpointTask SetOpticalTelegram(Byte minutes)
=> this.manager.Send(this.Address, new GetDebug
{
Cmd = new OpticalTelegram
{
Minutes = minutes
}
});
public ERegisterEndpointTask SetMetrologyParameters(Action<SetMetrologyParameters> options)
{
var parameters = new SetMetrologyParameters();
options(parameters);
return this.manager.Send(this.Address, parameters);
}
public ERegisterEndpointTask SetPCB(UInt32 pcb)
=> this.manager.Send(this.Address, new SetPCB
{
ID = pcb
});
public ERegisterEndpointTask SetPowerLevel(PowerLevelModes mode, Byte powerLevel)
=> this.manager.Send(this.Address, new SetPowerLevel
{
Mode = mode,
PowerLevel = powerLevel
});
public ERegisterEndpointTask SetTFXParameters(Action<SetTFXParameters> options)
{
var parameters = new SetTFXParameters();
options(parameters);
return this.manager.Send(this.Address, parameters);
}
public ERegisterEndpointTask SetWMBusMode(Action<WMBusMode> options)
{
var parameters = new WMBusMode();
options(parameters);
return this.manager.Send(this.Address, parameters);
}
public ERegisterEndpointTask SetWMBusTRansmitionInterval(UInt16 interval)
=> this.manager.Send(this.Address, new WMBusTransmition
{
Interval = interval
});
}
}

View File

@ -1,63 +0,0 @@
namespace Common.Hardware.WaterMeter.eRegister
{
using Common.Hardware.WaterMeter.eRegister.Internal;
using System;
public class ERegisterEndPointsManager : EndPointManager
{
public ERegisterEndPointsManager(String portName, Int32 timeout = 3000) : base(portName, timeout)
{
this.broadcaster.DeviceAvailable += this.Broadcaster_DeviceAvailable;
this.broadcaster.DeviceUnavailable += this.Broadcaster_DeviceUnavailable;
this.broadcaster.Logging += this.Broadcaster_Logging;
this.broadcaster.PamPoolChanged += this.Broadcaster_PamPoolChanged;
}
public UInt16 Frequency => this.broadcaster.Frequency;
public String SIRTID => this.broadcaster.SIRTID;
public ERegisterEndPoint Add(UInt32 address)
{
var ep = new ERegisterEndPoint(address, this);
return this.Add(ep);
}
public ERegisterEndPoint Add(ERegisterEndPoint ep)
=> this.endPoints.AddOrUpdate(ep.Address, ep, (k, v) => ep);
public ERegisterEndPoint Remove(UInt32 address)
{
_ = this.endPoints.TryRemove(address, out var ep);
return ep;
}
private void Broadcaster_DeviceAvailable(UInt32 address)
{
// TODO: throw new NotImplementedException();
}
private void Broadcaster_DeviceUnavailable(UInt32 address)
{
// TODO: throw new NotImplementedException();
}
private void Broadcaster_Exception(String text)
{
// TODO: throw new NotImplementedException();
}
private void Broadcaster_Logging(String text)
{
// TODO: throw new NotImplementedException();
}
private void Broadcaster_PamPoolChanged(UInt32[] addresses)
{
// TODO: throw new NotImplementedException();
}
}
}

View File

@ -1,12 +0,0 @@
namespace Common.Hardware.WaterMeter.eRegister
{
using Common.Hardware.Interfaces.Ports.SIRT;
using Common.Hardware.Interfaces.Ports.SIRT.Requests;
public class ERegisterEndpointTask : SIRTTask
{
public ERegisterEndpointTask(SIRTRequest request) : base(request)
{
}
}
}

View File

@ -0,0 +1,208 @@
//namespace Common.Hardware.WaterMeter.eRegister
//{
// using Common.Hardware.Interfaces.Ports.SIRT.Requests;
// using Common.Hardware.WaterMeter.eRegister.Features;
// using System;
// using System.Threading;
// public class EndPoint
// {
// private UInt32 address;
// internal EndPoint(UInt32 address)
// {
// this.address = address;
// }
// public UInt32 Address
// {
// get => this.address;
// set
// {
// this.OldAddress = this.address;
// this.address = value;
// }
// }
// public UInt32 OldAddress { get; private set; }
// public ERegisterEndpointTask ActivateAlarms(Action<AlarmMask> options)
// {
// var alarmMask = new SetAlarms();
// options(alarmMask);
// return this.manager.Run(this.Address, alarmMask);
// }
// public ERegisterEndpointTask ActivationByFlow(Byte rotationsX10)
// => this.manager.Run(this.Address, new GetDebug
// {
// Cmd = new ActivationByFlow
// {
// RotationsX10 = rotationsX10
// }
// });
// public ERegisterEndpointTask ChangeAlarmPersistence(Byte interval)
// => this.manager.Run(this.Address, new AlarmPersistence
// {
// Interval = interval
// });
// public ERegisterEndpointTask ChangeBatterySeconds(UInt32 seconds)
// => this.manager.Run(this.Address, new SetBytterySeconds
// {
// Seconds = seconds
// });
// public ERegisterEndpointTask ChangeCustomerText(String text)
// => this.manager.Run(this.Address, new ChangeCustomerText
// {
// Text = text
// });
// public ERegisterEndpointTask ChangeLATWindowsN(Byte n)
// => this.manager.Run(this.Address, new ChangeLATWindows
// {
// N = n
// });
// public ERegisterEndpointTask ChangeMeterType(MeterTypes type)
// => this.manager.Run(this.Address, new GetDebug
// {
// Cmd = new MeterType
// {
// Type = type
// }
// });
// public ERegisterEndpointTask ChangeNumberOfDeals(Options n)
// => this.manager.Run(this.Address, new ChangeNumberOfDeals
// {
// N = n
// });
// public ERegisterEndpointTask ChangeRadioId(UInt32 address, UInt32 newAddress)
// {
// var task = new ERegisterChageAddressTask(new WritePamRequest
// {
// Address = address,
// DelPamSemi = true,
// Payload = new ChangeRadioId
// {
// Address = newAddress
// }
// });
// var awaiter = new ManualResetEventSlim();
// ERegisterEndpointTask _task = task;
// task.AddressChanged += _address =>
// {
// this.Address = _address;
// _task = this.SetOpticalTelegram(1);
// awaiter.Set();
// };
// this.manager.Run(task);
// awaiter.Wait(60000);
// return _task;
// }
// public ERegisterEndpointTask ChangeRebootsCounter(Byte rebootsCount, Byte watchdogCount)
// => this.manager.Run(this.Address, new RebootsCounter
// {
// Reboot = rebootsCount,
// Watchdog = watchdogCount
// });
// public ERegisterEndpointTask ChangeWakeUp(WakeUpMode mode)
// => this.manager.Run(this.Address, new ChangeWakeUp
// {
// Mode = mode
// });
// public ERegisterEndpointTask DeactivateAlarms(Action<AlarmMask> options)
// {
// var alarmMask = new DeactivateAlarms();
// options(alarmMask);
// return this.manager.Run(this.Address, alarmMask);
// }
// public ERegisterEndpointTask GetCustomerDebug()
// => this.manager.Run(this.Address, new CustomerDebug());
// public ERegisterEndpointTask ChangeWMBusTransmitionInterval(UInt16 interval)
// => this.manager.Run(this.Address, new WMBusTransmition
// {
// Interval = interval
// });
// public ERegisterEndpointTask Reset(ResetMode mode)
// => this.manager.Run(this.Address, new Reset
// {
// Mode = mode
// });
// public ERegisterEndpointTask SetOpticalTelegram(Byte minutes)
// => this.manager.Run(this.Address, new GetDebug
// {
// Cmd = new OpticalTelegram
// {
// Minutes = minutes
// }
// });
// public ERegisterEndpointTask SetMetrologyParameters(Action<SetMetrologyParameters> options)
// {
// var parameters = new SetMetrologyParameters();
// options(parameters);
// return this.manager.Run(this.Address, parameters);
// }
// public ERegisterEndpointTask SetPCB(UInt32 pcb)
// => this.manager.Run(this.Address, new SetPCB
// {
// ID = pcb
// });
// public ERegisterEndpointTask SetPowerLevel(PowerLevelModes mode, Byte powerLevel)
// => this.manager.Run(this.Address, new SetPowerLevel
// {
// Mode = mode,
// PowerLevel = powerLevel
// });
// public ERegisterEndpointTask SetTFXParameters(Action<SetTFXParameters> options)
// {
// var parameters = new SetTFXParameters();
// options(parameters);
// return this.manager.Run(this.Address, parameters);
// }
// public ERegisterEndpointTask SetWMBusMode(Action<WMBusMode> options)
// {
// var parameters = new WMBusMode();
// options(parameters);
// return this.manager.Run(this.Address, parameters);
// }
// public ERegisterEndpointTask SetWMBusTRansmitionInterval(UInt16 interval)
// => this.manager.Run(this.Address, new WMBusTransmition
// {
// Interval = interval
// });
// }
//}

View File

@ -1,59 +0,0 @@
namespace Common.Hardware.WaterMeter.eRegister.Internal
{
using Common.Hardware.Interfaces.Ports;
using Common.Hardware.Interfaces.Ports.SIRT;
using Common.Hardware.Interfaces.Ports.SIRT.Requests;
using Common.Hardware.WaterMeter.eRegister.Features;
using System;
using System.Collections.Concurrent;
public abstract class EndPointManager
{
protected readonly SIRTBroadcaster broadcaster;
protected readonly ConcurrentDictionary<UInt32, ERegisterEndPoint> endPoints;
protected EndPointManager(String portName, Int32 timeout = 3000)
{
var settings = new SerialPortSettings
{
BaudRate = SerialPortBaudRate.X115200,
DataBits = SerialPortDataBits.X8,
Parity = SerialPortParity.None,
PortName = portName,
StopBits = SerialPortStopBits.One,
RWTimeout = timeout
};
this.broadcaster = new SIRTBroadcaster(settings);
this.endPoints = new ConcurrentDictionary<UInt32, ERegisterEndPoint>();
}
internal ERegisterEndpointTask Send(UInt32 address, Pam payload)
{
var request = new WritePamRequest
{
Address = address,
Payload = payload,
DelPamSemi = true
};
var task = new ERegisterEndpointTask(request);
this.broadcaster.AddTask(task);
return task;
}
public Boolean IsRunning => this.broadcaster.IsOpen && this.broadcaster.Activated;
internal Boolean EnsureConnected()
{
if (!this.IsRunning)
{
this.broadcaster.Close();
this.broadcaster.Open();
}
return this.IsRunning;
}
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net40" />
</packages>

View File

@ -61,6 +61,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Models\WritePamTask.cs" />
<Compile Include="Utilities\Appsettings.cs" />
<Compile Include="Utilities\CompilerServices.cs" />
<Compile Include="ViewModels\SIRTBroadcasterViewModel.cs" />

View File

@ -3,11 +3,6 @@
using Common.Hardware.Interfaces.Ports;
using Common.Hardware.Interfaces.Ports.SIRT;
using Common.Hardware.Interfaces.Ports.SIRT.Requests;
using Common.Hardware.Interfaces.Ports.SIRT.Responses;
using Common.Hardware.WaterMeter.eRegister;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using NLog;
using NLog.Config;
@ -16,7 +11,7 @@
using System;
using System.Threading;
public class SIRTBroadcasterModel
public partial class SIRTBroadcasterModel
{
private readonly SIRTBroadcaster broadcaster;
private readonly ILogger logger;
@ -71,30 +66,66 @@
var awaiter = new ManualResetEventSlim();
var request = new WritePamRequest
{
Address = 319020415,
Address = 319020416,
DelPamSemi = true,
Payload = new Byte[]
{
// 0x1F, 0x01, 0x08,
0x36, 0x13, 0x03, 0xDD, 0x7F,
0x50, 0x53, 0x65, 0x6E, 0x73, 0x75, 0x73, 0x4C, 0x61, 0x61,
0x00, 0x00, // wake up
0x10, 0x00, 0x00, // tx
0x02, 0x00, // lat
0x05, 0x00, // mbus
0x30, 0x06, 0x9F, 0x6B, 0xC7, // reading - 111111111
0x43, 0x03, 0x63, 0x93, 0x73, 0x22 // pin 3
0x35, 0x13, 0x03, 0xDD, 0x7F,
//0x1F, 0x01, 0x08,
//0x36, 0x13, 0x03, 0xDD, 0x7F,
//0x50, 0x53, 0x65, 0x6E, 0x73, 0x75, 0x73, 0x4C, 0x61, 0x61,
//0x00, 0x00, // wake up
//0x10, 0x00, 0x00, // tx
//0x02, 0x00, // lat
//0x05, 0x00, // mbus
//0x30, 0x06, 0x9F, 0x6B, 0xC7, // reading - 111111111
0x43, 0x03, 0x63, 0x93, 0x73, 0x22 // pin 3
}
};
var task = new WritePamTask(request);
task.Done += _ => awaiter.Set();
task.Cancelled += _ => awaiter.Set();
task.Logging += content => this.ProgrammingDone?.Invoke(task.Address, content);
task.Logging += content =>
{
this.ProgrammingDone?.Invoke(task.Address, content);
};
this.broadcaster.AddTask(task);
this.broadcaster.Run(task);
this.ProgrammingDone?.Invoke(task.Address, BitConverter.ToString(request));
awaiter.Wait();
awaiter.Reset();
request = new WritePamRequest
{
Address = task.Address,
DelPamSemi = true,
Payload = new Byte[]
{
0x1F, 0x01, 0x08,
//0x35, 0x13, 0x03, 0xDD, 0x80,
//0x36, 0x13, 0x03, 0xDD, 0x7F,
//0x50, 0x53, 0x65, 0x6E, 0x73, 0x75, 0x73, 0x4C, 0x61, 0x61,
//0x00, 0x00, // wake up
//0x10, 0x00, 0x00, // tx
//0x02, 0x00, // lat
//0x05, 0x00, // mbus
//0x30, 0x06, 0x9F, 0x6B, 0xC7, // reading - 111111111
0x43, 0x03, 0x63, 0x93, 0x73, 0x22 // pin 3
}
};
task = new WritePamTask(request);
task.Done += _ => awaiter.Set();
task.Cancelled += _ => awaiter.Set();
task.Logging += content =>
{
this.ProgrammingDone?.Invoke(task.Address, content);
// awaiter.Set();
};
this.broadcaster.Run(task);
awaiter.Wait();
}
@ -119,70 +150,5 @@
return LogManager.GetLogger(name);
}
public class WritePamTask : SIRTTask
{
public WritePamTask(SIRTRequest request) : base(request)
{
}
public event Action<String> Logging;
protected override Boolean FromAirReceived(FromAirResponse response)
{
var payload = response.Payload;
var length = response.Payload.Length;
var content = default(String);
var settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
};
settings.Converters.Add(new StringEnumConverter());
if (length == 13)
{
content = JsonConvert.SerializeObject(new BUP(payload), settings);
}
else if (length == 52)
{
content = JsonConvert.SerializeObject(new DEBUG(payload), settings);
}
else if (length == 91)
{
content = JsonConvert.SerializeObject(new SEMI(payload, response.MHz), settings);
}
else
{
content = BitConverter.ToString(payload);
}
this.Logging?.Invoke(content);
if (response.Payload[0] == SIRTConstants.Semi)
{
return true;
}
else
{
return false;
}
}
protected override Boolean AcknOrAnswerReceived(AcknOrAnswerResponse response)
{
var settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
};
settings.Converters.Add(new StringEnumConverter());
var content = JsonConvert.SerializeObject(response, settings);
this.Logging?.Invoke(content);
return base.AcknOrAnswerReceived(response);
}
}
}
}

View File

@ -0,0 +1,86 @@
namespace Common.UI.SIRTBroadcaster.Models
{
using Common.Hardware.Interfaces.Ports.SIRT;
using Common.Hardware.Interfaces.Ports.SIRT.Responses;
using Common.Hardware.WaterMeter.eRegister;
using Common.Utils.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
public class WritePamTask : SIRTTask
{
public WritePamTask(SIRTRequest request) : base(request)
{
this.Bups = new List<BUP>();
}
public event Action<String> Logging;
public SIRTRequest Request => this.request;
public ACKN ACKN { get; private set; }
public LAT LAT { get; private set; }
public DEBUG DEBUG { get; private set; }
public SEMI SEMI { get; private set; }
public ICollection<BUP> Bups { get; }
protected override Boolean FromAirReceived(FromAirResponse response)
{
var payload = response.Payload;
var length = response.Payload.Length;
if (length == 13)
{
var bup = new LAT(payload);
if (bup.AppCode == AppCode.LAT)
{
this.LAT = bup;
if (this.request.Payload[0] == 0x35)
{
this.Address = this.request.Payload.ToUInt32BigEndian(1);
this.NotifyAddressChanged(this.Address);
}
}
else
{
this.Bups.Add(bup);
}
}
else if (length == 52)
{
this.DEBUG = new DEBUG(payload);
}
else if (length == 91)
{
this.SEMI = new SEMI(payload, response.MHz);
}
else
{
// TODO:
}
this.Logging.Invoke(JsonConvert.SerializeObject(this, Formatting.Indented));
return this.SEMI != null;
}
protected override Boolean AcknOrAnswerReceived(AcknOrAnswerResponse response)
{
this.ACKN = new ACKN(response);
this.Logging.Invoke(JsonConvert.SerializeObject(this, Formatting.Indented));
return base.AcknOrAnswerReceived(response);
}
}
}