From 8ac74d53d687641b7af79e6ca3a84d8851b46236 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 Nov 2015 14:30:37 +1300 Subject: Fix LBS info for some decoders --- test/org/traccar/ProtocolDecoderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java index 2906f2002..5292bd32d 100644 --- a/test/org/traccar/ProtocolDecoderTest.java +++ b/test/org/traccar/ProtocolDecoderTest.java @@ -187,11 +187,11 @@ public class ProtocolDecoderTest { Assert.assertFalse("no attributes", attributes.isEmpty()); } - /*if (attributes.containsKey(Event.KEY_LAC) || attributes.containsKey(Event.KEY_CID)) { + /*if (attributes.containsKey(Event.KEY_MCC) || attributes.containsKey(Event.KEY_MNC)) { checkInteger(attributes.get(Event.KEY_MCC), 100, 999); checkInteger(attributes.get(Event.KEY_MNC), 0, 999); checkInteger(attributes.get(Event.KEY_LAC), 1, 65535); - checkInteger(attributes.get(Event.KEY_CID), 1, 65535); + checkInteger(attributes.get(Event.KEY_CID), 1, 268435455); }*/ } -- cgit v1.2.3 From de46b77e923d3412d74dbf745933bd62acaeca77 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 Nov 2015 17:22:29 +1300 Subject: Store correct MCC and MNC values --- src/org/traccar/protocol/MegastekProtocolDecoder.java | 12 +++++++----- src/org/traccar/protocol/MeitrackProtocolDecoder.java | 6 +++--- src/org/traccar/protocol/T800xProtocolDecoder.java | 12 ++++++++---- test/org/traccar/ProtocolDecoderTest.java | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index a58e57703..b2db50fd4 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -171,9 +171,11 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_CHARGE, Integer.parseInt(charger) == 1); } - position.set(Event.KEY_MCC, parser.next()); - position.set(Event.KEY_MNC, parser.next()); - position.set(Event.KEY_LAC, parser.next()); + if (parser.hasNext(3)) { + position.set(Event.KEY_MCC, parser.nextInt()); + position.set(Event.KEY_MNC, parser.nextInt()); + position.set(Event.KEY_LAC, parser.next()); + } } else { @@ -194,8 +196,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(getDeviceId()); - position.set(Event.KEY_MCC, parser.next()); - position.set(Event.KEY_MNC, parser.next()); + position.set(Event.KEY_MCC, parser.nextInt()); + position.set(Event.KEY_MNC, parser.nextInt()); position.set(Event.KEY_LAC, parser.next()); position.set(Event.KEY_GSM, parser.next()); diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 2b8460fc7..475329c5d 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -119,8 +119,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_ODOMETER, parser.next()); position.set("runtime", parser.next()); - position.set(Event.KEY_MCC, parser.next()); - position.set(Event.KEY_MCC, parser.next()); + position.set(Event.KEY_MCC, parser.nextInt()); + position.set(Event.KEY_MNC, parser.nextInt()); position.set(Event.KEY_LAC, parser.next()); position.set(Event.KEY_CID, parser.next()); position.set(Event.KEY_STATUS, parser.next()); @@ -196,7 +196,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_ODOMETER, buf.readUnsignedInt()); position.set("runtime", buf.readUnsignedInt()); position.set(Event.KEY_MCC, buf.readUnsignedShort()); - position.set(Event.KEY_MCC, buf.readUnsignedShort()); + position.set(Event.KEY_MNC, buf.readUnsignedShort()); position.set(Event.KEY_LAC, buf.readUnsignedShort()); position.set(Event.KEY_CID, buf.readUnsignedShort()); position.set(Event.KEY_STATUS, buf.readUnsignedShort()); diff --git a/src/org/traccar/protocol/T800xProtocolDecoder.java b/src/org/traccar/protocol/T800xProtocolDecoder.java index 2127be331..83d815e0f 100644 --- a/src/org/traccar/protocol/T800xProtocolDecoder.java +++ b/src/org/traccar/protocol/T800xProtocolDecoder.java @@ -143,10 +143,14 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, dateBuilder.getDate()); - position.set(Event.KEY_MCC, buf.readUnsignedShort()); - position.set(Event.KEY_MNC, buf.readUnsignedShort()); - position.set(Event.KEY_LAC, buf.readUnsignedShort()); - position.set(Event.KEY_CID, buf.readUnsignedShort()); + byte[] array = new byte[16]; + buf.readBytes(array); + ChannelBuffer swapped = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, array); + + position.set(Event.KEY_MCC, swapped.readUnsignedShort()); + position.set(Event.KEY_MNC, swapped.readUnsignedShort()); + position.set(Event.KEY_LAC, swapped.readUnsignedShort()); + position.set(Event.KEY_CID, swapped.readUnsignedShort()); // two more cell towers diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java index 5292bd32d..7aea23f1b 100644 --- a/test/org/traccar/ProtocolDecoderTest.java +++ b/test/org/traccar/ProtocolDecoderTest.java @@ -187,6 +187,22 @@ public class ProtocolDecoderTest { Assert.assertFalse("no attributes", attributes.isEmpty()); } + if (attributes.containsKey(Event.KEY_MCC)) { + checkInteger(attributes.get(Event.KEY_MCC), 100, 999); + } + + if (attributes.containsKey(Event.KEY_MNC)) { + checkInteger(attributes.get(Event.KEY_MNC), 0, 999); + } + + /*if (attributes.containsKey(Event.KEY_LAC)) { + checkInteger(attributes.get(Event.KEY_LAC), 1, 65535); + } + + if (attributes.containsKey(Event.KEY_CID)) { + checkInteger(attributes.get(Event.KEY_CID), 1, 268435455); + }*/ + /*if (attributes.containsKey(Event.KEY_MCC) || attributes.containsKey(Event.KEY_MNC)) { checkInteger(attributes.get(Event.KEY_MCC), 100, 999); checkInteger(attributes.get(Event.KEY_MNC), 0, 999); -- cgit v1.2.3 From 3ba58a7d025c33c5f4e5e2d595158ecf9f420008 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 Nov 2015 18:07:03 +1300 Subject: Store LAC and CID in right format --- src/org/traccar/protocol/EelinkProtocolDecoder.java | 5 ++++- src/org/traccar/protocol/Gl200ProtocolDecoder.java | 4 +++- src/org/traccar/protocol/Jt600ProtocolDecoder.java | 9 +++++++-- .../traccar/protocol/MegastekProtocolDecoder.java | 18 ++++++++++++------ .../traccar/protocol/MeitrackProtocolDecoder.java | 4 ++-- .../traccar/protocol/SuntechProtocolDecoder.java | 2 +- src/org/traccar/protocol/Tlt2hProtocolDecoder.java | 2 +- src/org/traccar/protocol/TotemProtocolDecoder.java | 21 ++++++++++++++++----- test/org/traccar/ProtocolDecoderTest.java | 4 ++-- 9 files changed, 48 insertions(+), 21 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index b3a062db3..b75587743 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -86,7 +86,10 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); position.setCourse(buf.readUnsignedShort()); - position.set(Event.KEY_CID, ChannelBuffers.hexDump(buf.readBytes(9))); + position.set(Event.KEY_MCC, buf.readUnsignedShort()); + position.set(Event.KEY_MNC, buf.readUnsignedShort()); + position.set(Event.KEY_LAC, buf.readUnsignedShort()); + position.set(Event.KEY_CID, buf.readUnsignedShort()); position.setValid((buf.readUnsignedByte() & 0x01) != 0); diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 06c548669..42786d4fe 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -116,7 +116,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .text(",") .number("(0ddd)?,") // mcc .number("(0ddd)?,") // mnc - .number("(xxxx|x{8})?,") // lac + .number("(?:xxxx)?") + .number("(xxxx)").optional(2) // lac + .text(",") .number("(xxxx)?,") // cell .groupBegin() .number("(d+.d)?,") // odometer diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index d9e31fe48..b576b063d 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -94,8 +94,13 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(buf.readUnsignedShort()); - position.set(Event.KEY_CID, buf.readUnsignedShort()); - position.set(Event.KEY_LAC, buf.readUnsignedShort()); + int cid = buf.readUnsignedShort(); + int lac = buf.readUnsignedShort(); + if (cid != 0 && lac != 0) { + position.set(Event.KEY_CID, cid); + position.set(Event.KEY_LAC, lac); + } + position.set(Event.KEY_GSM, buf.readUnsignedByte()); } else if (version == 2) { diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index b2db50fd4..dc9e6056e 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -53,14 +53,16 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { .number("(d)?,") // charger .number("(d+)?,") // mcc .number("(d+)?,") // mnc - .number("(xxxx,xxxx);") // location code + .number("(xxxx),") // lac + .number("(xxxx);") // cid .any() // checksum .compile(); private static final Pattern PATTERN_ALTERNATIVE = new PatternBuilder() .number("(d+),") // mcc .number("(d+),") // mnc - .number("(xxxx,xxxx),") // location code + .number("(xxxx),") // lac + .number("(xxxx),") // cid .number("(d+),") // gsm signal .number("(d+),") // battery .number("(d+),") // flags @@ -174,7 +176,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext(3)) { position.set(Event.KEY_MCC, parser.nextInt()); position.set(Event.KEY_MNC, parser.nextInt()); - position.set(Event.KEY_LAC, parser.next()); + position.set(Event.KEY_LAC, parser.nextInt(16)); + position.set(Event.KEY_CID, parser.nextInt(16)); } } else { @@ -198,7 +201,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_MCC, parser.nextInt()); position.set(Event.KEY_MNC, parser.nextInt()); - position.set(Event.KEY_LAC, parser.next()); + position.set(Event.KEY_LAC, parser.nextInt(16)); + position.set(Event.KEY_CID, parser.nextInt(16)); position.set(Event.KEY_GSM, parser.next()); position.set(Event.KEY_BATTERY, Double.parseDouble(parser.next())); @@ -238,7 +242,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // odometer .number("(d+),") // mcc .number("(d+),") // mnc - .number("(xxxx,xxxx),") // cell + .number("(xxxx),") // lac + .number("(xxxx),") // cid .number("(d+)?,") // gsm .expression("([01]+),") // input .expression("([01]+),") // output @@ -297,7 +302,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_ODOMETER, parser.nextDouble()); position.set(Event.KEY_MCC, parser.nextInt()); position.set(Event.KEY_MNC, parser.nextInt()); - position.set(Event.KEY_CID, parser.next()); + position.set(Event.KEY_LAC, parser.nextInt(16)); + position.set(Event.KEY_CID, parser.nextInt(16)); String gsm = parser.next(); if (gsm != null) { diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 475329c5d..4bde5cf75 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -121,8 +121,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.set("runtime", parser.next()); position.set(Event.KEY_MCC, parser.nextInt()); position.set(Event.KEY_MNC, parser.nextInt()); - position.set(Event.KEY_LAC, parser.next()); - position.set(Event.KEY_CID, parser.next()); + position.set(Event.KEY_LAC, parser.nextInt(16)); + position.set(Event.KEY_CID, parser.nextInt(16)); position.set(Event.KEY_STATUS, parser.next()); for (int i = 1; i <= 3; i++) { diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index b0d85b101..38f771eec 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -83,7 +83,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); position.setTime(dateBuilder.getDate()); - position.set(Event.KEY_CID, parser.next()); + parser.next(); // location code + bsic position.setValid(true); position.setLatitude(parser.nextDouble()); diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java index d9d50947e..24e9893bb 100644 --- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java +++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java @@ -86,7 +86,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); - position.set(Event.KEY_CID, parser.next()); + parser.next(); // base station info DateBuilder dateBuilder = new DateBuilder() .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index 321b78b7c..88eecab70 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -55,7 +55,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("(ddd)") // battery .number("(dddd)|") // power .number("(d+)|").optional() // adc - .number("(x+)|") // location code + .number("x*(xxxx)") // lac + .number("(xxxx)|") // cid .number("(d+)|") // temperature .number("(d+.d+)|") // odometer .number("d+|") // serial number @@ -84,7 +85,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("(dd)") // battery .number("(dd)|") // external power .number("(d+)|") // adc - .number("(x{8})|") // location code + .number("(xxxx)") // lac + .number("(xxxx)|") // cid .number("(d+)|") // temperature .number("(d+.d+)|") // odometer .number("d+|") // serial number @@ -107,7 +109,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .number("(dddd)") // adc 2 .number("(ddd)") // temperature 1 .number("(ddd)") // temperature 2 - .number("(x{8})") // location code + .number("(xxxx)") // lac + .number("(xxxx)") // cid .expression("([AV])") // validity .number("(dd)") // satellites .number("(ddd)") // course @@ -185,7 +188,14 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_BATTERY, parser.next()); position.set(Event.KEY_POWER, parser.nextDouble()); position.set(Event.PREFIX_ADC + 1, parser.next()); - position.set(Event.KEY_LAC, parser.next()); + + int lac = parser.nextInt(16); + int cid = parser.nextInt(16); + if (lac != 0 && cid != 0) { + position.set(Event.KEY_LAC, lac); + position.set(Event.KEY_CID, cid); + } + position.set(Event.PREFIX_TEMP + 1, parser.next()); position.set(Event.KEY_ODOMETER, parser.next()); @@ -203,7 +213,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.set(Event.PREFIX_ADC + 2, parser.next()); position.set(Event.PREFIX_TEMP + 1, parser.next()); position.set(Event.PREFIX_TEMP + 2, parser.next()); - position.set(Event.KEY_LAC, parser.next()); + position.set(Event.KEY_LAC, parser.nextInt(16)); + position.set(Event.KEY_CID, parser.nextInt(16)); position.setValid(parser.next().equals("A")); position.set(Event.KEY_SATELLITES, parser.next()); diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java index 7aea23f1b..dbb11965b 100644 --- a/test/org/traccar/ProtocolDecoderTest.java +++ b/test/org/traccar/ProtocolDecoderTest.java @@ -195,13 +195,13 @@ public class ProtocolDecoderTest { checkInteger(attributes.get(Event.KEY_MNC), 0, 999); } - /*if (attributes.containsKey(Event.KEY_LAC)) { + if (attributes.containsKey(Event.KEY_LAC)) { checkInteger(attributes.get(Event.KEY_LAC), 1, 65535); } if (attributes.containsKey(Event.KEY_CID)) { checkInteger(attributes.get(Event.KEY_CID), 1, 268435455); - }*/ + } /*if (attributes.containsKey(Event.KEY_MCC) || attributes.containsKey(Event.KEY_MNC)) { checkInteger(attributes.get(Event.KEY_MCC), 100, 999); -- cgit v1.2.3 From 12ac6af766b92b4d5cfd53957955e1bed4dcc151 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 Nov 2015 18:09:05 +1300 Subject: Make LBS unit test asserts stricter --- test/org/traccar/ProtocolDecoderTest.java | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'test') diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java index dbb11965b..ef98b3467 100644 --- a/test/org/traccar/ProtocolDecoderTest.java +++ b/test/org/traccar/ProtocolDecoderTest.java @@ -187,29 +187,13 @@ public class ProtocolDecoderTest { Assert.assertFalse("no attributes", attributes.isEmpty()); } - if (attributes.containsKey(Event.KEY_MCC)) { + if (attributes.containsKey(Event.KEY_MCC) || attributes.containsKey(Event.KEY_MNC)) { checkInteger(attributes.get(Event.KEY_MCC), 100, 999); - } - - if (attributes.containsKey(Event.KEY_MNC)) { checkInteger(attributes.get(Event.KEY_MNC), 0, 999); - } - - if (attributes.containsKey(Event.KEY_LAC)) { checkInteger(attributes.get(Event.KEY_LAC), 1, 65535); - } - - if (attributes.containsKey(Event.KEY_CID)) { checkInteger(attributes.get(Event.KEY_CID), 1, 268435455); } - /*if (attributes.containsKey(Event.KEY_MCC) || attributes.containsKey(Event.KEY_MNC)) { - checkInteger(attributes.get(Event.KEY_MCC), 100, 999); - checkInteger(attributes.get(Event.KEY_MNC), 0, 999); - checkInteger(attributes.get(Event.KEY_LAC), 1, 65535); - checkInteger(attributes.get(Event.KEY_CID), 1, 268435455); - }*/ - } private void checkInteger(Object value, int min, int max) { -- cgit v1.2.3 From 98aeb9261b37dc174c37236292cb2d726937c3d5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 Nov 2015 18:13:16 +1300 Subject: Make LBS tests even stricter --- src/org/traccar/protocol/TeltonikaProtocolDecoder.java | 2 +- test/org/traccar/ProtocolDecoderTest.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 3592cae79..2217b5ce4 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -114,7 +114,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(locationMask, 5)) { - position.set("area", buf.readUnsignedShort()); + position.set(Event.KEY_LAC, buf.readUnsignedShort()); position.set(Event.KEY_CID, buf.readUnsignedShort()); } diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java index ef98b3467..8f7ed628b 100644 --- a/test/org/traccar/ProtocolDecoderTest.java +++ b/test/org/traccar/ProtocolDecoderTest.java @@ -187,11 +187,16 @@ public class ProtocolDecoderTest { Assert.assertFalse("no attributes", attributes.isEmpty()); } + if (attributes.containsKey(Event.KEY_LAC) || attributes.containsKey(Event.KEY_CID)) { + checkInteger(attributes.get(Event.KEY_LAC), 1, 65535); + checkInteger(attributes.get(Event.KEY_CID), 1, 268435455); + } + if (attributes.containsKey(Event.KEY_MCC) || attributes.containsKey(Event.KEY_MNC)) { checkInteger(attributes.get(Event.KEY_MCC), 100, 999); checkInteger(attributes.get(Event.KEY_MNC), 0, 999); - checkInteger(attributes.get(Event.KEY_LAC), 1, 65535); - checkInteger(attributes.get(Event.KEY_CID), 1, 268435455); + Assert.assertTrue("value missing", attributes.containsKey(Event.KEY_LAC)); + Assert.assertTrue("value missing", attributes.containsKey(Event.KEY_CID)); } } -- cgit v1.2.3 From 3563910f1b551c02db5dffc9745bd8aba9cbeeeb Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 16 Nov 2015 11:33:06 +1300 Subject: Disable async debugging and add test --- src/org/traccar/web/AsyncServlet.java | 2 +- test/org/traccar/web/AsyncServletTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/org/traccar/web/AsyncServletTest.java (limited to 'test') diff --git a/src/org/traccar/web/AsyncServlet.java b/src/org/traccar/web/AsyncServlet.java index 63b08ff3e..3347f765c 100644 --- a/src/org/traccar/web/AsyncServlet.java +++ b/src/org/traccar/web/AsyncServlet.java @@ -50,7 +50,7 @@ public class AsyncServlet extends BaseServlet { public static class AsyncSession { - private static final boolean DEBUG_ASYNC = true; + public static final boolean DEBUG_ASYNC = false; private static final long SESSION_TIMEOUT = 30; private static final long REQUEST_TIMEOUT = 20; diff --git a/test/org/traccar/web/AsyncServletTest.java b/test/org/traccar/web/AsyncServletTest.java new file mode 100644 index 000000000..e2f7b2f21 --- /dev/null +++ b/test/org/traccar/web/AsyncServletTest.java @@ -0,0 +1,13 @@ +package org.traccar.web; + +import org.junit.Assert; +import org.junit.Test; + +public class AsyncServletTest { + + @Test + public void testDebugDisabled() { + Assert.assertFalse("debugging enabled", AsyncServlet.AsyncSession.DEBUG_ASYNC); + } + +} -- cgit v1.2.3 From 3471e62b0f3949621265c80dcaf2ba714aade697 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 17 Nov 2015 11:36:08 +1300 Subject: Finish Huabao protocol implementation --- src/org/traccar/MainEventHandler.java | 1 - .../traccar/protocol/HuabaoProtocolDecoder.java | 113 ++++++++++++++++++++- .../protocol/HuabaoProtocolDecoderTest.java | 9 ++ 3 files changed, 118 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index fa908a70c..f0ef36e5b 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -21,7 +21,6 @@ import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.socket.DatagramChannel; -import org.jboss.netty.handler.codec.http.HttpRequestDecoder; import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; import org.jboss.netty.handler.timeout.IdleStateEvent; import org.traccar.helper.Log; diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java index 931f985a5..792c89c8b 100644 --- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -16,10 +16,20 @@ package org.traccar.protocol; import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.BitUtil; +import org.traccar.helper.ChannelBufferTools; +import org.traccar.helper.Checksum; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Event; +import org.traccar.model.Position; import java.net.SocketAddress; +import java.nio.charset.Charset; +import java.util.TimeZone; public class HuabaoProtocolDecoder extends BaseProtocolDecoder { @@ -27,7 +37,38 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { super(protocol); } + public static final int MSG_GENERAL_RESPONSE = 0x8001; public static final int MSG_TERMINAL_REGISTER = 0x0100; + public static final int MSG_TERMINAL_REGISTER_RESPONSE = 0x8100; + public static final int MSG_TERMINAL_AUTH = 0x0102; + public static final int MSG_LOCATION_REPORT = 0x0200; + + public static final int RESULT_SUCCESS = 0; + + private void sendResponse( + Channel channel, SocketAddress remoteAddress, int type, ChannelBuffer id, ChannelBuffer data) { + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeByte(0x7e); + response.writeShort(type); + response.writeShort(data.readableBytes()); + response.writeBytes(id); + response.writeShort(1); // index + response.writeBytes(data); + response.writeByte(Checksum.xor(response.toByteBuffer(1, response.readableBytes() - 1))); + response.writeByte(0x7e); + if (channel != null) { + channel.write(response, remoteAddress); + } + } + + private void sendGeneralResponse( + Channel channel, SocketAddress remoteAddress, ChannelBuffer id, int type, int index) { + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeShort(index); + response.writeShort(type); + response.writeByte(RESULT_SUCCESS); + sendResponse(channel, remoteAddress, MSG_GENERAL_RESPONSE, id, response); + } @Override protected Object decode( @@ -36,10 +77,74 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; buf.readUnsignedByte(); // start marker - //int type = buf.readUnsignedShort(); - //int flags = buf.readUnsignedShort(); - buf.skipBytes(6); // phone number - buf.readUnsignedShort(); // index + int type = buf.readUnsignedShort(); + buf.readUnsignedShort(); // body length + ChannelBuffer id = buf.readBytes(6); // phone number + int index = buf.readUnsignedShort(); + + if (!identify(id.toString(Charset.defaultCharset()), channel, remoteAddress)) { + return null; + } + + if (type == MSG_TERMINAL_REGISTER) { + + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeShort(index); + response.writeByte(RESULT_SUCCESS); + response.writeBytes("authentication".getBytes(Charset.defaultCharset())); + sendResponse(channel, remoteAddress, MSG_TERMINAL_REGISTER_RESPONSE, id, response); + + } else if (type == MSG_TERMINAL_AUTH) { + + sendGeneralResponse(channel, remoteAddress, id, type, index); + + } else if (type == MSG_LOCATION_REPORT) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(getDeviceId()); + + position.set(Event.KEY_ALARM, buf.readUnsignedInt()); + + int flags = buf.readInt(); + + position.set(Event.KEY_IGNITION, BitUtil.check(flags, 0)); + + position.setValid(BitUtil.check(flags, 1)); + + double lat = buf.readUnsignedInt() * 0.000001; + double lon = buf.readUnsignedInt() * 0.000001; + + if (BitUtil.check(flags, 2)) { + position.setLatitude(-lat); + } else { + position.setLatitude(lat); + } + + if (BitUtil.check(flags, 3)) { + position.setLongitude(-lon); + } else { + position.setLongitude(lon); + } + + position.setAltitude(buf.readShort()); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1)); + position.setCourse(buf.readUnsignedShort()); + + DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+8")) + .setYear(ChannelBufferTools.readHexInteger(buf, 2)) + .setMonth(ChannelBufferTools.readHexInteger(buf, 2)) + .setDay(ChannelBufferTools.readHexInteger(buf, 2)) + .setHour(ChannelBufferTools.readHexInteger(buf, 2)) + .setMinute(ChannelBufferTools.readHexInteger(buf, 2)) + .setSecond(ChannelBufferTools.readHexInteger(buf, 2)); + position.setTime(dateBuilder.getDate()); + + // additional information + + return position; + + } return null; } diff --git a/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java index 0968d6d9c..1e2290851 100644 --- a/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java @@ -10,9 +10,18 @@ public class HuabaoProtocolDecoderTest extends ProtocolDecoderTest { HuabaoProtocolDecoder decoder = new HuabaoProtocolDecoder(new HuabaoProtocol()); + verifyNothing(decoder, binary( + "7E0100002D013511221122000500000000373031303748422D52303347424400000000000000000000003233363631303402CBD5424136383630387E")); + verifyNothing(decoder, binary( "7e0100002d007089994489002800000000000000000048422d523033474244000000000000000000000031393036373531024142433030303030d17e")); + verifyNothing(decoder, binary( + "7E0102000E013511221122000661757468656E7469636174696F6E3F7E")); + + verifyPosition(decoder, binary( + "7E02000032013511221122000700000000000C000301578CC006CA3A5C00470000000014072317201501040000000030011631010BD07E")); + } } -- cgit v1.2.3 From 78e325196729202e416655e87cf7d1593cda2cc7 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 18 Nov 2015 13:24:28 +1300 Subject: Initial code for location providers --- src/org/traccar/location/BaseLocationProvider.java | 37 ++++++++++++++++++ src/org/traccar/location/LocationProvider.java | 30 +++++++++++++++ .../location/OpenCellIdLocationProvider.java | 24 ++++++++++++ test/org/traccar/geocode/ReverseGeocoderTest.java | 4 -- .../org/traccar/location/LocationProviderTest.java | 44 ++++++++++++++++++++++ 5 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 src/org/traccar/location/BaseLocationProvider.java create mode 100644 src/org/traccar/location/LocationProvider.java create mode 100644 src/org/traccar/location/OpenCellIdLocationProvider.java create mode 100644 test/org/traccar/location/LocationProviderTest.java (limited to 'test') diff --git a/src/org/traccar/location/BaseLocationProvider.java b/src/org/traccar/location/BaseLocationProvider.java new file mode 100644 index 000000000..80b10b33c --- /dev/null +++ b/src/org/traccar/location/BaseLocationProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright 2015 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.location; + +import org.traccar.model.Event; + +import java.util.Map; + +public abstract class BaseLocationProvider implements LocationProvider { + + @Override + public void getLocation(Map attributes, LocationProviderCallback callback) { + if (attributes.containsKey(Event.KEY_MCC) || attributes.containsKey(Event.KEY_MNC)) { + Number mcc = (Number) attributes.get(Event.KEY_MCC); + Number mnc = (Number) attributes.get(Event.KEY_MNC); + Number lac = (Number) attributes.get(Event.KEY_LAC); + Number cid = (Number) attributes.get(Event.KEY_CID); + getLocation(mcc.intValue(), mnc.intValue(), lac.longValue(), cid.longValue(), callback); + } + } + + protected abstract void getLocation(int mcc, int mnc, long lac, long cid, LocationProviderCallback callback); + +} diff --git a/src/org/traccar/location/LocationProvider.java b/src/org/traccar/location/LocationProvider.java new file mode 100644 index 000000000..cbc9663f8 --- /dev/null +++ b/src/org/traccar/location/LocationProvider.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015 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.location; + +import java.util.Map; + +public interface LocationProvider { + + interface LocationProviderCallback { + + void onResult(double latitude, double longitude); + + } + + void getLocation(Map attributes, LocationProviderCallback callback); + +} diff --git a/src/org/traccar/location/OpenCellIdLocationProvider.java b/src/org/traccar/location/OpenCellIdLocationProvider.java new file mode 100644 index 000000000..22456c482 --- /dev/null +++ b/src/org/traccar/location/OpenCellIdLocationProvider.java @@ -0,0 +1,24 @@ +/* + * Copyright 2015 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.location; + +public class OpenCellIdLocationProvider extends BaseLocationProvider { + + protected void getLocation(int mcc, int mnc, long lac, long cid, LocationProviderCallback callback) { + // TODO + } + +} diff --git a/test/org/traccar/geocode/ReverseGeocoderTest.java b/test/org/traccar/geocode/ReverseGeocoderTest.java index 2336418d8..a572b0456 100644 --- a/test/org/traccar/geocode/ReverseGeocoderTest.java +++ b/test/org/traccar/geocode/ReverseGeocoderTest.java @@ -14,11 +14,9 @@ public class ReverseGeocoderTest { testNominatim(); testGisgraphy(); } - } public void testGoogle() { - ReverseGeocoder reverseGeocoder = new GoogleReverseGeocoder(); reverseGeocoder.getAddress(new AddressFormat(), 37.4217550, -122.0846330, new ReverseGeocoder.ReverseGeocoderCallback() { @@ -30,7 +28,6 @@ public class ReverseGeocoderTest { } public void testNominatim() { - ReverseGeocoder reverseGeocoder = new NominatimReverseGeocoder(); reverseGeocoder.getAddress(new AddressFormat(), 40.7337807, -73.9974401, new ReverseGeocoder.ReverseGeocoderCallback() { @@ -42,7 +39,6 @@ public class ReverseGeocoderTest { } public void testGisgraphy() { - ReverseGeocoder reverseGeocoder = new GisgraphyReverseGeocoder(); reverseGeocoder.getAddress(new AddressFormat(), 48.8530000, 2.3400000, new ReverseGeocoder.ReverseGeocoderCallback() { diff --git a/test/org/traccar/location/LocationProviderTest.java b/test/org/traccar/location/LocationProviderTest.java new file mode 100644 index 000000000..c4aedbb09 --- /dev/null +++ b/test/org/traccar/location/LocationProviderTest.java @@ -0,0 +1,44 @@ +package org.traccar.location; + +import org.junit.Assert; +import org.junit.Test; +import org.traccar.geocode.AddressFormat; +import org.traccar.geocode.GisgraphyReverseGeocoder; +import org.traccar.geocode.GoogleReverseGeocoder; +import org.traccar.geocode.NominatimReverseGeocoder; +import org.traccar.geocode.ReverseGeocoder; +import org.traccar.model.Event; + +import java.util.HashMap; +import java.util.Map; + +public class LocationProviderTest { + + private boolean enable = false; + + @Test + public void test() { + if (enable) { + testOpenCellId(); + } + } + + public void testOpenCellId() { + OpenCellIdLocationProvider locationProvider = new OpenCellIdLocationProvider(); + + Map attributes = new HashMap<>(); + attributes.put(Event.KEY_MCC, 250); + attributes.put(Event.KEY_MNC, 2); + attributes.put(Event.KEY_LAC, 4711); + attributes.put(Event.KEY_CID, 7989334); + + locationProvider.getLocation(attributes, new LocationProvider.LocationProviderCallback() { + @Override + public void onResult(double latitude, double longitude) { + Assert.assertEquals(60.07254, latitude, 0.00001); + Assert.assertEquals(30.30996, longitude, 0.00001); + } + }); + } + +} -- cgit v1.2.3 From 6ec22b7a68b5334e215662e4cb83a20f9a1cad18 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 18 Nov 2015 14:01:00 +1300 Subject: Implement OpenCellID location provider --- src/org/traccar/location/LocationProvider.java | 4 +- .../location/OpenCellIdLocationProvider.java | 44 +++++++++++++++++++++- .../org/traccar/location/LocationProviderTest.java | 15 +++++--- 3 files changed, 55 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/src/org/traccar/location/LocationProvider.java b/src/org/traccar/location/LocationProvider.java index cbc9663f8..2bff1a7ca 100644 --- a/src/org/traccar/location/LocationProvider.java +++ b/src/org/traccar/location/LocationProvider.java @@ -21,7 +21,9 @@ public interface LocationProvider { interface LocationProviderCallback { - void onResult(double latitude, double longitude); + void onSuccess(double latitude, double longitude); + + void onFailure(); } diff --git a/src/org/traccar/location/OpenCellIdLocationProvider.java b/src/org/traccar/location/OpenCellIdLocationProvider.java index 22456c482..2339585ad 100644 --- a/src/org/traccar/location/OpenCellIdLocationProvider.java +++ b/src/org/traccar/location/OpenCellIdLocationProvider.java @@ -15,10 +15,50 @@ */ package org.traccar.location; +import com.ning.http.client.AsyncCompletionHandler; +import com.ning.http.client.Response; +import org.traccar.Context; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; + public class OpenCellIdLocationProvider extends BaseLocationProvider { - protected void getLocation(int mcc, int mnc, long lac, long cid, LocationProviderCallback callback) { - // TODO + private String url; + + public OpenCellIdLocationProvider(String key) { + this("http://opencellid.org/cell/get", key); + } + + public OpenCellIdLocationProvider(String url, String key) { + this.url = url + "?format=json&mcc=%d&mnc=%d&lac=%d&cellid=%d&key=" + key; + } + + protected void getLocation(int mcc, int mnc, long lac, long cid, final LocationProviderCallback callback) { + String x = String.format(url, mcc, mnc, lac, cid); + Context.getAsyncHttpClient().prepareGet(String.format(url, mcc, mnc, lac, cid)) + .execute(new AsyncCompletionHandler() { + @Override + public Object onCompleted(Response response) throws Exception { + try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) { + JsonObject json = reader.readObject(); + if (json.containsKey("lat") && json.containsKey("lon")) { + callback.onSuccess( + json.getJsonNumber("lat").doubleValue(), + json.getJsonNumber("lon").doubleValue()); + } else { + callback.onFailure(); + } + } + return null; + } + + @Override + public void onThrowable(Throwable t) { + callback.onFailure(); + } + }); } } diff --git a/test/org/traccar/location/LocationProviderTest.java b/test/org/traccar/location/LocationProviderTest.java index c4aedbb09..b7280cfea 100644 --- a/test/org/traccar/location/LocationProviderTest.java +++ b/test/org/traccar/location/LocationProviderTest.java @@ -24,20 +24,25 @@ public class LocationProviderTest { } public void testOpenCellId() { - OpenCellIdLocationProvider locationProvider = new OpenCellIdLocationProvider(); + OpenCellIdLocationProvider locationProvider = new OpenCellIdLocationProvider("fake"); Map attributes = new HashMap<>(); - attributes.put(Event.KEY_MCC, 250); + attributes.put(Event.KEY_MCC, 260); attributes.put(Event.KEY_MNC, 2); - attributes.put(Event.KEY_LAC, 4711); - attributes.put(Event.KEY_CID, 7989334); + attributes.put(Event.KEY_LAC, 10250); + attributes.put(Event.KEY_CID, 26511); locationProvider.getLocation(attributes, new LocationProvider.LocationProviderCallback() { @Override - public void onResult(double latitude, double longitude) { + public void onSuccess(double latitude, double longitude) { Assert.assertEquals(60.07254, latitude, 0.00001); Assert.assertEquals(30.30996, longitude, 0.00001); } + + @Override + public void onFailure() { + Assert.fail(); + } }); } -- cgit v1.2.3 From 7b46396a9e5b6546b89e927c715c65d59296cd83 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 18 Nov 2015 21:37:03 +1300 Subject: Add LBS example for GPS103 protocol --- test/org/traccar/protocol/Gps103ProtocolDecoderTest.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 80d1424fc..03d7b5c72 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class Gps103ProtocolDecoderTest extends ProtocolDecoderTest { Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new Gps103Protocol()); + verifyNothing(decoder, text( + "imei:863070016871385,tracker,0000000119,,L,,,0FB6,,CB5D,,,")); + verifyPosition(decoder, text( "imei:359710045559474,tracker,151030080103,,F,000101.000,A,5443.3834,N,02512.9071,E,0.00,0;"), position("2015-10-30 00:01:01.000", true, 54.72306, 25.21512)); -- cgit v1.2.3 From a7f7df0ebdf56a6dbaa5a17600c05c5b6d3033a4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 18 Nov 2015 22:04:41 +1300 Subject: Support GSM based locations (fix #346) --- debug.xml | 2 ++ src/org/traccar/location/BaseLocationProvider.java | 22 +++++++++---- .../traccar/protocol/Gps103ProtocolDecoder.java | 36 +++++++++++++++++++--- .../protocol/Gps103ProtocolDecoderTest.java | 5 ++- 4 files changed, 54 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/debug.xml b/debug.xml index 2e6e4e12a..426dadc4c 100644 --- a/debug.xml +++ b/debug.xml @@ -20,6 +20,8 @@ false fake + 260 + 2 true diff --git a/src/org/traccar/location/BaseLocationProvider.java b/src/org/traccar/location/BaseLocationProvider.java index 80b10b33c..d6eddc1cd 100644 --- a/src/org/traccar/location/BaseLocationProvider.java +++ b/src/org/traccar/location/BaseLocationProvider.java @@ -15,6 +15,7 @@ */ package org.traccar.location; +import org.traccar.Context; import org.traccar.model.Event; import java.util.Map; @@ -23,13 +24,22 @@ public abstract class BaseLocationProvider implements LocationProvider { @Override public void getLocation(Map attributes, LocationProviderCallback callback) { - if (attributes.containsKey(Event.KEY_MCC) || attributes.containsKey(Event.KEY_MNC)) { - Number mcc = (Number) attributes.get(Event.KEY_MCC); - Number mnc = (Number) attributes.get(Event.KEY_MNC); - Number lac = (Number) attributes.get(Event.KEY_LAC); - Number cid = (Number) attributes.get(Event.KEY_CID); - getLocation(mcc.intValue(), mnc.intValue(), lac.longValue(), cid.longValue(), callback); + + Number mcc = (Number) attributes.get(Event.KEY_MCC); + if (mcc == null) { + mcc = Context.getConfig().getInteger("location.mcc"); + } + + Number mnc = (Number) attributes.get(Event.KEY_MNC); + if (mnc == null) { + mnc = Context.getConfig().getInteger("location.mnc"); } + + Number lac = (Number) attributes.get(Event.KEY_LAC); + Number cid = (Number) attributes.get(Event.KEY_CID); + + getLocation(mcc.intValue(), mnc.intValue(), lac.longValue(), cid.longValue(), callback); + } protected abstract void getLocation(int mcc, int mnc, long lac, long cid, LocationProviderCallback callback); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index aa693f42e..a91848f5b 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -63,6 +63,17 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_NETWORK = new PatternBuilder() + .text("imei:") + .number("(d+),") // imei + .expression("[^,]+,") // alarm + .number("d+,,") + .text("L,,,") + .number("(x+),,") // lac + .number("(x+),,,") // cid + .any() + .compile(); + private static final Pattern PATTERN_HANDSHAKE = new PatternBuilder() .number("##,imei:(d+),A") .compile(); @@ -93,14 +104,31 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { return null; } - Parser parser = new Parser(PATTERN, sentence); + Position position = new Position(); + position.setProtocol(getProtocolName()); + + Parser parser = new Parser(PATTERN_NETWORK, sentence); + if (parser.matches()) { + + if (!identify(parser.next(), channel, remoteAddress)) { + return null; + } + position.setDeviceId(getDeviceId()); + + getLastLocation(position, null); + + position.set(Event.KEY_LAC, parser.nextInt(16)); + position.set(Event.KEY_CID, parser.nextInt(16)); + + return position; + + } + + parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; } - Position position = new Position(); - position.setProtocol(getProtocolName()); - String imei = parser.next(); if (!identify(imei, channel, remoteAddress)) { return null; diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 03d7b5c72..371b137fd 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -10,7 +10,10 @@ public class Gps103ProtocolDecoderTest extends ProtocolDecoderTest { Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new Gps103Protocol()); - verifyNothing(decoder, text( + verifyAttributes(decoder, text( + "imei:359710041100000,tracker,000000000,,L,,,fa8,,c9af,,,,,0,0,0.00%,,")); + + verifyAttributes(decoder, text( "imei:863070016871385,tracker,0000000119,,L,,,0FB6,,CB5D,,,")); verifyPosition(decoder, text( -- cgit v1.2.3 From cc5d60ff499c39fb4db7e06b2e62fefe2a324f77 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 19 Nov 2015 09:51:28 +1300 Subject: Add more Huabao decoder unit tests --- test/org/traccar/protocol/HuabaoProtocolDecoderTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java index 1e2290851..b24b844d9 100644 --- a/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java @@ -22,6 +22,18 @@ public class HuabaoProtocolDecoderTest extends ProtocolDecoderTest { verifyPosition(decoder, binary( "7E02000032013511221122000700000000000C000301578CC006CA3A5C00470000000014072317201501040000000030011631010BD07E")); + verifyNothing(decoder, binary( + "7E010200100940278494700084323031313131303831313333323139369F7E")); + + verifyNothing(decoder, binary( + "7e010000190940278494700012000000000000000000000000000000000000094027849470000a7e")); + + verifyPosition(decoder, binary( + "7e0200002e094027587492000a000000010000000a03083db7001329f3000000140000130412164952010400000012360a0002341502cb0c20085c107e")); + + verifyPosition(decoder, binary( + "7e020000220014012499170007000000000000400e012af16f02cbd2ba000000000000150101194257010400000077a97e")); + } } -- cgit v1.2.3 From 5d919c8489ea3c88d3182fab77b6b24b9dd86bef Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 19 Nov 2015 10:35:57 +1300 Subject: Implement LBS support for TK103 --- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 36 ++++++++++++++++++---- .../traccar/protocol/Tk103ProtocolDecoderTest.java | 3 ++ 2 files changed, 33 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 95728c447..6fa4edb06 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -64,6 +64,16 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .number("d+") // installed .compile(); + private static final Pattern PATTERN_NETWORK = new PatternBuilder() + .number("(d{12})") // device id + .text("BZ00,") + .number("(d+),") // mcc + .number("(d+),") // mnc + .number("(x+),") // lac + .number("(x+),") // cid + .any() + .compile(); + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -88,11 +98,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { } } + Position position = new Position(); + position.setProtocol(getProtocolName()); + Parser parser = new Parser(PATTERN_BATTERY, sentence); if (parser.matches()) { - Position position = new Position(); - position.setProtocol(getProtocolName()); - if (!identify(parser.next(), channel)) { return null; } @@ -117,14 +127,28 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { return position; } + parser = new Parser(PATTERN_NETWORK, sentence); + if (parser.matches()) { + if (!identify(parser.next(), channel)) { + return null; + } + position.setDeviceId(getDeviceId()); + + getLastLocation(position, null); + + position.set(Event.KEY_MCC, parser.nextInt()); + position.set(Event.KEY_MNC, parser.nextInt()); + position.set(Event.KEY_LAC, parser.nextInt(16)); + position.set(Event.KEY_CID, parser.nextInt(16)); + + return position; + } + parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; } - Position position = new Position(); - position.setProtocol(getProtocolName()); - if (!identify(parser.next(), channel)) { return null; } diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index d9152ecf0..2bffbcd9a 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class Tk103ProtocolDecoderTest extends ProtocolDecoderTest { Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol()); + verifyAttributes(decoder, text( + "(088047194605BZ00,510,010,36e6,932c,43,36e6,766b,36,36e6,7668,32")); + verifyAttributes(decoder, text( "(013632651491,ZC20,040613,040137,6,42,112,0")); -- cgit v1.2.3 From 69270993f48c3ecb5d7b00e386fd67722448e8b5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 19 Nov 2015 11:03:34 +1300 Subject: Add approximate location filtering --- src/org/traccar/BasePipelineFactory.java | 7 ++++--- src/org/traccar/FilterHandler.java | 17 +++++++++++++---- src/org/traccar/LocationProviderHandler.java | 1 + test/org/traccar/FilterHandlerTest.java | 4 ++-- 4 files changed, 20 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index b02bd0e53..c011fb015 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -128,9 +128,6 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { addSpecificHandlers(pipeline); - if (filterHandler != null) { - pipeline.addLast("filter", filterHandler); - } if (distanceHandler != null) { pipeline.addLast("distance", distanceHandler); } @@ -144,6 +141,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { addDynamicHandlers(pipeline); + if (filterHandler != null) { + pipeline.addLast("filter", filterHandler); + } + if (Context.getDataManager() != null) { pipeline.addLast("dataHandler", new DefaultDataHandler()); } diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 79f40c979..75f2bfd2c 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -17,6 +17,7 @@ package org.traccar; import org.traccar.helper.DistanceCalculator; import org.traccar.helper.Log; +import org.traccar.model.Event; import org.traccar.model.Position; public class FilterHandler extends BaseDataHandler { @@ -27,18 +28,20 @@ public class FilterHandler extends BaseDataHandler { private final boolean filterZero; private final boolean filterDuplicate; private final boolean filterFuture; + private final boolean filterApproximate; private final int filterDistance; private final long filterLimit; public FilterHandler( - boolean filterInvalid, boolean filterZero, boolean filterDuplicate, - boolean filterFuture, int filterDistance, long filterLimit) { + boolean filterInvalid, boolean filterZero, boolean filterDuplicate, boolean filterFuture, + boolean filterApproximate, int filterDistance, long filterLimit) { this.filterInvalid = filterInvalid; this.filterZero = filterZero; this.filterDuplicate = filterDuplicate; this.filterDistance = filterDistance; this.filterFuture = filterFuture; + this.filterApproximate = filterApproximate; this.filterLimit = filterLimit; } @@ -49,6 +52,7 @@ public class FilterHandler extends BaseDataHandler { filterZero = config.getBoolean("filter.zero"); filterDuplicate = config.getBoolean("filter.duplicate"); filterFuture = config.getBoolean("filter.future"); + filterApproximate = config.getBoolean("filter.approximate"); filterDistance = config.getInteger("filter.distance"); filterLimit = config.getLong("filter.limit") * 1000; } @@ -85,6 +89,11 @@ public class FilterHandler extends BaseDataHandler { return filterFuture && position.getFixTime().getTime() > System.currentTimeMillis() + FILTER_FUTURE_LIMIT; } + private boolean filterApproximate(Position position) { + Boolean approximate = (Boolean) position.getAttributes().get(Event.KEY_APPROXIMATE); + return filterApproximate && approximate != null && approximate; + } + private boolean filterDistance(Position position) { if (filterDistance != 0) { Position last = getLastPosition(position.getDeviceId()); @@ -116,8 +125,8 @@ public class FilterHandler extends BaseDataHandler { private boolean filter(Position p) { - boolean result = filterInvalid(p) || filterZero(p) - || filterDuplicate(p) || filterFuture(p) || filterDistance(p); + boolean result = filterInvalid(p) || filterZero(p) || filterDuplicate(p) + || filterFuture(p) || filterApproximate(p) || filterDistance(p); if (filterLimit(p)) { result = false; diff --git a/src/org/traccar/LocationProviderHandler.java b/src/org/traccar/LocationProviderHandler.java index c0b610571..62d5f1d04 100644 --- a/src/org/traccar/LocationProviderHandler.java +++ b/src/org/traccar/LocationProviderHandler.java @@ -48,6 +48,7 @@ public class LocationProviderHandler implements ChannelUpstreamHandler { @Override public void onSuccess(double latitude, double longitude) { position.set(Event.KEY_APPROXIMATE, true); + position.setValid(true); position.setFixTime(position.getDeviceTime()); position.setLatitude(latitude); position.setLongitude(longitude); diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java index f860c489f..b1e4fcb16 100644 --- a/test/org/traccar/FilterHandlerTest.java +++ b/test/org/traccar/FilterHandlerTest.java @@ -15,8 +15,8 @@ public class FilterHandlerTest { @Before public void setUp() { - filtingHandler = new FilterHandler(true, true, true, true, 10, 10); - passingHandler = new FilterHandler(false, false, false, false, 0, 0); + filtingHandler = new FilterHandler(true, true, true, true, true, 10, 10); + passingHandler = new FilterHandler(false, false, false, false, false, 0, 0); } @After -- cgit v1.2.3 From 4c9466f694e48b69a14e9039bd9b8d717c3a3dc3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 20 Nov 2015 09:46:39 +1300 Subject: Add support for TKQ messages --- src/org/traccar/protocol/WatchProtocolDecoder.java | 8 ++++++-- test/org/traccar/protocol/WatchProtocolDecoderTest.java | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index a24d0a56b..92b7638fb 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -64,8 +64,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { private void sendResponse(Channel channel, String manufacturer, String id, String content) { if (channel != null) { - channel.write( - String.format("[%s*%s*%04x*%s]", manufacturer, id, content.length(), content)); + channel.write(String.format( + "[%s*%s*%04x*%s]", manufacturer, id, content.length(), content)); } } @@ -138,6 +138,10 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { return position; + } else if (type.equals("TKQ")) { + + sendResponse(channel, manufacturer, id, "TKQ"); + } return null; diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java index 41af104dd..16074d36f 100644 --- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class WatchProtocolDecoderTest extends ProtocolDecoderTest { WatchProtocolDecoder decoder = new WatchProtocolDecoder(new WatchProtocol()); + verifyNothing(decoder, text( + "[3G*8800000015*0003*TKQ")); + verifyPosition(decoder, text( "[3G*4700186508*00B1*UD,301015,084840,V,45.853100,N,14.6224899,E,0.00,0.0,0.0,0,84,61,0,11,00000008,7,255,293,70,60,6453,139,60,6432,139,60,6431,132,60,6457,127,60,16353,126,60,6451,121,60,16352,118")); -- cgit v1.2.3 From 40674d8338c679a958ced0a94c4b61716775045d Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 21 Nov 2015 10:52:34 +1300 Subject: Add another Meiligao unit test case --- src/org/traccar/protocol/MeiligaoFrameDecoder.java | 4 +--- test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/MeiligaoFrameDecoder.java b/src/org/traccar/protocol/MeiligaoFrameDecoder.java index 6dcc6fd9c..9fb530f8a 100644 --- a/src/org/traccar/protocol/MeiligaoFrameDecoder.java +++ b/src/org/traccar/protocol/MeiligaoFrameDecoder.java @@ -26,9 +26,7 @@ public class MeiligaoFrameDecoder extends FrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { // Strip not '$' (0x24) bytes from the beginning while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != 0x24) { diff --git a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java index 6d0ba50d5..0c3c570f5 100644 --- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java @@ -12,8 +12,11 @@ public class MeiligaoProtocolDecoderTest extends ProtocolDecoderTest { MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(new MeiligaoProtocol()); + verifyNothing(decoder, binary( + "24240011671440258855405000b24d0d0a")); + verifyPosition(decoder, binary( - "242400706796502079108999553131333131382e3030302c412c313033372e393637382c4e2c30363132312e353637392c572c302e35342c322e34322c3330303931352c2c2c412a37307c302e37377c392e397c303030307c303030302c303161327c3030313138373132374cae0d0a"), + "242400706796502079108999553131333131382e3030302c412c313033372e393637382c4e2c30363132312e353637392c572c302e35342c322e34322c3330303931352c2c2c412a37307c302e37377c392e397c303030307c303030302c303161327c3030313138373132374cae0d0a"), position("2015-09-30 11:31:18.000", true, 10.63280, -61.35947)); verifyPosition(decoder, binary( -- cgit v1.2.3