aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-04-08 23:47:53 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2013-04-08 23:47:53 +1200
commit6f7493e600316fd672162aa3f2b22b41c2642ebb (patch)
treeddbf331cf4fc106a08181bb1affb2f81dac65a77 /src
parent47e24e87a3dc3befc8ba46550eee3e90d38de5f2 (diff)
downloadtraccar-server-6f7493e600316fd672162aa3f2b22b41c2642ebb.tar.gz
traccar-server-6f7493e600316fd672162aa3f2b22b41c2642ebb.tar.bz2
traccar-server-6f7493e600316fd672162aa3f2b22b41c2642ebb.zip
Add trimble taip protocol (fix #152)
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/SyrusProtocolDecoder.java41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/SyrusProtocolDecoder.java b/src/org/traccar/protocol/SyrusProtocolDecoder.java
index 10aec4f26..7e809212a 100644
--- a/src/org/traccar/protocol/SyrusProtocolDecoder.java
+++ b/src/org/traccar/protocol/SyrusProtocolDecoder.java
@@ -36,15 +36,14 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
/**
* Regular expressions pattern
*/
- //"REV691615354941+3570173+1397742703203212;ID=Test"
static private Pattern pattern = Pattern.compile(
- "REV" + // Type
- "\\d{2}" + // Event index
+ "R[EP]V" + // Type
+ "(?:\\d{2}" + // Event index
"(\\d{4})" + // Week
- "(\\d)" + // Day
+ "(\\d))?" + // Day
"(\\d{5})" + // Seconds
- "([\\+\\-]\\d{2})(\\d{5})" + // Latitude
- "([\\+\\-]\\d{3})(\\d{5})" + // Longitude
+ "([\\+\\-]\\d{2})(\\d{5})" + // Latitude
+ "([\\+\\-]\\d{3})(\\d{5})" + // Longitude
"(\\d{3})" + // Speed
"(\\d{3})" + // Course
"\\d" + // Fix mode
@@ -64,6 +63,24 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
return new Date(millis);
}
+ private Date getTime(long seconds) {
+ Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ time.set(Calendar.HOUR, 0);
+ time.set(Calendar.MINUTE, 0);
+ time.set(Calendar.SECOND, 0);
+ time.set(Calendar.MILLISECOND, 0);
+
+ long millis = time.getTimeInMillis() + seconds * 1000;
+
+ long diff = new Date().getTime() - millis;
+
+ if (diff > 12 * 60 * 60 * 1000) {
+ millis += 24 * 60 * 60 * 1000;
+ }
+
+ return new Date(millis);
+ }
+
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
@@ -114,12 +131,16 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
position.setDeviceId(deviceId);
Integer index = 1;
-
+
// Time
- int week = Integer.valueOf(parser.group(index++));
- int day = Integer.valueOf(parser.group(index++));
+ String week = parser.group(index++);
+ String day = parser.group(index++);
int seconds = Integer.valueOf(parser.group(index++));
- position.setTime(getTime(week, day, seconds));
+ if (week != null && day != null) {
+ position.setTime(getTime(Integer.valueOf(week), Integer.valueOf(day), seconds));
+ } else {
+ position.setTime(getTime(seconds));
+ }
// Latitude
String latitude = parser.group(index) + '.' + parser.group(index + 1);