aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-23 11:41:06 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-23 11:41:32 +1200
commit88cc68e95606866a7f14c23f753462c6ed837703 (patch)
tree5a020b1c10075158e0611816cb60082d71c69460 /src
parent7ca76c37de75e4aeb617c51fa7b3a32ae8d25ae2 (diff)
downloadtraccar-server-88cc68e95606866a7f14c23f753462c6ed837703.tar.gz
traccar-server-88cc68e95606866a7f14c23f753462c6ed837703.tar.bz2
traccar-server-88cc68e95606866a7f14c23f753462c6ed837703.zip
Decode Sanav IO status
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/SanavProtocol.java2
-rw-r--r--src/org/traccar/protocol/SanavProtocolDecoder.java29
2 files changed, 25 insertions, 6 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;
}