1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.example.mina.server.box.lte3000;
import com.example.mina.server.util.CommandHelper;
import com.example.mina.server.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;
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[] bytes = new byte[in.limit()];
int len = bytes.length;
in.get(bytes);
String type = null;
Lte3000RequestMessage requestMessage = Lte3000RequestMessage.builder()
.cmd(new String(bytes))
.bytes(bytes)
.len(len)
.response46(Response_46)
.response53(Response_53)
.response58(Response_58)
.build();
//F: Firmware Version / Unit ID P.82
//0x46
if (bytes[3] == 'F') {
requestMessage.setType("Firmware Version");
}
//O:Query Output Channel P.106
//0x4F
if (bytes[3] == 'O') {
int col = this.getBcdPort(bytes[4], bytes[5], bytes[6]);
int row = 0;
requestMessage.setRow(row);
requestMessage.setCol(col);
requestMessage.setType("Query Output Channel");
}
//S: Set Crosspoint P.115
//0x53
if (bytes[3] == 'S') {
int row = this.getBcdPort(bytes[7], bytes[8], bytes[9]);
int col = this.getBcdPort(bytes[4], bytes[5], bytes[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 (bytes[3] == 'X' && bytes[4] == 'G' && bytes[5] == 'M' && bytes[6] == 'O' ) {
int col = this.getBcdPort(bytes[7], bytes[8], bytes[9]);
int attn = this.getBcdAttn(bytes[12], bytes[13]);
if (bytes[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 (bytes[3] == 'X' && bytes[4] == 'G' && bytes[5] == 'R' && bytes[6] == 'O' ) {
int col = this.getBcdPort(bytes[7], bytes[8], bytes[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 {
}
}