Commit f75899e26c64c7fbf190b9f2fac9b3e17f68cc27
1 parent
31003c45
Exists in
develop
fix: rmasm
Showing
13 changed files
with
609 additions
and
22 deletions
Show diff stats
src/main/java/com/example/mina/box/lte3000/Lte3000MessageDecoder.java
... | ... | @@ -7,11 +7,9 @@ import org.apache.mina.core.session.IoSession; |
7 | 7 | import org.apache.mina.filter.codec.ProtocolDecoder; |
8 | 8 | import org.apache.mina.filter.codec.ProtocolDecoderOutput; |
9 | 9 | |
10 | -import java.nio.charset.CharsetDecoder; | |
11 | -import java.nio.charset.StandardCharsets; | |
12 | 10 | |
13 | 11 | public class Lte3000MessageDecoder implements ProtocolDecoder { |
14 | - | |
12 | + | |
15 | 13 | private static final byte[] Response_46;// = "Fv7.46 Pv2.15 LTE2250/032X032".getBytes(); |
16 | 14 | private static final byte[] Response_53 = new byte[]{0x06, 0x30, 0x30, 0x53, 0x03, 0x56}; |
17 | 15 | private static final byte[] Response_58 = new byte[]{0x06, 0x30, 0x30, 0x58, 0x47, 0x4D, 0x4F, 0x03, 0x18}; |
... | ... | @@ -35,18 +33,18 @@ public class Lte3000MessageDecoder implements ProtocolDecoder { |
35 | 33 | return (CommandHelper.BCD_REV[a] - 30) * 10 + (CommandHelper.BCD_REV[b] - 30); |
36 | 34 | } |
37 | 35 | |
38 | - | |
39 | - | |
36 | + | |
37 | + | |
40 | 38 | @Override |
41 | 39 | public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { |
42 | 40 | //byte[] bytes = in.array(); |
43 | - byte[] cmd = new byte[in.limit()]; | |
44 | - int len = cmd.length; | |
45 | - in.get(cmd); | |
41 | + byte[] bytes = new byte[in.limit()]; | |
42 | + int len = bytes.length; | |
43 | + in.get(bytes); | |
46 | 44 | String type = null; |
47 | 45 | Lte3000RequestMessage requestMessage = Lte3000RequestMessage.builder() |
48 | - .cmd(new String(cmd)) | |
49 | - .bytes(cmd) | |
46 | + .cmd(new String(bytes)) | |
47 | + .bytes(bytes) | |
50 | 48 | .len(len) |
51 | 49 | .response46(Response_46) |
52 | 50 | .response53(Response_53) |
... | ... | @@ -55,14 +53,14 @@ public class Lte3000MessageDecoder implements ProtocolDecoder { |
55 | 53 | |
56 | 54 | //F: Firmware Version / Unit ID P.82 |
57 | 55 | //0x46 |
58 | - if (cmd[3] == 'F') { | |
56 | + if (bytes[3] == 'F') { | |
59 | 57 | requestMessage.setType("Firmware Version"); |
60 | 58 | } |
61 | 59 | |
62 | 60 | //O:Query Output Channel P.106 |
63 | 61 | //0x4F |
64 | - if (cmd[3] == 'O') { | |
65 | - int col = this.getBcdPort(cmd[4], cmd[5], cmd[6]); | |
62 | + if (bytes[3] == 'O') { | |
63 | + int col = this.getBcdPort(bytes[4], bytes[5], bytes[6]); | |
66 | 64 | int row = 0; |
67 | 65 | requestMessage.setRow(row); |
68 | 66 | requestMessage.setCol(col); |
... | ... | @@ -72,9 +70,9 @@ public class Lte3000MessageDecoder implements ProtocolDecoder { |
72 | 70 | |
73 | 71 | //S: Set Crosspoint P.115 |
74 | 72 | //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]); | |
73 | + if (bytes[3] == 'S') { | |
74 | + int row = this.getBcdPort(bytes[7], bytes[8], bytes[9]); | |
75 | + int col = this.getBcdPort(bytes[4], bytes[5], bytes[6]); | |
78 | 76 | requestMessage.setRow(row); |
79 | 77 | requestMessage.setCol(col); |
80 | 78 | requestMessage.setType("Set Crosspoint"); |
... | ... | @@ -82,10 +80,10 @@ public class Lte3000MessageDecoder implements ProtocolDecoder { |
82 | 80 | |
83 | 81 | //XGMO: Set Gain Control to Manual Mode - Output p.137 |
84 | 82 | //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) { | |
83 | + if (bytes[3] == 'X' && bytes[4] == 'G' && bytes[5] == 'M' && bytes[6] == 'O' ) { | |
84 | + int col = this.getBcdPort(bytes[7], bytes[8], bytes[9]); | |
85 | + int attn = this.getBcdAttn(bytes[12], bytes[13]); | |
86 | + if (bytes[11] == 0x2D) { | |
89 | 87 | |
90 | 88 | } |
91 | 89 | requestMessage.setAttn(attn); |
... | ... | @@ -94,8 +92,8 @@ public class Lte3000MessageDecoder implements ProtocolDecoder { |
94 | 92 | } |
95 | 93 | |
96 | 94 | //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]); | |
95 | + if (bytes[3] == 'X' && bytes[4] == 'G' && bytes[5] == 'R' && bytes[6] == 'O' ) { | |
96 | + int col = this.getBcdPort(bytes[7], bytes[8], bytes[9]); | |
99 | 97 | requestMessage.setCol(col); |
100 | 98 | requestMessage.setType("Gain Control Read Status"); |
101 | 99 | } | ... | ... |
src/main/java/com/example/mina/box/rmasm/RmasmCodecFactory.java
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +package com.example.mina.box.rmasm; | |
2 | + | |
3 | + | |
4 | +import com.example.mina.box.lte3000.Lte3000MessageDecoder; | |
5 | +import com.example.mina.box.lte3000.Lte3000MessageEncoder; | |
6 | +import org.apache.mina.core.session.IoSession; | |
7 | +import org.apache.mina.filter.codec.ProtocolCodecFactory; | |
8 | +import org.apache.mina.filter.codec.ProtocolDecoder; | |
9 | +import org.apache.mina.filter.codec.ProtocolEncoder; | |
10 | + | |
11 | + | |
12 | +/** | |
13 | + * @author 杜云山 | |
14 | + * @date 20/07/07 | |
15 | + */ | |
16 | +public class RmasmCodecFactory implements ProtocolCodecFactory { | |
17 | + | |
18 | + @Override | |
19 | + public ProtocolEncoder getEncoder(IoSession session) { | |
20 | + return new RmasmMessageEncoder(); | |
21 | + } | |
22 | + | |
23 | + @Override | |
24 | + public ProtocolDecoder getDecoder(IoSession session) { | |
25 | + return new RmasmMessageDecoder(); | |
26 | + } | |
27 | + | |
28 | + | |
29 | +} | ... | ... |
src/main/java/com/example/mina/box/rmasm/RmasmMessageDecoder.java
0 → 100644
... | ... | @@ -0,0 +1,30 @@ |
1 | +package com.example.mina.box.rmasm; | |
2 | + | |
3 | +import org.apache.mina.core.buffer.IoBuffer; | |
4 | +import org.apache.mina.core.session.IoSession; | |
5 | +import org.apache.mina.filter.codec.ProtocolDecoder; | |
6 | +import org.apache.mina.filter.codec.ProtocolDecoderOutput; | |
7 | + | |
8 | +public class RmasmMessageDecoder implements ProtocolDecoder { | |
9 | + | |
10 | + | |
11 | + public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { | |
12 | + byte[] bytes = new byte[in.limit()]; | |
13 | + in.get(bytes); | |
14 | + String cmd = new String(bytes).trim(); | |
15 | + | |
16 | + | |
17 | + RmasmRequestMessage rmasmRequestMessage = RmasmRequestMessage.builder().cmd(cmd).build(); | |
18 | + out.write(rmasmRequestMessage); | |
19 | + } | |
20 | + | |
21 | + @Override | |
22 | + public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception { | |
23 | + | |
24 | + } | |
25 | + | |
26 | + @Override | |
27 | + public void dispose(IoSession session) throws Exception { | |
28 | + | |
29 | + } | |
30 | +} | ... | ... |
src/main/java/com/example/mina/box/rmasm/RmasmMessageEncoder.java
0 → 100644
... | ... | @@ -0,0 +1,24 @@ |
1 | +package com.example.mina.box.rmasm; | |
2 | + | |
3 | +import com.example.mina.box.lte3000.Lte3000ResponseMessage; | |
4 | +import org.apache.mina.core.buffer.IoBuffer; | |
5 | +import org.apache.mina.core.session.IoSession; | |
6 | +import org.apache.mina.filter.codec.ProtocolEncoder; | |
7 | +import org.apache.mina.filter.codec.ProtocolEncoderOutput; | |
8 | + | |
9 | +public class RmasmMessageEncoder implements ProtocolEncoder { | |
10 | + | |
11 | + @Override | |
12 | + public void encode(IoSession session, Object message, ProtocolEncoderOutput out) { | |
13 | + | |
14 | + if (message instanceof Lte3000ResponseMessage) { | |
15 | + | |
16 | + byte[] result = ((Lte3000ResponseMessage) message).getResult(); | |
17 | + session.write(IoBuffer.wrap(result)); | |
18 | + } | |
19 | + } | |
20 | + | |
21 | + @Override | |
22 | + public void dispose(IoSession session) { | |
23 | + } | |
24 | +} | ... | ... |
src/main/java/com/example/mina/box/rmasm/RmasmRequestMessage.java
0 → 100644
... | ... | @@ -0,0 +1,23 @@ |
1 | +package com.example.mina.box.rmasm; | |
2 | + | |
3 | +import com.example.mina.base.BaseRequestMessage; | |
4 | +import lombok.AllArgsConstructor; | |
5 | +import lombok.Data; | |
6 | +import lombok.EqualsAndHashCode; | |
7 | +import lombok.experimental.SuperBuilder; | |
8 | + | |
9 | +/** | |
10 | + * @author 杜云山 | |
11 | + * @date 21/03/08 | |
12 | + */ | |
13 | +@EqualsAndHashCode(callSuper = true) | |
14 | +@SuperBuilder | |
15 | +@Data | |
16 | +@AllArgsConstructor | |
17 | +public class RmasmRequestMessage extends BaseRequestMessage { | |
18 | + | |
19 | + | |
20 | + | |
21 | + | |
22 | + | |
23 | +} | ... | ... |
src/main/java/com/example/mina/box/rmasm/RmasmResponseMessage.java
0 → 100644
... | ... | @@ -0,0 +1,16 @@ |
1 | +package com.example.mina.box.rmasm; | |
2 | + | |
3 | +import com.example.mina.base.BaseResponseMessage; | |
4 | +import lombok.AllArgsConstructor; | |
5 | +import lombok.Data; | |
6 | +import lombok.EqualsAndHashCode; | |
7 | +import lombok.experimental.SuperBuilder; | |
8 | + | |
9 | + | |
10 | +@EqualsAndHashCode(callSuper = true) | |
11 | +@SuperBuilder | |
12 | +@Data | |
13 | +@AllArgsConstructor | |
14 | +public class RmasmResponseMessage extends BaseResponseMessage { | |
15 | + | |
16 | +} | ... | ... |
src/main/java/com/example/mina/box/rmasm/RmasmVirtualBoxHandler.java
0 → 100644
... | ... | @@ -0,0 +1,111 @@ |
1 | +package com.example.mina.box.rmasm; | |
2 | + | |
3 | +import com.example.mina.base.AbstractVirtualBoxHandler; | |
4 | +import com.example.mina.entity.RmasmDataBuffer; | |
5 | +import com.example.mina.util.RmasmCommandHelper; | |
6 | +import lombok.extern.slf4j.Slf4j; | |
7 | +import org.apache.mina.core.session.IoSession; | |
8 | + | |
9 | +import java.nio.charset.StandardCharsets; | |
10 | +import java.util.Random; | |
11 | + | |
12 | +/** | |
13 | + * @author 杜云山 | |
14 | + * @date 21/03/05 | |
15 | + */ | |
16 | +@Slf4j | |
17 | +public class RmasmVirtualBoxHandler extends AbstractVirtualBoxHandler<RmasmRequestMessage, RmasmResponseMessage> { | |
18 | + | |
19 | + | |
20 | + | |
21 | + private RmasmDataBuffer dataBuffer; | |
22 | + | |
23 | + @Override | |
24 | + protected void initMatrix() { | |
25 | + | |
26 | + } | |
27 | + | |
28 | + @Override | |
29 | + protected RmasmResponseMessage handleMessage(RmasmRequestMessage requestMessage) { | |
30 | + String command = requestMessage.getCmd(); | |
31 | + String[] split = command.replaceAll("\r\n", "").split(" "); | |
32 | + | |
33 | + int maxOutput = dataBuffer.getMaxCol(); | |
34 | + | |
35 | + if (command.startsWith("SA")) { | |
36 | + // Set Attenuator | |
37 | + String index = split[1]; | |
38 | + String atten = split[2]; | |
39 | + int i = Integer.parseInt(index); | |
40 | + int input = RmasmCommandHelper.getInput(i, maxOutput); | |
41 | + int output = RmasmCommandHelper.getOutput(i, maxOutput); | |
42 | + dataBuffer.setAttenuation(input, output, Integer.parseInt(atten)); | |
43 | + int attenuation = dataBuffer.getAttenuation(input, output); | |
44 | + byte[] resultBytes = String.format("A%d:%ddB;\r\n", i, attenuation).getBytes(StandardCharsets.UTF_8); | |
45 | + return RmasmResponseMessage.builder().result(resultBytes).build(); | |
46 | + } | |
47 | + | |
48 | + if (command.startsWith("RA")) { | |
49 | + // Read Attenuator | |
50 | + String index = split[1]; | |
51 | + int startIndex; | |
52 | + int endIndex; | |
53 | + if (index.contains("-")) { | |
54 | + String[] splitIndex = index.split("-"); | |
55 | + startIndex = Integer.parseInt(splitIndex[0]); | |
56 | + endIndex = Integer.parseInt(splitIndex[1]); | |
57 | + } else { | |
58 | + startIndex = Integer.parseInt(index); | |
59 | + endIndex = startIndex; | |
60 | + } | |
61 | + StringBuilder result = new StringBuilder(); | |
62 | + for (int i = startIndex; i <= endIndex; i++) { | |
63 | + int input = RmasmCommandHelper.getInput(i, maxOutput); | |
64 | + int output = RmasmCommandHelper.getOutput(i, maxOutput); | |
65 | + int attenuation = dataBuffer.getAttenuation(input, output); | |
66 | + result.append(String.format("A%d:%ddB;", i, attenuation)); | |
67 | + } | |
68 | + | |
69 | + byte[] resultBytes = result.append("\r\n").toString().getBytes(StandardCharsets.UTF_8); | |
70 | + return RmasmResponseMessage.builder().result(resultBytes).build(); | |
71 | + } | |
72 | + | |
73 | + if (command.startsWith("RP")) { | |
74 | + // Read power meter | |
75 | + String index = split[1]; | |
76 | + | |
77 | + byte[] resultBytes = String.format | |
78 | + ("P%s:%.2f;\r\n", index, new Random().nextInt(99) + new Random().nextFloat() - 50) | |
79 | + .getBytes(StandardCharsets.UTF_8); | |
80 | + return RmasmResponseMessage.builder().result(resultBytes).build(); | |
81 | + } | |
82 | + byte[] resultBytes = new byte[0]; | |
83 | + return RmasmResponseMessage.builder().result(resultBytes).build(); | |
84 | + } | |
85 | + | |
86 | + | |
87 | + @Override | |
88 | + public void sessionCreated(IoSession session) { | |
89 | + | |
90 | + log.info("--- abstractVirtual server session created"); | |
91 | + } | |
92 | + | |
93 | + @Override | |
94 | + public void sessionOpened(IoSession session) { | |
95 | + | |
96 | + log.info("--- abstractVirtual server session Opened"); | |
97 | + } | |
98 | + | |
99 | + @Override | |
100 | + public void sessionClosed(IoSession session) { | |
101 | + | |
102 | + log.info("--- abstractVirtual server session Closed"); | |
103 | + } | |
104 | + | |
105 | + @Override | |
106 | + public void messageSent(IoSession session, Object message) { | |
107 | + | |
108 | + log.info("--- abstractVirtual 发送数据成功!{}", message); | |
109 | + } | |
110 | + | |
111 | +} | ... | ... |
src/main/java/com/example/mina/box/rmasm/RmasmVirtualBoxServer.java
0 → 100644
... | ... | @@ -0,0 +1,18 @@ |
1 | +package com.example.mina.box.rmasm; | |
2 | + | |
3 | +import com.example.mina.base.AbstractVirtualBoxServer; | |
4 | + | |
5 | +import com.example.mina.property.RmasmVirtualBoxProperties; | |
6 | +import lombok.extern.slf4j.Slf4j; | |
7 | +import org.springframework.context.annotation.Configuration; | |
8 | + | |
9 | + | |
10 | +@Slf4j | |
11 | +@Configuration(proxyBeanMethods = false) | |
12 | +public class RmasmVirtualBoxServer extends AbstractVirtualBoxServer { | |
13 | + | |
14 | + public RmasmVirtualBoxServer(RmasmVirtualBoxProperties rmasmVirtualBoxProperties) { | |
15 | + super(rmasmVirtualBoxProperties, new RmasmVirtualBoxHandler(),new RmasmCodecFactory()); | |
16 | + } | |
17 | + | |
18 | +} | ... | ... |
src/main/java/com/example/mina/entity/HardwareAssign.java
0 → 100644
... | ... | @@ -0,0 +1,244 @@ |
1 | +package com.example.mina.entity; | |
2 | + | |
3 | +import java.util.*; | |
4 | + | |
5 | +public class HardwareAssign { | |
6 | + | |
7 | +// private int userId;// all to this user | |
8 | + | |
9 | + private Map<Integer, Integer> outputUserMap;//<output,user> | |
10 | + private Map<Integer, List<Integer>> userInputListMap;//<user, input list> | |
11 | + | |
12 | + | |
13 | + public HardwareAssign() { | |
14 | + outputUserMap = new HashMap<>(); | |
15 | + userInputListMap = new HashMap<>(); | |
16 | + } | |
17 | + | |
18 | + | |
19 | + //-------------------- input ----------------------- | |
20 | + public int getRealInputByUser(int userId, int order) { | |
21 | + if(order < 1){ | |
22 | + return 0; | |
23 | + } | |
24 | + | |
25 | + List<Integer> idList = this.getAssignedInputListByUser(userId); | |
26 | + Collections.sort(idList); | |
27 | + if (order > idList.size()) { | |
28 | + return 0; | |
29 | + } | |
30 | + | |
31 | + return idList.get(order - 1); | |
32 | + } | |
33 | + | |
34 | + | |
35 | + public List<Integer> getAssignedInputListByUser(int userId) { | |
36 | + return userInputListMap.getOrDefault(userId, new ArrayList<>()); | |
37 | + } | |
38 | + | |
39 | + | |
40 | + | |
41 | + public void freeInputToUser(int inputPort, int userId) { | |
42 | + List<Integer> idList = userInputListMap.get(userId); | |
43 | + if (idList != null) { | |
44 | + idList.remove(Integer.valueOf(inputPort)); | |
45 | + } | |
46 | + } | |
47 | + | |
48 | + public void assignInputToUser(int inputPort, int userId) { | |
49 | + | |
50 | + List<Integer> idList = userInputListMap.computeIfAbsent(userId, k -> new ArrayList<>()); | |
51 | + | |
52 | + idList.add(inputPort); | |
53 | + } | |
54 | + | |
55 | + | |
56 | + public boolean isAssignedInputToUser(int inputPort, int userId) { | |
57 | + List<Integer> idList = userInputListMap.get(userId); | |
58 | + if (idList == null) { | |
59 | + return false; | |
60 | + } | |
61 | + | |
62 | + return idList.contains(inputPort); | |
63 | + | |
64 | + } | |
65 | + //-------------------- input ------- End ---------------- | |
66 | + | |
67 | + | |
68 | + | |
69 | + | |
70 | + | |
71 | + //-------------------- output ----------------------- | |
72 | + public int getRealOutputByUser(int userId, int order) { | |
73 | + if(order < 1){ | |
74 | + return 0; | |
75 | + } | |
76 | + | |
77 | + List<Integer> idList = this.getAssignedOutputListByUser(userId); | |
78 | + Collections.sort(idList); | |
79 | + if (order > idList.size()) { | |
80 | + return 0; | |
81 | + } | |
82 | + | |
83 | + return idList.get(order - 1); | |
84 | + } | |
85 | + | |
86 | + | |
87 | + public List<Integer> getAssignedOutputListByUser(int userId) { | |
88 | + List<Integer> idList = new ArrayList<>(); | |
89 | + | |
90 | + for(int id : outputUserMap.keySet()){ | |
91 | + int uid = outputUserMap.get(id); | |
92 | + if (uid == userId) { | |
93 | + idList.add(id); | |
94 | + } | |
95 | + } | |
96 | + | |
97 | + return idList; | |
98 | + } | |
99 | + | |
100 | + public List<Integer> getOutputAssignedUserList() { | |
101 | + List<Integer> idList = new ArrayList<>(); | |
102 | + | |
103 | + for (int id : outputUserMap.values()) { | |
104 | + boolean find = false; | |
105 | + | |
106 | + for (int uid : idList) { | |
107 | + if (id == uid) { | |
108 | + find = true; | |
109 | + break; | |
110 | + } | |
111 | + } | |
112 | + | |
113 | + if (!find) { | |
114 | + idList.add(id); | |
115 | + } | |
116 | + } | |
117 | + | |
118 | + return idList; | |
119 | + } | |
120 | + | |
121 | + | |
122 | + public int checkOutputAssigned(int outputPort) { | |
123 | + Integer id = outputUserMap.get(outputPort); | |
124 | + | |
125 | + return id == null ? 0 : id; | |
126 | + } | |
127 | + | |
128 | + public void freeAssignOutput(int outputPort, int fromUserId) { | |
129 | + Integer id = outputUserMap.get(outputPort); | |
130 | + if (id != null) { | |
131 | + if (id == fromUserId) { | |
132 | + outputUserMap.remove(outputPort); | |
133 | + } | |
134 | + } | |
135 | + } | |
136 | + | |
137 | + | |
138 | + public void assignOutputToUser(String colsStr, int toUserId) { | |
139 | + | |
140 | + if ((colsStr!=null) && !colsStr.isEmpty() && !colsStr.startsWith("null")) { | |
141 | + String[] tokens = colsStr.split(","); | |
142 | + for (String t : tokens) { | |
143 | + int port = Integer.valueOf(t); | |
144 | + if (port > 0) { | |
145 | + outputUserMap.put(port, toUserId); | |
146 | + } | |
147 | + } | |
148 | + } | |
149 | + } | |
150 | + | |
151 | + public void reAssignOutput(int outputPort, int fromUserId, int toUserId) { | |
152 | + if (outputPort > 0 && fromUserId > 0 && toUserId > 0) { | |
153 | + outputUserMap.put(outputPort, toUserId); | |
154 | + } | |
155 | + } | |
156 | + | |
157 | + | |
158 | + | |
159 | + | |
160 | + public boolean isAllAssignedToUser(int userId, int maxInput, int maxOutput) { | |
161 | + | |
162 | + Integer id; | |
163 | + | |
164 | + for (int i = 1; i <= maxOutput; i++) { | |
165 | + id = outputUserMap.get(i); | |
166 | + if (id == null || id != userId) { | |
167 | + return false; | |
168 | + } | |
169 | + } | |
170 | + | |
171 | + List<Integer> inList = userInputListMap.get(userId); | |
172 | + if(inList == null){ | |
173 | + for (int i = 1; i <= maxInput; i++) { | |
174 | + if(!inList.contains(i)){ | |
175 | + return false; | |
176 | + } | |
177 | + } | |
178 | + } | |
179 | + | |
180 | + return true; | |
181 | + } | |
182 | + | |
183 | + public void removeAllAssignToUser(int userId) { | |
184 | + List<Integer> removeList = new ArrayList<>(); | |
185 | + | |
186 | + for (int key : outputUserMap.keySet()) { | |
187 | + if (outputUserMap.get(key) == userId) { | |
188 | + removeList.add(key); | |
189 | + } | |
190 | + } | |
191 | + | |
192 | + for (int key : removeList) { | |
193 | + outputUserMap.remove(key); | |
194 | + } | |
195 | + | |
196 | + | |
197 | + if (userInputListMap.containsKey(userId)) { | |
198 | + userInputListMap.remove(userId); | |
199 | + } | |
200 | + | |
201 | + | |
202 | + } | |
203 | + | |
204 | + public void assignAllToUser(int userId, int maxInput, int maxOutput) { | |
205 | + | |
206 | + outputUserMap = new HashMap<>(); | |
207 | + userInputListMap = new HashMap<>(); | |
208 | + | |
209 | + | |
210 | + for (int i = 1; i <= maxOutput; i++) { | |
211 | + outputUserMap.put(i, userId); | |
212 | + } | |
213 | + | |
214 | + | |
215 | + List<Integer> inputList = new ArrayList<>(); | |
216 | + for (int i = 1; i <= maxInput; i++) { | |
217 | + inputList.add(i); | |
218 | + } | |
219 | + userInputListMap.put(userId, inputList); | |
220 | + | |
221 | + } | |
222 | + | |
223 | + //-------------------- output ------- End ---------------- | |
224 | + | |
225 | + | |
226 | + public Map<Integer, Integer> getOutputUserMap() { | |
227 | + if (outputUserMap == null) { | |
228 | + outputUserMap = new HashMap<>(); | |
229 | + } | |
230 | + return outputUserMap; | |
231 | + } | |
232 | + | |
233 | + public void setOutputUserMap(Map<Integer, Integer> outputUserMap) { | |
234 | + this.outputUserMap = outputUserMap; | |
235 | + } | |
236 | + | |
237 | + public Map<Integer, List<Integer>> getUserInputListMap() { | |
238 | + return userInputListMap; | |
239 | + } | |
240 | + | |
241 | + public void setUserInputListMap(Map<Integer, List<Integer>> userInputListMap) { | |
242 | + this.userInputListMap = userInputListMap; | |
243 | + } | |
244 | +} | ... | ... |
src/main/java/com/example/mina/entity/RmasmDataBuffer.java
0 → 100644
... | ... | @@ -0,0 +1,36 @@ |
1 | +package com.example.mina.entity; | |
2 | + | |
3 | +import com.example.mina.base.AbstractHardwareDataBuffer; | |
4 | + | |
5 | + | |
6 | +public class RmasmDataBuffer extends AbstractHardwareDataBuffer { | |
7 | + | |
8 | + public RmasmDataBuffer(int row, int col, int maxAtten) { | |
9 | + super(row, col, row, maxAtten); | |
10 | + | |
11 | + matrixData = new Entry[row][col]; | |
12 | + offsetData = new Entry[row]; | |
13 | + | |
14 | + int offset = -79; | |
15 | + int val; | |
16 | + int ox; | |
17 | + for (int i = 0; i < row; i++) { | |
18 | + val = Math.abs(offset); | |
19 | + ox = (val / 10) * 16 + (val % 10); | |
20 | + | |
21 | + if (offset < 0) { | |
22 | + ox += 0x80; | |
23 | + } | |
24 | + | |
25 | + offsetData[i] = new Entry(i, 0, "rr", ox, false); | |
26 | + offset += 5; | |
27 | + } | |
28 | + | |
29 | + for (int i = 0; i < row; i++) { | |
30 | + for (int k = 0; k < col; k++) { | |
31 | + matrixData[i][k] = new Entry(i, k, "kk", maxAtten, false); | |
32 | + } | |
33 | + } | |
34 | + } | |
35 | + | |
36 | +} | ... | ... |
src/main/java/com/example/mina/property/RmasmVirtualBoxProperties.java
0 → 100644
... | ... | @@ -0,0 +1,19 @@ |
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 | +@Getter | |
12 | +@Setter | |
13 | +@ToString | |
14 | +@ConfigurationProperties(prefix = "rmasm-virtual") | |
15 | +@Configuration | |
16 | +@EnableConfigurationProperties(RmasmVirtualBoxProperties.class) | |
17 | +public class RmasmVirtualBoxProperties extends AbstractVirtualBoxProperties { | |
18 | + | |
19 | +} | |
0 | 20 | \ No newline at end of file | ... | ... |
src/main/java/com/example/mina/util/RmasmCommandHelper.java
0 → 100644
... | ... | @@ -0,0 +1,35 @@ |
1 | +package com.example.mina.util; | |
2 | + | |
3 | +import java.nio.charset.StandardCharsets; | |
4 | + | |
5 | +public class RmasmCommandHelper { | |
6 | + /*public static byte[] genReadAllAttenuation(HardwareConfig hardwareConfig) { | |
7 | + int maxInput = hardwareConfig.getInputNumber(); | |
8 | + int maxOutput = hardwareConfig.getOutputNumber(); | |
9 | + int maxIndex = getIndex(maxInput, maxOutput, maxOutput); | |
10 | + return String.format("RA 1-%d\r\n", maxIndex).getBytes(StandardCharsets.UTF_8); | |
11 | + } | |
12 | + | |
13 | + public static byte[] genSetAttenuation(int input, int output, int atten, HardwareConfig hardwareConfig) { | |
14 | + int index = getIndex(input, output, hardwareConfig.getOutputNumber()); | |
15 | + String command = String.format("SA %d %d\r\n", index, atten); | |
16 | + return command.getBytes(StandardCharsets.UTF_8); | |
17 | + }*/ | |
18 | + | |
19 | + public static byte[] genReadPowermeter(int index) { | |
20 | + String command = String.format("RP %d\r\n", index); | |
21 | + return command.getBytes(StandardCharsets.UTF_8); | |
22 | + } | |
23 | + | |
24 | + public static int getInput(int index, int maxOutput) { | |
25 | + return ((index - 1) / maxOutput) + 1; | |
26 | + } | |
27 | + | |
28 | + public static int getOutput(int index, int maxOutput) { | |
29 | + return ((index - 1) % maxOutput) + 1; | |
30 | + } | |
31 | + | |
32 | + public static int getIndex(int input, int output, int maxOutput) { | |
33 | + return (input - 1) * maxOutput + output; | |
34 | + } | |
35 | +} | ... | ... |