diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-01-19 12:09:29 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-01-19 12:09:29 +1300 |
commit | 625048edc94a4356145b61713861c6b48535a220 (patch) | |
tree | 69de05db3a86c770e5a6be1c5dd4e7643dcf25e6 | |
parent | 1edf8f7a5390ea8cbbe9a87036166630cfea57f6 (diff) | |
download | trackermap-server-625048edc94a4356145b61713861c6b48535a220.tar.gz trackermap-server-625048edc94a4356145b61713861c6b48535a220.tar.bz2 trackermap-server-625048edc94a4356145b61713861c6b48535a220.zip |
Start implementing new GoSafe format
-rw-r--r-- | src/org/traccar/protocol/GoSafeProtocolDecoder.java | 22 | ||||
-rw-r--r-- | test/org/traccar/protocol/GoSafeProtocolDecoderTest.java | 6 |
2 files changed, 18 insertions, 10 deletions
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<Position> 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; diff --git a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java index e4f20f6ba..8569fcae8 100644 --- a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java @@ -10,11 +10,11 @@ public class GoSafeProtocolDecoderTest extends ProtocolTest { GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(new GoSafeProtocol()); - verifyNothing(decoder, text( - "*GS02,358696043774648")); + /*verifyPositions(decoder, text( + "*GS02,358696043774648,GPS:230040;A;S1.166829;E36.934287;0;0;170116,STT:20;0,MGR:32755204,ADC:0;11.2;1;28.3;2;4.1,GFS:0;0"));*/ verifyNothing(decoder, text( - "*GS02,358696043774648,GPS:230040;A;S1.166829;E36.934287;0;0;170116,STT:20;0,MGR:32755204,ADC:0;11.2;1;28.3;2;4.1,GFS:0;0")); + "*GS02,358696043774648")); verifyPositions(decoder, text( "*GS16,351535058709775,100356130215,,SYS:G79W;V1.06;V1.0.2,GPS:A;6;N24.802700;E46.616828;0;0;684;1.35,COT:60,ADC:4.31;0.10,DTT:20000;;0;0;0;1")); |