aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/T55ProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-01-11 11:39:18 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2014-01-11 11:39:18 +1300
commite357f5f9cd877c7ee79f950582e2d360080ef7ab (patch)
tree751196b33d203402a85603cea2b6c36a0288afa4 /src/org/traccar/protocol/T55ProtocolDecoder.java
parent12659dd920eb1ebf72c377f5075902539d7c4fc3 (diff)
downloadtrackermap-server-e357f5f9cd877c7ee79f950582e2d360080ef7ab.tar.gz
trackermap-server-e357f5f9cd877c7ee79f950582e2d360080ef7ab.tar.bz2
trackermap-server-e357f5f9cd877c7ee79f950582e2d360080ef7ab.zip
Extend T55 protocol
Diffstat (limited to 'src/org/traccar/protocol/T55ProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/T55ProtocolDecoder.java63
1 files changed, 60 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java
index 246036313..f055ec240 100644
--- a/src/org/traccar/protocol/T55ProtocolDecoder.java
+++ b/src/org/traccar/protocol/T55ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -68,6 +68,19 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
"(\\d+\\.?\\d*)?," + // Course
".+");
+ private static final Pattern patternTRCCR = Pattern.compile(
+ "\\$TRCCR," +
+ "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD)
+ "(\\d{2})(\\d{2})(\\d{2})\\.?\\d*," + // Time (HHMMSS.SSS)
+ "([AV])," + // Validity
+ "(-?\\d+\\.\\d+)," + // Latitude
+ "(-?\\d+\\.\\d+)," + // Longitude
+ "(\\d+\\.\\d+)," + // Speed
+ "(\\d+\\.\\d+)," + // Course
+ "(-?\\d+\\.\\d+)," + // Altitude
+ "(\\d+\\.\\d+)," + // Battery
+ ".+");
+
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
@@ -239,7 +252,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
position.setTime(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime());
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
@@ -275,7 +288,51 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
position.setExtendedInfo(extendedInfo.toString());
return position;
}
-
+
+ // Location
+ else if (sentence.startsWith("$TRCCR") && deviceId != null) {
+
+ // Parse message
+ Matcher parser = patternTRCCR.matcher(sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ // Create new position
+ Position position = new Position();
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("t55");
+ position.setDeviceId(deviceId);
+
+ Integer index = 1;
+
+ // Time
+ Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ time.clear();
+ time.set(Calendar.YEAR, Integer.valueOf(parser.group(index++)));
+ time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
+ time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
+ time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++)));
+ time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++)));
+ time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
+ position.setTime(time.getTime());
+
+ // Validity
+ position.setValid(parser.group(index++).compareTo("A") == 0);
+
+ // Location
+ position.setLatitude(Double.valueOf(parser.group(index++)));
+ position.setLongitude(Double.valueOf(parser.group(index++)));
+ position.setSpeed(Double.valueOf(parser.group(index++)));
+ position.setCourse(Double.valueOf(parser.group(index++)));
+ position.setAltitude(Double.valueOf(parser.group(index++)));
+
+ // Battery
+ extendedInfo.set("battery", parser.group(index++));
+
+ position.setExtendedInfo(extendedInfo.toString());
+ return position;
+ }
+
return null;
}