From 6153dceed18c7ae510cc1d71c407a0cc796dfefe Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 7 Feb 2016 07:24:17 +1000 Subject: Support new TLT-2H message format --- src/org/traccar/protocol/Tlt2hProtocolDecoder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java index 5f44bd989..802b00f1f 100644 --- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java +++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java @@ -35,7 +35,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_HEADER = new PatternBuilder() .number("#(d+)#") // imei - .expression("[^#]+#") + .expression("[^#]*#") .number("d+#") .expression("([^#]+)#") // status .number("d+") // number of records @@ -50,8 +50,8 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { .expression("([NS]),") .number("(d+)(dd.d+),") // longitude .number("([EW]),") - .number("(d+.d+)?,") // speed - .number("(d+.d+)?,") // course + .number("(d+.?d*)?,") // speed + .number("(d+.?d*)?,") // course .number("(dd)(dd)(dd)") // date (ddmmyy) .any() .compile(); -- cgit v1.2.3 From 18aaf44bcde8eb5243b069727fb4f056e94df938 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 7 Feb 2016 07:25:19 +1000 Subject: Change TLT-2H frame decoder --- src/org/traccar/protocol/Tlt2hProtocol.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/Tlt2hProtocol.java b/src/org/traccar/protocol/Tlt2hProtocol.java index d1a8ee735..3a1bf99ff 100644 --- a/src/org/traccar/protocol/Tlt2hProtocol.java +++ b/src/org/traccar/protocol/Tlt2hProtocol.java @@ -36,7 +36,7 @@ public class Tlt2hProtocol extends BaseProtocol { serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(32 * 1024, "##")); + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(32 * 1024, "##\r\n")); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("objectDecoder", new Tlt2hProtocolDecoder(Tlt2hProtocol.this)); -- cgit v1.2.3 From f325f30ab8d9097eec01a39f5e7ac02c11d608c3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 7 Feb 2016 07:45:44 +1000 Subject: Handle new line in Xexun messages --- src/org/traccar/protocol/XexunProtocolDecoder.java | 5 +++-- test/org/traccar/protocol/XexunProtocolDecoderTest.java | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java index f9369b463..0929ee99b 100644 --- a/src/org/traccar/protocol/XexunProtocolDecoder.java +++ b/src/org/traccar/protocol/XexunProtocolDecoder.java @@ -44,8 +44,9 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*)?,") // course .number("(dd)(dd)(dd),") // date .expression("[^*]*").text("*") - .number("xx,") // checksum - .expression("([FL]),") // signal + .number("xx") // checksum + .expression("\\r\\n").optional() + .expression(",([FL]),") // signal .expression("([^,]*),").optional() // alarm .any() .number("imei:(d+),") // imei diff --git a/test/org/traccar/protocol/XexunProtocolDecoderTest.java b/test/org/traccar/protocol/XexunProtocolDecoderTest.java index 27574ddce..76c516caf 100644 --- a/test/org/traccar/protocol/XexunProtocolDecoderTest.java +++ b/test/org/traccar/protocol/XexunProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class XexunProtocolDecoderTest extends ProtocolTest { XexunProtocolDecoder decoder = new XexunProtocolDecoder(new XexunProtocol(), false); + verifyPosition(decoder, text( + "GPRMC,121535.000,A,5417.2666,N,04822.1264,E,1.452,30.42,031014,0.0,A*4D\r\n,L,imei:355227042011730,")); + verifyPosition(decoder, text( "GPRMC,150120.000,A,3346.4463,S,15057.3083,E,0.0,117.4,010911,,,A*76,F,imei:351525010943661,"), position("2011-09-01 15:01:20.000", true, -33.77411, 150.95514)); -- cgit v1.2.3 From 230107d2157de837a570783855a430f7e81b842f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 9 Feb 2016 07:29:26 +1000 Subject: Send correct response for TRV protocol --- src/org/traccar/protocol/TrvProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java index 62cdd230c..c81dd08b9 100644 --- a/src/org/traccar/protocol/TrvProtocolDecoder.java +++ b/src/org/traccar/protocol/TrvProtocolDecoder.java @@ -78,7 +78,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { String type = sentence.substring(3, 7); if (channel != null) { - channel.write((char) (type.charAt(0) + 1) + type.substring(1)); // response + channel.write("TRV" + (char) (type.charAt(0) + 1) + type.substring(1) + "#"); // response } if (type.equals("AP00")) { -- cgit v1.2.3 From 810d4f77a77a7a66f22d747ef849925848b758f9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 9 Feb 2016 17:28:52 +1000 Subject: Support GPS103 OBD messages (fix #1632) --- src/org/traccar/model/Event.java | 1 + .../traccar/protocol/AtrackProtocolDecoder.java | 2 +- src/org/traccar/protocol/Gl200ProtocolDecoder.java | 2 +- .../traccar/protocol/Gps103ProtocolDecoder.java | 49 ++++++++++++++++++++++ .../protocol/Gps103ProtocolDecoderTest.java | 9 ++++ 5 files changed, 61 insertions(+), 2 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java index 6e3aa7f22..a9f6f9204 100644 --- a/src/org/traccar/model/Event.java +++ b/src/org/traccar/model/Event.java @@ -50,6 +50,7 @@ public abstract class Event extends Extensible { public static final String KEY_RPM = "rpm"; public static final String KEY_VIN = "vin"; public static final String KEY_APPROXIMATE = "approximate"; + public static final String KEY_THROTTLE = "throttle"; public static final String KEY_OBD_SPEED = "obd-speed"; public static final String KEY_OBD_ODOMETER = "obd-odometer"; diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index 2f0d692e9..72a17eed2 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -131,7 +131,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // engine load break; case "TR": - buf.readUnsignedByte(); // throttle position + position.set(Event.KEY_THROTTLE, buf.readUnsignedByte()); break; case "ET": buf.readUnsignedShort(); // engine coolant temp diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index a2681e10d..e4bf43979 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -203,7 +203,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set("odb-connect", parser.next()); position.set("dtcs-number", parser.next()); position.set("dtcs-codes", parser.next()); - position.set("throttle-position", parser.next()); + position.set(Event.KEY_THROTTLE, parser.next()); position.set(Event.KEY_FUEL, parser.next()); position.set(Event.KEY_OBD_ODOMETER, parser.next()); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 2c7397231..61a96695c 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -22,6 +22,7 @@ import org.traccar.BaseProtocolDecoder; 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; @@ -78,6 +79,27 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .number("##,imei:(d+),A") .compile(); + private static final Pattern PATTERN_OBD = new PatternBuilder() + .text("imei:") + .number("(d+),") // imei + .expression("OBD,") // type + .number("(dd)(dd)(dd)") // date + .number("(dd)(dd)(dd),") // time + .number("(d+),") // odometer + .number("(d+.d+)?,") // fuel instant + .number("(?:d+.d+)?,") // fuel average + .number("(d+),") // speed + .number("d+,") // power load + .number("(d+.d+%),") // throttle + .number("(d+),") // rpm + .number("(d+.d+%),") // battery + .number("[^,]*,") // dtc 1 + .number("[^,]*,") // dtc 2 + .number("[^,]*,") // dtc 3 + .number("[^,]*") // dtc 4 + .any() + .compile(); + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -124,6 +146,33 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { } + String x = PatternUtil.checkPattern(PATTERN_OBD.pattern(), sentence); + + parser = new Parser(PATTERN_OBD, sentence); + if (parser.matches()) { + + if (!identify(parser.next(), channel, remoteAddress)) { + return null; + } + position.setDeviceId(getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + + getLastLocation(position, dateBuilder.getDate()); + + position.set(Event.KEY_ODOMETER, parser.nextInt()); + position.set(Event.KEY_FUEL, parser.next()); + position.set(Event.KEY_OBD_SPEED, parser.next()); + position.set(Event.KEY_THROTTLE, parser.next()); + position.set(Event.KEY_RPM, parser.next()); + position.set(Event.KEY_BATTERY, parser.next()); + + return position; + + } + parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 9f5b386cc..ae3d2fa55 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -10,6 +10,15 @@ public class Gps103ProtocolDecoderTest extends ProtocolTest { Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new Gps103Protocol()); + verifyNothing(decoder, text( + "imei:865328021049167,OBD,141118115036,,,0.0,,000,0.0%,+,0.0%,00000,,,,,")); + + verifyAttributes(decoder, text( + "imei:359710049032874,OBD,160208152900,13555,,,45,0,24.71%,35,13.73%,1230,14.13,U1108,,,")); + + verifyAttributes(decoder, text( + "imei:359710049064398,OBD,160101035156,17887,0.00,17.06,0,0,0.00%,0,0.00%,16383,10.82,,,,")); + verifyPosition(decoder, text( "imei:868683020235846,rfid,160202091347,49121185,F,011344.000,A,0447.7273,N,07538.9934,W,0.00,0,,0,0,0.00%,,")); -- cgit v1.2.3 From 3b569e6e8994f02f7856c4ad48ac1342b79453fa Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 11 Feb 2016 08:53:12 +1100 Subject: Remove pattern debugging code --- src/org/traccar/protocol/Gps103ProtocolDecoder.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 61a96695c..a45e20ba2 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 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. @@ -22,7 +22,6 @@ import org.traccar.BaseProtocolDecoder; 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; @@ -146,8 +145,6 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { } - String x = PatternUtil.checkPattern(PATTERN_OBD.pattern(), sentence); - parser = new Parser(PATTERN_OBD, sentence); if (parser.matches()) { -- cgit v1.2.3 From 3884c75ab3849cdb7b2a86ff7fa64c1c22df4ad2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 11 Feb 2016 19:05:52 +1100 Subject: Add support for new Castel format --- .../traccar/protocol/CastelProtocolDecoder.java | 23 +++++++++++++++++++--- .../protocol/CastelProtocolDecoderTest.java | 6 ++++++ 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index e36d086f8..4b8f3b716 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -115,9 +115,14 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; - buf.skipBytes(2); // header + int header = buf.readUnsignedShort(); buf.readUnsignedShort(); // length - int version = buf.readUnsignedByte(); + + int version = -1; + if (header == 0x4040) { + version = buf.readUnsignedByte(); + } + ChannelBuffer id = buf.readBytes(20); int type = ChannelBuffers.swapShort(buf.readShort()); @@ -125,7 +130,19 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return null; } - if (version == 4) { + if (version == -1) { + + if (type == 0x2001) { + + buf.readUnsignedInt(); // index + buf.readUnsignedInt(); // unix time + buf.readUnsignedByte(); + + return readPosition(buf); + + } + + } else if (version == 4) { if (type == MSG_SC_HEARTBEAT) { diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java index b8795e09a..eafe80748 100644 --- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java @@ -12,6 +12,12 @@ public class CastelProtocolDecoderTest extends ProtocolTest { CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol()); + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "24243f00676e6768656636313031313132393030313734002001840d0000d2deb556020602100b35360456cf09e6ebac0200000000030000000001abc10d0a")); + + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "24243f00676e6768656636313031313132393030313734002001840d000000dfb556020602100b36298256cf0956ebac020000990c7f0000000001b4830d0a")); + verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040590004313030303030303030303800000000000000000040010072f53f56c25240560000000078b00900000000009c3100000000030100011900030001090b0f080106c04fe40b4037310c0060e001ff018d01e05e0d0a")); -- cgit v1.2.3 From e2a40de5021419222bcfa224e3543881235be7db Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 11 Feb 2016 21:37:54 +1100 Subject: Add new Castel response message --- src/org/traccar/protocol/CastelProtocolDecoder.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/org') diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 4b8f3b716..209862d1d 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -134,6 +134,24 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { if (type == 0x2001) { + if (channel != null) { + int length = 2 + 2 + id.readableBytes() + 2 + 4 + 8 + 2 + 2; + + ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length); + response.writeByte('@'); response.writeByte('@'); + response.writeShort(length); + response.writeBytes(id); + response.writeShort(ChannelBuffers.swapShort((short) 0x1001)); + response.writeInt((int) (System.currentTimeMillis() / 1000)); + for (int i = 0; i < 8; i++) { + response.writeByte(0xff); + } + response.writeShort( + Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex()))); + response.writeByte(0x0D); response.writeByte(0x0A); + channel.write(response, remoteAddress); + } + buf.readUnsignedInt(); // index buf.readUnsignedInt(); // unix time buf.readUnsignedByte(); -- cgit v1.2.3 From 538b2eca6dd2e317376e5161efa7ff0f1fbf9662 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 12 Feb 2016 08:42:16 +1100 Subject: Make TRV course format more flexible --- src/org/traccar/protocol/TrvProtocolDecoder.java | 2 +- test/org/traccar/protocol/TrvProtocolDecoderTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java index c81dd08b9..94796fa5e 100644 --- a/src/org/traccar/protocol/TrvProtocolDecoder.java +++ b/src/org/traccar/protocol/TrvProtocolDecoder.java @@ -44,7 +44,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { .expression("([EW])") .number("(ddd.d)") // speed .number("(dd)(dd)(dd)") // time - .number("(ddd.dd)") // course + .number("([d.]{6})") // course .number("(ddd)") // gsm .number("(ddd)") // satellites .number("(ddd)") // battery diff --git a/test/org/traccar/protocol/TrvProtocolDecoderTest.java b/test/org/traccar/protocol/TrvProtocolDecoderTest.java index b77c848a6..13ff61792 100644 --- a/test/org/traccar/protocol/TrvProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TrvProtocolDecoderTest.java @@ -19,6 +19,9 @@ public class TrvProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, text( "TRVCP01,100007100000001020151060011")); + verifyPosition(decoder, text( + "TRVAP01160211A2544.5118N05553.7586E105.711185941.52010001010010000,424,030,3011,27003")); + verifyPosition(decoder, text( "TRVAP01160209A2540.8863N05546.6125E005.6075734123.7910000810010000,424,030,3012,27323")); -- cgit v1.2.3 From 9b11013c2376ad0401c194d5cfa0014e0a08502e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 12 Feb 2016 09:13:02 +1100 Subject: Send index 0 for Castel response --- src/org/traccar/protocol/CastelProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 209862d1d..3179cbd78 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -142,7 +142,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { response.writeShort(length); response.writeBytes(id); response.writeShort(ChannelBuffers.swapShort((short) 0x1001)); - response.writeInt((int) (System.currentTimeMillis() / 1000)); + response.writeInt(0); for (int i = 0; i < 8; i++) { response.writeByte(0xff); } -- cgit v1.2.3