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();
    private String otherInfo;

    @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);
            }else if (key == 6) {//粘包
                otherInfo = "stick num:"+value;
                //trxMsg.setUart2unknown((int) value);
            }else if (key == 7) {//分片
                otherInfo = otherInfo + ", frag num:"+value;
                //trxMsg.setUart2unknown((int) value);
            }else if (key == 8) {//其他错误
                otherInfo = otherInfo + ", other err:"+value;
                //trxMsg.setUart2unknown((int) value);
            }
            else if (key == 11) {//串口3
                otherInfo = otherInfo + ", uart3 tx:"+value;
                //trxMsg.setUart2unknown((int) value);
            }
            else if (key == 12) {//串口3
                otherInfo = otherInfo + ", uart3 rx:"+value;
                //trxMsg.setUart2unknown((int) value);
            }

        }
    }

}
