From 1f3185d8a06f5d8cd3c05c15cbb7abbbfa81af37 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 26 Apr 2017 17:06:43 +1200 Subject: Implement additional Xirgo attributes --- src/org/traccar/helper/Parser.java | 8 +++++ src/org/traccar/helper/UnitsConverter.java | 9 +++++ src/org/traccar/protocol/XirgoProtocolDecoder.java | 39 ++++++++++++++++++++-- .../traccar/protocol/XirgoProtocolDecoderTest.java | 6 ++++ 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java index 69c80adb2..582b497cf 100644 --- a/src/org/traccar/helper/Parser.java +++ b/src/org/traccar/helper/Parser.java @@ -121,6 +121,14 @@ public class Parser { } } + public Double nextDouble() { + if (hasNext()) { + return Double.parseDouble(next()); + } else { + return null; + } + } + public double nextDouble(double defaultValue) { if (hasNext()) { return Double.parseDouble(next()); diff --git a/src/org/traccar/helper/UnitsConverter.java b/src/org/traccar/helper/UnitsConverter.java index e0d94c6dc..56d15e4e7 100644 --- a/src/org/traccar/helper/UnitsConverter.java +++ b/src/org/traccar/helper/UnitsConverter.java @@ -22,6 +22,7 @@ public final class UnitsConverter { private static final double KNOTS_TO_MPS_RATIO = 1.94384; private static final double KNOTS_TO_CPS_RATIO = 0.0194384449; private static final double METERS_TO_FEET_RATIO = 0.3048; + private static final double METERS_TO_MILE_RATIO = 1609.34; private UnitsConverter() { } @@ -62,4 +63,12 @@ public final class UnitsConverter { return value * METERS_TO_FEET_RATIO; } + public static double milesFromMeters(double value) { + return value / METERS_TO_MILE_RATIO; + } + + public static double metersFromMiles(double value) { + return value * METERS_TO_MILE_RATIO; + } + } diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java index c6d4b6978..77327e001 100644 --- a/src/org/traccar/protocol/XirgoProtocolDecoder.java +++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,6 +75,23 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // battery .number("(d+),") // gsm .number("(d+),") // gps + .groupBegin() + .number("d,") // reset mode + .expression("([01])") // input 1 + .expression("([01])") // input 1 + .expression("([01])") // input 1 + .expression("([01]),") // output 1 + .number("(d+.?d*),") // adc 1 + .number("(d+.?d*),") // fuel level + .number("d+,") // engine load + .number("(d+),") // engine hours + .number("(d+),") // oil pressure + .number("(d+),") // oil level + .number("(-?d+),") // oil temperature + .number("(d+),") // coolant pressure + .number("(d+),") // coolant level + .number("(-?d+)") // coolant temperature + .groupEnd("?") .any() .compile(); @@ -131,7 +148,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_HDOP, parser.next()); if (newFormat) { - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1609.34); + position.set(Position.KEY_ODOMETER, UnitsConverter.metersFromMiles(parser.nextDouble(0))); position.set(Position.KEY_FUEL_CONSUMPTION, parser.next()); } @@ -139,11 +156,27 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_RSSI, parser.next()); if (!newFormat) { - position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1609.34); + position.set(Position.KEY_ODOMETER, UnitsConverter.metersFromMiles(parser.nextDouble(0))); } position.setValid(parser.nextInt(0) == 1); + if (newFormat && parser.hasNext(13)) { + position.set(Position.PREFIX_IN + 1, parser.nextInt()); + position.set(Position.PREFIX_IN + 2, parser.nextInt()); + position.set(Position.PREFIX_IN + 3, parser.nextInt()); + position.set(Position.PREFIX_OUT + 1, parser.nextInt()); + position.set(Position.PREFIX_ADC + 1, parser.nextDouble()); + position.set(Position.KEY_FUEL_LEVEL, parser.nextDouble()); + position.set(Position.KEY_HOURS, parser.nextInt()); + position.set("oilPressure", parser.nextInt()); + position.set("oilLevel", parser.nextInt()); + position.set("oilTemp", parser.nextInt()); + position.set("coolantPressure", parser.nextInt()); + position.set("coolantLevel", parser.nextInt()); + position.set("coolantTemp", parser.nextInt()); + } + return position; } diff --git a/test/org/traccar/protocol/XirgoProtocolDecoderTest.java b/test/org/traccar/protocol/XirgoProtocolDecoderTest.java index 82076d7eb..cf046c42f 100644 --- a/test/org/traccar/protocol/XirgoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/XirgoProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class XirgoProtocolDecoderTest extends ProtocolTest { XirgoProtocolDecoder decoder = new XirgoProtocolDecoder(new XirgoProtocol()); + verifyPosition(decoder, text( + "$$352054058132185,4001,2017/04/21,00:01:05,32.54659,-116.90670,143.2,0,0,0,598,0.0,12,0.9,765840,7.0,14.5,19,1,1,0011,8.5,63.2,5,21999,184,255,671,207,100,185##")); + + verifyPosition(decoder, text( + "$$352054058132185,6011,2017/04/21,04:57:10,32.49658,-116.85957,250.9,0,0,0,602,0.0,12,0.8,765876,7.0,14.1,21,1,1,0011,10.1,0.0,5,170917890,280,255,627,0,100,167##")); + verifyPosition(decoder, text( "$$355922061611345,6001,2016/08/25,20:10:51,51.13042,-114.22752,1197,44.7,0.0,0.0,2622,27,12,0.8,1,0.0,13.9,24,1,0,0.0,-70,-809,688##")); -- cgit v1.2.3