diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2024-06-10 21:04:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-10 21:04:24 -0700 |
commit | 0bb9e28cf771a60db06a33b4967a2049bea72af5 (patch) | |
tree | 696f098730209799de5e6582884fb51e2c806e00 | |
parent | e92dea78ebad3f921c031a974378a218c6bd90b1 (diff) | |
parent | 7e80c11158a046045484affe9406adfde7219697 (diff) | |
download | trackermap-server-0bb9e28cf771a60db06a33b4967a2049bea72af5.tar.gz trackermap-server-0bb9e28cf771a60db06a33b4967a2049bea72af5.tar.bz2 trackermap-server-0bb9e28cf771a60db06a33b4967a2049bea72af5.zip |
Merge pull request #5339 from jcardus/patch-1
Ignition messages not correctly decoded
-rw-r--r-- | src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java | 50 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java | 7 |
2 files changed, 31 insertions, 26 deletions
diff --git a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java index 8edce9346..cfed351f2 100644 --- a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java @@ -1033,36 +1033,34 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { return positions; } - private static final Pattern PATTERN_IGN = new PatternBuilder() - .text("+").expression("(?:RESP|BUFF):GT[IV]G[NF],") - .expression("(?:.{6}|.{10})?,") // protocol version - .number("(d{15}|x{14}),") // imei - .expression("[^,]*,") // device name - .number("d+,") // ignition off duration - .expression(PATTERN_LOCATION.pattern()) - .number("(d{5}:dd:dd)?,") // hour meter - .number("(d{1,7}.d)?,") // odometer - .number("(dddd)(dd)(dd)") // date (yyyymmdd) - .number("(dd)(dd)(dd)").optional(2) // time (hhmmss) - .text(",") - .number("(xxxx)") // count number - .text("$").optional() - .compile(); - - private Object decodeIgn(Channel channel, SocketAddress remoteAddress, String sentence) { - Parser parser = new Parser(PATTERN_IGN, sentence); - Position position = initPosition(parser, channel, remoteAddress); - if (position == null) { + private Object decodeIgn( + Channel channel, SocketAddress remoteAddress, String[] v, String type) throws ParseException { + int index = 0; + index += 1; // header + String protocolVersion = v[index++]; // protocol version + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, v[index++]); + if (deviceSession == null) { return null; } + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); - decodeLocation(position, parser); + String model = getDeviceModel(deviceSession, protocolVersion); + index += 1; // device name + index += 1; // duration of ignition on/off - position.set(Position.KEY_IGNITION, sentence.contains("GN")); - position.set(Position.KEY_HOURS, parseHours(parser.next())); - position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + decodeLocation(position, model, v, index); - decodeDeviceTime(position, parser); + position.set(Position.KEY_IGNITION, type.contains("GN")); + position.set(Position.KEY_HOURS, parseHours(v[index++])); + position.set(Position.KEY_ODOMETER, Double.parseDouble(v[index]) * 1000); + + Date time = dateFormat.parse(v[v.length - 2]); + if (ignoreFixTime) { + position.setTime(time); + } else { + position.setDeviceTime(time); + } return position; } @@ -1682,7 +1680,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { case "IGF": case "VGN": case "VGF": - result = decodeIgn(channel, remoteAddress, sentence); + result = decodeIgn(channel, remoteAddress, values, type); break; case "LSW": case "TSW": diff --git a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java index 925a0da1c..406a447ab 100644 --- a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java @@ -513,6 +513,13 @@ public class Gl200TextProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, buffer( "+RESP:GTCAN,8020050605,867488060270575,,00,1,FFFFFFFF,8LBETF3W4N0001613,,,22.54,0,,,,,,,7.84,4.61,3.24,3.33,,8080,,,00,0.00,0.00,1,14,14,2371,0,001FFFFF,,,,,,,,,7158,9998,0,7.84,0.00,0.00,558,,,,,,,C0,,,,,0,0.0,346,2848.5,-78.592371,-0.968132,20240202083437,0740,0002,526C,00AE7907,00,20240202083440,3F6D$")); + verifyAttribute(decoder, buffer( + "+BUFF:GTIGN,6E0202,868589060169789,ra79,379,1,0.0,105,532.2,-70.616413,-33.393457,20240610201712,0730,0001,333A,00CFA301,01,11,,0.0,20240610201713,3AE2$"), + Position.KEY_IGNITION, true); + + verifyAttribute(decoder, buffer( + "+RESP:GTIGF,6E0202,868589060169789,ra79,145,1,0.0,83,532.2,-70.616413,-33.393457,20240610201937,0730,0001,333A,00CFA301,01,12,,0.0,20240610201938,3AE9$"), + Position.KEY_IGNITION, false); } } |