aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/SanavProtocol.java2
-rw-r--r--src/org/traccar/protocol/SanavProtocolDecoder.java29
-rw-r--r--test/org/traccar/protocol/SanavProtocolDecoderTest.java8
3 files changed, 29 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/SanavProtocol.java b/src/org/traccar/protocol/SanavProtocol.java
index 7a8a7ebf0..acc16f82b 100644
--- a/src/org/traccar/protocol/SanavProtocol.java
+++ b/src/org/traccar/protocol/SanavProtocol.java
@@ -18,7 +18,6 @@ package org.traccar.protocol;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
-import org.traccar.CharacterDelimiterFrameDecoder;
import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
@@ -35,7 +34,6 @@ public class SanavProtocol extends BaseProtocol {
serverList.add(new TrackerServer(false, getName()) {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
- pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '*'));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("objectDecoder", new SanavProtocolDecoder(SanavProtocol.this));
diff --git a/src/org/traccar/protocol/SanavProtocolDecoder.java b/src/org/traccar/protocol/SanavProtocolDecoder.java
index 6bbcd05b7..688157171 100644
--- a/src/org/traccar/protocol/SanavProtocolDecoder.java
+++ b/src/org/traccar/protocol/SanavProtocolDecoder.java
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -33,7 +34,6 @@ public class SanavProtocolDecoder extends BaseProtocolDecoder {
}
private static final Pattern PATTERN = new PatternBuilder()
- .any()
.expression("imei[:=]")
.number("(d+)") // imei
.expression("&?rmc[:=]")
@@ -47,6 +47,13 @@ public class SanavProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.d+),") // speed
.number("(d+.d+)?,") // course
.number("(dd)(dd)(dd),") // date (ddmmyy)
+ .groupBegin()
+ .expression("[^*]*")
+ .text("*")
+ .number("xx,")
+ .expression("[^,]+,") // status
+ .number("(d+),") // io
+ .groupEnd("?")
.any()
.compile();
@@ -68,17 +75,31 @@ public class SanavProtocolDecoder extends BaseProtocolDecoder {
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
+ position.setSpeed(parser.nextDouble());
position.setCourse(parser.nextDouble(0));
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
+ dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
position.setTime(dateBuilder.getDate());
+ if (parser.hasNext()) {
+ int io = parser.nextInt();
+ for (int i = 0; i < 5; i++) {
+ position.set(Position.PREFIX_IN + (i + 1), BitUtil.check(io, i));
+ }
+ position.set(Position.KEY_IGNITION, BitUtil.check(io, 5));
+ position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 6));
+ position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 7));
+ position.set(Position.KEY_CHARGE, BitUtil.check(io, 8));
+ if (!BitUtil.check(io, 9)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ }
+ }
+
return position;
}
diff --git a/test/org/traccar/protocol/SanavProtocolDecoderTest.java b/test/org/traccar/protocol/SanavProtocolDecoderTest.java
index 903f0aec0..3dea71e93 100644
--- a/test/org/traccar/protocol/SanavProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/SanavProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class SanavProtocolDecoderTest extends ProtocolTest {
SanavProtocolDecoder decoder = new SanavProtocolDecoder(new SanavProtocol());
verifyPosition(decoder, text(
+ "imei=353197040023431&rmc=$GPRMC,015258.000,A,2457.8101,N,12125.5393,E,0.00,0.00,210111,,*18,AUTO,0300,2.1,10,466,97,34E7,3391,74,466,9 7,3F2D,3391,65,466,97,39C9,3391,79,466,97,3F2C,3391,81,466,97,0000,00 00,83,466,97,0000,0000,85,466,97,0000,0000,85,1,24"));
+
+ verifyPosition(decoder, text(
"imei=1234567890&rmc=$GPRMC,091950.00,V,5300.10000,N,00900.14000,E,0.160,,200513,,,A*68,STOP,V3.872;67%,S4,H8.3,D2.38"));
verifyPosition(decoder, text(
@@ -27,10 +30,7 @@ public class SanavProtocolDecoderTest extends ProtocolTest {
"imei:352024020976845rmc:$GPRMC,000201.000,A,4655.7043,N,01941.3796,E,0.54,159.14,171013,,,A*65,AUTO"));
verifyPosition(decoder, text(
- "imei=352024028982787&rmc=$GPRMC,103048.000,A,4735.0399,N,01905.2895,E,0.00,0.00,171013,,"));
-
- verifyPosition(decoder, text(
- "65,AUTOimei=352024028982787&rmc=$GPRMC,103048.000,A,4735.0399,N,01905.2895,E,0.00,0.00,171013,,"));
+ "imei:352024020976845rmc:$GPRMC,000201.000,A,4655.7043,N,01941.3796,E,0.54,159.14,171013,,,A*65,AUTO"));
}