diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2013-04-08 23:47:53 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2013-04-08 23:47:53 +1200 |
commit | 6f7493e600316fd672162aa3f2b22b41c2642ebb (patch) | |
tree | ddbf331cf4fc106a08181bb1affb2f81dac65a77 | |
parent | 47e24e87a3dc3befc8ba46550eee3e90d38de5f2 (diff) | |
download | trackermap-server-6f7493e600316fd672162aa3f2b22b41c2642ebb.tar.gz trackermap-server-6f7493e600316fd672162aa3f2b22b41c2642ebb.tar.bz2 trackermap-server-6f7493e600316fd672162aa3f2b22b41c2642ebb.zip |
Add trimble taip protocol (fix #152)
-rw-r--r-- | src/org/traccar/protocol/SyrusProtocolDecoder.java | 41 | ||||
-rw-r--r-- | test/org/traccar/protocol/SyrusProtocolDecoderTest.java | 3 |
2 files changed, 34 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); diff --git a/test/org/traccar/protocol/SyrusProtocolDecoderTest.java b/test/org/traccar/protocol/SyrusProtocolDecoderTest.java index d8a704dff..a7c542bf8 100644 --- a/test/org/traccar/protocol/SyrusProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SyrusProtocolDecoderTest.java @@ -12,6 +12,9 @@ public class SyrusProtocolDecoderTest { decoder.setDataManager(new TestDataManager()); assertNotNull(decoder.decode(null, null, + ">RPV15714+3739438-1220384601512612;ID=1234;*7F")); + + assertNotNull(decoder.decode(null, null, "\r\n>REV691615354941+3570173+1397742703203212;ID=Test")); assertNotNull(decoder.decode(null, null, |