diff options
author | Valerii Vyshniak <valeravi@vi-soft.com.ua> | 2017-11-16 23:14:27 +0100 |
---|---|---|
committer | Valerii Vyshniak <valeravi@vi-soft.com.ua> | 2017-11-18 18:53:22 +0100 |
commit | b5f33434ff94cbad7a8c37f9211b0c939c6cdc4b (patch) | |
tree | 527e625d24650b3ffa7f4a9989beb974fa5284ba /src/org | |
parent | 3ac49cd8e224887e9a5f8b7a1787183fbdb0e73f (diff) | |
download | trackermap-server-b5f33434ff94cbad7a8c37f9211b0c939c6cdc4b.tar.gz trackermap-server-b5f33434ff94cbad7a8c37f9211b0c939c6cdc4b.tar.bz2 trackermap-server-b5f33434ff94cbad7a8c37f9211b0c939c6cdc4b.zip |
T580W: add battery level to all events
It is possible to use "processing.copyAttributes" configuration to have
battery level in all events, but this will not work if battery events will
be filtered somehow and dropped from DB, so it will be no event in DB with
latest battery level. So, ensure all our events have latest battery level.
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/protocol/Tk103ProtocolDecoder.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 9232fa249..e52d60848 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -29,6 +29,8 @@ import org.traccar.model.Position; import org.traccar.model.WifiAccessPoint; import java.net.SocketAddress; +import java.util.HashMap; +import java.util.Map; import java.util.regex.Pattern; public class Tk103ProtocolDecoder extends BaseProtocolDecoder { @@ -236,6 +238,34 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { } } + private static Map<Long, Position> batteryInfo = new HashMap<Long, Position>(); + + public void setLastBatteryPower(Position positionWithCurrentBatteryInfo) { + batteryInfo.put(positionWithCurrentBatteryInfo.getDeviceId(), positionWithCurrentBatteryInfo); + } + + // It is possible to use "processing.copyAttributes" configuration to have battery level in all events, + // but this will not work if battery events will be filtered somehow and dropped from DB, so it will be no + // event in DB with latest battery level. So, ensure all our events have latest battery level. + public void getLastBatteryPower(Position position) { + if (position != null && position.getDeviceId() != 0) { + Position bi = batteryInfo.get(position.getDeviceId()); + if (bi == null) { + bi = new Position(); + getLastLocation(bi, null); + } + if (bi.getAttributes().containsKey(Position.KEY_BATTERY_LEVEL)) { + position.set(Position.KEY_BATTERY_LEVEL, bi.getDouble(Position.KEY_BATTERY_LEVEL)); + } + if (bi.getAttributes().containsKey(Position.KEY_BATTERY)) { + position.set(Position.KEY_BATTERY, bi.getDouble(Position.KEY_BATTERY)); + } + if (bi.getAttributes().containsKey(Position.KEY_POWER)) { + position.set(Position.KEY_POWER, bi.getDouble(Position.KEY_POWER)); + } + } + } + private Position decodeBattery(Channel channel, SocketAddress remoteAddress, String sentence) { Parser parser = new Parser(PATTERN_BATTERY, sentence); if (!parser.matches()) { @@ -268,6 +298,8 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_POWER, power * 0.1); } + setLastBatteryPower(position); + return position; } @@ -288,6 +320,8 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, null); + getLastBatteryPower(position); + position.setNetwork(new Network(CellTower.from( parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0)))); @@ -313,6 +347,8 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, null); + getLastBatteryPower(position); + Network network = new Network(); // Parse LBS @@ -402,6 +438,8 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { decodeType(position, parser.next(), parser.next()); + getLastBatteryPower(position); + DateBuilder dateBuilder = new DateBuilder(); if (alternative) { dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); |