From 184f9bb3ffa4015836ca6c67552771a4a901c15e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 20 Apr 2018 15:44:50 +1200 Subject: Decode additional P60 parameters --- src/org/traccar/protocol/Pt60ProtocolDecoder.java | 49 +++++++++++++++++++---- 1 file changed, 42 insertions(+), 7 deletions(-) (limited to 'src/org/traccar/protocol/Pt60ProtocolDecoder.java') 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; } -- cgit v1.2.3