diff options
-rw-r--r-- | src/org/traccar/model/Position.java | 1 | ||||
-rw-r--r-- | src/org/traccar/protocol/Pt60ProtocolDecoder.java | 49 | ||||
-rw-r--r-- | src/org/traccar/protocol/WatchProtocolDecoder.java | 2 | ||||
-rw-r--r-- | test/org/traccar/protocol/Pt60ProtocolDecoderTest.java | 6 |
4 files changed, 50 insertions, 8 deletions
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index fca0f16e3..b0e08244c 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -39,6 +39,7 @@ public class Position extends Message { public static final String KEY_ODOMETER_TRIP = "tripOdometer"; // meters public static final String KEY_HOURS = "hours"; public static final String KEY_STEPS = "steps"; + public static final String KEY_HEART_RATE = "heartRate"; public static final String KEY_INPUT = "input"; public static final String KEY_OUTPUT = "output"; public static final String KEY_IMAGE = "image"; 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; } diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index b58c3b6a1..f55b6f7be 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -273,7 +273,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { position.set("pressureHigh", values[valueIndex++]); position.set("pressureLow", values[valueIndex++]); } - position.set("pulse", values[valueIndex]); + position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[valueIndex])); return position; diff --git a/test/org/traccar/protocol/Pt60ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt60ProtocolDecoderTest.java index 08fe7658e..69d77fe66 100644 --- a/test/org/traccar/protocol/Pt60ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Pt60ProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class Pt60ProtocolDecoderTest extends ProtocolTest { Pt60ProtocolDecoder decoder = new Pt60ProtocolDecoder(new Pt60Protocol()); + verifyAttributes(decoder, text( + "@G#@,V01,14,357653051059785,9404223001501310,20180419165604,101,26,")); + + verifyAttributes(decoder, text( + "@G#@,V01,13,357653051059785,9404223001501310,20180419112656,1180,")); + verifyPosition(decoder, text( "@G#@,V01,6,111112222233333,8888888888888888,20150312010203,23.2014050;104.235212,")); |