aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-06-18 14:17:20 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-06-18 14:17:20 +1200
commitb03f931ee7a294650a919c7b85e3bb988c913277 (patch)
tree1ec85e231b350ab3e3a5845f0e1f55fa7d857b8e /src/org
parentec934702d0d5f0d51ad00de84778d612e0f58ec6 (diff)
downloadtrackermap-server-b03f931ee7a294650a919c7b85e3bb988c913277.tar.gz
trackermap-server-b03f931ee7a294650a919c7b85e3bb988c913277.tar.bz2
trackermap-server-b03f931ee7a294650a919c7b85e3bb988c913277.zip
Implement GL300 heartbeat
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index 61282f521..5db31a397 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -15,6 +15,7 @@
*/
package org.traccar.protocol;
+import java.net.SocketAddress;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.regex.Matcher;
@@ -33,12 +34,18 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
+ private static final Pattern heartbeatPattern = Pattern.compile(
+ "\\+ACK\\:GTHBD," +
+ "([0-9A-Z]{2}\\p{XDigit}{4})," +
+ ".*," +
+ "(\\p{XDigit}{4})\\$?");
+
private static final Pattern pattern = Pattern.compile(
"(?:(?:\\+(?:RESP|BUFF):)|" +
"(?:\\x00?\\x04,\\p{XDigit}{4},[01],))" +
"GT...," +
- "(?:[0-9a-fA-F]{6})?," + // Protocol version
- "(\\d{15}),.*," + // IMEI
+ "(?:[0-9A-Z]{2}\\p{XDigit}{4})?," + // Protocol version
+ "([^,]+),.*," + // IMEI
"(\\d*)," + // GPS accuracy
"(\\d+.\\d)?," + // Speed
"(\\d+)?," + // Course
@@ -49,7 +56,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
"(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS)
"(\\d{4})?," + // MCC
"(\\d{4})?," + // MNC
- "(\\p{XDigit}{4})?," + // LAC
+ "(\\p{XDigit}{4}|\\p{XDigit}{8})?," + // LAC
"(\\p{XDigit}{4})?," + // Cell
"(?:(\\d+\\.\\d)?," + // Odometer
"(\\d{1,3})?)?" + // Battery
@@ -57,13 +64,23 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
@Override
protected Object decode(
- ChannelHandlerContext ctx, Channel channel, Object msg)
+ ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, Object msg)
throws Exception {
String sentence = (String) msg;
+ // Handle heartbeat
+ Matcher parser = heartbeatPattern.matcher(sentence);
+ if (parser.matches()) {
+ String s = "+SACK:GTHBD," + parser.group(1) + "," + parser.group(2) + "$";
+ if (channel != null) {
+ channel.write("+SACK:GTHBD," + parser.group(1) + "," + parser.group(2) + "$", remoteAddress);
+ }
+ return null;
+ }
+
// Parse message
- Matcher parser = pattern.matcher(sentence);
+ parser = pattern.matcher(sentence);
if (!parser.matches()) {
return null;
}
@@ -130,6 +147,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_ODOMETER, odometer);
}
position.set(Event.KEY_BATTERY, parser.group(index++));
+
return position;
}