aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-26 02:44:36 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-26 11:45:31 +1200
commitc700bfdb66071ba224ddf01e9827e721562fed7a (patch)
treeefab24c586077373a826dd605652b04431010bd7 /src
parent5346d413972191b3089969e4832bed2ffabbfb83 (diff)
downloadtraccar-server-c700bfdb66071ba224ddf01e9827e721562fed7a.tar.gz
traccar-server-c700bfdb66071ba224ddf01e9827e721562fed7a.tar.bz2
traccar-server-c700bfdb66071ba224ddf01e9827e721562fed7a.zip
Implement AutoTrack XL protocol
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/AutoTrackProtocol.java44
-rw-r--r--src/org/traccar/protocol/AutoTrackProtocolDecoder.java121
2 files changed, 165 insertions, 0 deletions
diff --git a/src/org/traccar/protocol/AutoTrackProtocol.java b/src/org/traccar/protocol/AutoTrackProtocol.java
new file mode 100644
index 000000000..d6d4ac177
--- /dev/null
+++ b/src/org/traccar/protocol/AutoTrackProtocol.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * 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 io.netty.handler.codec.LengthFieldBasedFrameDecoder;
+import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
+import org.traccar.TrackerServer;
+
+import java.nio.ByteOrder;
+import java.util.List;
+
+public class AutoTrackProtocol extends BaseProtocol {
+
+ public AutoTrackProtocol() {
+ super("autotrack");
+ }
+
+ @Override
+ public void initTrackerServers(List<TrackerServer> serverList) {
+ serverList.add(new TrackerServer(false, getName()) {
+ @Override
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
+ pipeline.addLast("frameDecoder",
+ new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, 1024, 5, 2, 2, 0, true));
+ pipeline.addLast("objectDecoder", new AutoTrackProtocolDecoder(AutoTrackProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/AutoTrackProtocolDecoder.java b/src/org/traccar/protocol/AutoTrackProtocolDecoder.java
new file mode 100644
index 000000000..370c561d9
--- /dev/null
+++ b/src/org/traccar/protocol/AutoTrackProtocolDecoder.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * 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 io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
+import org.traccar.helper.UnitsConverter;
+import org.traccar.model.Position;
+
+import java.net.SocketAddress;
+import java.util.Date;
+
+public class AutoTrackProtocolDecoder extends BaseProtocolDecoder {
+
+ public AutoTrackProtocolDecoder(AutoTrackProtocol protocol) {
+ super(protocol);
+ }
+
+ public static final int MSG_LOGIN_REQUEST = 51;
+ public static final int MSG_LOGIN_CONFIRM = 101;
+ public static final int MSG_TELEMETRY_1 = 52;
+ public static final int MSG_TELEMETRY_2 = 66;
+ public static final int MSG_TELEMETRY_3 = 67;
+ public static final int MSG_KEEP_ALIVE = 114;
+
+ private Position decodeTelemetry(DeviceSession deviceSession, ByteBuf buf) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setTime(new Date(1007078400000L + buf.readUnsignedIntLE() * 1000)); // seconds since 2002
+ position.setLatitude(buf.readIntLE() * 0.0000001);
+ position.setLongitude(buf.readIntLE() * 0.0000001);
+
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
+ position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE());
+
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
+
+ position.set(Position.KEY_INPUT, buf.readUnsignedShortLE());
+ buf.readUnsignedIntLE(); // di 3 count
+ buf.readUnsignedIntLE(); // di 4 count
+
+ for (int i = 0; i < 5; i++) {
+ position.set(Position.PREFIX_ADC + (i + 1), buf.readUnsignedShortLE());
+ }
+
+ position.setCourse(buf.readUnsignedShortLE());
+
+ position.set(Position.KEY_STATUS, buf.readUnsignedShortLE());
+ position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, buf.readLongLE());
+ position.set(Position.KEY_INDEX, buf.readUnsignedShortLE());
+
+ buf.readUnsignedShortLE(); // checksum
+
+ return position;
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ByteBuf buf = (ByteBuf) msg;
+
+ buf.skipBytes(4); // sync
+ int type = buf.readUnsignedByte();
+ buf.readUnsignedShortLE(); // length
+
+ switch (type) {
+ case MSG_LOGIN_REQUEST:
+ String imei = ByteBufUtil.hexDump(buf.readBytes(8));
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
+ if (deviceSession == null) {
+ return null;
+ }
+ int fuelConst = buf.readUnsignedShortLE();
+ int tripConst = buf.readUnsignedShortLE();
+ if (channel != null) {
+ ByteBuf response = Unpooled.buffer();
+ response.writeInt(0xF1F1F1F1); // sync
+ response.writeByte(MSG_LOGIN_CONFIRM);
+ response.writeShortLE(12); // length
+ response.writeBytes(ByteBufUtil.decodeHexDump(imei));
+ response.writeShortLE(fuelConst);
+ response.writeShortLE(tripConst);
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
+ }
+ return null;
+ case MSG_TELEMETRY_1:
+ case MSG_TELEMETRY_2:
+ case MSG_TELEMETRY_3:
+ deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
+ return decodeTelemetry(deviceSession, buf);
+ default:
+ return null;
+ }
+ }
+
+}