diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-06-23 11:50:12 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-06-23 11:50:12 +1200 |
commit | 7dec68dabcb5690f7c4092a0d0df17d787c9176c (patch) | |
tree | 10a1893923f95291f82dc61a47c1caa51161736d | |
parent | 102c142c5868ab572c23eb3a3f65979c68180fc1 (diff) | |
download | trackermap-server-7dec68dabcb5690f7c4092a0d0df17d787c9176c.tar.gz trackermap-server-7dec68dabcb5690f7c4092a0d0df17d787c9176c.tar.bz2 trackermap-server-7dec68dabcb5690f7c4092a0d0df17d787c9176c.zip |
Extend PT502 decoder (fix #1263)
-rw-r--r-- | src/org/traccar/protocol/Pt502ProtocolDecoder.java | 39 | ||||
-rw-r--r-- | test/org/traccar/protocol/Pt502ProtocolDecoderTest.java | 7 |
2 files changed, 42 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index 3db463cf6..fe22b0fdc 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -35,7 +35,8 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { }
private static final Pattern pattern = Pattern.compile(
- ".*\\$POS," + // Data Frame start
+ ".*" +
+ "\\$[A-Z]{3}\\d?," + // Type
"(\\d+)," + // Id
"(\\d{2})(\\d{2})(\\d{2})\\.(\\d{3})," + // Time (HHMMSS.SSS)
"([AV])," + // Validity
@@ -45,7 +46,14 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { "([EW])," +
"(\\d+\\.\\d+)?," + // Speed
"(\\d+\\.\\d+)?," + // Course
- "(\\d{2})(\\d{2})(\\d{2})," + // Date
+ "(\\d{2})(\\d{2})(\\d{2}),,," + // Date
+ "./" +
+ "([01])+," + // Input
+ "([01])+/" + // Output
+ "([^/]+)/" + // ADC
+ "(\\d+)" + // Odometer
+ "(?:/([^/]+)?/" + // RFID
+ "(\\p{XDigit}{3}))?" + // State
".*");
@Override
@@ -118,6 +126,33 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++)));
position.setTime(time.getTime());
+ // IO
+ position.set(Event.KEY_INPUT, parser.group(index++));
+ position.set(Event.KEY_OUTPUT, parser.group(index++));
+
+ // ADC
+ String adc = parser.group(index++);
+ if (adc != null) {
+ String[] values = adc.split(",");
+ for (int i = 0; i < values.length; i++) {
+ position.set(Event.PREFIX_ADC + (i + 1), Integer.parseInt(values[i], 16));
+ }
+ }
+
+ position.set(Event.KEY_ODOMETER, parser.group(index++));
+
+ // Driver
+ position.set(Event.KEY_RFID, parser.group(index++));
+
+ // Other
+ String status = parser.group(index++);
+ if (status != null) {
+ int value = Integer.parseInt(status, 16);
+ position.set(Event.KEY_BATTERY, value >> 8);
+ position.set(Event.KEY_GSM, (value >> 4) & 0xf);
+ position.set(Event.KEY_SATELLITES, value & 0xf);
+ }
+
return position;
}
}
diff --git a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java index 0f63c6fd7..83ddef991 100644 --- a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java @@ -12,6 +12,9 @@ public class Pt502ProtocolDecoderTest extends ProtocolDecoderTest { Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(null); verify(decoder.decode(null, null, + "$POS,11023456,033731.000,A,0335.2617,N,09841.1587,E,0.00,88.12,210615,,,A/0000,0/1f8/388900//f33//")); + + verify(decoder.decode(null, null, "$POS,6094,205523.000,A,1013.6223,N,06728.4248,W,0.0,99.3,011112,,,A/00000,00000/0/23895000//")); verify(decoder.decode(null, null, @@ -23,8 +26,8 @@ public class Pt502ProtocolDecoderTest extends ProtocolDecoderTest { verify(decoder.decode(null, null, "$POS,6095,233344.000,V,0933.0451,N,06912.3360,W,,,151112,,,N/00000,00000/0/1677600/")); - /*verify(decoder.decode(null, null, - "$PHO0,6091,233606.000,A,0902.9855,N,06944.3654,W,0.0,43.8,141112,,,A/00010,00000/0/224000//"));*/ + verify(decoder.decode(null, null, + "$PHO0,6091,233606.000,A,0902.9855,N,06944.3654,W,0.0,43.8,141112,,,A/00010,00000/0/224000//")); verify(decoder.decode(null, null, "$POS,353451000164,082405.000,A,1254.8501,N,10051.6752,E,0.00,237.99,160513,,,A/0000,0/0/55000//a71/")); |