package com.imdroid.sideslope.message;

import com.imdroid.secapi.dto.GnssTrxMsg;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalTime;

/**
 * 停止指示消息
 *
 * @author LiGang
 */
@Data
@EqualsAndHashCode(callSuper=true)
public class D3F2StopIndicationMessage extends BaseMessage {

    private GnssTrxMsg trxMsg = new GnssTrxMsg();

    @Override
    public void decodeBody(ByteBuf src) {
        trxMsg.setDeviceid(getId());
        trxMsg.setCreatetime(createTime);
        trxMsg.setDevicetime(LocalTime.ofSecondOfDay(getPps()));
        int keys = (this.len - 6) / 5;
        for (int i = 0; i < keys; i++) {
            int key = src.readUnsignedByte();
            long value = src.readUnsignedInt();
            if (key == 0) {
                trxMsg.setUart1txbytes((int) value);
            } else if (key == 1) {
                trxMsg.setUart1rxbytes((int) value);
            } else if (key == 2) {
                trxMsg.setUart1unknown((int) value);
            } else if (key == 3) {
                trxMsg.setUart2txbytes((int) value);
            } else if (key == 4) {
                trxMsg.setUart2rxbytes((int) value);
            } else if (key == 5) {
                trxMsg.setUart2unknown((int) value);
            }
        }
    }

}
