aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/FifotrackProtocolDecoder.java28
-rw-r--r--test/org/traccar/protocol/FifotrackProtocolDecoderTest.java9
2 files changed, 26 insertions, 11 deletions
diff --git a/src/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/org/traccar/protocol/FifotrackProtocolDecoder.java
index 9e8d01117..a4b7932e6 100644
--- a/src/org/traccar/protocol/FifotrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/FifotrackProtocolDecoder.java
@@ -37,7 +37,7 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
.text("$$")
.number("d+,") // length
.number("(d+),") // imei
- .number("d+,") // index
+ .number("x+,") // index
.expression("[^,]+,") // type
.number("(d+)?,") // alarm
.number("(dd)(dd)(dd)") // date
@@ -51,15 +51,15 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // odometer
.number("d+,") // runtime
.number("(xxxx),") // status
- .number("(x+),") // input
- .number("(x+),") // output
+ .number("(x+)?,") // input
+ .number("(x+)?,") // output
.number("(d+)|") // mcc
.number("(d+)|") // mnc
.number("(x+)|") // lac
.number("(x+),") // cid
- .number("([x|]+),") // adc
- .expression("([^,]+),") // rfid
- .expression("([^*]+)") // sensors
+ .number("([x|]+)") // adc
+ .expression(",([^,]+)") // rfid
+ .expression(",([^*]+)").optional(2) // sensors
.any()
.compile();
@@ -97,8 +97,12 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_ODOMETER, parser.nextLong());
position.set(Position.KEY_STATUS, parser.nextInt(16));
- position.set(Position.KEY_INPUT, parser.nextInt(16));
- position.set(Position.KEY_OUTPUT, parser.nextInt(16));
+ if (parser.hasNext()) {
+ position.set(Position.KEY_INPUT, parser.nextInt(16));
+ }
+ if (parser.hasNext()) {
+ position.set(Position.KEY_OUTPUT, parser.nextInt(16));
+ }
position.set(Position.KEY_MCC, parser.nextInt());
position.set(Position.KEY_MNC, parser.nextInt());
@@ -112,9 +116,11 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_RFID, parser.next());
- String[] sensors = parser.next().split("\\|");
- for (int i = 0; i < sensors.length; i++) {
- position.set(Position.PREFIX_IO + (i + 1), sensors[i]);
+ if (parser.hasNext()) {
+ String[] sensors = parser.next().split("\\|");
+ for (int i = 0; i < sensors.length; i++) {
+ position.set(Position.PREFIX_IO + (i + 1), sensors[i]);
+ }
}
return position;
diff --git a/test/org/traccar/protocol/FifotrackProtocolDecoderTest.java b/test/org/traccar/protocol/FifotrackProtocolDecoderTest.java
index 60f22a91a..7cde4b5c9 100644
--- a/test/org/traccar/protocol/FifotrackProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/FifotrackProtocolDecoderTest.java
@@ -11,6 +11,15 @@ public class FifotrackProtocolDecoderTest extends ProtocolTest {
FifotrackProtocolDecoder decoder = new FifotrackProtocolDecoder(new FifotrackProtocol());
verifyPosition(decoder, text(
+ "$$105,866104023179743,AB,A00,,161007085534,A,54.738791,25.271918,0,350,151,0,17929,0000,0,,246|1|65|96DB,936|0*0B"));
+
+ verifyPosition(decoder, text(
+ "$$103,866104023179743,5,A00,,161006192841,A,54.738791,25.271918,0,342,200,0,4265,0000,0,,246|1|65|96DB,9C4|0*75"));
+
+ verifyPosition(decoder, text(
+ "$$103,866104023179743,4,A00,,161006192810,V,54.738791,25.271918,0,158,122,0,4235,0000,0,,246|1|65|96DB,9C5|0*69"));
+
+ verifyPosition(decoder, text(
"$$135,866104023192332,29,A01,,160606093046,A,22.546430,114.079730,0,186,181,0,415322,0000,02,2,460|0|27B3|EA7,A2F|3B9|3|0,940C7E,31.76|30.98*46"));
}