diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-12-24 17:17:04 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-12-24 17:17:04 -0800 |
commit | b9d7296716168154ced0ad44f4ee8b334944ab72 (patch) | |
tree | 7fabbcf68eabd00db2f2d26b2e4bf4516ae3de6f /src/main | |
parent | 1ca3ab609cc77706178a9784287272555d577382 (diff) | |
download | trackermap-server-b9d7296716168154ced0ad44f4ee8b334944ab72.tar.gz trackermap-server-b9d7296716168154ced0ad44f4ee8b334944ab72.tar.bz2 trackermap-server-b9d7296716168154ced0ad44f4ee8b334944ab72.zip |
Implement MQTT responses
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/traccar/protocol/IotmProtocolDecoder.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java b/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java index 9a3a4dee1..e172f6ab2 100644 --- a/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java @@ -18,11 +18,12 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.MqttConnAckMessage; import io.netty.handler.codec.mqtt.MqttConnectMessage; import io.netty.handler.codec.mqtt.MqttConnectReturnCode; +import io.netty.handler.codec.mqtt.MqttMessage; import io.netty.handler.codec.mqtt.MqttMessageBuilders; import io.netty.handler.codec.mqtt.MqttPublishMessage; +import io.netty.handler.codec.mqtt.MqttSubscribeMessage; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.NetworkMessage; @@ -108,7 +109,15 @@ public class IotmProtocolDecoder extends BaseProtocolDecoder { ? MqttConnectReturnCode.CONNECTION_ACCEPTED : MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED; - MqttConnAckMessage response = MqttMessageBuilders.connAck().returnCode(returnCode).build(); + MqttMessage response = MqttMessageBuilders.connAck().returnCode(returnCode).build(); + + if (channel != null) { + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + } + + } else if (msg instanceof MqttSubscribeMessage) { + + MqttMessage response = MqttMessageBuilders.subAck().packetId((short) 1).build(); if (channel != null) { channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); @@ -175,6 +184,12 @@ public class IotmProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // checksum + MqttMessage response = MqttMessageBuilders.pubAck().packetId((short) 1).build(); + + if (channel != null) { + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + } + return positions.isEmpty() ? null : positions; } |