ReFactor: UI1236 implementation
This commit is contained in:
@@ -155,7 +155,7 @@
|
|||||||
</site>
|
</site>
|
||||||
<site name="MeterProcessState" id="2">
|
<site name="MeterProcessState" id="2">
|
||||||
<application path="/" applicationPool="Clr4IntegratedAppPool">
|
<application path="/" applicationPool="Clr4IntegratedAppPool">
|
||||||
<virtualDirectory path="/" physicalPath="C:\Users\drabesch_ro\Repo\lab\la_operations\laa_production\Common\Service\MeterProcessState" />
|
<virtualDirectory path="/" physicalPath="D:\Projekte\SENSUS_GitLab\laa_production\Common\Service\MeterProcessState" />
|
||||||
</application>
|
</application>
|
||||||
<bindings>
|
<bindings>
|
||||||
<binding protocol="http" bindingInformation="*:56011:localhost" />
|
<binding protocol="http" bindingInformation="*:56011:localhost" />
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
|
|||||||
|
|
||||||
public abstract List<Byte> DecodeDataForLogicLayer(List<Byte> rawData);
|
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>
|
/// </summary>
|
||||||
void SetDefaultResponseTimeout();
|
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>
|
/// <summary>
|
||||||
/// Send out data (including transport protocol specific data like CRC) to physical port (like UART or IrDA)
|
/// 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[IrdaSyncByteIndex] != IrdaSyncByte
|
||||||
|| ((irdaRecord[IrdaHeaderIndex] & IrdaReceiveHeaderMask) != (IrdaReceiveHeader & IrdaReceiveHeaderMask)
|
|| ((irdaRecord[IrdaHeaderIndex] & IrdaReceiveHeaderMask) != (IrdaReceiveHeader & IrdaReceiveHeaderMask)
|
||||||
&& (irdaRecord[IrdaHeaderIndex] != IrdaWakeupHeader)
|
&& (irdaRecord[IrdaHeaderIndex] != IrdaWakeupHeader)
|
||||||
|| (irdaRecord[IrdaMessageIndex] != IrdaMessageId)
|
|| (irdaRecord[IrdaMessageIndex] != IrdaMessageId)
|
||||||
&& irdaRecord[IrdaMessageIndex] != IrdaWakeupId))
|
&& irdaRecord[IrdaMessageIndex] != IrdaWakeupId))
|
||||||
{
|
{
|
||||||
var error = new ApplicationException("Reply from IrDA is invalid.");
|
var error = new ApplicationException("Reply from IrDA is invalid.");
|
||||||
Logger.Error(error.Message, error);
|
Logger.Error(error.Message, error);
|
||||||
@@ -169,24 +169,28 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
|
|||||||
|
|
||||||
return irdaRecord;
|
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>()
|
var collection = new List<Byte>
|
||||||
{
|
{
|
||||||
(byte) 35,
|
35,
|
||||||
(byte) (requestProtocolPayload.Length / 2)
|
(Byte) (requestProtocolPayload.Length / 2)
|
||||||
};
|
};
|
||||||
collection.AddRange((IEnumerable<byte>)requestProtocolPayload);
|
collection.AddRange(requestProtocolPayload);
|
||||||
ushort reversedLsb8408 = Xylem.Common.Utils.Crc16Ccitt.Crc16Ccitt.CalculateReversedLsb8408(collection.ToArray());
|
var crcResult = Crc16Ccitt.CalculateReversedLsb8408(collection.ToArray());
|
||||||
List<byte> byteList = new List<byte>()
|
var byteList = new List<Byte>
|
||||||
{
|
{
|
||||||
(byte) 155
|
155
|
||||||
};
|
};
|
||||||
byteList.AddRange((IEnumerable<byte>)collection);
|
byteList.AddRange(collection);
|
||||||
byteList.Add((byte)((uint)reversedLsb8408 & (uint)byte.MaxValue));
|
byteList.Add((Byte)(crcResult & 0xFF));
|
||||||
byteList.Add((byte)((uint)reversedLsb8408 >> 8));
|
byteList.Add((Byte)(crcResult >> 8));
|
||||||
this.Logger.Info("DecodeDataForPhysicalLayerUI1236 PC->Cordonel(" + BitConverter.ToString(byteList.ToArray()) + ")");
|
Logger.Info("DecodeDataForPhysicalLayerUI1236 PC->Cordonel(" + BitConverter.ToString(byteList.ToArray()) + ")");
|
||||||
return byteList;
|
return byteList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,6 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
|
|||||||
return rawData;
|
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1878,12 +1878,18 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
public byte[] SendUI1236Command(byte[] UI1236Frame,bool waitForResult = true,bool checkRegister = false,ushort skipRetryErrorCode = 4)
|
/// 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));
|
_logger.Info($"Slot:{Slot} - Sending Ui-1236 frame: {ui1236Frame} ");
|
||||||
RequestRecord sendFifoUi1236 = this.RequestProtocol.AddRecordToSendFifoUI1236(UI1236Frame);
|
var sendFifoUi1236 = RequestProtocol.AddRecordToSendFifoUI1236(ui1236Frame);
|
||||||
this.RequestProtocolProcess();
|
RequestProtocolProcess();
|
||||||
return sendFifoUi1236.ResponsePayload.ToArray();
|
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.ProtocolCore;
|
||||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol.Consts;
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol.Consts;
|
||||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
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
|
namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||||
{
|
{
|
||||||
@@ -308,23 +306,33 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RequestRecord AddRecordToSendFifoUI1236(
|
/// <summary>
|
||||||
byte[] payload,
|
/// Record dispatcher to send FIFO of UI1236 command
|
||||||
RegisterDefinition register = null,
|
/// </summary>
|
||||||
bool hideDataInLog = false,
|
/// <remarks date="2022-Aug-24" author="R.Drabesch">
|
||||||
ushort skipRetryErrorCode = 4)
|
/// - 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;
|
const Byte maxValue = byte.MaxValue;
|
||||||
List<byte> requestProtocolData = new List<byte>()
|
var requestProtocolData = new List<Byte>
|
||||||
{
|
{
|
||||||
maxValue
|
maxValue
|
||||||
};
|
};
|
||||||
requestProtocolData.AddRange((IEnumerable<byte>)payload);
|
requestProtocolData.AddRange(payload);
|
||||||
ITransmitProtocol transmitProtocol = this.GetTransmitProtocol();
|
var transmitProtocol = GetTransmitProtocol();
|
||||||
List<byte> encodedRequestData = transmitProtocol.DecodeDataForPhysicalLayerUI1236(payload);
|
var encodedRequestData = transmitProtocol.DecodeDataForPhysicalLayerUI1236(payload);
|
||||||
TransmitPortSettings transmitPortSettings = transmitProtocol.GetTransmitPortSettings();
|
var transmitPortSettings = transmitProtocol.GetTransmitPortSettings();
|
||||||
RequestRecord sendFifoUi1236 = new RequestRecord(maxValue, requestProtocolData, encodedRequestData, transmitPortSettings.ResponseTimeoutMs, register, hideDataInLog, skipRetryErrorCode);
|
var sendFifoUi1236 = new RequestRecord(maxValue, requestProtocolData, encodedRequestData,
|
||||||
this._recordsSendFifo.Enqueue(sendFifoUi1236);
|
transmitPortSettings.ResponseTimeoutMs, register, hideDataInLog, skipRetryErrorCode);
|
||||||
|
_recordsSendFifo.Enqueue(sendFifoUi1236);
|
||||||
return sendFifoUi1236;
|
return sendFifoUi1236;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,7 +562,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
|||||||
OnMeterRegisterUpdated?.Invoke(this, new RegisterUpdatedEventArgs(meterRegister, completeResponse.ToArray()));
|
OnMeterRegisterUpdated?.Invoke(this, new RegisterUpdatedEventArgs(meterRegister, completeResponse.ToArray()));
|
||||||
if (expectedLength.HasValue && completeResponse.Count < expectedLength.Value)
|
if (expectedLength.HasValue && completeResponse.Count < expectedLength.Value)
|
||||||
{
|
{
|
||||||
_logger.Debug($"Too Short. Payload contains zero");
|
_logger.Debug("Too Short. Payload contains zero");
|
||||||
}
|
}
|
||||||
return cRecord;
|
return cRecord;
|
||||||
}
|
}
|
||||||
@@ -569,15 +577,15 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
|||||||
}
|
}
|
||||||
else if (cRecord == null)
|
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)
|
else if (cRecord.ResponsePayload == null)
|
||||||
{
|
{
|
||||||
_logger.Debug($"Too Short.ResponsePayload is empty or null");
|
_logger.Debug("Too Short.ResponsePayload is empty or null");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Debug($"Too Short.Unkown reason");
|
_logger.Debug("Too Short.Unkown reason");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -681,8 +689,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
|||||||
//reorder FIFO to bring login at first position
|
//reorder FIFO to bring login at first position
|
||||||
for (var i = 0; i < _recordsSendFifo.Count; i++)
|
for (var i = 0; i < _recordsSendFifo.Count; i++)
|
||||||
{
|
{
|
||||||
RequestRecord tmpRecord;
|
_recordsSendFifo.TryPeek(out var tmpRecord);
|
||||||
_recordsSendFifo.TryPeek(out tmpRecord);
|
|
||||||
if (tmpRecord == null || tmpRecord.Register.GetIdent() == topRegister)
|
if (tmpRecord == null || tmpRecord.Register.GetIdent() == topRegister)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user