Commit d409a30408e32f32b420a104b125c05094b3d540
Merge branch 'dev' of http://139.198.15.205/linbenlei/virtualbox into dev
Showing
4 changed files
with
247 additions
and
0 deletions
Show diff stats
src/main/java/com/example/mina/base/AeroflexDataBuffer.java
0 → 100644
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +package com.example.mina.base; | ||
2 | + | ||
3 | +/** | ||
4 | + * @author 杜云山 | ||
5 | + * @date 2021/03/05 | ||
6 | + */ | ||
7 | +public class AeroflexDataBuffer extends HardwareDataBuffer { | ||
8 | + | ||
9 | + public AeroflexDataBuffer(int row, int maxAtten) { | ||
10 | + super(row, row, row, maxAtten); | ||
11 | + | ||
12 | + matrix_data = new Entry[row][row]; | ||
13 | + offset_data = new Entry[row]; | ||
14 | + | ||
15 | + for (int i = 0; i < row; i++) { | ||
16 | + for (int k = 0; k < row; k++) { | ||
17 | + matrix_data[i][k] = new Entry(i, k, "kk", maxAtten, false); | ||
18 | + } | ||
19 | + } | ||
20 | + | ||
21 | + for (int i = 0; i < row; i++) { | ||
22 | + offset_data[i] = new Entry(i, 0, "rr", maxAtten, false); | ||
23 | + } | ||
24 | + | ||
25 | + } | ||
26 | + | ||
27 | +} |
@@ -0,0 +1,60 @@ | @@ -0,0 +1,60 @@ | ||
1 | +package com.example.mina.base; | ||
2 | + | ||
3 | +/** | ||
4 | + * @author 杜云山 | ||
5 | + * @date 2021/03/05 | ||
6 | + */ | ||
7 | +public class Entry { | ||
8 | + | ||
9 | + private final int row; | ||
10 | + | ||
11 | + private final int col; | ||
12 | + | ||
13 | + private final String name; | ||
14 | + | ||
15 | + private int value; | ||
16 | + | ||
17 | + private final boolean booked; | ||
18 | + | ||
19 | + private final long timestamp; | ||
20 | + | ||
21 | + public static final Entry EMPTY = new Entry(0, 0, null, 0, false); | ||
22 | + | ||
23 | + public Entry(int row, int col, String name, int value, boolean booked) { | ||
24 | + this.row = row; | ||
25 | + this.col = col; | ||
26 | + this.name = name; | ||
27 | + this.value = value; | ||
28 | + this.booked = booked; | ||
29 | + this.timestamp = System.nanoTime(); | ||
30 | + } | ||
31 | + | ||
32 | + public int getRow() { | ||
33 | + return row; | ||
34 | + } | ||
35 | + | ||
36 | + public int getCol() { | ||
37 | + return col; | ||
38 | + } | ||
39 | + | ||
40 | + public String getName() { | ||
41 | + return name; | ||
42 | + } | ||
43 | + | ||
44 | + public int getValue() { | ||
45 | + return value; | ||
46 | + } | ||
47 | + | ||
48 | + public boolean isBooked() { | ||
49 | + return booked; | ||
50 | + } | ||
51 | + | ||
52 | + public void setValue(int v) { | ||
53 | + this.value = v; | ||
54 | + } | ||
55 | + | ||
56 | + public long getTimestamp() { | ||
57 | + return this.timestamp; | ||
58 | + } | ||
59 | + | ||
60 | +} |
src/main/java/com/example/mina/base/HardwareDataBuffer.java
0 → 100644
@@ -0,0 +1,86 @@ | @@ -0,0 +1,86 @@ | ||
1 | +package com.example.mina.base; | ||
2 | + | ||
3 | +public class HardwareDataBuffer { | ||
4 | + | ||
5 | + protected int maxRow; | ||
6 | + protected int maxCol; | ||
7 | + protected int maxOffset; | ||
8 | + | ||
9 | + protected int maxAtten; | ||
10 | + | ||
11 | + | ||
12 | + protected Entry[][] matrix_data; | ||
13 | + protected Entry[] offset_data; | ||
14 | + | ||
15 | + public HardwareDataBuffer() {} | ||
16 | + | ||
17 | + public HardwareDataBuffer(int row, int col, int offset, int maxAtten){ | ||
18 | + this.maxRow = row; | ||
19 | + this.maxCol = col; | ||
20 | + this.maxOffset = offset; | ||
21 | + this.maxAtten = maxAtten; | ||
22 | + } | ||
23 | + | ||
24 | + | ||
25 | + /** | ||
26 | + * Set cross point attenuation value. Actually that is not correct. | ||
27 | + * In case of LTE device, this is a ON/OFF status (0,1) | ||
28 | + * | ||
29 | + * @param row the row index. *** starts from 1 *** | ||
30 | + * @param col the col index. *** starts from 1 *** | ||
31 | + * @param val the attenuation value | ||
32 | + */ | ||
33 | + public synchronized void setAttenuation(int row, int col, int val){ | ||
34 | + | ||
35 | + if(val != -1 && (row < 1 || row > maxRow || col < 1 || col > maxCol)) { | ||
36 | + //Logger.atError().log("HardwareDataBuffer: setAttenuation(int row, int col, int val) " + row + "/" + col + "/" + val); | ||
37 | + return; | ||
38 | + } | ||
39 | + if(val == -1) val = maxAtten; | ||
40 | + matrix_data[row - 1][col -1 ] = new Entry(row -1 , col -1 , "rr", val, false);; | ||
41 | + } | ||
42 | + | ||
43 | + | ||
44 | + public int getAttenuation(int row, int col){ | ||
45 | + return matrix_data[row - 1][col -1 ].getValue(); | ||
46 | + } | ||
47 | + | ||
48 | + public synchronized void setOffset(int row,int val){ | ||
49 | + if(row < 1 || row > maxOffset){ | ||
50 | + //rfmazeLogger.atError().log("HardwareDataBuffer: setOffset(int row, int val) " + row + "/" + val); | ||
51 | + return; | ||
52 | + } | ||
53 | + offset_data[row - 1] = new Entry(row -1 , 0 , "rr", val, false);; | ||
54 | + } | ||
55 | + | ||
56 | + public int getOffset(int row){ | ||
57 | + return offset_data[row - 1].getValue(); | ||
58 | + } | ||
59 | + | ||
60 | + | ||
61 | + public Entry[] getOffset_data() { | ||
62 | + return offset_data; | ||
63 | + } | ||
64 | + | ||
65 | + public Entry[][] getMatrix_data() { | ||
66 | + return matrix_data; | ||
67 | + } | ||
68 | + | ||
69 | + public int getMaxRow(){ | ||
70 | + return maxRow; | ||
71 | + } | ||
72 | + | ||
73 | + public int getMaxCol(){ | ||
74 | + return maxCol; | ||
75 | + } | ||
76 | + | ||
77 | + public int getMaxOffset() { | ||
78 | + return maxOffset; | ||
79 | + } | ||
80 | + | ||
81 | + public int getMaxAtten() { | ||
82 | + return maxAtten; | ||
83 | + } | ||
84 | + | ||
85 | + | ||
86 | +} |
@@ -0,0 +1,74 @@ | @@ -0,0 +1,74 @@ | ||
1 | +package com.example.mina.util; | ||
2 | + | ||
3 | +public class StrUtil { | ||
4 | + | ||
5 | + private static final String[] EMPTY_ARRAY = new String[0]; | ||
6 | + | ||
7 | + public static void main(String[] args) { | ||
8 | + System.out.println(toInt("93")); | ||
9 | + | ||
10 | +// System.out.println(parseCommaInts("2a")); | ||
11 | + | ||
12 | + } | ||
13 | + | ||
14 | + public static int[] parseCommaInts(String str) { | ||
15 | + if (str == null) { | ||
16 | + return new int[0]; | ||
17 | + } | ||
18 | + | ||
19 | + String[] ss = str.split(","); | ||
20 | + int[] ids = new int[ss.length]; | ||
21 | + | ||
22 | + int count = 0; | ||
23 | + for (int i = 0; i < ss.length; i++) { | ||
24 | + int p = toInt(ss[i]); | ||
25 | + ids[i] = p; | ||
26 | + if (p >= 0) { | ||
27 | + count++; | ||
28 | + } | ||
29 | + } | ||
30 | + | ||
31 | + if (count < ss.length) { | ||
32 | + int[] ids2 = new int[count]; | ||
33 | + count = 0; | ||
34 | + for (int i = 0; i < ss.length; i++) { | ||
35 | + if (ids[i] >= 0) { | ||
36 | + ids2[count++] = ids[i]; | ||
37 | + } | ||
38 | + } | ||
39 | + | ||
40 | + ids = ids2; | ||
41 | + } | ||
42 | + | ||
43 | + return ids; | ||
44 | + } | ||
45 | + | ||
46 | + public static int toInt(String s) { | ||
47 | + if (isEmpty(s)) { | ||
48 | + return -1; | ||
49 | + } | ||
50 | + | ||
51 | + try { | ||
52 | + float f = Float.parseFloat(s.trim()); | ||
53 | + return (int) f; | ||
54 | + } catch (Exception e) { | ||
55 | + e.printStackTrace(); | ||
56 | + return -1; | ||
57 | + } | ||
58 | + | ||
59 | + } | ||
60 | + | ||
61 | + public static void printArray(String[] ssss) { | ||
62 | + if (ssss == null) { | ||
63 | + System.out.println(" -- NULL --"); | ||
64 | + } | ||
65 | + for (String s : ssss) { | ||
66 | + System.out.println(s); | ||
67 | + } | ||
68 | + } | ||
69 | + | ||
70 | + public static boolean isEmpty(String s) { | ||
71 | + return s == null || s.trim().isEmpty(); | ||
72 | + } | ||
73 | + | ||
74 | +} |