From 625048edc94a4356145b61713861c6b48535a220 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 19 Jan 2016 12:09:29 +1300 Subject: Start implementing new GoSafe format --- .../traccar/protocol/GoSafeProtocolDecoder.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java index 2fb7522d3..810aee3e0 100644 --- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,11 +41,12 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // imei .number("(dd)(dd)(dd)") // time .number("(dd)(dd)(dd),") // date + .optional(2) .expression("(.*)#?") // data .compile(); private static final Pattern PATTERN_ITEM = new PatternBuilder() - .number("(x+)?,") // event + .number("(x+)?,").optional() // event .groupBegin() .text("SYS:") .expression("[^,]*,") @@ -105,7 +106,10 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); - position.setTime(time); + + if (time != null) { + position.setTime(time); + } position.set(Event.KEY_EVENT, parser.next()); @@ -153,14 +157,18 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { return null; } - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); + 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(); + } List positions = new LinkedList<>(); Parser itemParser = new Parser(PATTERN_ITEM, parser.next()); while (itemParser.find()) { - positions.add(decodePosition(itemParser, dateBuilder.getDate())); + positions.add(decodePosition(itemParser, time)); } return positions; -- cgit v1.2.3