aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/T800xProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/T800xProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/T800xProtocolDecoder.java46
1 files changed, 18 insertions, 28 deletions
diff --git a/src/org/traccar/protocol/T800xProtocolDecoder.java b/src/org/traccar/protocol/T800xProtocolDecoder.java
index 7bc780c83..d5504c190 100644
--- a/src/org/traccar/protocol/T800xProtocolDecoder.java
+++ b/src/org/traccar/protocol/T800xProtocolDecoder.java
@@ -15,11 +15,13 @@
*/
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.ByteBufUtil;
+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.helper.BcdUtil;
import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
@@ -29,7 +31,6 @@ import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.nio.ByteOrder;
public class T800xProtocolDecoder extends BaseProtocolDecoder {
@@ -43,21 +44,15 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_ALARM = 0x04;
public static final int MSG_COMMAND = 0x81;
- private static float readSwappedFloat(ChannelBuffer buf) {
- byte[] bytes = new byte[4];
- buf.readBytes(bytes);
- return ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes).readFloat();
- }
-
- private void sendResponse(Channel channel, short header, int type, ChannelBuffer imei) {
+ private void sendResponse(Channel channel, short header, int type, ByteBuf imei) {
if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(15);
+ ByteBuf response = Unpooled.buffer(15);
response.writeShort(header);
response.writeByte(type);
response.writeShort(response.capacity()); // length
response.writeShort(0x0001); // index
response.writeBytes(imei);
- channel.write(response);
+ channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
@@ -84,16 +79,16 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
short header = buf.readShort();
int type = buf.readUnsignedByte();
buf.readUnsignedShort(); // length
int index = buf.readUnsignedShort();
- ChannelBuffer imei = buf.readBytes(8);
+ ByteBuf imei = buf.readSlice(8);
DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, ChannelBuffers.hexDump(imei).substring(1));
+ channel, remoteAddress, ByteBufUtil.hexDump(imei).substring(1));
if (deviceSession == null) {
return null;
}
@@ -154,29 +149,24 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
position.setValid(!BitUtil.check(status, 7));
position.setTime(dateBuilder.getDate());
- position.setAltitude(readSwappedFloat(buf));
- position.setLongitude(readSwappedFloat(buf));
- position.setLatitude(readSwappedFloat(buf));
- position.setSpeed(UnitsConverter.knotsFromKph(
- BcdUtil.readInteger(buf, 4) * 0.1));
+ position.setAltitude(buf.readFloatLE());
+ position.setLongitude(buf.readFloatLE());
+ position.setLatitude(buf.readFloatLE());
+ position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4) * 0.1));
position.setCourse(buf.readUnsignedShort());
} else {
getLastLocation(position, dateBuilder.getDate());
- byte[] array = new byte[16];
- buf.readBytes(array);
- ChannelBuffer swapped = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, array);
-
- int mcc = swapped.readUnsignedShort();
- int mnc = swapped.readUnsignedShort();
+ int mcc = buf.readUnsignedShortLE();
+ int mnc = buf.readUnsignedShortLE();
if (mcc != 0xffff && mnc != 0xffff) {
Network network = new Network();
for (int i = 0; i < 3; i++) {
network.addCellTower(CellTower.from(
- mcc, mnc, swapped.readUnsignedShort(), swapped.readUnsignedShort()));
+ mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE()));
}
position.setNetwork(network);
}