package com.njzscloud.common.localizer.htzj.listener;

import com.njzscloud.common.localizer.contant.BodyCharset;
import com.njzscloud.common.localizer.contant.LocalizerType;
import com.njzscloud.common.localizer.jt808.message.TerminalMessageBody;
import com.njzscloud.common.localizer.jt808.message.TerminalTxtMessage;
import com.njzscloud.common.localizer.jt808.support.JT808MessageListener;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HtzjListeners extends JT808MessageListener {

    public HtzjListeners() {
        super(LocalizerType.HangTianZiJin);
    }

    /**
     * 终端文本信息汇报消息
     */
    @Override
    public void onTxtReport(TerminalMessageBody message) {
        byte[] body = message.getBody();
        ByteBuf byteBuf = Unpooled.wrappedBuffer(body);
        try {
            TerminalTxtMessage terminalTxtReportMsg = new TerminalTxtMessage(byteBuf);
            String txt = terminalTxtReportMsg.getTxt(BodyCharset.ASCII);
            log.info("终端文本信息汇报消息: 【\n{}\n】", txt);
        } catch (Exception e) {
            byteBuf.release();
        }
    }
}
