aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/At2000ProtocolDecoder.java57
-rw-r--r--src/org/traccar/protocol/GatorProtocolDecoder.java34
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java55
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java69
5 files changed, 152 insertions, 66 deletions
diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java
index 58b6f44e8..00973f2aa 100644
--- a/src/org/traccar/protocol/At2000ProtocolDecoder.java
+++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java
@@ -31,6 +31,8 @@ import java.net.SocketAddress;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
public class At2000ProtocolDecoder extends BaseProtocolDecoder {
@@ -100,28 +102,55 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
byte[] data = new byte[buf.capacity() - BLOCK_LENGTH];
buf.readBytes(data);
buf = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, cipher.update(data));
- buf.readUnsignedShort(); // index
- buf.readUnsignedShort(); // reserved
+ List<Position> positions = new LinkedList<>();
+
+ while (buf.readableBytes() >= 63) {
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ buf.readUnsignedShort(); // index
+ buf.readUnsignedShort(); // reserved
+
+ position.setValid(true);
+
+ position.setTime(new Date(buf.readLong() * 1000));
- position.setValid(true);
+ position.setLatitude(buf.readFloat());
+ position.setLongitude(buf.readFloat());
+ position.setAltitude(buf.readFloat());
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloat()));
+ position.setCourse(buf.readFloat());
- position.setTime(new Date(buf.readLong() * 1000));
+ buf.readUnsignedInt(); // geozone event
+ buf.readUnsignedInt(); // io events
+ buf.readUnsignedInt(); // geozone value
+ buf.readUnsignedInt(); // io values
+ buf.readUnsignedShort(); // operator
- position.setLatitude(buf.readFloat());
- position.setLongitude(buf.readFloat());
- position.setAltitude(buf.readFloat());
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloat()));
- position.setCourse(buf.readFloat());
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
+
+ position.set(Position.KEY_POWER, buf.readUnsignedShort() + "mV");
+
+ buf.readUnsignedShort(); // cid
+ buf.readUnsignedByte(); // rssi
+ buf.readUnsignedByte(); // current profile
+
+ position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
+ position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte());
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+
+ positions.add(position);
+
+ }
- return position;
+ return positions;
}
diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java
index d9c8a086c..f01efb9d8 100644
--- a/src/org/traccar/protocol/GatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/GatorProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,6 +56,21 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder {
return String.format("%02d%02d%02d%02d%02d", d1, d2, d3, d4, d5);
}
+ private void sendResponse(Channel channel, byte calibration) {
+ if (channel != null) {
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer();
+ response.writeByte(0x24); response.writeByte(0x24); // header
+ response.writeByte(MSG_HEARTBEAT); // size
+ response.writeShort(5);
+ response.writeByte(calibration);
+ response.writeByte(0); // main order
+ response.writeByte(0); // slave order
+ response.writeByte(1); // calibration
+ response.writeByte(0x0D);
+ channel.write(response);
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -70,22 +85,9 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(), buf.readUnsignedByte(),
buf.readUnsignedByte(), buf.readUnsignedByte());
- if (type == MSG_HEARTBEAT) {
-
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeByte(0x24); response.writeByte(0x24); // header
- response.writeByte(MSG_HEARTBEAT); // size
- response.writeShort(5);
- response.writeByte(buf.readUnsignedByte());
- response.writeByte(0); // main order
- response.writeByte(0); // slave order
- response.writeByte(1); // calibration
- response.writeByte(0x0D);
- channel.write(response);
- }
+ sendResponse(channel, buf.getByte(buf.writerIndex() - 2));
- } else if (type == MSG_POSITION_DATA || type == MSG_ROLLCALL_RESPONSE
+ if (type == MSG_POSITION_DATA || type == MSG_ROLLCALL_RESPONSE
|| type == MSG_ALARM_DATA || type == MSG_BLIND_AREA) {
Position position = new Position();
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index c2a3b2b09..37f6294be 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -66,19 +66,18 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
}
private void processStatus(Position position, long status) {
- if (!BitUtil.check(status, 0) || !BitUtil.check(status, 1)
- || !BitUtil.check(status, 2)) {
-
- if (!BitUtil.check(status, 0)) {
- position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
- } else if (!BitUtil.check(status, 1)) {
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- } else if (!BitUtil.check(status, 2)) {
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- }
+
+ if (!BitUtil.check(status, 0)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
+ } else if (!BitUtil.check(status, 1)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ } else if (!BitUtil.check(status, 2)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
}
+
position.set(Position.KEY_IGNITION, !BitUtil.check(status, 10));
position.set(Position.KEY_STATUS, status);
+
}
private String decodeBattery(int value) {
@@ -245,16 +244,6 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
processStatus(position, parser.nextLong(16));
- if (parser.hasNext(4)) {
- int mcc = parser.nextInt(16);
- int mnc = parser.nextInt(16);
- int lac = parser.nextInt(16);
- int cid = parser.nextInt(16);
- if (mcc != 0 && mnc != 0 && lac != 0 && cid != 0) {
- position.setNetwork(new Network(CellTower.from(mcc, mnc, lac, cid)));
- }
- }
-
return position;
}
@@ -305,20 +294,20 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
String marker = buf.toString(0, 1, StandardCharsets.US_ASCII);
- if (marker.equals("*")) {
- String sentence = buf.toString(StandardCharsets.US_ASCII);
- if (sentence.contains(",NBR,")) {
- return decodeLbs(sentence, channel, remoteAddress);
- } else {
- return decodeText(sentence, channel, remoteAddress);
- }
- } else if (marker.equals("$")) {
- return decodeBinary(buf, channel, remoteAddress);
- } else if (marker.equals("X")) {
- return null; // X mode
+ switch (marker) {
+ case "*":
+ String sentence = buf.toString(StandardCharsets.US_ASCII);
+ if (sentence.contains(",NBR,")) {
+ return decodeLbs(sentence, channel, remoteAddress);
+ } else {
+ return decodeText(sentence, channel, remoteAddress);
+ }
+ case "$":
+ return decodeBinary(buf, channel, remoteAddress);
+ case "X":
+ default:
+ return null;
}
-
- return null;
}
}
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index 5508cad92..382865e8f 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -119,6 +119,9 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
case "altitude":
position.setAltitude(Double.parseDouble(value));
break;
+ case "accuracy":
+ position.setAccuracy(Double.parseDouble(value));
+ break;
case "hdop":
position.set(Position.KEY_HDOP, Double.parseDouble(value));
break;
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index 07df2de13..4a48fe7b6 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,11 +18,15 @@ package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
+import org.traccar.model.CellTower;
+import org.traccar.model.Network;
import org.traccar.model.Position;
+import org.traccar.model.WifiAccessPoint;
import java.net.SocketAddress;
import java.util.Date;
@@ -56,11 +60,13 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.?d*),") // course
.number("(d+.?d*),") // altitude
.number("(d+),") // satellites
- .number("(d+),") // gsm
+ .number("(d+),") // rssi
.number("(d+),") // battery
.number("(d+),") // steps
.number("d+,") // tumbles
- .any()
+ .number("(x+),") // status
+ .expression("([^\\]]*)") // cell and wifi
+ .text("]").optional()
.compile();
private void sendResponse(Channel channel, String manufacturer, String id, String content) {
@@ -70,6 +76,59 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private String decodeAlarm(int status) {
+ if (BitUtil.check(status, 0)) {
+ return Position.ALARM_LOW_BATTERY;
+ } else if (BitUtil.check(status, 1)) {
+ return Position.ALARM_GEOFENCE_EXIT;
+ } else if (BitUtil.check(status, 2)) {
+ return Position.ALARM_GEOFENCE_ENTER;
+ } else if (BitUtil.check(status, 3)) {
+ return Position.ALARM_OVERSPEED;
+ } else if (BitUtil.check(status, 16)) {
+ return Position.ALARM_SOS;
+ } else if (BitUtil.check(status, 17)) {
+ return Position.ALARM_LOW_BATTERY;
+ } else if (BitUtil.check(status, 18)) {
+ return Position.ALARM_GEOFENCE_EXIT;
+ } else if (BitUtil.check(status, 19)) {
+ return Position.ALARM_GEOFENCE_ENTER;
+ }
+ return null;
+ }
+
+ private void decodeTail(Position position, String data) {
+ String[] values = data.split(",");
+ int index = 0;
+
+ Network network = new Network();
+
+ int cellCount = Integer.parseInt(values[index++]);
+ index += 1; // timing advance
+ int mcc = Integer.parseInt(values[index++]);
+ int mnc = Integer.parseInt(values[index++]);
+
+ for (int i = 0; i < cellCount; i++) {
+ network.addCellTower(CellTower.from(mcc, mnc,
+ Integer.parseInt(values[index++]), Integer.parseInt(values[index++]),
+ Integer.parseInt(values[index++])));
+ }
+
+ if (index < values.length && !values[index].isEmpty()) {
+ int wifiCount = Integer.parseInt(values[index++]);
+
+ for (int i = 0; i < wifiCount; i++) {
+ index += 1; // wifi name
+ network.addWifiAccessPoint(WifiAccessPoint.from(
+ values[index++], Integer.parseInt(values[index++])));
+ }
+ }
+
+ if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
+ position.setNetwork(network);
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -141,6 +200,10 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
position.set("steps", parser.nextInt());
+ position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt(16)));
+
+ decodeTail(position, parser.next());
+
return position;
} else if (type.equals("TKQ")) {