aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-12-17 20:43:07 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-12-18 21:35:30 +1300
commit7ccf052eec0d2d71903c99bd8620c2bbfa45f311 (patch)
treeb89969c6ed5c23432ef748e95faf7414139ec0da
parent5d974ea790397d0646f013e91c8d3b0829ffbd54 (diff)
downloadtrackermap-server-7ccf052eec0d2d71903c99bd8620c2bbfa45f311.tar.gz
trackermap-server-7ccf052eec0d2d71903c99bd8620c2bbfa45f311.tar.bz2
trackermap-server-7ccf052eec0d2d71903c99bd8620c2bbfa45f311.zip
Implement Arnavi communication protocol
-rw-r--r--debug.xml1
-rw-r--r--src/org/traccar/protocol/ArnaviProtocol.java45
-rw-r--r--src/org/traccar/protocol/ArnaviProtocolDecoder.java98
-rw-r--r--test/org/traccar/protocol/ArnaviProtocolDecoderTest.java21
4 files changed, 165 insertions, 0 deletions
diff --git a/debug.xml b/debug.xml
index 53126404a..ccfb5579e 100644
--- a/debug.xml
+++ b/debug.xml
@@ -269,5 +269,6 @@
<entry key='disha.port'>5097</entry>
<entry key='thinkrace.port'>5098</entry>
<entry key='pathaway.port'>5099</entry>
+ <entry key='arnavi.port'>5100</entry>
</properties>
diff --git a/src/org/traccar/protocol/ArnaviProtocol.java b/src/org/traccar/protocol/ArnaviProtocol.java
new file mode 100644
index 000000000..6afd0282d
--- /dev/null
+++ b/src/org/traccar/protocol/ArnaviProtocol.java
@@ -0,0 +1,45 @@
+/*
+ * 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.frame.LineBasedFrameDecoder;
+import org.jboss.netty.handler.codec.string.StringDecoder;
+import org.traccar.BaseProtocol;
+import org.traccar.TrackerServer;
+
+import java.util.List;
+
+public class ArnaviProtocol extends BaseProtocol {
+
+ public ArnaviProtocol() {
+ super("arnavi");
+ }
+
+ @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 LineBasedFrameDecoder(1024));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("objectDecoder", new ArnaviProtocolDecoder(ArnaviProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/ArnaviProtocolDecoder.java b/src/org/traccar/protocol/ArnaviProtocolDecoder.java
new file mode 100644
index 000000000..47c459446
--- /dev/null
+++ b/src/org/traccar/protocol/ArnaviProtocolDecoder.java
@@ -0,0 +1,98 @@
+/*
+ * 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.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.DateBuilder;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
+import org.traccar.model.Event;
+import org.traccar.model.Position;
+
+import java.net.SocketAddress;
+import java.util.regex.Pattern;
+
+public class ArnaviProtocolDecoder extends BaseProtocolDecoder {
+
+ public ArnaviProtocolDecoder(ArnaviProtocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("$AV,")
+ .number("Vd,") // type
+ .number("(d+),") // device id
+ .number("(d+),") // index
+ .number("(d+),") // power
+ .number("(d+),") // battery
+ .number("-?d+,")
+ .expression("[01],") // movement
+ .expression("([01]),") // ignition
+ .number("(d+),") // input
+ .number("d+,d+,") // input 1
+ .number("d+,d+,").optional() // input 2
+ .expression("[01],") // fix type
+ .number("(d+),") // satellites
+ .number("(dd)(dd)(dd),") // time
+ .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
+ .any()
+ .compile();
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ Parser parser = new Parser(PATTERN, (String) msg);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ if (!identify(parser.next(), channel, remoteAddress)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
+
+ position.set(Event.KEY_INDEX, parser.nextInt());
+ position.set(Event.KEY_POWER, parser.nextInt() * 0.01);
+ position.set(Event.KEY_BATTERY, parser.nextInt() * 0.01);
+ position.set(Event.KEY_IGNITION, parser.nextInt() == 1);
+ position.set(Event.KEY_INPUT, parser.nextInt());
+ position.set(Event.KEY_SATELLITES, parser.nextInt());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ position.setValid(true);
+ position.setLatitude(parser.nextCoordinate());
+ position.setLongitude(parser.nextCoordinate());
+ position.setSpeed(parser.nextDouble());
+ position.setCourse(parser.nextDouble());
+
+ dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ return position;
+ }
+
+}
diff --git a/test/org/traccar/protocol/ArnaviProtocolDecoderTest.java b/test/org/traccar/protocol/ArnaviProtocolDecoderTest.java
new file mode 100644
index 000000000..31daedf24
--- /dev/null
+++ b/test/org/traccar/protocol/ArnaviProtocolDecoderTest.java
@@ -0,0 +1,21 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class ArnaviProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ ArnaviProtocolDecoder decoder = new ArnaviProtocolDecoder(new ArnaviProtocol());
+
+ verifyPosition(decoder, text(
+ "$AV,V2,32768,12487,2277,203,-1,0,0,193,0,0,1,13,200741,5950.6773N,03029.1043E,0.0,0.0,121012,*6E"));
+
+ verifyPosition(decoder, text(
+ "$AV,V3,999999,12487,2277,203,65534,0,0,193,65535,65535,65535,65535,1,13,200741,5950.6773N,03029.1043E,300.0,360.0,121012,65535,65535,65535,SF*6E"));
+
+ }
+
+}