package com.imdroid.secapi.dto;

import com.baomidou.mybatisplus.annotation.TableName;
import com.imdroid.secapi.utils.HexUtil;
import lombok.Data;

import java.io.Serializable;

/**
 * GNSS设备组参数，包括工作周期、工作时间等
 *
 * @author LiGang
 */
@Data
@TableName(value = "gnssgroup")
public class GnssGroup implements Serializable {
    public final static short LOW_POWER_MODE = 0;
    public final static short NORMAL_POWER_MODE = 1;
    Integer id;

    Integer work_cycle;
    Integer active_time;
    Integer active_offset;
    Short rs_adv; // reference station only
    Short power_mode;
    Integer device_num;

    public String getConfigCmd(GnssDevice device){
        String cmd = "D3110009";
        cmd += HexUtil.Int2HexString(Integer.parseInt(device.getDeviceid()))
                +HexUtil.Byte2HexString((byte) work_cycle.intValue())
                +HexUtil.Byte2HexString((byte) active_time.intValue())
                +HexUtil.Byte2HexString((byte) active_offset.intValue())
                +((device.getDevicetype() == GnssDevice.TYPE_ROVER)?"00":HexUtil.Byte2HexString((byte) rs_adv.shortValue()))
                +HexUtil.Byte2HexString((byte) power_mode.shortValue());
        return cmd;
    }

    public boolean equals(GnssGroup group){
        return (this.work_cycle.equals(group.work_cycle) &&
                this.active_time.equals(group.active_time) &&
                this.active_offset.equals(group.active_offset) &&
                this.rs_adv.equals(group.rs_adv) &&
                this.power_mode.equals(group.power_mode));
    }
}
