diff options
-rw-r--r-- | src/main/java/org/traccar/protocol/T55ProtocolDecoder.java | 48 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/T55ProtocolDecoderTest.java | 3 |
2 files changed, 50 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java b/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java index b75addfae..230d29216 100644 --- a/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2020 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import org.traccar.Protocol; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; @@ -109,6 +110,20 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_QZE = new PatternBuilder() + .text("QZE,") + .number("(d{15}),") // imei + .number("(d+),") // event + .number("(dd)(dd)(dddd),") // date (mmddyyyy) + .number("(dd)(dd)(dd),") // time (hhmmss) + .number("(-?d+.d+),") // latitude + .number("(-?d+.d+),") // longitude + .number("(d+),") // speed + .number("(d+),") // course + .expression("([AV]),") // validity + .expression("([01])") // ignition + .compile(); + private Position position = null; private Position decodeGprmc( @@ -256,6 +271,35 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { return position; } + private Position decodeQze(Channel channel, SocketAddress remoteAddress, String sentence) { + + Parser parser = new Parser(PATTERN_QZE, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + position.set(Position.KEY_EVENT, parser.nextInt()); + + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt())); + position.setCourse(parser.nextInt()); + position.setValid(parser.next().equals("A")); + + position.set(Position.KEY_IGNITION, parser.nextInt() > 0); + + return position; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -308,6 +352,8 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { return decodeTrccr(deviceSession, sentence); } else if (sentence.startsWith("$GPIOP")) { return decodeGpiop(deviceSession, sentence); + } else if (sentence.startsWith("QZE")) { + return decodeQze(channel, remoteAddress, sentence); } return null; diff --git a/src/test/java/org/traccar/protocol/T55ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/T55ProtocolDecoderTest.java index c0511f2a1..25fef58f1 100644 --- a/src/test/java/org/traccar/protocol/T55ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/T55ProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class T55ProtocolDecoderTest extends ProtocolTest { T55ProtocolDecoder decoder = new T55ProtocolDecoder(null); + verifyPosition(decoder, text( + "QZE,868994033976700,35,28062020,113553,22.13673,114.57263,0,22,A,0")); + verifyNull(decoder, text( "$DEVID,0x0103846677F21422*41")); |