From 7dec68dabcb5690f7c4092a0d0df17d787c9176c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 23 Jun 2015 11:50:12 +1200 Subject: Extend PT502 decoder (fix #1263) --- src/org/traccar/protocol/Pt502ProtocolDecoder.java | 39 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol/Pt502ProtocolDecoder.java') 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; } } -- cgit v1.2.3