package com.example.mina.box.lte3000; import com.example.mina.util.CommandHelper; import com.example.mina.util.Lte3000CommandHelper; import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; import org.apache.mina.filter.codec.ProtocolDecoder; import org.apache.mina.filter.codec.ProtocolDecoderOutput; import java.nio.charset.CharsetDecoder; import java.nio.charset.StandardCharsets; public class Lte3000MessageDecoder implements ProtocolDecoder { private static final byte[] Response_46;// = "Fv7.46 Pv2.15 LTE2250/032X032".getBytes(); private static final byte[] Response_53 = new byte[]{0x06, 0x30, 0x30, 0x53, 0x03, 0x56}; private static final byte[] Response_58 = new byte[]{0x06, 0x30, 0x30, 0x58, 0x47, 0x4D, 0x4F, 0x03, 0x18}; static { byte[] bs = "Fv7.46 Pv2.15 XRM2250/032X064".getBytes(); Response_46 = new byte[bs.length + 6]; System.arraycopy(bs, 0, Response_46, 4, bs.length); Response_46[0] = 0x06; Response_46[1] = 0x30; Response_46[2] = 0x30; Response_46[3] = 0x46; Response_46[bs.length + 4] = 0x03; Lte3000CommandHelper.setCHK(Response_46); } private int getBcdPort(byte a, byte b, byte c) { return (CommandHelper.BCD_REV[a] - 30) * 100 + (CommandHelper.BCD_REV[b] - 30) * 10 + (CommandHelper.BCD_REV[c] - 30); } private int getBcdAttn(byte a, byte b) { return (CommandHelper.BCD_REV[a] - 30) * 10 + (CommandHelper.BCD_REV[b] - 30); } @Override public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { //byte[] bytes = in.array(); byte[] cmd = new byte[in.limit()]; int len = cmd.length; in.get(cmd); String type = null; Lte3000RequestMessage requestMessage = Lte3000RequestMessage.builder() .cmd(new String(cmd)) .bytes(cmd) .len(len) .response46(Response_46) .response53(Response_53) .response58(Response_58) .build(); //F: Firmware Version / Unit ID P.82 //0x46 if (cmd[3] == 'F') { requestMessage.setType("Firmware Version"); } //O:Query Output Channel P.106 //0x4F if (cmd[3] == 'O') { int col = this.getBcdPort(cmd[4], cmd[5], cmd[6]); int row = 0; requestMessage.setRow(row); requestMessage.setCol(col); requestMessage.setType("Query Output Channel"); } //S: Set Crosspoint P.115 //0x53 if (cmd[3] == 'S') { int row = this.getBcdPort(cmd[7], cmd[8], cmd[9]); int col = this.getBcdPort(cmd[4], cmd[5], cmd[6]); requestMessage.setRow(row); requestMessage.setCol(col); requestMessage.setType("Set Crosspoint"); } //XGMO: Set Gain Control to Manual Mode - Output p.137 //0x58 0x47 0x4D 0x4F if (cmd[3] == 'X' && cmd[4] == 'G' && cmd[5] == 'M' && cmd[6] == 'O' ) { int col = this.getBcdPort(cmd[7], cmd[8], cmd[9]); int attn = this.getBcdAttn(cmd[12], cmd[13]); if (cmd[11] == 0x2D) { } requestMessage.setAttn(attn); requestMessage.setCol(col); requestMessage.setType("Set Gain Control to Manual Mode"); } //XGRO: Gain Control Read Status - Output P.139 if (cmd[3] == 'X' && cmd[4] == 'G' && cmd[5] == 'R' && cmd[6] == 'O' ) { int col = this.getBcdPort(cmd[7], cmd[8], cmd[9]); requestMessage.setCol(col); requestMessage.setType("Gain Control Read Status"); } out.write(requestMessage); } @Override public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception { } @Override public void dispose(IoSession session) throws Exception { } }