diff options
-rw-r--r-- | src/org/traccar/protocol/EskyProtocolDecoder.java | 33 | ||||
-rw-r--r-- | test/org/traccar/protocol/EskyFrameDecoderTest.java | 4 | ||||
-rw-r--r-- | test/org/traccar/protocol/EskyProtocolDecoderTest.java | 3 |
3 files changed, 26 insertions, 14 deletions
diff --git a/src/org/traccar/protocol/EskyProtocolDecoder.java b/src/org/traccar/protocol/EskyProtocolDecoder.java index 60ef4f846..bf790541b 100644 --- a/src/org/traccar/protocol/EskyProtocolDecoder.java +++ b/src/org/traccar/protocol/EskyProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2018 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. @@ -37,16 +37,18 @@ public class EskyProtocolDecoder extends BaseProtocolDecoder { .number("d+;") // index .number("(d+);") // imei .text("R;") // data type - .number("(d+)").text("+") // satellites + .number("(d+)[+;]") // satellites .number("(dd)(dd)(dd)") // date - .number("(dd)(dd)(dd)").text("+") // time - .number("(-?d+.d+)").text("+") // latitude - .number("(-?d+.d+)").text("+") // longitude - .number("(d+.d+)").text("+") // speed - .number("(d+)").text("+") // course - .text("0x").number("(d+)").text("+") // input - .number("(d+)").text("+") // message type - .number("(d+)").text("+") // odometer + .number("(dd)(dd)(dd)[+;]") // time + .number("(-?d+.d+)[+;]") // latitude + .number("(-?d+.d+)[+;]") // longitude + .number("(d+.d+)[+;]") // speed + .number("(d+)[+;]") // course + .groupBegin() + .text("0x").number("(d+)[+;]") // input + .number("(d+)[+;]") // message type + .number("(d+)[+;]") // odometer + .groupEnd("?") .number("(d+)") // voltage .any() .compile(); @@ -77,10 +79,13 @@ public class EskyProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromMps(parser.nextDouble())); position.setCourse(parser.nextDouble()); - position.set(Position.KEY_INPUT, parser.nextHexInt()); - position.set(Position.KEY_EVENT, parser.nextInt()); - position.set(Position.KEY_ODOMETER, parser.nextInt()); - position.set(Position.KEY_POWER, parser.nextInt()); + if (parser.hasNext(3)) { + position.set(Position.KEY_INPUT, parser.nextHexInt()); + position.set(Position.KEY_EVENT, parser.nextInt()); + position.set(Position.KEY_ODOMETER, parser.nextInt()); + } + + position.set(Position.KEY_BATTERY, parser.nextInt() * 0.001); return position; } diff --git a/test/org/traccar/protocol/EskyFrameDecoderTest.java b/test/org/traccar/protocol/EskyFrameDecoderTest.java index 3b16a9051..ed587e4f3 100644 --- a/test/org/traccar/protocol/EskyFrameDecoderTest.java +++ b/test/org/traccar/protocol/EskyFrameDecoderTest.java @@ -11,6 +11,10 @@ public class EskyFrameDecoderTest extends ProtocolTest { EskyFrameDecoder decoder = new EskyFrameDecoder(); verifyFrame( + binary("454f3b303b3836313331313030363436313930383b523b363b3138303432303130343735313b322e39373839363b3130312e36353039313b302e37353b3332303b333339383b313b7c"), + decoder.decode(null, null, binary("454f3b303b3836313331313030363436313930383b523b363b3138303432303130343735313b322e39373839363b3130312e36353039313b302e37353b3332303b333339383b313b7c"))); + + verifyFrame( binary("454c3b313b3836343930363032393139363632363b3137303832323134333432363b"), decoder.decode(null, null, binary("454c3b313b3836343930363032393139363632363b3137303832323134333432363b"))); diff --git a/test/org/traccar/protocol/EskyProtocolDecoderTest.java b/test/org/traccar/protocol/EskyProtocolDecoderTest.java index 5132f42c1..10112f24c 100644 --- a/test/org/traccar/protocol/EskyProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EskyProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class EskyProtocolDecoderTest extends ProtocolTest { EskyProtocolDecoder decoder = new EskyProtocolDecoder(new EskyProtocol()); + verifyPosition(decoder, text( + "EO;0;861311006461908;R;6;180420104751;2.97896;101.65091;0.75;320;3398;1;|")); + verifyNull(decoder, text( "EL;1;864906029196626;170822143426;")); |