From 2bf8597601c9ab2d9569a7cd63c5bf351ce44763 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 6 Nov 2015 16:22:23 +1300 Subject: Replace EV603 decoder with MiniFinder --- src/org/traccar/protocol/Ev603Protocol.java | 45 --------- src/org/traccar/protocol/Ev603ProtocolDecoder.java | 103 --------------------- .../protocol/MiniFinderProtocolDecoder.java | 28 ++++-- 3 files changed, 20 insertions(+), 156 deletions(-) delete mode 100644 src/org/traccar/protocol/Ev603Protocol.java delete mode 100644 src/org/traccar/protocol/Ev603ProtocolDecoder.java (limited to 'src/org/traccar/protocol') 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 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; -- cgit v1.2.3