From 152dde860450adb9ae8409d69f429f35ad1b3b13 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 26 Sep 2017 11:57:08 +0500 Subject: Improve Teltonika IO decoding --- test/org/traccar/ProtocolTest.java | 4 ++++ test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'test/org/traccar') diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java index 7bff41acd..01395fc11 100644 --- a/test/org/traccar/ProtocolTest.java +++ b/test/org/traccar/ProtocolTest.java @@ -257,6 +257,10 @@ public class ProtocolTest extends BaseTest { Assert.assertTrue(attributes.get(Position.KEY_DRIVER_UNIQUE_ID) instanceof String); } + if (attributes.containsKey(Position.KEY_STEPS)) { + Assert.assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number); + } + if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) { for (CellTower cellTower : position.getNetwork().getCellTowers()) { checkInteger(cellTower.getMobileCountryCode(), 0, 999); diff --git a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java index a945178a1..beae48d67 100644 --- a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java @@ -59,6 +59,12 @@ public class TeltonikaProtocolDecoderTest extends ProtocolTest { verifyPositions(decoder, binary( "00000000000000a608010000013f14a1d1ce000f0eb790209a778000ab010c0500000000000000000100003390")); + verifyPositions(decoder, binary( + "000000000000004508010000015eb70a86d00024089d4d21dee3860137005f12005f000e06ef01f00150011503c800450108b5000bb6000642382718005fcd057ace19d3430f57440000000001000002bf")); + + verifyPositions(decoder, binary( + "000000000000004a08010000015ebc1da508002411926621f15246010b00b913005e000f06ef01f00150011505c800450108b5000bb6000642381b18005ecd0318ce19cd430f5844000001f1000061a900010000c8e1")); + decoder.setExtended(true); verifyPositions(decoder, false, binary( -- cgit v1.2.3 From 2e4fe0f4201ff43f65e36fb1ba386a1fa26b9aab Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 26 Sep 2017 14:17:28 +0500 Subject: Added intermediate "decodeParameter" function and KEY_ROAMING attribute --- src/org/traccar/model/Position.java | 1 + .../traccar/protocol/TeltonikaProtocolDecoder.java | 32 ++++++++++------------ test/org/traccar/ProtocolTest.java | 4 +++ 3 files changed, 19 insertions(+), 18 deletions(-) (limited to 'test/org/traccar') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 31af3d38a..93456b1b0 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -30,6 +30,7 @@ public class Position extends Message { public static final String KEY_SATELLITES_VISIBLE = "satVisible"; public static final String KEY_RSSI = "rssi"; public static final String KEY_GPS = "gps"; + public static final String KEY_ROAMING = "roaming"; public static final String KEY_EVENT = "event"; public static final String KEY_ALARM = "alarm"; public static final String KEY_STATUS = "status"; diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 3dd00ead7..8754d7d81 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -93,7 +93,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeParameter(Position position, int id, ChannelBuffer buf, int length) { + private void decodeOtherParameter(Position position, int id, ChannelBuffer buf, int length) { switch (id) { case 1: case 2: @@ -199,7 +199,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_MOTION, readValue(buf, length, false) == 1); break; case 244: - position.set("roaming", readValue(buf, length, false) == 1); + position.set(Position.KEY_ROAMING, readValue(buf, length, false) == 1); break; default: position.set(Position.PREFIX_IO + id, readValue(buf, length, false)); @@ -207,6 +207,14 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } + private void decodeParameter(Position position, int id, ChannelBuffer buf, int length, int codec) { + if (codec == CODEC_GH3000) { + decodeGh3000Parameter(position, id, buf, length); + } else { + decodeOtherParameter(position, id, buf, length); + } + } + private void decodeNetwork(Position position) { long cid = position.getLong(Position.PREFIX_IO + 205); int lac = position.getInteger(Position.PREFIX_IO + 206); @@ -315,11 +323,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(globalMask, 1)) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - if (codec == CODEC_GH3000) { - decodeGh3000Parameter(position, buf.readUnsignedByte(), buf, 1); - } else { - decodeParameter(position, buf.readUnsignedByte(), buf, 1); - } + decodeParameter(position, buf.readUnsignedByte(), buf, 1, codec); } } @@ -327,11 +331,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(globalMask, 2)) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - if (codec == CODEC_GH3000) { - decodeGh3000Parameter(position, buf.readUnsignedByte(), buf, 2); - } else { - decodeParameter(position, buf.readUnsignedByte(), buf, 2); - } + decodeParameter(position, buf.readUnsignedByte(), buf, 2, codec); } } @@ -339,11 +339,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(globalMask, 3)) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - if (codec == CODEC_GH3000) { - decodeGh3000Parameter(position, buf.readUnsignedByte(), buf, 4); - } else { - decodeParameter(position, buf.readUnsignedByte(), buf, 4); - } + decodeParameter(position, buf.readUnsignedByte(), buf, 4, codec); } } @@ -351,7 +347,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (codec == CODEC_FM4X00) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - decodeParameter(position, buf.readUnsignedByte(), buf, 8); + decodeOtherParameter(position, buf.readUnsignedByte(), buf, 8); } } diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java index 01395fc11..1daefabd6 100644 --- a/test/org/traccar/ProtocolTest.java +++ b/test/org/traccar/ProtocolTest.java @@ -261,6 +261,10 @@ public class ProtocolTest extends BaseTest { Assert.assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number); } + if (attributes.containsKey(Position.KEY_ROAMING)) { + Assert.assertTrue(attributes.get(Position.KEY_ROAMING) instanceof Boolean); + } + if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) { for (CellTower cellTower : position.getNetwork().getCellTowers()) { checkInteger(cellTower.getMobileCountryCode(), 0, 999); -- cgit v1.2.3