|
@@ -1,5 +1,6 @@
|
|
|
package com.tidecloud.dataacceptance.service.impl;
|
|
|
|
|
|
+import com.accept.client.DeviceCronClient;
|
|
|
import com.accept.client.VoiceMsgClient;
|
|
|
import com.accept.model.VoiceMsgVo;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -14,7 +15,6 @@ import io.netty.channel.ChannelHandler.Sharable;
|
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
|
|
import io.netty.channel.socket.SocketChannel;
|
|
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
|
|
-import io.netty.handler.codec.DelimiterBasedFrameDecoder;
|
|
|
import io.netty.handler.logging.LogLevel;
|
|
|
import io.netty.handler.logging.LoggingHandler;
|
|
|
import io.netty.util.ByteProcessor;
|
|
@@ -70,14 +70,20 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
*/
|
|
|
private static Map<String, WorkModel> modelMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
- private final ByteBuf TAG_AP07 = Unpooled.copiedBuffer("AP07".getBytes());
|
|
|
- private final ByteBuf TAG_COMMA = Unpooled.copiedBuffer(",".getBytes());
|
|
|
+
|
|
|
+ * 心率
|
|
|
+ */
|
|
|
+ private static Map<String, Integer> beatMap = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
|
|
|
private static final ByteProcessor FIND_COMMA = new ByteProcessor.IndexOfProcessor((byte) ',');
|
|
|
|
|
|
@Autowired
|
|
|
private VoiceMsgClient voiceMsgClient;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DeviceCronClient deviceCronClient;
|
|
|
+
|
|
|
@Override
|
|
|
protected void handle(ByteBuf in, Channel channel) throws Exception {
|
|
|
|
|
@@ -126,20 +132,12 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
checkSwitchMap(factory, deviceId, channel);
|
|
|
sendMsg2Kafka((msg + deviceId + "," + DateUtil.formatDate2String(new Date())).getBytes(), deviceId, channel);
|
|
|
logger.warn("心跳报文下发 msg+" + msg);
|
|
|
-
|
|
|
- VoiceMsgVo voiceF = voiceMsgClient.queryVoiceMsg(deviceId, 1);
|
|
|
- if (voiceF.getLag() == 1) {
|
|
|
- normalBP28Reply(channel, voiceF);
|
|
|
- }
|
|
|
+ voiceReplyToClient(deviceId, channel);
|
|
|
+ snedApthReplyToClient(deviceId, channel);
|
|
|
break;
|
|
|
case "AP01":
|
|
|
String gpsState = msg.substring(12, 13);
|
|
|
|
|
|
- String gDay = msg.substring(6, 12);
|
|
|
- String gTime = msg.substring(39, 45);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
setSwitchMap(deviceId, gpsState, msg, channel);
|
|
|
normalReply(factory, channel, "BP01");
|
|
|
break;
|
|
@@ -166,8 +164,23 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
break;
|
|
|
case "APHT":
|
|
|
sendMsg2Kafka((msg + deviceId + "," + DateUtil.formatDate2String(new Date())).getBytes(), deviceId, channel);
|
|
|
+ normalReply(factory, channel, "BPHT");
|
|
|
+ if (beatMap.containsKey(deviceId)) {
|
|
|
+ beatMap.put(deviceId, 2);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "AP49":
|
|
|
+ String heatBeat = msg.substring(7, 9);
|
|
|
+ StringBuffer sb = new StringBuffer("IWAPHT,");
|
|
|
+ sb.append(heatBeat).append(",").append("0,0,#");
|
|
|
+ sendMsg2Kafka((sb.toString() + deviceId + "," + DateUtil.formatDate2String(new Date())).getBytes(), deviceId, channel);
|
|
|
normalReply(factory, channel, "BP49");
|
|
|
-
|
|
|
+ if (beatMap.containsKey(deviceId)) {
|
|
|
+ beatMap.put(deviceId, 2);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "APXL":
|
|
|
+ beatMap.put(deviceId, 1);
|
|
|
break;
|
|
|
case "AP07":
|
|
|
|
|
@@ -206,6 +219,71 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ * 语音下行发送
|
|
|
+ *
|
|
|
+ * @param deviceId
|
|
|
+ * @param channel
|
|
|
+ */
|
|
|
+ protected void voiceReplyToClient(String deviceId, Channel channel) {
|
|
|
+ try {
|
|
|
+ VoiceMsgVo voiceF = voiceMsgClient.queryVoiceMsg(deviceId, 1);
|
|
|
+ if (voiceF.getLag() == 1) {
|
|
|
+ normalBP28Reply(channel, voiceF);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("语音下行发送异常!!!!! deviceId=" + deviceId);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 心率下行发送
|
|
|
+ * beatMap (1 下发成功,2 下发完成)
|
|
|
+ *
|
|
|
+ * @param deviceId
|
|
|
+ * @param channel
|
|
|
+ */
|
|
|
+ protected void snedApthReplyToClient(String deviceId, Channel channel) {
|
|
|
+ try {
|
|
|
+ if (!beatMap.isEmpty()
|
|
|
+ || beatMap.containsKey(deviceId)
|
|
|
+ || Integer.valueOf(2).equals(beatMap.get(deviceId))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Boolean lag = deviceCronClient.getSendApThByDeviceId(deviceId);
|
|
|
+ if (lag) {
|
|
|
+ setBPXLToClient(deviceId, channel);
|
|
|
+ } else {
|
|
|
+ beatMap.remove(deviceId);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("心率下行发送异常!!!!! deviceId=" + deviceId);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 获取心率数据 下行指令
|
|
|
+ *
|
|
|
+ * @param deviceId
|
|
|
+ * @param channel
|
|
|
+ */
|
|
|
+ protected void setBPXLToClient(String deviceId, Channel channel) {
|
|
|
+ StringBuilder replyCommand = new StringBuilder();
|
|
|
+ replyCommand.append("IWBPXL").append(",");
|
|
|
+ replyCommand.append(deviceId).append(",");
|
|
|
+ replyCommand.append("080835");
|
|
|
+ replyCommand.append("#");
|
|
|
+ String replyCommandStr = replyCommand.toString();
|
|
|
+ ByteBuf buffer = Unpooled.buffer(replyCommandStr.getBytes().length);
|
|
|
+ buffer.writeBytes(replyCommandStr.getBytes());
|
|
|
+ ChannelFuture channelFuture = channel.writeAndFlush(buffer);
|
|
|
+ channelFuture.addListener(future -> logger.info("Normal reply :" + replyCommandStr));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 语音上行回复
|
|
|
*
|
|
@@ -245,11 +323,6 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
ByteBuf buffer = Unpooled.buffer(replyCommandStr.getBytes().length);
|
|
|
buffer.writeBytes(replyCommandStr.getBytes());
|
|
|
buffer.writeBytes(voiceMsg.getMsg());
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
buffer.readerIndex(0);
|
|
|
ChannelFuture channelFuture = channel.writeAndFlush(buffer);
|
|
|
channelFuture.addListener(future -> logger.info("Normal reply :" + replyCommandStr + JSON.toJSON(voiceMsg.getMsg())));
|