Commit f364f7aea0bc0abe5094d284eae22ed6af2fcb2a
1 parent
c76144ec
Exists in
develop
fix: lte
Showing
8 changed files
with
534 additions
and
0 deletions
Show diff stats
pom.xml
@@ -20,6 +20,12 @@ | @@ -20,6 +20,12 @@ | ||
20 | <dependencies> | 20 | <dependencies> |
21 | 21 | ||
22 | <dependency> | 22 | <dependency> |
23 | + <groupId>org.apache.commons</groupId> | ||
24 | + <artifactId>commons-lang3</artifactId> | ||
25 | + <version>3.8.1</version> | ||
26 | + </dependency> | ||
27 | + | ||
28 | + <dependency> | ||
23 | <groupId>org.springframework.boot</groupId> | 29 | <groupId>org.springframework.boot</groupId> |
24 | <artifactId>spring-boot-starter</artifactId> | 30 | <artifactId>spring-boot-starter</artifactId> |
25 | </dependency> | 31 | </dependency> |
src/main/java/com/example/mina/boxhandler/Lte3000VirtualBoxHandler.java
0 → 100644
No preview for this file type
src/main/java/com/example/mina/boxserver/Lte3000VirtualBoxServer.java
0 → 100644
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +package com.example.mina.boxserver; | ||
2 | + | ||
3 | +import com.example.mina.boxhandler.AeroflexVirtualBoxHandler; | ||
4 | +import com.example.mina.boxhandler.Lte3000VirtualBoxHandler; | ||
5 | +import com.example.mina.property.AeroflexVirtualBoxProperties; | ||
6 | +import com.example.mina.property.Lte3000VirtualBoxProperties; | ||
7 | +import lombok.extern.slf4j.Slf4j; | ||
8 | +import org.springframework.context.annotation.Configuration; | ||
9 | + | ||
10 | + | ||
11 | +@Slf4j | ||
12 | +@Configuration(proxyBeanMethods = false) | ||
13 | +public class Lte3000VirtualBoxServer extends AbstractVirtualBoxServer { | ||
14 | + | ||
15 | + public Lte3000VirtualBoxServer(Lte3000VirtualBoxProperties lte3000VirtualBoxProperties) { | ||
16 | + super(lte3000VirtualBoxProperties, new Lte3000VirtualBoxHandler()); | ||
17 | + } | ||
18 | + | ||
19 | +} |
src/main/java/com/example/mina/entity/Lte3000DataBuffer.java
0 → 100644
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +package com.example.mina.entity; | ||
2 | + | ||
3 | +import com.example.mina.base.AbstractHardwareDataBuffer; | ||
4 | + | ||
5 | + | ||
6 | +public class Lte3000DataBuffer extends AbstractHardwareDataBuffer { | ||
7 | + | ||
8 | + public Lte3000DataBuffer(int row, int col, int maxAtten){ | ||
9 | + super(row, col, col, maxAtten); | ||
10 | + | ||
11 | + matrixData = new Entry[row][col]; | ||
12 | + offsetData = new Entry[col]; // LTE is on col | ||
13 | + | ||
14 | + int offset = maxAtten; | ||
15 | + for(int i = 0; i < col; i++){ | ||
16 | + offsetData[i] = new Entry(i, 0, "rr", offset, false); | ||
17 | +// offset += 5; | ||
18 | + } | ||
19 | + | ||
20 | + for(int i = 0; i < row; i++){ | ||
21 | + for(int k = 0; k < col; k++){ | ||
22 | + if (i == k) { | ||
23 | + matrixData[i][k] = new Entry(i, k, "kk", 1, false); | ||
24 | + }else{ | ||
25 | + matrixData[i][k] = new Entry(i, k, "kk", 0, false); | ||
26 | + } | ||
27 | + } | ||
28 | + } | ||
29 | + } | ||
30 | + | ||
31 | +} |
src/main/java/com/example/mina/helper/Lte3000CommandHelper.java
0 → 100644
@@ -0,0 +1,180 @@ | @@ -0,0 +1,180 @@ | ||
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 | +} | ||
0 | \ No newline at end of file | 181 | \ No newline at end of file |
src/main/java/com/example/mina/property/Lte3000VirtualBoxProperties.java
0 → 100644
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +package com.example.mina.property; | ||
2 | + | ||
3 | +import lombok.Getter; | ||
4 | +import lombok.Setter; | ||
5 | +import lombok.ToString; | ||
6 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
7 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
8 | +import org.springframework.context.annotation.Configuration; | ||
9 | + | ||
10 | +/** | ||
11 | + * @author 杜云山 | ||
12 | + * @date 2021/03/05 | ||
13 | + */ | ||
14 | +@Getter | ||
15 | +@Setter | ||
16 | +@ToString | ||
17 | +@ConfigurationProperties(prefix = "lte3000-virtual") | ||
18 | +@Configuration | ||
19 | +@EnableConfigurationProperties(Lte3000VirtualBoxProperties.class) | ||
20 | +public class Lte3000VirtualBoxProperties extends AbstractVirtualBoxProperties { | ||
21 | + | ||
22 | +} | ||
0 | \ No newline at end of file | 23 | \ No newline at end of file |
@@ -0,0 +1,63 @@ | @@ -0,0 +1,63 @@ | ||
1 | +package com.example.mina.util; | ||
2 | + | ||
3 | +public class LogUtils { | ||
4 | + | ||
5 | + public static String toHexString(byte b){ | ||
6 | + String s = Integer.toHexString(b); | ||
7 | + if(s.length() > 2){ | ||
8 | + s = s.substring(s.length() - 2); | ||
9 | + } | ||
10 | + s = "0x" +s.toUpperCase(); | ||
11 | + | ||
12 | + return s; | ||
13 | + } | ||
14 | + | ||
15 | + public static String toHexString(byte[] b) { | ||
16 | + if(b == null ) return ""; | ||
17 | + | ||
18 | + StringBuilder s = new StringBuilder(); | ||
19 | + | ||
20 | + for(int i = 0; i < b.length; i++){ | ||
21 | + s.append(toHexString(b[i])).append(" "); | ||
22 | + } | ||
23 | + | ||
24 | + return s.toString(); | ||
25 | + } | ||
26 | + | ||
27 | + public static String toHexString(byte[] b, int len) { | ||
28 | + if(b == null) return ""; | ||
29 | + int min = Math.min(len, b.length); | ||
30 | + StringBuilder s = new StringBuilder(); | ||
31 | + for(int i = 0; i < min; i++){ | ||
32 | + s.append(toHexString(b[i])).append(" "); | ||
33 | + } | ||
34 | + | ||
35 | + return s.toString(); | ||
36 | + } | ||
37 | + | ||
38 | + | ||
39 | + public static void println(String s) { | ||
40 | + System.out.println(s); | ||
41 | + } | ||
42 | + public static void println(String s, String s2) { | ||
43 | + System.out.println(s + s2); | ||
44 | + } | ||
45 | + public static void println(String title, byte[] bs) { | ||
46 | + | ||
47 | + System.out.println(title + toHexString(bs)); | ||
48 | + } | ||
49 | + public static void println(String title, byte[] bs, int len) { | ||
50 | + | ||
51 | + System.out.println(title + toHexString(bs, len)); | ||
52 | + } | ||
53 | + | ||
54 | + public static void printLTEcmd(byte[] bs, int len) { | ||
55 | + | ||
56 | + for (int i = 0; i < len; i++) { | ||
57 | + System.out.print((char)bs[i]); | ||
58 | + } | ||
59 | + System.out.println(); | ||
60 | + } | ||
61 | + | ||
62 | + | ||
63 | +} |
src/main/resources/application.yml