diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-03-19 14:36:22 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-03-19 14:36:22 +1300 |
commit | 4ba1c3d923b3687df93030125c5efd34d1de002d (patch) | |
tree | 629e4be8af9eb0447def407b71426bee9a945a25 | |
parent | 86c0a49ceb012c36fe0bc30be63e27e7608d0f63 (diff) | |
download | trackermap-server-4ba1c3d923b3687df93030125c5efd34d1de002d.tar.gz trackermap-server-4ba1c3d923b3687df93030125c5efd34d1de002d.tar.bz2 trackermap-server-4ba1c3d923b3687df93030125c5efd34d1de002d.zip |
Implement ARKNAV communication protocol
-rw-r--r-- | debug.xml | 1 | ||||
-rw-r--r-- | src/org/traccar/protocol/ArknavProtocol.java | 45 | ||||
-rw-r--r-- | src/org/traccar/protocol/ArknavProtocolDecoder.java | 86 | ||||
-rw-r--r-- | test/org/traccar/protocol/ArknavProtocolDecoderTest.java | 25 |
4 files changed, 157 insertions, 0 deletions
@@ -302,5 +302,6 @@ <entry key='homtecs.port'>5104</entry> <entry key='fox.port'>5105</entry> <entry key='gnx.port'>5106</entry> + <entry key='arknav.port'>5107</entry> </properties> diff --git a/src/org/traccar/protocol/ArknavProtocol.java b/src/org/traccar/protocol/ArknavProtocol.java new file mode 100644 index 000000000..13cb2572f --- /dev/null +++ b/src/org/traccar/protocol/ArknavProtocol.java @@ -0,0 +1,45 @@ +/* + * Copyright 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. + * 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 ArknavProtocol extends BaseProtocol { + + public ArknavProtocol() { + super("arknav"); + } + + @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, '\r')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new ArknavProtocolDecoder(ArknavProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/ArknavProtocolDecoder.java b/src/org/traccar/protocol/ArknavProtocolDecoder.java new file mode 100644 index 000000000..9e85cac3b --- /dev/null +++ b/src/org/traccar/protocol/ArknavProtocolDecoder.java @@ -0,0 +1,86 @@ +/* + * Copyright 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. + * 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 ArknavProtocolDecoder extends BaseProtocolDecoder { + + public ArknavProtocolDecoder(ArknavProtocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .number("(d+),") // imei + .expression(".{6},") // id code + .number("ddd,") // status + .number("Lddd,") // version + .expression("([AV]),") // validity + .number("(dd)(dd.d+),") // latitude + .expression("([NS]),") + .number("(ddd)(dd.d+),") // longitude + .expression("([EW]),") + .number("(d+.?d*),") // speed + .number("(d+.?d*),") // course + .number("(d+.?d*),") // hdop + .number("(dd):(dd):(dd) ") // time + .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.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); + + position.set(Event.KEY_HDOP, parser.nextDouble()); + + DateBuilder dateBuilder = new DateBuilder() + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + return position; + } + +} diff --git a/test/org/traccar/protocol/ArknavProtocolDecoderTest.java b/test/org/traccar/protocol/ArknavProtocolDecoderTest.java new file mode 100644 index 000000000..841e5675b --- /dev/null +++ b/test/org/traccar/protocol/ArknavProtocolDecoderTest.java @@ -0,0 +1,25 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class ArknavProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + ArknavProtocolDecoder decoder = new ArknavProtocolDecoder(new ArknavProtocol()); + + verifyPosition(decoder, text( + "358266016278447,05*827,000,L001,V,4821.6584,N,01053.8650,E,000.0,000.0,00.0,08:46:04 17-03-16,9.5A,D7,0,79,0,,,,"), + position("2016-03-17 08:46:04.000", false, 48.36097, 10.89775)); + + verifyPosition(decoder, text( + "123456789012345,05*850,000,L001,A,2459.3640,N,12125.2958,E,000.0,224.8,00.8,07:47:26 09-09-05,9.00,D3,0,C4,1,,,,")); + + verifyPosition(decoder, text( + "123456789012345,05*850,000,L001,A,2459.3640,N,12125.2958,E,000.0,224.8,00.8,07:47:26 09-09-05,9.00,D3,0,C4,1,,,00000000,")); + + } + +} |