diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-06 16:22:23 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-06 16:22:23 +1300 |
commit | 2bf8597601c9ab2d9569a7cd63c5bf351ce44763 (patch) | |
tree | abf2d02c0d063157214f6917c0e4e522bc78878c | |
parent | dbcfd8488213623e68607fa946df63256dbabf18 (diff) | |
download | traccar-server-2bf8597601c9ab2d9569a7cd63c5bf351ce44763.tar.gz traccar-server-2bf8597601c9ab2d9569a7cd63c5bf351ce44763.tar.bz2 traccar-server-2bf8597601c9ab2d9569a7cd63c5bf351ce44763.zip |
Replace EV603 decoder with MiniFinder
5 files changed, 44 insertions, 195 deletions
diff --git a/src/org/traccar/protocol/Ev603Protocol.java b/src/org/traccar/protocol/Ev603Protocol.java deleted file mode 100644 index 8e00b534f..000000000 --- a/src/org/traccar/protocol/Ev603Protocol.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.traccar.BaseProtocol; -import org.traccar.CharacterDelimiterFrameDecoder; -import org.traccar.TrackerServer; - -import java.util.List; - -public class Ev603Protocol extends BaseProtocol { - - public Ev603Protocol() { - super("ev603"); - } - - @Override - public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ';')); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new Ev603ProtocolDecoder(Ev603Protocol.this)); - } - }); - } - -} diff --git a/src/org/traccar/protocol/Ev603ProtocolDecoder.java b/src/org/traccar/protocol/Ev603ProtocolDecoder.java deleted file mode 100644 index 451aff7f2..000000000 --- a/src/org/traccar/protocol/Ev603ProtocolDecoder.java +++ /dev/null @@ -1,103 +0,0 @@ -/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
- * Luis Parada (luis.parada@gmail.com)
- *
- * 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 java.net.SocketAddress;
-import java.util.Calendar;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.jboss.netty.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.model.Position;
-
-public class Ev603ProtocolDecoder extends BaseProtocolDecoder {
-
- public Ev603ProtocolDecoder(Ev603Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = Pattern.compile(
- "!.," + // Type
- "(\\d{2})/(\\d{2})/(\\d{2})," + // Date dd/mm/YY
- "(\\d{2}):(\\d{2}):(\\d{2})," + // Time hh:mm:ss
- "(-?\\d+\\.\\d+)," + // Latitude
- "(-?\\d+\\.\\d+)," + // Longitude
- "(\\d+\\.?\\d*)," + // Speed
- "(\\d+\\.?\\d*)," + // Course
- ".*");
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg)
- throws Exception {
-
- String sentence = (String) msg;
-
- // Detect device ID
- if (sentence.startsWith("!1,")) {
-
- identify(sentence.substring(3), channel);
-
- } else {
-
- // Parse message
- Matcher parser = PATTERN.matcher(sentence);
- if (!hasDeviceId() || !parser.matches()) {
- return null;
- }
-
- // Create new position
- Position position = new Position();
- position.setDeviceId(getDeviceId());
- position.setProtocol(getProtocolName());
- Integer index = 1;
-
- // Date
- Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- time.clear();
- time.set(Calendar.DAY_OF_MONTH, Integer.parseInt(parser.group(index++)));
- time.set(Calendar.MONTH, Integer.parseInt(parser.group(index++)) - 1);
- time.set(Calendar.YEAR, 2000 + Integer.parseInt(parser.group(index++)));
-
- // Time
- time.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parser.group(index++)));
- time.set(Calendar.MINUTE, Integer.parseInt(parser.group(index++)));
- time.set(Calendar.SECOND, Integer.parseInt(parser.group(index++)));
- position.setTime(time.getTime());
-
- // Validity
- position.setValid(true);
-
- // Coordinates
- position.setLatitude(Double.parseDouble(parser.group(index++)));
- position.setLongitude(Double.parseDouble(parser.group(index++)));
-
- // Speed
- position.setSpeed(Double.parseDouble(parser.group(index++)));
-
- // Course
- position.setCourse(Double.parseDouble(parser.group(index++)));
- if (position.getCourse() > 360) {
- position.setCourse(0);
- }
- return position;
- }
-
- return null;
- }
-}
diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index 9f4febccb..5a5ef3964 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -33,19 +33,23 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN = new PatternBuilder() - .text("!D,") + .expression("![AD],") .number("(d+)/(d+)/(d+),") // date .number("(d+):(d+):(d+),") // time .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude .number("(d+.?d*),") // speed .number("(d+.?d*),") // course + .groupBegin() .number("(x+),") // flags .number("(-?d+.d+),") // altitude .number("(d+),") // battery .number("(d+),") // satellites in use .number("(d+),") // satellites in view .text("0") + .or() + .any() + .groupEnd() .compile(); @Override @@ -58,7 +62,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { identify(sentence.substring(3, sentence.length()), channel); - } else if (sentence.startsWith("!D") && hasDeviceId()) { + } else if ((sentence.startsWith("!D") || sentence.startsWith("!A")) && hasDeviceId()) { Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { @@ -77,16 +81,24 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); + if (position.getCourse() > 360) { + position.setCourse(0); + } + + if (parser.hasNext(5)) { - int flags = parser.nextInt(16); - position.set(Event.KEY_FLAGS, flags); - position.setValid(BitUtil.check(flags, 0)); + int flags = parser.nextInt(16); + position.set(Event.KEY_FLAGS, flags); + position.setValid(BitUtil.check(flags, 0)); - position.setAltitude(parser.nextDouble()); + position.setAltitude(parser.nextDouble()); - position.set(Event.KEY_BATTERY, parser.next()); - position.set(Event.KEY_SATELLITES, parser.next()); + position.set(Event.KEY_BATTERY, parser.next()); + position.set(Event.KEY_SATELLITES, parser.next()); + + } return position; diff --git a/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java b/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java deleted file mode 100644 index a843fcf21..000000000 --- a/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.traccar.protocol; - -import org.junit.Test; -import org.traccar.ProtocolDecoderTest; - -public class Ev603ProtocolDecoderTest extends ProtocolDecoderTest { - - @Test - public void testDecode() throws Exception { - - Ev603ProtocolDecoder decoder = new Ev603ProtocolDecoder(new Ev603Protocol()); - - verifyNothing(decoder, text( - "!1,123456789012345")); - - verifyNothing(decoder, text( - "!5,17,V")); - - verifyNothing(decoder, text( - "!1,860719027585011")); - - verifyPosition(decoder, text( - "!A,26/10/12,00:28:41,7.770385,-72.215706,0.0,25101,0")); - - verifyPosition(decoder, text( - "!A,01/12/10,13:25:35,22.641724,114.023666,000.1,281.6,0")); - - verifyPosition(decoder, text( - "!D,08/07/15,04:01:32,40.428257,-3.704808,0,0,170001,701.7,22,5,14,0")); - - verifyPosition(decoder, text( - "!D,08/07/15,04:55:13,40.428257,-3.704932,0,0,180001,680.0,8,8,13,0")); - - verifyPosition(decoder, text( - "!D,08/07/15,02:01:32,40.428230,-3.704950,4,170,170001,682.7,43,6,13,0")); - - } - -} diff --git a/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java b/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java index dae9e6bc9..04e5c1172 100644 --- a/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java @@ -11,6 +11,30 @@ public class MiniFinderProtocolDecoderTest extends ProtocolDecoderTest { MiniFinderProtocolDecoder decoder = new MiniFinderProtocolDecoder(new MiniFinderProtocol()); verifyNothing(decoder, text( + "!1,123456789012345")); + + verifyNothing(decoder, text( + "!5,17,V")); + + verifyNothing(decoder, text( + "!1,860719027585011")); + + verifyPosition(decoder, text( + "!A,26/10/12,00:28:41,7.770385,-72.215706,0.0,25101,0")); + + verifyPosition(decoder, text( + "!A,01/12/10,13:25:35,22.641724,114.023666,000.1,281.6,0")); + + verifyPosition(decoder, text( + "!D,08/07/15,04:01:32,40.428257,-3.704808,0,0,170001,701.7,22,5,14,0")); + + verifyPosition(decoder, text( + "!D,08/07/15,04:55:13,40.428257,-3.704932,0,0,180001,680.0,8,8,13,0")); + + verifyPosition(decoder, text( + "!D,08/07/15,02:01:32,40.428230,-3.704950,4,170,170001,682.7,43,6,13,0")); + + verifyNothing(decoder, text( "!1,860719020212696")); verifyPosition(decoder, text( |