diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-03-05 22:21:45 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-03-05 22:22:26 -0800 |
commit | 7eecff54effb04d27fdd1d67ed75a1e2dbc3c693 (patch) | |
tree | 193354df3922cfdb000487a97de69cf71cfd2c9a /src | |
parent | 74b5d0c139dd9a76064395aa733330083fd46fb8 (diff) | |
download | trackermap-server-7eecff54effb04d27fdd1d67ed75a1e2dbc3c693.tar.gz trackermap-server-7eecff54effb04d27fdd1d67ed75a1e2dbc3c693.tar.bz2 trackermap-server-7eecff54effb04d27fdd1d67ed75a1e2dbc3c693.zip |
Support OKO AVTO format
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/OkoProtocolDecoder.java | 23 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/OkoProtocolDecoderTest.java | 6 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/protocol/OkoProtocolDecoder.java b/src/main/java/org/traccar/protocol/OkoProtocolDecoder.java index 5adf61494..4d9c9afc4 100644 --- a/src/main/java/org/traccar/protocol/OkoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/OkoProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2020 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. @@ -36,7 +36,7 @@ public class OkoProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("{") .number("(d{15}),").optional() // imei - .number("(dd)(dd)(dd).d+,") // time + .number("(dd)(dd)(dd)(?:.d+)?,") // time .expression("([AV]),") // validity .number("(dd)(dd.d+),") // latitude .expression("([NS]),") @@ -46,14 +46,23 @@ public class OkoProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*)?,") // course .number("(dd)(dd)(dd),") // date (ddmmyy) .number("(d+),") // satellites - .number("(d+.d+),") // adc + .number("(d+.d+|xx),") // adc .number("(xx),") // event - .number("(d+.d+),") // power + .number("(d+.d+|xx),") // power .number("d,") // memory status - .number("(xx)") // io + .number("(xx)?") // io .any() .compile(); + private double decodeVoltage(Parser parser) { + String value = parser.next(); + if (value.contains(".")) { + return Double.parseDouble(value); + } else { + return Integer.parseInt(value, 16) * 0.1; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -89,9 +98,9 @@ public class OkoProtocolDecoder extends BaseProtocolDecoder { position.setTime(dateBuilder.getDate()); position.set(Position.KEY_SATELLITES, parser.nextInt()); - position.set(Position.PREFIX_ADC + 1, parser.nextDouble()); + position.set(Position.PREFIX_ADC + 1, decodeVoltage(parser)); position.set(Position.KEY_EVENT, parser.next()); - position.set(Position.KEY_POWER, parser.nextDouble()); + position.set(Position.KEY_POWER, decodeVoltage(parser)); position.set(Position.KEY_INPUT, parser.nextHexInt()); return position; diff --git a/src/test/java/org/traccar/protocol/OkoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/OkoProtocolDecoderTest.java index e2f72c161..d6b8e9a4a 100644 --- a/src/test/java/org/traccar/protocol/OkoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/OkoProtocolDecoderTest.java @@ -11,6 +11,12 @@ public class OkoProtocolDecoderTest extends ProtocolTest { OkoProtocolDecoder decoder = new OkoProtocolDecoder(null); verifyPosition(decoder, text( + "{868204000482330,125138,A,5026.821,N,03032.472,E,0.0,171,240200,7,00,F9,7D,1,,,,,,,91,,,187.7,M,2,,}")); + + verifyPosition(decoder, text( + "{123456789098765,132810.000,A,4926.4243,N,03203.6831,E,0.08,83.52,131010,07,5C,FB,7A,1,27,,,,,,CB,128,15grn,197.6,M,3,01FE,02AC}")); + + verifyPosition(decoder, text( "{861694033681089,045403.00,A,4924.14181,N,03207.43787,E,0.080,,151117,07,0.00,01,24.8,1,02,5n4}")); verifyPosition(decoder, text( |