From 6d8061f868ca142018581d38410dcff80256c9cd Mon Sep 17 00:00:00 2001 From: David Bergh Date: Thu, 7 Sep 2023 16:13:12 +0200 Subject: Add Meitrack WiFi Aps, celltowers and network info Includes WiFi aps, celltowers and network information. Based on page 8-10 of Meitrack protocol: https://www.meitrack.com/cd-download/Protocols/MEITRACK_P88L_GPRS_Protocol.pdf Closes #5171 --- .../traccar/protocol/MeitrackProtocolDecoder.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java index 0f0d22021..eb0a80e05 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -16,6 +16,7 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; @@ -30,6 +31,7 @@ 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; @@ -394,6 +396,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); + Network network = new Network(); + buf.readUnsignedShortLE(); // length buf.readUnsignedShortLE(); // index @@ -537,6 +541,32 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte(); int length = buf.readUnsignedByte(); switch (id) { + case 0x1D: + case 0x1E: + case 0x1F: + case 0x20: + case 0x21: + case 0x22: + case 0x23: + case 0x24: + case 0x25: + String wifiMAC = ByteBufUtil.hexDump(buf.readSlice(6)); + int wifiRSSI = buf.readUnsignedShortLE(); + network.addWifiAccessPoint(WifiAccessPoint.from(wifiMAC, wifiRSSI)); + break; + case 0x0E: + case 0x0F: + case 0x10: + case 0x12: + case 0x13: + int stationMCC = buf.readUnsignedShortLE(); + int stationMNC = buf.readUnsignedShortLE(); + int stationLAC = buf.readUnsignedShortLE(); + long stationID = buf.readUnsignedIntLE(); + int stationRX_LEVEL = buf.readUnsignedShortLE(); + network.addCellTower(CellTower.from(stationMCC, stationMNC, stationLAC, stationID, + stationRX_LEVEL)); + break; case 0x2A: case 0x2B: case 0x2C: @@ -548,6 +578,13 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // label position.set(Position.PREFIX_TEMP + (id - 0x2A), buf.readShortLE() * 0.01); break; + case 0x4B: + position.set("networkVersion", buf.readUnsignedByte()); + position.set("networkType", buf.readUnsignedByte()); + int networkDescLen = buf.readUnsignedByte(); + String networkDesc = buf.readSlice(networkDescLen).toString(StandardCharsets.US_ASCII); + network.setRadioType(networkDesc); + break; case 0xFE31: buf.readUnsignedByte(); // alarm protocol buf.readUnsignedByte(); // alarm type @@ -570,6 +607,9 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { } } + if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) { + position.setNetwork(network); + } positions.add(position); } -- cgit v1.2.3 From bb46ff66b74731dd7c7b2359017b0cd8c137824c Mon Sep 17 00:00:00 2001 From: David Bergh Date: Fri, 8 Sep 2023 15:30:47 +0200 Subject: Use signed short for RSSI --- src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java index eb0a80e05..3ee9d9732 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -551,7 +551,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { case 0x24: case 0x25: String wifiMAC = ByteBufUtil.hexDump(buf.readSlice(6)); - int wifiRSSI = buf.readUnsignedShortLE(); + int wifiRSSI = buf.readShortLE(); network.addWifiAccessPoint(WifiAccessPoint.from(wifiMAC, wifiRSSI)); break; case 0x0E: @@ -563,7 +563,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { int stationMNC = buf.readUnsignedShortLE(); int stationLAC = buf.readUnsignedShortLE(); long stationID = buf.readUnsignedIntLE(); - int stationRX_LEVEL = buf.readUnsignedShortLE(); + int stationRX_LEVEL = buf.readShortLE(); network.addCellTower(CellTower.from(stationMCC, stationMNC, stationLAC, stationID, stationRX_LEVEL)); break; -- cgit v1.2.3 From 33f0df11d027a48be2c3c1030198855311e13d00 Mon Sep 17 00:00:00 2001 From: David Bergh Date: Mon, 11 Sep 2023 09:20:38 +0200 Subject: Reformat MAC + inline --- .../java/org/traccar/protocol/MeitrackProtocolDecoder.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java index 3ee9d9732..0b17b3ee7 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -550,7 +550,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { case 0x23: case 0x24: case 0x25: - String wifiMAC = ByteBufUtil.hexDump(buf.readSlice(6)); + String wifiMAC = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:"); int wifiRSSI = buf.readShortLE(); network.addWifiAccessPoint(WifiAccessPoint.from(wifiMAC, wifiRSSI)); break; @@ -559,13 +559,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { case 0x10: case 0x12: case 0x13: - int stationMCC = buf.readUnsignedShortLE(); - int stationMNC = buf.readUnsignedShortLE(); - int stationLAC = buf.readUnsignedShortLE(); - long stationID = buf.readUnsignedIntLE(); - int stationRX_LEVEL = buf.readShortLE(); - network.addCellTower(CellTower.from(stationMCC, stationMNC, stationLAC, stationID, - stationRX_LEVEL)); + network.addCellTower(CellTower.from(buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), + buf.readUnsignedShortLE(), buf.readUnsignedIntLE(), buf.readShortLE())); break; case 0x2A: case 0x2B: @@ -582,8 +577,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.set("networkVersion", buf.readUnsignedByte()); position.set("networkType", buf.readUnsignedByte()); int networkDescLen = buf.readUnsignedByte(); - String networkDesc = buf.readSlice(networkDescLen).toString(StandardCharsets.US_ASCII); - network.setRadioType(networkDesc); + network.setRadioType(buf.readSlice(networkDescLen).toString(StandardCharsets.US_ASCII)); break; case 0xFE31: buf.readUnsignedByte(); // alarm protocol -- cgit v1.2.3 From 2b2eb27834968addc35ec3e4be1be88a0f8806ac Mon Sep 17 00:00:00 2001 From: David Bergh Date: Tue, 12 Sep 2023 07:26:18 +0200 Subject: Skip network --- src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java index 0b17b3ee7..2e786070f 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -574,10 +574,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_TEMP + (id - 0x2A), buf.readShortLE() * 0.01); break; case 0x4B: - position.set("networkVersion", buf.readUnsignedByte()); - position.set("networkType", buf.readUnsignedByte()); - int networkDescLen = buf.readUnsignedByte(); - network.setRadioType(buf.readSlice(networkDescLen).toString(StandardCharsets.US_ASCII)); + buf.skipBytes(length); // network information break; case 0xFE31: buf.readUnsignedByte(); // alarm protocol -- cgit v1.2.3 From df28582395349cfc71cfdea1baf1a7683f804110 Mon Sep 17 00:00:00 2001 From: David Bergh Date: Wed, 13 Sep 2023 10:50:59 +0200 Subject: Fix mac address formatting --- src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java index 2e786070f..8a1e14834 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -550,9 +550,9 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { case 0x23: case 0x24: case 0x25: - String wifiMAC = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:"); - int wifiRSSI = buf.readShortLE(); - network.addWifiAccessPoint(WifiAccessPoint.from(wifiMAC, wifiRSSI)); + String wifiMac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:"); + network.addWifiAccessPoint(WifiAccessPoint.from(wifiMac.substring(0, wifiMac.length() - 1), + buf.readShortLE())); break; case 0x0E: case 0x0F: -- cgit v1.2.3