aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/EasyTrackProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/GpsGateProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/Gt02ProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/L100FrameDecoder.java50
-rw-r--r--src/org/traccar/protocol/L100Protocol.java42
-rw-r--r--src/org/traccar/protocol/L100ProtocolDecoder.java118
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java6
9 files changed, 236 insertions, 18 deletions
diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
index fa792d7b5..41f395fd9 100644
--- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
@@ -86,13 +86,13 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
.setTime(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16));
position.setTime(dateBuilder.getDate());
- if (BitUtil.check(parser.nextInt(16), 7)) {
+ if (BitUtil.check(parser.nextInt(16), 3)) {
position.setLatitude(-parser.nextInt(16) / 600000.0);
} else {
position.setLatitude(parser.nextInt(16) / 600000.0);
}
- if (BitUtil.check(parser.nextInt(16), 7)) {
+ if (BitUtil.check(parser.nextInt(16), 3)) {
position.setLongitude(-parser.nextInt(16) / 600000.0);
} else {
position.setLongitude(parser.nextInt(16) / 600000.0);
diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
index 1cb0ddfde..afc17a9f7 100644
--- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
@@ -58,10 +58,10 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
.expression("([EW]),")
.number("(d+.?d*),") // altitude
.number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
+ .number("(d+.?d*)?,") // course
.number("(dd)(dd)(dd),") // date (ddmmyy)
.number("(dd)(dd)(dd).?(d+)?,") // time
- .expression("([01]),") // validity
+ .expression("([01])") // validity
.any()
.compile();
diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
index d93b93b83..dea1416ac 100644
--- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 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.
@@ -26,6 +26,7 @@ import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
@@ -33,8 +34,9 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- public static final int MSG_HEARTBEAT = 0x1A;
public static final int MSG_DATA = 0x10;
+ public static final int MSG_HEARTBEAT = 0x1A;
+ public static final int MSG_RESPONSE = 0x1C;
@Override
protected Object decode(
@@ -102,6 +104,13 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(latitude);
position.setLongitude(longitude);
+ } else if (type == MSG_RESPONSE) {
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_RESULT,
+ buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII));
+
} else {
return null;
diff --git a/src/org/traccar/protocol/L100FrameDecoder.java b/src/org/traccar/protocol/L100FrameDecoder.java
new file mode 100644
index 000000000..92af255dd
--- /dev/null
+++ b/src/org/traccar/protocol/L100FrameDecoder.java
@@ -0,0 +1,50 @@
+/*
+ * 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.buffer.ChannelBuffer;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.handler.codec.frame.FrameDecoder;
+
+public class L100FrameDecoder extends FrameDecoder {
+
+ @Override
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+
+ if (buf.readableBytes() < 80) {
+ return null;
+ }
+
+ int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x02);
+ if (index == -1) {
+ index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x04);
+ if (index == -1) {
+ return null;
+ }
+ }
+
+ index += 2; // checksum
+
+ if (buf.readableBytes() >= index - buf.readerIndex()) {
+ return buf.readBytes(index - buf.readerIndex());
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/L100Protocol.java b/src/org/traccar/protocol/L100Protocol.java
new file mode 100644
index 000000000..95a4dce68
--- /dev/null
+++ b/src/org/traccar/protocol/L100Protocol.java
@@ -0,0 +1,42 @@
+/*
+ * 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.traccar.BaseProtocol;
+import org.traccar.TrackerServer;
+
+import java.util.List;
+
+public class L100Protocol extends BaseProtocol {
+
+ public L100Protocol() {
+ super("l100");
+ }
+
+ @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 L100FrameDecoder());
+ pipeline.addLast("objectDecoder", new L100ProtocolDecoder(L100Protocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java
new file mode 100644
index 000000000..ff0687751
--- /dev/null
+++ b/src/org/traccar/protocol/L100ProtocolDecoder.java
@@ -0,0 +1,118 @@
+/*
+ * 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.buffer.ChannelBuffer;
+import org.jboss.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.helper.DateBuilder;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
+import org.traccar.model.Position;
+
+import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.regex.Pattern;
+
+public class L100ProtocolDecoder extends BaseProtocolDecoder {
+
+ public L100ProtocolDecoder(L100Protocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("ATL")
+ .number("(d{15}),") // imei
+ .text("$GPRMC,")
+ .number("(dd)(dd)(dd).ddd,") // time
+ .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("(dd)(dd)(dd),") // date
+ .any()
+ .text("#")
+ .number("([01]+),") // io status
+ .number("(d+.d+|N.C),") // adc
+ .expression("[^,]*,") // reserved
+ .expression("[^,]*,") // reserved
+ .number("(d+.d+),") // odometer
+ .number("(d+.d+),") // temperature
+ .number("(d+.d+),") // battery
+ .number("(d+),") // gsm
+ .number("(d+),") // mcc
+ .number("(d+),") // mnc
+ .number("(d+),") // lac
+ .number("(d+)") // cid
+ .text("ATL")
+ .compile();
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ buf.readUnsignedByte(); // start marker
+ buf.readUnsignedByte(); // type
+
+ String sentence = buf.readBytes(buf.readableBytes() - 2).toString(StandardCharsets.US_ASCII);
+
+ Parser parser = new Parser(PATTERN, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ position.setValid(parser.next().equals("A"));
+ 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());
+
+ position.set(Position.KEY_STATUS, parser.next());
+ position.set(Position.PREFIX_ADC + 1, parser.next());
+ position.set(Position.KEY_ODOMETER, parser.nextDouble());
+ position.set(Position.PREFIX_TEMP + 1, parser.nextDouble());
+ position.set(Position.KEY_BATTERY, parser.nextDouble());
+ position.set(Position.KEY_GSM, parser.nextInt());
+ position.set(Position.KEY_MCC, parser.nextInt());
+ position.set(Position.KEY_MNC, parser.nextInt());
+ position.set(Position.KEY_LAC, parser.nextInt());
+ position.set(Position.KEY_CID, parser.nextInt());
+
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index cfa8990dd..f46511b27 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -16,10 +16,8 @@
package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.jboss.netty.handler.codec.http.HttpVersion;
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
@@ -50,8 +48,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
Map<String, List<String>> params = decoder.getParameters();
if (params.isEmpty()) {
- decoder = new QueryStringDecoder(
- request.getContent().toString(StandardCharsets.US_ASCII), false);
+ decoder = new QueryStringDecoder(request.getContent().toString(StandardCharsets.US_ASCII), false);
params = decoder.getParameters();
}
@@ -66,6 +63,10 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
case "deviceid":
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value);
if (deviceSession == null) {
+ if (channel != null) {
+ channel.write(
+ new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST));
+ }
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
@@ -123,9 +124,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
}
if (channel != null) {
- HttpResponse response = new DefaultHttpResponse(
- HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
- channel.write(response).addListener(ChannelFutureListener.CLOSE);
+ channel.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK));
}
return position;
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index a0998d50d..a76c208b5 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -118,12 +118,12 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
int battery = parser.nextInt();
if (battery != 65535) {
- position.set(Position.KEY_BATTERY, battery);
+ position.set(Position.KEY_BATTERY, battery * 0.01);
}
int power = parser.nextInt();
if (power != 65535) {
- position.set(Position.KEY_POWER, power);
+ position.set(Position.KEY_POWER, power * 0.1);
}
return position;
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index ca63e701e..326552e7f 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.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.
@@ -47,9 +47,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
.number("(dd)(dd)(dd),") // date (ddmmyy)
.number("(dd)(dd)(dd),") // time
.expression("([AV]),") // validity
- .number(" *-?(d+.d+),") // latitude
+ .number(" *(-?d+.d+),") // latitude
.expression("([NS]),")
- .number(" *-?(d+.d+),") // longitude
+ .number(" *(-?d+.d+),") // longitude
.expression("([EW])?,")
.number("(d+.d+),") // speed
.number("(d+.?d*),") // course