From ca72b34c7d7dcf2d6b20b87ce3f8cc26ac7911a1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 13 Mar 2018 01:55:23 +1300 Subject: Fix CT-03 init response --- src/org/traccar/protocol/WatchProtocolDecoder.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/org/traccar/protocol/WatchProtocolDecoder.java') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 1dd07a3f7..495803ab6 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -171,7 +171,11 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { buf.readerIndex(contentIndex + 1); } - if (type.equals("LK")) { + if (type.equals("INIT")) { + + sendResponse(channel, manufacturer, id, index, "INIT,1"); + + } else if (type.equals("LK")) { sendResponse(channel, manufacturer, id, index, "LK"); -- cgit v1.2.3 From 7264149967d2bee385afcab6a8435d4b77141a49 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 13 Mar 2018 02:05:48 +1300 Subject: Fix method length issue --- src/org/traccar/protocol/WatchProtocolDecoder.java | 69 +++++++++++----------- 1 file changed, 35 insertions(+), 34 deletions(-) (limited to 'src/org/traccar/protocol/WatchProtocolDecoder.java') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 495803ab6..12ec3bd3f 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -97,8 +97,38 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { return null; } - private void decodeTail(Position position, String data) { - String[] values = data.split(","); + private Position decodePosition(DeviceSession deviceSession, String data) { + + Parser parser = new Parser(PATTERN_POSITION, data); + if (!parser.matches()) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); + + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); + position.setCourse(parser.nextDouble(0)); + position.setAltitude(parser.nextDouble(0)); + + position.set(Position.KEY_SATELLITES, parser.nextInt(0)); + position.set(Position.KEY_RSSI, parser.nextInt(0)); + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0)); + + position.set(Position.KEY_STEPS, parser.nextInt(0)); + + int status = parser.nextHexInt(0); + position.set(Position.KEY_ALARM, decodeAlarm(status)); + if (BitUtil.check(status, 4)) { + position.set(Position.KEY_MOTION, true); + } + + String[] values = parser.next().split(","); int index = 0; Network network = new Network(); @@ -127,6 +157,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) { position.setNetwork(network); } + + return position; } @Override @@ -200,38 +232,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, manufacturer, id, index, "AL"); } - Parser parser = new Parser(PATTERN_POSITION, buf.toString(StandardCharsets.US_ASCII)); - if (!parser.matches()) { - return null; - } - - Position position = new Position(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); - - position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); - - position.setValid(parser.next().equals("A")); - position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); - position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); - position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); - position.setCourse(parser.nextDouble(0)); - position.setAltitude(parser.nextDouble(0)); - - position.set(Position.KEY_SATELLITES, parser.nextInt(0)); - position.set(Position.KEY_RSSI, parser.nextInt(0)); - position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0)); - - position.set(Position.KEY_STEPS, parser.nextInt(0)); - - int status = parser.nextHexInt(0); - position.set(Position.KEY_ALARM, decodeAlarm(status)); - if (BitUtil.check(status, 4)) { - position.set(Position.KEY_MOTION, true); - } - - decodeTail(position, parser.next()); - - return position; + return decodePosition(deviceSession, buf.toString(StandardCharsets.US_ASCII)); } else if (type.equals("TKQ")) { -- cgit v1.2.3 From 7c7002e3b001b9e4f8f9a00f9a14dff87b5c9862 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 14 Mar 2018 07:58:15 +1300 Subject: Support Watch blood pressure --- src/org/traccar/protocol/WatchProtocolDecoder.java | 14 +++++++++----- test/org/traccar/protocol/WatchProtocolDecoderTest.java | 3 +++ 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src/org/traccar/protocol/WatchProtocolDecoder.java') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 12ec3bd3f..325f2efd9 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -238,7 +238,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, manufacturer, id, index, "TKQ"); - } else if (type.equals("PULSE") || type.equals("heart")) { + } else if (type.equals("PULSE") || type.equals("heart") || type.equals("bphrt")) { if (buf.readable()) { @@ -247,10 +247,14 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, new Date()); - position.setValid(false); - String pulse = buf.toString(StandardCharsets.US_ASCII); - position.set("pulse", pulse); - position.set(Position.KEY_RESULT, pulse); + String[] values = buf.toString(StandardCharsets.US_ASCII).split(","); + int valueIndex = 0; + + if (type.equals("bphrt")) { + position.set("pressureLow", values[valueIndex++]); + position.set("pressureHigh", values[valueIndex++]); + } + position.set("pulse", values[valueIndex]); return position; diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java index 657cb0640..6ba04bf8e 100644 --- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class WatchProtocolDecoderTest extends ProtocolTest { WatchProtocolDecoder decoder = new WatchProtocolDecoder(new WatchProtocol()); + verifyAttributes(decoder, buffer( + "[3G*4700609403*0013*bphrt,120,79,73,,,,]")); + verifyPosition(decoder, buffer( "[3G*8308373902*0080*AL,230817,095346,A,47.083950,N,15.4821850,E,7.60,273.8,0.0,4,15,44,0,0,00200010,2,255,232,1,7605,42530,118,7605,58036,119,0,65.8]")); -- cgit v1.2.3 From 9863a0a0c9e3f796679f0fda3ab1048a3bac2475 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 15 Mar 2018 06:05:03 +1300 Subject: Fix Watch pressure decoding --- src/org/traccar/protocol/WatchProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org/traccar/protocol/WatchProtocolDecoder.java') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 325f2efd9..c57279296 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -251,8 +251,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { int valueIndex = 0; if (type.equals("bphrt")) { - position.set("pressureLow", values[valueIndex++]); position.set("pressureHigh", values[valueIndex++]); + position.set("pressureLow", values[valueIndex++]); } position.set("pulse", values[valueIndex]); -- cgit v1.2.3