aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2022-06-29 07:03:28 -0700
committerGitHub <noreply@github.com>2022-06-29 07:03:28 -0700
commitcd8ac19111d704e0257acc07ce104d47c857f778 (patch)
tree148519c356dc9bf2192466433d23b09dc69f8c13
parent9345f8e086105ba30e9e9cf87b3fc5b0740d68e8 (diff)
parent627c077b4134b9ed31236b1c4dbd219091c22a77 (diff)
downloadtrackermap-server-cd8ac19111d704e0257acc07ce104d47c857f778.tar.gz
trackermap-server-cd8ac19111d704e0257acc07ce104d47c857f778.tar.bz2
trackermap-server-cd8ac19111d704e0257acc07ce104d47c857f778.zip
Merge pull request #4877 from wkhaksar/watch-protocol-and-no-cell-towers
Fix for watch protocol with no cell towers
-rw-r--r--src/main/java/org/traccar/protocol/WatchProtocolDecoder.java9
-rw-r--r--src/test/java/org/traccar/ProtocolTest.java21
-rw-r--r--src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java3
3 files changed, 24 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
index 35fdc3ca5..a71c5606d 100644
--- a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
@@ -142,8 +142,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
Network network = new Network();
int cellCount = Integer.parseInt(values[index++]);
- index += 1; // timing advance
if (cellCount > 0) {
+ index += 1; // timing advance
int mcc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0;
int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0;
@@ -164,8 +164,11 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
for (int i = 0; i < wifiCount; i++) {
index += 1; // wifi name
- network.addWifiAccessPoint(WifiAccessPoint.from(
- values[index++], Integer.parseInt(values[index++])));
+ String macAddress = values[index++];
+ String rssi = values[index++];
+ if (!macAddress.isEmpty() && !macAddress.equals("0") && !rssi.isEmpty()) {
+ network.addWifiAccessPoint(WifiAccessPoint.from(macAddress, Integer.parseInt(rssi)));
+ }
}
}
diff --git a/src/test/java/org/traccar/ProtocolTest.java b/src/test/java/org/traccar/ProtocolTest.java
index 353593c29..3e27bbe28 100644
--- a/src/test/java/org/traccar/ProtocolTest.java
+++ b/src/test/java/org/traccar/ProtocolTest.java
@@ -14,6 +14,7 @@ import org.traccar.helper.DataConverter;
import org.traccar.model.CellTower;
import org.traccar.model.Command;
import org.traccar.model.Position;
+import org.traccar.model.WifiAccessPoint;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
@@ -310,12 +311,20 @@ public class ProtocolTest extends BaseTest {
assertTrue(attributes.get(Position.KEY_RESULT) instanceof String);
}
- if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) {
- for (CellTower cellTower : position.getNetwork().getCellTowers()) {
- checkInteger(cellTower.getMobileCountryCode(), 0, 999);
- checkInteger(cellTower.getMobileNetworkCode(), 0, 999);
- checkInteger(cellTower.getLocationAreaCode(), 1, 65535);
- checkInteger(cellTower.getCellId(), 0, 268435455);
+ if (position.getNetwork() != null) {
+ if (position.getNetwork().getCellTowers() != null) {
+ for (CellTower cellTower : position.getNetwork().getCellTowers()) {
+ checkInteger(cellTower.getMobileCountryCode(), 0, 999);
+ checkInteger(cellTower.getMobileNetworkCode(), 0, 999);
+ checkInteger(cellTower.getLocationAreaCode(), 1, 65535);
+ checkInteger(cellTower.getCellId(), 0, 268435455);
+ }
+ }
+
+ if (position.getNetwork().getWifiAccessPoints() != null) {
+ for (WifiAccessPoint wifiAccessPoint : position.getNetwork().getWifiAccessPoints()) {
+ assertTrue("validation failed for mac address with zero value", !wifiAccessPoint.getMacAddress().equals("0"));
+ }
}
}
diff --git a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java
index 6f6298ffa..7eb167a74 100644
--- a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java
@@ -142,6 +142,9 @@ public class WatchProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, buffer(
"[ZJ*014111001350304*0038*008a*UD,070318,021027,V,00.000000,N,000.000000,E,0,0,0,0,100,18,1000,50,00000000,4,255,460,0,9346,5223,42,9346,5214,20,9784,4083,11,9346,5221,5]"));
+
+ verifyPosition(decoder, buffer(
+ "[3G*8800000015*00DD*UD,010120,025946,V,0.0,N,0.0,E,22.0,0,-1,0,100,98,0,0,00000000,0,5,eduroam,f4:db:e6:d2:a8:00,-53,eduroam,f4:db:e6:da:d0:80,-79,eduroam,78:0c:f0:24:f9:80,-82,Lions,b0:be:76:0a:05:9a,-82,tubs-guest,f4:db:e6:d2:a8:01,-53,0.0]"));
}