diff options
Diffstat (limited to 'src/org/traccar/protocol/Jt600ProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/Jt600ProtocolDecoder.java | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index fd2448c0d..6d066299a 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -21,6 +21,7 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BcdUtil; +import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; @@ -202,7 +203,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_U01 = new PatternBuilder() .text("(") .number("(d+),") // id - .number("Udd,") // type + .number("(Udd),") // type .number("d+,").optional() // alarm .number("(dd)(dd)(dd),") // date (ddmmyy) .number("(dd)(dd)(dd),") // time @@ -218,7 +219,8 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // lac .number("(d+),") // gsm signal .number("(d+),") // odometer - .number("(d+)") // index + .number("(d+),?") // serial number + .number("(xx)").optional() // checksum .any() .compile(); @@ -234,6 +236,8 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { return null; } + String messageType = parser.next(); + Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -259,8 +263,32 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextLong() * 1000); position.set(Position.KEY_INDEX, parser.nextInt()); - return position; + switch (messageType) { + case "U01": + case "U02": + case "U03": + // support protocol with check sum + if (parser.hasNext(2)) { + int checkSum = parser.nextInt(16); + int calculatedCheckSum = Checksum.xor(sentence.substring(1, sentence.length() - 3)); + if (checkSum == calculatedCheckSum) { + sendResponse(channel, "(S39)"); + return position; + } else { + return null; + } + // support protocol without check sum + } else { + return position; + } + case "U06": + sendResponse(channel, "(S20)"); + return position; + default: + return null; + } } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -282,4 +310,9 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { return null; } + private void sendResponse(Channel channel, String response) { + if (channel != null) { + channel.write(ChannelBuffers.copiedBuffer(response, StandardCharsets.US_ASCII)); + } + } } |