using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BatCharging.Model;
namespace BatCharging.Service
{
///
/// 解包基础的ASDU字节列表
///
public class MsgHeadAsduDecoder
{
///
/// 解包基础的ASDU字节数组
///
/// 接收到字节数组
/// ASDU消息
public static ASDU GetBaseASDUMsg(byte[] msgRecv)
{
ASDU msgResult = null;
if(msgRecv != null)
{
int num=msgRecv.Length;
if(num > 15)
{
msgResult = new ASDU
{
FrameTypeNo = msgRecv[15],
MsgBodyCount = msgRecv[16],
TransReason = BitConverter.ToUInt16(msgRecv,17),
PublicAddr = ByteUtils.ToUInt16(msgRecv, 19),
MsgBodyAddr = msgRecv.Skip(21).Take(3).ToArray(),
MsgBodyContents = msgRecv.Skip(24).ToArray()
};
}
}
else
{
return null;
}
return msgResult;
}
}
}