aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/RetranslatorProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-12 13:57:19 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-12 13:57:19 +1200
commit1fe468bf5b004845e8904b66198597d28d37a029 (patch)
treebdd210609275a0acc3bfc13159eb92e28bdd4485 /src/org/traccar/protocol/RetranslatorProtocolDecoder.java
parent69a4af1c2b419fd7cc6356bcc2bf760969a73f95 (diff)
downloadtrackermap-server-1fe468bf5b004845e8904b66198597d28d37a029.tar.gz
trackermap-server-1fe468bf5b004845e8904b66198597d28d37a029.tar.bz2
trackermap-server-1fe468bf5b004845e8904b66198597d28d37a029.zip
Migrate new protocols
Diffstat (limited to 'src/org/traccar/protocol/RetranslatorProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/RetranslatorProtocolDecoder.java28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/org/traccar/protocol/RetranslatorProtocolDecoder.java b/src/org/traccar/protocol/RetranslatorProtocolDecoder.java
index 756b0bcaf..b31dce5d7 100644
--- a/src/org/traccar/protocol/RetranslatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/RetranslatorProtocolDecoder.java
@@ -15,15 +15,15 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
@@ -33,21 +33,15 @@ public class RetranslatorProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private double readDouble(ChannelBuffer buf) {
- byte[] bytes = new byte[8];
- buf.readBytes(bytes);
- return ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes).readDouble();
- }
-
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
if (channel != null) {
- channel.write(ChannelBuffers.wrappedBuffer(new byte[]{0x11}));
+ channel.writeAndFlush(new NetworkMessage(Unpooled.wrappedBuffer(new byte[]{0x11}), remoteAddress));
}
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedInt(); // length
@@ -65,7 +59,7 @@ public class RetranslatorProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedInt(); // bit flags
- while (buf.readable()) {
+ while (buf.isReadable()) {
buf.readUnsignedShort(); // block type
int blockEnd = buf.readInt() + buf.readerIndex();
@@ -78,9 +72,9 @@ public class RetranslatorProtocolDecoder extends BaseProtocolDecoder {
if (name.equals("posinfo")) {
position.setValid(true);
- position.setLongitude(readDouble(buf));
- position.setLatitude(readDouble(buf));
- position.setAltitude(readDouble(buf));
+ position.setLongitude(buf.readDoubleLE());
+ position.setLatitude(buf.readDoubleLE());
+ position.setAltitude(buf.readDoubleLE());
position.setSpeed(buf.readShort());
position.setCourse(buf.readShort());
position.set(Position.KEY_SATELLITES, buf.readByte());
@@ -95,7 +89,7 @@ public class RetranslatorProtocolDecoder extends BaseProtocolDecoder {
position.set(name, buf.readInt());
break;
case 4:
- position.set(name, readDouble(buf));
+ position.set(name, buf.readDoubleLE());
break;
case 5:
position.set(name, buf.readLong());