126 lines
3.6 KiB
C#
126 lines
3.6 KiB
C#
namespace Common.Hardware.WaterMeter.eRegister.Features
|
|
{
|
|
using Common.Utils.Extensions;
|
|
|
|
using System;
|
|
|
|
public class SetMetrologyParameters : Pam
|
|
{
|
|
private Byte[] bitsFromByte11;
|
|
|
|
public SetMetrologyParameters() : base(18, MetrologyParameters)
|
|
=> this.bitsFromByte11 = new Byte[8];
|
|
|
|
public Byte PamLength => this.bytes[1];
|
|
|
|
public Int32 Vpp
|
|
{
|
|
get => this.bytes.ToInt32BigEndian(2);
|
|
set => value.ToBigEndianBytes().CopyTo(this.bytes, 2);
|
|
}
|
|
|
|
public Int32 OffsetFactor
|
|
{
|
|
get => this.bytes.ToInt32BigEndian(6);
|
|
set => value.ToBigEndianBytes().CopyTo(this.bytes, 6);
|
|
}
|
|
|
|
public Byte OffsetTime
|
|
{
|
|
get => this.bytes[10];
|
|
set => this.bytes[10] = value;
|
|
}
|
|
|
|
public Byte FactoryCalibration
|
|
{
|
|
get => this.bytes[11];
|
|
set => this.bytes[11] = value;
|
|
}
|
|
|
|
public MeterUnits Units
|
|
{
|
|
get
|
|
{
|
|
var value = 0;
|
|
|
|
value ^= this.bitsFromByte11[4];
|
|
value ^= this.bitsFromByte11[3] << 1;
|
|
value ^= this.bitsFromByte11[2] << 2;
|
|
value ^= this.bitsFromByte11[1] << 3;
|
|
value ^= this.bitsFromByte11[0] << 4;
|
|
|
|
return (MeterUnits)value;
|
|
}
|
|
set
|
|
{
|
|
var units = (Byte)value;
|
|
|
|
this.bitsFromByte11[4] = (Byte)(units >> 0 & 1);
|
|
this.bitsFromByte11[3] = (Byte)(units >> 1 & 1);
|
|
this.bitsFromByte11[2] = (Byte)(units >> 2 & 1);
|
|
this.bitsFromByte11[1] = (Byte)(units >> 3 & 1);
|
|
this.bitsFromByte11[0] = (Byte)(units >> 4 & 1);
|
|
}
|
|
}
|
|
|
|
public DecimalPointLocations DecimalPoint
|
|
{
|
|
get
|
|
{
|
|
var result = 0;
|
|
|
|
result ^= bytes[5] << 0;
|
|
result ^= bytes[6] << 1;
|
|
|
|
return (DecimalPointLocations)result;
|
|
}
|
|
set
|
|
{
|
|
var x = (Byte)value;
|
|
|
|
this.bitsFromByte11[6] = (Byte)(x >> 0 & 1);
|
|
this.bitsFromByte11[5] = (Byte)(x >> 1 & 1);
|
|
}
|
|
}
|
|
|
|
public Byte CandIRules
|
|
{
|
|
get => this.bitsFromByte11[7];
|
|
set => this.bitsFromByte11[7] = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// This controls whether the volume can accumulate in the reverse direction. If this bit is set
|
|
/// the device will only count forward.For example, if the display starts at 0 and 50 liters of
|
|
/// water flow in the forward direction, then 20 liters in the reverse direction the display will
|
|
/// show 50 liters.If 10 liters then flows in the forward direction the display will show 60 liters.
|
|
/// (i.e. 50 - 20 + 10 = 60.)
|
|
/// </summary>
|
|
public Boolean UseCandIRules
|
|
{
|
|
get => this.CandIRules == 1;
|
|
set => this.CandIRules = (Byte)(value ? 1 : 0);
|
|
}
|
|
|
|
public Byte MeterSize
|
|
{
|
|
get => this.bytes[13];
|
|
set => this.bytes[13] = value;
|
|
}
|
|
|
|
public UInt32 VppLED
|
|
{
|
|
get => this.bytes.ToUInt32BigEndian(14);
|
|
set => value.ToBigEndianBytes().CopyTo(this.bytes, 14);
|
|
}
|
|
|
|
public override Byte[] ToByteArray()
|
|
{
|
|
this.bytes[12] = this.bitsFromByte11.ToByte();
|
|
this.bytes[1] = 0x10;
|
|
|
|
return base.ToByteArray();
|
|
}
|
|
}
|
|
}
|