|
@@ -0,0 +1,553 @@
|
|
|
+package com.huimv.env.lamp.server;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.huimv.env.common.dao.entity.EnvDeviceRegisterEntity;
|
|
|
+import com.huimv.env.common.service.IDeviceRegisterService;
|
|
|
+import com.huimv.env.common.service.ISprayConfigService;
|
|
|
+import com.huimv.env.common.service.ISprayTimeService;
|
|
|
+import com.huimv.env.common.service.ITempThresholdService;
|
|
|
+import com.huimv.env.common.utils.RegexUtil;
|
|
|
+//import com.huimv.env.input.producer.Producer;
|
|
|
+//import com.huimv.env.input.service.ICommandProcessorService;
|
|
|
+//import com.huimv.env.input.utils.DateUtil2;
|
|
|
+import com.huimv.env.lamp.service.LampInputHandleService;
|
|
|
+import io.netty.buffer.ByteBuf;
|
|
|
+import io.netty.buffer.Unpooled;
|
|
|
+import io.netty.channel.ChannelHandler;
|
|
|
+import io.netty.channel.ChannelHandlerContext;
|
|
|
+import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
|
+import io.netty.util.CharsetUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Project : huimv.shiwan
|
|
|
+ * @Package : com.huimv.biosafety.uface.controller
|
|
|
+ * @Description : TODO
|
|
|
+ * @Version : 1.0
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Create : 2020-12-25
|
|
|
+ **/
|
|
|
+@ChannelHandler.Sharable
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class LampInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
+ @Autowired
|
|
|
+ private RegexUtil regexUtil;
|
|
|
+// @Autowired
|
|
|
+// private ICommandProcessorService cmdProService;
|
|
|
+// @Autowired
|
|
|
+// private DateUtil2 dateUtil;
|
|
|
+// @Autowired
|
|
|
+// private Producer producer;
|
|
|
+ private StringBuilder askTextSb = null;
|
|
|
+ @Autowired
|
|
|
+ private ITempThresholdService tempThresholdService;
|
|
|
+ @Autowired
|
|
|
+ private ISprayConfigService sprayConfigService;
|
|
|
+ @Autowired
|
|
|
+ private ISprayTimeService sprayTimeService;
|
|
|
+ @Autowired
|
|
|
+ private IDeviceRegisterService deviceRegisterService;
|
|
|
+ @Resource
|
|
|
+ private LampInputHandleService lampInputHandleService;
|
|
|
+
|
|
|
+ //
|
|
|
+ public void appendClientAsk(String text) {
|
|
|
+ if (this.askTextSb == null) {
|
|
|
+ askTextSb = new StringBuilder();
|
|
|
+ }
|
|
|
+ askTextSb.append(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
|
|
+ ByteBuf data = (ByteBuf) msg;
|
|
|
+ String clientAskText = data.toString(CharsetUtil.UTF_8);
|
|
|
+ //保存实例内的客户端请求
|
|
|
+ appendClientAsk(clientAskText);
|
|
|
+ //临时写入耳标数据到文件
|
|
|
+// writeTxt(clientAskText,"all");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
|
|
+ if (askTextSb.toString().indexOf("end") != -1) {
|
|
|
+ // {处理客户端消息}
|
|
|
+ handleClientAskCmd(askTextSb.toString(), ctx);
|
|
|
+ //清空重置;
|
|
|
+ askTextSb.delete(0, askTextSb.length());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
|
|
+ if (cause.getMessage().indexOf("Connection reset") != -1) {
|
|
|
+ log.info("相关采集器设备正在重启:" + cause.toString());
|
|
|
+ }
|
|
|
+// cause.printStackTrace();
|
|
|
+ ctx.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : handleClientAskCmd
|
|
|
+ * @Description : 处理请求小心
|
|
|
+ * @Params : [clientAskText, ctx]
|
|
|
+ * @Return : void
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/3/28
|
|
|
+ * @Time : 17:36
|
|
|
+ */
|
|
|
+ private void handleClientAskCmd(String clientAskText, ChannelHandlerContext ctx) throws ParseException, IOException {
|
|
|
+ clientAskText = clientAskText.replaceAll("\r", "").replaceAll("\n", "");
|
|
|
+ //{处理非正常命令}
|
|
|
+// int countPlus = regexUtil.countPlus(clientAskText);
|
|
|
+// if (countPlus < 4) {
|
|
|
+// System.out.println("当前数据为不完整数据,故丢弃.>>" + clientAskText);
|
|
|
+// } else {
|
|
|
+ //--处理客户端请求数据
|
|
|
+ //{拆分粘包数据}
|
|
|
+ JSONArray askJa = parseAskCmdPackage(clientAskText);
|
|
|
+ for (int a = 0; a < askJa.size(); a++) {
|
|
|
+ String askText = askJa.getString(a);
|
|
|
+ //{处理请求命令}
|
|
|
+ askCmdActuator(askText, ctx);
|
|
|
+ }
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : askCmdActuator
|
|
|
+ * @Description :
|
|
|
+ * @Params : [askText, ctx]
|
|
|
+ * @Return : void
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2022/3/23
|
|
|
+ * @Time : 18:08
|
|
|
+ */
|
|
|
+ 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;
|
|
|
+// case "4":
|
|
|
+// //上传湿度数据
|
|
|
+// uploadHumi(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "5":
|
|
|
+// //氨气数据上传
|
|
|
+// uploadAmmonia(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "6":
|
|
|
+// //获取喷雾除臭配置
|
|
|
+// getSprayConfig(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "7":
|
|
|
+// //上报喷雾除臭状态
|
|
|
+// uploadSprayEquipStatus(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "8":
|
|
|
+// //水压
|
|
|
+// uploadWaterGege(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "9":
|
|
|
+// //PH
|
|
|
+// uploadPH(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "10":
|
|
|
+// //水表
|
|
|
+// uploadWaterMeter(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "11":
|
|
|
+// //电表
|
|
|
+// uploadElectricityMeter(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "12":
|
|
|
+// //获取设备开关
|
|
|
+// getSparySwitch(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "13":
|
|
|
+// //上报设备状态
|
|
|
+// getSparyStatus(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+//
|
|
|
+// case "14":
|
|
|
+// //获取报警使能
|
|
|
+// getAlarmConfig(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "15":
|
|
|
+// //短信发送
|
|
|
+// uploadSendMessage(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "16":
|
|
|
+// //声光报警短信
|
|
|
+// uploadAudibleAndVisualAlarmMessage(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "17":
|
|
|
+// //报警器打电话
|
|
|
+// uploadTelephoneAlarm(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "18":
|
|
|
+// //高温,低温报警参数请求
|
|
|
+// getTempThresholdConfig(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+// case "19":
|
|
|
+// //平台消息推送
|
|
|
+// uploadPlatformMessagePushInfo(askText, idCode, ctx);
|
|
|
+// break;
|
|
|
+ default:
|
|
|
+ System.out.println("==>未知命令");
|
|
|
+ log.error(">>当前数据为非法数据-未知命令>>" + askText);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// //上报设备状态
|
|
|
+// private void getSparyStatus(String askText, String deviceCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>上报设备状态上传请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(deviceCode)) {
|
|
|
+// System.out.println("##上报设备状态上传请求-未注册设备 deviceCode=" + deviceCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //上报设备状态
|
|
|
+// String answerText = "hm+118+13+1010101010101010+201702081523+6+end";
|
|
|
+// log.info(">>上报设备状态上传请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// //上报设备状态请求到消息队列
|
|
|
+//// producer.sendWaterGege(askText);
|
|
|
+// }
|
|
|
+// //获取设备开关
|
|
|
+// private void getSparySwitch(String askText, String deviceCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>获取设备开关上传请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(deviceCode)) {
|
|
|
+// System.out.println("##获取设备开关上传请求-未注册设备 deviceCode=" + deviceCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //TODO 获取设备开关请求
|
|
|
+// String answerText = "hm+118+12+1010101010101010+6+end";
|
|
|
+// log.info(">>获取设备开关上传请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// //获取设备开关请求
|
|
|
+//// producer.sendWaterGege(askText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //电表
|
|
|
+// private void uploadElectricityMeter(String askText, String deviceCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>电表上传请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(deviceCode)) {
|
|
|
+// System.out.println("##电表上传请求-未注册设备 deviceCode=" + deviceCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //电表上传请求
|
|
|
+// String answerText = "hm+11+0+7+end";
|
|
|
+// log.info(">>电表上传请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// //电表请求到消息队列
|
|
|
+//// producer.sendWaterGege(askText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //水表
|
|
|
+// private void uploadWaterMeter(String askText, String deviceCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>水表上传请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(deviceCode)) {
|
|
|
+// System.out.println("##水表上传请求-未注册设备 deviceCode=" + deviceCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //水表上传请求
|
|
|
+// String answerText = "hm+10+0+7+end";
|
|
|
+// log.info(">>水表上传请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// //发送水表请求到消息队列
|
|
|
+//// producer.sendWaterGege(askText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //PH
|
|
|
+// private void uploadPH(String askText, String deviceCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>PH上传请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(deviceCode)) {
|
|
|
+// System.out.println("##PH上传请求-未注册设备 deviceCode=" + deviceCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //PH传请求
|
|
|
+// String answerText = "hm+9+0+7+end";
|
|
|
+// log.info(">>PH上传请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// //发送PH请求到消息队列
|
|
|
+//// producer.sendWaterGege(askText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //水压
|
|
|
+// private void uploadWaterGege(String askText, String deviceCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>水压上传请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(deviceCode)) {
|
|
|
+// System.out.println("##水压上传请求-未注册设备 deviceCode=" + deviceCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //水压上传请求
|
|
|
+// String answerText = "hm+8+0+7+end";
|
|
|
+// log.info(">>水压上传请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// //水压请求到消息队列
|
|
|
+// producer.sendWaterGege(askText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //平台消息推送请求
|
|
|
+// private void uploadPlatformMessagePushInfo(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>平台消息推送请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(idCode)) {
|
|
|
+// System.out.println("##平台消息推送请求-未注册设备 idCode=" + idCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// String answerText = "hm+19+0+2+end";
|
|
|
+// log.info(">>平台消息推送请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+//
|
|
|
+// //发送喷雾设备状态到消息队列
|
|
|
+// producer.sendPushMessageToMQ(askText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //高温,低温报警参数请求
|
|
|
+// private void getTempThresholdConfig(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>高温,低温报警参数请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(idCode)) {
|
|
|
+// System.out.println("##高温,低温报警参数请求-未注册设备 idCode=" + idCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// String threshold = tempThresholdService.getTempThresholdByDeviceCode(idCode);
|
|
|
+// String answerText = "hm+"+idCode+"+18+"+threshold+"+6+end";
|
|
|
+// log.info(">>高温,低温报警参数请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //报警器打电话请求
|
|
|
+// private void uploadTelephoneAlarm(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>报警器打电话请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(idCode)) {
|
|
|
+// System.out.println("##报警器打电话请求-未注册设备 idCode=" + idCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// String answerText = "hm+17+0+2+end";
|
|
|
+// log.info(">>报警器打电话请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //声光报警短信发送请求
|
|
|
+// private void uploadAudibleAndVisualAlarmMessage(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>声光报警短信发送请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(idCode)) {
|
|
|
+// System.out.println("##声光报警短信发送请求-未注册设备 idCode=" + idCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// String answerText = "hm+16+0+2+end";
|
|
|
+// log.info(">>声光报警短信发送请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //短信发送请求
|
|
|
+// private void uploadSendMessage(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>短信发送请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(idCode)) {
|
|
|
+// System.out.println("##>短信发送请求-未注册设备 idCode=" + idCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// String answerText = "hm+15+0+2+end";
|
|
|
+// log.info(">>>短信发送请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //获取报警使能请求
|
|
|
+// private void getAlarmConfig(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>获取报警使能请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(idCode)) {
|
|
|
+// System.out.println("##获取报警使能请求-未注册设备 idCode=" + idCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //(声光报警、短信报警、语音报警) 1:关闭,2:打开
|
|
|
+// String answerText = "hm+"+idCode+"+14+2(111)2(111)2(111)2(111)2(111)+0+4+end";
|
|
|
+// log.info(">>获取报警使能请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //上报喷雾除臭状态请求
|
|
|
+// private void uploadSprayEquipStatus(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>上报喷雾除臭状态请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(idCode)) {
|
|
|
+// System.out.println("##上报喷雾除臭状态请求-未注册设备 idCode=" + idCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// String answerText = "hm+" + idCode + "+7+6+end";
|
|
|
+// log.info(">>上报喷雾除臭状态请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// //发送喷雾设备状态到消息队列
|
|
|
+// producer.sendSprayEquipStatusToMQ(askText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //获取喷雾除臭配置请求
|
|
|
+// private void getSprayConfig(String askText, String deviceCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>获取喷雾除臭配置请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(deviceCode)) {
|
|
|
+// System.out.println("##获取喷雾除臭配置请求-未注册设备 idCode=" + deviceCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //读取设备注册信息
|
|
|
+// EnvDeviceRegisterEntity envDeviceRegisterEntity = deviceRegisterService.getDeviceRegisterByDeviceCode(deviceCode);
|
|
|
+// if (envDeviceRegisterEntity == null) {
|
|
|
+// log.error("该设备[" + deviceCode + "]未注册.");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// java.sql.Date todayDate = new java.sql.Date(new java.util.Date().getTime());
|
|
|
+// Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
|
|
|
+// String farmCode = envDeviceRegisterEntity.getFarmCode();
|
|
|
+//
|
|
|
+// //读取喷雾配置表数据
|
|
|
+// JSONObject configJo = sprayConfigService.getSprayConfigByDeviceCode(deviceCode, farmCode);
|
|
|
+// int runMode = configJo.getInteger("runMode");
|
|
|
+// int deviceStatus = configJo.getInteger("deviceStatus");
|
|
|
+// int timeInterval = configJo.getInteger("timeInterval") * 60;
|
|
|
+// //读取定时时间配置表数据
|
|
|
+// String sprayTime = sprayTimeService.getSprayTimeByDeviceCode(deviceCode);
|
|
|
+//// String answerText = "hm+"+deviceCode+"+6+1+1+0101,60,10,10,0202,60,10,10,0303,60,10,10,0404,60,10,10+60+6+end";
|
|
|
+// String answerText = "hm+" + deviceCode + "+6+" + runMode + "+" + deviceStatus + "+" + sprayTime + "+" + timeInterval + "+6+end";
|
|
|
+// log.info("<<获取喷雾除臭配置请求-应答数据<<" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //氨气度上传请求
|
|
|
+// private void uploadAmmonia(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>氨气度上传请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(idCode)) {
|
|
|
+// System.out.println("##氨气度上传请求-未注册设备 idCode=" + idCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// String answerText = "hm+5+0+8+end";
|
|
|
+// log.info(">>氨气度上传请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+//
|
|
|
+// //发送氨气请求到消息队列
|
|
|
+// producer.sendAmmoniaAskToMQ(askText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //湿度度上传请求
|
|
|
+// private void uploadHumi(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>湿度度上传请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(idCode)) {
|
|
|
+// System.out.println("##湿度度上传请求-未注册设备 idCode=" + idCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// String answerText = "hm+4+0+8+end";
|
|
|
+// log.info(">>湿度度上传请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// //发送湿度请求到消息队列
|
|
|
+// producer.sendHumiAskToMQ(askText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 温度度上传
|
|
|
+// private void uploadTemp(String askText, String deviceCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>温度度上传请求 askText>>" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(deviceCode)) {
|
|
|
+// System.out.println("##温度度上传请求-未注册设备 deviceCode=" + deviceCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //温度度上传请求
|
|
|
+// String answerText = "hm+3+0+7+end";
|
|
|
+// log.info(">>温度度上传请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// //发送温度请求到消息队列
|
|
|
+// producer.sendTempAskToMQ(askText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //时间同步请求
|
|
|
+// private void getServerTime(String askText, String deviceCode, ChannelHandlerContext ctx) throws ParseException {
|
|
|
+// System.out.println("==>时间同步请求:" + askText);
|
|
|
+// if (!cmdProService.isEffectiveDevice(deviceCode)) {
|
|
|
+// System.out.println("##时间同步请求-未注册设备 idCode=" + deviceCode);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// String answerText = "hm+2+" + dateUtil.getNowText() + "+0+4+end";
|
|
|
+// log.info(">>时间同步请求-应答数据>>" + answerText);
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //获取远程设备编码
|
|
|
+// private void getDeviceCode(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+// System.out.println("==>获取远程设备编码请求:" + askText.trim());
|
|
|
+// //{读取设备编码}
|
|
|
+// String deviceCode = cmdProService.getDeviceCodeByChipId(idCode);
|
|
|
+// log.info("获取远程设备编码请求,芯片id>>" + idCode + " ,deviceCode>>" + deviceCode);
|
|
|
+// if (deviceCode == null) {
|
|
|
+// log.error("该设备未注册,已舍弃请求.");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// String answerText = "hm+1+0+" + deviceCode + "+123+8+end";
|
|
|
+// log.info("<<获取远程设备编码请求-应答数据:" + answerText);
|
|
|
+// //{应答指令}
|
|
|
+// answerCmd(answerText, ctx);
|
|
|
+// }
|
|
|
+
|
|
|
+ //应答
|
|
|
+ public void answerCmd(String answerText, ChannelHandlerContext ctx) {
|
|
|
+ ctx.writeAndFlush(Unpooled.copiedBuffer(answerText.getBytes()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查无效耳标
|
|
|
+ public boolean checkValidEarmark(String earmark) {
|
|
|
+ if (earmark.trim().equalsIgnoreCase("ffffffffffffffff") || earmark.trim().equalsIgnoreCase("0000000000000000")) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //拆分粘包数据
|
|
|
+ public JSONArray parseAskCmdPackage(String text) {
|
|
|
+ String key = "end";
|
|
|
+ Pattern pattern = Pattern.compile(key);
|
|
|
+ Matcher matcher = pattern.matcher(text);
|
|
|
+ int count = 0;
|
|
|
+ while (matcher.find()) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ JSONArray dataJa = new JSONArray();
|
|
|
+ if (count == 1) {
|
|
|
+ dataJa.add(text);
|
|
|
+ } else {
|
|
|
+ for (int a = 0; a < count; a++) {
|
|
|
+ int p1 = text.indexOf("end");
|
|
|
+ dataJa.add(text.substring(0, p1 + 3));
|
|
|
+ text = text.substring(p1 + 3, text.length());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dataJa;
|
|
|
+ }
|
|
|
+}
|