Commit 542dbf88cdca09acec3b2168a4f18af9c3107afa

Authored by 林本磊
1 parent c542fca8
Exists in develop

fix: 删除main方法

src/main/java/com/example/mina/box/lte3000/Lte3000VirtualBoxHandler.java
... ... @@ -2,7 +2,7 @@ package com.example.mina.box.lte3000;
2 2  
3 3 import com.example.mina.base.AbstractVirtualBoxHandler;
4 4 import com.example.mina.entity.Lte3000DataBuffer;
5   -import com.example.mina.helper.Lte3000CommandHelper;
  5 +import com.example.mina.util.Lte3000CommandHelper;
6 6 import com.example.mina.util.CommandHelper;
7 7 import lombok.extern.slf4j.Slf4j;
8 8 import org.apache.mina.core.session.IoSession;
... ... @@ -54,16 +54,6 @@ public class Lte3000VirtualBoxHandler extends AbstractVirtualBoxHandler<Lte3000R
54 54 return null;
55 55 }
56 56  
57   - @Override
58   - public void messageReceived(IoSession session, Object message) {
59   -
60   - if (message instanceof Lte3000RequestMessage) {
61   -
62   - Lte3000ResponseMessage responseMessage = handleMessage((Lte3000RequestMessage) message);
63   - session.write(responseMessage);
64   - }
65   - }
66   -
67 57  
68 58  
69 59 @Override
... ...
src/main/java/com/example/mina/helper/Lte3000CommandHelper.java
... ... @@ -1,180 +0,0 @@
1   -package com.example.mina.helper;
2   -
3   -import org.apache.commons.lang3.ArrayUtils;
4   -
5   -import java.nio.charset.StandardCharsets;
6   -
7   -public class Lte3000CommandHelper {
8   -
9   -//20- 21-! 22-" 23-# 24-$ 25-% 26-& 27-' 28-( 29-) 2a-* 2b-+ 2c-, 2d-- 2e-. 2f-/
10   -//30-0 31-1 32-2 33-3 34-4 35-5 36-6 37-7 38-8 39-9
11   -// 3a-: 3b-; 3c-< 3d-= 3e-> 3f-? 40-@
12   -// 41-A 42-B 43-C 44-D 45-E 46-F 47-G 48-H 49-I 4a-J 4b-K 4c-L 4d-M 4e-N 4f-O 50-P 51-Q 52-R 53-S 54-T 55-U 56-V 57-W 58-X 59-Y 5a-Z
13   -// 5b-[ 5c-\ 5d-] 5e-^ 5f-_ 60-`
14   -// 61-a 62-b 63-c 64-d 65-e 66-f 67-g 68-h 69-i 6a-j 6b-k 6c-l 6d-m 6e-n 6f-o 70-p 71-q 72-r 73-s 74-t 75-u 76-v 77-w 78-x 79-y 7a-z
15   -// 7b-{ 7c-| 7d-} 7e-~
16   -
17   - ////def for Quinteck:
18   -//#define STX 0x02
19   -//#define ETX 0x03
20   -//#define ACK 0x06
21   -//#define NAK 0x15
22   -//#define RBM_ADDR_H 0x50
23   -//#define RBM_ADDR_L 0x00
24   -//#define NEXUS_ADDR_H 0x40
25   -//#define NEXUS_ADDR_L 0x00
26   -
27   - public static final byte STX = 0X02;
28   - public static final byte ETX = 0X03;
29   - public static final byte ACK = 0X06;
30   - public static final byte NAK = 0X15;
31   -
32   - public static void main(String[] args) {
33   - byte[] bs = Lte3000CommandHelper.genCommandGetCross(1);
34   -
35   -
36   -
37   - System.exit(0);
38   -
39   - }
40   -
41   - public static void setCHK(byte[] bs) {
42   - bs[bs.length - 1] = 0;
43   -
44   - for (int i = 0; i < bs.length - 1; i++) {
45   - bs[bs.length - 1] ^= bs[i];
46   - }
47   - }
48   -
49   - public static int getBcdPort(byte a, byte b, byte c) {
50   - //return (CommandHelper.BCD_REV[a] - 30) * 100 + (CommandHelper.BCD_REV[b] - 30) * 10 + (CommandHelper.BCD_REV[c] - 30);
51   - return Integer.parseInt(new StringBuilder().append(a - 0x30).append(b - 0x30).append(c - 0x30).toString());
52   - }
53   -
54   - /**
55   - * input: "-12.2"
56   - * @param a sign
57   - * @param b tenth
58   - * @param c single
59   - * @param d dot
60   - * @param e tenths
61   - * @return int -12 if -12.2
62   - */
63   - public static int getBcdAttn(byte a, byte b, byte c, byte d, byte e) {
64   - String port = new StringBuilder()
65   - //.append((char)a) // sign -/+
66   - .append(b - 0x30).append(c - 0x30) // integer
67   - //.append((char)d) // .
68   - //.append(e - 0x30)
69   - .toString(); // tenths.
70   - return Integer.parseInt(port);
71   - }
72   -
73   - public static byte[] genCommandSetAttn(int col, int val){
74   - byte[] command = new byte[18];
75   - byte[] vCol = intToReversedBytes(col);
76   - byte[] vVal = intToReversedBytes(val);
77   - command[0] = STX;
78   - command[1] = 0x30;
79   - command[2] = 0x30;
80   - command[3] = 'X';
81   - command[4] = 'G';
82   - command[5] = 'M';
83   - command[6] = 'O';
84   - command[7] = vCol.length > 2 ? vCol[2] : 0x30;
85   - command[8] = vCol.length > 1 ? vCol[1] : 0x30;
86   - command[9] = vCol.length > 0 ? vCol[0] : 0x30;
87   - command[10] = '@';
88   - command[11] = '-';
89   - command[12] = vVal.length > 1 ? vVal[1] : 0x30;
90   - command[13] = vVal.length > 0 ? vVal[0] : 0x30;
91   - command[14] = '.';
92   - command[15] = '0';
93   - command[16] = ETX;
94   - command[17] = 0;
95   -
96   - setCHK(command);
97   -
98   - return command;
99   - }
100   -
101   - public static byte[] genCommandGetAttn(int col){
102   - byte[] command = new byte[12];
103   - byte[] vCol = intToReversedBytes(col);
104   - command[0] = STX;
105   - command[1] = 0x30;
106   - command[2] = 0x30;
107   - command[3] = 'X';
108   - command[4] = 'G';
109   - command[5] = 'R';
110   - command[6] = 'O';
111   - command[7] = vCol.length > 2 ? vCol[2] : 0x30;
112   - command[8] = vCol.length > 1 ? vCol[1] : 0x30;
113   - command[9] = vCol.length > 0 ? vCol[0] : 0x30;
114   - command[10] = ETX;
115   - command[11] = 0;
116   -
117   - setCHK(command);
118   -
119   - return command;
120   - }
121   -
122   -
123   - public static byte[] genCommandSetCross(int row, int col){
124   - byte[] command = new byte[12];
125   - byte[] vRow = intToReversedBytes(row);
126   - byte[] vCol = intToReversedBytes(col);
127   - command[0] = STX;
128   - command[1] = 0x30;
129   - command[2] = 0x30;
130   - command[3] = 'S';
131   - command[4] = vCol.length > 2 ? vCol[2] : 0x30;
132   - command[5] = vCol.length > 1 ? vCol[1] : 0x30;
133   - command[6] = vCol.length > 0 ? vCol[0] : 0x30;
134   - command[7] = vRow.length > 2 ? vRow[2] : 0x30;
135   - command[8] = vRow.length > 1 ? vRow[1] : 0x30;
136   - command[9] = vRow.length > 0 ? vRow[0] : 0x30;
137   - command[10] = ETX;
138   - command[11] = 0;
139   -
140   - setCHK(command);
141   -
142   - return command;
143   - }
144   -
145   - /**
146   - * 1234 => "1234" => ['4','3','2','1']
147   - * 1 => [31]
148   - * 12 => [32,31]
149   - * 123 => [33,32,31]
150   - * @param value value to convert
151   - * @return result
152   - */
153   - public static byte[] intToReversedBytes(int value) {
154   - byte[] result = String.valueOf(value).getBytes(StandardCharsets.US_ASCII);
155   - ArrayUtils.reverse(result);
156   - return result;
157   - }
158   -
159   - public static byte[] genCommandGetCross(int col){
160   - byte[] command = new byte[9];
161   - byte[] value = String.valueOf(col).getBytes(StandardCharsets.US_ASCII);
162   - ArrayUtils.reverse(value);
163   - command[0] = STX;
164   - command[1] = 0x30;
165   - command[2] = 0x30;
166   - command[3] = 'O';
167   - command[4] = value.length >= 3 ? value[2] : 0x30;
168   - command[5] = value.length >= 2 ? value[1] : 0x30;
169   - command[6] = value.length >= 1 ? value[0] : 0x30;
170   - command[7] = ETX;
171   - command[8] = 0;
172   -
173   - setCHK(command);
174   -
175   - return command;
176   - }
177   -
178   -
179   -
180   -}
181 0 \ No newline at end of file
src/main/java/com/example/mina/util/Lte3000CommandHelper.java 0 → 100644
... ... @@ -0,0 +1,172 @@
  1 +package com.example.mina.util;
  2 +
  3 +import org.apache.commons.lang3.ArrayUtils;
  4 +
  5 +import java.nio.charset.StandardCharsets;
  6 +
  7 +public class Lte3000CommandHelper {
  8 +
  9 +//20- 21-! 22-" 23-# 24-$ 25-% 26-& 27-' 28-( 29-) 2a-* 2b-+ 2c-, 2d-- 2e-. 2f-/
  10 +//30-0 31-1 32-2 33-3 34-4 35-5 36-6 37-7 38-8 39-9
  11 +// 3a-: 3b-; 3c-< 3d-= 3e-> 3f-? 40-@
  12 +// 41-A 42-B 43-C 44-D 45-E 46-F 47-G 48-H 49-I 4a-J 4b-K 4c-L 4d-M 4e-N 4f-O 50-P 51-Q 52-R 53-S 54-T 55-U 56-V 57-W 58-X 59-Y 5a-Z
  13 +// 5b-[ 5c-\ 5d-] 5e-^ 5f-_ 60-`
  14 +// 61-a 62-b 63-c 64-d 65-e 66-f 67-g 68-h 69-i 6a-j 6b-k 6c-l 6d-m 6e-n 6f-o 70-p 71-q 72-r 73-s 74-t 75-u 76-v 77-w 78-x 79-y 7a-z
  15 +// 7b-{ 7c-| 7d-} 7e-~
  16 +
  17 + ////def for Quinteck:
  18 +//#define STX 0x02
  19 +//#define ETX 0x03
  20 +//#define ACK 0x06
  21 +//#define NAK 0x15
  22 +//#define RBM_ADDR_H 0x50
  23 +//#define RBM_ADDR_L 0x00
  24 +//#define NEXUS_ADDR_H 0x40
  25 +//#define NEXUS_ADDR_L 0x00
  26 +
  27 + public static final byte STX = 0X02;
  28 + public static final byte ETX = 0X03;
  29 + public static final byte ACK = 0X06;
  30 + public static final byte NAK = 0X15;
  31 +
  32 +
  33 + public static void setCHK(byte[] bs) {
  34 + bs[bs.length - 1] = 0;
  35 +
  36 + for (int i = 0; i < bs.length - 1; i++) {
  37 + bs[bs.length - 1] ^= bs[i];
  38 + }
  39 + }
  40 +
  41 + public static int getBcdPort(byte a, byte b, byte c) {
  42 + //return (CommandHelper.BCD_REV[a] - 30) * 100 + (CommandHelper.BCD_REV[b] - 30) * 10 + (CommandHelper.BCD_REV[c] - 30);
  43 + return Integer.parseInt(new StringBuilder().append(a - 0x30).append(b - 0x30).append(c - 0x30).toString());
  44 + }
  45 +
  46 + /**
  47 + * input: "-12.2"
  48 + * @param a sign
  49 + * @param b tenth
  50 + * @param c single
  51 + * @param d dot
  52 + * @param e tenths
  53 + * @return int -12 if -12.2
  54 + */
  55 + public static int getBcdAttn(byte a, byte b, byte c, byte d, byte e) {
  56 + String port = new StringBuilder()
  57 + //.append((char)a) // sign -/+
  58 + .append(b - 0x30).append(c - 0x30) // integer
  59 + //.append((char)d) // .
  60 + //.append(e - 0x30)
  61 + .toString(); // tenths.
  62 + return Integer.parseInt(port);
  63 + }
  64 +
  65 + public static byte[] genCommandSetAttn(int col, int val){
  66 + byte[] command = new byte[18];
  67 + byte[] vCol = intToReversedBytes(col);
  68 + byte[] vVal = intToReversedBytes(val);
  69 + command[0] = STX;
  70 + command[1] = 0x30;
  71 + command[2] = 0x30;
  72 + command[3] = 'X';
  73 + command[4] = 'G';
  74 + command[5] = 'M';
  75 + command[6] = 'O';
  76 + command[7] = vCol.length > 2 ? vCol[2] : 0x30;
  77 + command[8] = vCol.length > 1 ? vCol[1] : 0x30;
  78 + command[9] = vCol.length > 0 ? vCol[0] : 0x30;
  79 + command[10] = '@';
  80 + command[11] = '-';
  81 + command[12] = vVal.length > 1 ? vVal[1] : 0x30;
  82 + command[13] = vVal.length > 0 ? vVal[0] : 0x30;
  83 + command[14] = '.';
  84 + command[15] = '0';
  85 + command[16] = ETX;
  86 + command[17] = 0;
  87 +
  88 + setCHK(command);
  89 +
  90 + return command;
  91 + }
  92 +
  93 + public static byte[] genCommandGetAttn(int col){
  94 + byte[] command = new byte[12];
  95 + byte[] vCol = intToReversedBytes(col);
  96 + command[0] = STX;
  97 + command[1] = 0x30;
  98 + command[2] = 0x30;
  99 + command[3] = 'X';
  100 + command[4] = 'G';
  101 + command[5] = 'R';
  102 + command[6] = 'O';
  103 + command[7] = vCol.length > 2 ? vCol[2] : 0x30;
  104 + command[8] = vCol.length > 1 ? vCol[1] : 0x30;
  105 + command[9] = vCol.length > 0 ? vCol[0] : 0x30;
  106 + command[10] = ETX;
  107 + command[11] = 0;
  108 +
  109 + setCHK(command);
  110 +
  111 + return command;
  112 + }
  113 +
  114 +
  115 + public static byte[] genCommandSetCross(int row, int col){
  116 + byte[] command = new byte[12];
  117 + byte[] vRow = intToReversedBytes(row);
  118 + byte[] vCol = intToReversedBytes(col);
  119 + command[0] = STX;
  120 + command[1] = 0x30;
  121 + command[2] = 0x30;
  122 + command[3] = 'S';
  123 + command[4] = vCol.length > 2 ? vCol[2] : 0x30;
  124 + command[5] = vCol.length > 1 ? vCol[1] : 0x30;
  125 + command[6] = vCol.length > 0 ? vCol[0] : 0x30;
  126 + command[7] = vRow.length > 2 ? vRow[2] : 0x30;
  127 + command[8] = vRow.length > 1 ? vRow[1] : 0x30;
  128 + command[9] = vRow.length > 0 ? vRow[0] : 0x30;
  129 + command[10] = ETX;
  130 + command[11] = 0;
  131 +
  132 + setCHK(command);
  133 +
  134 + return command;
  135 + }
  136 +
  137 + /**
  138 + * 1234 => "1234" => ['4','3','2','1']
  139 + * 1 => [31]
  140 + * 12 => [32,31]
  141 + * 123 => [33,32,31]
  142 + * @param value value to convert
  143 + * @return result
  144 + */
  145 + public static byte[] intToReversedBytes(int value) {
  146 + byte[] result = String.valueOf(value).getBytes(StandardCharsets.US_ASCII);
  147 + ArrayUtils.reverse(result);
  148 + return result;
  149 + }
  150 +
  151 + public static byte[] genCommandGetCross(int col){
  152 + byte[] command = new byte[9];
  153 + byte[] value = String.valueOf(col).getBytes(StandardCharsets.US_ASCII);
  154 + ArrayUtils.reverse(value);
  155 + command[0] = STX;
  156 + command[1] = 0x30;
  157 + command[2] = 0x30;
  158 + command[3] = 'O';
  159 + command[4] = value.length >= 3 ? value[2] : 0x30;
  160 + command[5] = value.length >= 2 ? value[1] : 0x30;
  161 + command[6] = value.length >= 1 ? value[0] : 0x30;
  162 + command[7] = ETX;
  163 + command[8] = 0;
  164 +
  165 + setCHK(command);
  166 +
  167 + return command;
  168 + }
  169 +
  170 +
  171 +
  172 +}
0 173 \ No newline at end of file
... ...