From e3df6564fb04e329899e1ced2b096fd6ed4f818a Mon Sep 17 00:00:00 2001 From: huanglang <1037084308@qq.com> Date: Wed, 31 Mar 2021 19:43:45 +0800 Subject: [PATCH] 1、POM文件修改;2、QRB类型虚拟设备CS端第一版联调基本完成。 --- pom.xml | 6 ++++++ src/main/java/com/example/mina/Application.java | 42 ++++++++++++++++++++++++++++++++++++++++-- src/main/java/com/example/mina/client/base/AbstractMatrixIoHandler.java | 6 +++--- src/main/java/com/example/mina/client/base/MatrixClient.java | 11 +++++++++-- src/main/java/com/example/mina/client/base/MatrixCommand.java | 19 ++++++++++++++++++- src/main/java/com/example/mina/client/base/MatrixConstants.java | 2 ++ src/main/java/com/example/mina/client/base/MatrixResponse.java | 22 ++++++++++++++++++++++ src/main/java/com/example/mina/client/box/aeroflex/AeroflexClientIoHandler.java | 5 +++-- src/main/java/com/example/mina/client/box/lte3000/Lte3000ClientIoHandler.java | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------- src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ClientFactory.java | 22 ++++++++++++++++++++++ src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ClientIoHandler.java | 38 ++++++++++++++++++++++++++++++++++++++ src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ProtocolFactory.java | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/example/mina/client/box/rec6000/REC6000ClientIoHandler.java | 5 +++-- src/main/java/com/example/mina/server/box/qrb3000/Qrb3000VirtualBoxHandler.java | 5 +++-- 14 files changed, 379 insertions(+), 93 deletions(-) create mode 100644 src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ClientFactory.java create mode 100644 src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ClientIoHandler.java create mode 100644 src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ProtocolFactory.java diff --git a/pom.xml b/pom.xml index 8679a6a..f398a89 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,12 @@ org.apache.mina mina-http 2.1.4 + + + mina-core + org.apache.mina + + diff --git a/src/main/java/com/example/mina/Application.java b/src/main/java/com/example/mina/Application.java index fba4ea6..9667b32 100644 --- a/src/main/java/com/example/mina/Application.java +++ b/src/main/java/com/example/mina/Application.java @@ -17,7 +17,7 @@ public class Application { public static void main(String[] args) { // SpringApplication.run(Application.class, args); - ConfigurableApplicationContext run = SpringApplication.run(Application.class, args); + /*ConfigurableApplicationContext run = SpringApplication.run(Application.class, args); ClientManager clientManager = run.getBean(ClientManager.class); @@ -48,7 +48,45 @@ public class Application { MatrixClient REC3000Client = clientManager.getOrCreateClient(REC3000); - REC3000Client.setAttenuation(1, 2, 3, null); + REC3000Client.setAttenuation(1, 2, 3, null);*/ + + ConfigurableApplicationContext run = SpringApplication.run(Application.class, args); + + ClientManager clientManager = run.getBean(ClientManager.class); + + MatrixConnectConfig connectConfig = MatrixConnectConfig.builder() + .deviceId("15") + .deviceType(MatrixConstants.MATRIX_TYPE_QRB) + .host("127.0.0.1") + .port(9103) + .build(); + + MatrixClient client = clientManager.getOrCreateClient(connectConfig); + + +// client.setAttenuation(1,2,3, null); +// LockSupport.parkNanos(1000_000_000); + +// client.setOffset(1, 2); + client.getOffset(2); + LockSupport.parkNanos(1000_000_000); + +// client.setOffset(1,2); +// LockSupport.parkNanos(1000_000_000); + + +// client.setAttenuation(1,2,3, MatrixCommand.Type.AERO_GET_ATTN); + +// MatrixConnectConfig REC3000 = MatrixConnectConfig.builder() +// .deviceId("158") +// .deviceType(MatrixConstants.MATRIX_TYPE_QRB) +// .host("127.0.0.1") +// .port(9099) +// .build(); +// +// MatrixClient REC3000Client = clientManager.getOrCreateClient(REC3000); +// +// REC3000Client.setAttenuation(1, 2, 3, null); } diff --git a/src/main/java/com/example/mina/client/base/AbstractMatrixIoHandler.java b/src/main/java/com/example/mina/client/base/AbstractMatrixIoHandler.java index c371a15..732b628 100644 --- a/src/main/java/com/example/mina/client/base/AbstractMatrixIoHandler.java +++ b/src/main/java/com/example/mina/client/base/AbstractMatrixIoHandler.java @@ -36,13 +36,13 @@ public abstract class AbstractMatrixIoHandler extends IoHandlerAdapter { @Override public void messageReceived(IoSession session, Object message) { - if (!(message instanceof IoBuffer)) { + if (!(message instanceof MatrixResponse)) { log.error("客户端接收到的消息不为定义的响应类! message:" + message); throw new RuntimeException("Unsupported response message"); } //TODO 客户端将数据服务器的字符串数组读取出来 - byte[] response = null; + MatrixResponse response = (MatrixResponse) message; log.info("the client recieved the device response, device:{}, response is: {}", getConnectConfig(session), response); handleCommandResponse(response); @@ -76,5 +76,5 @@ public abstract class AbstractMatrixIoHandler extends IoHandlerAdapter { log.info("the system has connected to device, device is {}", getConnectConfig(session)); } - abstract public boolean handleCommandResponse(byte[] response); + abstract public boolean handleCommandResponse(MatrixResponse response); } diff --git a/src/main/java/com/example/mina/client/base/MatrixClient.java b/src/main/java/com/example/mina/client/base/MatrixClient.java index 8474c53..7a63b1a 100644 --- a/src/main/java/com/example/mina/client/base/MatrixClient.java +++ b/src/main/java/com/example/mina/client/base/MatrixClient.java @@ -128,9 +128,16 @@ public class MatrixClient { sendCommand(command); } - public void setOffset(int row, int offset) { + public void setOffset(int col, int offset) { MatrixCommand command = MatrixCommand.builder().command(MatrixConstants.COMMAND_SET_OFFSET) - .row(row).offset(offset).build(); + .col(col).offset(offset).build(); + + sendCommand(command); + } + + public void getOffset(int col) { + MatrixCommand command = MatrixCommand.builder().command(MatrixConstants.COMMAND_GET_OFFSET) + .col(col).build(); sendCommand(command); } diff --git a/src/main/java/com/example/mina/client/base/MatrixCommand.java b/src/main/java/com/example/mina/client/base/MatrixCommand.java index 1039510..415a5b4 100644 --- a/src/main/java/com/example/mina/client/base/MatrixCommand.java +++ b/src/main/java/com/example/mina/client/base/MatrixCommand.java @@ -6,17 +6,34 @@ import lombok.Data; @Data @Builder public class MatrixCommand { - + /** + * 矩阵id + */ private String matrixId; + /** + * 指令类型,来自MatrixConstants + */ private Integer command; + /** + * 矩阵行坐标 + */ private Integer row; + /** + * 矩阵列坐标 + */ private Integer col; + /** + * 矩阵指定行列位置的值,如衰减值 + */ private Integer attn; + /** + * 相位值,偏移量 + */ private Integer offset; private Type type; diff --git a/src/main/java/com/example/mina/client/base/MatrixConstants.java b/src/main/java/com/example/mina/client/base/MatrixConstants.java index dd6adfc..687c0e3 100644 --- a/src/main/java/com/example/mina/client/base/MatrixConstants.java +++ b/src/main/java/com/example/mina/client/base/MatrixConstants.java @@ -10,6 +10,8 @@ public class MatrixConstants { public static final String MATRIX_TYPE_REC3000 = "REC3000"; + public static final String MATRIX_TYPE_QRB = "QRB3000"; + public static final int COMMAND_RESET = 1; public static final int COMMAND_SET_ATTN = 2; diff --git a/src/main/java/com/example/mina/client/base/MatrixResponse.java b/src/main/java/com/example/mina/client/base/MatrixResponse.java index b7aef8c..1b42253 100644 --- a/src/main/java/com/example/mina/client/base/MatrixResponse.java +++ b/src/main/java/com/example/mina/client/base/MatrixResponse.java @@ -1,4 +1,26 @@ package com.example.mina.client.base; +import lombok.Data; + +@Data public class MatrixResponse { + private Integer row; + + private Integer col; + + private Boolean isSetOffset; + + private Integer offset; + + private Boolean isSetAttn; + + private Integer attn; + + public MatrixResponse() { + isSetAttn = false; + isSetOffset = false; + + offset = -1; + attn = -1; + } } diff --git a/src/main/java/com/example/mina/client/box/aeroflex/AeroflexClientIoHandler.java b/src/main/java/com/example/mina/client/box/aeroflex/AeroflexClientIoHandler.java index 7b538fc..e28ff58 100644 --- a/src/main/java/com/example/mina/client/box/aeroflex/AeroflexClientIoHandler.java +++ b/src/main/java/com/example/mina/client/box/aeroflex/AeroflexClientIoHandler.java @@ -2,6 +2,7 @@ package com.example.mina.client.box.aeroflex; import com.example.mina.client.base.AbstractMatrixIoHandler; import com.example.mina.client.base.MatrixDataProxy; +import com.example.mina.client.base.MatrixResponse; import lombok.extern.slf4j.Slf4j; import org.apache.mina.core.session.IoSession; @@ -22,8 +23,8 @@ public class AeroflexClientIoHandler extends AbstractMatrixIoHandler { @Override - public boolean handleCommandResponse(byte[] response) { - log.info("------AeroflexClientIoHandler-----{}",response); + public boolean handleCommandResponse(MatrixResponse matrixResponse) { + log.info("------AeroflexClientIoHandler-----{}",matrixResponse); return false; } diff --git a/src/main/java/com/example/mina/client/box/lte3000/Lte3000ClientIoHandler.java b/src/main/java/com/example/mina/client/box/lte3000/Lte3000ClientIoHandler.java index 61a7a5e..ade7108 100644 --- a/src/main/java/com/example/mina/client/box/lte3000/Lte3000ClientIoHandler.java +++ b/src/main/java/com/example/mina/client/box/lte3000/Lte3000ClientIoHandler.java @@ -2,6 +2,7 @@ package com.example.mina.client.box.lte3000; import com.example.mina.client.base.AbstractMatrixIoHandler; import com.example.mina.client.base.MatrixDataProxy; +import com.example.mina.client.base.MatrixResponse; import com.example.mina.server.util.Lte3000CommandHelper; import lombok.extern.slf4j.Slf4j; @@ -21,85 +22,85 @@ public class Lte3000ClientIoHandler extends AbstractMatrixIoHandler { } @Override - public boolean handleCommandResponse(byte[] response) { - int responseLen = response.length; - if (response[0] != Lte3000CommandHelper.ACK || responseLen < 6) { - return false; - } - //api document: "SRM - MRF - MRM - XRM - QRM - LTE Protocol v2.15 Rev FR.pdf" - - //O:Query Output Channel P.106 - //0x4F - if (responseLen == 9 && isSameValue(response[3], 0x4F)) { // 'O' -// 0x6 0x46 0x46 0x4F 0x30 0x32 0x38 0x3 0x70 - int col = Lte3000CommandHelper.getBcdPort(response[4], response[5], response[6]); - int row = Lte3000CommandHelper.getBcdPort(response[4], response[5], response[6]); - // limits only one set "ON" in a column, others should be OFF -// for (int i = 1; i <= responsePool.getMaxRow(); i++) { -// if (i == row) { -// responsePool.setAttenuation(i, col, 1); -// } else { -// responsePool.setAttenuation(i, col, 0); -// } -// } TODO 再次调用MatrixDataProxy的方法来设置衰减值 - log.info("RESPONSE Ox4F. ROW = {}, COL = {}", row, col); - return true; - } - - //S: Set CrossPoint P.115 - //0x53 - if (responseLen == 6 && isSameValue(response[3], 0x53)) { - int col = Lte3000CommandHelper.getBcdPort(response[4], response[5], response[6]); - int row = Lte3000CommandHelper.getBcdPort(response[7], response[8], response[9]); - // limits only one set "ON" in a column, others should be OFF -// for (int i = 1; i <= responsePool.getMaxRow(); i++) { -// if (i == row) { -// responsePool.setAttenuation(i, col, 1); -// } else { -// responsePool.setAttenuation(i, col, 0); -// } -// } TODO 再次调用MatrixDataProxy的方法来设置衰减值 - log.info("RESPONSE Ox53. ROW = {}, COL = {}", row, col); - return true; - } - - //XGMO: Set Gain Control to Manual Mode - Output p.137 - //0x58 0x47 0x4D 0x4F - if (responseLen == 9 && response[3] == 'X' && response[4] == 'G' && response[5] == 'M' && response[6] == 'O') { -// receive - 0x2 0x30 0x30 0x58 0x47 0x4D 0x4F 0x30 0x30 0x31 0x40 0x2D 0x36 0x33 0x2E 0x30 0x3 0x5B -// 00XGMO001@-63.0[ -// set col/attn 1/63 - - int col = Lte3000CommandHelper.getBcdPort(response[7], response[8], response[9]); - int attn = Lte3000CommandHelper.getBcdAttn(response[11], response[12], response[13], response[14], response[15]); - //responsePool.setOffset(col, attn); TODO 再次调用MatrixDataProxy的方法来设置衰减值 - log.info("RESPONSE XGMO. ATTN = {}, COL = {}", attn, col); - return true; - } - - - //XGRO: Gain Control Read Status - Output P.139 - if (responseLen == 16 && response[3] == 'X' && response[4] == 'G' && response[5] == 'R' && response[6] == 'O') { - /* - Example Command: - 02 XX XX 58 46 52 4F 30 31 36 03 XX - STX ADR ADR X G R O O 1 6 ETX CHK - (Read attenuation control status of system output 16) - */ - /* - Example Response: - 06 XX XX 58 46 52 4F 4D 40 2D 31 33 2E 35 03 XX - ACK ADR ADR X G R O M @ - 1 3 . 5 ETX CHX - (Output set at -13.5 dB of attenuation in manual mode. ) - */ - int col = Lte3000CommandHelper.getBcdPort(response[7], response[8], response[9]); - int attn = Lte3000CommandHelper.getBcdAttn(response[9], response[10], response[11], response[12], response[13]); - //responsePool.setOffset(col, attn); TODO 再次调用MatrixDataProxy的方法来设置衰减值 - log.info("RESPONSE XGRO. ATTN = {}, COL = {}", attn, col); - return true; - } - - log.info("收到服务器回传的消息了"); + public boolean handleCommandResponse(MatrixResponse matrixResponse) { +// int responseLen = response.length; +// if (response[0] != Lte3000CommandHelper.ACK || responseLen < 6) { +// return false; +// } +// //api document: "SRM - MRF - MRM - XRM - QRM - LTE Protocol v2.15 Rev FR.pdf" +// +// //O:Query Output Channel P.106 +// //0x4F +// if (responseLen == 9 && isSameValue(response[3], 0x4F)) { // 'O' +//// 0x6 0x46 0x46 0x4F 0x30 0x32 0x38 0x3 0x70 +// int col = Lte3000CommandHelper.getBcdPort(response[4], response[5], response[6]); +// int row = Lte3000CommandHelper.getBcdPort(response[4], response[5], response[6]); +// // limits only one set "ON" in a column, others should be OFF +//// for (int i = 1; i <= responsePool.getMaxRow(); i++) { +//// if (i == row) { +//// responsePool.setAttenuation(i, col, 1); +//// } else { +//// responsePool.setAttenuation(i, col, 0); +//// } +//// } TODO 再次调用MatrixDataProxy的方法来设置衰减值 +// log.info("RESPONSE Ox4F. ROW = {}, COL = {}", row, col); +// return true; +// } +// +// //S: Set CrossPoint P.115 +// //0x53 +// if (responseLen == 6 && isSameValue(response[3], 0x53)) { +// int col = Lte3000CommandHelper.getBcdPort(response[4], response[5], response[6]); +// int row = Lte3000CommandHelper.getBcdPort(response[7], response[8], response[9]); +// // limits only one set "ON" in a column, others should be OFF +//// for (int i = 1; i <= responsePool.getMaxRow(); i++) { +//// if (i == row) { +//// responsePool.setAttenuation(i, col, 1); +//// } else { +//// responsePool.setAttenuation(i, col, 0); +//// } +//// } TODO 再次调用MatrixDataProxy的方法来设置衰减值 +// log.info("RESPONSE Ox53. ROW = {}, COL = {}", row, col); +// return true; +// } +// +// //XGMO: Set Gain Control to Manual Mode - Output p.137 +// //0x58 0x47 0x4D 0x4F +// if (responseLen == 9 && response[3] == 'X' && response[4] == 'G' && response[5] == 'M' && response[6] == 'O') { +//// receive - 0x2 0x30 0x30 0x58 0x47 0x4D 0x4F 0x30 0x30 0x31 0x40 0x2D 0x36 0x33 0x2E 0x30 0x3 0x5B +//// 00XGMO001@-63.0[ +//// set col/attn 1/63 +// +// int col = Lte3000CommandHelper.getBcdPort(response[7], response[8], response[9]); +// int attn = Lte3000CommandHelper.getBcdAttn(response[11], response[12], response[13], response[14], response[15]); +// //responsePool.setOffset(col, attn); TODO 再次调用MatrixDataProxy的方法来设置衰减值 +// log.info("RESPONSE XGMO. ATTN = {}, COL = {}", attn, col); +// return true; +// } +// +// +// //XGRO: Gain Control Read Status - Output P.139 +// if (responseLen == 16 && response[3] == 'X' && response[4] == 'G' && response[5] == 'R' && response[6] == 'O') { +// /* +// Example Command: +// 02 XX XX 58 46 52 4F 30 31 36 03 XX +// STX ADR ADR X G R O O 1 6 ETX CHK +// (Read attenuation control status of system output 16) +// */ +// /* +// Example Response: +// 06 XX XX 58 46 52 4F 4D 40 2D 31 33 2E 35 03 XX +// ACK ADR ADR X G R O M @ - 1 3 . 5 ETX CHX +// (Output set at -13.5 dB of attenuation in manual mode. ) +// */ +// int col = Lte3000CommandHelper.getBcdPort(response[7], response[8], response[9]); +// int attn = Lte3000CommandHelper.getBcdAttn(response[9], response[10], response[11], response[12], response[13]); +// //responsePool.setOffset(col, attn); TODO 再次调用MatrixDataProxy的方法来设置衰减值 +// log.info("RESPONSE XGRO. ATTN = {}, COL = {}", attn, col); +// return true; +// } +// +// log.info("收到服务器回传的消息了"); return false; } } diff --git a/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ClientFactory.java b/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ClientFactory.java new file mode 100644 index 0000000..5f33d5d --- /dev/null +++ b/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ClientFactory.java @@ -0,0 +1,22 @@ +package com.example.mina.client.box.qrb3000; + +import com.example.mina.client.base.AbstractClientFactory; +import com.example.mina.client.base.MatrixConstants; +import org.apache.mina.core.filterchain.IoFilterChain; +import org.apache.mina.filter.codec.ProtocolCodecFilter; +import org.springframework.stereotype.Component; + +@Component(MatrixConstants.MATRIX_TYPE_QRB) +public class Qrb3000ClientFactory extends AbstractClientFactory { + + @Override + public Qrb3000ClientIoHandler getClientHandler() { + System.out.println("=============getClientHandler=================="); + return new Qrb3000ClientIoHandler(); + } + + @Override + public void buildFilterChain(IoFilterChain ioFilterChain) { + ioFilterChain.addLast("codec", new ProtocolCodecFilter(new Qrb3000ProtocolFactory())); + } +} diff --git a/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ClientIoHandler.java b/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ClientIoHandler.java new file mode 100644 index 0000000..9ad07ef --- /dev/null +++ b/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ClientIoHandler.java @@ -0,0 +1,38 @@ +package com.example.mina.client.box.qrb3000; + +import com.example.mina.client.base.AbstractMatrixIoHandler; +import com.example.mina.client.base.MatrixDataProxy; +import com.example.mina.client.base.MatrixResponse; +import lombok.extern.slf4j.Slf4j; +import org.apache.mina.core.session.IoSession; + +/** + * @author hl + * @date 2021/3/10 + */ +@Slf4j +public class Qrb3000ClientIoHandler extends AbstractMatrixIoHandler { + + //public AeroflexClientIoHandler(MatrixDataProxy matrixDataProxy) { + // super(matrixDataProxy); + // } + + public Qrb3000ClientIoHandler() { + super(new MatrixDataProxy()); + } + + + @Override + public boolean handleCommandResponse(MatrixResponse matrixResponse) { + log.info("------Qrb3000ClientIoHandler-----{}",matrixResponse); + return false; + } + + @Override + public void sessionCreated(IoSession session) { + System.out.println("=========111========"); + } + + + +} diff --git a/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ProtocolFactory.java b/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ProtocolFactory.java new file mode 100644 index 0000000..7216584 --- /dev/null +++ b/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ProtocolFactory.java @@ -0,0 +1,130 @@ +package com.example.mina.client.box.qrb3000; + +import com.example.mina.client.base.MatrixCommand; +import com.example.mina.client.base.MatrixConstants; +import com.example.mina.client.base.MatrixResponse; +import com.example.mina.server.util.CommandHelper; +import lombok.extern.slf4j.Slf4j; +import org.apache.mina.core.buffer.IoBuffer; +import org.apache.mina.core.session.IoSession; +import org.apache.mina.filter.codec.*; + +import java.nio.charset.CharacterCodingException; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; +import java.nio.charset.StandardCharsets; + +@Slf4j +public class Qrb3000ProtocolFactory implements ProtocolCodecFactory { + + private static final CharsetDecoder DECODER = StandardCharsets.UTF_8.newDecoder(); + + private static final CharsetEncoder ENCODER = StandardCharsets.UTF_8.newEncoder(); + + @Override + public ProtocolEncoder getEncoder(IoSession ioSession) throws Exception { + return new Qrb3000ProtocolEncoder(); + } + + @Override + public ProtocolDecoder getDecoder(IoSession ioSession) throws Exception { + return new Qrb3000ProtocolDecoder(); + } + + public static class Qrb3000ProtocolEncoder extends ProtocolEncoderAdapter { + + @Override + public void encode(IoSession ioSession, Object msg, ProtocolEncoderOutput protocolEncoderOutput) + throws CharacterCodingException { + + if (!(msg instanceof MatrixCommand)) { + log.error("error msg, msg is: {}", msg); + return; + } + + MatrixCommand mc = (MatrixCommand) msg; + log.info("---发送数据参数!Attn = {},Col = {},Command = {},Row = {},MatrixId = {},type = {}", + mc.getAttn(), + mc.getCol(), + mc.getCommand(), + mc.getRow(), + mc.getMatrixId(), + mc.getType() + ); + int cmd = mc.getCommand(); + + IoBuffer buffer = IoBuffer.allocate(100, false).setAutoExpand(true); + + if (cmd == MatrixConstants.COMMAND_SET_ATTN) { + buffer.put((byte)0x30); + buffer.put((byte)0xFE); + buffer.put((byte)0xFE); + buffer.put(mc.getRow().byteValue()); + buffer.put(mc.getCol().byteValue()); + buffer.put(mc.getAttn().byteValue()); + buffer.put((byte)0xFE); + buffer.put((byte)0xFE); + } + if (cmd == MatrixConstants.COMMAND_SET_OFFSET) { + buffer.put((byte)0x68); + buffer.put((byte)0xFE); + buffer.put((byte)0xFE); + buffer.put(mc.getCol().byteValue()); + buffer.put(mc.getOffset().byteValue()); + buffer.put((byte)0xFE); + buffer.put((byte)0xFE); + buffer.put((byte)0xFE); + + } + if (cmd == MatrixConstants.COMMAND_GET_OFFSET) { + buffer.put((byte)0xFE); + buffer.put((byte)0xFE); + buffer.put((byte)0xFE); + buffer.put(mc.getCol().byteValue()); + buffer.put((byte)0xFE); + buffer.put((byte)0xFE); + buffer.put((byte)0xFE); + } + + buffer.flip(); + protocolEncoderOutput.write(buffer); + } + } + + public static class Qrb3000ProtocolDecoder extends ProtocolDecoderAdapter { + + @Override + public void decode(IoSession ioSession, IoBuffer ioBuffer, ProtocolDecoderOutput protocolDecoderOutput) + throws Exception { + log.info("--server返回给----client ------IoBuffer{}", ioBuffer); + MatrixResponse response = new MatrixResponse(); + int len = ioBuffer.limit(); + byte[] bytes = new byte[len]; + ioBuffer.get(bytes); + int cmd = bytes[0]; + if(cmd == 0x30 && len==8) { + int row = CommandHelper.BCD_REV[bytes[3]]; + int col = CommandHelper.BCD_REV[bytes[4]]; + int attn = bytes[5]; + + response.setRow(row); + response.setCol(col); + response.setIsSetAttn(true); + response.setAttn(attn); + + } else if (cmd == 0x68 && len ==8) { + int offset = bytes[6]; + int col = CommandHelper.BCD_REV[bytes[3]]; + response.setIsSetOffset(true); + response.setCol(col); + response.setOffset(offset); + } else { + int offset = bytes[6]; + response.setOffset(offset); + } + protocolDecoderOutput.write(response); + } + + } + +} diff --git a/src/main/java/com/example/mina/client/box/rec6000/REC6000ClientIoHandler.java b/src/main/java/com/example/mina/client/box/rec6000/REC6000ClientIoHandler.java index 3c886b4..63d0fe5 100644 --- a/src/main/java/com/example/mina/client/box/rec6000/REC6000ClientIoHandler.java +++ b/src/main/java/com/example/mina/client/box/rec6000/REC6000ClientIoHandler.java @@ -2,6 +2,7 @@ package com.example.mina.client.box.rec6000; import com.example.mina.client.base.AbstractMatrixIoHandler; import com.example.mina.client.base.MatrixDataProxy; +import com.example.mina.client.base.MatrixResponse; import lombok.extern.slf4j.Slf4j; import org.apache.mina.core.session.IoSession; @@ -22,8 +23,8 @@ public class REC6000ClientIoHandler extends AbstractMatrixIoHandler { @Override - public boolean handleCommandResponse(byte[] response) { - log.info("------REC3000ClientIoHandler-----{}",response); + public boolean handleCommandResponse(MatrixResponse matrixResponse) { + log.info("------REC3000ClientIoHandler-----{}",matrixResponse); return false; } diff --git a/src/main/java/com/example/mina/server/box/qrb3000/Qrb3000VirtualBoxHandler.java b/src/main/java/com/example/mina/server/box/qrb3000/Qrb3000VirtualBoxHandler.java index 82f077b..7764984 100644 --- a/src/main/java/com/example/mina/server/box/qrb3000/Qrb3000VirtualBoxHandler.java +++ b/src/main/java/com/example/mina/server/box/qrb3000/Qrb3000VirtualBoxHandler.java @@ -50,6 +50,7 @@ public class Qrb3000VirtualBoxHandler } if (len == message.LENGTH8) { +// byte[] input = message.getInput(); switch (message.getInput()[0]) { case 0x30: LogUtils.println(String.format("setAttenuation: %d, %d, %d", @@ -59,14 +60,14 @@ public class Qrb3000VirtualBoxHandler dataBuffer.setAttenuation(CommandHelper.BCD_REV[message.getInput()[3]], CommandHelper.BCD_REV[message.getInput()[4]], message.getInput()[5]); + buffer[5] = (byte) dataBuffer.getAttenuation(CommandHelper.BCD_REV[message.getInput()[3]], CommandHelper.BCD_REV[message.getInput()[4]]); return Qrb3000ResponseMessage.builder().result(buffer).build(); case 0x68: // dataBuffer.setOffset(Qrb3000CommandHelper.BCD_REV[message.getInput()[3]], random.nextInt(120) - 60 ); - - buffer[6] = (byte) dataBuffer.getOffset(CommandHelper.BCD_REV[message.getInput()[3]]); + buffer[6] = (byte)dataBuffer.getOffset(CommandHelper.BCD_REV[message.getInput()[3]]); return Qrb3000ResponseMessage.builder().result(buffer).build(); case 0x62: -- libgit2 0.21.2