From 2e709a88706cee2861fa53ac4dc4c5f76762e8b2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 7 Apr 2015 18:25:18 +1200 Subject: Add TK110 support to GPS103 --- .../traccar/protocol/Gps103ProtocolDecoder.java | 34 ++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 2069634d6..90b170cff 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2015 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. @@ -45,7 +45,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { "(\\d{2}):?(\\d{2})(?:\\d{2})?," + // Local Time "[^,]*," + "[FL]," + // F - full / L - low - "(\\d{2})(\\d{2})(\\d{2})\\.(\\d+)," + // Time UTC (HHMMSS.SSS) + "(?:(\\d{2})(\\d{2})(\\d{2})\\.(\\d+)|" + // Time UTC (HHMMSS.SSS) + "(?:\\d{1,5}\\.\\d+))," + "([AV])," + // Validity "(\\d+)(\\d{2}\\.\\d+)," + // Latitude (DDMM.MMMM) "([NS])," + @@ -117,23 +118,32 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { int localHours = Integer.valueOf(parser.group(index++)); int localMinutes = Integer.valueOf(parser.group(index++)); - int utcHours = Integer.valueOf(parser.group(index++)); - int utcMinutes = Integer.valueOf(parser.group(index++)); + String utcHours = parser.group(index++); + String utcMinutes = parser.group(index++); // Time time.set(Calendar.HOUR_OF_DAY, localHours); time.set(Calendar.MINUTE, localMinutes); - time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++))); + String seconds = parser.group(index++); + if (seconds != null) { + time.set(Calendar.SECOND, Integer.valueOf(seconds)); + } + String milliseconds = parser.group(index++); + if (milliseconds != null) { + time.set(Calendar.MILLISECOND, Integer.valueOf(milliseconds)); + } // Timezone calculation - int deltaMinutes = (localHours - utcHours) * 60 + localMinutes - utcMinutes; - if (deltaMinutes <= -12 * 60) { - deltaMinutes += 24 * 60; - } else if (deltaMinutes > 12 * 60) { - deltaMinutes -= 24 * 60; + if (utcHours != null && utcMinutes != null) { + int deltaMinutes = (localHours - Integer.valueOf(utcHours)) * 60; + deltaMinutes += localMinutes - Integer.valueOf(utcMinutes); + if (deltaMinutes <= -12 * 60) { + deltaMinutes += 24 * 60; + } else if (deltaMinutes > 12 * 60) { + deltaMinutes -= 24 * 60; + } + time.add(Calendar.MINUTE, -deltaMinutes); } - time.add(Calendar.MINUTE, -deltaMinutes); position.setTime(time.getTime()); // Validity -- cgit v1.2.3