diff options
Diffstat (limited to 'src/org/traccar/protocol/TeltonikaProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/TeltonikaProtocolDecoder.java | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index d2069e6c9..5e9b6640e 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -15,12 +15,14 @@ */ 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.Context; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.BitUtil; import org.traccar.helper.UnitsConverter; import org.traccar.model.CellTower; @@ -48,20 +50,20 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { this.extended = Context.getConfig().getBoolean(getProtocolName() + ".extended"); } - private DeviceSession parseIdentification(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + private DeviceSession parseIdentification(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { int length = buf.readUnsignedShort(); String imei = buf.toString(buf.readerIndex(), length, StandardCharsets.US_ASCII); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(1); + ByteBuf response = Unpooled.buffer(1); if (deviceSession != null) { response.writeByte(1); } else { response.writeByte(0); } - channel.write(response); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } return deviceSession; } @@ -71,17 +73,17 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { public static final int CODEC_12 = 0x0C; public static final int CODEC_16 = 0x10; - private void decodeSerial(Position position, ChannelBuffer buf) { + private void decodeSerial(Position position, ByteBuf buf) { getLastLocation(position, null); position.set(Position.KEY_TYPE, buf.readUnsignedByte()); - position.set(Position.KEY_RESULT, buf.readBytes(buf.readInt()).toString(StandardCharsets.US_ASCII)); + position.set(Position.KEY_RESULT, buf.readSlice(buf.readInt()).toString(StandardCharsets.US_ASCII)); } - private long readValue(ChannelBuffer buf, int length, boolean signed) { + private long readValue(ByteBuf buf, int length, boolean signed) { switch (length) { case 1: return signed ? buf.readByte() : buf.readUnsignedByte(); @@ -94,7 +96,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeOtherParameter(Position position, int id, ChannelBuffer buf, int length) { + private void decodeOtherParameter(Position position, int id, ByteBuf buf, int length) { switch (id) { case 1: case 2: @@ -141,6 +143,16 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { case 80: position.set("workMode", readValue(buf, length, false)); break; + case 129: + case 130: + case 131: + case 132: + case 133: + case 134: + String driver = id == 129 || id == 132 ? "" : position.getString("driver1"); + position.set("driver" + (id >= 132 ? 2 : 1), + driver + buf.readSlice(length).toString(StandardCharsets.US_ASCII).trim()); + break; case 179: position.set(Position.PREFIX_OUT + 1, readValue(buf, length, false) == 1); break; @@ -153,6 +165,29 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { case 182: position.set(Position.KEY_HDOP, readValue(buf, length, false) * 0.1); break; + case 236: + if (readValue(buf, length, false) == 1) { + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + } + break; + case 237: + position.set(Position.KEY_MOTION, readValue(buf, length, false) == 0); + break; + case 238: + switch ((int) readValue(buf, length, false)) { + case 1: + position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + break; + case 2: + position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); + break; + case 3: + position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); + break; + default: + break; + } + break; case 239: position.set(Position.KEY_IGNITION, readValue(buf, length, false) == 1); break; @@ -168,7 +203,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeGh3000Parameter(Position position, int id, ChannelBuffer buf, int length) { + private void decodeGh3000Parameter(Position position, int id, ByteBuf buf, int length) { switch (id) { case 1: position.set(Position.KEY_BATTERY_LEVEL, readValue(buf, length, false)); @@ -211,7 +246,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeParameter(Position position, int id, ChannelBuffer buf, int length, int codec) { + private void decodeParameter(Position position, int id, ByteBuf buf, int length, int codec) { if (codec == CODEC_GH3000) { decodeGh3000Parameter(position, id, buf, length); } else { @@ -232,7 +267,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeLocation(Position position, ChannelBuffer buf, int codec) { + private void decodeLocation(Position position, ByteBuf buf, int codec) { int globalMask = 0x0f; @@ -359,7 +394,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (extended) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - position.set(Position.PREFIX_IO + buf.readUnsignedByte(), ChannelBuffers.hexDump(buf.readBytes(16))); + position.set(Position.PREFIX_IO + buf.readUnsignedByte(), ByteBufUtil.hexDump(buf.readSlice(16))); } } @@ -368,7 +403,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } private List<Position> parseData( - Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int locationPacketId, String... imei) { + Channel channel, SocketAddress remoteAddress, ByteBuf buf, int locationPacketId, String... imei) { List<Position> positions = new LinkedList<>(); if (!connectionless) { @@ -400,17 +435,17 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (channel != null) { if (connectionless) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeShort(5); response.writeShort(0); response.writeByte(0x01); response.writeByte(locationPacketId); response.writeByte(count); - channel.write(response, remoteAddress); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } else { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeInt(count); - channel.write(response); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } } @@ -420,7 +455,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { @Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; if (connectionless) { return decodeUdp(channel, remoteAddress, buf); @@ -429,7 +464,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private Object decodeTcp(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { + private Object decodeTcp(Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws Exception { if (buf.getUnsignedShort(0) > 0) { parseIdentification(channel, remoteAddress, buf); @@ -441,13 +476,13 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { return null; } - private Object decodeUdp(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { + private Object decodeUdp(Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws Exception { buf.readUnsignedShort(); // length buf.readUnsignedShort(); // packet id buf.readUnsignedByte(); // packet type int locationPacketId = buf.readUnsignedByte(); - String imei = buf.readBytes(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII); + String imei = buf.readSlice(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII); return parseData(channel, remoteAddress, buf, locationPacketId, imei); |