Commit 31003c45064ee97b9bff1e122a5053b44db7cb65
1 parent
168cba4b
Exists in
develop
fix: lte改写
Showing
5 changed files
with
172 additions
and
92 deletions
Show diff stats
src/main/java/com/example/mina/box/lte3000/Lte3000CodecFactory.java
1 | package com.example.mina.box.lte3000; | 1 | package com.example.mina.box.lte3000; |
2 | 2 | ||
3 | -import com.example.mina.box.lte3000.Lte3000RequestMessage; | ||
4 | -import com.example.mina.box.lte3000.Lte3000ResponseMessage; | ||
5 | -import org.apache.mina.core.buffer.IoBuffer; | 3 | + |
6 | import org.apache.mina.core.session.IoSession; | 4 | import org.apache.mina.core.session.IoSession; |
7 | import org.apache.mina.filter.codec.*; | 5 | import org.apache.mina.filter.codec.*; |
8 | 6 | ||
9 | -import java.nio.charset.CharsetDecoder; | ||
10 | -import java.nio.charset.StandardCharsets; | ||
11 | 7 | ||
12 | /** | 8 | /** |
13 | * @author 杜云山 | 9 | * @author 杜云山 |
@@ -25,54 +21,5 @@ public class Lte3000CodecFactory implements ProtocolCodecFactory { | @@ -25,54 +21,5 @@ public class Lte3000CodecFactory implements ProtocolCodecFactory { | ||
25 | return new Lte3000MessageDecoder(); | 21 | return new Lte3000MessageDecoder(); |
26 | } | 22 | } |
27 | 23 | ||
28 | - static class Lte3000MessageEncoder implements ProtocolEncoder { | ||
29 | - | ||
30 | - @Override | ||
31 | - public void encode(IoSession session, Object message, ProtocolEncoderOutput out) { | ||
32 | - | ||
33 | - if (message instanceof Lte3000ResponseMessage) { | ||
34 | - | ||
35 | - byte[] result = ((Lte3000ResponseMessage) message).getResult(); | ||
36 | - session.write(IoBuffer.wrap(result)); | ||
37 | - } | ||
38 | - } | ||
39 | - | ||
40 | - @Override | ||
41 | - public void dispose(IoSession session) { | ||
42 | - } | ||
43 | - | ||
44 | - } | ||
45 | - | ||
46 | - static class Lte3000MessageDecoder implements ProtocolDecoder { | ||
47 | - | ||
48 | - private final CharsetDecoder decoder = StandardCharsets.UTF_16.newDecoder(); | ||
49 | - @Override | ||
50 | - public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { | ||
51 | - //String string = in.getString(decoder); | ||
52 | - //byte[] bytes = in.array(); | ||
53 | - byte[] bytes = new byte[in.limit()]; | ||
54 | - int len = bytes.length; | ||
55 | - in.get(bytes); | ||
56 | - | ||
57 | - Lte3000RequestMessage requestMessage = Lte3000RequestMessage.builder() | ||
58 | - .cmd(new String(bytes)) | ||
59 | - .bytes(bytes) | ||
60 | - .len(len) | ||
61 | - .build(); | ||
62 | - | ||
63 | - out.write(requestMessage); | ||
64 | - } | ||
65 | - | ||
66 | - @Override | ||
67 | - public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception { | ||
68 | - | ||
69 | - } | ||
70 | - | ||
71 | - @Override | ||
72 | - public void dispose(IoSession session) throws Exception { | ||
73 | - | ||
74 | - } | ||
75 | - | ||
76 | - } | ||
77 | 24 | ||
78 | } | 25 | } |
src/main/java/com/example/mina/box/lte3000/Lte3000MessageDecoder.java
0 → 100644
@@ -0,0 +1,114 @@ | @@ -0,0 +1,114 @@ | ||
1 | +package com.example.mina.box.lte3000; | ||
2 | + | ||
3 | +import com.example.mina.util.CommandHelper; | ||
4 | +import com.example.mina.util.Lte3000CommandHelper; | ||
5 | +import org.apache.mina.core.buffer.IoBuffer; | ||
6 | +import org.apache.mina.core.session.IoSession; | ||
7 | +import org.apache.mina.filter.codec.ProtocolDecoder; | ||
8 | +import org.apache.mina.filter.codec.ProtocolDecoderOutput; | ||
9 | + | ||
10 | +import java.nio.charset.CharsetDecoder; | ||
11 | +import java.nio.charset.StandardCharsets; | ||
12 | + | ||
13 | +public class Lte3000MessageDecoder implements ProtocolDecoder { | ||
14 | + | ||
15 | + private static final byte[] Response_46;// = "Fv7.46 Pv2.15 LTE2250/032X032".getBytes(); | ||
16 | + private static final byte[] Response_53 = new byte[]{0x06, 0x30, 0x30, 0x53, 0x03, 0x56}; | ||
17 | + private static final byte[] Response_58 = new byte[]{0x06, 0x30, 0x30, 0x58, 0x47, 0x4D, 0x4F, 0x03, 0x18}; | ||
18 | + | ||
19 | + static { | ||
20 | + byte[] bs = "Fv7.46 Pv2.15 XRM2250/032X064".getBytes(); | ||
21 | + Response_46 = new byte[bs.length + 6]; | ||
22 | + System.arraycopy(bs, 0, Response_46, 4, bs.length); | ||
23 | + Response_46[0] = 0x06; | ||
24 | + Response_46[1] = 0x30; | ||
25 | + Response_46[2] = 0x30; | ||
26 | + Response_46[3] = 0x46; | ||
27 | + Response_46[bs.length + 4] = 0x03; | ||
28 | + Lte3000CommandHelper.setCHK(Response_46); | ||
29 | + } | ||
30 | + | ||
31 | + private int getBcdPort(byte a, byte b, byte c) { | ||
32 | + return (CommandHelper.BCD_REV[a] - 30) * 100 + (CommandHelper.BCD_REV[b] - 30) * 10 + (CommandHelper.BCD_REV[c] - 30); | ||
33 | + } | ||
34 | + private int getBcdAttn(byte a, byte b) { | ||
35 | + return (CommandHelper.BCD_REV[a] - 30) * 10 + (CommandHelper.BCD_REV[b] - 30); | ||
36 | + } | ||
37 | + | ||
38 | + | ||
39 | + | ||
40 | + @Override | ||
41 | + public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { | ||
42 | + //byte[] bytes = in.array(); | ||
43 | + byte[] cmd = new byte[in.limit()]; | ||
44 | + int len = cmd.length; | ||
45 | + in.get(cmd); | ||
46 | + String type = null; | ||
47 | + Lte3000RequestMessage requestMessage = Lte3000RequestMessage.builder() | ||
48 | + .cmd(new String(cmd)) | ||
49 | + .bytes(cmd) | ||
50 | + .len(len) | ||
51 | + .response46(Response_46) | ||
52 | + .response53(Response_53) | ||
53 | + .response58(Response_58) | ||
54 | + .build(); | ||
55 | + | ||
56 | + //F: Firmware Version / Unit ID P.82 | ||
57 | + //0x46 | ||
58 | + if (cmd[3] == 'F') { | ||
59 | + requestMessage.setType("Firmware Version"); | ||
60 | + } | ||
61 | + | ||
62 | + //O:Query Output Channel P.106 | ||
63 | + //0x4F | ||
64 | + if (cmd[3] == 'O') { | ||
65 | + int col = this.getBcdPort(cmd[4], cmd[5], cmd[6]); | ||
66 | + int row = 0; | ||
67 | + requestMessage.setRow(row); | ||
68 | + requestMessage.setCol(col); | ||
69 | + requestMessage.setType("Query Output Channel"); | ||
70 | + | ||
71 | + } | ||
72 | + | ||
73 | + //S: Set Crosspoint P.115 | ||
74 | + //0x53 | ||
75 | + if (cmd[3] == 'S') { | ||
76 | + int row = this.getBcdPort(cmd[7], cmd[8], cmd[9]); | ||
77 | + int col = this.getBcdPort(cmd[4], cmd[5], cmd[6]); | ||
78 | + requestMessage.setRow(row); | ||
79 | + requestMessage.setCol(col); | ||
80 | + requestMessage.setType("Set Crosspoint"); | ||
81 | + } | ||
82 | + | ||
83 | + //XGMO: Set Gain Control to Manual Mode - Output p.137 | ||
84 | + //0x58 0x47 0x4D 0x4F | ||
85 | + if (cmd[3] == 'X' && cmd[4] == 'G' && cmd[5] == 'M' && cmd[6] == 'O' ) { | ||
86 | + int col = this.getBcdPort(cmd[7], cmd[8], cmd[9]); | ||
87 | + int attn = this.getBcdAttn(cmd[12], cmd[13]); | ||
88 | + if (cmd[11] == 0x2D) { | ||
89 | + | ||
90 | + } | ||
91 | + requestMessage.setAttn(attn); | ||
92 | + requestMessage.setCol(col); | ||
93 | + requestMessage.setType("Set Gain Control to Manual Mode"); | ||
94 | + } | ||
95 | + | ||
96 | + //XGRO: Gain Control Read Status - Output P.139 | ||
97 | + if (cmd[3] == 'X' && cmd[4] == 'G' && cmd[5] == 'R' && cmd[6] == 'O' ) { | ||
98 | + int col = this.getBcdPort(cmd[7], cmd[8], cmd[9]); | ||
99 | + requestMessage.setCol(col); | ||
100 | + requestMessage.setType("Gain Control Read Status"); | ||
101 | + } | ||
102 | + out.write(requestMessage); | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception { | ||
107 | + | ||
108 | + } | ||
109 | + | ||
110 | + @Override | ||
111 | + public void dispose(IoSession session) throws Exception { | ||
112 | + | ||
113 | + } | ||
114 | +} |
src/main/java/com/example/mina/box/lte3000/Lte3000MessageEncoder.java
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +package com.example.mina.box.lte3000; | ||
2 | + | ||
3 | +import org.apache.mina.core.buffer.IoBuffer; | ||
4 | +import org.apache.mina.core.session.IoSession; | ||
5 | +import org.apache.mina.filter.codec.ProtocolEncoder; | ||
6 | +import org.apache.mina.filter.codec.ProtocolEncoderOutput; | ||
7 | + | ||
8 | +public class Lte3000MessageEncoder implements ProtocolEncoder { | ||
9 | + | ||
10 | + @Override | ||
11 | + public void encode(IoSession session, Object message, ProtocolEncoderOutput out) { | ||
12 | + | ||
13 | + if (message instanceof Lte3000ResponseMessage) { | ||
14 | + | ||
15 | + byte[] result = ((Lte3000ResponseMessage) message).getResult(); | ||
16 | + session.write(IoBuffer.wrap(result)); | ||
17 | + } | ||
18 | + } | ||
19 | + | ||
20 | + @Override | ||
21 | + public void dispose(IoSession session) { | ||
22 | + } | ||
23 | +} |
src/main/java/com/example/mina/box/lte3000/Lte3000RequestMessage.java
@@ -19,4 +19,21 @@ public class Lte3000RequestMessage extends BaseRequestMessage { | @@ -19,4 +19,21 @@ public class Lte3000RequestMessage extends BaseRequestMessage { | ||
19 | protected Integer len; | 19 | protected Integer len; |
20 | 20 | ||
21 | protected byte[] bytes; | 21 | protected byte[] bytes; |
22 | + | ||
23 | + protected String type; | ||
24 | + | ||
25 | + protected Integer row; | ||
26 | + | ||
27 | + protected Integer col; | ||
28 | + | ||
29 | + protected Integer attn; | ||
30 | + | ||
31 | + protected byte[] response46; | ||
32 | + | ||
33 | + protected byte[] response53; | ||
34 | + | ||
35 | + protected byte[] response58; | ||
36 | + | ||
37 | + | ||
38 | + | ||
22 | } | 39 | } |
src/main/java/com/example/mina/box/lte3000/Lte3000VirtualBoxHandler.java
No preview for this file type