aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-02-21 11:48:00 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-02-21 11:48:00 +1300
commit2c8223bed1ae6ed809a50a4e459e3cc50068bd86 (patch)
tree919c279ad1750109910c0e1e0c9ba270909a34bc
parent63d3e629fd0b4d02b1885160e4289596cfd958c0 (diff)
downloadtraccar-server-2c8223bed1ae6ed809a50a4e459e3cc50068bd86.tar.gz
traccar-server-2c8223bed1ae6ed809a50a4e459e3cc50068bd86.tar.bz2
traccar-server-2c8223bed1ae6ed809a50a4e459e3cc50068bd86.zip
Support another Telic protocol format
-rw-r--r--src/org/traccar/protocol/TelicProtocol.java13
-rw-r--r--src/org/traccar/protocol/TelicProtocolDecoder.java19
-rw-r--r--test/org/traccar/protocol/TelicProtocolDecoderTest.java8
3 files changed, 28 insertions, 12 deletions
diff --git a/src/org/traccar/protocol/TelicProtocol.java b/src/org/traccar/protocol/TelicProtocol.java
index c2a7287dd..b2139c54c 100644
--- a/src/org/traccar/protocol/TelicProtocol.java
+++ b/src/org/traccar/protocol/TelicProtocol.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.
@@ -17,11 +17,12 @@ package org.traccar.protocol;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
import org.jboss.netty.handler.codec.string.StringDecoder;
import org.traccar.BaseProtocol;
-import org.traccar.CharacterDelimiterFrameDecoder;
import org.traccar.TrackerServer;
+import java.nio.ByteOrder;
import java.util.List;
public class TelicProtocol extends BaseProtocol {
@@ -32,14 +33,16 @@ public class TelicProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\0'));
+ pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 4, 1, 4));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("objectDecoder", new TelicProtocolDecoder(TelicProtocol.this));
}
- });
+ };
+ server.setEndianness(ByteOrder.LITTLE_ENDIAN);
+ serverList.add(server);
}
}
diff --git a/src/org/traccar/protocol/TelicProtocolDecoder.java b/src/org/traccar/protocol/TelicProtocolDecoder.java
index 466b40aa4..3ba81de6e 100644
--- a/src/org/traccar/protocol/TelicProtocolDecoder.java
+++ b/src/org/traccar/protocol/TelicProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 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.
@@ -39,8 +39,13 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder {
.number("d+,")
.number("(dd)(dd)(dd)") // date
.number("(dd)(dd)(dd),") // time
+ .groupBegin()
+ .number("(ddd)(dd)(dddd),") // longitude
+ .number("(dd)(dd)(dddd),") // latitude
+ .or()
.number("(-?d+),") // longitude
.number("(-?d+),") // latitude
+ .groupEnd()
.number("(d),") // validity
.number("(d+),") // speed
.number("(d+),") // course
@@ -72,8 +77,16 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder {
.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
position.setTime(dateBuilder.getDate());
- position.setLongitude(parser.nextDouble() / 10000);
- position.setLatitude(parser.nextDouble() / 10000);
+ if (parser.hasNext(6)) {
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN));
+ }
+
+ if (parser.hasNext(2)) {
+ position.setLongitude(parser.nextDouble() / 10000);
+ position.setLatitude(parser.nextDouble() / 10000);
+ }
+
position.setValid(parser.nextInt() != 1);
position.setSpeed(parser.nextDouble());
position.setCourse(parser.nextDouble());
diff --git a/test/org/traccar/protocol/TelicProtocolDecoderTest.java b/test/org/traccar/protocol/TelicProtocolDecoderTest.java
index 536875a2f..62a80c94f 100644
--- a/test/org/traccar/protocol/TelicProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/TelicProtocolDecoderTest.java
@@ -10,15 +10,15 @@ public class TelicProtocolDecoderTest extends ProtocolTest {
TelicProtocolDecoder decoder = new TelicProtocolDecoder(new TelicProtocol());
- verifyNothing(decoder, text(
- "0026436729|232|01|003002030"));
+ verifyPosition(decoder, text(
+ "002017297899,190216202500,0,190216202459,014221890,46492170,3,0,0,6,,,1034,43841,,0000,00,0,209,0,0407\u0000"));
verifyPosition(decoder, text(
- "182043672999,010100001301,0,270613041652,166653,475341,3,0,355,6,2,1,231,8112432,23201,01,00,217,0,0,0,0,7"),
+ "182043672999,010100001301,0,270613041652,166653,475341,3,0,355,6,2,1,231,8112432,23201,01,00,217,0,0,0,0,7\u0000"),
position("2013-06-27 04:16:52.000", true, 47.53410, 16.66530));
verifyPosition(decoder, text(
- "182043672999,010100001301,0,270613041652,166653,475341,3,0,355,6,2,1,231,8112432,23201,01,00,217,0,0,0,0,7"));
+ "182043672999,010100001301,0,270613041652,166653,475341,3,0,355,6,2,1,231,8112432,23201,01,00,217,0,0,0,0,7\u0000"));
}