aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/BoxProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/CguardProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/EnforaProtocol.java9
-rw-r--r--src/org/traccar/protocol/FifotrackProtocol.java2
-rw-r--r--src/org/traccar/protocol/FifotrackProtocolDecoder.java83
-rw-r--r--src/org/traccar/protocol/ItsProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/L100ProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/OwnTracksProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java2
9 files changed, 114 insertions, 24 deletions
diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java
index 9f3ce29b2..d7b401a2d 100644
--- a/src/org/traccar/protocol/BoxProtocolDecoder.java
+++ b/src/org/traccar/protocol/BoxProtocolDecoder.java
@@ -20,6 +20,7 @@ import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
@@ -84,16 +85,16 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder {
position.setTime(parser.nextDateTime());
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
+ position.setLatitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
+ position.setCourse(parser.nextDouble());
- position.set(Position.KEY_ODOMETER_TRIP, parser.nextDouble(0) * 1000);
+ position.set(Position.KEY_ODOMETER_TRIP, parser.nextDouble() * 1000);
position.set(Position.KEY_EVENT, parser.next());
- int status = parser.nextInt(0);
- position.setValid((status & 0x04) == 0);
+ int status = parser.nextInt();
+ position.setValid(!BitUtil.check(status, 2));
position.set(Position.KEY_STATUS, status);
return position;
diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java
index 9786afd6a..d934921f1 100644
--- a/src/org/traccar/protocol/CguardProtocolDecoder.java
+++ b/src/org/traccar/protocol/CguardProtocolDecoder.java
@@ -101,7 +101,11 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
break;
case "BAT1":
- position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(value));
+ if (value.contains(".")) {
+ position.set(Position.KEY_BATTERY, Double.parseDouble(value));
+ } else {
+ position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(value));
+ }
break;
case "PWR1":
position.set(Position.KEY_POWER, Double.parseDouble(value));
diff --git a/src/org/traccar/protocol/EnforaProtocol.java b/src/org/traccar/protocol/EnforaProtocol.java
index 3bbbee6a2..f78e4b377 100644
--- a/src/org/traccar/protocol/EnforaProtocol.java
+++ b/src/org/traccar/protocol/EnforaProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2019 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.
@@ -36,6 +36,13 @@ public class EnforaProtocol extends BaseProtocol {
pipeline.addLast(new EnforaProtocolDecoder(EnforaProtocol.this));
}
});
+ addServer(new TrackerServer(true, getName()) {
+ @Override
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
+ pipeline.addLast(new EnforaProtocolEncoder());
+ pipeline.addLast(new EnforaProtocolDecoder(EnforaProtocol.this));
+ }
+ });
}
}
diff --git a/src/org/traccar/protocol/FifotrackProtocol.java b/src/org/traccar/protocol/FifotrackProtocol.java
index 5de581c7a..371e01e55 100644
--- a/src/org/traccar/protocol/FifotrackProtocol.java
+++ b/src/org/traccar/protocol/FifotrackProtocol.java
@@ -17,6 +17,7 @@ package org.traccar.protocol;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
@@ -28,6 +29,7 @@ public class FifotrackProtocol extends BaseProtocol {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast(new LineBasedFrameDecoder(1024));
+ pipeline.addLast(new StringEncoder());
pipeline.addLast(new StringDecoder());
pipeline.addLast(new FifotrackProtocolDecoder(FifotrackProtocol.this));
}
diff --git a/src/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/org/traccar/protocol/FifotrackProtocolDecoder.java
index 4412df86b..5831a75dd 100644
--- a/src/org/traccar/protocol/FifotrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/FifotrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2019 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.
@@ -15,10 +15,15 @@
*/
package org.traccar.protocol;
+import io.netty.buffer.ByteBuf;
+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.Protocol;
+import org.traccar.helper.Checksum;
+import org.traccar.helper.DataConverter;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
@@ -31,6 +36,8 @@ import java.util.regex.Pattern;
public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
+ private ByteBuf photo;
+
public FifotrackProtocolDecoder(Protocol protocol) {
super(protocol);
}
@@ -65,11 +72,43 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ private static final Pattern PATTERN_PHOTO = new PatternBuilder()
+ .text("$$")
+ .number("d+,") // length
+ .number("(d+),") // imei
+ .any()
+ .number("(d+),") // length
+ .expression("([^*]+)") // photo id
+ .text("*")
+ .number("xx")
+ .compile();
+
+ private static final Pattern PATTERN_PHOTO_DATA = new PatternBuilder()
+ .text("$$")
+ .number("d+,") // length
+ .number("(d+),") // imei
+ .expression("([^*]+)") // photo id
+ .number("(d+),") // offset
+ .number("(d+),") // size
+ .number("(x+)") // data
+ .text("*")
+ .number("xx")
+ .compile();
- Parser parser = new Parser(PATTERN, (String) msg);
+ private void requestPhoto(Channel channel, SocketAddress socketAddress, String imei, String file) {
+ if (channel != null) {
+ String content = "D06," + file + "," + photo.writerIndex() + "," + Math.min(1024, photo.writableBytes());
+ int length = 1 + imei.length() + 1 + content.length() + 5;
+ String response = String.format("@@%02d,%s,%s*", length, imei, content);
+ response += Checksum.sum(response) + "\r\n";
+ channel.writeAndFlush(new NetworkMessage(response, socketAddress));
+ }
+ }
+
+ private Object decodeLocation(
+ Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
@@ -122,4 +161,38 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+ int typeIndex = sentence.indexOf(',', sentence.indexOf(',', sentence.indexOf(',') + 1) + 1) + 1;
+ String type = sentence.substring(typeIndex, typeIndex + 3);
+
+ if (type.equals("D05")) {
+ Parser parser = new Parser(PATTERN_PHOTO, sentence);
+ if (parser.matches()) {
+ String imei = parser.next();
+ int length = parser.nextInt();
+ String photoId = parser.next();
+ photo = Unpooled.buffer(length);
+ requestPhoto(channel, remoteAddress, imei, photoId);
+ }
+ } else if (type.equals("D06")) {
+ Parser parser = new Parser(PATTERN_PHOTO_DATA, sentence);
+ if (parser.matches()) {
+ String imei = parser.next();
+ String photoId = parser.next();
+ parser.nextInt(); // offset
+ parser.nextInt(); // size
+ photo.writeBytes(DataConverter.parseHex(parser.next()));
+ requestPhoto(channel, remoteAddress, imei, photoId);
+ }
+ } else {
+ return decodeLocation(channel, remoteAddress, sentence);
+ }
+
+ return null;
+ }
+
}
diff --git a/src/org/traccar/protocol/ItsProtocolDecoder.java b/src/org/traccar/protocol/ItsProtocolDecoder.java
index e2b1dc238..a200ff8b7 100644
--- a/src/org/traccar/protocol/ItsProtocolDecoder.java
+++ b/src/org/traccar/protocol/ItsProtocolDecoder.java
@@ -36,22 +36,22 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN = new PatternBuilder()
.expression("[^$]*")
- .text("$,")
- .expression("[^,]+,") // event
+ .text("$")
+ .expression(",?[^,]+,") // event
.groupBegin()
.expression("[^,]+,") // vendor
.expression("[^,]+,") // firmware version
- .groupEnd("?")
.expression("[^,]+,") // type
- .groupBegin()
.number("d+,")
.expression("[LH],") // history
- .groupEnd("?")
+ .or()
+ .expression("[^,]+,") // type
+ .groupEnd()
.number("(d{15}),") // imei
.groupBegin()
.expression("(?:NM|SP),") // status
.or()
- .expression("[^,]+,") // vehicle registration
+ .expression("[^,]*,") // vehicle registration
.number("([01]),") // valid
.groupEnd()
.number("(dd),?(dd),?(dddd),") // date (ddmmyyyy)
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java
index 4d6b8f34b..9868de435 100644
--- a/src/org/traccar/protocol/L100ProtocolDecoder.java
+++ b/src/org/traccar/protocol/L100ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2019 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.
@@ -189,6 +189,10 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt(), rssi)));
}
+ if (channel != null) {
+ channel.writeAndFlush(new NetworkMessage(String.valueOf((char) 0x01), remoteAddress));
+ }
+
return position;
}
diff --git a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
index 4ce880316..323d97fa3 100644
--- a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
+++ b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
@@ -56,7 +56,7 @@ public class OwnTracksProtocolDecoder extends BaseHttpProtocolDecoder {
return null;
}
- Position position = new Position();
+ Position position = new Position(getProtocolName());
String uniqueId;
if (root.containsKey("topic")) {
@@ -84,7 +84,6 @@ public class OwnTracksProtocolDecoder extends BaseHttpProtocolDecoder {
}
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
position.setTime(new Date(root.getJsonNumber("tst").longValue() * 1000));
if (root.containsKey("sent")) {
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index c80cd9cda..974d2c106 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -97,7 +97,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
response.writeByte(1); // nod
response.writeShort(0);
response.writeShort(Checksum.crc16(
- Checksum.CRC16_IBM, response.nioBuffer(8, response.readableBytes() - 8)));
+ Checksum.CRC16_IBM, response.nioBuffer(8, response.readableBytes() - 10)));
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
}