aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/MainModule.java5
-rw-r--r--src/main/java/org/traccar/geocoder/JsonGeocoder.java4
-rw-r--r--src/main/java/org/traccar/handler/CopyAttributesHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/GeocoderHandler.java11
-rw-r--r--src/main/java/org/traccar/protocol/Gs100ProtocolDecoder.java6
-rw-r--r--src/main/java/org/traccar/protocol/ItsProtocolDecoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/StartekProtocolEncoder.java2
-rw-r--r--src/main/java/org/traccar/protocol/UlbotechProtocol.java6
-rw-r--r--src/main/java/org/traccar/protocol/UlbotechProtocolEncoder.java42
-rw-r--r--src/test/java/org/traccar/protocol/Gs100ProtocolDecoderTest.java3
-rw-r--r--src/test/java/org/traccar/protocol/ItsProtocolDecoderTest.java3
-rw-r--r--src/test/java/org/traccar/protocol/StartekProtocolEncoderTest.java2
-rw-r--r--src/test/java/org/traccar/protocol/UlbotechProtocolEncoderTest.java23
13 files changed, 104 insertions, 24 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index 2b7fa5c61..350af6bd7 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -286,10 +286,9 @@ public class MainModule extends AbstractModule {
@Singleton
@Provides
public static GeocoderHandler provideGeocoderHandler(
- Config config, @Nullable Geocoder geocoder, IdentityManager identityManager,
- StatisticsManager statisticsManager) {
+ Config config, @Nullable Geocoder geocoder, IdentityManager identityManager) {
if (geocoder != null) {
- return new GeocoderHandler(config, geocoder, identityManager, statisticsManager);
+ return new GeocoderHandler(config, geocoder, identityManager);
}
return null;
}
diff --git a/src/main/java/org/traccar/geocoder/JsonGeocoder.java b/src/main/java/org/traccar/geocoder/JsonGeocoder.java
index 8c442def3..4f34fb973 100644
--- a/src/main/java/org/traccar/geocoder/JsonGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/JsonGeocoder.java
@@ -18,6 +18,8 @@ package org.traccar.geocoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
+import org.traccar.Main;
+import org.traccar.database.StatisticsManager;
import javax.json.JsonObject;
import javax.ws.rs.ClientErrorException;
@@ -95,6 +97,8 @@ public abstract class JsonGeocoder implements Geocoder {
}
}
+ Main.getInjector().getInstance(StatisticsManager.class).registerGeocoderRequest();
+
Invocation.Builder request = Context.getClient().target(String.format(url, latitude, longitude)).request();
if (callback != null) {
diff --git a/src/main/java/org/traccar/handler/CopyAttributesHandler.java b/src/main/java/org/traccar/handler/CopyAttributesHandler.java
index 3cd7d144d..f386116b0 100644
--- a/src/main/java/org/traccar/handler/CopyAttributesHandler.java
+++ b/src/main/java/org/traccar/handler/CopyAttributesHandler.java
@@ -34,11 +34,6 @@ public class CopyAttributesHandler extends BaseDataHandler {
protected Position handlePosition(Position position) {
String attributesString = identityManager.lookupAttributeString(
position.getDeviceId(), "processing.copyAttributes", "", false, true);
- if (attributesString.isEmpty()) {
- attributesString = Position.KEY_DRIVER_UNIQUE_ID;
- } else {
- attributesString += "," + Position.KEY_DRIVER_UNIQUE_ID;
- }
Position last = identityManager.getLastPosition(position.getDeviceId());
if (last != null) {
for (String attribute : attributesString.split("[ ,]")) {
diff --git a/src/main/java/org/traccar/handler/GeocoderHandler.java b/src/main/java/org/traccar/handler/GeocoderHandler.java
index b96f01b3a..614cf97d6 100644
--- a/src/main/java/org/traccar/handler/GeocoderHandler.java
+++ b/src/main/java/org/traccar/handler/GeocoderHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2021 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.
@@ -24,7 +24,6 @@ import org.traccar.Context;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.IdentityManager;
-import org.traccar.database.StatisticsManager;
import org.traccar.geocoder.Geocoder;
import org.traccar.model.Position;
@@ -35,16 +34,14 @@ public class GeocoderHandler extends ChannelInboundHandlerAdapter {
private final Geocoder geocoder;
private final IdentityManager identityManager;
- private final StatisticsManager statisticsManager;
private final boolean ignorePositions;
private final boolean processInvalidPositions;
private final int geocoderReuseDistance;
public GeocoderHandler(
- Config config, Geocoder geocoder, IdentityManager identityManager, StatisticsManager statisticsManager) {
+ Config config, Geocoder geocoder, IdentityManager identityManager) {
this.geocoder = geocoder;
this.identityManager = identityManager;
- this.statisticsManager = statisticsManager;
ignorePositions = Context.getConfig().getBoolean(Keys.GEOCODER_IGNORE_POSITIONS);
processInvalidPositions = config.getBoolean(Keys.GEOCODER_PROCESS_INVALID_POSITIONS);
geocoderReuseDistance = config.getInteger(Keys.GEOCODER_REUSE_DISTANCE, 0);
@@ -65,10 +62,6 @@ public class GeocoderHandler extends ChannelInboundHandlerAdapter {
}
}
- if (statisticsManager != null) {
- statisticsManager.registerGeocoderRequest();
- }
-
geocoder.getAddress(position.getLatitude(), position.getLongitude(),
new Geocoder.ReverseGeocoderCallback() {
@Override
diff --git a/src/main/java/org/traccar/protocol/Gs100ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gs100ProtocolDecoder.java
index 28a42476c..69232dd55 100644
--- a/src/main/java/org/traccar/protocol/Gs100ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Gs100ProtocolDecoder.java
@@ -99,15 +99,15 @@ public class Gs100ProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(Integer.parseInt(coordinates.substring(10, 12))
+ Integer.parseInt(coordinates.substring(12, 18)) * 0.0001 / 60);
int flags = Integer.parseInt(coordinates.substring(9, 10), 16);
- if (!BitUtil.check(flags, 4)) {
+ if (!BitUtil.check(flags, 3)) {
position.setLongitude(-position.getLongitude());
}
- if (!BitUtil.check(flags, 3)) {
+ if (!BitUtil.check(flags, 2)) {
position.setLatitude(-position.getLatitude());
}
String other = ByteBufUtil.hexDump(buf.readSlice(4));
- position.setSpeed(Integer.parseInt(other.substring(0, 5)));
+ position.setSpeed(Integer.parseInt(other.substring(0, 5)) * 0.01);
position.setCourse(Integer.parseInt(other.substring(5, 8)));
} else {
diff --git a/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java b/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java
index a7e9200f1..9eed58347 100644
--- a/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java
@@ -79,7 +79,7 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.?d*),") // power
.number("(d+.?d*),") // battery
.number("([01]),") // emergency
- .expression("[CO]?,") // tamper
+ .expression("[COYN]?,") // tamper
.expression("(.*),") // cells
.number("([012]{4}),") // inputs
.number("([01]{2}),") // outputs
@@ -100,6 +100,12 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder {
.number("d+,") // index
.number("(d+.?d*),") // adc1
.number("(d+.?d*),") // adc2
+ .or()
+ .number("(d+.d+),") // adc1
+ .number("(d+),") // odometer
+ .number("(d{6}),") // index
+ .expression("([^,]+),") // response format
+ .expression("([^,]+),") // response
.groupEnd("?")
.groupEnd("?")
.or()
@@ -270,6 +276,14 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.PREFIX_ADC + 2, parser.nextDouble());
}
+ if (parser.hasNext(5)) {
+ position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
+ position.set(Position.KEY_ODOMETER, parser.nextInt());
+ position.set(Position.KEY_INDEX, parser.nextInt());
+ position.set("responseFormat", parser.next());
+ position.set("response", parser.next());
+ }
+
if (parser.hasNext(2)) {
position.setAltitude(parser.nextDouble());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
diff --git a/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java b/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java
index a96502f11..300004c5e 100644
--- a/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java
@@ -31,7 +31,7 @@ public class StartekProtocolEncoder extends StringProtocolEncoder {
protected String formatCommand(Command command, String format, String... keys) {
String uniqueId = getUniqueId(command.getDeviceId());
String payload = super.formatCommand(command, format, keys);
- int length = uniqueId.length() + 1 + payload.length();
+ int length = 1 + uniqueId.length() + 1 + payload.length();
String sentence = "$$:" + length + "," + uniqueId + "," + payload;
return sentence + Checksum.sum(sentence) + "\r\n";
}
diff --git a/src/main/java/org/traccar/protocol/UlbotechProtocol.java b/src/main/java/org/traccar/protocol/UlbotechProtocol.java
index b99ec1cc6..dfe5235f0 100644
--- a/src/main/java/org/traccar/protocol/UlbotechProtocol.java
+++ b/src/main/java/org/traccar/protocol/UlbotechProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2021 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.
@@ -18,14 +18,18 @@ package org.traccar.protocol;
import org.traccar.BaseProtocol;
import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
+import org.traccar.model.Command;
public class UlbotechProtocol extends BaseProtocol {
public UlbotechProtocol() {
+ setSupportedDataCommands(
+ Command.TYPE_CUSTOM);
addServer(new TrackerServer(false, getName()) {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast(new UlbotechFrameDecoder());
+ pipeline.addLast(new UlbotechProtocolEncoder(UlbotechProtocol.this));
pipeline.addLast(new UlbotechProtocolDecoder(UlbotechProtocol.this));
}
});
diff --git a/src/main/java/org/traccar/protocol/UlbotechProtocolEncoder.java b/src/main/java/org/traccar/protocol/UlbotechProtocolEncoder.java
new file mode 100644
index 000000000..5528c7242
--- /dev/null
+++ b/src/main/java/org/traccar/protocol/UlbotechProtocolEncoder.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2021 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.protocol;
+
+import io.netty.buffer.Unpooled;
+import org.traccar.BaseProtocolEncoder;
+import org.traccar.Protocol;
+import org.traccar.model.Command;
+
+import java.nio.charset.StandardCharsets;
+
+public class UlbotechProtocolEncoder extends BaseProtocolEncoder {
+
+ public UlbotechProtocolEncoder(Protocol protocol) {
+ super(protocol);
+ }
+
+ @Override
+ protected Object encodeCommand(Command command) {
+ switch (command.getType()) {
+ case Command.TYPE_CUSTOM:
+ return Unpooled.copiedBuffer(
+ "*TS01," + command.getString(Command.KEY_DATA) + "#", StandardCharsets.US_ASCII);
+ default:
+ return null;
+ }
+ }
+
+}
diff --git a/src/test/java/org/traccar/protocol/Gs100ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gs100ProtocolDecoderTest.java
index 91bbf386c..68c9b8219 100644
--- a/src/test/java/org/traccar/protocol/Gs100ProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/Gs100ProtocolDecoderTest.java
@@ -14,6 +14,9 @@ public class Gs100ProtocolDecoderTest extends ProtocolTest {
"474C490F383632343632303332353036373030133839333831303131363039313838343837323546084657312E302E3236"));
verifyPositions(decoder, binary(
+ "47440416900000124833220421018478956c445263460110426616900000124838220421018478907c445263470055824116900000124839220421018478890c445263440091526116900000124840220421018478867c4452634401312272"));
+
+ verifyPositions(decoder, binary(
"47440216900000064113030417020236402C452286650051929716900000064115030417020236408C4522866800379020"));
}
diff --git a/src/test/java/org/traccar/protocol/ItsProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/ItsProtocolDecoderTest.java
index 8277b8843..dfd86969a 100644
--- a/src/test/java/org/traccar/protocol/ItsProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/ItsProtocolDecoderTest.java
@@ -17,6 +17,9 @@ public class ItsProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, text(
"$LGN,,869867037009679,3.2AIH,9.99546000,N,76.35886167,E"));
+ verifyPosition(decoder, text(
+ "$,NRM,MARK,V0.0.1,NR,01,L,358980100040246,000000000,1,10032021,073239,25.932051,N,71.509872,E,0.6,1.40,13,211.2,1.4,0.7,IDEA,0,1,0.1,3.7,0,N,20,404,60,A5F,FD3F,A5F,6F88,29,A5F,5855,18,A5F,6F87,18,A5F,FD41,14,0000,00,0.1,0,000027,0,0,0,4E9C,*"));
+
verifyAttribute(decoder, text(
"$,C,CTPL,4.0.0,NR,01,L,869247045166383,NA00000000,1,12032020,144453,30.452524,N,077.610351,E,1.4,34.8,14,384.19,1.8,0.8,IDEA P,1,1,14.2,4.17,0,C,22,404,82,0FB1,3B26,516B,0FB1,18,3B25,0FB1,15,5169,0FB1,14,3B27,0FB1,13,0000,00,8083,194.9,0B,*,IP=106.67.5.173"),
Position.KEY_ODOMETER, 194900.0);
diff --git a/src/test/java/org/traccar/protocol/StartekProtocolEncoderTest.java b/src/test/java/org/traccar/protocol/StartekProtocolEncoderTest.java
index f23cfb227..7eeb19edf 100644
--- a/src/test/java/org/traccar/protocol/StartekProtocolEncoderTest.java
+++ b/src/test/java/org/traccar/protocol/StartekProtocolEncoderTest.java
@@ -17,7 +17,7 @@ public class StartekProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_STOP);
- assertEquals("$$:23,123456789012345,900,1,19E\r\n", encoder.encodeCommand(null, command));
+ assertEquals("$$:24,123456789012345,900,1,19F\r\n", encoder.encodeCommand(null, command));
}
diff --git a/src/test/java/org/traccar/protocol/UlbotechProtocolEncoderTest.java b/src/test/java/org/traccar/protocol/UlbotechProtocolEncoderTest.java
new file mode 100644
index 000000000..288f8dc70
--- /dev/null
+++ b/src/test/java/org/traccar/protocol/UlbotechProtocolEncoderTest.java
@@ -0,0 +1,23 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+import org.traccar.model.Command;
+
+public class UlbotechProtocolEncoderTest extends ProtocolTest {
+
+ @Test
+ public void testEncode() {
+
+ var encoder = new UlbotechProtocolEncoder(null);
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_CUSTOM);
+ command.set(Command.KEY_DATA, "UNO;13912345678");
+
+ verifyCommand(encoder, command, buffer("*TS01,UNO;13912345678#"));
+
+ }
+
+}