321 lines
12 KiB
C#
321 lines
12 KiB
C#
namespace Common.Hardware.WaterMeter.eRegister
|
|
{
|
|
using Common.Hardware.Interfaces.Ports.SIRT;
|
|
using Common.Hardware.Interfaces.Ports.SIRT.Parameters;
|
|
using Common.Hardware.WaterMeter.eRegister.Features;
|
|
using Common.Utils.Extensions;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
|
|
public class ParameterSet
|
|
{
|
|
public Int32 SharedId { get; set; }
|
|
|
|
public Int32 Psno { get; set; }
|
|
|
|
public Int32 Slotno { get; set; }
|
|
|
|
public Int32 Serialno { get; set; }
|
|
|
|
public Boolean IsSealed { get; set; }
|
|
|
|
public Byte[] EncryptionKey { get; private set; }
|
|
|
|
public UInt32 RadioAddress { get; set; }
|
|
|
|
public UInt32 FinalAddress { get; set; }
|
|
|
|
public Byte MeterMode { get; private set; }
|
|
|
|
public Byte PowerModeSensusRF { get; private set; }
|
|
|
|
public Byte PowerModeFlexNet { get; private set; }
|
|
|
|
public Byte[] Parameters { get; set; }
|
|
|
|
public Int32 VolumePerPulse { get; private set; }
|
|
|
|
public Int32 OffsetFactor { get; private set; }
|
|
|
|
public Byte OffsetTime { get; private set; }
|
|
|
|
public Byte FactoryCalibration { get; private set; }
|
|
|
|
public Byte CandIRules { get; private set; }
|
|
|
|
public Byte MeterSize { get; private set; }
|
|
|
|
public Int32 VolumePerLedPulse { get; private set; }
|
|
|
|
public UInt32 DisplayVolume { get; private set; }
|
|
|
|
public UInt32 MeterId { get; private set; }
|
|
|
|
public Byte AlarmsMask { get; private set; }
|
|
|
|
public String CustomerText { get; private set; }
|
|
|
|
public Byte DecimalPoint { get; private set; }
|
|
|
|
public Int32 StandardVolume { get; private set; }
|
|
|
|
public Byte LeakageDetection { get; private set; }
|
|
|
|
public Byte BrokenPipeDetection { get; private set; }
|
|
|
|
public Byte HistoricalErrorLimit { get; private set; }
|
|
|
|
public UInt16 DataLoggerTimeInterval { get; private set; }
|
|
|
|
public Byte DataLoggerMinFlowTime { get; private set; }
|
|
|
|
public Byte DataLoggerMinFlow { get; private set; }
|
|
|
|
public Byte FixedDateReadingDay { get; private set; }
|
|
|
|
public Byte FixedDateReadingSettingI { get; private set; }
|
|
|
|
public Byte FixedDateReadingSettingII { get; private set; }
|
|
|
|
public Byte MBusStatus { get; private set; }
|
|
|
|
public Int32 UTCSeconds { get; private set; }
|
|
|
|
public Int16 TransmissionInterval { get; private set; }
|
|
|
|
public Byte NumberOfLatWindows { get; private set; }
|
|
|
|
public Int32 RadioKeyType { get; private set; }
|
|
|
|
public Byte OTASettings { get; private set; }
|
|
|
|
public Byte ActivationByFlow { get; private set; }
|
|
|
|
public UInt16 OpenMeteringTransmissionInterval { get; private set; }
|
|
|
|
public Byte TransmissionIntervalLast { get; private set; }
|
|
|
|
public Int16 WUP { get; private set; }
|
|
|
|
internal ProgrammingTask BuildWupTxLatMBusTask()
|
|
=> new ProgrammingTask
|
|
{
|
|
Cmd = SirtMessage.W_PAM,
|
|
P1 = new P811
|
|
{
|
|
DelPamSemi = true,
|
|
WakeUpCmd = true
|
|
},
|
|
Address = this.RadioAddress,
|
|
Data = new Byte[] // Multipam commands
|
|
{
|
|
0x00, 0x00, // WUP stay awake
|
|
0x02, 0x00, // LAT window interval
|
|
0x05, 0x07, // MBus status
|
|
0x10, 0x00, 0x03, // TX interval
|
|
0x43, 0x02, 0x14, 0x0E, 0x80, 0x40, // Pin level II
|
|
},
|
|
EncryptionKey = this.IsSealed ? this.EncryptionKey : null
|
|
};
|
|
|
|
internal ProgrammingTask BuildTestParametersTask()
|
|
=> new ProgrammingTask
|
|
{
|
|
Cmd = SirtMessage.W_PAM,
|
|
P1 = new P811
|
|
{
|
|
DelPamSemi = true
|
|
},
|
|
Address = this.RadioAddress,
|
|
Data = new SetMetrologyParameters
|
|
{
|
|
Vpp = this.VolumePerPulse,
|
|
OffsetFactor = this.OffsetFactor,
|
|
OffsetTime = this.OffsetTime,
|
|
FactoryCalibration = this.FactoryCalibration,
|
|
CandIRules = this.CandIRules,
|
|
MeterSize = this.MeterSize,
|
|
VppLED = (UInt32)this.VolumePerLedPulse,
|
|
}
|
|
.Append(new ProvidePin
|
|
{
|
|
AuthLevel = AuthLevel.III
|
|
}),
|
|
EncryptionKey = this.IsSealed ? this.EncryptionKey : null
|
|
};
|
|
|
|
internal ProgrammingTask BuildSetupDisplayTask()
|
|
=> new ProgrammingTask
|
|
{
|
|
Cmd = SirtMessage.W_PAM,
|
|
P1 = new P811
|
|
{
|
|
DelPamSemi = true
|
|
},
|
|
Address = this.RadioAddress,
|
|
Data = new Byte[]
|
|
{
|
|
0x30, 0x06, 0x9F, 0x6B, 0xC7, // Display: 111111111
|
|
0x43, 0x03, 0x63, 0x93, 0x73, 0x22 // Pin level III
|
|
},
|
|
EncryptionKey = this.IsSealed ? this.EncryptionKey : null
|
|
};
|
|
|
|
internal ProgrammingTask BuildOptoOnTask()
|
|
=> new ProgrammingTask
|
|
{
|
|
Cmd = SirtMessage.W_PAM,
|
|
P1 = new P811
|
|
{
|
|
DelPamSemi = true
|
|
},
|
|
Address = this.RadioAddress,
|
|
Data = new OpticalTelegram
|
|
{
|
|
Minutes = 1 // TODO: Get opto value
|
|
}.Append(new ProvidePin
|
|
{
|
|
AuthLevel = Features.AuthLevel.III
|
|
}),
|
|
EncryptionKey = this.IsSealed ? this.EncryptionKey : null
|
|
};
|
|
|
|
public void ParseParameters()
|
|
{
|
|
var length = this.Parameters?.Length ?? 0;
|
|
|
|
if (length <= 0)
|
|
{
|
|
return;
|
|
}
|
|
else if (length == 20)
|
|
{
|
|
// 0 1 2 3 - 6 7 - 10 11 12 13 14 15 - 18 19
|
|
// LL Pm SM VolPerPu OffFactr ot FC 11 MS VpLEDPul RK
|
|
// 12 92 10 82710000 00000000 05 00 00 28 02710000 01
|
|
|
|
this.VolumePerPulse = this.Parameters.ToInt32BE(3);
|
|
this.OffsetFactor = this.Parameters.ToInt32BE(7);
|
|
this.OffsetTime = this.Parameters[11];
|
|
this.FactoryCalibration = this.Parameters[12];
|
|
this.CandIRules = this.Parameters[13];
|
|
this.MeterSize = this.Parameters[14];
|
|
this.VolumePerLedPulse = this.Parameters.ToInt32BE(15);
|
|
this.RadioKeyType = this.Parameters[19];
|
|
|
|
}
|
|
else if (length == 55)
|
|
{
|
|
this.DisplayVolume = this.Parameters.ToUInt32BE(0);
|
|
this.MeterId = this.Parameters.ToUInt32BE(4);
|
|
this.AlarmsMask = this.Parameters[8];
|
|
this.CustomerText = Encoding.ASCII.GetString(this.Parameters, 9, 9);
|
|
this.DecimalPoint = this.Parameters[18];
|
|
this.StandardVolume = this.Parameters.ToInt32BE(19);
|
|
this.LeakageDetection = this.Parameters[23];
|
|
this.BrokenPipeDetection = this.Parameters[24];
|
|
this.HistoricalErrorLimit = this.Parameters[25];
|
|
this.DataLoggerTimeInterval = this.Parameters.ToUInt16BE(26);
|
|
this.DataLoggerMinFlowTime = this.Parameters[28];
|
|
this.DataLoggerMinFlow = this.Parameters[29];
|
|
this.FixedDateReadingDay = this.Parameters[30];
|
|
this.FixedDateReadingSettingI = this.Parameters[31];
|
|
this.FixedDateReadingSettingII = this.Parameters[32];
|
|
this.MBusStatus = this.Parameters[33];
|
|
this.UTCSeconds = this.Parameters.ToInt32BE(34);
|
|
this.TransmissionInterval = this.Parameters.ToInt16BE(38);
|
|
this.NumberOfLatWindows = this.Parameters[40];
|
|
this.RadioKeyType = this.Parameters[41];
|
|
this.FinalAddress = this.Parameters.ToUInt32BE(42);
|
|
this.MeterMode = this.Parameters[46];
|
|
this.PowerModeSensusRF = this.Parameters[47];
|
|
this.PowerModeFlexNet = this.Parameters[48];
|
|
this.OTASettings = this.Parameters[49];
|
|
this.ActivationByFlow = this.Parameters[50];
|
|
this.OpenMeteringTransmissionInterval = this.Parameters.ToUInt16BE(51);
|
|
this.TransmissionIntervalLast = this.Parameters[53];
|
|
this.WUP = this.Parameters.ToInt16BE(54);
|
|
}
|
|
|
|
var uri = $"http://sla12iis01.emea.sensus.net/LaaProductionWeb/api/eregister/radiokey?serialno={this.Serialno}&radioKeyType={this.RadioKeyType}";
|
|
|
|
using (var request = new HttpRequestMessage(HttpMethod.Get, uri))
|
|
{
|
|
using (var response = new HttpClient().SendAsync(request).Result)
|
|
{
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var radioKey = response?.Content?.ReadAsStringAsync()?.Result;
|
|
|
|
if (!String.IsNullOrWhiteSpace(radioKey))
|
|
{
|
|
this.EncryptionKey = radioKey.ToByteArray();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerable<ProgrammingTask> BuildFinalProgrammingTasks()
|
|
{
|
|
var tasks = new EregisterFeatures
|
|
{
|
|
ChangeWakeUp = new ChangeWakeUp(WakeUpMode.StayAwake),
|
|
ChangeMeterReading = new ChangeMeterReading(this.DisplayVolume),
|
|
ChangeCustomerText = new ChangeCustomerText(this.Serialno),
|
|
DeactivateAlarms = new DeactivateAlarms(this.AlarmsMask),
|
|
ResetAlarms = new ResetAlarms(Byte.MaxValue),
|
|
ParameterizeLeakageDetection = new ParameterizeLeakageDetection(this.LeakageDetection),
|
|
ParameterizeBrokenPipeDetection = new ParameterizeBrokenPipeDetection(this.BrokenPipeDetection),
|
|
SetHistoricalErrorLimit = new SetHistoricalErrorLimit(this.HistoricalErrorLimit),
|
|
ChangeDataLoggerSettings = new ChangeDataLoggerSettings
|
|
{
|
|
TimeInterval = this.DataLoggerTimeInterval,
|
|
TimeOfMinimumFlow = this.DataLoggerMinFlowTime,
|
|
MinimumFlow = this.DataLoggerMinFlow
|
|
},
|
|
ChangeFixedDateReadingSettings = new ChangeFixedDateReadingSettings
|
|
{
|
|
DayOfMonth = this.FixedDateReadingDay,
|
|
SettingI = this.FixedDateReadingSettingI,
|
|
SettingII = this.FixedDateReadingSettingII
|
|
},
|
|
WirelessMBusMode = new WirelessMBusMode(this.MBusStatus),
|
|
SetPowerLevelSensusRF = new SetPowerLevel(this.PowerModeSensusRF),
|
|
SetPowerLevelFlexNet = new SetPowerLevel(this.PowerModeFlexNet),
|
|
ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows(this.NumberOfLatWindows),
|
|
ChangeTransmissionInterval = new ChangeTransmissionInterval(this.TransmissionIntervalLast),
|
|
OpenMeteringTransmitionIntervalWMBus = new OpenMeteringTransmitionIntervalWMBus(this.OpenMeteringTransmissionInterval),
|
|
Debug = new EregisterFeaturesDebug
|
|
{
|
|
DisableOTAFirmwareUpdate = new DisableOTAFirmwareUpdate(this.OTASettings),
|
|
SetActivationByThreshold = new SetActivationByThreshold(this.OTASettings),
|
|
}
|
|
}
|
|
.BuildPams()
|
|
.BuildTasks(options =>
|
|
{
|
|
options.Address = this.RadioAddress;
|
|
options.Cmd = SirtMessage.W_PAM;
|
|
options.P1 = new P811
|
|
{
|
|
DelPamSemi = true
|
|
};
|
|
});
|
|
|
|
foreach (var task in tasks)
|
|
{
|
|
yield return task;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//// TODO:
|
|
//// Pin level 2
|
|
//.Append(new ChangeSensusRFEncryptionKey(this.EncryptionKey))
|
|
//// Pin level 3
|
|
//.Append(new ChangeRadioId(this.FinalAddress)) |