Commit c76144ec7c375463148eec4de0cf588e1283e17e
1 parent
40f3a57b
Exists in
develop
抽取properties及server
Showing
13 changed files
with
435 additions
and
426 deletions
Show diff stats
src/main/java/com/example/mina/box1/AeroflexVirtualBoxHandler.java
... | ... | @@ -1,139 +0,0 @@ |
1 | -package com.example.mina.box1; | |
2 | - | |
3 | -import com.example.mina.base.AbstractVirtualBoxHandler; | |
4 | -import com.example.mina.entity.AeroflexDataBuffer; | |
5 | -import com.example.mina.util.StrUtil; | |
6 | -import lombok.extern.slf4j.Slf4j; | |
7 | -import org.apache.mina.core.buffer.IoBuffer; | |
8 | -import org.apache.mina.core.session.IoSession; | |
9 | - | |
10 | -/** | |
11 | - * @author 杜云山 | |
12 | - * @date 21/03/05 | |
13 | - */ | |
14 | -@Slf4j | |
15 | -public class AeroflexVirtualBoxHandler extends AbstractVirtualBoxHandler { | |
16 | - | |
17 | - private static final byte[] ERROR = "ERROR".getBytes(); | |
18 | - | |
19 | - private static final byte[] NONE = "OK".getBytes(); | |
20 | - | |
21 | - private static final String SET_ALL = "ATTN ALL MAX"; | |
22 | - | |
23 | - private static final String SET_ONE = "ATTN"; | |
24 | - | |
25 | - private static final String GET_ONE = "ATTN?"; | |
26 | - | |
27 | - private static final String SPACE_SPLIT = " "; | |
28 | - | |
29 | - private static final String SEMICOLON_SPLIT = ";"; | |
30 | - | |
31 | - private AeroflexDataBuffer dataBuffer; | |
32 | - | |
33 | - public AeroflexVirtualBoxHandler() { | |
34 | - this.initMatrix(); | |
35 | - } | |
36 | - | |
37 | - @Override | |
38 | - protected void initMatrix() { | |
39 | - | |
40 | - int row = 10; | |
41 | - int col = 1; | |
42 | - int maxAttenuate = 888; | |
43 | - | |
44 | - dataBuffer = new AeroflexDataBuffer(row, maxAttenuate); | |
45 | - } | |
46 | - | |
47 | - @Override | |
48 | - public void messageReceived(IoSession session, Object message) { | |
49 | - | |
50 | - IoBuffer ioBuffer = (IoBuffer) message; | |
51 | - byte[] bytes = ioBuffer.array(); | |
52 | - | |
53 | - byte[] result = handleMessage(bytes, bytes.length); | |
54 | - | |
55 | - session.write(IoBuffer.wrap(result)); | |
56 | - } | |
57 | - | |
58 | - @Override | |
59 | - protected byte[] handleMessage(byte[] cmd, int len) { | |
60 | - String command = new String(cmd).trim(); | |
61 | - | |
62 | - log.info("aeroflexVirtualBoxHandler receive: {}", command); | |
63 | - | |
64 | - if (command.startsWith(SET_ALL)) { | |
65 | - //set all to max | |
66 | - for (int i = 1; i < dataBuffer.getMaxRow(); i++) { | |
67 | - dataBuffer.setOffset(i, dataBuffer.getMaxAttenuate()); | |
68 | - } | |
69 | - | |
70 | - return NONE; | |
71 | - } else if (command.startsWith(GET_ONE)) { | |
72 | - //get | |
73 | - String[] sss = command.split(SPACE_SPLIT); | |
74 | - if (sss.length >= 2) { | |
75 | - | |
76 | - int row = StrUtil.toInt(sss[1]); | |
77 | - if (row >= 0 && row <= dataBuffer.getMaxRow()) { | |
78 | - String str = String.valueOf(dataBuffer.getOffset(row)); | |
79 | - log.info("aeroflexVirtualBoxHandler return: {}", str); | |
80 | - return str.getBytes(); | |
81 | - } | |
82 | - } | |
83 | - return ERROR; | |
84 | - | |
85 | - } else if (command.startsWith(SET_ONE)) { | |
86 | - //Set, Follow by ATTN? | |
87 | - String[] aa = command.split(SEMICOLON_SPLIT); | |
88 | - | |
89 | - String[] sss = aa[0].split(SPACE_SPLIT); | |
90 | - | |
91 | - if (sss.length >= 3) { | |
92 | - | |
93 | - int row = StrUtil.toInt(sss[1]); | |
94 | - int val = StrUtil.toInt(sss[2]); | |
95 | - | |
96 | - if (row >= 0 && row <= dataBuffer.getMaxRow()) { | |
97 | - if (val >= 0 && val <= dataBuffer.getMaxAttenuate()) { | |
98 | - dataBuffer.setOffset(row, val); | |
99 | - | |
100 | - String str = String.valueOf(dataBuffer.getOffset(row)); | |
101 | - log.info("aeroflexVirtualBoxHandler return =====> {}", str); | |
102 | - return str.getBytes(); | |
103 | - } | |
104 | - } | |
105 | - } | |
106 | - | |
107 | - return ERROR; | |
108 | - | |
109 | - } else { | |
110 | - return ERROR; | |
111 | - } | |
112 | - | |
113 | - } | |
114 | - | |
115 | - @Override | |
116 | - public void sessionCreated(IoSession session) { | |
117 | - | |
118 | - log.info("--- abstractVirtual server session created"); | |
119 | - } | |
120 | - | |
121 | - @Override | |
122 | - public void sessionOpened(IoSession session) { | |
123 | - | |
124 | - log.info("--- abstractVirtual server session Opened"); | |
125 | - } | |
126 | - | |
127 | - @Override | |
128 | - public void sessionClosed(IoSession session) { | |
129 | - | |
130 | - log.info("--- abstractVirtual server session Closed"); | |
131 | - } | |
132 | - | |
133 | - @Override | |
134 | - public void messageSent(IoSession session, Object message) { | |
135 | - | |
136 | - log.info("--- abstractVirtual 发送数据成功!{}", message); | |
137 | - } | |
138 | - | |
139 | -} |
src/main/java/com/example/mina/box1/Rbm3000VirtualBoxHander.java
... | ... | @@ -1,176 +0,0 @@ |
1 | -package com.example.mina.box1; | |
2 | - | |
3 | -import com.example.mina.base.AbstractVirtualBoxHandler; | |
4 | -import com.example.mina.base.CommandHelper; | |
5 | -import com.example.mina.entity.AeroflexDataBuffer; | |
6 | -import com.example.mina.entity.Entry; | |
7 | -import lombok.extern.slf4j.Slf4j; | |
8 | -import org.apache.mina.core.buffer.IoBuffer; | |
9 | -import org.apache.mina.core.session.IoSession; | |
10 | - | |
11 | -/** | |
12 | - * @author dy | |
13 | - * @date 2021/3/5 | |
14 | - */ | |
15 | -@Slf4j | |
16 | -public class Rbm3000VirtualBoxHander extends AbstractVirtualBoxHandler { | |
17 | - | |
18 | - private AeroflexDataBuffer dataBuffer; | |
19 | - | |
20 | - public Rbm3000VirtualBoxHander() { | |
21 | - this.initMatrix(); | |
22 | - } | |
23 | - | |
24 | - @Override | |
25 | - protected void initMatrix() { | |
26 | - | |
27 | - int row = 6; | |
28 | - int col = 8; | |
29 | - int maxAtten = 222; | |
30 | - | |
31 | - dataBuffer = new AeroflexDataBuffer(row, maxAtten); | |
32 | - } | |
33 | - | |
34 | - @Override | |
35 | - protected byte[] handleMessage(byte[] cmd, int len) { | |
36 | - return new byte[0]; | |
37 | - } | |
38 | - | |
39 | - @Override | |
40 | - public void messageReceived(IoSession session, Object message) { | |
41 | - | |
42 | - IoBuffer ioBuffer = (IoBuffer) message; | |
43 | - byte[] bytes = new byte[ioBuffer.limit()]; | |
44 | - ioBuffer.get(bytes, ioBuffer.position(), ioBuffer.limit()); | |
45 | - | |
46 | - byte[] result = handleCommand(bytes, bytes.length); | |
47 | - | |
48 | - session.write(IoBuffer.wrap(result)); | |
49 | - } | |
50 | - | |
51 | - @Override | |
52 | - public void sessionCreated(IoSession session) { | |
53 | - | |
54 | - log.info("---server session created"); | |
55 | - } | |
56 | - | |
57 | - @Override | |
58 | - public void sessionOpened(IoSession session) { | |
59 | - | |
60 | - log.info("---server session Opened"); | |
61 | - } | |
62 | - | |
63 | - @Override | |
64 | - public void sessionClosed(IoSession session) { | |
65 | - | |
66 | - log.info("---server session Closed"); | |
67 | - } | |
68 | - | |
69 | - @Override | |
70 | - public void messageSent(IoSession session, Object message) { | |
71 | - | |
72 | - log.info("---发送数据成功了。。。{}", message); | |
73 | - } | |
74 | - | |
75 | - protected byte[] handleCommand(byte[] cmd, int len) { | |
76 | - | |
77 | - byte[] buffer; | |
78 | - Entry[][] entries = dataBuffer.getMatrixData(); | |
79 | - | |
80 | - if (len == 8) { | |
81 | - switch (cmd[0]) { | |
82 | - case 0x30: | |
83 | - int row = CommandHelper.BCD_REV[cmd[3]]; | |
84 | - int col = CommandHelper.BCD_REV[cmd[4]]; | |
85 | - | |
86 | - int rowCol = 0; | |
87 | - int colRow = 0; | |
88 | - | |
89 | - for (int i = 0; i < dataBuffer.getMaxCol(); i++) { | |
90 | - if (entries[row - 1][i].getValue() == 1) { | |
91 | - rowCol = i + 1; | |
92 | - break; | |
93 | - } | |
94 | - } | |
95 | - for (int i = 0; i < dataBuffer.getMaxRow(); i++) { | |
96 | - if (entries[i][col - 1].getValue() == 1) { | |
97 | - colRow = i + 1; | |
98 | - } | |
99 | - } | |
100 | - | |
101 | - dataBuffer.setAttenuation(row, rowCol, 0); | |
102 | - dataBuffer.setAttenuation(row, col, 1); | |
103 | - dataBuffer.setAttenuation(colRow, col, 0); | |
104 | - dataBuffer.setAttenuation(colRow, rowCol, 1); | |
105 | - | |
106 | - buffer = new byte[8]; | |
107 | - buffer[0] = cmd[0]; | |
108 | - buffer[1] = cmd[1]; | |
109 | - buffer[2] = cmd[2]; | |
110 | - buffer[3] = cmd[3]; | |
111 | - buffer[4] = cmd[4]; | |
112 | - buffer[5] = CommandHelper.BCD[colRow]; | |
113 | - buffer[6] = CommandHelper.BCD[rowCol]; | |
114 | - buffer[7] = (byte) 0x03; | |
115 | - | |
116 | - return buffer; | |
117 | - case 0x68: | |
118 | - boolean isA = (cmd[3] == (byte) 0x0A); | |
119 | - int callPort = CommandHelper.BCD_REV[cmd[4]]; | |
120 | - int returnPort = 0; | |
121 | - | |
122 | - if (isA) { | |
123 | - for (int i = 0; i < dataBuffer.getMaxCol(); i++) { | |
124 | - if (entries[callPort - 1][i].getValue() == 1) { | |
125 | - returnPort = i + 1; | |
126 | - break; | |
127 | - } | |
128 | - } | |
129 | - } else { | |
130 | - for (int i = 0; i < dataBuffer.getMaxRow(); i++) { | |
131 | - if (entries[i][callPort - 1].getValue() == 1) { | |
132 | - returnPort = i + 1; | |
133 | - } | |
134 | - } | |
135 | - } | |
136 | - | |
137 | - buffer = new byte[8]; | |
138 | - buffer[0] = cmd[0]; | |
139 | - buffer[1] = cmd[1]; | |
140 | - buffer[2] = cmd[2]; | |
141 | - if (isA) { | |
142 | - buffer[3] = 0x0B; | |
143 | - } else { | |
144 | - buffer[3] = 0x0A; | |
145 | - } | |
146 | - buffer[4] = CommandHelper.BCD[returnPort]; | |
147 | - buffer[5] = 0x00; | |
148 | - buffer[6] = 0x06; | |
149 | - buffer[7] = (byte) 0x03; | |
150 | - | |
151 | - return buffer; | |
152 | - case 0x62: | |
153 | - buffer = new byte[8]; | |
154 | - buffer[0] = cmd[0]; | |
155 | - buffer[1] = cmd[1]; | |
156 | - buffer[2] = cmd[2]; | |
157 | - buffer[3] = cmd[3]; | |
158 | - buffer[4] = cmd[4]; | |
159 | - buffer[5] = cmd[5]; | |
160 | - buffer[6] = cmd[6]; | |
161 | - buffer[7] = (byte) 0x03; | |
162 | - | |
163 | - return buffer; | |
164 | - default: | |
165 | - break; | |
166 | - } | |
167 | - } | |
168 | - | |
169 | - buffer = new byte[len + 2]; | |
170 | - buffer[0] = (byte) 0xFE; | |
171 | - buffer[1] = (byte) 0xFE; | |
172 | - System.arraycopy(cmd, 0, buffer, 2, len); | |
173 | - | |
174 | - return buffer; | |
175 | - } | |
176 | -} |
src/main/java/com/example/mina/boxhandler/AeroflexVirtualBoxHandler.java
0 → 100644
... | ... | @@ -0,0 +1,139 @@ |
1 | +package com.example.mina.boxhandler; | |
2 | + | |
3 | +import com.example.mina.base.AbstractVirtualBoxHandler; | |
4 | +import com.example.mina.entity.AeroflexDataBuffer; | |
5 | +import com.example.mina.util.StrUtil; | |
6 | +import lombok.extern.slf4j.Slf4j; | |
7 | +import org.apache.mina.core.buffer.IoBuffer; | |
8 | +import org.apache.mina.core.session.IoSession; | |
9 | + | |
10 | +/** | |
11 | + * @author 杜云山 | |
12 | + * @date 21/03/05 | |
13 | + */ | |
14 | +@Slf4j | |
15 | +public class AeroflexVirtualBoxHandler extends AbstractVirtualBoxHandler { | |
16 | + | |
17 | + private static final byte[] ERROR = "ERROR".getBytes(); | |
18 | + | |
19 | + private static final byte[] NONE = "OK".getBytes(); | |
20 | + | |
21 | + private static final String SET_ALL = "ATTN ALL MAX"; | |
22 | + | |
23 | + private static final String SET_ONE = "ATTN"; | |
24 | + | |
25 | + private static final String GET_ONE = "ATTN?"; | |
26 | + | |
27 | + private static final String SPACE_SPLIT = " "; | |
28 | + | |
29 | + private static final String SEMICOLON_SPLIT = ";"; | |
30 | + | |
31 | + private AeroflexDataBuffer dataBuffer; | |
32 | + | |
33 | + public AeroflexVirtualBoxHandler() { | |
34 | + this.initMatrix(); | |
35 | + } | |
36 | + | |
37 | + @Override | |
38 | + protected void initMatrix() { | |
39 | + | |
40 | + int row = 10; | |
41 | + int col = 1; | |
42 | + int maxAttenuate = 888; | |
43 | + | |
44 | + dataBuffer = new AeroflexDataBuffer(row, maxAttenuate); | |
45 | + } | |
46 | + | |
47 | + @Override | |
48 | + public void messageReceived(IoSession session, Object message) { | |
49 | + | |
50 | + IoBuffer ioBuffer = (IoBuffer) message; | |
51 | + byte[] bytes = ioBuffer.array(); | |
52 | + | |
53 | + byte[] result = handleMessage(bytes, bytes.length); | |
54 | + | |
55 | + session.write(IoBuffer.wrap(result)); | |
56 | + } | |
57 | + | |
58 | + @Override | |
59 | + protected byte[] handleMessage(byte[] cmd, int len) { | |
60 | + String command = new String(cmd).trim(); | |
61 | + | |
62 | + log.info("aeroflexVirtualBoxHandler receive: {}", command); | |
63 | + | |
64 | + if (command.startsWith(SET_ALL)) { | |
65 | + //set all to max | |
66 | + for (int i = 1; i < dataBuffer.getMaxRow(); i++) { | |
67 | + dataBuffer.setOffset(i, dataBuffer.getMaxAttenuate()); | |
68 | + } | |
69 | + | |
70 | + return NONE; | |
71 | + } else if (command.startsWith(GET_ONE)) { | |
72 | + //get | |
73 | + String[] sss = command.split(SPACE_SPLIT); | |
74 | + if (sss.length >= 2) { | |
75 | + | |
76 | + int row = StrUtil.toInt(sss[1]); | |
77 | + if (row >= 0 && row <= dataBuffer.getMaxRow()) { | |
78 | + String str = String.valueOf(dataBuffer.getOffset(row)); | |
79 | + log.info("aeroflexVirtualBoxHandler return: {}", str); | |
80 | + return str.getBytes(); | |
81 | + } | |
82 | + } | |
83 | + return ERROR; | |
84 | + | |
85 | + } else if (command.startsWith(SET_ONE)) { | |
86 | + //Set, Follow by ATTN? | |
87 | + String[] aa = command.split(SEMICOLON_SPLIT); | |
88 | + | |
89 | + String[] sss = aa[0].split(SPACE_SPLIT); | |
90 | + | |
91 | + if (sss.length >= 3) { | |
92 | + | |
93 | + int row = StrUtil.toInt(sss[1]); | |
94 | + int val = StrUtil.toInt(sss[2]); | |
95 | + | |
96 | + if (row >= 0 && row <= dataBuffer.getMaxRow()) { | |
97 | + if (val >= 0 && val <= dataBuffer.getMaxAttenuate()) { | |
98 | + dataBuffer.setOffset(row, val); | |
99 | + | |
100 | + String str = String.valueOf(dataBuffer.getOffset(row)); | |
101 | + log.info("aeroflexVirtualBoxHandler return =====> {}", str); | |
102 | + return str.getBytes(); | |
103 | + } | |
104 | + } | |
105 | + } | |
106 | + | |
107 | + return ERROR; | |
108 | + | |
109 | + } else { | |
110 | + return ERROR; | |
111 | + } | |
112 | + | |
113 | + } | |
114 | + | |
115 | + @Override | |
116 | + public void sessionCreated(IoSession session) { | |
117 | + | |
118 | + log.info("--- abstractVirtual server session created"); | |
119 | + } | |
120 | + | |
121 | + @Override | |
122 | + public void sessionOpened(IoSession session) { | |
123 | + | |
124 | + log.info("--- abstractVirtual server session Opened"); | |
125 | + } | |
126 | + | |
127 | + @Override | |
128 | + public void sessionClosed(IoSession session) { | |
129 | + | |
130 | + log.info("--- abstractVirtual server session Closed"); | |
131 | + } | |
132 | + | |
133 | + @Override | |
134 | + public void messageSent(IoSession session, Object message) { | |
135 | + | |
136 | + log.info("--- abstractVirtual 发送数据成功!{}", message); | |
137 | + } | |
138 | + | |
139 | +} | ... | ... |
src/main/java/com/example/mina/boxhandler/Rbm3000VirtualBoxHander.java
0 → 100644
... | ... | @@ -0,0 +1,176 @@ |
1 | +package com.example.mina.boxhandler; | |
2 | + | |
3 | +import com.example.mina.base.AbstractVirtualBoxHandler; | |
4 | +import com.example.mina.base.CommandHelper; | |
5 | +import com.example.mina.entity.AeroflexDataBuffer; | |
6 | +import com.example.mina.entity.Entry; | |
7 | +import lombok.extern.slf4j.Slf4j; | |
8 | +import org.apache.mina.core.buffer.IoBuffer; | |
9 | +import org.apache.mina.core.session.IoSession; | |
10 | + | |
11 | +/** | |
12 | + * @author dy | |
13 | + * @date 2021/3/5 | |
14 | + */ | |
15 | +@Slf4j | |
16 | +public class Rbm3000VirtualBoxHander extends AbstractVirtualBoxHandler { | |
17 | + | |
18 | + private AeroflexDataBuffer dataBuffer; | |
19 | + | |
20 | + public Rbm3000VirtualBoxHander() { | |
21 | + this.initMatrix(); | |
22 | + } | |
23 | + | |
24 | + @Override | |
25 | + protected void initMatrix() { | |
26 | + | |
27 | + int row = 6; | |
28 | + int col = 8; | |
29 | + int maxAtten = 222; | |
30 | + | |
31 | + dataBuffer = new AeroflexDataBuffer(row, maxAtten); | |
32 | + } | |
33 | + | |
34 | + @Override | |
35 | + protected byte[] handleMessage(byte[] cmd, int len) { | |
36 | + return new byte[0]; | |
37 | + } | |
38 | + | |
39 | + @Override | |
40 | + public void messageReceived(IoSession session, Object message) { | |
41 | + | |
42 | + IoBuffer ioBuffer = (IoBuffer) message; | |
43 | + byte[] bytes = new byte[ioBuffer.limit()]; | |
44 | + ioBuffer.get(bytes, ioBuffer.position(), ioBuffer.limit()); | |
45 | + | |
46 | + byte[] result = handleCommand(bytes, bytes.length); | |
47 | + | |
48 | + session.write(IoBuffer.wrap(result)); | |
49 | + } | |
50 | + | |
51 | + @Override | |
52 | + public void sessionCreated(IoSession session) { | |
53 | + | |
54 | + log.info("---server session created"); | |
55 | + } | |
56 | + | |
57 | + @Override | |
58 | + public void sessionOpened(IoSession session) { | |
59 | + | |
60 | + log.info("---server session Opened"); | |
61 | + } | |
62 | + | |
63 | + @Override | |
64 | + public void sessionClosed(IoSession session) { | |
65 | + | |
66 | + log.info("---server session Closed"); | |
67 | + } | |
68 | + | |
69 | + @Override | |
70 | + public void messageSent(IoSession session, Object message) { | |
71 | + | |
72 | + log.info("---发送数据成功了。。。{}", message); | |
73 | + } | |
74 | + | |
75 | + protected byte[] handleCommand(byte[] cmd, int len) { | |
76 | + | |
77 | + byte[] buffer; | |
78 | + Entry[][] entries = dataBuffer.getMatrixData(); | |
79 | + | |
80 | + if (len == 8) { | |
81 | + switch (cmd[0]) { | |
82 | + case 0x30: | |
83 | + int row = CommandHelper.BCD_REV[cmd[3]]; | |
84 | + int col = CommandHelper.BCD_REV[cmd[4]]; | |
85 | + | |
86 | + int rowCol = 0; | |
87 | + int colRow = 0; | |
88 | + | |
89 | + for (int i = 0; i < dataBuffer.getMaxCol(); i++) { | |
90 | + if (entries[row - 1][i].getValue() == 1) { | |
91 | + rowCol = i + 1; | |
92 | + break; | |
93 | + } | |
94 | + } | |
95 | + for (int i = 0; i < dataBuffer.getMaxRow(); i++) { | |
96 | + if (entries[i][col - 1].getValue() == 1) { | |
97 | + colRow = i + 1; | |
98 | + } | |
99 | + } | |
100 | + | |
101 | + dataBuffer.setAttenuation(row, rowCol, 0); | |
102 | + dataBuffer.setAttenuation(row, col, 1); | |
103 | + dataBuffer.setAttenuation(colRow, col, 0); | |
104 | + dataBuffer.setAttenuation(colRow, rowCol, 1); | |
105 | + | |
106 | + buffer = new byte[8]; | |
107 | + buffer[0] = cmd[0]; | |
108 | + buffer[1] = cmd[1]; | |
109 | + buffer[2] = cmd[2]; | |
110 | + buffer[3] = cmd[3]; | |
111 | + buffer[4] = cmd[4]; | |
112 | + buffer[5] = CommandHelper.BCD[colRow]; | |
113 | + buffer[6] = CommandHelper.BCD[rowCol]; | |
114 | + buffer[7] = (byte) 0x03; | |
115 | + | |
116 | + return buffer; | |
117 | + case 0x68: | |
118 | + boolean isA = (cmd[3] == (byte) 0x0A); | |
119 | + int callPort = CommandHelper.BCD_REV[cmd[4]]; | |
120 | + int returnPort = 0; | |
121 | + | |
122 | + if (isA) { | |
123 | + for (int i = 0; i < dataBuffer.getMaxCol(); i++) { | |
124 | + if (entries[callPort - 1][i].getValue() == 1) { | |
125 | + returnPort = i + 1; | |
126 | + break; | |
127 | + } | |
128 | + } | |
129 | + } else { | |
130 | + for (int i = 0; i < dataBuffer.getMaxRow(); i++) { | |
131 | + if (entries[i][callPort - 1].getValue() == 1) { | |
132 | + returnPort = i + 1; | |
133 | + } | |
134 | + } | |
135 | + } | |
136 | + | |
137 | + buffer = new byte[8]; | |
138 | + buffer[0] = cmd[0]; | |
139 | + buffer[1] = cmd[1]; | |
140 | + buffer[2] = cmd[2]; | |
141 | + if (isA) { | |
142 | + buffer[3] = 0x0B; | |
143 | + } else { | |
144 | + buffer[3] = 0x0A; | |
145 | + } | |
146 | + buffer[4] = CommandHelper.BCD[returnPort]; | |
147 | + buffer[5] = 0x00; | |
148 | + buffer[6] = 0x06; | |
149 | + buffer[7] = (byte) 0x03; | |
150 | + | |
151 | + return buffer; | |
152 | + case 0x62: | |
153 | + buffer = new byte[8]; | |
154 | + buffer[0] = cmd[0]; | |
155 | + buffer[1] = cmd[1]; | |
156 | + buffer[2] = cmd[2]; | |
157 | + buffer[3] = cmd[3]; | |
158 | + buffer[4] = cmd[4]; | |
159 | + buffer[5] = cmd[5]; | |
160 | + buffer[6] = cmd[6]; | |
161 | + buffer[7] = (byte) 0x03; | |
162 | + | |
163 | + return buffer; | |
164 | + default: | |
165 | + break; | |
166 | + } | |
167 | + } | |
168 | + | |
169 | + buffer = new byte[len + 2]; | |
170 | + buffer[0] = (byte) 0xFE; | |
171 | + buffer[1] = (byte) 0xFE; | |
172 | + System.arraycopy(cmd, 0, buffer, 2, len); | |
173 | + | |
174 | + return buffer; | |
175 | + } | |
176 | +} | ... | ... |
src/main/java/com/example/mina/boxserver/AbstractVirtualBoxServer.java
0 → 100644
... | ... | @@ -0,0 +1,56 @@ |
1 | +package com.example.mina.boxserver; | |
2 | + | |
3 | +import com.example.mina.base.AbstractVirtualBoxHandler; | |
4 | +import com.example.mina.property.AbstractVirtualBoxProperties; | |
5 | +import lombok.extern.slf4j.Slf4j; | |
6 | +import org.apache.mina.transport.socket.nio.NioSocketAcceptor; | |
7 | +import org.springframework.boot.ApplicationArguments; | |
8 | +import org.springframework.boot.ApplicationRunner; | |
9 | + | |
10 | +import java.net.InetSocketAddress; | |
11 | + | |
12 | +/** | |
13 | + * @author 杜云山 | |
14 | + * @date 21/03/05 | |
15 | + */ | |
16 | +@Slf4j | |
17 | +public class AbstractVirtualBoxServer implements ApplicationRunner { | |
18 | + | |
19 | + private final AbstractVirtualBoxProperties abstractVirtualBoxProperties; | |
20 | + | |
21 | + private final AbstractVirtualBoxHandler abstractVirtualBoxHandler; | |
22 | + | |
23 | + public AbstractVirtualBoxServer(AbstractVirtualBoxProperties abstractVirtualBoxProperties, | |
24 | + AbstractVirtualBoxHandler abstractVirtualBoxHandler) { | |
25 | + this.abstractVirtualBoxProperties = abstractVirtualBoxProperties; | |
26 | + this.abstractVirtualBoxHandler = abstractVirtualBoxHandler; | |
27 | + } | |
28 | + | |
29 | + @Override | |
30 | + public void run(ApplicationArguments args) { | |
31 | + | |
32 | + String name = abstractVirtualBoxProperties.getName(); | |
33 | + Integer port = abstractVirtualBoxProperties.getPort(); | |
34 | + | |
35 | + if (!abstractVirtualBoxProperties.getEnable()) { | |
36 | + log.info("{}服务端 配置未开启", name); | |
37 | + return; | |
38 | + } | |
39 | + | |
40 | + if (port == null) { | |
41 | + log.info("{}服务端 端口未配置", name); | |
42 | + return; | |
43 | + } | |
44 | + | |
45 | + try { | |
46 | + NioSocketAcceptor acceptor = new NioSocketAcceptor(); | |
47 | + acceptor.setHandler(abstractVirtualBoxHandler); | |
48 | + acceptor.setReuseAddress(true); | |
49 | + acceptor.bind(new InetSocketAddress(port)); | |
50 | + log.info("{}服务端已经启动,监听端口: {}", name, port); | |
51 | + } catch (Exception e) { | |
52 | + log.error("无法启动{}服务端, {}", name, e.getMessage(), e); | |
53 | + } | |
54 | + } | |
55 | + | |
56 | +} | ... | ... |
src/main/java/com/example/mina/boxserver/AeroflexVirtualBoxServer.java
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +package com.example.mina.boxserver; | |
2 | + | |
3 | +import com.example.mina.boxhandler.AeroflexVirtualBoxHandler; | |
4 | +import com.example.mina.property.AeroflexVirtualBoxProperties; | |
5 | +import lombok.extern.slf4j.Slf4j; | |
6 | +import org.springframework.context.annotation.Configuration; | |
7 | + | |
8 | +/** | |
9 | + * @author 杜云山 | |
10 | + * @date 21/03/05 | |
11 | + */ | |
12 | +@Slf4j | |
13 | +@Configuration(proxyBeanMethods = false) | |
14 | +public class AeroflexVirtualBoxServer extends AbstractVirtualBoxServer { | |
15 | + | |
16 | + public AeroflexVirtualBoxServer(AeroflexVirtualBoxProperties aeroflexVirtualBoxProperties) { | |
17 | + super(aeroflexVirtualBoxProperties, new AeroflexVirtualBoxHandler()); | |
18 | + } | |
19 | + | |
20 | +} | ... | ... |
src/main/java/com/example/mina/boxserver/Rbm3000VirtualBoxServer.java
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +package com.example.mina.boxserver; | |
2 | + | |
3 | +import com.example.mina.boxhandler.Rbm3000VirtualBoxHander; | |
4 | +import com.example.mina.property.Rbm3000VitualBoxProperties; | |
5 | +import lombok.extern.slf4j.Slf4j; | |
6 | +import org.springframework.context.annotation.Configuration; | |
7 | + | |
8 | +/** | |
9 | + * @author 杜云山 | |
10 | + * @date 21/03/05 | |
11 | + */ | |
12 | +@Slf4j | |
13 | +@Configuration(proxyBeanMethods = false) | |
14 | +public class Rbm3000VirtualBoxServer extends AbstractVirtualBoxServer { | |
15 | + | |
16 | + public Rbm3000VirtualBoxServer(Rbm3000VitualBoxProperties rbm3000VitualBoxProperties) { | |
17 | + super(rbm3000VitualBoxProperties, new Rbm3000VirtualBoxHander()); | |
18 | + } | |
19 | + | |
20 | +} | ... | ... |
src/main/java/com/example/mina/config/AeroflexVirtualBoxConfiguration.java
... | ... | @@ -1,50 +0,0 @@ |
1 | -package com.example.mina.config; | |
2 | - | |
3 | -import com.example.mina.box1.AeroflexVirtualBoxHandler; | |
4 | -import com.example.mina.property.AeroflexVirtualBoxProperties; | |
5 | -import lombok.extern.slf4j.Slf4j; | |
6 | -import org.apache.mina.transport.socket.nio.NioSocketAcceptor; | |
7 | -import org.springframework.context.annotation.Configuration; | |
8 | - | |
9 | -import javax.annotation.PostConstruct; | |
10 | -import java.net.InetSocketAddress; | |
11 | - | |
12 | -/** | |
13 | - * @author 杜云山 | |
14 | - * @date 21/03/05 | |
15 | - */ | |
16 | -@Slf4j | |
17 | -@Configuration(proxyBeanMethods = false) | |
18 | -public class AeroflexVirtualBoxConfiguration { | |
19 | - | |
20 | - private final AeroflexVirtualBoxProperties aeroflexVirtualBoxProperties; | |
21 | - | |
22 | - public AeroflexVirtualBoxConfiguration(AeroflexVirtualBoxProperties aeroflexVirtualBoxProperties) { | |
23 | - this.aeroflexVirtualBoxProperties = aeroflexVirtualBoxProperties; | |
24 | - } | |
25 | - | |
26 | - @PostConstruct | |
27 | - public void init() { | |
28 | - | |
29 | - if (!aeroflexVirtualBoxProperties.getEnable()) { | |
30 | - log.info("AeroflexVirtual服务端 配置未开启"); | |
31 | - return; | |
32 | - } | |
33 | - | |
34 | - if (aeroflexVirtualBoxProperties.getPort() == null) { | |
35 | - log.info("AeroflexVirtual服务端 端口未配置"); | |
36 | - return; | |
37 | - } | |
38 | - | |
39 | - try { | |
40 | - NioSocketAcceptor acceptor = new NioSocketAcceptor(); | |
41 | - acceptor.setHandler(new AeroflexVirtualBoxHandler()); | |
42 | - acceptor.setReuseAddress(true); | |
43 | - acceptor.bind(new InetSocketAddress(aeroflexVirtualBoxProperties.getPort())); | |
44 | - log.info("AeroflexVirtual服务端已经启动,监听端口: {}", aeroflexVirtualBoxProperties.getPort()); | |
45 | - } catch (Exception e) { | |
46 | - log.error("无法启动AeroflexVirtual服务端, {}", e.getMessage(), e); | |
47 | - } | |
48 | - } | |
49 | - | |
50 | -} |
src/main/java/com/example/mina/config/Rbm3000VirtualBoxConfiguration.java
... | ... | @@ -1,51 +0,0 @@ |
1 | -package com.example.mina.config; | |
2 | - | |
3 | -import com.example.mina.box1.Rbm3000VirtualBoxHander; | |
4 | -import com.example.mina.property.Rbm3000VitualBoxProperties; | |
5 | -import lombok.extern.slf4j.Slf4j; | |
6 | -import org.apache.mina.transport.socket.nio.NioSocketAcceptor; | |
7 | -import org.springframework.context.annotation.Configuration; | |
8 | - | |
9 | -import javax.annotation.PostConstruct; | |
10 | -import java.net.InetSocketAddress; | |
11 | - | |
12 | -/** | |
13 | - * @author 杜云山 | |
14 | - * @date 21/03/05 | |
15 | - */ | |
16 | -@Slf4j | |
17 | -@Configuration(proxyBeanMethods = false) | |
18 | -public class Rbm3000VirtualBoxConfiguration { | |
19 | - | |
20 | - private final Rbm3000VitualBoxProperties rbm3000VitualBoxProperties; | |
21 | - | |
22 | - public Rbm3000VirtualBoxConfiguration(Rbm3000VitualBoxProperties rbm3000VitualBoxProperties) { | |
23 | - this.rbm3000VitualBoxProperties = rbm3000VitualBoxProperties; | |
24 | - } | |
25 | - | |
26 | - | |
27 | - @PostConstruct | |
28 | - public void init() { | |
29 | - | |
30 | - if (!rbm3000VitualBoxProperties.getEnable()) { | |
31 | - log.info("Rbm3000Virtual服务端 配置未开启"); | |
32 | - return; | |
33 | - } | |
34 | - | |
35 | - if (rbm3000VitualBoxProperties.getPort() == null) { | |
36 | - log.info("Rbm3000Virtual服务端 端口未配置"); | |
37 | - return; | |
38 | - } | |
39 | - | |
40 | - try { | |
41 | - NioSocketAcceptor acceptor = new NioSocketAcceptor(); | |
42 | - acceptor.setHandler(new Rbm3000VirtualBoxHander()); | |
43 | - acceptor.setReuseAddress(true); | |
44 | - acceptor.bind(new InetSocketAddress(rbm3000VitualBoxProperties.getPort())); | |
45 | - log.info("Rbm3000Virtual服务端已经启动,监听端口: {}", rbm3000VitualBoxProperties.getPort()); | |
46 | - } catch (Exception e) { | |
47 | - log.error("无法启动Rbm3000Virtual服务端, {}", e.getMessage(), e); | |
48 | - } | |
49 | - } | |
50 | - | |
51 | -} |
src/main/java/com/example/mina/property/AbstractVirtualBoxProperties.java
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +package com.example.mina.property; | |
2 | + | |
3 | +import lombok.Getter; | |
4 | +import lombok.Setter; | |
5 | + | |
6 | +/** | |
7 | + * @author 杜云山 | |
8 | + * @date 2021/03/05 | |
9 | + */ | |
10 | +@Getter | |
11 | +@Setter | |
12 | +public abstract class AbstractVirtualBoxProperties { | |
13 | + | |
14 | + protected String name = ""; | |
15 | + | |
16 | + protected Boolean enable = false; | |
17 | + | |
18 | + protected Integer port = null; | |
19 | + | |
20 | +} | |
0 | 21 | \ No newline at end of file | ... | ... |
src/main/java/com/example/mina/property/AeroflexVirtualBoxProperties.java
... | ... | @@ -17,10 +17,6 @@ import org.springframework.context.annotation.Configuration; |
17 | 17 | @ConfigurationProperties(prefix = "aeroflex-virtual") |
18 | 18 | @Configuration |
19 | 19 | @EnableConfigurationProperties(AeroflexVirtualBoxProperties.class) |
20 | -public class AeroflexVirtualBoxProperties { | |
21 | - | |
22 | - private Boolean enable = false; | |
23 | - | |
24 | - private Integer port = null; | |
20 | +public class AeroflexVirtualBoxProperties extends AbstractVirtualBoxProperties { | |
25 | 21 | |
26 | 22 | } |
27 | 23 | \ No newline at end of file | ... | ... |
src/main/java/com/example/mina/property/Rbm3000VitualBoxProperties.java
... | ... | @@ -17,10 +17,6 @@ import org.springframework.context.annotation.Configuration; |
17 | 17 | @ConfigurationProperties(prefix = "rbm3000-vitualbox-virtual") |
18 | 18 | @Configuration |
19 | 19 | @EnableConfigurationProperties(Rbm3000VitualBoxProperties.class) |
20 | -public class Rbm3000VitualBoxProperties { | |
21 | - | |
22 | - private Boolean enable = false; | |
23 | - | |
24 | - private Integer port = null; | |
20 | +public class Rbm3000VitualBoxProperties extends AbstractVirtualBoxProperties { | |
25 | 21 | |
26 | 22 | } |
27 | 23 | \ No newline at end of file | ... | ... |