aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/model/Network.java6
-rw-r--r--src/main/java/org/traccar/protocol/GoSafeProtocolDecoder.java59
-rw-r--r--src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java2
-rw-r--r--src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java5
-rw-r--r--src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java11
-rw-r--r--src/test/java/org/traccar/protocol/GoSafeProtocolDecoderTest.java3
-rw-r--r--src/test/java/org/traccar/protocol/Minifinder2ProtocolDecoderTest.java6
-rw-r--r--src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java3
-rw-r--r--src/test/java/org/traccar/protocol/TaipProtocolDecoderTest.java3
9 files changed, 58 insertions, 40 deletions
diff --git a/src/main/java/org/traccar/model/Network.java b/src/main/java/org/traccar/model/Network.java
index 2d56950f1..4d67fc5d8 100644
--- a/src/main/java/org/traccar/model/Network.java
+++ b/src/main/java/org/traccar/model/Network.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 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.
@@ -30,6 +30,10 @@ public class Network {
addCellTower(cellTower);
}
+ public Network(WifiAccessPoint wifiAccessPoint) {
+ addWifiAccessPoint(wifiAccessPoint);
+ }
+
private Integer homeMobileCountryCode;
public Integer getHomeMobileCountryCode() {
diff --git a/src/main/java/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/main/java/org/traccar/protocol/GoSafeProtocolDecoder.java
index 95ef18f20..8164a016d 100644
--- a/src/main/java/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/GoSafeProtocolDecoder.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.
@@ -30,7 +30,8 @@ import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.util.Date;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
@@ -45,8 +46,6 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.text("*GS") // header
.number("d+,") // protocol version
.number("(d+),") // imei
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .number("(dd)(dd)(dd),") // date (ddmmyy)
.expression("([^#]*)#?") // data
.compile();
@@ -68,6 +67,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.compile();
private void decodeFragment(Position position, String fragment) {
+
int dataIndex = fragment.indexOf(':');
int index = 0;
String[] values;
@@ -76,6 +76,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
} else {
values = fragment.substring(dataIndex + 1).split(";");
}
+
switch (fragment.substring(0, dataIndex)) {
case "GPS":
position.setValid(values[index++].equals("A"));
@@ -171,42 +172,27 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
}
}
- private Object decodeData(DeviceSession deviceSession, Date time, String data) {
-
- List<Position> positions = new LinkedList<>();
- Position position = null;
- int index = 0;
- String[] fragments = data.split(",");
+ private Position decodePosition(DeviceSession deviceSession, String sentence) throws ParseException {
- while (index < fragments.length) {
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
- if (fragments[index].isEmpty() || Character.isDigit(fragments[index].charAt(0))) {
-
- if (position != null) {
- positions.add(position);
- }
+ int index = 0;
+ String[] fragments = sentence.split(",");
- position = new Position(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
- position.setTime(time);
+ position.setTime(new SimpleDateFormat("HHmmssddMMyy").parse(fragments[index++]));
- if (!fragments[index++].isEmpty()) {
- position.set(Position.KEY_EVENT, Integer.parseInt(fragments[index - 1]));
+ for (; index < fragments.length; index += 1) {
+ if (!fragments[index].isEmpty()) {
+ if (Character.isDigit(fragments[index].charAt(0))) {
+ position.set(Position.KEY_EVENT, Integer.parseInt(fragments[index]));
+ } else {
+ decodeFragment(position, fragments[index]);
}
-
- } else {
-
- decodeFragment(position, fragments[index++]);
-
}
-
}
- if (position != null) {
- positions.add(position);
- }
-
- return positions;
+ return position;
}
@Override
@@ -256,12 +242,11 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
} else {
- Date time = new Date();
- if (parser.hasNext(6)) {
- time = parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY);
+ List<Position> positions = new LinkedList<>();
+ for (String item : parser.next().split("$")) {
+ positions.add(decodePosition(deviceSession, item));
}
-
- return decodeData(deviceSession, time, parser.next());
+ return positions;
}
}
diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
index d942edbfe..ee28a5062 100644
--- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -814,7 +814,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
if (subType == 0x00) {
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort() * 0.01);
return position;
} else if (subType == 0x05) {
int flags = buf.readUnsignedByte();
diff --git a/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java
index 989aa32b9..75c8b11d3 100644
--- a/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java
@@ -33,6 +33,7 @@ import org.traccar.model.WifiAccessPoint;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
+import java.util.Date;
public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder {
@@ -149,6 +150,10 @@ public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder {
mac.substring(0, mac.length() - 1), rssi));
}
break;
+ case 0x24:
+ position.setTime(new Date(buf.readUnsignedIntLE() * 1000));
+ position.set(Position.KEY_STATUS, buf.readUnsignedIntLE());
+ break;
case 0x40:
buf.readUnsignedIntLE(); // timestamp
int heartRate = buf.readUnsignedByte();
diff --git a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
index e9a943e0e..0e0d8d608 100644
--- a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
@@ -16,6 +16,7 @@
package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.FullHttpRequest;
@@ -25,7 +26,9 @@ import org.traccar.DeviceSession;
import org.traccar.Protocol;
import org.traccar.helper.DataConverter;
import org.traccar.helper.UnitsConverter;
+import org.traccar.model.Network;
import org.traccar.model.Position;
+import org.traccar.model.WifiAccessPoint;
import javax.json.Json;
import javax.json.JsonObject;
@@ -104,7 +107,9 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
break;
case 0x06:
- buf.skipBytes(7); // wifi
+ String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
+ position.setNetwork(new Network(WifiAccessPoint.from(
+ mac.substring(0, mac.length() - 1), buf.readUnsignedByte())));
break;
case 0x07:
buf.skipBytes(10); // wifi extended
@@ -126,6 +131,10 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
buf.release();
}
+ if (position.getLatitude() == 0 && position.getLongitude() == 0) {
+ getLastLocation(position, position.getDeviceTime());
+ }
+
if (json.containsKey("rssi")) {
position.set(Position.KEY_RSSI, json.getJsonNumber("rssi").doubleValue());
}
diff --git a/src/test/java/org/traccar/protocol/GoSafeProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/GoSafeProtocolDecoderTest.java
index 70c86bb23..4fbfa6fc1 100644
--- a/src/test/java/org/traccar/protocol/GoSafeProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/GoSafeProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class GoSafeProtocolDecoderTest extends ProtocolTest {
GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(null);
verifyPositions(decoder, text(
+ "*GS06,860078024206844,075029250619,,SYS:G3SC;V3.37;V1.1.8,GPS:A;10;N3.009522;E101.512320;5;137;31;0.69,COT:27376703,ADC:25.81;4.28;2.60,DTT:5004;E1;0;0;0;3$075031250619,,SYS:G3SC;V3.37;V1.1.8,GPS:A;9;N3.009488;E101.512344;6;145;31;0.76,COT:27376703,ADC:25.58;4.25;2.28,DTT:5004;E1;0;0;0;3$075033250619,,SYS:G3SC;V3.37;V1.1.8,GPS:A;10;N3.009459;E101.512360;5;152;31;0.69,COT:27376722,ADC:25.78;4.29;2.30,DTT:5004;E1;0;0;0;3#"));
+
+ verifyPositions(decoder, text(
"*GS06,860078024226974,101437211218,,SYS:G3SC;V3.36;V1.1.8,GPS:A;7;N3.052302;E101.787216;16;137;48;1.58,COT:4261733103,ADC:22.86;0.58;0.01,DTT:4004;E1;0;0;0;3$101439211218,,SYS:G3SC;V3.36;V1.1.8,GPS:A;8;N3.052265;E101.787200;12;152;46;1.31,COT:4261733103,ADC:22.98;0.58;0.01,DTT:4004;E1;0;0;0;3$101441211218,,SYS:G3SC;V3.36;V1.1.8,GPS:A;8;N3.052247;E101.787232;8;131;46;1.34,COT:4261733103,ADC:23.13;0.58;0.01,DTT:4004;E1;0;0;0;3$101510211218,,SYS:G3SC;V3.36;V1.1.8,GPS:A;8;N3.052150;E101.787152;0;131;40;0.97,COT:4261733160,ADC:22.88;0.58;0.01,DTT:4000;E1;0;0;0;1$101540211218,,SYS:G3SC;V3.36;V1.1.8,GPS:A;7;N3.052150;E101.787152;0;131;40;0.97,COT:4261733160,ADC:22.91;0.58;0.00,DTT:4000;E1;0;0;0;1#"));
verifyPositions(decoder, text(
diff --git a/src/test/java/org/traccar/protocol/Minifinder2ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Minifinder2ProtocolDecoderTest.java
index 2b1fdf988..c0ce67cb6 100644
--- a/src/test/java/org/traccar/protocol/Minifinder2ProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/Minifinder2ProtocolDecoderTest.java
@@ -10,6 +10,12 @@ public class Minifinder2ProtocolDecoderTest extends ProtocolTest {
Minifinder2ProtocolDecoder decoder = new Minifinder2ProtocolDecoder(null);
+ verifyNull(decoder, binary(
+ "ab10150076f1320003100133353534363530373130323933303602105a"));
+
+ verifyPosition(decoder, binary(
+ "ab103f007e2533000110013335353436353037313032393330360930e09d245d210100000924b49e245d01025b201620e6c03b1ef367420400000000aa026d00c90e0000100110"));
+
verifyAttributes(decoder, binary(
"ab1845005d39370301100133353836383830303030303338303209245b92b55c84004b610502001000002221ca00050b4a005cc30f4a0056c80f4a003ba90e4a0055c8074a005dc3034a0057c8"));
diff --git a/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java
index b8ef735ce..7e7fc24bc 100644
--- a/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class SigfoxProtocolDecoderTest extends ProtocolTest {
SigfoxProtocolDecoder decoder = new SigfoxProtocolDecoder(null);
+ verifyAttributes(decoder, request(HttpMethod.POST, "/",
+ buffer("{ \"device\": \"40D310\", \"payload\": \"20061494480389f956042a\", \"time\": 1563043532, \"seqNumber\": 1076 }")));
+
verifyPosition(decoder, request(HttpMethod.POST, "/",
buffer("{ \"device\": \"1CEDCE\", \"payload\": \"2002419b4a91c2c6580e0564\", \"time\": 1559924939, \"seqNumber\": 87 }")));
diff --git a/src/test/java/org/traccar/protocol/TaipProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TaipProtocolDecoderTest.java
index bdbaec8aa..0b9eacb8d 100644
--- a/src/test/java/org/traccar/protocol/TaipProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/TaipProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class TaipProtocolDecoderTest extends ProtocolTest {
TaipProtocolDecoder decoder = new TaipProtocolDecoder(null);
+ verifyNull(decoder, text(
+ ">RLN25601000+297185103-0955755990+000059150000+0000000012000000000000000000000000000000000000000000000000000000000012;ID=3580;*48<"));
+
verifyPosition(decoder, text(
">RGP211217112154-2748332-058946350000000FF7F2100;ID=AA01;#0002;*2D<"));