From 79e54300d36d1e6c55452e9a68d219cb68ab9085 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 24 Nov 2015 15:49:24 +1300 Subject: Fix Tytan temperature data decoding --- test/org/traccar/protocol/TytanProtocolDecoderTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/org/traccar/protocol/TytanProtocolDecoderTest.java b/test/org/traccar/protocol/TytanProtocolDecoderTest.java index d291baa6e..bfbc01f52 100644 --- a/test/org/traccar/protocol/TytanProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TytanProtocolDecoderTest.java @@ -12,6 +12,15 @@ public class TytanProtocolDecoderTest extends ProtocolDecoderTest { TytanProtocolDecoder decoder = new TytanProtocolDecoder(new TytanProtocol()); + verifyPositions(decoder, binary( + "B500192000001405125652CA9B1A325FC98D11A9990018020118FC0D")); + + verifyPositions(decoder, binary( + "B500197800007422125652D7AC32325FD08D11A69900180200188280")); + + verifyPositions(decoder, binary( + "B500181000001405115652DEEB2A325FC68D11A7D00005012A2AE1")); + verifyPositions(decoder, binary( "B5005690000068494F561CEAE932325FD28D11A299000702000063045532030066013567018768014B6901286B0240396C04030785986D013E7F040000A7CE81040000A76C82027EAB83080FA01068FFFF0F3C880202583156")); -- cgit v1.2.3 From 89c6edc4b15b9ebebc9699f4740959753ec56bc6 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 24 Nov 2015 22:57:51 +1300 Subject: Add Ulbotech frame decoder test --- .../traccar/protocol/UlbotechFrameDecoderTest.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/org/traccar/protocol/UlbotechFrameDecoderTest.java (limited to 'test') diff --git a/test/org/traccar/protocol/UlbotechFrameDecoderTest.java b/test/org/traccar/protocol/UlbotechFrameDecoderTest.java new file mode 100644 index 000000000..76e4f799d --- /dev/null +++ b/test/org/traccar/protocol/UlbotechFrameDecoderTest.java @@ -0,0 +1,20 @@ +package org.traccar.protocol; + +import org.junit.Assert; +import org.junit.Test; +import org.traccar.ProtocolDecoderTest; + +public class UlbotechFrameDecoderTest extends ProtocolDecoderTest { + + @Test + public void testDecode() throws Exception { + + UlbotechFrameDecoder decoder = new UlbotechFrameDecoder(); + + Assert.assertEquals( + binary("f8010108679650230646339de69054010e015ee17506bde2c60000000000ac0304024000000404000009f705060390181422170711310583410c0000310d00312f834131018608040003130a100101136cf8"), + decoder.decode(null, null, binary("f8010108679650230646339de69054010e015ee17506bde2c60000000000ac0304024000000404000009f70005060390181422170711310583410c0000310d00312f834131018608040003130a100101136cf8"))); + + } + +} -- cgit v1.2.3 From fcdea01510dc9bf7144c76f4dd3a08c8c4eebaca Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 24 Nov 2015 22:58:06 +1300 Subject: Fix Ulbotech event data decoding --- src/org/traccar/protocol/UlbotechProtocolDecoder.java | 4 +++- test/org/traccar/protocol/UlbotechProtocolDecoderTest.java | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 5d882ffd8..dd6fb1593 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -204,7 +204,9 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { case DATA_EVENT: position.set(Event.KEY_EVENT, buf.readUnsignedByte()); - position.set("event-mask", buf.readUnsignedInt()); + if (length > 1) { + position.set("event-mask", buf.readUnsignedInt()); + } break; default: diff --git a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java index 30e040e3d..4dd061f1c 100644 --- a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java @@ -12,6 +12,9 @@ public class UlbotechProtocolDecoderTest extends ProtocolDecoderTest { UlbotechProtocolDecoder decoder = new UlbotechProtocolDecoder(new UlbotechProtocol()); + verifyPosition(decoder, binary( + "f8010108679650230646339de69054010e015ee17506bde2c60000000000ac0304024000000404000009f705060390181422170711310583410c0000310d00312f834131018608040003130a100101136cf8")); + verifyPosition(decoder, binary( "f8010108679650230651689dc8e45b010e01194a26fbd47fa6001f003c0054030402420000040400024d7b0506037c18692212071131057f410c0ee0310d1b312f41413112ef0804000dd59fcc32f8")); -- cgit v1.2.3 From 9e5de36d24d477bddc7addc29f4b504314b644cf Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 25 Nov 2015 09:20:01 +1300 Subject: Support Teltonika messages without location --- .../traccar/protocol/TeltonikaProtocolDecoder.java | 69 ++++++++++++---------- test/org/traccar/ProtocolDecoderTest.java | 12 ++-- .../protocol/TeltonikaProtocolDecoderTest.java | 3 + 3 files changed, 48 insertions(+), 36 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 2217b5ce4..e82425a54 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -81,49 +81,54 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { long time = buf.readUnsignedInt() & 0x3fffffff; time += 1167609600; // 2007-01-01 00:00:00 - position.setTime(new Date(time * 1000)); globalMask = buf.readUnsignedByte(); - if (!BitUtil.check(globalMask, 0)) { - return null; - } + if (BitUtil.check(globalMask, 0)) { - int locationMask = buf.readUnsignedByte(); + position.setTime(new Date(time * 1000)); - if (BitUtil.check(locationMask, 0)) { - position.setLatitude(buf.readFloat()); - position.setLongitude(buf.readFloat()); - } + int locationMask = buf.readUnsignedByte(); - if (BitUtil.check(locationMask, 1)) { - position.setAltitude(buf.readUnsignedShort()); - } + if (BitUtil.check(locationMask, 0)) { + position.setLatitude(buf.readFloat()); + position.setLongitude(buf.readFloat()); + } - if (BitUtil.check(locationMask, 2)) { - position.setCourse(buf.readUnsignedByte() * 360.0 / 256); - } + if (BitUtil.check(locationMask, 1)) { + position.setAltitude(buf.readUnsignedShort()); + } - if (BitUtil.check(locationMask, 3)) { - position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); - } + if (BitUtil.check(locationMask, 2)) { + position.setCourse(buf.readUnsignedByte() * 360.0 / 256); + } - if (BitUtil.check(locationMask, 4)) { - int satellites = buf.readUnsignedByte(); - position.set(Event.KEY_SATELLITES, satellites); - position.setValid(satellites >= 3); - } + if (BitUtil.check(locationMask, 3)) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + } - if (BitUtil.check(locationMask, 5)) { - position.set(Event.KEY_LAC, buf.readUnsignedShort()); - position.set(Event.KEY_CID, buf.readUnsignedShort()); - } + if (BitUtil.check(locationMask, 4)) { + int satellites = buf.readUnsignedByte(); + position.set(Event.KEY_SATELLITES, satellites); + position.setValid(satellites >= 3); + } - if (BitUtil.check(locationMask, 6)) { - position.set(Event.KEY_GSM, buf.readUnsignedByte()); - } + if (BitUtil.check(locationMask, 5)) { + position.set(Event.KEY_LAC, buf.readUnsignedShort()); + position.set(Event.KEY_CID, buf.readUnsignedShort()); + } + + if (BitUtil.check(locationMask, 6)) { + position.set(Event.KEY_GSM, buf.readUnsignedByte()); + } + + if (BitUtil.check(locationMask, 7)) { + position.set("operator", buf.readUnsignedInt()); + } + + } else { + + getLastLocation(position, new Date(time * 1000)); - if (BitUtil.check(locationMask, 7)) { - position.set("operator", buf.readUnsignedInt()); } } else { diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java index 8f7ed628b..5d2acdda1 100644 --- a/test/org/traccar/ProtocolDecoderTest.java +++ b/test/org/traccar/ProtocolDecoderTest.java @@ -119,21 +119,25 @@ public class ProtocolDecoderTest { } protected void verifyPositions(BaseProtocolDecoder decoder, Object object) throws Exception { - verifyDecodedList(decoder.decode(null, null, object), null); + verifyDecodedList(decoder.decode(null, null, object), true, null); + } + + protected void verifyPositions(BaseProtocolDecoder decoder, boolean checkLocation, Object object) throws Exception { + verifyDecodedList(decoder.decode(null, null, object), checkLocation, null); } protected void verifyPositions(BaseProtocolDecoder decoder, Object object, Position position) throws Exception { - verifyDecodedList(decoder.decode(null, null, object), position); + verifyDecodedList(decoder.decode(null, null, object), true, position); } - private void verifyDecodedList(Object decodedObject, Position expected) { + private void verifyDecodedList(Object decodedObject, boolean checkLocation, Position expected) { Assert.assertNotNull("list is null", decodedObject); Assert.assertTrue("not a list", decodedObject instanceof List); Assert.assertFalse("list if empty", ((List) decodedObject).isEmpty()); for (Object item : (List) decodedObject) { - verifyDecodedPosition(item, true, false, expected); + verifyDecodedPosition(item, checkLocation, false, expected); } } diff --git a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java index 7e3f7cb35..9e3c9a377 100644 --- a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java @@ -16,6 +16,9 @@ public class TeltonikaProtocolDecoderTest extends ProtocolDecoderTest { verifyNothing(decoder, binary( "000F313233343536373839303132333435")); + verifyPositions(decoder, false, binary( + "0000000000000055070450aa14320201f00150aa17f3031f42332a4c4193d68c008d00020901f00150aa1b6a031f423383f54193624f009d00000a01f00150aa1c230fc01a0000552b040164f400dd00f0010143100c0105000000050400006846")); + verifyPositions(decoder, binary( "000000000000003508010000014f8e016420002141bbaf0f4e96a7fffa0000120000000602010047030242669c92000002c7000000009100000000000100002df3")); -- cgit v1.2.3 From 2c399889e9b61c8e3580c046a70b556e1ab628e3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 25 Nov 2015 09:49:54 +1300 Subject: Improve H02 protocol decoder regex --- src/org/traccar/protocol/H02ProtocolDecoder.java | 31 +++++++++++++++++++--- .../traccar/protocol/H02ProtocolDecoderTest.java | 6 +++++ 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index d245fbdc8..ff3ee169e 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -27,6 +27,7 @@ import org.traccar.helper.ChannelBufferTools; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.helper.PatternUtil; import org.traccar.model.Event; import org.traccar.model.Position; @@ -122,9 +123,17 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .any() .number("(dd)(dd)(dd),") // time .expression("([AV])?,") // validity - .number("-?(d+)-?(dd.d+),") // latitude + .groupBegin() + .number("(d+)(dd.d+),") // latitude + .or() + .number("-(d+)-(d+.d+),") // latitude + .groupEnd() .expression("([NS]),") - .number("-?(d+)-?(dd.d+),") // longitude + .groupBegin() + .number("(d+)(dd.d+),") // longitude + .or() + .number("-(d+)-(d+.d+),") // longitude + .groupEnd() .expression("([EW]),") .number("(d+.?d*),") // speed .number("(d+.?d*)?,") // course @@ -135,6 +144,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { private Position decodeText(String sentence, Channel channel) { + String x = PatternUtil.checkPattern(PATTERN.pattern(), sentence); + Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; @@ -155,8 +166,20 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); } - position.setLatitude(parser.nextCoordinate()); - position.setLongitude(parser.nextCoordinate()); + if (parser.hasNext(2)) { + position.setLatitude(parser.nextCoordinate()); + } + if (parser.hasNext(2)) { + position.setLatitude(parser.nextCoordinate()); + } + + if (parser.hasNext(2)) { + position.setLongitude(parser.nextCoordinate()); + } + if (parser.hasNext(2)) { + position.setLongitude(parser.nextCoordinate()); + } + position.setSpeed(parser.nextDouble()); position.setCourse(parser.nextDouble()); diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java index b7d2b07b0..be503cc65 100644 --- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class H02ProtocolDecoderTest extends ProtocolDecoderTest { public void testDecode() throws Exception { H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol()); + + verifyPosition(decoder, buffer( + "*HQ,1451316485,V1,121557,A,-23-3.3408,S,-48-2.8926,W,0.1,158,241115,FFFFFFFF#")); + + verifyPosition(decoder, buffer( + "*HQ,1451316485,V1,121557,A,-23-35.3408,S,-48-2.8926,W,0.1,158,241115,FFFFFFFF#")); verifyPosition(decoder, buffer( "*HQ,355488020119695,V1,050418,,2827.61232,N,07703.84822,E,0.00,0,031015,FFFEFBFF#"), -- cgit v1.2.3 From 67f512fb2b481ebca78dab2163733ca2c3cef55a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 25 Nov 2015 22:05:43 +1300 Subject: Implement TK103 alarm messages support --- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 5 +++++ test/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 3 +++ 2 files changed, 8 insertions(+) (limited to 'test') diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 6fa4edb06..e8d0d210d 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -154,6 +154,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(getDeviceId()); + int alarm = sentence.indexOf("BO01"); + if (alarm != -1) { + position.set(Event.KEY_ALARM, Integer.parseInt(sentence.substring(alarm + 4, alarm + 5))); + } + DateBuilder dateBuilder = new DateBuilder(); if (parser.next() == null) { dateBuilder.setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()); diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index 2bffbcd9a..c05d546ff 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()); + verifyPosition(decoder, text( + "(013612345678BO012061830A2934.0133N10627.2544E040.0080331309.6200000000L000770AD")); + verifyAttributes(decoder, text( "(088047194605BZ00,510,010,36e6,932c,43,36e6,766b,36,36e6,7668,32")); -- cgit v1.2.3