diff options
author | jcardus <joaquim.cardeira@gmail.com> | 2020-03-25 17:25:19 +0000 |
---|---|---|
committer | jcardus <joaquim.cardeira@gmail.com> | 2020-03-25 17:25:19 +0000 |
commit | feac85bad4004fb3e316a88285626e12840398d2 (patch) | |
tree | d268a79d63b9d1f27b6e433fedc90de7b427b172 /src/main/java/org/traccar/protocol/EskyProtocolDecoder.java | |
parent | 7b669e3181f637f06b31b55bd930584c7b08e897 (diff) | |
parent | f3d465abe7f255ec44e976caade642e4c2fd7598 (diff) | |
download | trackermap-server-feac85bad4004fb3e316a88285626e12840398d2.tar.gz trackermap-server-feac85bad4004fb3e316a88285626e12840398d2.tar.bz2 trackermap-server-feac85bad4004fb3e316a88285626e12840398d2.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/main/java/org/traccar/protocol/EskyProtocolDecoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/EskyProtocolDecoder.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/EskyProtocolDecoder.java b/src/main/java/org/traccar/protocol/EskyProtocolDecoder.java index 641b2e28f..1a4f9b906 100644 --- a/src/main/java/org/traccar/protocol/EskyProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/EskyProtocolDecoder.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. @@ -16,9 +16,12 @@ package org.traccar.protocol; import io.netty.channel.Channel; +import io.netty.channel.socket.DatagramChannel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.Protocol; +import org.traccar.helper.BitUtil; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -35,7 +38,7 @@ public class EskyProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .expression("..;") // header - .number("d+;") // index + .number("d+;") .number("(d+);") // imei .text("R;") // data type .number("(d+)[+;]") // satellites @@ -58,7 +61,8 @@ public class EskyProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - Parser parser = new Parser(PATTERN, (String) msg); + String sentence = (String) msg; + Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; } @@ -81,13 +85,21 @@ public class EskyProtocolDecoder extends BaseProtocolDecoder { position.setCourse(parser.nextDouble()); if (parser.hasNext(3)) { - position.set(Position.KEY_INPUT, parser.nextHexInt()); + int input = parser.nextHexInt(); + position.set(Position.KEY_IGNITION, !BitUtil.check(input, 0)); + position.set(Position.PREFIX_IN + 1, !BitUtil.check(input, 1)); + position.set(Position.PREFIX_IN + 2, !BitUtil.check(input, 2)); position.set(Position.KEY_EVENT, parser.nextInt()); position.set(Position.KEY_ODOMETER, parser.nextInt()); } position.set(Position.KEY_BATTERY, parser.nextInt() * 0.001); + int index = sentence.lastIndexOf('+'); + if (index > 0 && channel instanceof DatagramChannel) { + channel.writeAndFlush(new NetworkMessage("ACK," + sentence.substring(index + 1) + "#", remoteAddress)); + } + return position; } |