aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-09-27 21:51:29 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-09-27 21:51:29 +1200
commitfefce2dff1931e430deb4d8723d7e8362b7e7698 (patch)
tree8ba373f0bff00c6250546dc62cca2fb0c55e9ee1
parent38e77023844a5c76112ed79ddf8308cedfc3e099 (diff)
downloadtrackermap-server-fefce2dff1931e430deb4d8723d7e8362b7e7698.tar.gz
trackermap-server-fefce2dff1931e430deb4d8723d7e8362b7e7698.tar.bz2
trackermap-server-fefce2dff1931e430deb4d8723d7e8362b7e7698.zip
Support Vodofo protocol
-rw-r--r--src/org/traccar/protocol/UproProtocolDecoder.java36
-rw-r--r--test/org/traccar/protocol/UproProtocolDecoderTest.java6
2 files changed, 35 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/UproProtocolDecoder.java b/src/org/traccar/protocol/UproProtocolDecoder.java
index 1c2944a6c..7efe3b94f 100644
--- a/src/org/traccar/protocol/UproProtocolDecoder.java
+++ b/src/org/traccar/protocol/UproProtocolDecoder.java
@@ -31,7 +31,6 @@ import org.traccar.model.Position;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
-import java.text.ParseException;
import java.util.regex.Pattern;
public class UproProtocolDecoder extends BaseProtocolDecoder {
@@ -42,7 +41,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN_HEADER = new PatternBuilder()
.text("*")
- .expression("..20")
+ .expression("(..20)") // head
.expression("([01])") // ack
.number("(d+),") // device id
.expression("(.)") // type
@@ -96,7 +95,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
ByteBuf buf = (ByteBuf) msg;
if (buf.getByte(buf.readerIndex()) != '*') {
- throw new ParseException(null, 0);
+ return null;
}
int headerIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '&');
@@ -110,6 +109,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ String head = parser.next();
boolean reply = parser.next().equals("1");
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
@@ -124,7 +124,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
String subtype = parser.next();
if (reply && channel != null) {
- channel.writeAndFlush(new NetworkMessage("*MG20Y" + type + subtype + "#", remoteAddress));
+ channel.writeAndFlush(new NetworkMessage("*" + head + "Y" + type + subtype + "#", remoteAddress));
}
while (buf.isReadable()) {
@@ -155,6 +155,13 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
}
position.set(Position.KEY_ODOMETER, odometer * 2 * 1852 / 3600);
break;
+ case 'F':
+ position.setSpeed(
+ Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)) * 0.1);
+ break;
+ case 'K':
+ position.set("statusExtended", data.toString(StandardCharsets.US_ASCII));
+ break;
case 'P':
position.setNetwork(new Network(CellTower.from(
Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)),
@@ -163,13 +170,28 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII), 16))));
break;
case 'Q':
- position.set("obd-pid", ByteBufUtil.hexDump(data));
+ position.set("obdPid", ByteBufUtil.hexDump(data));
break;
case 'R':
- position.set("odb-travel", ByteBufUtil.hexDump(data));
+ if (head.startsWith("HQ")) {
+ position.set(Position.KEY_RSSI,
+ Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)));
+ position.set(Position.KEY_SATELLITES,
+ Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)));
+ } else {
+ position.set("odbTravel", ByteBufUtil.hexDump(data));
+ }
break;
case 'S':
- position.set("obd-traffic", ByteBufUtil.hexDump(data));
+ position.set("obdTraffic", ByteBufUtil.hexDump(data));
+ break;
+ case 'T':
+ position.set(Position.KEY_BATTERY_LEVEL,
+ Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)));
+ break;
+ case 'V':
+ position.set(Position.KEY_POWER,
+ Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)) * 0.1);
break;
default:
break;
diff --git a/test/org/traccar/protocol/UproProtocolDecoderTest.java b/test/org/traccar/protocol/UproProtocolDecoderTest.java
index 42e3d16cf..4b886902f 100644
--- a/test/org/traccar/protocol/UproProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/UproProtocolDecoderTest.java
@@ -10,6 +10,12 @@ public class UproProtocolDecoderTest extends ProtocolTest {
UproProtocolDecoder decoder = new UproProtocolDecoder(new UproProtocol());
+ verifyPosition(decoder, buffer(
+ "*HQ200999999,AB1&A1656512233362911356523660000230618&B0100060010&C00000<6<&F0000&R2405&V0109&W0000003E&K00100&T65&X(k89860045191536000374)#"));
+
+ verifyPosition(decoder, buffer(
+ "*HQ20113800138000,YAA&A0732142233550011405829060520190314&B0100000000&C00001234&R3109&T80#"));
+
verifyPosition(decoder, binary(
"2a4d473230313836383530303032303030343836372c414226413035303032343138313438373536303636303131373732323030303031313132313626583331302c3236302c34383837322c353639312c37333b34383837322c3732322c38363b34383837322c353639332c38383b34383837322c323336332c39303b34383837322c323336322c393726423030303030303030303026573030264e3230265a31342659313430303323"));