merge
This commit is contained in:
@@ -24,7 +24,7 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
|
||||
|
||||
public abstract List<Byte> DecodeDataForLogicLayer(List<Byte> rawData);
|
||||
|
||||
public abstract List<byte> DecodeDataForPhysicalLayerUI1236(byte[] payload);
|
||||
public abstract List<Byte> DecodeDataForPhysicalLayerUI1236(Byte[] payload);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
|
||||
/// </summary>
|
||||
void SetDefaultResponseTimeout();
|
||||
|
||||
List<byte> DecodeDataForPhysicalLayerUI1236(byte[] payload);
|
||||
// ReSharper disable once InconsistentNaming UI1236 is a naming forced by the caller
|
||||
List<Byte> DecodeDataForPhysicalLayerUI1236(Byte[] payload);
|
||||
|
||||
/// <summary>
|
||||
/// Send out data (including transport protocol specific data like CRC) to physical port (like UART or IrDA)
|
||||
|
||||
@@ -99,8 +99,8 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
|
||||
|| irdaRecord[IrdaSyncByteIndex] != IrdaSyncByte
|
||||
|| ((irdaRecord[IrdaHeaderIndex] & IrdaReceiveHeaderMask) != (IrdaReceiveHeader & IrdaReceiveHeaderMask)
|
||||
&& (irdaRecord[IrdaHeaderIndex] != IrdaWakeupHeader)
|
||||
|| (irdaRecord[IrdaMessageIndex] != IrdaMessageId)
|
||||
&& irdaRecord[IrdaMessageIndex] != IrdaWakeupId))
|
||||
|| (irdaRecord[IrdaMessageIndex] != IrdaMessageId)
|
||||
&& irdaRecord[IrdaMessageIndex] != IrdaWakeupId))
|
||||
{
|
||||
var error = new ApplicationException("Reply from IrDA is invalid.");
|
||||
Logger.Error(error.Message, error);
|
||||
@@ -169,24 +169,28 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
|
||||
|
||||
return irdaRecord;
|
||||
}
|
||||
|
||||
public override List<byte> DecodeDataForPhysicalLayerUI1236(byte[] requestProtocolPayload)
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <remarks date="2022-Aug-24" author="R.Drabesch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
public override List<Byte> DecodeDataForPhysicalLayerUI1236(Byte[] requestProtocolPayload)
|
||||
{
|
||||
List<byte> collection = new List<byte>()
|
||||
{
|
||||
(byte) 35,
|
||||
(byte) (requestProtocolPayload.Length / 2)
|
||||
};
|
||||
collection.AddRange((IEnumerable<byte>)requestProtocolPayload);
|
||||
ushort reversedLsb8408 = Xylem.Common.Utils.Crc16Ccitt.Crc16Ccitt.CalculateReversedLsb8408(collection.ToArray());
|
||||
List<byte> byteList = new List<byte>()
|
||||
{
|
||||
(byte) 155
|
||||
};
|
||||
byteList.AddRange((IEnumerable<byte>)collection);
|
||||
byteList.Add((byte)((uint)reversedLsb8408 & (uint)byte.MaxValue));
|
||||
byteList.Add((byte)((uint)reversedLsb8408 >> 8));
|
||||
this.Logger.Info("DecodeDataForPhysicalLayerUI1236 PC->Cordonel(" + BitConverter.ToString(byteList.ToArray()) + ")");
|
||||
var collection = new List<Byte>
|
||||
{
|
||||
35,
|
||||
(Byte) (requestProtocolPayload.Length / 2)
|
||||
};
|
||||
collection.AddRange(requestProtocolPayload);
|
||||
var crcResult = Crc16Ccitt.CalculateReversedLsb8408(collection.ToArray());
|
||||
var byteList = new List<Byte>
|
||||
{
|
||||
155
|
||||
};
|
||||
byteList.AddRange(collection);
|
||||
byteList.Add((Byte)(crcResult & 0xFF));
|
||||
byteList.Add((Byte)(crcResult >> 8));
|
||||
Logger.Info("DecodeDataForPhysicalLayerUI1236 PC->Cordonel(" + BitConverter.ToString(byteList.ToArray()) + ")");
|
||||
return byteList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,6 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
|
||||
return rawData;
|
||||
}
|
||||
|
||||
public override List<byte> DecodeDataForPhysicalLayerUI1236(byte[] payload) => throw new ApplicationException("Streaming port cannot send data");
|
||||
public override List<Byte> DecodeDataForPhysicalLayerUI1236(Byte[] payload) => throw new ApplicationException("Streaming port cannot send data");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,22 +144,26 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
|
||||
|
||||
return uartRecord;
|
||||
}
|
||||
public override List<byte> DecodeDataForPhysicalLayerUI1236(byte[] requestProtocolPayload)
|
||||
{
|
||||
List<byte> byteList1 = new List<byte>();
|
||||
List<byte> list = ((IEnumerable<byte>)requestProtocolPayload).ToList<byte>();
|
||||
List<byte> byteList2 = new List<byte>();
|
||||
byteList1.Add((byte)(requestProtocolPayload.Length + 4 + 2));
|
||||
byteList1.Add((byte)0);
|
||||
byteList1.Add((byte)0);
|
||||
ushort num = this.CrcCalc(byteList1, list);
|
||||
byteList2.Add((byte)91);
|
||||
byteList2.AddRange((IEnumerable<byte>)byteList1);
|
||||
byteList2.Add((byte)((uint)num & (uint)byte.MaxValue));
|
||||
byteList2.Add((byte)((uint)num >> 8));
|
||||
byteList2.AddRange((IEnumerable<byte>)list);
|
||||
return byteList2;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <remarks date="2022-Aug-24" author="R.Drabesch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
public override List<Byte> DecodeDataForPhysicalLayerUI1236(Byte[] requestProtocolPayload)
|
||||
{
|
||||
var uartHeader = new List<Byte>();
|
||||
var uartPayload = requestProtocolPayload.ToList();
|
||||
var uartRecord = new List<Byte>();
|
||||
uartHeader.Add((Byte)(requestProtocolPayload.Length + 4 + 2));
|
||||
uartHeader.Add(0);
|
||||
uartHeader.Add(0);
|
||||
var crcResult = CrcCalc(uartHeader, uartPayload);
|
||||
uartRecord.Add(91);
|
||||
uartRecord.AddRange(uartHeader);
|
||||
uartRecord.Add((Byte)(crcResult & 0xFF));
|
||||
uartRecord.Add((Byte)(crcResult >> 8));
|
||||
uartRecord.AddRange(uartPayload);
|
||||
return uartRecord;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
|
||||
/// </summary>
|
||||
public String PortName
|
||||
{
|
||||
get
|
||||
{
|
||||
get =>
|
||||
//if the serial port object does not exists
|
||||
return GetSerialPort() == null ? "NA" : _portName;
|
||||
}
|
||||
GetSerialPort() == null ? "NA" : _portName;
|
||||
set
|
||||
{
|
||||
if (value == null) return;
|
||||
|
||||
@@ -21,13 +21,18 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
|
||||
ProductionMode = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Load configuration file from AppRoaming or working directory
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
public ProcessConfig(String file)
|
||||
{
|
||||
// chack for AppRoaming
|
||||
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(Genesis), file);
|
||||
|
||||
if (!File.Exists(configFile))
|
||||
{
|
||||
// take actual working directory
|
||||
configFile = Path.Combine(file);
|
||||
if (!File.Exists(configFile))
|
||||
{
|
||||
@@ -54,15 +59,15 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write file to AppRoaming and backup it to actual working directory
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
public void Update(String file)
|
||||
{
|
||||
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(Genesis), file);
|
||||
|
||||
if (!File.Exists(configFile))
|
||||
{
|
||||
configFile = Path.Combine(file);
|
||||
}
|
||||
|
||||
File.WriteAllText(configFile, JsonConvert.SerializeObject(this));
|
||||
File.WriteAllText(file, JsonConvert.SerializeObject(this));
|
||||
}
|
||||
|
||||
@@ -104,11 +109,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool AutoUpdateFiles { get; set; }
|
||||
public Boolean AutoUpdateFiles { get; set; }
|
||||
|
||||
[DefaultValue(true)]
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
||||
|
||||
public bool ProductionMode { get; set; } = true;
|
||||
public Boolean ProductionMode { get; set; } = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1878,13 +1878,18 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public byte[] SendUI1236Command(byte[] UI1236Frame,bool waitForResult = true,bool checkRegister = false,ushort skipRetryErrorCode = 4)
|
||||
/// <summary>
|
||||
/// Send UI1236 command
|
||||
/// </summary>
|
||||
/// <remarks date="2022-Aug-24" author="R.Drabesch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
// ReSharper disable once InconsistentNaming UI1236 is a naming forced by the caller
|
||||
public Byte[] SendUI1236Command(Byte[] ui1236Frame,Boolean waitForResult = true,Boolean checkRegister = false,UInt16 skipRetryErrorCode = 4)
|
||||
{
|
||||
this._logger.Info(string.Format("Slot:{0} - Sending Ui-1236 frame: {1} ", (object)this.Slot, (object)UI1236Frame));
|
||||
this.RequestProtocol.AdditionalRetryTimeoutMs = 500000;
|
||||
RequestRecord sendFifoUi1236 = this.RequestProtocol.AddRecordToSendFifoUI1236(UI1236Frame);
|
||||
this.RequestProtocolProcess();
|
||||
_logger.Info($"Slot:{Slot} - Sending Ui-1236 frame: {ui1236Frame} ");
|
||||
var sendFifoUi1236 = RequestProtocol.AddRecordToSendFifoUI1236(ui1236Frame);
|
||||
RequestProtocolProcess();
|
||||
return sendFifoUi1236.ResponsePayload.ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@ using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.ProtocolCore;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol.Consts;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
||||
using Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol;
|
||||
using Xylem.Common.Hardware.Interfaces.Ports.PortCore;
|
||||
|
||||
namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
{
|
||||
@@ -307,23 +305,33 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
}
|
||||
|
||||
|
||||
public RequestRecord AddRecordToSendFifoUI1236(
|
||||
byte[] payload,
|
||||
RegisterDefinition register = null,
|
||||
bool hideDataInLog = false,
|
||||
ushort skipRetryErrorCode = 4)
|
||||
/// <summary>
|
||||
/// Record dispatcher to send FIFO of UI1236 command
|
||||
/// </summary>
|
||||
/// <remarks date="2022-Aug-24" author="R.Drabesch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
/// <param name="payload">Data package with all details like CRC, etc</param>
|
||||
/// <param name="register"><see cref="RegisterDefinition" /> which is intend</param>
|
||||
/// <param name="hideDataInLog">hiding data in log file to avoid spying of passwords</param>
|
||||
/// <param name="skipRetryErrorCode">error mask to skip retries</param>
|
||||
/// <returns>the assembled record for the send FIFO</returns>
|
||||
// ReSharper disable once InconsistentNaming UI1236 is a naming forced by the caller
|
||||
public RequestRecord AddRecordToSendFifoUI1236(Byte[] payload, RegisterDefinition register = null,
|
||||
Boolean hideDataInLog = false, UInt16 skipRetryErrorCode = CommunicationConfig.SkipRetryErrorCode)
|
||||
{
|
||||
byte maxValue = byte.MaxValue;
|
||||
List<byte> requestProtocolData = new List<byte>()
|
||||
{
|
||||
maxValue
|
||||
};
|
||||
requestProtocolData.AddRange((IEnumerable<byte>)payload);
|
||||
ITransmitProtocol transmitProtocol = this.GetTransmitProtocol();
|
||||
List<byte> encodedRequestData = transmitProtocol.DecodeDataForPhysicalLayerUI1236(payload);
|
||||
TransmitPortSettings transmitPortSettings = transmitProtocol.GetTransmitPortSettings();
|
||||
RequestRecord sendFifoUi1236 = new RequestRecord(maxValue, requestProtocolData, encodedRequestData,50000, register, hideDataInLog, skipRetryErrorCode);
|
||||
this._recordsSendFifo.Enqueue(sendFifoUi1236);
|
||||
const Byte maxValue = byte.MaxValue;
|
||||
var requestProtocolData = new List<Byte>
|
||||
{
|
||||
maxValue
|
||||
};
|
||||
requestProtocolData.AddRange(payload);
|
||||
var transmitProtocol = GetTransmitProtocol();
|
||||
var encodedRequestData = transmitProtocol.DecodeDataForPhysicalLayerUI1236(payload);
|
||||
var transmitPortSettings = transmitProtocol.GetTransmitPortSettings();
|
||||
var sendFifoUi1236 = new RequestRecord(maxValue, requestProtocolData, encodedRequestData,
|
||||
transmitPortSettings.ResponseTimeoutMs, register, hideDataInLog, skipRetryErrorCode);
|
||||
_recordsSendFifo.Enqueue(sendFifoUi1236);
|
||||
return sendFifoUi1236;
|
||||
}
|
||||
|
||||
@@ -553,7 +561,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
OnMeterRegisterUpdated?.Invoke(this, new RegisterUpdatedEventArgs(meterRegister, completeResponse.ToArray()));
|
||||
if (expectedLength.HasValue && completeResponse.Count < expectedLength.Value)
|
||||
{
|
||||
_logger.Debug($"Too Short. Payload contains zero");
|
||||
_logger.Debug("Too Short. Payload contains zero");
|
||||
}
|
||||
return cRecord;
|
||||
}
|
||||
@@ -568,15 +576,15 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
}
|
||||
else if (cRecord == null)
|
||||
{
|
||||
_logger.Debug($"Too Short.Record is empty or null");
|
||||
_logger.Debug("Too Short.Record is empty or null");
|
||||
}
|
||||
else if (cRecord.ResponsePayload == null)
|
||||
{
|
||||
_logger.Debug($"Too Short.ResponsePayload is empty or null");
|
||||
_logger.Debug("Too Short.ResponsePayload is empty or null");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Debug($"Too Short.Unkown reason");
|
||||
_logger.Debug("Too Short.Unkown reason");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -680,8 +688,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
//reorder FIFO to bring login at first position
|
||||
for (var i = 0; i < _recordsSendFifo.Count; i++)
|
||||
{
|
||||
RequestRecord tmpRecord;
|
||||
_recordsSendFifo.TryPeek(out tmpRecord);
|
||||
_recordsSendFifo.TryPeek(out var tmpRecord);
|
||||
if (tmpRecord == null || tmpRecord.Register.GetIdent() == topRegister)
|
||||
{
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user