diff options
Diffstat (limited to 'src/org/traccar')
99 files changed, 809 insertions, 719 deletions
diff --git a/src/org/traccar/api/resource/ReportResource.java b/src/org/traccar/api/resource/ReportResource.java index a1b35d64e..a0f686e80 100644 --- a/src/org/traccar/api/resource/ReportResource.java +++ b/src/org/traccar/api/resource/ReportResource.java @@ -51,7 +51,7 @@ public class ReportResource extends BaseResource { @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Route.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -76,7 +76,7 @@ public class ReportResource extends BaseResource { @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Events.getExcel(stream, getUserId(), deviceIds, groupIds, types, - DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -99,7 +99,7 @@ public class ReportResource extends BaseResource { @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Summary.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); @@ -123,7 +123,7 @@ public class ReportResource extends BaseResource { @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Trips.getExcel(stream, getUserId(), deviceIds, groupIds, - DateUtil.parseDateTime(from), DateUtil.parseDateTime(to)); + DateUtil.parseDate(from), DateUtil.parseDate(to)); return Response.ok(stream.toByteArray()) .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build(); diff --git a/src/org/traccar/helper/DateUtil.java b/src/org/traccar/helper/DateUtil.java index de36d4420..30bb1b2fa 100644 --- a/src/org/traccar/helper/DateUtil.java +++ b/src/org/traccar/helper/DateUtil.java @@ -18,7 +18,6 @@ package org.traccar.helper; import java.util.Calendar; import java.util.Date; -import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.ISODateTimeFormat; @@ -64,9 +63,4 @@ public final class DateUtil { public static Date parseDate(String value) { return DATE_FORMAT.parseDateTime(value).toDate(); } - - public static DateTime parseDateTime(String value) { - return DATE_FORMAT.withOffsetParsed().parseDateTime(value); - } - } diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java index d64993ccb..2253b79fc 100644 --- a/src/org/traccar/helper/Parser.java +++ b/src/org/traccar/helper/Parser.java @@ -15,13 +15,15 @@ */ package org.traccar.helper; +import java.util.Date; +import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Parser { private int position; - private Matcher matcher; + private final Matcher matcher; public Parser(Pattern pattern, String input) { matcher = pattern.matcher(input); @@ -165,4 +167,111 @@ public class Parser { return nextCoordinate(CoordinateFormat.DEG_MIN_HEM); } + public enum DateTimeFormat { + HMS, // HHMMSS + SMH, // SSMMHH + + HMS_YMD, // HHMMSSYYYYMMDD or HHMMSSYYMMDD + HMS_DMY, // HHMMSSDDMMYYYY or HHMMSSDDMMYY + SMH_YMD, // SSMMHHYYYYMMDD or SSMMHHYYMMDD + SMH_DMY, // SSMMHHDDMMYYYY or SSMMHHDDMMYY + + DMY_HMS, // DDMMYYYYHHMMSS or DDMMYYHHMMSS + DMY_HMSS, // DDMMYYYYHHMMSS.sss or DDMMYYHHMMSS.sss + YMD_HMS, // YYYYMMDDHHMMSS or YYMMDDHHMMSS + YMD_HMSS, // YYYYMMDDHHMMSS.sss or YYMMDDHHMMSS.sss + } + + private static final DateTimeFormat DEFAULT_FORMAT = DateTimeFormat.YMD_HMS; + private static final String DEFAULT_TZ = "UTC"; + private static final int DEFAULT_RADIX = 10; + + public Date nextDateTime(DateTimeFormat format, String tz, int radix) { + int year = 0, month = 0, day = 0; + int hour = 0, minute = 0, second = 0, millisecond = 0; + TimeZone timeZone = TimeZone.getTimeZone(tz); + + switch (format) { + case HMS: + hour = nextInt(radix); minute = nextInt(radix); second = nextInt(radix); + break; + case SMH: + second = nextInt(radix); minute = nextInt(radix); hour = nextInt(radix); + break; + case HMS_YMD: + hour = nextInt(radix); minute = nextInt(radix); second = nextInt(radix); + year = nextInt(radix); month = nextInt(radix); day = nextInt(radix); + break; + case HMS_DMY: + hour = nextInt(radix); minute = nextInt(radix); second = nextInt(radix); + day = nextInt(radix); month = nextInt(radix); year = nextInt(radix); + break; + case SMH_YMD: + second = nextInt(radix); minute = nextInt(radix); hour = nextInt(radix); + year = nextInt(radix); month = nextInt(radix); day = nextInt(radix); + break; + case SMH_DMY: + second = nextInt(radix); minute = nextInt(radix); hour = nextInt(radix); + day = nextInt(radix); month = nextInt(radix); year = nextInt(radix); + break; + case DMY_HMS: + case DMY_HMSS: + day = nextInt(radix); month = nextInt(radix); year = nextInt(radix); + hour = nextInt(radix); minute = nextInt(radix); second = nextInt(radix); + break; + case YMD_HMS: + case YMD_HMSS: + default: + year = nextInt(radix); month = nextInt(radix); day = nextInt(radix); + hour = nextInt(radix); minute = nextInt(radix); second = nextInt(radix); + break; + } + + if (format == DateTimeFormat.YMD_HMSS || format == DateTimeFormat.DMY_HMSS) { + millisecond = nextInt(radix); // (ddd) + } + + if (year >= 0 && year < 100) { + year += 2000; + } + + DateBuilder dateBuilder = new DateBuilder(timeZone); + + if (format != DateTimeFormat.HMS || format != DateTimeFormat.SMH) { + dateBuilder.setDate(year, month, day); + } + + dateBuilder.setTime(hour, minute, second, millisecond); + + return dateBuilder.getDate(); + } + + public Date nextDateTime(String tz, int radix) { + return nextDateTime(DEFAULT_FORMAT, tz, radix); + } + + public Date nextDateTime(DateTimeFormat format, int radix) { + return nextDateTime(format, DEFAULT_TZ, radix); + } + + public Date nextDateTime(DateTimeFormat format, String tz) { + return nextDateTime(format, tz, DEFAULT_RADIX); + } + + public Date nextDateTime(DateTimeFormat format) { + return nextDateTime(format, DEFAULT_TZ, DEFAULT_RADIX); + } + + public Date nextDateTime(String tz) { + return nextDateTime(DEFAULT_FORMAT, tz, DEFAULT_RADIX); + } + + public Date nextDateTime(int radix) { + return nextDateTime(DEFAULT_FORMAT, DEFAULT_TZ, radix); + } + + public Date nextDateTime() { + return nextDateTime(DEFAULT_FORMAT, DEFAULT_TZ, DEFAULT_RADIX); + } + } diff --git a/src/org/traccar/protocol/AppelloProtocolDecoder.java b/src/org/traccar/protocol/AppelloProtocolDecoder.java index 02c966834..38f4315de 100644 --- a/src/org/traccar/protocol/AppelloProtocolDecoder.java +++ b/src/org/traccar/protocol/AppelloProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -36,8 +35,8 @@ public class AppelloProtocolDecoder extends BaseProtocolDecoder { .text("FOLLOWIT,") // brand .number("(d+),") // imei .groupBegin() - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd).?d*,") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .or() .text("UTCTIME,") .groupEnd() @@ -71,10 +70,7 @@ public class AppelloProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); } else { getLastLocation(position, null); } diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java index 2bc3b3a09..56723e0ef 100644 --- a/src/org/traccar/protocol/AquilaProtocolDecoder.java +++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -121,10 +120,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(parser.next().equals("A")); diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java index 71beb7d1d..47d79ccd8 100644 --- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -35,8 +34,8 @@ public class Ardi01ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number("(d+),") // imei - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(-?d+.d+),") // longitude .number("(-?d+.d+),") // latitude .number("(d+.?d*),") // speed @@ -66,10 +65,7 @@ public class Ardi01ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/ArknavProtocolDecoder.java b/src/org/traccar/protocol/ArknavProtocolDecoder.java index d6abd4134..2b343e7c3 100644 --- a/src/org/traccar/protocol/ArknavProtocolDecoder.java +++ b/src/org/traccar/protocol/ArknavProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -45,8 +44,8 @@ public class ArknavProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*),") // speed .number("(d+.?d*),") // course .number("(d+.?d*),") // hdop - .number("(dd):(dd):(dd) ") // time - .number("(dd)-(dd)-(dd),") // date + .number("(dd):(dd):(dd) ") // time (hh:mm:ss) + .number("(dd)-(dd)-(dd),") // date (dd-mm-yy) .any() .compile(); @@ -76,10 +75,7 @@ public class ArknavProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_HDOP, parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); return position; } diff --git a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java index 24c155c84..5f15323e6 100644 --- a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java +++ b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -35,7 +34,7 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .expression("(..),") // type .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([AV]),") // validity .number("(d+)(dd.d+)([NS]),") // latitude .number("(d+)(dd.d+)([EW]),") // longitude @@ -72,10 +71,7 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_TYPE, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/ArnaviProtocolDecoder.java b/src/org/traccar/protocol/ArnaviProtocolDecoder.java index 1215f7bad..56f58f2b5 100644 --- a/src/org/traccar/protocol/ArnaviProtocolDecoder.java +++ b/src/org/traccar/protocol/ArnaviProtocolDecoder.java @@ -47,12 +47,12 @@ public class ArnaviProtocolDecoder extends BaseProtocolDecoder { .number("d+,d+,").optional() // input 2 .expression("[01],") // fix type .number("(d+),") // satellites - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(dd)(dd.d+)([NS]),") // latitude .number("(ddd)(dd.d+)([EW]),") // longitude .number("(d+.d+),") // speed .number("(d+.d+),") // course - .number("(dd)(dd)(dd)") // date + .number("(dd)(dd)(dd)") // date (ddmmyy) .any() .compile(); diff --git a/src/org/traccar/protocol/AuroProtocolDecoder.java b/src/org/traccar/protocol/AuroProtocolDecoder.java index 26bf7dfc8..72dea3b61 100644 --- a/src/org/traccar/protocol/AuroProtocolDecoder.java +++ b/src/org/traccar/protocol/AuroProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -44,8 +43,8 @@ public class AuroProtocolDecoder extends BaseProtocolDecoder { .number("d{10}") // status .number("([-+])(ddd)(dd)(dddd)") // longitude .number("([-+])(ddd)(dd)(dddd)") // latitude - .number("(dd)(dd)(dddd)") // date - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dddd)") // date (ddmmyyyy) + .number("(dd)(dd)(dd)") // time (hhmmss) .number("(ddd)") // course .number("d{6}") .number("(ddd)") // speed @@ -78,10 +77,7 @@ public class AuroProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN)); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setCourse(parser.nextDouble()); position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); diff --git a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java index 744117cfe..4f691171c 100644 --- a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java @@ -37,12 +37,12 @@ public class AutoGradeProtocolDecoder extends BaseProtocolDecoder { .text("(") .number("d{12}") // index .number("(d{15})") // imei - .number("(dd)(dd)(dd)") // date + .number("(dd)(dd)(dd)") // date (ddmmyy) .expression("([AV])") // validity .number("(d+)(dd.d+)([NS])") // latitude .number("(d+)(dd.d+)([EW])") // longitude .number("([d.]{5})") // speed - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // time (hhmmss) .number("([d.]{6})") // course .expression("(.)") // status .number("A(xxxx)") diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java index e4dcd6ad7..82c1c9c24 100644 --- a/src/org/traccar/protocol/BoxProtocolDecoder.java +++ b/src/org/traccar/protocol/BoxProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -35,8 +34,8 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("L,") - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .text("G,") .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude @@ -82,10 +81,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); position.setProtocol(getProtocolName()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java index 0952a0978..40af1c812 100644 --- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/CarTrackProtocolDecoder.java @@ -40,7 +40,7 @@ public class CarTrackProtocolDecoder extends BaseProtocolDecoder { .text("&A") .number("(dddd)") // command .text("&B") - .number("(dd)(dd)(dd).(ddd),") // time + .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss) .expression("([AV]),") // validity .number("(dd)(dd.dddd),") // latitude .expression("([NS]),") diff --git a/src/org/traccar/protocol/CarcellProtocolDecoder.java b/src/org/traccar/protocol/CarcellProtocolDecoder.java index b41f14ad5..40e40a40f 100644 --- a/src/org/traccar/protocol/CarcellProtocolDecoder.java +++ b/src/org/traccar/protocol/CarcellProtocolDecoder.java @@ -21,7 +21,6 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.Parser.CoordinateFormat; import org.traccar.helper.PatternBuilder; @@ -57,8 +56,8 @@ public class CarcellProtocolDecoder extends BaseProtocolDecoder { .number("(d),") // jamming .number("(d+),") // hdop .expression("([CG]),?") // clock type - .number("(dd)(dd)(dd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // date (ddmmyy) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d),") // block .number("(d),") // ignition .groupBegin() @@ -67,7 +66,7 @@ public class CarcellProtocolDecoder extends BaseProtocolDecoder { .number("(d),") // painel .number("(d+),") // battery voltage .or() - .number("(dd),") // time + .number("(dd),") // time until delivery .expression("([AF])") // panic .number("(d),") // aux .number("(d{2,4}),") // battery voltage @@ -129,10 +128,7 @@ public class CarcellProtocolDecoder extends BaseProtocolDecoder { position.set("clockType", parser.next()); - DateBuilder dateBuilder = new DateBuilder(). - setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.set("blocked", parser.next().equals("1")); position.set(Position.KEY_IGNITION, parser.next().equals("1")); diff --git a/src/org/traccar/protocol/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java index 9abfe2f86..144b29f49 100644 --- a/src/org/traccar/protocol/CarscopProtocolDecoder.java +++ b/src/org/traccar/protocol/CarscopProtocolDecoder.java @@ -35,7 +35,7 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("*") .any() - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // time (hhmmss) .expression("([AV])") // validity .number("(dd)(dd.dddd)") // latitude .expression("([NS])") diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java index 0f58a24c7..19144017a 100644 --- a/src/org/traccar/protocol/CguardProtocolDecoder.java +++ b/src/org/traccar/protocol/CguardProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -35,8 +34,8 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_NV = new PatternBuilder() .text("NV:") - .number("(dd)(dd)(dd) ") // date - .number("(dd)(dd)(dd):") // time + .number("(dd)(dd)(dd) ") // date (yymmdd) + .number("(dd)(dd)(dd):") // time (hhmmss) .number("(-?d+.d+):") // longitude .number("(-?d+.d+):") // latitude .number("(d+.?d*):") // speed @@ -47,8 +46,8 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_BC = new PatternBuilder() .text("BC:") - .number("(dd)(dd)(dd) ") // date - .number("(dd)(dd)(dd):") // time + .number("(dd)(dd)(dd) ") // date (yymmdd) + .number("(dd)(dd)(dd):") // time (hhmmss) .expression("(.+)") // data .compile(); @@ -63,10 +62,7 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(true); position.setLatitude(parser.nextDouble()); @@ -92,11 +88,7 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime()); String[] data = parser.next().split(":"); for (int i = 0; i < data.length / 2; i++) { diff --git a/src/org/traccar/protocol/CityeasyProtocolDecoder.java b/src/org/traccar/protocol/CityeasyProtocolDecoder.java index 2351232f9..a9fee9fe7 100644 --- a/src/org/traccar/protocol/CityeasyProtocolDecoder.java +++ b/src/org/traccar/protocol/CityeasyProtocolDecoder.java @@ -21,7 +21,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Checksum; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.CellTower; @@ -40,8 +39,8 @@ public class CityeasyProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .groupBegin() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("([AV]),") // validity .number("(d+),") // satellites .number("([NS]),(d+.d+),") // latitude @@ -98,10 +97,7 @@ public class CityeasyProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext(15)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(parser.next().equals("A")); position.set(Position.KEY_SATELLITES, parser.next()); diff --git a/src/org/traccar/protocol/CradlepointProtocolDecoder.java b/src/org/traccar/protocol/CradlepointProtocolDecoder.java index b9e1a3e86..0656b831f 100644 --- a/src/org/traccar/protocol/CradlepointProtocolDecoder.java +++ b/src/org/traccar/protocol/CradlepointProtocolDecoder.java @@ -18,13 +18,11 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.Date; import java.util.regex.Pattern; public class CradlepointProtocolDecoder extends BaseProtocolDecoder { @@ -35,7 +33,7 @@ public class CradlepointProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .expression("([^,]+),") // id - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d+)(dd.d+),") // latitude .expression("([NS]),") .number("(d+)(dd.d+),") // longitude @@ -69,9 +67,7 @@ public class CradlepointProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder(new Date()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS)); position.setValid(true); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/DishaProtocolDecoder.java b/src/org/traccar/protocol/DishaProtocolDecoder.java index 6b4f91833..26ca1a856 100644 --- a/src/org/traccar/protocol/DishaProtocolDecoder.java +++ b/src/org/traccar/protocol/DishaProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -36,7 +35,7 @@ public class DishaProtocolDecoder extends BaseProtocolDecoder { .text("$A#A#") .number("(d+)#") // imei .expression("([AVMX])#") // validity - .number("(dd)(dd)(dd)#") // time + .number("(dd)(dd)(dd)#") // time (hhmmss) .number("(dd)(dd)(dd)#") // date (ddmmyy) .number("(dd)(dd.d+)#") // latitude .expression("([NS])#") @@ -77,10 +76,7 @@ public class DishaProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java index c4baad5ab..7c91b843c 100644 --- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -38,16 +37,10 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // imei .expression("([^,]{2}),") // command .expression("([AV]),") // validity - .number("(xx)") // year - .number("(xx)") // month - .number("(xx),") // day - .number("(xx)") // hours - .number("(xx)") // minutes - .number("(xx),") // seconds - .number("(x)") - .number("(x{7}),") // latitude - .number("(x)") - .number("(x{7}),") // longitude + .number("(xx)(xx)(xx),") // date (yymmdd) + .number("(xx)(xx)(xx),") // time (hhmmss) + .number("(x)(x{7}),") // latitude + .number("(x)(x{7}),") // longitude .number("(x{4}),") // speed .number("(x{4}),") // course .number("(x{8}),") // status @@ -81,10 +74,7 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16)) - .setTime(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16)); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(16)); if (BitUtil.check(parser.nextInt(16), 3)) { position.setLatitude(-parser.nextInt(16) / 600000.0); diff --git a/src/org/traccar/protocol/EnforaProtocolDecoder.java b/src/org/traccar/protocol/EnforaProtocolDecoder.java index 3c4473200..f9045a6f6 100644 --- a/src/org/traccar/protocol/EnforaProtocolDecoder.java +++ b/src/org/traccar/protocol/EnforaProtocolDecoder.java @@ -38,7 +38,7 @@ public class EnforaProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("GPRMC,") - .number("(dd)(dd)(dd).(d+),") // time + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .expression("([AV]),") // validity .number("(dd)(dd.d+),") // latitude .expression("([NS]),") @@ -100,7 +100,7 @@ public class EnforaProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/ExtremTracProtocolDecoder.java b/src/org/traccar/protocol/ExtremTracProtocolDecoder.java index 43fae1e19..deb1ed24b 100644 --- a/src/org/traccar/protocol/ExtremTracProtocolDecoder.java +++ b/src/org/traccar/protocol/ExtremTracProtocolDecoder.java @@ -35,7 +35,7 @@ public class ExtremTracProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("$GPRMC,") .number("(d+),") // device id - .number("(dd)(dd)(dd).d+,") // time + .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss) .expression("([AV]),") // validity .number("(d+)(dd.d+),") // latitude .expression("([NS]),") @@ -43,7 +43,7 @@ public class ExtremTracProtocolDecoder extends BaseProtocolDecoder { .expression("([EW]),") .number("(d+.?d*),") // speed .number("(d+.?d*),") // course - .number("(dd)(dd)(dd),") // date + .number("(dd)(dd)(dd),") // date (ddmmyy) .any() .compile(); @@ -66,7 +66,7 @@ public class ExtremTracProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/org/traccar/protocol/FifotrackProtocolDecoder.java index 995722fa7..bec212f30 100644 --- a/src/org/traccar/protocol/FifotrackProtocolDecoder.java +++ b/src/org/traccar/protocol/FifotrackProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -42,8 +41,8 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder { .number("x+,") // index .expression("[^,]+,") // type .number("(d+)?,") // alarm - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("([AV]),") // validity .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude @@ -85,10 +84,7 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/FlextrackProtocolDecoder.java b/src/org/traccar/protocol/FlextrackProtocolDecoder.java index 9a9e849ca..2d7414f82 100644 --- a/src/org/traccar/protocol/FlextrackProtocolDecoder.java +++ b/src/org/traccar/protocol/FlextrackProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -45,8 +44,8 @@ public class FlextrackProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number("(-?d+),") // index .text("UNITSTAT,") - .number("(dddd)(dd)(dd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd),") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("d+,") // node id .number("([NS])(d+).(d+.d+),") // latitude .number("([EW])(d+).(d+.d+),") // longitude @@ -110,10 +109,7 @@ public class FlextrackProtocolDecoder extends BaseProtocolDecoder { sendAcknowledgement(channel, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(true); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); diff --git a/src/org/traccar/protocol/FoxProtocolDecoder.java b/src/org/traccar/protocol/FoxProtocolDecoder.java index e48b13cb7..83bebd7c0 100644 --- a/src/org/traccar/protocol/FoxProtocolDecoder.java +++ b/src/org/traccar/protocol/FoxProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -36,8 +35,8 @@ public class FoxProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number("(d+),") // status id .expression("([AV]),") // validity - .number("(dd)(dd)(dd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // date (ddmmyy) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(dd)(dd.d+),") // latitude .expression("([NS]),") .number("(ddd)(dd.d+),") // longitude @@ -97,11 +96,7 @@ public class FoxProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); - + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); diff --git a/src/org/traccar/protocol/FreedomProtocolDecoder.java b/src/org/traccar/protocol/FreedomProtocolDecoder.java index a8995b8aa..50546782c 100644 --- a/src/org/traccar/protocol/FreedomProtocolDecoder.java +++ b/src/org/traccar/protocol/FreedomProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -35,8 +34,8 @@ public class FreedomProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("IMEI,") .number("(d+),") // imei - .number("(dddd)/(dd)/(dd), ") // date - .number("(dd):(dd):(dd), ") // time + .number("(dddd)/(dd)/(dd), ") // date (yyyy/dd/mm) + .number("(dd):(dd):(dd), ") // time (hh:mm:ss) .expression("([NS]), ") .number("Lat:(dd)(d+.d+), ") // latitude .expression("([EW]), ") @@ -65,10 +64,7 @@ public class FreedomProtocolDecoder extends BaseProtocolDecoder { position.setValid(true); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java index daef6ea52..0b3c72a91 100644 --- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -50,8 +49,8 @@ public class Gl100ProtocolDecoder extends BaseProtocolDecoder { .number("d*,") // gps accuracy .number("(-?d+.d+),") // longitude .number("(-?d+.d+),") // latitude - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .any() .compile(); @@ -89,10 +88,7 @@ public class Gl100ProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); return position; } diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 74a734143..d7ee57782 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -20,7 +20,6 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -30,6 +29,7 @@ import org.traccar.model.Position; import org.traccar.model.WifiAccessPoint; import java.net.SocketAddress; +import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.regex.Matcher; @@ -47,8 +47,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("([0-9A-Z]{2}xxxx),") // protocol version .number("(d{15}|x{14}),") // imei .any().text(",") - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(xxxx)") // counter .text("$").optional() .compile(); @@ -86,8 +86,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("[-+]dddd,") // timezone .expression("[01],") // daylight saving .groupEnd() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(xxxx)") // counter .text("$").optional() .compile(); @@ -100,8 +100,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .expression("([^,]*),") // device type .number("(xxxx),") // firmware version .number("(xxxx),") // hardware version - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(xxxx)") // counter .text("$").optional() .compile(); @@ -113,8 +113,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(-?d{1,5}.d)?,") // altitude .number("(-?d{1,3}.d{6})?,") // longitude .number("(-?d{1,2}.d{6})?,") // latitude - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .groupBegin() .number("(0ddd)?,") // mcc @@ -158,8 +158,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // odometer .expression(PATTERN_LOCATION.pattern()) .number("(d{1,7}.d)?,") // odometer - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -191,8 +191,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(?:d+.?d*|Inf|NaN)?,") // fuel consumption .number("(d+)?,") // fuel level .groupEnd() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -207,8 +207,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .expression(PATTERN_LOCATION.pattern()) .number("(d{5}:dd:dd)?,") // hour meter .number("(d{1,7}.d)?,") // odometer - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -225,8 +225,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .expression(PATTERN_LOCATION.pattern()) .number("(d+.d),") // odometer .text(",,,,") - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -240,8 +240,21 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // count .number("((?:x{12},-?d+,,,,)+),,,,") // wifi .number("(d{1,3}),") // battery - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) + .text(",") + .number("(xxxx)") // count number + .text("$").optional() + .compile(); + + private static final Pattern PATTERN_GSM = new PatternBuilder() + .text("+RESP:GTGSM,") + .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version + .number("(d{15}|x{14}),") // imei + .expression("(?:STR|CTN|NMR|RTL),") // fix type + .expression("(.*)") // cells + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -262,8 +275,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .or() .number("(d{1,7}.d)?,") // odometer .groupEnd() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -281,16 +294,16 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(-?d{1,5}.d)?,") // altitude .number("(-?d{1,3}.d{6})?,") // longitude .number("(-?d{1,2}.d{6})?,") // latitude - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(0ddd),") // mcc .number("(0ddd),") // mnc .number("(xxxx),") // lac .number("(xxxx),").optional(4) // cell .any() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").optional(2) // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) .text(",") .number("(xxxx)") // count number .text("$").optional() @@ -313,10 +326,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime()); position.setValid(false); position.set(Position.KEY_RESULT, "Command " + type + " accepted"); return position; @@ -360,11 +370,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_INPUT, parser.next()); position.set(Position.KEY_OUTPUT, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime()); position.set(Position.KEY_INDEX, parser.nextInt(16)); @@ -390,11 +396,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_VERSION_FW, parser.nextInt(16)); position.set(Position.KEY_VERSION_HW, parser.nextInt(16)); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime()); return position; } @@ -412,11 +414,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.setValid(true); position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); - - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); } else { getLastLocation(position, null); } @@ -463,11 +461,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -537,11 +533,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { // workaround for wrong location time if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -569,11 +563,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -602,11 +594,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -647,6 +637,40 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { return position; } + private Object decodeGsm(Channel channel, SocketAddress remoteAddress, String sentence) { + Parser parser = new Parser(PATTERN_GSM, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + Network network = new Network(); + + String[] data = parser.next().split(","); + for (int i = 0; i < 6; i++) { + if (!data[i * 6].isEmpty()) { + network.addCellTower(CellTower.from( + Integer.parseInt(data[i * 6]), Integer.parseInt(data[i * 6 + 1]), + Integer.parseInt(data[i * 6 + 2], 16), Integer.parseInt(data[i * 6 + 3], 16), + Integer.parseInt(data[i * 6 + 4]))); + } + } + + position.setNetwork(network); + + return position; + } + private Object decodeOther(Channel channel, SocketAddress remoteAddress, String sentence, String type) { Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { @@ -678,11 +702,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { // workaround for wrong location time if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -724,10 +746,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { } if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); } if (parser.hasNext(4)) { @@ -736,11 +755,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { } if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (!position.getOutdated() && position.getFixTime().after(dateBuilder.getDate())) { - position.setTime(dateBuilder.getDate()); + Date date = parser.nextDateTime(); + if (!position.getOutdated() && position.getFixTime().after(date)) { + position.setTime(date); } } @@ -798,6 +815,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { case "WIF": result = decodeWif(channel, remoteAddress, sentence); break; + case "GSM": + result = decodeGsm(channel, remoteAddress, sentence); + break; case "VER": result = decodeVer(channel, remoteAddress, sentence); break; diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java index 4c127a90b..50d621271 100644 --- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java +++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java @@ -212,12 +212,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); position.setValid(!parser.next().equals("1")); - - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); - + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setAltitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/GnxProtocolDecoder.java b/src/org/traccar/protocol/GnxProtocolDecoder.java index aff86ea7b..cb29f5d23 100644 --- a/src/org/traccar/protocol/GnxProtocolDecoder.java +++ b/src/org/traccar/protocol/GnxProtocolDecoder.java @@ -18,13 +18,11 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.TimeZone; import java.util.regex.Pattern; public class GnxProtocolDecoder extends BaseProtocolDecoder { @@ -37,10 +35,10 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // imei .number("d+,") // length .expression("([01]),") // history - .number("(dd)(dd)(dd),") // device time - .number("(dd)(dd)(dd),") // device date - .number("(dd)(dd)(dd),") // fix time - .number("(dd)(dd)(dd),") // fix date + .number("(dd)(dd)(dd),") // device time (hhmmss) + .number("(dd)(dd)(dd),") // device date (ddmmyy) + .number("(dd)(dd)(dd),") // fix time (hhmmss) + .number("(dd)(dd)(dd),") // fix date (ddmmyy) .number("(d),") // valid .number("(dd.d+),") // latitude .expression("([NS]),") @@ -95,17 +93,8 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ARCHIVE, true); } - DateBuilder dateBuilder; - - dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+5:30")) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setDeviceTime(dateBuilder.getDate()); - - dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+5:30")) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setFixTime(dateBuilder.getDate()); + position.setDeviceTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY, "GMT+5:30")); + position.setFixTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY, "GMT+5:30")); position.setValid(parser.nextInt() != 0); diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java index 96f745917..51479ad52 100644 --- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java @@ -43,8 +43,8 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { .text("*GS") // header .number("d+,") // protocol version .number("(d+),") // imei - .number("(dd)(dd)(dd)") // time - .number("(dd)(dd)(dd),") // date + .number("(dd)(dd)(dd)") // time (hhmmss) + .number("(dd)(dd)(dd),") // date (ddmmyy) .expression("(.*)#?") // data .compile(); @@ -121,7 +121,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { .number("d+,") // protocol version .number("(d+),") // imei .text("GPS:") - .number("(dd)(dd)(dd);") // time + .number("(dd)(dd)(dd);") // time (hhmmss) .number("d;").optional() // fix type .expression("([AV]);") // validity .number("([NS])(d+.d+);") // latitude @@ -129,7 +129,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { .number("(d+)?;") // speed .number("(d+);") // course .number("(d+.?d*)").optional() // hdop - .number("(dd)(dd)(dd)") // date + .number("(dd)(dd)(dd)") // date (ddmmyy) .any() .compile(); @@ -242,10 +242,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { Date time = null; if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - time = dateBuilder.getDate(); + time = parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY); } List<Position> positions = new LinkedList<>(); diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java index 0c613eb2d..aa1ab57fb 100644 --- a/src/org/traccar/protocol/GotopProtocolDecoder.java +++ b/src/org/traccar/protocol/GotopProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -38,7 +37,7 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder { .expression("[^,]+,") // type .expression("([AV]),") // validity .number("DATE:(dd)(dd)(dd),") // date (yyddmm) - .number("TIME:(dd)(dd)(dd),") // time + .number("TIME:(dd)(dd)(dd),") // time (hhmmss) .number("LAT:(d+.d+)([NS]),") // latitude .number("LOT:(d+.d+)([EW]),") // longitude .text("Speed:").number("(d+.d+),") // speed @@ -67,10 +66,7 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 2f8fe4bba..49f1a2049 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -38,12 +38,12 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .text("imei:") .number("(d+),") // imei .expression("([^,]+),") // alarm - .number("(dd)/?(dd)/?(dd) ?") // local date - .number("(dd):?(dd)(?:dd)?,") // local time + .number("(dd)/?(dd)/?(dd) ?") // local date (yymmdd) + .number("(dd):?(dd)(?:dd)?,") // local time (hhmmss) .expression("([^,]+)?,") // rfid .expression("[FL],") // full / low .groupBegin() - .number("(dd)(dd)(dd).(d+)") // time utc (hhmmss.sss) + .number("(dd)(dd)(dd).d+") // time utc (hhmmss) .or() .number("(?:d{1,5}.d+)?") .groupEnd() @@ -85,8 +85,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .text("imei:") .number("(d+),") // imei .expression("OBD,") // type - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d+),") // odometer .number("(d+.d+)?,") // fuel instant .number("(d+.d+)?,") // fuel average @@ -204,11 +204,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime()); position.set(Position.KEY_ODOMETER, parser.nextInt()); parser.next(); // instant fuel consumption @@ -267,7 +263,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { String utcHours = parser.next(); String utcMinutes = parser.next(); - dateBuilder.setTime(localHours, localMinutes, parser.nextInt(), parser.nextInt()); + dateBuilder.setTime(localHours, localMinutes, parser.nextInt()); // Timezone calculation if (utcHours != null && utcMinutes != null) { diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java index 47b02de94..701b1874b 100644 --- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java @@ -35,7 +35,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_GPRMC = new PatternBuilder() .text("$GPRMC,") - .number("(dd)(dd)(dd).?(d+)?,") // time + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .expression("([AV]),") // validity .number("(dd)(dd.d+),") // latitude .expression("([NS]),") @@ -60,7 +60,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*),") // speed .number("(d+.?d*)?,") // course .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd).?(d+)?,") // time + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .expression("([01])") // validity .any() .compile(); @@ -123,7 +123,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); @@ -158,10 +158,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(parser.nextDouble()); position.setCourse(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setValid(parser.next().equals("1")); diff --git a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java index 3f9b52cd1..36f4a19c6 100644 --- a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -37,8 +36,8 @@ public class GpsMarkerProtocolDecoder extends BaseProtocolDecoder { .number("d") // type .number("(?:xx)?") // index .number("(d{15})") // imei - .number("T(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd)?") // time + .number("T(dd)(dd)(dd)") // date (ddmmyy) + .number("(dd)(dd)(dd)?") // time (hhmmss) .expression("([NS])") .number("(dd)(dd)(dddd)") // latitude .expression("([EW])") @@ -71,10 +70,7 @@ public class GpsMarkerProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setValid(true); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN)); diff --git a/src/org/traccar/protocol/GpsmtaProtocolDecoder.java b/src/org/traccar/protocol/GpsmtaProtocolDecoder.java index 4436b7605..e0dd5fd51 100644 --- a/src/org/traccar/protocol/GpsmtaProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsmtaProtocolDecoder.java @@ -34,7 +34,7 @@ public class GpsmtaProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .expression("([^ ]+) ") // uid - .number("(d+) ") // time + .number("(d+) ") // time (unix time) .number("(d+.d+) ") // latitude .number("(d+.d+) ") // longitude .number("(d+) ") // speed diff --git a/src/org/traccar/protocol/Gt30ProtocolDecoder.java b/src/org/traccar/protocol/Gt30ProtocolDecoder.java index 6c3f8c0a4..c034300d0 100644 --- a/src/org/traccar/protocol/Gt30ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt30ProtocolDecoder.java @@ -38,7 +38,7 @@ public class Gt30ProtocolDecoder extends BaseProtocolDecoder { .expression("(.{14})") // device id .number("x{4}") // type .expression("(.)?") // alarm - .number("(dd)(dd)(dd).(d+),") // time + .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss) .expression("([AV]),") // validity .number("(d+)(dd.d+),") // latitude .expression("([NS]),") diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index 6ab997b86..b11a1e0e6 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -142,6 +142,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.setCourse((buf.readUnsignedByte() & 0x0f) * 100.0 + BcdUtil.readInteger(buf, 2)); processStatus(position, buf.readUnsignedInt()); + return position; } @@ -151,7 +152,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // imei .expression("[^,]+,") .any() - .number("(?:(dd)(dd)(dd))?,") // time + .number("(?:(dd)(dd)(dd))?,") // time (hhmmss) .expression("([AV])?,") // validity .groupBegin() .number("-(d+)-(d+.d+),") // latitude @@ -170,7 +171,18 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .number("(?:(dd)(dd)(dd))?") // date (ddmmyy) .any() .number(",(x{8})") // status - .expression("(?:#|,.*)") + .groupBegin() + .number(",(d+),") // odometer + .number("(-?d+),") // temperature + .number("(d+.d+),") // fuel + .number("(-?d+),") // altitude + .number("(x+),") // lac + .number("(x+)#") // cid + .or() + .expression(",.*") + .or() + .text("#") + .groupEnd() .compile(); private static final Pattern PATTERN_NBR = new PatternBuilder() @@ -178,7 +190,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .expression("..,") // manufacturer .number("(d+),") // imei .text("NBR,") - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d+),") // mcc .number("(d+),") // mnc .number("d+,") // gsm delay time @@ -240,6 +252,16 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { processStatus(position, parser.nextLong(16)); + if (parser.hasNext(6)) { + position.set(Position.KEY_ODOMETER, parser.nextInt()); + position.set(Position.PREFIX_TEMP + 1, parser.nextInt()); + position.set(Position.KEY_FUEL_LEVEL, parser.nextDouble()); + + position.setAltitude(parser.nextInt()); + + position.setNetwork(new Network(CellTower.fromLacCid(parser.nextInt(16), parser.nextInt(16)))); + } + return position; } diff --git a/src/org/traccar/protocol/HaicomProtocolDecoder.java b/src/org/traccar/protocol/HaicomProtocolDecoder.java index db26db820..45a56cc10 100644 --- a/src/org/traccar/protocol/HaicomProtocolDecoder.java +++ b/src/org/traccar/protocol/HaicomProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -37,8 +36,8 @@ public class HaicomProtocolDecoder extends BaseProtocolDecoder { .text("$GPRS") .number("(d+),") // imei .expression("([^,]+),") // version - .number("(dd)(dd)(dd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d)") // flags .number("(dd)(d{5})") // latitude .number("(ddd)(d{5}),") // longitude @@ -74,10 +73,7 @@ public class HaicomProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_VERSION_FW, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); int flags = parser.nextInt(); diff --git a/src/org/traccar/protocol/HomtecsProtocolDecoder.java b/src/org/traccar/protocol/HomtecsProtocolDecoder.java index 78bf0a813..2557e1ac7 100644 --- a/src/org/traccar/protocol/HomtecsProtocolDecoder.java +++ b/src/org/traccar/protocol/HomtecsProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -34,8 +33,8 @@ public class HomtecsProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .expression("([^,]+),") // id - .number("(dd)(dd)(dd),") // date - .number("(dd)(dd)(dd).(d+),") // time + .number("(dd)(dd)(dd),") // date (yymmdd) + .number("(dd)(dd)(dd).d+,") // time (hhmmss) .number("(d+),") // satellites .number("(dd)(dd.d+),") // latitude .expression("([NS]),") @@ -64,11 +63,7 @@ public class HomtecsProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); - - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.YMD_HMS)); position.setValid(true); position.set(Position.KEY_SATELLITES, parser.nextInt()); diff --git a/src/org/traccar/protocol/HunterProProtocolDecoder.java b/src/org/traccar/protocol/HunterProProtocolDecoder.java index fc19257f6..6f2bb8fd8 100644 --- a/src/org/traccar/protocol/HunterProProtocolDecoder.java +++ b/src/org/traccar/protocol/HunterProProtocolDecoder.java @@ -35,7 +35,7 @@ public class HunterProProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number(">(d+)<") // identifier .text("$GPRMC,") - .number("(dd)(dd)(dd).?d*,") // time + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .expression("([AV]),") // validity .number("(dd)(dd.d+),") // latitude .expression("([NS]),") diff --git a/src/org/traccar/protocol/IdplProtocolDecoder.java b/src/org/traccar/protocol/IdplProtocolDecoder.java index 5e3638d8e..b5a23e1f2 100644 --- a/src/org/traccar/protocol/IdplProtocolDecoder.java +++ b/src/org/traccar/protocol/IdplProtocolDecoder.java @@ -22,7 +22,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.Protocol; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.Parser.CoordinateFormat; import org.traccar.helper.PatternBuilder; @@ -38,8 +37,8 @@ public class IdplProtocolDecoder extends BaseProtocolDecoder { .text("*ID") // start of frame .number("(d+),") // command code .number("(d+),") // imei - .number("(dd)(dd)(dd),") // current date - .number("(dd)(dd)(dd),") // current time + .number("(dd)(dd)(dd),") // current date (ddmmyy) + .number("(dd)(dd)(dd),") // current time (hhmmss) .expression("([A|V]),") // gps fix .number("(dd)(dd).?(d+),([NS]),") // latitude .number("(ddd)(dd).?(d+),([EW]),") // longitude @@ -81,10 +80,7 @@ public class IdplProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate(CoordinateFormat.DEG_MIN_MIN_HEM)); diff --git a/src/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/org/traccar/protocol/IntellitracProtocolDecoder.java index 70251fc51..0f69101aa 100644 --- a/src/org/traccar/protocol/IntellitracProtocolDecoder.java +++ b/src/org/traccar/protocol/IntellitracProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -35,8 +34,8 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .expression(".+,").optional() .number("(d+),") // identifier - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(-?d+.d+),") // longitude .number("(-?d+.d+),") // latitude .number("(d+.?d*),") // speed @@ -82,10 +81,7 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java index 60aadd025..9a23a95fe 100644 --- a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java +++ b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java @@ -19,7 +19,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
-import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.model.CellTower;
@@ -38,8 +37,8 @@ public class JpKorjarProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder()
.text("KORJAR.PL,")
.number("(d+),") // imei
- .number("(dd)(dd)(dd)") // date
- .number("(dd)(dd)(dd),") // time
+ .number("(dd)(dd)(dd)") // date (yymmdd)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
.number("(d+.d+)([NS]),") // latitude
.number("(d+.d+)([EW]),") // longitude
.number("(d+.d+),") // speed
@@ -70,10 +69,7 @@ public class JpKorjarProtocolDecoder extends BaseProtocolDecoder { }
position.setDeviceId(deviceSession.getDeviceId());
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
- .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
- position.setTime(dateBuilder.getDate());
+ position.setTime(parser.nextDateTime());
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index c8e41b03f..05b4abbb0 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -162,7 +162,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { .expression("([NS]),") .expression("([AV]),") // validity .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d+),") // speed .number("(d+),") // course .number("(d+),") // power @@ -192,10 +192,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextCoordinate()); position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); position.setCourse(parser.nextDouble()); @@ -214,7 +211,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { .number("(Udd),") // type .number("d+,").optional() // alarm .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([TF]),") // validity .number("(d+.d+),([NS]),") // latitude .number("(d+.d+),([EW]),") // longitude @@ -250,10 +247,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setValid(parser.next().equals("T")); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); diff --git a/src/org/traccar/protocol/KenjiProtocolDecoder.java b/src/org/traccar/protocol/KenjiProtocolDecoder.java index 8e59341bd..43038ec94 100644 --- a/src/org/traccar/protocol/KenjiProtocolDecoder.java +++ b/src/org/traccar/protocol/KenjiProtocolDecoder.java @@ -39,13 +39,13 @@ public class KenjiProtocolDecoder extends BaseProtocolDecoder { .number("M(x{6}),") // alarm .number("O(x{4}),") // output .number("I(x{4}),") // input - .number("D(dd)(dd)(dd),") // time + .number("D(dd)(dd)(dd),") // time (hhmmss) .expression("([AV]),") // valid .number("([NS])(dd)(dd.d+),") // latitude .number("([EW])(ddd)(dd.d+),") // longitude .number("T(d+.d+),") // speed .number("H(d+.d+),") // course - .number("Y(dd)(dd)(dd),") // date + .number("Y(dd)(dd)(dd),") // date (ddmmyy) .number("G(d+)") // satellites .any() .compile(); diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java index bdf4ba29b..b7c91bc7f 100644 --- a/src/org/traccar/protocol/L100ProtocolDecoder.java +++ b/src/org/traccar/protocol/L100ProtocolDecoder.java @@ -40,7 +40,7 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { .text("ATL") .number("(d{15}),") // imei .text("$GPRMC,") - .number("(dd)(dd)(dd).ddd,") // time + .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss) .expression("([AV]),") // validity .number("(dd)(dd.d+),") // latitude .expression("([NS]),") @@ -48,7 +48,7 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { .expression("([EW]),") .number("(d+.?d*)?,") // speed .number("(d+.?d*)?,") // course - .number("(dd)(dd)(dd),") // date + .number("(dd)(dd)(dd),") // date (ddmmyy) .any() .text("#") .number("([01]+),") // io status @@ -92,7 +92,7 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 62bc8fa37..d0bc7583c 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -36,7 +36,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("$AVRMC,") .expression("([^,]+),") // identifier - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([AVRPavrp]),") // validity .number("(dd)(dd.d+),") // latitude .expression("([NS]),") diff --git a/src/org/traccar/protocol/MaestroProtocolDecoder.java b/src/org/traccar/protocol/MaestroProtocolDecoder.java index f0b328cf9..dfda3d693 100644 --- a/src/org/traccar/protocol/MaestroProtocolDecoder.java +++ b/src/org/traccar/protocol/MaestroProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -43,8 +42,8 @@ public class MaestroProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // gsm .expression("([01]),") // starter .expression("([01]),") // ignition - .number("(dd)/(dd)/(dd),") // date - .number("(dd):(dd):(dd),") // time + .number("(dd)/(dd)/(dd),") // date (yy/mm/dd) + .number("(dd):(dd):(dd),") // time (hh:mm:ss) .number("(-?d+.d+),") // longitude .number("(-?d+.d+),") // latitude .number("(d+.?d*),") // altitude @@ -82,10 +81,7 @@ public class MaestroProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_CHARGE, parser.nextInt() == 1); position.set(Position.KEY_IGNITION, parser.nextInt() == 1); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/ManPowerProtocolDecoder.java b/src/org/traccar/protocol/ManPowerProtocolDecoder.java index 39b651d7e..08cb8b818 100644 --- a/src/org/traccar/protocol/ManPowerProtocolDecoder.java +++ b/src/org/traccar/protocol/ManPowerProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -38,8 +37,8 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder { .expression("[^,]*,[^,]*,") .expression("([^,]*),") // status .number("d+,d+,d+.?d*,") - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([AV]),") // validity .number("(dd)(dd.dddd),") // latitude .expression("([NS]),") @@ -69,10 +68,7 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_STATUS, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 60660adf6..6be4845a7 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -36,7 +36,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_GPRMC = new PatternBuilder() .text("$GPRMC,") - .number("(dd)(dd)(dd).d+,") // time + .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss) .expression("([AV]),") // validity .number("(d+)(dd.d+),([NS]),") // latitude .number("(d+)(dd.d+),([EW]),") // longitude @@ -88,7 +88,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { } DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); @@ -230,7 +230,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { .expression("[^,]*,") // name .expression("([RS]),") .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([AV]),") // validity .number("(d+)(dd.d+),([NS]),") // latitude .number("(d+)(dd.d+),([EW]),") // longitude @@ -287,10 +287,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ARCHIVE, true); } - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index de739d0a4..af0b356a6 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -39,7 +39,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN = new PatternBuilder() - .number("(dd)(dd)(dd).?(d+)?,") // time + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .expression("([AV]),") // validity .number("(d+)(dd.d+),") // latitude .expression("([NS]),") @@ -72,7 +72,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { .compile(); private static final Pattern PATTERN_RFID = new PatternBuilder() - .number("|(dd)(dd)(dd),") // time + .number("|(dd)(dd)(dd),") // time (hhmmss) .number("(dd)(dd)(dd),") // date (ddmmyy) .number("(d+)(dd.d+),") // latitude .expression("([NS]),") @@ -211,9 +211,6 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { DateBuilder dateBuilder = new DateBuilder() .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (parser.hasNext()) { - dateBuilder.setMillis(parser.nextInt()); - } position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); @@ -268,10 +265,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { return null; } - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); position.setValid(true); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index a4a0d2d42..bd6f3e8be 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -20,7 +20,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -50,8 +49,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // event .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude - .number("(dd)(dd)(dd)") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("([AV]),") // validity .number("(d+),") // satellites .number("(d+),") // rssi @@ -107,10 +106,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(parser.next().equals("A")); diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index 94c67b616..db01eaa9f 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -35,8 +34,8 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN_FIX = new PatternBuilder() - .number("(d+)/(d+)/(d+),") // date - .number("(d+):(d+):(d+),") // time + .number("(d+)/(d+)/(d+),") // date (dd/mm/yy) + .number("(d+):(d+):(d+),") // time (hh:mm:ss) .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude .compile(); @@ -78,11 +77,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { private void decodeFix(Position position, Parser parser) { - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); - + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); } diff --git a/src/org/traccar/protocol/MtxProtocolDecoder.java b/src/org/traccar/protocol/MtxProtocolDecoder.java index 0b84603bd..8ad4ad314 100644 --- a/src/org/traccar/protocol/MtxProtocolDecoder.java +++ b/src/org/traccar/protocol/MtxProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -35,8 +34,8 @@ public class MtxProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("#MTX,") .number("(d+),") // imei - .number("(dddd)(dd)(dd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd),") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude .number("(d+.?d*),") // speed @@ -78,10 +77,7 @@ public class MtxProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(true); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/PathAwayProtocolDecoder.java b/src/org/traccar/protocol/PathAwayProtocolDecoder.java index 036cfa445..0a2204222 100644 --- a/src/org/traccar/protocol/PathAwayProtocolDecoder.java +++ b/src/org/traccar/protocol/PathAwayProtocolDecoder.java @@ -25,7 +25,6 @@ import org.jboss.netty.handler.codec.http.HttpVersion; import org.jboss.netty.handler.codec.http.QueryStringDecoder; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -46,7 +45,7 @@ public class PathAwayProtocolDecoder extends BaseProtocolDecoder { .expression("[^,]*,") // icon .expression("[^,]*,") // color .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude .number("(-?d+.?d*),") // altitude @@ -77,10 +76,7 @@ public class PathAwayProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setValid(true); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/PretraceProtocolDecoder.java b/src/org/traccar/protocol/PretraceProtocolDecoder.java index fa590c5a1..dc83b7ed2 100644 --- a/src/org/traccar/protocol/PretraceProtocolDecoder.java +++ b/src/org/traccar/protocol/PretraceProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,8 +38,8 @@ public class PretraceProtocolDecoder extends BaseProtocolDecoder { .number("Uddd") // type .number("d") // gps type .expression("([AV])") // validity - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd)") // time (hhmmss) .number("(dd)(dd.dddd)") // latitude .expression("([NS])") .number("(ddd)(dd.dddd)") // longitude @@ -78,10 +77,7 @@ public class PretraceProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java index d25d96150..11df9d218 100644 --- a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java @@ -35,7 +35,7 @@ public class Pt3000ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number("%(d+),") // imei .text("$GPRMC,") - .number("(dd)(dd)(dd).?d*,") // time + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .expression("([AV]),") // validity .number("(dd)(dd.d+),") // latitude .expression("([NS]),") diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index a72d237d3..e2d7f059a 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -41,7 +41,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { .any().text("$")
.expression("([^,]+),") // type
.number("(d+),") // id
- .number("(dd)(dd)(dd).(ddd),") // time
+ .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss)
.expression("([AV]),") // validity
.number("(dd)(dd.dddd),") // latitude
.expression("([NS]),")
@@ -49,7 +49,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { .expression("([EW]),")
.number("(d+.d+)?,") // speed
.number("(d+.d+)?,") // course
- .number("(dd)(dd)(dd),,,") // date
+ .number("(dd)(dd)(dd),,,") // date (ddmmyy)
.expression("./")
.expression("([01])+,") // input
.expression("([01])+/") // output
diff --git a/src/org/traccar/protocol/RaveonProtocolDecoder.java b/src/org/traccar/protocol/RaveonProtocolDecoder.java index 1fd3d4cd7..1fd5e6636 100644 --- a/src/org/traccar/protocol/RaveonProtocolDecoder.java +++ b/src/org/traccar/protocol/RaveonProtocolDecoder.java @@ -18,14 +18,12 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.Date; import java.util.regex.Pattern; public class RaveonProtocolDecoder extends BaseProtocolDecoder { @@ -40,7 +38,7 @@ public class RaveonProtocolDecoder extends BaseProtocolDecoder { .number("d+,") .number("(-?)(d+)(dd.d+),") // latitude .number("(-?)(d+)(dd.d+),") // longitude - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d),") // validity .number("(d+),") // satellites .number("(-?d+),") // altitude @@ -77,9 +75,7 @@ public class RaveonProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); - DateBuilder dateBuilder = new DateBuilder(new Date()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS)); position.setValid(parser.nextInt() != 0); diff --git a/src/org/traccar/protocol/RitiProtocolDecoder.java b/src/org/traccar/protocol/RitiProtocolDecoder.java index a879633c2..fd31ee4e2 100644 --- a/src/org/traccar/protocol/RitiProtocolDecoder.java +++ b/src/org/traccar/protocol/RitiProtocolDecoder.java @@ -36,7 +36,7 @@ public class RitiProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("$GPRMC,") - .number("(dd)(dd)(dd).?d*,") // time + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .expression("([AV]),") // validity .number("(dd)(dd.d+),") // latitude .expression("([NS]),") diff --git a/src/org/traccar/protocol/SanavProtocolDecoder.java b/src/org/traccar/protocol/SanavProtocolDecoder.java index 606668713..bd49585f6 100644 --- a/src/org/traccar/protocol/SanavProtocolDecoder.java +++ b/src/org/traccar/protocol/SanavProtocolDecoder.java @@ -38,7 +38,7 @@ public class SanavProtocolDecoder extends BaseProtocolDecoder { .number("(d+)") // imei .expression("&?rmc[:=]") .text("$GPRMC,") - .number("(dd)(dd)(dd).(d+),") // time + .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss) .expression("([AV]),") // validity .number("(d+)(dd.d+),") // latitude .expression("([NS]),") diff --git a/src/org/traccar/protocol/SiwiProtocolDecoder.java b/src/org/traccar/protocol/SiwiProtocolDecoder.java index 78f32d01e..76b1e4322 100644 --- a/src/org/traccar/protocol/SiwiProtocolDecoder.java +++ b/src/org/traccar/protocol/SiwiProtocolDecoder.java @@ -18,14 +18,12 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.TimeZone; import java.util.regex.Pattern; public class SiwiProtocolDecoder extends BaseProtocolDecoder { @@ -53,8 +51,8 @@ public class SiwiProtocolDecoder extends BaseProtocolDecoder { .number("(-?d+.d+),") // longitude .number("(-?d+),") // altitude .number("(d+),") // course - .number("(dd)(dd)(dd),") // time - .number("(dd)(dd)(dd),") // date + .number("(dd)(dd)(dd),") // time (hhmmss) + .number("(dd)(dd)(dd),") // date (ddmmyy) .any() .compile(); @@ -90,10 +88,7 @@ public class SiwiProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(parser.nextDouble()); position.setCourse(parser.nextInt()); - DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("IST")) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY, "IST")); return position; } diff --git a/src/org/traccar/protocol/StarLinkProtocolDecoder.java b/src/org/traccar/protocol/StarLinkProtocolDecoder.java index 0cd162a95..8d35ea5ba 100644 --- a/src/org/traccar/protocol/StarLinkProtocolDecoder.java +++ b/src/org/traccar/protocol/StarLinkProtocolDecoder.java @@ -91,19 +91,22 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); + position.setValid(true); position.set(Position.KEY_INDEX, parser.nextInt()); String[] data = parser.next().split(","); Integer lac = null, cid = null; + int event = 0; for (int i = 0; i < Math.min(data.length, dataTags.length); i++) { switch (dataTags[i]) { case "#EDT#": position.setDeviceTime(dateFormat.parse(data[i])); break; - case "EID": - position.set(Position.KEY_EVENT, data[i]); + case "#EID#": + event = Integer.parseInt(data[i]); + position.set(Position.KEY_EVENT, event); break; case "#PDT#": position.setFixTime(dateFormat.parse(data[i])); @@ -121,7 +124,7 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder { position.setCourse(Integer.parseInt(data[i])); break; case "#ODO#": - position.set(Position.KEY_ODOMETER, Integer.parseInt(data[i])); + position.set(Position.KEY_ODOMETER, Long.parseLong(data[i]) * 1000); break; case "#IN1#": position.set(Position.PREFIX_IN + 1, Integer.parseInt(data[i])); @@ -177,6 +180,10 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder { position.setNetwork(new Network(CellTower.fromLacCid(lac, cid))); } + if (event == 20) { + position.set(Position.KEY_RFID, data[data.length - 1]); + } + return position; } diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java index 9f7980032..599c16a3c 100644 --- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java +++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -38,8 +37,8 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // imei .text("D001,") // type .expression("[^,]*,") // vehicle - .number("(dd)/(dd)/(dd),") // date - .number("(dd):(dd):(dd),") // time + .number("(dd)/(dd)/(dd),") // date (dd/mm/yy) + .number("(dd):(dd):(dd),") // time (hh:mm:ss) .number("(dd)(dd).?(d+)([NS]),") // latitude .number("(ddd)(dd).?(d+)([EW]),") // longitude .number("(d+.?d*),") // speed @@ -85,10 +84,7 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index 55d5c224a..e19335cb0 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -31,11 +31,13 @@ import java.util.TimeZone; public class SuntechProtocolDecoder extends BaseProtocolDecoder { private int protocolType; + private boolean hbm; public SuntechProtocolDecoder(SuntechProtocol protocol) { super(protocol); protocolType = Context.getConfig().getInteger(getProtocolName() + ".protocolType"); + hbm = Context.getConfig().getBoolean(getProtocolName() + ".hbm"); } public void setProtocolType(int protocolType) { @@ -144,12 +146,16 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_INDEX, Integer.parseInt(values[index++])); } - if (index < values.length) { - position.set(Position.KEY_HOURS, Integer.parseInt(values[index++])); - } + if (hbm) { + + if (index < values.length) { + position.set(Position.KEY_HOURS, Integer.parseInt(values[index++])); + } + + if (index < values.length) { + position.set(Position.KEY_BATTERY, Double.parseDouble(values[index])); + } - if (index < values.length) { - position.set(Position.KEY_BATTERY, Double.parseDouble(values[index])); } return position; diff --git a/src/org/traccar/protocol/SupermateProtocolDecoder.java b/src/org/traccar/protocol/SupermateProtocolDecoder.java index 5e6615e9f..17e870950 100644 --- a/src/org/traccar/protocol/SupermateProtocolDecoder.java +++ b/src/org/traccar/protocol/SupermateProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -42,16 +41,10 @@ public class SupermateProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // command id .expression("([^,]{2}),") // command .expression("([AV]),") // validity - .number("(xx)") // year - .number("(xx)") // month - .number("(xx),") // day - .number("(xx)") // hours - .number("(xx)") // minutes - .number("(xx),") // seconds - .number("(x)") - .number("(x{7}),") // latitude - .number("(x)") - .number("(x{7}),") // longitude + .number("(xx)(xx)(xx),") // date (yymmdd) + .number("(xx)(xx)(xx),") // time (hhmmss) + .number("(x)(x{7}),") // latitude + .number("(x)(x{7}),") // longitude .number("(x{4}),") // speed .number("(x{4}),") // course .number("(x{12}),") // status @@ -86,10 +79,7 @@ public class SupermateProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16)) - .setTime(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16)); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(16)); if (parser.nextInt(16) == 8) { position.setLatitude(-parser.nextInt(16) / 600000.0); diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java index cd50a99ff..c60c92d45 100644 --- a/src/org/traccar/protocol/T55ProtocolDecoder.java +++ b/src/org/traccar/protocol/T55ProtocolDecoder.java @@ -36,7 +36,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_GPRMC = new PatternBuilder() .text("$GPRMC,") - .number("(dd)(dd)(dd).?d*,") // time + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .expression("([AV]),") // validity .number("(dd)(dd.d+),") // latitude .expression("([NS]),") @@ -44,7 +44,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { .expression("([EW]),") .number("(d+.?d*)?,") // speed .number("(d+.?d*)?,") // course - .number("(dd)(dd)(dd),") // date + .number("(dd)(dd)(dd),") // date (ddmmyy) .expression("[^*]+") .text("*") .expression("[^,]+") @@ -59,7 +59,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_GPGGA = new PatternBuilder() .text("$GPGGA,") - .number("(dd)(dd)(dd).?d*,") // time + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .number("(d+)(dd.d+),") // latitude .expression("([NS]),") .number("(d+)(dd.d+),") // longitude @@ -81,8 +81,8 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_TRCCR = new PatternBuilder() .text("$TRCCR,") - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd).?d*,") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd).?d*,") // time (hhmmss) .expression("([AV]),") // validity .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude @@ -210,10 +210,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index c53538223..24fe36220 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -18,6 +18,7 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.DateUtil; import org.traccar.helper.Parser; @@ -50,8 +51,8 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { .or() .expression("(?:RGP|RCQ|RBR)") // type .number("(?:dd)?") - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // date (mmddyy) + .number("(dd)(dd)(dd)") // time (hhmmss) .groupEnd() .number("([-+]dd)(d{5})") // latitude .number("([-+]ddd)(d{5})") // longitude @@ -108,10 +109,7 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { } if (parser.hasNext(6)) { - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); } position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG)); @@ -138,6 +136,10 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { attributes = sentence.substring(beginIndex, endIndex).split(";"); } + String uniqueId = null; + DeviceSession deviceSession = null; + String messageIndex = null; + if (attributes != null) { for (String attribute : attributes) { int index = attribute.indexOf('='); @@ -147,13 +149,11 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { switch (key) { case "id": - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value); + uniqueId = value; + deviceSession = getDeviceSession(channel, remoteAddress, value); if (deviceSession != null) { position.setDeviceId(deviceSession.getDeviceId()); } - if (sendResponse && channel != null) { - channel.write(value); - } break; case "sv": @@ -173,13 +173,26 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { break; } + } else if (attribute.startsWith("#")) { + messageIndex = attribute; } } } - if (position.getDeviceId() != 0) { + if (deviceSession != null) { + if (sendResponse && channel != null) { + if (messageIndex != null) { + String response = ">ACK;" + messageIndex + ";ID=" + uniqueId + ";"; + response += Checksum.nmea(response) + "<"; + channel.write(response); + } else { + channel.write(uniqueId); + } + } + return position; } + return null; } diff --git a/src/org/traccar/protocol/TelicProtocolDecoder.java b/src/org/traccar/protocol/TelicProtocolDecoder.java index 1560efccc..0ed1ce2d9 100644 --- a/src/org/traccar/protocol/TelicProtocolDecoder.java +++ b/src/org/traccar/protocol/TelicProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,8 +38,8 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // type .number("d{12},") // event time .number("d+,") - .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd)") // date (ddmmyy) + .number("(dd)(dd)(dd),") // time (hhmmss) .groupBegin() .number("(ddd)(dd)(dddd),") // longitude .number("(dd)(dd)(dddd),") // latitude @@ -82,10 +81,7 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, decodeAlarm(event)); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); if (parser.hasNext(6)) { position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN)); diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java index c2a94257d..45e151897 100644 --- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java @@ -49,7 +49,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("(") .expression("[A-Z]+") - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // time (hhmmss) .expression("([AV])") // validity .number("(dd)(dd.dddd)([NS])") // latitude .number("(ddd)(dd.dddd)([EW])") // longitude diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 9dc94678e..64314f6c8 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -41,14 +41,14 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .number("(d+)(,)?") // device id .expression(".{4},?") // command .number("d*") // imei? - .number("(dd)(dd)(dd),?") // date + .number("(dd)(dd)(dd),?") // date (mmddyy if comma-delimited, otherwise yyddmm) .expression("([AV]),?") // validity .number("(d+)(dd.d+)") // latitude .expression("([NS]),?") .number("(d+)(dd.d+)") // longitude .expression("([EW]),?") .number("(d+.d)(?:d*,)?") // speed - .number("(dd)(dd)(dd),?") // time + .number("(dd)(dd)(dd),?") // time (hhmmss) .number("(d+.?d{1,2}),?") // course .number("(?:([01]{8})|(x{8}))?,?") // state .number("(?:L(x+))?") // odometer @@ -61,7 +61,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // device id .text("ZC20,") .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("d+,") // battery level .number("(d+),") // battery voltage .number("(d+),") // power voltage @@ -138,11 +138,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - - getLastLocation(position, dateBuilder.getDate()); + getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); int battery = parser.nextInt(); if (battery != 65535) { diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java index 7df671109..9f0e8e888 100644 --- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java +++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java @@ -45,7 +45,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_POSITION = new PatternBuilder() .number("#(x+)?") // cell info .text("$GPRMC,") - .number("(dd)(dd)(dd).(d+),") // time + .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss) .expression("([AV]),") // validity .number("(d+)(dd.d+),") // latitude .expression("([NS]),") @@ -91,8 +91,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { parser.next(); // base station info DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - parser.next(); + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/TmgProtocolDecoder.java b/src/org/traccar/protocol/TmgProtocolDecoder.java index a0459a161..223f1e419 100644 --- a/src/org/traccar/protocol/TmgProtocolDecoder.java +++ b/src/org/traccar/protocol/TmgProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,8 +38,8 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { .expression("(...),") // type .expression("[LH],") // history .number("(d+),") // imei - .number("(dd)(dd)(dddd),") // date - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dddd),") // date (ddmmyyyy) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(d),") // status .number("(dd)(dd.d+),") // latitude .expression("([NS]),") @@ -114,10 +113,7 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { break; } - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setValid(parser.nextInt() > 0); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java index 0be411246..2f853982f 100644 --- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java +++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -37,7 +36,7 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder { .number("(d+)") // imei .any() .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // time (hhmmss) .expression("([AV])") .number("(dd)(dd.dddd)([NS])") // latitude .number("(ddd)(dd.dddd)([EW])") // longitude @@ -63,10 +62,7 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index c7dc9e6c1..54eb2b5a5 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -41,20 +41,20 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // imei .expression("(..)") // alarm .text("$GPRMC,") - .number("(dd)(dd)(dd).d+,") // time + .number("(dd)(dd)(dd).d+,") // time (hhmmss) .expression("([AV]),") // validity .number("(d+)(dd.d+),([NS]),") // latitude .number("(d+)(dd.d+),([EW]),") // longitude .number("(d+.?d*)?,") // speed .number("(d+.?d*)?,") // course - .number("(dd)(dd)(dd)") // date + .number("(dd)(dd)(dd)") // date (ddmmyy) .expression("[^*]*").text("*") .number("xx|") // checksum .number("(d+.d+)|") // pdop .number("(d+.d+)|") // hdop .number("(d+.d+)|") // vdop .number("(d+)|") // io status - .number("d+|") // time + .number("d+|") // battery time .number("d") // charged .number("(ddd)") // battery .number("(dddd)|") // power @@ -75,7 +75,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // imei .expression("(..)") // alarm type .number("(dd)(dd)(dd)") // date (ddmmyy) - .number("(dd)(dd)(dd)|") // time + .number("(dd)(dd)(dd)|") // time (hhmmss) .expression("([AV])|") // validity .number("(d+)(dd.d+)|") // latitude .expression("([NS])|") @@ -103,8 +103,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("xx") // length .number("(d+)|") // imei .expression("(..)") // alarm type - .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // date (ddmmyy) + .number("(dd)(dd)(dd)") // time (hhmmss) .number("(xxxx)") // io status .expression("[01]") // charging .number("(dd)") // battery @@ -135,7 +135,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // imei .number("(x{8})") // status .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // time (hhmmss) .number("(dd)") // battery .number("(dd)") // external power .number("(dddd)") // adc 1 @@ -269,10 +269,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext()) { position.set(Position.KEY_ALARM, decodeAlarm(Short.parseShort(parser.next(), 16))); } - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.set(Position.PREFIX_IO + 1, parser.next()); position.set(Position.KEY_BATTERY, parser.nextDouble() * 0.1); @@ -298,10 +296,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { } else if (pattern == PATTERN4) { position.set(Position.KEY_STATUS, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.set(Position.KEY_BATTERY, parser.nextDouble() * 0.1); position.set(Position.KEY_POWER, parser.nextDouble()); diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java index 20f7d2968..605a1e0b5 100644 --- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -44,7 +43,7 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder { .expression("([^,]+),") // id .expression("([AL]),") // validity .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([NS])") .number("(dd)(dd.d+)") // latitude .expression("([EW])") @@ -82,10 +81,7 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); diff --git a/src/org/traccar/protocol/Tr900ProtocolDecoder.java b/src/org/traccar/protocol/Tr900ProtocolDecoder.java index 1f867d5d1..a566c637c 100644 --- a/src/org/traccar/protocol/Tr900ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tr900ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -37,7 +36,7 @@ public class Tr900ProtocolDecoder extends BaseProtocolDecoder { .number("d+,") // period .number("(d),") // fix .number("(dd)(dd)(dd),") // date (yymmdd) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([EW])") .number("(ddd)(dd.d+),") // longitude .expression("([NS])") @@ -75,10 +74,7 @@ public class Tr900ProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.nextInt() == 1); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN)); diff --git a/src/org/traccar/protocol/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java index f909e8488..677f88cdc 100644 --- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java +++ b/src/org/traccar/protocol/TrackboxProtocolDecoder.java @@ -33,7 +33,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN = new PatternBuilder() - .number("(dd)(dd)(dd).(ddd),") // time + .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss) .number("(dd)(dd.dddd)([NS]),") // latitude .number("(ddd)(dd.dddd)([EW]),") // longitude .number("(d+.d),") // hdop @@ -42,7 +42,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // course .number("d+.d+,") // speed (kph) .number("(d+.d+),") // speed (knots) - .number("(dd)(dd)(dd),") // date + .number("(dd)(dd)(dd),") // date (ddmmyy) .number("(d+)") // satellites .compile(); diff --git a/src/org/traccar/protocol/TrakMateProtocolDecoder.java b/src/org/traccar/protocol/TrakMateProtocolDecoder.java index 95eef67c8..03ec6cc67 100644 --- a/src/org/traccar/protocol/TrakMateProtocolDecoder.java +++ b/src/org/traccar/protocol/TrakMateProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -42,8 +41,8 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { .expression("([^ ]+)|") // uid .number("(d+.d+)|") // latitude .number("(d+.d+)|") // longitude - .number("(dd)(dd)(dd)|") // time - .number("(dd)(dd)(dd)|") // date + .number("(dd)(dd)(dd)|") // time (hhmmss) + .number("(dd)(dd)(dd)|") // date (ddmmyy) .number("(d+.d+)|") // software ver .number("(d+.d+)|") // Hardware ver .any() @@ -55,8 +54,8 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // seq .number("(d+.d+)|") // latitude .number("(d+.d+)|") // longitude - .number("(dd)(dd)(dd)|") // time - .number("(dd)(dd)(dd)|") // date + .number("(dd)(dd)(dd)|") // time (hhmmss) + .number("(dd)(dd)(dd)|") // date (ddmmyy) .number("(d+.d+)|") // speed .number("(d+.d+)|") // heading .number("(d+)|") // ignition @@ -81,8 +80,8 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { .number("(d+)|") // Alert status .number("(d+.d+)|") // latitude .number("(d+.d+)|") // longitude - .number("(dd)(dd)(dd)|") // time - .number("(dd)(dd)(dd)|") // date + .number("(dd)(dd)(dd)|") // time (hhmmss) + .number("(dd)(dd)(dd)|") // date (ddmmyy) .number("(d+.d+)|") // speed .number("(d+.d+)|") // heading .any() @@ -120,10 +119,7 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder(timeZone) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); position.set(Position.KEY_VERSION_FW, parser.next()); position.set(Position.KEY_VERSION_HW, parser.next()); @@ -154,10 +150,7 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder(timeZone) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); position.setSpeed(parser.nextDouble()); position.setCourse(parser.nextDouble()); @@ -186,10 +179,7 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder(timeZone) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); position.setSpeed(parser.nextDouble()); position.setCourse(parser.nextDouble()); diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java index c9a8322ed..f1a8c7427 100644 --- a/src/org/traccar/protocol/TrvProtocolDecoder.java +++ b/src/org/traccar/protocol/TrvProtocolDecoder.java @@ -38,14 +38,14 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("TRV") .number("APdd") - .number("(dd)(dd)(dd)") // date + .number("(dd)(dd)(dd)") // date (yymmdd) .expression("([AV])") // validity .number("(dd)(dd.d+)") // latitude .expression("([NS])") .number("(ddd)(dd.d+)") // longitude .expression("([EW])") .number("(ddd.d)") // speed - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // time (hhmmss) .number("([d.]{6})") // course .number("(ddd)") // gsm .number("(ddd)") // satellites diff --git a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java index 32e20c272..88895ff1a 100644 --- a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -49,15 +48,15 @@ public class Tt8850ProtocolDecoder extends BaseProtocolDecoder { .number("(-?d{1,5}.d)?,") // altitude .number("(-?d{1,3}.d{6}),") // longitude .number("(-?d{1,2}.d{6}),") // latitude - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(0ddd)?,") // mcc .number("(0ddd)?,") // mnc .number("(xxxx)?,") // lac .number("(xxxx)?,") // cell .any() - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(xxxx)") .compile(); @@ -87,10 +86,7 @@ public class Tt8850ProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); if (parser.hasNext(4)) { position.setNetwork(new Network( diff --git a/src/org/traccar/protocol/UproProtocolDecoder.java b/src/org/traccar/protocol/UproProtocolDecoder.java index 37536d1dd..44916988e 100644 --- a/src/org/traccar/protocol/UproProtocolDecoder.java +++ b/src/org/traccar/protocol/UproProtocolDecoder.java @@ -50,13 +50,13 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { .compile(); private static final Pattern PATTERN_LOCATION = new PatternBuilder() - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)") // time (hhmmss) .number("(dd)(dd)(dddd)") // latitude .number("(ddd)(dd)(dddd)") // longitude .number("(d)") // flags .number("(dd)") // speed .number("(dd)") // course - .number("(dd)(dd)(dd)") // date + .number("(dd)(dd)(dd)") // date (ddmmyy) .compile(); private void decodeLocation(Position position, String data) { diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java index 58ece0e75..caa0e5e23 100644 --- a/src/org/traccar/protocol/V680ProtocolDecoder.java +++ b/src/org/traccar/protocol/V680ProtocolDecoder.java @@ -47,8 +47,8 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),([NS]),") // latitude .number("(d+.d+),") // speed .number("(d+.?d*)?#") // course - .number("(dd)(dd)(dd)#") // date - .number("(dd)(dd)(dd)") // time + .number("(dd)(dd)(dd)#") // date (ddmmyy) + .number("(dd)(dd)(dd)") // time (hhmmss) .any() .compile(); diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java index 0eac50817..7abef7386 100644 --- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java +++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -37,8 +36,8 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder { .text("$1,") .expression("([^,]+),") // identifier .number("(d+),").optional() // imei - .number("(dd),(dd),(dd),") // date - .number("(dd),(dd),(dd),") // time + .number("(dd),(dd),(dd),") // date (dd,mm,yy) + .number("(dd),(dd),(dd),") // time (hh,mm,ss) .groupBegin() .number("(dd)(dd).?(d+)([NS]),") // latitude .number("(ddd)(dd).?(d+)([EW]),") // longitude @@ -91,10 +90,7 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); if (parser.hasNext(8)) { position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 4a48fe7b6..d95f8c714 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -50,7 +49,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_POSITION = new PatternBuilder() .text(",") .number("(dd)(dd)(dd),") // date (ddmmyy) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([AV]),") // validity .number(" *(-?d+.d+),") // latitude .expression("([NS]),") @@ -182,10 +181,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java index e3db1f8f0..c5b8890f3 100644 --- a/src/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/org/traccar/protocol/WialonProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,7 +38,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number("(dd)(dd)(dd);") // date (ddmmyy) - .number("(dd)(dd)(dd);") // time + .number("(dd)(dd)(dd);") // time (hhmmss) .number("(dd)(dd.d+);") // latitude .expression("([NS]);") .number("(ddd)(dd.d+);") // longitude @@ -85,10 +84,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java index 491252bf6..fff4e9103 100644 --- a/src/org/traccar/protocol/WondexProtocolDecoder.java +++ b/src/org/traccar/protocol/WondexProtocolDecoder.java @@ -19,7 +19,6 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,8 +38,8 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .number("[^d]*") // deader .number("(d+),") // device identifier - .number("(dddd)(dd)(dd)") // date - .number("(dd)(dd)(dd),") // time + .number("(dddd)(dd)(dd)") // date (yyyymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) .number("(-?d+.d+),") // longitude .number("(-?d+.d+),") // latitude .number("(d+),") // speed @@ -98,10 +97,7 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLongitude(parser.nextDouble()); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java index 5e390a4b7..f60b3e693 100644 --- a/src/org/traccar/protocol/XexunProtocolDecoder.java +++ b/src/org/traccar/protocol/XexunProtocolDecoder.java @@ -37,13 +37,13 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_BASIC = new PatternBuilder() .expression("G[PN]RMC,") - .number("(?:(dd)(dd)(dd))?.(d+),") // time + .number("(?:(dd)(dd)(dd))?.?d*,") // time (hhmmss) .expression("([AV]),") // validity .number("(d*?)(d?d.d+),([NS]),") // latitude .number("(d*?)(d?d.d+),([EW])?,") // longitude .number("(d+.?d*),") // speed .number("(d+.?d*)?,") // course - .number("(?:(dd)(dd)(dd))?,") // date + .number("(?:(dd)(dd)(dd))?,") // date (ddmmyy) .expression("[^*]*").text("*") .number("xx") // checksum .expression("\\r\\n").optional() @@ -104,7 +104,7 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder { } DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java index 633479350..cc97a77f9 100644 --- a/src/org/traccar/protocol/XirgoProtocolDecoder.java +++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -39,8 +38,8 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { .text("$$") .number("(d+),") // imei .number("(d+),") // event - .number("(dddd)/(dd)/(dd),") // date - .number("(dd):(dd):(dd),") // time + .number("(dddd)/(dd)/(dd),") // date (yyyy/mm/dd) + .number("(dd):(dd):(dd),") // time (hh:mm:ss) .number("(-?d+.?d*),") // latitude .number("(-?d+.?d*),") // longitude .number("(-?d+.?d*),") // altitude @@ -59,8 +58,8 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { .text("$$") .number("(d+),") // imei .number("(d+),") // event - .number("(dddd)/(dd)/(dd),") // date - .number("(dd):(dd):(dd),") // time + .number("(dddd)/(dd)/(dd),") // date (yyyy/mm/dd) + .number("(dd):(dd):(dd),") // time (hh:mm:ss) .number("(-?d+.?d*),") // latitude .number("(-?d+.?d*),") // longitude .number("(-?d+.?d*),") // altitude @@ -120,10 +119,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_EVENT, parser.next()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/Xt013ProtocolDecoder.java b/src/org/traccar/protocol/Xt013ProtocolDecoder.java index 40231a06d..93e26e986 100644 --- a/src/org/traccar/protocol/Xt013ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xt013ProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -38,7 +37,7 @@ public class Xt013ProtocolDecoder extends BaseProtocolDecoder { .text("TK,") .number("(d+),") // imei .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .number("([+-]d+.d+),") // latitude .number("([+-]d+.d+),") // longitude .number("(d+),") // speed @@ -75,10 +74,7 @@ public class Xt013ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/Xt2400Protocol.java b/src/org/traccar/protocol/Xt2400Protocol.java new file mode 100644 index 000000000..0c5e9cd4c --- /dev/null +++ b/src/org/traccar/protocol/Xt2400Protocol.java @@ -0,0 +1,41 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; + +import java.util.List; + +public class Xt2400Protocol extends BaseProtocol { + + public Xt2400Protocol() { + super("xt2400"); + } + + @Override + public void initTrackerServers(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new Xt2400ProtocolDecoder(Xt2400Protocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/Xt2400ProtocolDecoder.java b/src/org/traccar/protocol/Xt2400ProtocolDecoder.java new file mode 100644 index 000000000..a42c6175f --- /dev/null +++ b/src/org/traccar/protocol/Xt2400ProtocolDecoder.java @@ -0,0 +1,187 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.Context; +import org.traccar.DeviceSession; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Position; + +import javax.xml.bind.DatatypeConverter; +import java.net.SocketAddress; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Xt2400ProtocolDecoder extends BaseProtocolDecoder { + + public Xt2400ProtocolDecoder(Xt2400Protocol protocol) { + super(protocol); + + String config = Context.getConfig().getString(getProtocolName() + ".config"); + if (config != null) { + setConfig(config); + } + } + + private static final Map<Integer, Integer> TAG_LENGTH_MAP = new HashMap<>(); + + static { + int[] l1 = { + 0x01, 0x02, 0x04, 0x0b, 0x0c, 0x0d, 0x12, 0x13, + 0x16, 0x17, 0x1c, 0x1f, 0x23, 0x2c, 0x2d, 0x30, + 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x40, 0x41, + 0x53, 0x66, 0x69, 0x6a, 0x93, 0x94, 0x96 + }; + int[] l2 = { + 0x05, 0x09, 0x0a, 0x14, 0x15, 0x1d, 0x1e, 0x24, + 0x26, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, + 0x49, 0x57, 0x58, 0x59, 0x5a, 0x6b, 0x6f, 0x7A, + 0x7B, 0x7C, 0x7d, 0x7E, 0x7F, 0x80, 0x81, 0x82, + 0x83, 0x84, 0x85, 0x86 + }; + int[] l4 = { + 0x03, 0x06, 0x07, 0x08, 0x0e, 0x0f, 0x10, 0x11, + 0x18, 0x19, 0x1a, 0x1b, 0x20, 0x21, 0x22, 0x2e, + 0x2f, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, + 0x51, 0x52, 0x54, 0x55, 0x56, 0x5b, 0x5c, 0x5d, + 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x68, 0x6e, 0x71, + 0x72, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d + }; + for (int i : l1) { + TAG_LENGTH_MAP.put(i, 1); + } + for (int i : l2) { + TAG_LENGTH_MAP.put(i, 2); + } + for (int i : l4) { + TAG_LENGTH_MAP.put(i, 4); + } + TAG_LENGTH_MAP.put(0x65, 17); + TAG_LENGTH_MAP.put(0x73, 16); + TAG_LENGTH_MAP.put(0x95, 24); + } + + private static int getTagLength(int tag) { + Integer length = TAG_LENGTH_MAP.get(tag); + if (length == null) { + throw new IllegalArgumentException("Unknown tag: " + tag); + } + return length; + } + + private Map<Short, byte[]> formats = new HashMap<>(); + + public void setConfig(String configString) { + Pattern pattern = Pattern.compile(":wycfg pcr\\[\\d+\\] ([0-9a-fA-F]{2})[0-9a-fA-F]{2}([0-9a-fA-F]+)"); + Matcher matcher = pattern.matcher(configString); + while (matcher.find()) { + formats.put(Short.parseShort(matcher.group(1), 16), DatatypeConverter.parseHexBinary(matcher.group(2))); + } + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + ChannelBuffer buf = (ChannelBuffer) msg; + + byte[] format = null; + if (formats.size() > 1) { + format = formats.get(buf.getUnsignedByte(buf.readerIndex())); + } else if (!formats.isEmpty()) { + format = formats.values().iterator().next(); + } + + if (format == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + + for (byte tag : format) { + switch ((int) tag) { + case 0x03: + DeviceSession deviceSession = getDeviceSession( + channel, remoteAddress, String.valueOf(buf.readUnsignedInt())); + if (deviceSession == null) { + return null; + } + position.setDeviceId(deviceSession.getDeviceId()); + break; + case 0x04: + position.set(Position.KEY_EVENT, buf.readUnsignedByte()); + break; + case 0x05: + position.set(Position.KEY_INDEX, buf.readUnsignedShort()); + break; + case 0x06: + position.setTime(new Date(buf.readUnsignedInt() * 1000)); + break; + case 0x07: + position.setLatitude(buf.readInt() * 0.000001); + break; + case 0x08: + position.setLongitude(buf.readInt() * 0.000001); + break; + case 0x09: + position.setAltitude(buf.readShort() * 0.1); + break; + case 0x0a: + position.setCourse(buf.readShort() * 0.1); + break; + case 0x0b: + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + break; + case 0x10: + position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt()); + break; + case 0x12: + position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); + break; + case 0x13: + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + break; + case 0x16: + position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.1); + break; + case 0x17: + position.set(Position.KEY_POWER, buf.readUnsignedByte() * 0.1); + break; + default: + buf.skipBytes(getTagLength(tag)); + break; + } + } + + if (position.getLatitude() != 0 && position.getLongitude() != 0) { + position.setValid(true); + } else { + getLastLocation(position, position.getDeviceTime()); + } + + return position; + } + +} diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java index 85f1264a8..d79ae4439 100644 --- a/src/org/traccar/protocol/YwtProtocolDecoder.java +++ b/src/org/traccar/protocol/YwtProtocolDecoder.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; -import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -37,7 +36,7 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { .number("(d+):") // unit identifier .number("d+,") // subtype .number("(dd)(dd)(dd)") // date (yymmdd) - .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // time (hhmmss) .expression("([EW])") .number("(ddd.d{6}),") // longitude .expression("([NS])") @@ -88,10 +87,7 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + position.setTime(parser.nextDateTime()); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG)); position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG)); diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java index d2255684f..0706f1382 100644 --- a/src/org/traccar/reports/Events.java +++ b/src/org/traccar/reports/Events.java @@ -26,17 +26,8 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import org.apache.poi.ss.util.WorkbookUtil; -import org.joda.time.DateTime; -import org.jxls.area.Area; -import org.jxls.builder.xls.XlsCommentAreaBuilder; -import org.jxls.common.CellRef; -import org.jxls.formula.StandardFormulaProcessor; -import org.jxls.transform.Transformer; -import org.jxls.transform.poi.PoiTransformer; -import org.jxls.util.TransformerFactory; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Event; @@ -70,13 +61,13 @@ public final class Events { public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, - Collection<String> types, DateTime from, DateTime to) throws SQLException, IOException { + Collection<String> types, Date from, Date to) throws SQLException, IOException { ArrayList<DeviceReport> devicesEvents = new ArrayList<>(); ArrayList<String> sheetNames = new ArrayList<>(); HashMap<Long, String> geofenceNames = new HashMap<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); - Collection<Event> events = Context.getDataManager().getEvents(deviceId, from.toDate(), to.toDate()); + Collection<Event> events = Context.getDataManager().getEvents(deviceId, from, to); boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS); for (Iterator<Event> iterator = events.iterator(); iterator.hasNext();) { Event event = iterator.next(); @@ -112,25 +103,13 @@ public final class Events { String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/"); try (InputStream inputStream = new FileInputStream(templatePath + "/events.xlsx")) { - org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext(); + org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId); jxlsContext.putVar("devices", devicesEvents); jxlsContext.putVar("sheetNames", sheetNames); jxlsContext.putVar("geofenceNames", geofenceNames); jxlsContext.putVar("from", from); jxlsContext.putVar("to", to); - jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId)); - jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId)); - jxlsContext.putVar("timezone", from.getZone()); - jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]"); - Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream); - List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build(); - for (Area xlsArea : xlsAreas) { - xlsArea.applyAt(new CellRef(xlsArea.getStartCellRef().getCellName()), jxlsContext); - xlsArea.setFormulaProcessor(new StandardFormulaProcessor()); - xlsArea.processFormulas(); - } - transformer.deleteSheet(xlsAreas.get(0).getStartCellRef().getSheetName()); - transformer.write(); + ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext); } } } diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index ed97c6857..e2a743b2f 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -16,14 +16,27 @@ */ package org.traccar.reports; +import org.apache.velocity.tools.generic.DateTool; +import org.jxls.area.Area; +import org.jxls.builder.xls.XlsCommentAreaBuilder; +import org.jxls.common.CellRef; +import org.jxls.formula.StandardFormulaProcessor; +import org.jxls.transform.Transformer; +import org.jxls.transform.poi.PoiTransformer; +import org.jxls.util.TransformerFactory; import org.traccar.Context; import org.traccar.helper.Log; import org.traccar.model.Position; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.Collection; +import java.util.List; +import java.util.Locale; import java.util.TimeZone; public final class ReportUtils { @@ -96,4 +109,29 @@ public final class ReportUtils { return "-"; } + public static org.jxls.common.Context initializeContext(long userId) { + org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext(); + jxlsContext.putVar("distanceUnit", getDistanceUnit(userId)); + jxlsContext.putVar("speedUnit", getSpeedUnit(userId)); + jxlsContext.putVar("webUrl", Context.getVelocityEngine().getProperty("web.url")); + jxlsContext.putVar("dateTool", new DateTool()); + jxlsContext.putVar("timezone", getTimezone(userId)); + jxlsContext.putVar("locale", Locale.getDefault()); + jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]"); + return jxlsContext; + } + + public static void processTemplateWithSheets(InputStream templateStream, OutputStream targetStream, + org.jxls.common.Context jxlsContext) throws IOException { + Transformer transformer = TransformerFactory.createTransformer(templateStream, targetStream); + List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build(); + for (Area xlsArea : xlsAreas) { + xlsArea.applyAt(new CellRef(xlsArea.getStartCellRef().getCellName()), jxlsContext); + xlsArea.setFormulaProcessor(new StandardFormulaProcessor()); + xlsArea.processFormulas(); + } + transformer.deleteSheet(xlsAreas.get(0).getStartCellRef().getSheetName()); + transformer.write(); + } + } diff --git a/src/org/traccar/reports/Route.java b/src/org/traccar/reports/Route.java index c1acaf322..aa6b7105b 100644 --- a/src/org/traccar/reports/Route.java +++ b/src/org/traccar/reports/Route.java @@ -24,17 +24,8 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.List; import org.apache.poi.ss.util.WorkbookUtil; -import org.joda.time.DateTime; -import org.jxls.area.Area; -import org.jxls.builder.xls.XlsCommentAreaBuilder; -import org.jxls.common.CellRef; -import org.jxls.formula.StandardFormulaProcessor; -import org.jxls.transform.Transformer; -import org.jxls.transform.poi.PoiTransformer; -import org.jxls.util.TransformerFactory; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Group; @@ -58,13 +49,13 @@ public final class Route { public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, - DateTime from, DateTime to) throws SQLException, IOException { + Date from, Date to) throws SQLException, IOException { ArrayList<DeviceReport> devicesRoutes = new ArrayList<>(); ArrayList<String> sheetNames = new ArrayList<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); Collection<Position> positions = Context.getDataManager() - .getPositions(deviceId, from.toDate(), to.toDate()); + .getPositions(deviceId, from, to); DeviceReport deviceRoutes = new DeviceReport(); Device device = Context.getIdentityManager().getDeviceById(deviceId); deviceRoutes.setDeviceName(device.getName()); @@ -81,24 +72,12 @@ public final class Route { String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/"); try (InputStream inputStream = new FileInputStream(templatePath + "/route.xlsx")) { - org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext(); + org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId); jxlsContext.putVar("devices", devicesRoutes); jxlsContext.putVar("sheetNames", sheetNames); jxlsContext.putVar("from", from); jxlsContext.putVar("to", to); - jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId)); - jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId)); - jxlsContext.putVar("timezone", from.getZone()); - jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]"); - Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream); - List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build(); - for (Area xlsArea : xlsAreas) { - xlsArea.applyAt(new CellRef(xlsArea.getStartCellRef().getCellName()), jxlsContext); - xlsArea.setFormulaProcessor(new StandardFormulaProcessor()); - xlsArea.processFormulas(); - } - transformer.deleteSheet(xlsAreas.get(0).getStartCellRef().getSheetName()); - transformer.write(); + ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext); } } } diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java index cacb4d1d6..abe0277da 100644 --- a/src/org/traccar/reports/Summary.java +++ b/src/org/traccar/reports/Summary.java @@ -25,8 +25,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import org.joda.time.DateTime; -import org.jxls.transform.poi.PoiTransformer; import org.jxls.util.JxlsHelper; import org.traccar.Context; import org.traccar.model.Position; @@ -79,18 +77,15 @@ public final class Summary { public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, - DateTime from, DateTime to) throws SQLException, IOException { - Collection<SummaryReport> summaries = getObjects(userId, deviceIds, groupIds, from.toDate(), to.toDate()); + Date from, Date to) throws SQLException, IOException { + Collection<SummaryReport> summaries = getObjects(userId, deviceIds, groupIds, from, to); String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/"); try (InputStream inputStream = new FileInputStream(templatePath + "/summary.xlsx")) { - org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext(); + org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId); jxlsContext.putVar("summaries", summaries); jxlsContext.putVar("from", from); jxlsContext.putVar("to", to); - jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId)); - jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId)); - jxlsContext.putVar("timezone", from.getZone()); JxlsHelper.getInstance().setUseFastFormulaProcessor(false) .processTemplate(inputStream, outputStream, jxlsContext); } diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java index 45b52b63c..eeb2f2681 100644 --- a/src/org/traccar/reports/Trips.java +++ b/src/org/traccar/reports/Trips.java @@ -24,17 +24,8 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.List; import org.apache.poi.ss.util.WorkbookUtil; -import org.joda.time.DateTime; -import org.jxls.area.Area; -import org.jxls.builder.xls.XlsCommentAreaBuilder; -import org.jxls.common.CellRef; -import org.jxls.formula.StandardFormulaProcessor; -import org.jxls.transform.Transformer; -import org.jxls.transform.poi.PoiTransformer; -import org.jxls.util.TransformerFactory; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Group; @@ -193,12 +184,12 @@ public final class Trips { public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, - DateTime from, DateTime to) throws SQLException, IOException { + Date from, Date to) throws SQLException, IOException { ArrayList<DeviceReport> devicesTrips = new ArrayList<>(); ArrayList<String> sheetNames = new ArrayList<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); - Collection<TripReport> trips = detectTrips(deviceId, from.toDate(), to.toDate()); + Collection<TripReport> trips = detectTrips(deviceId, from, to); DeviceReport deviceTrips = new DeviceReport(); Device device = Context.getIdentityManager().getDeviceById(deviceId); deviceTrips.setDeviceName(device.getName()); @@ -215,23 +206,12 @@ public final class Trips { String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/"); try (InputStream inputStream = new FileInputStream(templatePath + "/trips.xlsx")) { - org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext(); + org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId); jxlsContext.putVar("devices", devicesTrips); jxlsContext.putVar("sheetNames", sheetNames); jxlsContext.putVar("from", from); jxlsContext.putVar("to", to); - jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId)); - jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId)); - jxlsContext.putVar("timezone", from.getZone()); - Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream); - List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build(); - for (Area xlsArea : xlsAreas) { - xlsArea.applyAt(new CellRef(xlsArea.getStartCellRef().getCellName()), jxlsContext); - xlsArea.setFormulaProcessor(new StandardFormulaProcessor()); - xlsArea.processFormulas(); - } - transformer.deleteSheet(xlsAreas.get(0).getStartCellRef().getSheetName()); - transformer.write(); + ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext); } } |