diff options
16 files changed, 137 insertions, 14 deletions
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/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index e36d086f8..3179cbd78 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,37 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return null; } - if (version == 4) { + if (version == -1) { + + 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(0); + 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(); + + return readPosition(buf); + + } + + } else if (version == 4) { if (type == MSG_SC_HEARTBEAT) { 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..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. @@ -78,6 +78,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 +145,31 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { } + 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/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)); 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(); diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java index 62cdd230c..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 @@ -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")) { 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/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")); diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java index 61d38f7d1..b06715e29 100644 --- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java @@ -11,6 +11,12 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest { Gl200ProtocolDecoder decoder = new Gl200ProtocolDecoder(new Gl200Protocol()); verifyPosition(decoder, text( + "+RESP:GTFRI,110100,A5868800000015,,0,0,1,1,4.3,92,70.0,121.354335,31.222073,20110214013254,0460,0000,18d8,6141,00,80,20110214013254,000C")); + + verifyNothing(decoder, text( + "+RESP:GTFRI,210102,A10000458356CE,,0,1,1,15,1.4,0,190.6,-85.765763,42.894896,20160208164505,4126,210,0,18673,00,92,20160208164507,00A6")); + + verifyPosition(decoder, text( "+BUFF:GTFRI,060402,862894021808798,,,10,1,1,0.0,349,394.3,-63.287717,-17.662410,20160116234031,0736,0003,6ABA,8305,00,3326.8,,,,94,220100,,,,20160116194035,4D83")); verifyPosition(decoder, text( 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%,,")); diff --git a/test/org/traccar/protocol/MxtProtocolDecoderTest.java b/test/org/traccar/protocol/MxtProtocolDecoderTest.java index 37373c8de..014fcb287 100644 --- a/test/org/traccar/protocol/MxtProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MxtProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class MxtProtocolDecoderTest extends ProtocolTest { MxtProtocolDecoder decoder = new MxtProtocolDecoder(new MxtProtocol()); verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "01a631144c7e0008643ad2f456fb2d49747cfe4cbe0ffd002008800000001021000fd43d3f1403000000ff300000f42760001031102445a81fda04")); + + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "01a631361e7a00082471418b052a2c46b587ffc01ae3fd000008800000000000003345422203000000f000f00000000000ea1e04")); verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, diff --git a/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java b/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java index 438dc057c..c4fbdcdf4 100644 --- a/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java @@ -11,6 +11,10 @@ public class Tlt2hProtocolDecoderTest extends ProtocolTest { Tlt2hProtocolDecoder decoder = new Tlt2hProtocolDecoder(new Tlt2hProtocol()); verifyPositions(decoder, text( + "#357671030108689##0000#AUTO#1\r\n", + "#13AE2F8F$GPRMC,211452.000,A,0017.378794,S,03603.441981,E,0.000,0,060216,,,A*68\r\n")); + + verifyPositions(decoder, text( "#357671030946351#V500#0000#AUTO#1\r\n", "#$GPRMC,223835.000,A,0615.3545,S,10708.5779,E,14.62,97.41,070313,,,D*70\r\n"), position("2013-03-07 22:38:35.000", true, -6.25591, 107.14297)); diff --git a/test/org/traccar/protocol/TrvProtocolDecoderTest.java b/test/org/traccar/protocol/TrvProtocolDecoderTest.java index 037254486..13ff61792 100644 --- a/test/org/traccar/protocol/TrvProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TrvProtocolDecoderTest.java @@ -16,6 +16,15 @@ public class TrvProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, text( "TRVCP01,06000908000102")); + 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")); + verifyPosition(decoder, text( "TRVAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671")); 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 @@ -12,6 +12,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)); |