aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/helper/StringUtil.java32
-rw-r--r--src/main/java/org/traccar/protocol/WatchProtocolDecoder.java9
2 files changed, 37 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/helper/StringUtil.java b/src/main/java/org/traccar/helper/StringUtil.java
new file mode 100644
index 000000000..9b4d717f4
--- /dev/null
+++ b/src/main/java/org/traccar/helper/StringUtil.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.helper;
+
+public final class StringUtil {
+
+ private StringUtil() {
+ }
+
+ public static boolean containsHex(String value) {
+ for (char c : value.toCharArray()) {
+ if (c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F') {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
index e100d0dc0..40d56b130 100644
--- a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2023 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.
@@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.StringUtil;
import org.traccar.session.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -139,7 +140,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
String[] values = parser.next().split(",");
int index = 0;
- if (values.length < 4 || !values[index + 3].startsWith("F")) {
+ if (values.length < 4 || !StringUtil.containsHex(values[index + 3])) {
Network network = new Network();
@@ -150,8 +151,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0;
for (int i = 0; i < cellCount; i++) {
- int lac = Integer.parseInt(values[index++]);
- int cid = Integer.parseInt(values[index++]);
+ int lac = Integer.parseInt(values[index], StringUtil.containsHex(values[index++]) ? 16 : 10);
+ int cid = Integer.parseInt(values[index], StringUtil.containsHex(values[index++]) ? 16 : 10);
String rssi = values[index++];
if (!rssi.isEmpty()) {
network.addCellTower(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(rssi)));