/// <summary>
/// 位置信息汇报
/// </summary>
public class PositionFrame : BDBaseFrame
{
public PositionFrame()
{
FrameType = BDFrameType.Position;
}
/// <summary>
/// 报警标志
/// </summary>
public UInt32 AlarmFlag { get; set; }
/// <summary>
/// 状态
/// </summary>
public UInt32 StatusFlag { get; set; }
/// <summary>
/// 纬度 DWORD 以度为单位的纬度值乘以 10 的 6 次方,精确到百万分之一度
/// </summary>
public double Lat { get; set; }
/// <summary>
/// 经度 DWORD 以度为单位的经度值乘以 10 的 6 次方,精确到百万分之一度
/// </summary>
public double Lng { get; set; }
/// <summary>
/// 高程 WORD 海拔高度,单位为米(m)
/// </summary>
public UInt16 Height { get; set; }
/// <summary>
/// 速度 WORD 1/10km/h
/// </summary>
public float Speed { get; set; }
/// <summary>
/// 方向 WORD 0-359,正北为 0,顺时针
/// </summary>
public UInt16 Direction { get; set; }
/// <summary>
/// 时间 BCD[6] YY-MM-DD-hh-mm-ss(GMT+8 时间,本标准中之后涉及的时间均采用此时区)
/// </summary>
public DateTime GpsDateTime { get; set; }
public override void DecoderFrame(IByteBuffer byteBuffer)
{
base.DecoderFrame(byteBuffer);
AlarmFlag = byteBuffer.ReadUnsignedInt();
StatusFlag = byteBuffer.ReadUnsignedInt();
Lat = byteBuffer.ReadUnsignedInt() / 1000000.0;
Lng = byteBuffer.ReadUnsignedInt() / 1000000.0;
Height = byteBuffer.ReadUnsignedShort();
Speed = byteBuffer.ReadUnsignedShort() / 10.0f;
Direction = byteBuffer.ReadUnsignedShort();
//时间 BCD[6]
byte[] bcdTime = new byte[6];
byteBuffer.ReadBytes(bcdTime);
string bcdTimeString = FrameHelper.Bcd2String(bcdTime);
DateTime gpsTime;
if (DateTime.TryParseExact(bcdTimeString, "yyMMddHHmmss", new CultureInfo("zh-CN", true), DateTimeStyles.None, out gpsTime))
GpsDateTime = gpsTime;
else
GpsDateTime = new DateTime(2001, 1, 1, 0, 0, 0);
}
public override IByteBuffer EncoderContent()
{
IByteBuffer contentBuffer = Unpooled.Buffer(100, 1024);
contentBuffer.WriteInt((int)AlarmFlag);
contentBuffer.WriteInt((int)StatusFlag);
contentBuffer.WriteInt((int)(Lat * 1000000));
contentBuffer.WriteInt((int)(Lng * 1000000));
contentBuffer.WriteUnsignedShort(Height);
contentBuffer.WriteUnsignedShort((UInt16)(Speed * 10));
contentBuffer.WriteUnsignedShort(Direction);
//时间 BCD[6]
byte[] timeBcdBuffer = FrameHelper.WriteBCDString(GpsDateTime.ToString("yyMMddHHmmss"));
contentBuffer.WriteBytes(timeBcdBuffer);
return contentBuffer;
}
public override string ToString()
{
return string.Format("通讯号:{0},时间:{1},经纬度{2}|{3},高度:{4},方向:{5}", TerminalPhone, GpsDateTime.ToString("yyyy-MM-dd HH:mm:ss"), Lng, Lat, Height, Direction);
}
}
5.dotnetty EncoderHandler 封装,上面封装的只是消息体的数据,没有包括标识位,消息头,验证码,标识位,在发送数据通道中,需要把数据加上标识位,消息头,验证码,标识位。包括数据包转义
/// <summary>
/// 北斗数据包 封装
/// &