This commit is contained in:
Thomas Wiedebusch
2022-09-01 10:10:47 +02:00
29 changed files with 417 additions and 391 deletions
@@ -24,6 +24,8 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
public abstract List<Byte> DecodeDataForLogicLayer(List<Byte> rawData);
public abstract List<byte> DecodeDataForPhysicalLayerUI1236(byte[] payload);
}
}
@@ -22,6 +22,8 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
/// </summary>
void SetDefaultResponseTimeout();
List<byte> DecodeDataForPhysicalLayerUI1236(byte[] payload);
/// <summary>
/// Send out data (including transport protocol specific data like CRC) to physical port (like UART or IrDA)
/// </summary>
@@ -169,5 +169,25 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
return irdaRecord;
}
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()) + ")");
return byteList;
}
}
}
@@ -47,5 +47,7 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
{
return rawData;
}
public override List<byte> DecodeDataForPhysicalLayerUI1236(byte[] payload) => throw new ApplicationException("Streaming port cannot send data");
}
}
@@ -144,7 +144,22 @@ 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;
}
}
}
@@ -1878,6 +1878,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
}
}
public byte[] SendUI1236Command(byte[] UI1236Frame,bool waitForResult = true,bool checkRegister = false,ushort skipRetryErrorCode = 4)
{
this._logger.Info(string.Format("Slot:{0} - Sending Ui-1236 frame: {1} ", (object)this.Slot, (object)UI1236Frame));
RequestRecord sendFifoUi1236 = this.RequestProtocol.AddRecordToSendFifoUI1236(UI1236Frame);
this.RequestProtocolProcess();
return sendFifoUi1236.ResponsePayload.ToArray();
}
#endregion
#region Class handling
@@ -11,6 +11,8 @@ 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
{
@@ -305,6 +307,27 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
return recordForSendFifo;
}
public RequestRecord AddRecordToSendFifoUI1236(
byte[] payload,
RegisterDefinition register = null,
bool hideDataInLog = false,
ushort skipRetryErrorCode = 4)
{
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, transmitPortSettings.ResponseTimeoutMs, register, hideDataInLog, skipRetryErrorCode);
this._recordsSendFifo.Enqueue(sendFifoUi1236);
return sendFifoUi1236;
}
/// <summary>
/// Called after successful response.
/// Decode and check record, handle Errors and dispatch result.
@@ -1 +1 @@
5ed75d99ee45ff67821090f1b3dbb001dd9e4fe3
46bd00889699f5a20a4981a22f62b66368323855