aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/ItsProtocol.java6
-rw-r--r--src/main/java/org/traccar/protocol/ItsProtocolDecoder.java6
-rw-r--r--src/main/java/org/traccar/protocol/ItsProtocolEncoder.java36
-rw-r--r--src/test/java/org/traccar/protocol/ItsProtocolDecoderTest.java3
-rw-r--r--src/test/java/org/traccar/protocol/ItsProtocolEncoderTest.java24
5 files changed, 71 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/ItsProtocol.java b/src/main/java/org/traccar/protocol/ItsProtocol.java
index e074f9277..45df3da11 100644
--- a/src/main/java/org/traccar/protocol/ItsProtocol.java
+++ b/src/main/java/org/traccar/protocol/ItsProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 - 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.
@@ -20,10 +20,14 @@ import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
+import org.traccar.model.Command;
public class ItsProtocol extends BaseProtocol {
public ItsProtocol() {
+ setSupportedDataCommands(
+ Command.TYPE_ENGINE_STOP,
+ Command.TYPE_ENGINE_RESUME);
addServer(new TrackerServer(false, getName()) {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
diff --git a/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java b/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java
index 313575f27..8c1b9b480 100644
--- a/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java
@@ -54,11 +54,11 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder {
.expression("(..),") // status
.or()
.expression("[^,]*,") // vehicle registration
- .number("([01]),") // valid
+ .number("([01]),").optional() // valid
.groupEnd()
.number("(dd),?(dd),?(dddd),") // date (ddmmyyyy)
.number("(dd),?(dd),?(dd),") // time (hhmmss)
- .expression("([AV]),").optional() // valid
+ .expression("([01AV]),").optional() // valid
.number("(d+.d+),([NS]),") // latitude
.number("(d+.d+),([EW]),") // longitude
.groupBegin()
@@ -176,7 +176,7 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder {
}
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
if (parser.hasNext()) {
- position.setValid(parser.next().equals("A"));
+ position.setValid(parser.next().matches("[1A]"));
}
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
diff --git a/src/main/java/org/traccar/protocol/ItsProtocolEncoder.java b/src/main/java/org/traccar/protocol/ItsProtocolEncoder.java
new file mode 100644
index 000000000..ebbbd87cd
--- /dev/null
+++ b/src/main/java/org/traccar/protocol/ItsProtocolEncoder.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 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.
+ * 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 org.traccar.StringProtocolEncoder;
+import org.traccar.model.Command;
+
+public class ItsProtocolEncoder extends StringProtocolEncoder {
+
+ @Override
+ protected Object encodeCommand(Command command) {
+
+ switch (command.getType()) {
+ case Command.TYPE_ENGINE_STOP:
+ return "@SET#RLP,OP1,";
+ case Command.TYPE_ENGINE_RESUME:
+ return "@CLR#RLP,OP1,";
+ default:
+ return null;
+ }
+ }
+
+}
diff --git a/src/test/java/org/traccar/protocol/ItsProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/ItsProtocolDecoderTest.java
index e5a1eacfa..1992892df 100644
--- a/src/test/java/org/traccar/protocol/ItsProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/ItsProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class ItsProtocolDecoderTest extends ProtocolTest {
ItsProtocolDecoder decoder = new ItsProtocolDecoder(null);
+ verifyPosition(decoder, text(
+ "$RLP,N.A,2.0.2,NR,01,L,869867030181814,N.A,28022019,180155,1,28.688226,N,076.993570,E,0.0,80.26,17,201.0,0.89,0.60,VODAFONE I,0,1,25.0,4.20,0,C,14,404,11,415,F34A,51f7,415,13,840b,415,8,a3f7,0c2,5,ef77,415,5,0001,00,17888,47,*"));
+
verifyAttribute(decoder, text(
"$TEL123,Teltonika,03.18.16,NR,1,L,352093085223096,KA09X6945,1,24122018,055749,12.303873,N,76.690697,E,0.0,349.00,10,795.0,0.50,0.40,Airtel,0,1,14.6,4.1,0,,28,404,45,625A,116E,29,28DF,03A3,28,9A5C,0923,26,116F,625A,25,2A51,03A3,0010,00,000042,0.1,0.1,0,()*7B"),
Position.PREFIX_ADC + 2, 0.1);
diff --git a/src/test/java/org/traccar/protocol/ItsProtocolEncoderTest.java b/src/test/java/org/traccar/protocol/ItsProtocolEncoderTest.java
new file mode 100644
index 000000000..e7c4318b3
--- /dev/null
+++ b/src/test/java/org/traccar/protocol/ItsProtocolEncoderTest.java
@@ -0,0 +1,24 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+import org.traccar.model.Command;
+
+import static org.junit.Assert.assertEquals;
+
+public class ItsProtocolEncoderTest extends ProtocolTest {
+
+ @Test
+ public void testEncode() throws Exception {
+
+ ItsProtocolEncoder encoder = new ItsProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_ENGINE_STOP);
+
+ assertEquals("@SET#RLP,OP1,", encoder.encodeCommand(command));
+
+ }
+
+}