diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-09-30 02:58:57 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-09-30 02:58:57 +1300 |
commit | 7d8f4290bbd4400152660923f4e8024d016b27ec (patch) | |
tree | 00d4675384a6ebd177dfd36e6ba4899c02f1382e | |
parent | 2484aa3465994e7281cd98427cdc338f5cbdbce1 (diff) | |
download | trackermap-server-7d8f4290bbd4400152660923f4e8024d016b27ec.tar.gz trackermap-server-7d8f4290bbd4400152660923f4e8024d016b27ec.tar.bz2 trackermap-server-7d8f4290bbd4400152660923f4e8024d016b27ec.zip |
Implement JT701 device support
4 files changed, 43 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/Jt600FrameDecoder.java b/src/org/traccar/protocol/Jt600FrameDecoder.java index cb7fce0c0..bc6ad1b53 100644 --- a/src/org/traccar/protocol/Jt600FrameDecoder.java +++ b/src/org/traccar/protocol/Jt600FrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2013 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. @@ -35,7 +35,8 @@ public class Jt600FrameDecoder extends FrameDecoder { char type = (char) buf.getByte(buf.readerIndex()); if (type == '$') { - int length = buf.getUnsignedShort(buf.readerIndex() + 7) + 10; + boolean longFormat = buf.getUnsignedByte(buf.readerIndex() + 1) == 0x75; + int length = buf.getUnsignedShort(buf.readerIndex() + (longFormat ? 8 : 7)) + 10; if (length >= buf.readableBytes()) { return buf.readBytes(length); } diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index b30bd7b85..fd2448c0d 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -50,6 +50,8 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { buf.readByte(); // header + boolean longFormat = buf.getUnsignedByte(buf.readerIndex()) == 0x75; + String id = String.valueOf(Long.parseLong(ChannelBuffers.hexDump(buf.readBytes(5)))); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { @@ -57,9 +59,12 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - int version = BcdUtil.readInteger(buf, 1); - buf.readUnsignedByte(); // type - buf.readBytes(2); // length + if (longFormat) { + buf.readUnsignedByte(); // protocol + } + + int version = buf.readUnsignedByte() >> 4; + buf.readUnsignedShort(); // length DateBuilder dateBuilder = new DateBuilder() .setDay(BcdUtil.readInteger(buf, 2)) @@ -87,7 +92,28 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(BcdUtil.readInteger(buf, 2)); position.setCourse(buf.readUnsignedByte() * 2.0); - if (version == 1) { + if (longFormat) { + + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000); + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + + buf.readUnsignedInt(); // vehicle id combined + + position.set(Position.KEY_STATUS, buf.readUnsignedShort()); + + int battery = buf.readUnsignedByte(); + if (battery == 0xff) { + position.set(Position.KEY_CHARGE, true); + } else { + position.set(Position.KEY_BATTERY, battery + "%"); + } + + position.set(Position.KEY_CID, buf.readUnsignedShort()); + position.set(Position.KEY_LAC, buf.readUnsignedShort()); + position.set(Position.KEY_GSM, buf.readUnsignedByte()); + position.set(Position.KEY_INDEX, buf.readUnsignedByte()); + + } else if (version == 1) { position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.set(Position.KEY_POWER, buf.readUnsignedByte()); diff --git a/test/org/traccar/protocol/Jt600FrameDecoderTest.java b/test/org/traccar/protocol/Jt600FrameDecoderTest.java index ccfbcf0d0..43f7461d0 100644 --- a/test/org/traccar/protocol/Jt600FrameDecoderTest.java +++ b/test/org/traccar/protocol/Jt600FrameDecoderTest.java @@ -12,6 +12,10 @@ public class Jt600FrameDecoderTest extends ProtocolTest { Jt600FrameDecoder decoder = new Jt600FrameDecoder(); Assert.assertEquals( + binary("2475605035891613002328091601152806086750106533350c00000000000a000000000000e1ff4f97007f1607"), + decoder.decode(null, null, binary("2475605035891613002328091601152806086750106533350c00000000000a000000000000e1ff4f97007f1607"))); + + Assert.assertEquals( binary("28333132303832303032392C5730312C30323535332E333535352C452C323433382E303939372C532C412C3137313031322C3035333333392C302C382C32302C362C33312C352C32302C323029"), decoder.decode(null, null, binary("28333132303832303032392C5730312C30323535332E333535352C452C323433382E303939372C532C412C3137313031322C3035333333392C302C382C32302C362C33312C352C32302C323029"))); diff --git a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java index 706987164..64db2a124 100644 --- a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java @@ -11,6 +11,12 @@ public class Jt600ProtocolDecoderTest extends ProtocolTest { Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(new Jt600Protocol()); + verifyPosition(decoder, binary( + "2475201509260111002313101503464722331560113555309F00000000002D0500CB206800F064109326381A03")); + + verifyPosition(decoder, binary( + "2475605035891613002328091601152806086750106533350c00000000000a000000000000e1ff4f97007f1607")); + verifyPosition(decoder, buffer( "(3301210003,U01,040812,185302,T,22.564025,N,113.242329,E,5.21,152,9,32%,00000000000011,10133,5173,22,100,1)")); |