Skip to content

Commit

Permalink
Merge pull request #39 from drolx/merge-upstream-6-5-6
Browse files Browse the repository at this point in the history
Merge upstream for v6.5.7
  • Loading branch information
gpproton authored Oct 27, 2024
2 parents 07c9dd9 + cd00374 commit 8bfaa7c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 8 deletions.
27 changes: 25 additions & 2 deletions src/main/java/org/traccar/forward/PositionForwarderWialon.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;

public class PositionForwarderWialon implements PositionForwarder {

Expand Down Expand Up @@ -74,7 +76,7 @@ public void forward(PositionData positionData, ResultHandler resultHandler) {
String uniqueId = positionData.getDevice().getUniqueId();

String payload = String.format(
"%s;%02d%.5f;%s;%03d%.5f;%s;%d;%d;%d;NA;NA;NA;NA;;%s;NA",
"%s;%02d%.5f;%s;%03d%.5f;%s;%d;%d;%d;NA;NA;NA;NA;;%s;%s",
dateFormat.format(position.getFixTime()),
(int) Math.abs(position.getLatitude()),
Math.abs(position.getLatitude()) % 1 * 60,
Expand All @@ -85,7 +87,8 @@ public void forward(PositionData positionData, ResultHandler resultHandler) {
(int) UnitsConverter.kphFromKnots(position.getSpeed()),
(int) position.getCourse(),
(int) position.getAltitude(),
position.getString(Position.KEY_DRIVER_UNIQUE_ID, "NA"));
position.getString(Position.KEY_DRIVER_UNIQUE_ID, "NA"),
formatAttributes(position.getAttributes()));

String message;
if (version.startsWith("2")) {
Expand All @@ -108,4 +111,24 @@ public void forward(PositionData positionData, ResultHandler resultHandler) {
}
}

public static String formatAttributes(Map<String, Object> attributes) {
if (attributes.isEmpty()) {
return "NA";
}
return attributes.entrySet().stream()
.map(entry -> {
Object value = entry.getValue();
int type;
if (value instanceof Double || value instanceof Float) {
type = 2;
} else if (value instanceof Number) {
type = 1;
} else {
type = 3;
}
return entry.getKey() + ":" + type + ":" + value;
})
.collect(Collectors.joining(","));
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/traccar/handler/EngineHoursHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void onPosition(Position position, Callback callback) {
if (last != null) {
long hours = last.getLong(Position.KEY_HOURS);
if (last.getBoolean(Position.KEY_IGNITION) && position.getBoolean(Position.KEY_IGNITION)) {
hours += position.getFixTime().getTime() - last.getFixTime().getTime();
hours += position.getDeviceTime().getTime() - last.getDeviceTime().getTime();
}
if (hours != 0) {
position.set(Position.KEY_HOURS, hours);
Expand Down
49 changes: 44 additions & 5 deletions src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public Gt06ProtocolDecoder(Protocol protocol) {
public static final int MSG_BMS = 0x40; // WD-209
public static final int MSG_MULTIMEDIA = 0x41; // WD-209
public static final int MSG_ALARM = 0x95; // JC100
public static final int MSG_PERIPHERAL = 0xF2; // VL842

private enum Variant {
VXT01,
Expand Down Expand Up @@ -815,8 +816,13 @@ private Object decodeBasic(Channel channel, SocketAddress remoteAddress, ByteBuf
position.addAlarm(decodeAlarm(buf.readUnsignedByte(), modelLW));
buf.readUnsignedByte(); // language
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
buf.readUnsignedByte(); // working mode
int mode = buf.readUnsignedByte();
position.set(Position.KEY_POWER, buf.readUnsignedShort() / 100.0);
buf.readUnsignedByte(); // reserved
buf.readUnsignedShort(); // working time
if (mode == 4) {
position.set(Position.PREFIX_TEMP + 1, buf.readShort() / 10.0);
}
} else {
if (type == MSG_GPS_LBS_STATUS_5) {
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
Expand Down Expand Up @@ -1366,8 +1372,6 @@ private Object decodeExtended(Channel channel, SocketAddress remoteAddress, Byte
if (photo != null) {
buf.readBytes(photo, buf.readableBytes() - 3 * 2);
if (!photo.isWritable()) {
position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, new Date(timestamp));
position.set(Position.KEY_IMAGE, writeMediaFile(deviceSession.getUniqueId(), photo, "jpg"));
photos.remove(mediaId).release();
Expand All @@ -1382,8 +1386,6 @@ private Object decodeExtended(Channel channel, SocketAddress remoteAddress, Byte

} else if (type == MSG_SERIAL) {

position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);

buf.readUnsignedByte(); // external device type code
Expand All @@ -1398,6 +1400,43 @@ private Object decodeExtended(Channel channel, SocketAddress remoteAddress, Byte

return position;

} else if (type == MSG_PERIPHERAL) {

long timestamp = buf.readUnsignedInt() * 1000;
getLastLocation(position, new Date(timestamp));

while (buf.readableBytes() > 6) {
int statusId = buf.readUnsignedShort();
switch (statusId) {
case 0x000A -> {
int statusLength = buf.readUnsignedShort();
buf.readUnsignedByte(); // mac address type
position.set("mac", ByteBufUtil.hexDump(buf.readSlice(6)));
int event = buf.readUnsignedByte();
position.set(Position.KEY_EVENT, event);
int eventData = buf.readUnsignedByte();
position.set("eventData", event > 0 ? eventData : null);
position.set("dataType", buf.readUnsignedByte());
position.set("dataDetails", ByteBufUtil.hexDump(buf.readSlice(statusLength - 10)));
}
case 0x000C -> {
buf.readUnsignedByte(); // length
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_CHARGE, buf.readUnsignedByte() > 0 ? true : null);
position.set("batteryCycles", buf.readUnsignedShort());
buf.skipBytes(6);
}
default -> {
int statusLength = buf.readUnsignedByte();
buf.skipBytes(statusLength == 0 ? buf.readUnsignedByte() : statusLength);
}
}
}

sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null);

return position;

}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ private static void register(int id, Set<String> models, BiConsumer<Position, By
register(110, fmbXXX, (p, b) -> p.set(Position.KEY_FUEL_CONSUMPTION, b.readUnsignedShort() * 0.1));
register(113, fmbXXX, (p, b) -> p.set(Position.KEY_BATTERY_LEVEL, b.readUnsignedByte()));
register(115, fmbXXX, (p, b) -> p.set("engineTemp", b.readShort() * 0.1));
register(701, Set.of("FMC640", "FMC650", "FMM640"), (p, b) -> p.set("bleTemp1", b.readShort() * 0.01));
register(702, Set.of("FMC640", "FMC650", "FMM640"), (p, b) -> p.set("bleTemp2", b.readShort() * 0.01));
register(703, Set.of("FMC640", "FMC650", "FMM640"), (p, b) -> p.set("bleTemp3", b.readShort() * 0.01));
register(704, Set.of("FMC640", "FMC650", "FMM640"), (p, b) -> p.set("bleTemp4", b.readShort() * 0.01));
register(179, null, (p, b) -> p.set(Position.PREFIX_OUT + 1, b.readUnsignedByte() > 0));
register(180, null, (p, b) -> p.set(Position.PREFIX_OUT + 2, b.readUnsignedByte() > 0));
register(181, null, (p, b) -> p.set(Position.KEY_PDOP, b.readUnsignedShort() * 0.1));
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/traccar/web/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ private void initSessionConfig(ServletContextHandler servletHandler) {
break;
}
}

sessionCookieConfig.setHttpOnly(true);
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ public void testDecode() throws Exception {
verifyNull(decoder, binary(
"78780D01086471700328358100093F040D0A"));

verifyAttributes(decoder, binary(
"79790016f26718e430000c0a470000000010020000000024bff50d0a"));

verifyAttributes(decoder, binary(
"79790037f26718e389000b0a0423027aca200c465a60000a001d01c4a82828ccfe0000024254425554544f4e2c412c53233136382c35340016a1eb0d0a"));

verifyAttribute(decoder, binary(
"7878131340b2fa000201040000000000011c00400e550d0a"),
Position.PREFIX_TEMP + 1, 28.4);

verifyAttribute(decoder, binary(
"787817360005040002003201010018020192006a015f0324aeaf0d0a"),
Position.KEY_BATTERY, 4.02);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public void testDecode() throws Exception {

var decoder = inject(new Tr20ProtocolDecoder(null));

verifyPosition(decoder, text(
"%%0561,A,241025160359,N0951.6626W08357.0266,000,025,F0.0,00020000,108,CFG:0.12|"));

verifyPosition(decoder, text(
"%%m13,L,221221103115,N1237.2271W00801.9500,000,000,B13.1:F0.0,04020000,253,CFG:133.00|"));

Expand Down

0 comments on commit 8bfaa7c

Please sign in to comment.