package com.zy.core.netty.domain.fire; import com.zy.core.netty.IMessageBody; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufUtil; import lombok.Data; import org.springframework.cache.annotation.SpringCacheAnnotationParser; /** * 心跳 pac * 8230303234303030303030313130353138303E303F3131383083 * Created by vincent on 2022/7/30 */ @Data public class Fire_3030 implements IMessageBody { /** * 机器号 */ private Integer no; /** * 回路 */ private Integer loop; /** * 部位号 */ private Integer partNo; private Integer year; private Integer month; private Integer day; private Integer hour; private Integer minute; private Integer seconds; private Integer validCode; @Override public byte[] writeToBytes() { ByteBuf byteBuf = ByteBufAllocator.DEFAULT.heapBuffer(DEFAULT_LEN); byteBuf.writeShort(no); // todo return ByteBufUtil.getBytes(byteBuf); } @Override public Fire_3030 readFromBytes(byte[] bytes) { // ByteBuf byteBuf = ByteBufAllocator.DEFAULT.heapBuffer(bytes.length > DEFAULT_LEN ? bytes.length + 100 : DEFAULT_LEN); // byteBuf.writeBytes(bytes); // byteBuf.resetReaderIndex(); // byteBuf.skipBytes(3); // this.no = byteBuf.readShort(); // byteBuf.skipBytes(6); // this.year = byteBuf.readShort(); // this.month = byteBuf.readShort(); // this.day = byteBuf.readShort(); // this.hour = byteBuf.readShort(); // this.minute = byteBuf.readShort(); // this.seconds = byteBuf.readShort(); // this.validCode = byteBuf.readShort(); // byteBuf.skipBytes(1); // byteBuf.release(); // System.out.println(byteBuf.refCnt()); this.no = analyze(new byte[]{bytes[3], bytes[4]}); this.loop = analyze(new byte[]{bytes[5], bytes[6]}); this.partNo = analyze(new byte[]{bytes[7], bytes[8]}); //0100201 对应 30 31 0200201 对应 34 35 this.year = analyze(new byte[]{bytes[11], bytes[12]}); this.month = analyze(new byte[]{bytes[13], bytes[14]}); this.day = analyze(new byte[]{bytes[15], bytes[16]}); this.hour = analyze(new byte[]{bytes[17], bytes[18]}); this.minute = analyze(new byte[]{bytes[19], bytes[20]}); this.seconds = analyze(new byte[]{bytes[21], bytes[22]}); this.validCode = analyze(new byte[]{bytes[23], bytes[24]}); return this; } public static Integer analyze(byte[] bytes) { return Integer.parseInt(Integer.toString(bytes[0] & 0x0F, 16) + Integer.toString(bytes[1] & 0x0F, 16), 16); } }