|
|
@ -68,7 +68,7 @@ public class Decoder : ByteToMessageDecoder
|
|
|
|
byte[]? data = null;
|
|
|
|
byte[]? data = null;
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ASDU asdu = Parse(buffer, totalFrameLength, out data);
|
|
|
|
ASDU asdu = Parse(buffer, totalFrameLength, delimiter, out data);
|
|
|
|
Log(chargerSn).Info($"receive {BitUtls.BytesToHexStr(data)}:{JsonConvert.SerializeObject(asdu)} from {chargerSn}");
|
|
|
|
Log(chargerSn).Info($"receive {BitUtls.BytesToHexStr(data)}:{JsonConvert.SerializeObject(asdu)} from {chargerSn}");
|
|
|
|
output.Add(asdu);
|
|
|
|
output.Add(asdu);
|
|
|
|
buffer.Clear();
|
|
|
|
buffer.Clear();
|
|
|
@ -118,18 +118,12 @@ public class Decoder : ByteToMessageDecoder
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ASDU Parse(IByteBuffer byteBuffer, int totalFrameLength, out byte[] data)
|
|
|
|
public ASDU Parse(IByteBuffer byteBuffer, int totalFrameLength, IByteBuffer delimiter, out byte[] data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
data = new byte[totalFrameLength];
|
|
|
|
data = new byte[totalFrameLength];
|
|
|
|
byteBuffer.ReadBytes(data);
|
|
|
|
byteBuffer.ReadBytes(data);
|
|
|
|
|
|
|
|
|
|
|
|
string ou = string.Empty;
|
|
|
|
int removeIndex = delimiter.Capacity;
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ou += data[i].ToString("X2") + " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO bug length取值不对,上述测试使用
|
|
|
|
|
|
|
|
int removeIndex = _delimiters.Length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ushort cmd = byteBuffer.GetByte(14 + removeIndex);
|
|
|
|
ushort cmd = byteBuffer.GetByte(14 + removeIndex);
|
|
|
|
ushort recordType = byteBuffer.GetByte(23 + removeIndex);
|
|
|
|
ushort recordType = byteBuffer.GetByte(23 + removeIndex);
|
|
|
|