aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-04-27 11:43:08 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-04-27 11:43:08 -0700
commit68beaf9a13f6b9e8023dd73bb7078f80b4a24cf8 (patch)
treeadd268be865501be3a6b517fba714876de8195b9 /src
parentc2c1e429865e84a09ce95dc9f9c8e707fa9c50eb (diff)
downloadtraccar-server-68beaf9a13f6b9e8023dd73bb7078f80b4a24cf8.tar.gz
traccar-server-68beaf9a13f6b9e8023dd73bb7078f80b4a24cf8.tar.bz2
traccar-server-68beaf9a13f6b9e8023dd73bb7078f80b4a24cf8.zip
Implement Radar Trio protocol
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/RadarProtocol.java35
-rw-r--r--src/main/java/org/traccar/protocol/RadarProtocolDecoder.java191
-rw-r--r--src/test/java/org/traccar/protocol/RadarProtocolDecoderTest.java20
3 files changed, 246 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/protocol/RadarProtocol.java b/src/main/java/org/traccar/protocol/RadarProtocol.java
new file mode 100644
index 000000000..9783778f0
--- /dev/null
+++ b/src/main/java/org/traccar/protocol/RadarProtocol.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2019 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;
+
+public class RadarProtocol extends BaseProtocol {
+
+ public RadarProtocol() {
+ addServer(new TrackerServer(false, getName()) {
+ @Override
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
+ pipeline.addLast(new LengthFieldBasedFrameDecoder(1024, 12, 2, -14, 0));
+ pipeline.addLast(new RadarProtocolDecoder(RadarProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/main/java/org/traccar/protocol/RadarProtocolDecoder.java b/src/main/java/org/traccar/protocol/RadarProtocolDecoder.java
new file mode 100644
index 000000000..765171e9c
--- /dev/null
+++ b/src/main/java/org/traccar/protocol/RadarProtocolDecoder.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2019 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.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.Protocol;
+import org.traccar.helper.BitUtil;
+import org.traccar.helper.UnitsConverter;
+import org.traccar.model.Position;
+
+import java.net.SocketAddress;
+import java.util.BitSet;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+
+public class RadarProtocolDecoder extends BaseProtocolDecoder {
+
+ public RadarProtocolDecoder(Protocol protocol) {
+ super(protocol);
+ }
+
+ public static final int MSG_TRACKING = 0x4C;
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ByteBuf buf = (ByteBuf) msg;
+
+ buf.readUnsignedByte(); // product id
+ buf.readUnsignedByte(); // product version
+
+ String serialNumber = String.valueOf(buf.readUnsignedInt());
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, serialNumber);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ buf.readUnsignedByte(); // index
+ buf.readUnsignedInt(); // timestamp
+ int type = buf.readUnsignedByte();
+ buf.readUnsignedShort(); // length
+
+ if (type == MSG_TRACKING) {
+
+ buf.readUnsignedShort(); // memory count
+ buf.readUnsignedShort(); // memory index
+ int count = buf.readUnsignedShort();
+ buf.readUnsignedShort(); // first index
+
+ List<Position> positions = new LinkedList<>();
+
+ for (int index = 0; index < count; index++) {
+
+ Position position = new Position(getProtocolName());
+
+ position.set(Position.KEY_EVENT, buf.readUnsignedShort());
+
+ int maskLength = buf.readUnsignedByte();
+ BitSet mask = BitSet.valueOf(buf.nioBuffer(buf.readerIndex(), maskLength));
+ buf.skipBytes(maskLength);
+
+ buf.readUnsignedShort(); // length
+
+ if (mask.get(0)) {
+ position.setDeviceTime(new Date(buf.readUnsignedInt() * 1000));
+ }
+ if (mask.get(1)) {
+ position.setFixTime(new Date(buf.readUnsignedInt() * 1000));
+ }
+ if (mask.get(2)) {
+ position.setLatitude(buf.readInt() / 360000.0);
+ }
+ if (mask.get(3)) {
+ position.setLongitude(buf.readInt() / 360000.0);
+ }
+ if (mask.get(4)) {
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
+ }
+ if (mask.get(5)) {
+ position.setCourse(buf.readUnsignedShort() * 0.1);
+ }
+ if (mask.get(6)) {
+ position.setAltitude(buf.readShort());
+ }
+ if (mask.get(7)) {
+ int flags = buf.readUnsignedByte();
+ position.setValid(BitUtil.check(flags, 0));
+ position.set(Position.KEY_SATELLITES, BitUtil.from(flags, 4));
+ }
+ if (mask.get(8)) {
+ long flags = buf.readUnsignedInt();
+ position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0));
+ position.set(Position.KEY_CHARGE, BitUtil.check(flags, 1));
+ position.set(Position.KEY_MOTION, BitUtil.check(flags, 2));
+ for (int i = 0; i < 3; i++) {
+ position.set(Position.PREFIX_IN + i, BitUtil.check(flags, 4 + i));
+ }
+ }
+ if (mask.get(9)) {
+ int flags = buf.readUnsignedShort();
+ position.set(Position.KEY_BLOCKED, BitUtil.check(flags, 0));
+ position.set(Position.PREFIX_IN + 0, BitUtil.check(flags, 4));
+ }
+ for (int i = 10; i <= 14; i++) {
+ if (mask.get(i)) {
+ buf.readUnsignedShort(); // reserved
+ }
+ }
+ if (mask.get(15)) {
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100);
+ }
+ if (mask.get(16)) {
+ buf.readUnsignedInt(); // reserved
+ }
+ for (int i = 17; i <= 27; i++) {
+ if (mask.get(i)) {
+ buf.readUnsignedByte(); // reserved
+ }
+ }
+ for (int i = 28; i <= 37; i += 2) {
+ if (mask.get(i)) {
+ buf.skipBytes(12); // reserved
+ }
+ if (mask.get(i + 1)) {
+ buf.readUnsignedByte(); // reserved
+ }
+ }
+ if (mask.get(38)) {
+ buf.skipBytes(6); // driver id
+ }
+ if (mask.get(39)) {
+ buf.readUnsignedShort(); // hardware problems
+ }
+ if (mask.get(40)) {
+ buf.readShort(); // acceleration x
+ }
+ if (mask.get(41)) {
+ buf.readShort(); // acceleration y
+ }
+ if (mask.get(42)) {
+ buf.readShort(); // acceleration z
+ }
+ if (mask.get(43)) {
+ buf.skipBytes(10); // operator
+ }
+ if (mask.get(44)) {
+ buf.readUnsignedShort(); // power
+ }
+ for (int i = 45; i <= 49; i++) {
+ if (mask.get(i)) {
+ buf.readUnsignedByte(); // reserved
+ }
+ }
+ if (mask.get(50)) {
+ buf.readShort(); // tilt
+ }
+
+ if (position.getDeviceTime() != null && position.getFixTime() != null) {
+ positions.add(position);
+ }
+
+ }
+
+ // ACK 0x9C
+
+ return positions.isEmpty() ? null : positions;
+
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/test/java/org/traccar/protocol/RadarProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/RadarProtocolDecoderTest.java
new file mode 100644
index 000000000..3289474d1
--- /dev/null
+++ b/src/test/java/org/traccar/protocol/RadarProtocolDecoderTest.java
@@ -0,0 +1,20 @@
+package org.traccar.protocol;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class RadarProtocolDecoderTest extends ProtocolTest {
+
+ @Ignore
+ @Test
+ public void testDecode() throws Exception {
+
+ RadarProtocolDecoder decoder = new RadarProtocolDecoder(null);
+
+ verifyPosition(decoder, binary(
+ "361800011459015cb497554c01c101ff003500050038000207ff831c04c01f1c00555cb464895cb46487ff7f04eafeffdbd80000079402ead0000000110000000000120d2aff150000000000000002000a00050002436c61726f0000000000008b00000003764500037653005207ff831c04c01f1c00555cb4648a5cb46489ff7f04eafeffdbd80000079402ead0000000010000000000120e00ff150000000000000002000800060002436c61726f0000000000008d00000003764600037654000207ff831c04c01f1c00555cb464d85cb464d7ff7f04eafeffdbd80000079402ead0000000110000000000120e2aff150000000000000002000700070003436c61726f0000000000008d000000037694000376a2005207ff831c04c01f1c00555cb464d95cb464d9ff7f04eafeffdbd80000079402eac0000000010000000000120e00ff150000000000000002000700070003436c61726f0000000000008d000000037695000376a3000207ff831c04c01f1c00555cb465065cb46504ff7f04eafeffdbd80000079402ead0000000110000000000120e2aff150000000000000000000500060005436c61726f0000000000008d0000000376c2000376d07ed7"));
+
+ }
+
+}