diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-04-24 06:51:06 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-04-24 06:51:06 +1200 |
commit | b342537302665a679ff7458aad27d8137a8838f3 (patch) | |
tree | fc5736db844b09cfc7c74934809abf58a0bdf47f /src/org/traccar/protocol/TrvProtocolDecoder.java | |
parent | 72f12c56689bc5b90e4b2256027a88289e5f47fa (diff) | |
download | traccar-server-b342537302665a679ff7458aad27d8137a8838f3.tar.gz traccar-server-b342537302665a679ff7458aad27d8137a8838f3.tar.bz2 traccar-server-b342537302665a679ff7458aad27d8137a8838f3.zip |
Implement PT33 protocol variant
Diffstat (limited to 'src/org/traccar/protocol/TrvProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/TrvProtocolDecoder.java | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java index 415828ffd..88ac76134 100644 --- a/src/org/traccar/protocol/TrvProtocolDecoder.java +++ b/src/org/traccar/protocol/TrvProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 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. @@ -27,6 +27,8 @@ import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.regex.Pattern; public class TrvProtocolDecoder extends BaseProtocolDecoder { @@ -36,7 +38,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN = new PatternBuilder() - .text("TRV") + .expression("[A-Z]{2,3}") .number("APdd") .number("(dd)(dd)(dd)") // date (yymmdd) .expression("([AV])") // validity @@ -61,7 +63,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { .compile(); private static final Pattern PATTERN_HEATRBEAT = new PatternBuilder() - .text("TRV") + .expression("[A-Z]{2,3}") .text("CP01,") .number("(ddd)") // gsm .number("(ddd)") // gps @@ -78,13 +80,20 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; - String type = sentence.substring(3, 7); + String id = sentence.startsWith("TRV") ? sentence.substring(0, 3) : sentence.substring(0, 2); + String type = sentence.substring(id.length(), id.length() + 4); + if (channel != null) { - channel.write("TRV" + (char) (type.charAt(0) + 1) + type.substring(1) + "#"); // response + if (type.equals("AP00") && id.equals("IW")) { + String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); + channel.write(id + (char) (type.charAt(0) + 1) + type.substring(1) + "," + time + ",0#"); + } else { + channel.write(id + (char) (type.charAt(0) + 1) + type.substring(1) + "#"); + } } if (type.equals("AP00")) { - getDeviceSession(channel, remoteAddress, sentence.substring(7)); + getDeviceSession(channel, remoteAddress, sentence.substring(id.length() + type.length())); return null; } |