diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-04-20 15:44:50 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-04-20 15:44:50 +1200 |
commit | 184f9bb3ffa4015836ca6c67552771a4a901c15e (patch) | |
tree | 75fee04a5d778862f2a21b37e6ce484c539b1cdb /src/org/traccar/protocol/Pt60ProtocolDecoder.java | |
parent | 773768093c6c78906e54abe128cb1b4ca9430313 (diff) | |
download | traccar-server-184f9bb3ffa4015836ca6c67552771a4a901c15e.tar.gz traccar-server-184f9bb3ffa4015836ca6c67552771a4a901c15e.tar.bz2 traccar-server-184f9bb3ffa4015836ca6c67552771a4a901c15e.zip |
Decode additional P60 parameters
Diffstat (limited to 'src/org/traccar/protocol/Pt60ProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/Pt60ProtocolDecoder.java | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/Pt60ProtocolDecoder.java b/src/org/traccar/protocol/Pt60ProtocolDecoder.java index c87c22c5f..26f07a0a9 100644 --- a/src/org/traccar/protocol/Pt60ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt60ProtocolDecoder.java @@ -34,16 +34,19 @@ public class Pt60ProtocolDecoder extends BaseProtocolDecoder { super(protocol); } + public static final int MSG_TRACK = 6; + public static final int MSG_STEP_COUNT = 13; + public static final int MSG_HEART_RATE = 14; + private static final Pattern PATTERN = new PatternBuilder() .text("@G#@,") // header .number("Vdd,") // protocol version - .number("d,") // type + .number("(d+),") // type .number("(d+),") // imei .number("(d+),") // imsi .number("(dddd)(dd)(dd)") // date (yyyymmdd) .number("(dd)(dd)(dd),") // time (hhmmss) - .number("(-?d+.d+);") // latitude - .number("(-?d+.d+),") // longitude + .expression("(.*)") // data .compile(); private void sendResponse(Channel channel) { @@ -64,6 +67,12 @@ public class Pt60ProtocolDecoder extends BaseProtocolDecoder { return null; } + int type = parser.nextInt(); + + if (type != MSG_TRACK && type != MSG_STEP_COUNT && type != MSG_HEART_RATE) { + return null; + } + Position position = new Position(getProtocolName()); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next(), parser.next()); @@ -72,10 +81,36 @@ public class Pt60ProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - position.setValid(true); - position.setTime(parser.nextDateTime()); - position.setLatitude(parser.nextDouble()); - position.setLongitude(parser.nextDouble()); + position.setDeviceTime(parser.nextDateTime()); + + String[] values = parser.next().split(","); + + if (type == MSG_TRACK) { + + position.setValid(true); + position.setFixTime(position.getDeviceTime()); + + String[] coordinates = values[0].split(";"); + position.setLatitude(Double.parseDouble(coordinates[0])); + position.setLongitude(Double.parseDouble(coordinates[1])); + + } else { + + getLastLocation(position, position.getDeviceTime()); + + switch (type) { + case MSG_STEP_COUNT: + position.set(Position.KEY_STEPS, Integer.parseInt(values[0])); + break; + case MSG_HEART_RATE: + position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[0])); + position.set(Position.KEY_BATTERY, Integer.parseInt(values[1])); + break; + default: + break; + } + + } return position; } |