diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/FilterHandler.java | 13 | ||||
-rw-r--r-- | src/org/traccar/protocol/AquilaProtocolDecoder.java | 22 | ||||
-rw-r--r-- | src/org/traccar/protocol/DmtProtocolDecoder.java | 52 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gl200TextProtocolDecoder.java | 5 |
4 files changed, 66 insertions, 26 deletions
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 1cf4ccd86..93f71d4e1 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -26,6 +26,7 @@ public class FilterHandler extends BaseDataHandler { private boolean filterDuplicate; private long filterFuture; private boolean filterApproximate; + private int filterAccuracy; private boolean filterStatic; private int filterDistance; private int filterMaxSpeed; @@ -48,6 +49,10 @@ public class FilterHandler extends BaseDataHandler { this.filterFuture = filterFuture; } + public void setFilterAccuracy(int filterAccuracy) { + this.filterAccuracy = filterAccuracy; + } + public void setFilterApproximate(boolean filterApproximate) { this.filterApproximate = filterApproximate; } @@ -79,6 +84,7 @@ public class FilterHandler extends BaseDataHandler { filterZero = config.getBoolean("filter.zero"); filterDuplicate = config.getBoolean("filter.duplicate"); filterFuture = config.getLong("filter.future") * 1000; + filterAccuracy = config.getInteger("filter.accuracy"); filterApproximate = config.getBoolean("filter.approximate"); filterStatic = config.getBoolean("filter.static"); filterDistance = config.getInteger("filter.distance"); @@ -114,6 +120,10 @@ public class FilterHandler extends BaseDataHandler { return filterFuture != 0 && position.getFixTime().getTime() > System.currentTimeMillis() + filterFuture; } + private boolean filterAccuracy(Position position) { + return filterAccuracy != 0 && position.getAccuracy() > filterAccuracy; + } + private boolean filterApproximate(Position position) { return filterApproximate && position.getBoolean(Position.KEY_APPROXIMATE); } @@ -183,6 +193,9 @@ public class FilterHandler extends BaseDataHandler { if (filterFuture(position)) { filterType.append("Future "); } + if (filterAccuracy(position)) { + filterType.append("Accuracy "); + } if (filterApproximate(position)) { filterType.append("Approximate "); } diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java index 638affdc3..d8081612d 100644 --- a/src/org/traccar/protocol/AquilaProtocolDecoder.java +++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java @@ -42,6 +42,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { .number("(dd)(dd)(dd)") // date (yymmdd) .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([AV]),") // validity + .groupBegin() .number("(d+),") // gsm .number("(d+),") // speed .number("(d+),") // distance @@ -120,6 +121,10 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // external voltage .number("(d+),") // internal voltage .groupEnd() + .or() + .number("(d+),") // sensor id + .expression("([^,]+),") // sensor data + .groupEnd() .text("*") .number("xx") // checksum .compile(); @@ -150,11 +155,11 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - position.set(Position.KEY_RSSI, parser.nextInt(0)); - - position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); - - position.set(Position.KEY_ODOMETER, parser.nextInt(0)); + if (parser.hasNext(3)) { + position.set(Position.KEY_RSSI, parser.nextInt(0)); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); + position.set(Position.KEY_ODOMETER, parser.nextInt(0)); + } if (parser.hasNext(9)) { @@ -186,7 +191,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { String dtcs = parser.next(); position.set(Position.KEY_DTCS, dtcs.substring(1, dtcs.length() - 1).replace('|', ' ')); - } else { + } else if (parser.hasNext(10)) { position.setCourse(parser.nextInt(0)); @@ -200,6 +205,11 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_POWER, parser.nextInt(0)); position.set(Position.KEY_BATTERY, parser.nextInt(0)); + } else if (parser.hasNext(2)) { + + position.set("sensorId", parser.nextInt()); + position.set("sensorData", parser.next()); + } return position; diff --git a/src/org/traccar/protocol/DmtProtocolDecoder.java b/src/org/traccar/protocol/DmtProtocolDecoder.java index d7dc545a6..a66156ba2 100644 --- a/src/org/traccar/protocol/DmtProtocolDecoder.java +++ b/src/org/traccar/protocol/DmtProtocolDecoder.java @@ -43,6 +43,24 @@ public class DmtProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_COMMIT = 0x05; public static final int MSG_COMMIT_RESPONSE = 0x06; + public static final int MSG_CANNED_REQUEST_1 = 0x14; + public static final int MSG_CANNED_RESPONSE_1 = 0x15; + public static final int MSG_CANNED_REQUEST_2 = 0x22; + public static final int MSG_CANNED_RESPONSE_2 = 0x23; + + private void sendResponse(Channel channel, int type, ChannelBuffer content) { + if (channel != null) { + ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); + response.writeByte(0x02); response.writeByte(0x55); // header + response.writeByte(type); + response.writeShort(content != null ? content.readableBytes() : 0); + if (content != null) { + response.writeBytes(content); + } + channel.write(response); + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -62,26 +80,26 @@ public class DmtProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession = getDeviceSession( channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII)); - if (channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); - response.writeByte(0x02); response.writeByte(0x55); // header - response.writeByte(MSG_HELLO_RESPONSE); - response.writeShort(4 + 4); - response.writeInt((int) (System.currentTimeMillis() / 1000)); - response.writeInt(deviceSession != null ? 0 : 1); // flags - channel.write(response); - } + ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); + response.writeInt((int) (System.currentTimeMillis() / 1000)); + response.writeInt(deviceSession != null ? 0 : 1); // flags + sendResponse(channel, MSG_HELLO_RESPONSE, response); } else if (type == MSG_COMMIT) { - if (channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); - response.writeByte(0x02); response.writeByte(0x55); // header - response.writeByte(MSG_COMMIT_RESPONSE); - response.writeShort(1); - response.writeByte(1); // flags (success) - channel.write(response); - } + ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); + response.writeByte(1); // flags (success) + sendResponse(channel, MSG_COMMIT_RESPONSE, response); + + } else if (type == MSG_CANNED_REQUEST_1) { + + ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); + response.writeBytes(new byte[12]); + sendResponse(channel, MSG_CANNED_RESPONSE_1, response); + + } else if (type == MSG_CANNED_REQUEST_2) { + + sendResponse(channel, MSG_CANNED_RESPONSE_2, null); } else if (type == MSG_DATA_RECORD) { diff --git a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java index 31325d2f8..d32f0a71f 100644 --- a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java @@ -692,9 +692,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { decodeLocation(position, parser); - // power value only on some devices if (power > 10) { - position.set(Position.KEY_POWER, power); + position.set(Position.KEY_POWER, power * 0.001); // only on some devices } position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); @@ -749,7 +748,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { decodeLocation(position, parser); - position.set(Position.KEY_POWER, power); + position.set(Position.KEY_POWER, power * 0.001); position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000); position.set(Position.KEY_HOURS, parser.next()); position.set(Position.PREFIX_ADC + 1, parser.next()); |