using InSituLaboratory.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace InSituLaboratory.Common
{
///
/// 基站协议封装
///
public class JZEncapsulation
{
public List EncapAction(List bytes)
{
//定义封装好的报文List
List byteaq = new List();
//添加包头
byteaq.Add(0xAA);
byteaq.Add(0xBB);
//添加版本号
byteaq.Add(0x01);
//添加包长度
byteaq.Add(0x00);
byteaq.Add(0x00);
//添加包ID
byteaq.Add(0x00);
byteaq.Add(0x00);
byteaq.Add(0x00);
byteaq.Add(0x00);
//循环添加下位机报文
foreach (byte b in bytes)
{
byteaq.Add(b);
}
byte[] bytes_length = BitConverter.GetBytes(byteaq.Count() + 3);
byteaq[3] = bytes_length[1];
byteaq[4] = bytes_length[0];
//添加crc校验
byteaq.Add(tools.GetXor(byteaq.ToArray()));
byteaq.Add(0xEE);
byteaq.Add(0xFF);
return byteaq;
}
}
}