aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java337
1 files changed, 102 insertions, 235 deletions
diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java
index 88b6380a5..e9e37d18a 100644
--- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -108,41 +108,24 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(int event) {
- switch (event) {
- case 1:
- return Position.ALARM_SOS;
- case 17:
- return Position.ALARM_LOW_BATTERY;
- case 18:
- return Position.ALARM_LOW_POWER;
- case 19:
- return Position.ALARM_OVERSPEED;
- case 20:
- return Position.ALARM_GEOFENCE_ENTER;
- case 21:
- return Position.ALARM_GEOFENCE_EXIT;
- case 22:
- return Position.ALARM_POWER_RESTORED;
- case 23:
- return Position.ALARM_POWER_CUT;
- case 36:
- return Position.ALARM_TOW;
- case 44:
- return Position.ALARM_JAMMING;
- case 78:
- return Position.ALARM_ACCIDENT;
- case 90:
- case 91:
- return Position.ALARM_CORNERING;
- case 129:
- return Position.ALARM_BRAKING;
- case 130:
- return Position.ALARM_ACCELERATION;
- case 135:
- return Position.ALARM_FATIGUE_DRIVING;
- default:
- return null;
- }
+ return switch (event) {
+ case 1 -> Position.ALARM_SOS;
+ case 17 -> Position.ALARM_LOW_BATTERY;
+ case 18 -> Position.ALARM_LOW_POWER;
+ case 19 -> Position.ALARM_OVERSPEED;
+ case 20 -> Position.ALARM_GEOFENCE_ENTER;
+ case 21 -> Position.ALARM_GEOFENCE_EXIT;
+ case 22 -> Position.ALARM_POWER_RESTORED;
+ case 23 -> Position.ALARM_POWER_CUT;
+ case 36 -> Position.ALARM_TOW;
+ case 44 -> Position.ALARM_JAMMING;
+ case 78 -> Position.ALARM_ACCIDENT;
+ case 90, 91 -> Position.ALARM_CORNERING;
+ case 129 -> Position.ALARM_BRAKING;
+ case 130 -> Position.ALARM_ACCELERATION;
+ case 135 -> Position.ALARM_FATIGUE_DRIVING;
+ default -> null;
+ };
}
private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {
@@ -207,35 +190,22 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
}
switch (Objects.requireNonNullElse(getDeviceModel(deviceSession), "").toUpperCase()) {
- case "MVT340":
- case "MVT380":
+ case "MVT340", "MVT380" -> {
position.set(Position.KEY_BATTERY, parser.nextHexInt() * 3.0 * 2.0 / 1024.0);
position.set(Position.KEY_POWER, parser.nextHexInt(0) * 3.0 * 16.0 / 1024.0);
- break;
- case "MT90":
+ }
+ case "MT90" -> {
position.set(Position.KEY_BATTERY, parser.nextHexInt() * 3.3 * 2.0 / 4096.0);
position.set(Position.KEY_POWER, parser.nextHexInt(0));
- break;
- case "T1":
- case "T3":
- case "MVT100":
- case "MVT600":
- case "MVT800":
- case "TC68":
- case "TC68S":
+ }
+ case "T1", "T3", "MVT100", "MVT600", "MVT800", "TC68", "TC68S" -> {
position.set(Position.KEY_BATTERY, parser.nextHexInt() * 3.3 * 2.0 / 4096.0);
position.set(Position.KEY_POWER, parser.nextHexInt(0) * 3.3 * 16.0 / 4096.0);
- break;
- case "T311":
- case "T322X":
- case "T333":
- case "T355":
- case "T366":
- case "T366G":
- default:
+ }
+ default -> {
position.set(Position.KEY_BATTERY, parser.nextHexInt() / 100.0);
position.set(Position.KEY_POWER, parser.nextHexInt(0) / 100.0);
- break;
+ }
}
}
@@ -243,12 +213,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
String eventData = parser.next();
if (eventData != null && !eventData.isEmpty()) {
switch (event) {
- case 37:
- position.set(Position.KEY_DRIVER_UNIQUE_ID, eventData);
- break;
- default:
- position.set("eventData", eventData);
- break;
+ case 37 -> position.set(Position.KEY_DRIVER_UNIQUE_ID, eventData);
+ default -> position.set("eventData", eventData);
}
}
@@ -402,42 +368,22 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (id) {
- case 0x01:
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- break;
- case 0x05:
- position.setValid(buf.readUnsignedByte() > 0);
- break;
- case 0x06:
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- break;
- case 0x07:
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- break;
- case 0x14:
- position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
- break;
- case 0x15:
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
- break;
- case 0x47:
+ case 0x01 -> position.set(Position.KEY_EVENT, buf.readUnsignedByte());
+ case 0x05 -> position.setValid(buf.readUnsignedByte() > 0);
+ case 0x06 -> position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+ case 0x07 -> position.set(Position.KEY_RSSI, buf.readUnsignedByte());
+ case 0x14 -> position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
+ case 0x15 -> position.set(Position.KEY_INPUT, buf.readUnsignedByte());
+ case 0x47 -> {
int lockState = buf.readUnsignedByte();
if (lockState > 0) {
position.set(Position.KEY_LOCK, lockState == 2);
}
- break;
- case 0x97:
- position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
- break;
- case 0x9D:
- position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
- break;
- case 0xFE69:
- position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
- break;
- default:
- buf.readUnsignedByte();
- break;
+ }
+ case 0x97 -> position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
+ case 0x9D -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
+ case 0xFE69 -> position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
+ default -> buf.readUnsignedByte();
}
}
@@ -446,58 +392,23 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (id) {
- case 0x08:
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
- break;
- case 0x09:
- position.setCourse(buf.readUnsignedShortLE());
- break;
- case 0x0A:
- position.set(Position.KEY_HDOP, buf.readUnsignedShortLE());
- break;
- case 0x0B:
- position.setAltitude(buf.readShortLE());
- break;
- case 0x16:
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x17:
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x19:
- position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x1A:
- position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x29:
- position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x40:
- position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
- break;
- case 0x91:
- case 0x92:
- position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShortLE());
- break;
- case 0x98:
- position.set(Position.KEY_FUEL_USED, buf.readUnsignedShortLE());
- break;
- case 0x99:
- position.set(Position.KEY_RPM, buf.readUnsignedShortLE());
- break;
- case 0x9C:
- position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShortLE());
- break;
- case 0x9F:
- position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShortLE());
- break;
- case 0xC9:
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShortLE());
- break;
- default:
- buf.readUnsignedShortLE();
- break;
+ case 0x08 -> position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
+ case 0x09 -> position.setCourse(buf.readUnsignedShortLE());
+ case 0x0A -> position.set(Position.KEY_HDOP, buf.readUnsignedShortLE());
+ case 0x0B -> position.setAltitude(buf.readShortLE());
+ case 0x16 -> position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE() * 0.01);
+ case 0x17 -> position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShortLE() * 0.01);
+ case 0x19 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01);
+ case 0x1A -> position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01);
+ case 0x29 -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShortLE() * 0.01);
+ case 0x40 -> position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
+ case 0x91, 0x92 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShortLE());
+ case 0x98 -> position.set(Position.KEY_FUEL_USED, buf.readUnsignedShortLE());
+ case 0x99 -> position.set(Position.KEY_RPM, buf.readUnsignedShortLE());
+ case 0x9C -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShortLE());
+ case 0x9F -> position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShortLE());
+ case 0xC9 -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShortLE());
+ default -> buf.readUnsignedShortLE();
}
}
@@ -506,39 +417,17 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (id) {
- case 0x02:
- position.setLatitude(buf.readIntLE() * 0.000001);
- break;
- case 0x03:
- position.setLongitude(buf.readIntLE() * 0.000001);
- break;
- case 0x04:
- position.setTime(new Date((946684800 + buf.readUnsignedIntLE()) * 1000)); // 2000-01-01
- break;
- case 0x0C:
- position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
- break;
- case 0x0D:
- position.set("runtime", buf.readUnsignedIntLE());
- break;
- case 0x25:
- position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE()));
- break;
- case 0x9B:
- position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedIntLE());
- break;
- case 0xA0:
- position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE() * 0.001);
- break;
- case 0xA2:
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE() * 0.01);
- break;
- case 0xFEF4:
- position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 60000);
- break;
- default:
- buf.readUnsignedIntLE();
- break;
+ case 0x02 -> position.setLatitude(buf.readIntLE() * 0.000001);
+ case 0x03 -> position.setLongitude(buf.readIntLE() * 0.000001);
+ case 0x04 -> position.setTime(new Date((946684800 + buf.readUnsignedIntLE()) * 1000)); // 2000-01-01
+ case 0x0C -> position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
+ case 0x0D -> position.set("runtime", buf.readUnsignedIntLE());
+ case 0x25 -> position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE()));
+ case 0x9B -> position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedIntLE());
+ case 0xA0 -> position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE() * 0.001);
+ case 0xA2 -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE() * 0.01);
+ case 0xFEF4 -> position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 60000);
+ default -> buf.readUnsignedIntLE();
}
}
@@ -548,48 +437,27 @@ 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:
+ case 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 -> {
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:
- case 0x10:
- case 0x12:
- case 0x13:
+ }
+ case 0x0E, 0x0F, 0x10, 0x12, 0x13 -> {
network.addCellTower(CellTower.from(
buf.readUnsignedShortLE(), buf.readUnsignedShortLE(),
buf.readUnsignedShortLE(), buf.readUnsignedIntLE(), buf.readShortLE()));
- break;
- case 0x2A:
- case 0x2B:
- case 0x2C:
- case 0x2D:
- case 0x2E:
- case 0x2F:
- case 0x30:
- case 0x31:
+ }
+ case 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31 -> {
buf.readUnsignedByte(); // label
position.set(Position.PREFIX_TEMP + (id - 0x2A), buf.readShortLE() * 0.01);
- break;
- case 0x4B:
- buf.skipBytes(length); // network information
- break;
- case 0xFE31:
+ }
+ case 0x4B -> buf.skipBytes(length); // network information
+ case 0xFE31 -> {
buf.readUnsignedByte(); // alarm protocol
buf.readUnsignedByte(); // alarm type
buf.skipBytes(length - 2);
- break;
- case 0xFE73:
+ }
+ case 0xFE73 -> {
buf.readUnsignedByte(); // version
position.set(
"tagName",
@@ -602,8 +470,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedShortLE(); // low temperature threshold
buf.readUnsignedShortLE(); // high humidity threshold
buf.readUnsignedShortLE(); // low humidity threshold
- break;
- case 0xFEA8:
+ }
+ case 0xFEA8 -> {
for (int k = 1; k <= 3; k++) {
if (buf.readUnsignedByte() > 0) {
String key = k == 1 ? Position.KEY_BATTERY_LEVEL : "battery" + k + "Level";
@@ -613,10 +481,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
}
}
buf.readUnsignedByte(); // battery alert
- break;
- default:
- buf.skipBytes(length);
- break;
+ }
+ default -> buf.skipBytes(length);
}
}
@@ -650,24 +516,25 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
index = buf.indexOf(index + 1, buf.writerIndex(), (byte) ',');
String type = buf.toString(index + 1, 3, StandardCharsets.US_ASCII);
- switch (type) {
- case "AAC":
+ return switch (type) {
+ case "AAC" -> {
if (channel != null) {
String response = String.format("@@z27,%s,AAC,1*", imei);
response += Checksum.sum(response) + "\r\n";
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
- return null;
- case "D00":
+ yield null;
+ }
+ case "D00" -> {
if (photo == null) {
photo = Unpooled.buffer();
}
index = index + 1 + type.length() + 1;
- int endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
+ int endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
String file = buf.toString(index, endIndex - index, StandardCharsets.US_ASCII);
index = endIndex + 1;
- endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
+ endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
int total = Integer.parseInt(buf.toString(index, endIndex - index, StandardCharsets.US_ASCII));
index = endIndex + 1;
endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
@@ -686,31 +553,31 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
photo.release();
photo = null;
- return position;
+ yield position;
} else {
if ((current + 1) % 8 == 0) {
requestPhotoPacket(channel, remoteAddress, imei, file, current + 1);
}
- return null;
+ yield null;
}
- case "D03":
+ }
+ case "D03" -> {
photo = Unpooled.buffer();
requestPhotoPacket(channel, remoteAddress, imei, "camera_picture.jpg", 0);
- return null;
- case "D82":
+ yield null;
+ }
+ case "D82" -> {
Position position = new Position(getProtocolName());
position.setDeviceId(getDeviceSession(channel, remoteAddress, imei).getDeviceId());
getLastLocation(position, null);
String result = buf.toString(index + 1, buf.writerIndex() - index - 4, StandardCharsets.US_ASCII);
position.set(Position.KEY_RESULT, result);
- return position;
- case "CCC":
- return decodeBinaryC(channel, remoteAddress, buf);
- case "CCE":
- return decodeBinaryE(channel, remoteAddress, buf);
- default:
- return decodeRegular(channel, remoteAddress, buf);
- }
+ yield position;
+ }
+ case "CCC" -> decodeBinaryC(channel, remoteAddress, buf);
+ case "CCE" -> decodeBinaryE(channel, remoteAddress, buf);
+ default -> decodeRegular(channel, remoteAddress, buf);
+ };
}
}