aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/WristbandProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/WristbandProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/WristbandProtocolDecoder.java80
1 files changed, 70 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/WristbandProtocolDecoder.java b/src/org/traccar/protocol/WristbandProtocolDecoder.java
index 4e044c915..7f2b0af85 100644
--- a/src/org/traccar/protocol/WristbandProtocolDecoder.java
+++ b/src/org/traccar/protocol/WristbandProtocolDecoder.java
@@ -25,7 +25,10 @@ import org.traccar.Protocol;
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.nio.charset.StandardCharsets;
@@ -46,12 +49,16 @@ public class WristbandProtocolDecoder extends BaseProtocolDecoder {
Channel channel, String imei, String version, int type, String data) {
if (channel != null) {
- String sentence = String.format("YX%s|%s|0|{F%d#%s}\r\n", imei, version, type, data);
+ String sentence = String.format("YX%s|%s|0|{F%02d#%s}\r\n", imei, version, type, data);
ByteBuf response = Unpooled.buffer();
- response.writeBytes(new byte[]{0x00, 0x01, 0x02});
- response.writeShort(sentence.length());
+ if (type != 91) {
+ response.writeBytes(new byte[]{0x00, 0x01, 0x02});
+ response.writeShort(sentence.length());
+ }
response.writeCharSequence(sentence, StandardCharsets.US_ASCII);
- response.writeBytes(new byte[]{(byte) 0xFF, (byte) 0xFE, (byte) 0xFC});
+ if (type != 91) {
+ response.writeBytes(new byte[]{(byte) 0xFF, (byte) 0xFE, (byte) 0xFC});
+ }
channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
@@ -59,7 +66,7 @@ public class WristbandProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN = new PatternBuilder()
.expression("..") // header
.number("(d+)|") // imei
- .number("(vd+.d+)|") // version
+ .number("([vV]d+.d+)|") // version
.number("d+|") // model
.text("{")
.number("F(d+)") // function
@@ -81,12 +88,56 @@ public class WristbandProtocolDecoder extends BaseProtocolDecoder {
position.setValid(true);
position.setLongitude(Double.parseDouble(values[0]));
position.setLatitude(Double.parseDouble(values[1]));
- position.setTime(new SimpleDateFormat("yyyyMMddHHmmss").parse(values[2]));
+ position.setTime(new SimpleDateFormat("yyyyMMddHHmm").parse(values[2]));
position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[3])));
return position;
}
+ private Position decodeStatus(DeviceSession deviceSession, String sentence) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(sentence.split(",")[0]));
+
+ return position;
+ }
+
+ private Position decodeNetwork(DeviceSession deviceSession, String sentence, boolean wifi) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ Network network = new Network();
+ String[] fragments = sentence.split("\\|");
+
+ if (wifi) {
+ for (String item : fragments[0].split("_")) {
+ String[] values = item.split(",");
+ network.addWifiAccessPoint(WifiAccessPoint.from(values[0], Integer.parseInt(values[1])));
+ }
+ }
+
+ for (String item : fragments[wifi ? 1 : 0].split(":")) {
+ String[] values = item.split(",");
+ int lac = Integer.parseInt(values[0]);
+ int mnc = Integer.parseInt(values[1]);
+ int mcc = Integer.parseInt(values[2]);
+ int cid = Integer.parseInt(values[3]);
+ int rssi = Integer.parseInt(values[4]);
+ network.addCellTower(CellTower.from(mcc, mnc, lac, cid, rssi));
+ }
+
+ position.setNetwork(network);
+
+ return position;
+ }
+
private List<Position> decodeMessage(
Channel channel, SocketAddress remoteAddress, String sentence) throws ParseException {
@@ -105,23 +156,32 @@ public class WristbandProtocolDecoder extends BaseProtocolDecoder {
int type = parser.nextInt();
List<Position> positions = new LinkedList<>();
+ String data = parser.next();
switch (type) {
case 90:
- sendResponse(channel, imei, version, type, getServer(channel));
+ sendResponse(channel, imei, version, type, getServer(channel, ','));
break;
case 91:
String time = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());
- sendResponse(channel, imei, version, type, time + "|" + getServer(channel));
+ sendResponse(channel, imei, version, type, time + "|" + getServer(channel, ','));
break;
case 1:
- sendResponse(channel, imei, version, type, "0");
+ positions.add(decodeStatus(deviceSession, data));
+ sendResponse(channel, imei, version, type, data.split(",")[1]);
break;
case 2:
- for (String fragment : parser.next().split("\\|")) {
+ for (String fragment : data.split("\\|")) {
positions.add(decodePosition(deviceSession, fragment));
}
break;
+ case 3:
+ case 4:
+ positions.add(decodeNetwork(deviceSession, data, type == 3));
+ break;
+ case 64:
+ sendResponse(channel, imei, version, type, data);
+ break;
default:
break;
}