From e142f095923519d638e8f480cdd4eb2c12b23501 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 14 Jan 2017 17:21:40 +1300 Subject: Support cell and wifi for Watch protocol --- src/org/traccar/protocol/WatchProtocolDecoder.java | 67 +++++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 07df2de13..bb760b3a0 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 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. @@ -18,11 +18,15 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; +import org.traccar.model.WifiAccessPoint; import java.net.SocketAddress; import java.util.Date; @@ -56,11 +60,13 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*),") // course .number("(d+.?d*),") // altitude .number("(d+),") // satellites - .number("(d+),") // gsm + .number("(d+),") // rssi .number("(d+),") // battery .number("(d+),") // steps .number("d+,") // tumbles - .any() + .number("(x+),") // status + .expression("([^\\]]*)") // cell and wifi + .text("]").optional() .compile(); private void sendResponse(Channel channel, String manufacturer, String id, String content) { @@ -70,6 +76,57 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { } } + private String decodeAlarm(int status) { + if (BitUtil.check(status, 0)) { + return Position.ALARM_LOW_BATTERY; + } else if (BitUtil.check(status, 1)) { + return Position.ALARM_GEOFENCE_EXIT; + } else if (BitUtil.check(status, 2)) { + return Position.ALARM_GEOFENCE_ENTER; + } else if (BitUtil.check(status, 3)) { + return Position.ALARM_OVERSPEED; + } else if (BitUtil.check(status, 16)) { + return Position.ALARM_SOS; + } else if (BitUtil.check(status, 17)) { + return Position.ALARM_LOW_BATTERY; + } else if (BitUtil.check(status, 18)) { + return Position.ALARM_GEOFENCE_EXIT; + } else if (BitUtil.check(status, 19)) { + return Position.ALARM_GEOFENCE_ENTER; + } + return null; + } + + private void decodeLbs(Position position, String data) { + String[] values = data.split(","); + int index = 0; + + Network network = new Network(); + + int cellCount = Integer.parseInt(values[index++]); + index += 1; // timing advance + int mcc = Integer.parseInt(values[index++]); + int mnc = Integer.parseInt(values[index++]); + + for (int i = 0; i < cellCount; i++) { + network.addCellTower(CellTower.from(mcc, mnc, + Integer.parseInt(values[index++]), Integer.parseInt(values[index++]), + Integer.parseInt(values[index++]))); + } + + if (index < values.length && !values[index].isEmpty()) { + int wifiCount = Integer.parseInt(values[index++]); + + for (int i = 0; i < wifiCount; i++) { + index += 1; // wifi name + network.addWifiAccessPoint(WifiAccessPoint.from( + values[index++], Integer.parseInt(values[index++]))); + } + } + + position.setNetwork(network); + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -141,6 +198,10 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { position.set("steps", parser.nextInt()); + position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt(16))); + + decodeLbs(position, parser.next()); + return position; } else if (type.equals("TKQ")) { -- cgit v1.2.3