|
@@ -94,6 +94,8 @@ public class LampInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
@Override
|
|
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
|
|
log.info("连接断开");
|
|
|
+ channelReadComplete(ctx);
|
|
|
+ ctx.close();
|
|
|
}
|
|
|
@Override
|
|
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
|
@@ -101,6 +103,7 @@ public class LampInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
log.info("相关采集器设备正在重启:" + cause.toString());
|
|
|
}
|
|
|
// cause.printStackTrace();
|
|
|
+ channelReadComplete(ctx);
|
|
|
ctx.close();
|
|
|
}
|
|
|
|
|
@@ -140,36 +143,52 @@ public class LampInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
* @Date : 2022/3/23
|
|
|
* @Time : 18:08
|
|
|
*/
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String s = "hm+87021038+2+1+3hm+87021038+2+1+306+2023022005731+6+end";
|
|
|
+ for (String hm : s.split("hm")) {
|
|
|
+ System.out.println("0 "+hm);
|
|
|
+ }
|
|
|
+ for (String hm : s.split("end")) {
|
|
|
+ System.out.println("1 "+hm);
|
|
|
+ }
|
|
|
+ }
|
|
|
private void askCmdActuator(String askText, ChannelHandlerContext ctx) throws ParseException, IOException {
|
|
|
System.out.println("======>接收设备请求:" + askText);
|
|
|
- String[] dataArray = askText.split("\\+");
|
|
|
- String cmdHeader = dataArray[0];
|
|
|
- if (!cmdHeader.trim().equalsIgnoreCase("hm")) {
|
|
|
- log.info("当前命令是非hm命令[" + askText + "]");
|
|
|
- return;
|
|
|
- }
|
|
|
- //芯片id/设备编码
|
|
|
- String idCode = dataArray[1];
|
|
|
- String cmd = dataArray[2];
|
|
|
- Map map = new HashMap();
|
|
|
- map.put("askText", askText);
|
|
|
- switch (cmd) {
|
|
|
- case "1":
|
|
|
- //同步时间
|
|
|
- lampInputHandleService.synchronizationTime(askText, idCode, ctx);
|
|
|
- break;
|
|
|
- case "2":
|
|
|
- //上传温度
|
|
|
- lampInputHandleService.getLampTemp(askText, idCode, ctx);
|
|
|
- break;
|
|
|
- case "3":
|
|
|
- //获取保温箱配置
|
|
|
- lampInputHandleService.getLampConfig(askText, idCode, ctx);
|
|
|
- break;
|
|
|
- default:
|
|
|
- System.out.println("==>未知命令");
|
|
|
- log.error(">>当前数据为非法数据-未知命令>>" + askText);
|
|
|
+ String[] hms = askText.split("hm");
|
|
|
+ String[] ends = askText.split("end");
|
|
|
+ if (hms.length<=2 && ends.length <=1){
|
|
|
+ String[] dataArray = askText.split("\\+");
|
|
|
+ String cmdHeader = dataArray[0];
|
|
|
+ if (!cmdHeader.trim().equalsIgnoreCase("hm")) {
|
|
|
+ log.info("当前命令是非hm命令[" + askText + "]");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //芯片id/设备编码
|
|
|
+ String idCode = dataArray[1];
|
|
|
+ String cmd = dataArray[2];
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("askText", askText);
|
|
|
+ switch (cmd) {
|
|
|
+ case "1":
|
|
|
+ //同步时间
|
|
|
+ lampInputHandleService.synchronizationTime(askText, idCode, ctx);
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ //上传温度
|
|
|
+ lampInputHandleService.getLampTemp(askText, idCode, ctx);
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ //获取保温箱配置
|
|
|
+ lampInputHandleService.getLampConfig(askText, idCode, ctx);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ System.out.println("==>未知命令");
|
|
|
+ log.error(">>当前数据为非法数据-未知命令>>" + askText);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ lampInputHandleService.getLampTempError(askText,ctx);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//拆分粘包数据
|