From 364ee0cdf23dd6d63714b8fb118ad87b850f99c3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 23 Jan 2019 20:49:19 -0800 Subject: Extend VTFMS protocol support --- src/org/traccar/protocol/VtfmsProtocolDecoder.java | 25 ++++++++++++++++------ .../traccar/protocol/VtfmsProtocolDecoderTest.java | 4 ++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/org/traccar/protocol/VtfmsProtocolDecoder.java b/src/org/traccar/protocol/VtfmsProtocolDecoder.java index c08261a59..17fac4311 100644 --- a/src/org/traccar/protocol/VtfmsProtocolDecoder.java +++ b/src/org/traccar/protocol/VtfmsProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2019 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. @@ -60,7 +60,7 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // power voltage .number("[^,]*,") // reserved .number("(d+)?,") // fuel level - .number("(d+.d+),") // adc 1 + .number("(d+.d+)?,") // adc 1 .number("[^,]*,") // reserved .number("(d+.d+)?,") // adc 2 .expression("([01]),") // di 1 @@ -93,6 +93,11 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder { } } + private double convertToDegrees(double value) { + double degrees = Math.floor(value / 100); + return degrees + (value - degrees * 100) / 60; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -116,12 +121,18 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); - position.setLatitude(parser.nextDouble(0)); - position.setLongitude(parser.nextDouble(0)); - if (parser.hasNext()) { - position.setCourse(parser.nextDouble(0)); + double latitude = parser.nextDouble(); + double longitude = parser.nextDouble(); + if (Math.abs(latitude) > 90 || Math.abs(longitude) > 180) { + position.setLatitude(convertToDegrees(latitude)); + position.setLongitude(convertToDegrees(longitude)); + } else { + position.setLatitude(latitude); + position.setLongitude(longitude); } + + position.setCourse(parser.nextDouble(0)); if (parser.hasNext()) { String direction = parser.next(); for (int i = 0; i < DIRECTIONS.length; i++) { @@ -132,7 +143,7 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder { } } - position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); position.set(Position.KEY_HOURS, UnitsConverter.msFromHours(parser.nextInt())); position.set("idleHours", parser.nextInt()); diff --git a/test/org/traccar/protocol/VtfmsProtocolDecoderTest.java b/test/org/traccar/protocol/VtfmsProtocolDecoderTest.java index 2d3940528..ede5dc7ac 100644 --- a/test/org/traccar/protocol/VtfmsProtocolDecoderTest.java +++ b/test/org/traccar/protocol/VtfmsProtocolDecoderTest.java @@ -10,6 +10,10 @@ public class VtfmsProtocolDecoderTest extends ProtocolTest { VtfmsProtocolDecoder decoder = new VtfmsProtocolDecoder(null); + verifyPosition(decoder, text( + "(861359037432331,0EF87,00,0,21,2,01,,A,154559,230119,1101.4046,07656.3859,241,000,00078,00000,K,0000812,1,12.7,,,,,,1,0,0,0,1,1,1,+919566531111*+919994462226,)054"), + position("2019-01-23 15:45:59.000", true, 11.02341, 76.93977)); + verifyPosition(decoder, text( "(865733028143493,00I76,00,000,,,,,A,133755,210617,10.57354,077.24912,SW,000,00598,00000,K,0017368,1,12.7,,,0.000,,,0,0,0,0,1,1,0,,)074")); -- cgit v1.2.3