liusuyi
2024-10-23 37aeda6f5a45a220955eafd55bf5154c71c2d705
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.ard.tianyu.netty.command;// PointFlyCommand.java
import io.netty.buffer.ByteBuf;
 
public class PointFlyCommand extends BaseCommand {
    private double longitude;
    private double latitude;
    private float height;
    private float speed;
 
    public PointFlyCommand(double longitude, double latitude, float height, float speed) {
        this.longitude = longitude;
        this.latitude = latitude;
        this.height = height;
        this.speed = speed;
        setDataHeader((short) 0x7479);
        setCmdCode((byte) 0xD1);
        setDataLength((short) 17); // 数据长度计算
    }
 
    @Override
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入帧头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeByte(getCmdCode());        // 写入指令编号
        out.writeDouble(longitude);         // 写入经度
        out.writeDouble(latitude);          // 写入纬度
        out.writeFloat(height);             // 写入高度
        out.writeFloat(speed);              // 写入速度
    }
}