|
@@ -2,9 +2,9 @@ package com.huimv.env.input.server;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
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 freemarker.template.utility.DateUtil;
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
import io.netty.channel.ChannelHandler;
|
|
@@ -44,6 +44,8 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
private ICommandProcessorService cmdProService;
|
|
|
@Autowired
|
|
|
private DateUtil2 dateUtil;
|
|
|
+ @Autowired
|
|
|
+ private Producer producer;
|
|
|
private StringBuilder askTextSb = null;
|
|
|
|
|
|
//
|
|
@@ -132,150 +134,232 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
String cmd = dataArray[2];
|
|
|
Map map = new HashMap();
|
|
|
map.put("askText", askText);
|
|
|
- if (cmdHeader.trim().equalsIgnoreCase("hm")) {
|
|
|
- if (cmd.trim().equalsIgnoreCase("1")) {
|
|
|
- System.out.println("==>获取远程设备编码请求:" + askText.trim());
|
|
|
-// //{读取设备编码}
|
|
|
- String deviceCode = cmdProService.getDeviceCodeByChipId(idCode);
|
|
|
- log.info("获取远程设备编码请求,芯片id>>" + idCode + " ,deviceCode>>" + deviceCode);
|
|
|
- if (deviceCode != null) {
|
|
|
- String answerText = "hm+1+0+" + deviceCode + "+123+8+end";
|
|
|
- log.info("<<获取远程设备编码请求-应答数据:" + answerText);
|
|
|
- //{应答指令}
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- log.error("该设备未注册,已舍弃请求.");
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("2")) {
|
|
|
- System.out.println("==>时间同步请求:" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- //时间同步请求
|
|
|
- String answerText = "hm+2+" + dateUtil.getNowText() + "+4+end";
|
|
|
- log.info(">>时间同步请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##时间同步请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("3")) {
|
|
|
- System.out.println("==>温度度上传请求 askText>>" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- //温度度上传请求
|
|
|
- String answerText = "hm+3+0+7+end";
|
|
|
- log.info(">>温度度上传请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##温度度上传请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("4")) {
|
|
|
- System.out.println("==>湿度度上传请求 askText>>" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- //湿度度上传请求
|
|
|
- String answerText = "hm+4+0+8+end";
|
|
|
- log.info(">>湿度度上传请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##湿度度上传请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("5")) {
|
|
|
- System.out.println("==>氨气度上传请求 askText>>" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- //氨气度上传请求
|
|
|
- String answerText = "hm+5+0+8+end";
|
|
|
- log.info(">>氨气度上传请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##氨气度上传请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("6")) {
|
|
|
- System.out.println("==>获取喷雾除臭配置请求 askText>>" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- //获取喷雾除臭配置请求
|
|
|
- String answerText = "hm+158+6+1+1+(201708080101,60,10,10)(201708080202,60,10,10)(201708080303,60,10,10)(201708080404,60,10,10)...+60+201702081523+6+end";
|
|
|
- log.info(">>获取喷雾除臭配置请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##获取喷雾除臭配置请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("7")) {
|
|
|
- System.out.println("==>上报喷雾除臭状态请求 askText>>" + askText);
|
|
|
- //上报喷雾除臭状态请求
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- String answerText = "hm+158+7+6+end";
|
|
|
- log.info(">>上报喷雾除臭状态请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##上报喷雾除臭状态请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("14")) {
|
|
|
- //获取报警使能请求
|
|
|
- System.out.println("==>获取报警使能请求 askText>>" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- String answerText = "hm+158+14+1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)+0+4+end";
|
|
|
- log.info(">>获取报警使能请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##获取报警使能请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("15")) {
|
|
|
- //短信发送请求
|
|
|
- System.out.println("==>短信发送请求 askText>>" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- String answerText = "hm+15+0+2+end";
|
|
|
- log.info(">>>短信发送请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##>短信发送请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("16")) {
|
|
|
- System.out.println("==>声光报警短信发送请求 askText>>" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- //声光报警短信发送请求
|
|
|
- String answerText = "hm+16+0+2+end";
|
|
|
- log.info(">>声光报警短信发送请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##声光报警短信发送请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("17")) {
|
|
|
- System.out.println("==>报警器打电话请求 askText>>" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- //报警器打电话请求
|
|
|
- String answerText = "hm+17+0+2+end";
|
|
|
- log.info(">>报警器打电话请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##报警器打电话请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("18")) {
|
|
|
- System.out.println("==>高温,低温报警参数请求 askText>>" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- //高温,低温报警参数请求
|
|
|
- String answerText = "hm+158+18+265+12+6+end";
|
|
|
- log.info(">>高温,低温报警参数请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##高温,低温报警参数请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else if (cmd.trim().equalsIgnoreCase("19")) {
|
|
|
- System.out.println("==>平台消息推送请求 askText>>" + askText);
|
|
|
- if (cmdProService.isEffectiveDevice(idCode)) {
|
|
|
- //平台消息推送请求
|
|
|
- String answerText = "hm+19+0+2+end";
|
|
|
- log.info(">>平台消息推送请求-应答数据>>" + answerText);
|
|
|
- answerCmd(answerText, ctx);
|
|
|
- } else {
|
|
|
- System.out.println("##平台消息推送请求-未注册设备 idCode=" + idCode);
|
|
|
- }
|
|
|
- } else {
|
|
|
+ switch (cmd) {
|
|
|
+ case "1":
|
|
|
+ //获取远程设备编码
|
|
|
+ getDeviceCode(askText, idCode, ctx);
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ //同步时间
|
|
|
+ getServerTime(askText, idCode, ctx);
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ //温度上传数据
|
|
|
+ uploadTemp(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 "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);
|
|
|
- }
|
|
|
- } else {
|
|
|
- System.out.println("==>未知命令头");
|
|
|
- log.error("##当前请求数据为非法数据-未知命令头>>" + 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //高温,低温报警参数请求
|
|
|
+ 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 answerText = "hm+158+18+265+12+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;
|
|
|
+ }
|
|
|
+ String answerText = "hm+158+14+1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)+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+158+7+6+end";
|
|
|
+ log.info(">>上报喷雾除臭状态请求-应答数据>>" + answerText);
|
|
|
+ answerCmd(answerText, ctx);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取喷雾除臭配置请求
|
|
|
+ private void getSprayConfig(String askText, String idCode, ChannelHandlerContext ctx) {
|
|
|
+ System.out.println("==>获取喷雾除臭配置请求 askText>>" + askText);
|
|
|
+ if (!cmdProService.isEffectiveDevice(idCode)) {
|
|
|
+ System.out.println("##获取喷雾除臭配置请求-未注册设备 idCode=" + idCode);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String answerText = "hm+158+6+1+1+(201708080101,60,10,10)(201708080202,60,10,10)(201708080303,60,10,10)(201708080404,60,10,10)...+60+201702081523+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()));
|
|
|
}
|