You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using BatCharging.Model;
|
|
|
|
namespace BatCharging.Service
|
|
{
|
|
/// <summary>
|
|
/// 解包基础的ASDU字节列表
|
|
/// </summary>
|
|
public class MsgHeadAsduDecoder
|
|
{
|
|
/// <summary>
|
|
/// 解包基础的ASDU字节数组
|
|
/// </summary>
|
|
/// <param name="msgRecv">接收到字节数组</param>
|
|
/// <returns>ASDU消息</returns>
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|