aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-06-29 19:18:59 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-06-29 19:18:59 -0700
commitb56dea19d0fb6742425c00af0ad6034bd4b1abd6 (patch)
tree54b8dbcba7171c91fa7e63ff52086d0c48e98150
parent2bc8a4fb021ed2677626f06948b96192facd4d7b (diff)
downloadtrackermap-server-b56dea19d0fb6742425c00af0ad6034bd4b1abd6.tar.gz
trackermap-server-b56dea19d0fb6742425c00af0ad6034bd4b1abd6.tar.bz2
trackermap-server-b56dea19d0fb6742425c00af0ad6034bd4b1abd6.zip
Implement alarm decoding
-rw-r--r--src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java46
-rw-r--r--src/test/java/org/traccar/protocol/FifotrackProtocolDecoderTest.java4
2 files changed, 34 insertions, 16 deletions
diff --git a/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java
index cc4eaa790..458e92065 100644
--- a/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java
@@ -105,6 +105,24 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private String decodeAlarm(Integer alarm) {
+ if (alarm != null) {
+ switch (alarm) {
+ case 2:
+ return Position.ALARM_SOS;
+ case 14:
+ return Position.ALARM_LOW_POWER;
+ case 15:
+ return Position.ALARM_POWER_CUT;
+ case 16:
+ return Position.ALARM_POWER_RESTORED;
+ default:
+ return null;
+ }
+ }
+ return null;
+ }
+
private Object decodeLocation(
Channel channel, SocketAddress remoteAddress, String sentence) {
@@ -121,28 +139,24 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.set(Position.KEY_ALARM, parser.next());
+ position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt()));
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
- position.setCourse(parser.nextInt(0));
- position.setAltitude(parser.nextInt(0));
-
- position.set(Position.KEY_ODOMETER, parser.nextLong(0));
- position.set(Position.KEY_STATUS, parser.nextHexInt(0));
- if (parser.hasNext()) {
- position.set(Position.KEY_INPUT, parser.nextHexInt(0));
- }
- if (parser.hasNext()) {
- position.set(Position.KEY_OUTPUT, parser.nextHexInt(0));
- }
+ position.setLatitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
+ position.setCourse(parser.nextInt());
+ position.setAltitude(parser.nextInt());
+
+ position.set(Position.KEY_ODOMETER, parser.nextLong());
+ position.set(Position.KEY_STATUS, parser.nextHexInt());
+ position.set(Position.KEY_INPUT, parser.nextHexInt());
+ position.set(Position.KEY_OUTPUT, parser.nextHexInt());
position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
+ parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt())));
String[] adc = parser.next().split("\\|");
for (int i = 0; i < adc.length; i++) {
diff --git a/src/test/java/org/traccar/protocol/FifotrackProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/FifotrackProtocolDecoderTest.java
index 16572fb47..2e75a180f 100644
--- a/src/test/java/org/traccar/protocol/FifotrackProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/FifotrackProtocolDecoderTest.java
@@ -12,6 +12,10 @@ public class FifotrackProtocolDecoderTest extends ProtocolTest {
FifotrackProtocolDecoder decoder = new FifotrackProtocolDecoder(null);
verifyAttribute(decoder, buffer(
+ "$$123,869467049296388,B996,A01,2,190624131813,V,22.333746,113.590670,0,124,-1,26347,0,0004,00,0,460|0|2694|5A5D,174|0|0|0,B48CEB,*77"),
+ Position.KEY_ALARM, Position.ALARM_SOS);
+
+ verifyAttribute(decoder, buffer(
"$$125,869467049296388,548,A01,38,190619025856,A,22.333905,113.590261,0,12,60,16666,0,0000,00,0,460|0|2694|13F8,1A2|4C1|0|0,B4A067,*7A"),
Position.KEY_DRIVER_UNIQUE_ID, "11837543");