aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java38
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));