aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/TeltonikaProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index e052b10d5..e4966aabe 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -30,7 +30,7 @@ import org.traccar.model.Event;
import org.traccar.model.Position;
public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
-
+
public TeltonikaProtocolDecoder(TeltonikaProtocol protocol) {
super(protocol);
}
@@ -51,74 +51,74 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
private static final int CODEC_GH3000 = 0x07;
private static final int CODEC_FM4X00 = 0x08;
private static final int CODEC_12 = 0x0C;
-
+
private List<Position> parseLocation(Channel channel, ChannelBuffer buf) {
List<Position> positions = new LinkedList<>();
-
+
buf.skipBytes(4); // marker
buf.readUnsignedInt(); // data length
int codec = buf.readUnsignedByte(); // codec
-
+
if (codec == CODEC_12) {
// TODO: decode serial port data
return null;
}
-
+
int count = buf.readUnsignedByte();
-
+
for (int i = 0; i < count; i++) {
Position position = new Position();
position.setProtocol(getProtocolName());
-
+
position.setDeviceId(getDeviceId());
-
+
int globalMask = 0x0f;
-
+
if (codec == CODEC_GH3000) {
long time = buf.readUnsignedInt() & 0x3fffffff;
time += 1167609600; // 2007-01-01 00:00:00
position.setTime(new Date(time * 1000));
-
+
globalMask = buf.readUnsignedByte();
if (!BitUtil.check(globalMask, 0)) {
return null;
}
-
+
int locationMask = buf.readUnsignedByte();
-
+
if (BitUtil.check(locationMask, 0)) {
position.setLatitude(buf.readFloat());
position.setLongitude(buf.readFloat());
}
-
+
if (BitUtil.check(locationMask, 1)) {
position.setAltitude(buf.readUnsignedShort());
}
-
+
if (BitUtil.check(locationMask, 2)) {
position.setCourse(buf.readUnsignedByte() * 360.0 / 256);
}
-
+
if (BitUtil.check(locationMask, 3)) {
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
}
-
+
if (BitUtil.check(locationMask, 4)) {
int satellites = buf.readUnsignedByte();
position.set(Event.KEY_SATELLITES, satellites);
position.setValid(satellites >= 3);
}
-
+
if (BitUtil.check(locationMask, 5)) {
position.set("area", buf.readUnsignedShort());
position.set(Event.KEY_CELL, buf.readUnsignedShort());
}
-
+
if (BitUtil.check(locationMask, 6)) {
position.set(Event.KEY_GSM, buf.readUnsignedByte());
}
-
+
if (BitUtil.check(locationMask, 7)) {
position.set("operator", buf.readUnsignedInt());
}
@@ -146,7 +146,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // total IO data records
}
-
+
// Read 1 byte data
if (BitUtil.check(globalMask, 1)) {
int cnt = buf.readUnsignedByte();
@@ -185,29 +185,29 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
positions.add(position);
}
-
+
if (channel != null) {
ChannelBuffer response = ChannelBuffers.directBuffer(4);
response.writeInt(count);
channel.write(response);
}
-
+
return positions;
}
-
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg)
throws Exception {
-
+
ChannelBuffer buf = (ChannelBuffer) msg;
-
+
if (buf.getUnsignedShort(0) > 0) {
parseIdentification(channel, buf);
} else {
return parseLocation(channel, buf);
}
-
+
return null;
}